Open banool opened 8 months ago
I'm using version 7.7.0 of the @pulumi/gcp provider.
@banool I believe there are a few things worth mentioning here.
primaryInstance.instanceId
to reference the database.alloydb.iam_authentication
) (see 5).alloydb.User
instead to create a BUILT_IN
user?deletedWith
resource option to speed up the instance deletion.alloydb.iam_authentication
, but probably because I don't have the necessary permissions.Side note: For one user, I used defaultCluster.name
and the other primaryInstance.instanceId
.
import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";
const defaultNetwork = new gcp.compute.Network("alloydb-network", {
name: "alloydb-network"
});
const defaultCluster = new gcp.alloydb.Cluster("alloydb-cluster", {
clusterId: "alloydb-cluster",
location: "australia-southeast1",
networkConfig: {
network: defaultNetwork.id
},
initialUser: {
password: "cluster_secret",
},
});
const privateIpAlloc = new gcp.compute.GlobalAddress("private_ip_alloc", {
name: "alloydb-ip-alloc",
addressType: "INTERNAL",
purpose: "VPC_PEERING",
prefixLength: 16,
network: defaultNetwork.id,
});
const vpcConnection = new gcp.servicenetworking.Connection("vpc_connection", {
network: defaultNetwork.id,
service: "servicenetworking.googleapis.com",
reservedPeeringRanges: [privateIpAlloc.name],
});
const primaryInstance = new gcp.alloydb.Instance("primary", {
instanceId: "alloydb-instance",
cluster: defaultCluster.name,
machineConfig: {
cpuCount: 4,
},
instanceType: "PRIMARY",
databaseFlags: {
"alloydb.iam_authentication": "on"
},
},{
dependsOn: vpcConnection,
});
const user1 = new gcp.alloydb.User("alloydb-user", {
cluster: defaultCluster.name,
userId: "alloydb-user",
userType: "ALLOYDB_BUILT_IN",
password: "dwlkemdwlkjedwlkjmoihjoijkmcvewolkmdwokme",
databaseRoles: ["alloydbiamuser"]
}, {
deletedWith: primaryInstance
});
// // This code requires additional work and doesn't work.
// // The error returned is "Error, failed to insert user sql-user into instance alloydb-instance: googleapi: Error 403: The client is not authorized to make this request., notAuthorized"
// const user2 = new gcp.sql.User("sql-user", {
// name: "sql-user",
// instance: primaryInstance.instanceId,
// password: "dkjmoihjoijkmcvewolkmd9w8eud98w123wedfdvcdwokme",
// deletionPolicy: "ABANDON",
// type: "BUILT_IN",
// }, {
// deletedWith: primaryInstance
// });
Hey, thanks for the quick response!
I was able to get it to work with just 3:
new gcp.alloydb.User(prefixName(`read-only`), {
userId: READ_POOL_USERNAME,
password: readPoolUserSecrets.initialPassword.result,
userType: "ALLOYDB_BUILT_IN",
databaseRoles: ["pg_read_all_data"],
cluster: this.cluster.name,
});
Makes total sense to use an alloydb-specific user class, I just didn't know it exists. I suppose I just googled "pulumi sql user" and that's what came up. Perhaps a warning at the top of the docs there that points you to the db-specific user classes would be good, since the docs as they are don't work for AlloyDB (presumably you have to make some of the other changes you mentioned, such as using instanceId
rather than name
).
Thanks!
What happened?
I followed the guide as per the docs: https://www.pulumi.com/registry/packages/gcp/api-docs/sql/user/.
When you do this, you get the following error:
This is the log of the resource it is trying to create:
It seems like
name
returns the fully qualified resource ID, not just the instance name. Weirdly enough if I just use the instance name it also doesn't work, I get a 403, which if this answer is right, implies the instance name isn't real, which makes me think the fully qualified resource ID is indeed actually what we want: https://stackoverflow.com/q/45481153/3846032. If so though, something else is amiss.Example
See above.
Output of
pulumi about
Additional context
No response
Contributing
No response