Hi folks, I have a `gcp.secretmanager.Secret`, and...
# general
k
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
@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
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
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
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
okay, why are you using the
.get
method then? its already in your state. Just pass
secret_id
k
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
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
Ok, I got this. Your second statement pushes the fog away ... this is probably a wrong approach
🙏