https://pulumi.com logo
#general
Title
# general
k

kind-keyboard-17263

06/03/2022, 3:08 PM
Hi folks, I have a
gcp.secretmanager.Secret
, and I need the
.secret_id
field. I have read that it must be done either by using
apply
or
lifting
. So:
Copy code
existing_secret = gcp.secretmanager.Secret.get(
    secret_basic.name.apply(lambda name: name),
    secret_basic.secret_id.apply(lambda id: id))
But I keep on having:
Copy code
TypeError: Expected resource name to be a string
What am I doing wrong ?
b

billowy-army-68599

06/03/2022, 3:30 PM
@kind-keyboard-17263 the
.get
methods still need a resource name, you're invoking the function incorrectly, the first property should be its name
k

kind-keyboard-17263

06/03/2022, 3:34 PM
Thanks for answering, @billowy-army-68599. The created resource is:
Copy code
secret_resource: {
        create_time: "2022-06-03T14:38:41.088076Z"
        id         : "some_id"
        labels     : {
            env: "qa"
        }
        name       : "projects/xxx/secrets/secret"
        project    : "blabla"
        replication: {
            automatic   : false
            user_managed: {
                replicas: [
                    [0]: {
                        location: "europe-west1"
                    }
                ]
            }
        }
        secret_id  : "secret"
        urn        : "blablabla"
    }
I tried to use
secret.name
, but I have the same error constantly. I mean, if I pass to random string, I have a correct "resouce does not exist" error, my problem is how to extrapolate properties from the Output instance
b

billowy-army-68599

06/03/2022, 3:37 PM
have you defined a secret to create, or just using the
.get
method?
Copy code
existing_secret = gcp.secretmanager.Secret.get(
    secret_basic.name.apply(lambda name: name),
    secret_basic.secret_id.apply(lambda id: id))
This is incorrect, it should be something like: existing_secret = gcp.secretmanager.Secret.get('resourcename', {}`
k

kind-keyboard-17263

06/03/2022, 3:38 PM
Copy code
secret =  gcp.secretmanager.Secret("secret-basic",
    labels={
        "env": "qa",
    },
    replication=gcp.secretmanager.SecretReplicationArgs(
        user_managed=gcp.secretmanager.SecretReplicationUserManagedArgs(
            replicas=[
                gcp.secretmanager.SecretReplicationUserManagedReplicaArgs(
                    location="europe-west1",
                )
            ],
        ),
    ),
    secret_id="secret")
and then trying to use the static
get
method
b

billowy-army-68599

06/03/2022, 3:40 PM
okay, why are you using the
.get
method then? its already in your state. Just pass
secret_id
k

kind-keyboard-17263

06/03/2022, 3:42 PM
Good point. I am refactoring the script, and in a next execution I could "add" dynamically a resource object (for example if I inject variables from the outside). If this happens, I need to know if a given set of resources already exists. Does that any sens e?
b

billowy-army-68599

06/03/2022, 3:45 PM
thats am imperative operation, which kinda goes against Pulumi's model. In any case, if you want to grab an existing secret you have to know its name. and the resource name has to be a static value, it can't be an output
k

kind-keyboard-17263

06/03/2022, 3:46 PM
Ok, I got this. Your second statement pushes the fog away ... this is probably a wrong approach
🙏
4 Views