is it possible to turn a `Promise<gcp.container...
# general
g
is it possible to turn a
Promise<gcp.container.GetClusterResult>
into an
Input<gcp.container.GetClusterResult>
or
Output<gcp.container.GetClusterResult>
so that I can pass subproperties of the result to pulumi resources without manual unwrapping?
m
Yep! A
Promise<T>
is directly assignable to an
Input<T>
.
More precisely, it's already an
Input<T>
, as
Input<T>
is defined as the union of
T | Input<T> | Output<T>
g
Hmm, what I meant was to be able to get a subproperty of the result and pass it downstream without unwrapping
i.e. this would be nice:
Copy code
const clusterResult = gcp.container.getCluster({name: 'my-custer'})

new my.Resource('foo', {
  clusterEndPoint: clusterResult.endpoint
})
if
clusterResult
would be a regular pulumi resource i could tap into the subproperties without unwrapping.
but since it’s a
Promise
I first would have to unwrap it via
.then
in order to get a subproperty.
i
Yeah, this is the chief advantage of using
.get
over data sources -
.get
does give you a regular pulumi resource
g
Ok, makes sense
somehow I can’t get .get to work though 😕
I created a small example
creates a GCS bucket via
gsutil mb <gs://pulumi-experiment-bucket>
now I’m trying to use that bucket in pulumi via
Copy code
import * as gcp from '@pulumi/gcp';

const myBucket = gcp.storage.Bucket.get('my-bucket', 'pulumi-experiment-bucket');
but I’m getting this error:
Copy code
Previewing changes:

     Type                   Name                                            Plan       Info
 +   pulumi:pulumi:Stack    pulumi-query-experiments-christian-experiments  create
 >-  └─ gcp:storage:Bucket  my-bucket                                       read       1 error

Diagnostics:
  gcp:storage:Bucket: my-bucket
    error: Preview failed: refreshing urn:pulumi:christian-experiments::pulumi-query-experiments::gcp:storage/bucket:Bucket::my-bucket: Error reading Storage Bucket "": googleapi: Error 400: Required parameter: project, required

error: an error occurred while advancing the preview
Note I already set the project in the provider config via
pulumi config set gcp:project my-project
ok actually I got it working now by changing it to
Copy code
import * as gcp from '@pulumi/gcp';

const myBucket = gcp.storage.Bucket.get(
  'my-bucket',
  'pulumi-experiment-bucket',
  { project: 'my-project', name: 'pulumi-experiment-bucket' }
);
i
ah, yeah, I was just typing that up
g
I guess I’m confused what the second parameter is for though?
i
My understanding is that if the cloud provider requires additional arguments to its APIs that retrieve the given object, you may have to pass them as the third parameter.
In this case, the project
g
hmm, well let’s leave the project aside. When I have the project id already configured in the provider this doesn’t work:
Copy code
import * as gcp from '@pulumi/gcp';

const myBucket = gcp.storage.Bucket.get(
  'my-bucket',
  'pulumi-experiment-bucket'
);
but THIS works:
Copy code
import * as gcp from '@pulumi/gcp';

const myBucket = gcp.storage.Bucket.get(
  'my-bucket',
  'pulumi-experiment-bucket',
  { name: 'pulumi-experiment-bucket' }
);
So I’m wondering why I have to specify the bucket name twice (once as second param, and once as property
name
to the third param)?
i
The second argument to
.get
is actually an ID, which uniquely identifies the bucket - it may not be the same as the name of the bucket itself.
g
In general I’m confused about why the second param is necessary at all if the values in the third parameter seem to be used for the lookup?
Well at least in GCP I think the bucket name IS the id.
There’s no random uuid or so assigned to a bucket.
Hmm, so I now changed the ID param to something other than
name
and now pulumi fails with:
Copy code
Previewing changes:

     Type                   Name                                            Plan       Info
 +   pulumi:pulumi:Stack    pulumi-query-experiments-christian-experiments  create
 >-  └─ gcp:storage:Bucket  my-bucket                                       read       1 error

Diagnostics:
  gcp:storage:Bucket: my-bucket
    error: Preview failed: reading resource urn:pulumi:christian-experiments::pulumi-query-experiments::gcp:storage/bucket:Bucket::my-bucket yielded an unexpected ID;expected pulumi-experiment-bucket-foo, got pulumi-experiment-bucket

error: an error occurred while advancing the preview
So it seems pulumi uses indeed the
name
property for the lookup but then tries to match that name with the manually provided
id
and complains if they don’t match.
i
Ah, that is interesting!
@microscopic-florist-22719 might know more about this behavior
g
I’m not sure if this a GCP provider specific issue, but I find this confusing. I think the desired behaviour should be to not require passing the
name
property at all, because the
id
is assumed to be name anyways.
And as far as I can see it this problem applies to a lot of GCP resources. GCP uses deterministic / named IDs for most of the resources (compared to AWS which often has a random ID and a separate name property for their resources).
m
This is very odd.
This seems like it could be a tricky integration issue with the GCP Terraform provider, which is what our Pulumi GCP provider is derived from
Can you file an issue in https://github.com/pulumi/pulumi-gcp describing what you're seeing? This is definitely something I'd like to investigate further.
g
ok sure
m
Thanks!
g
@microscopic-florist-22719 there you go: https://github.com/pulumi/pulumi-gcp/issues/48
m
Thanks!