Open pasqualet opened 2 years ago
Can you tell me a little bit more about what you are trying to do here? This is a template repo to create components and you might instead be looking for a component like: https://github.com/pulumi/pulumi-aws-static-website or https://github.com/pulumi/pulumi-awsx.
I'm developing a set of Pulumi components for AWS with TypeScript and I want to publish them as a Pulumi Package. So I'm testing this repository to build the pacakge, but I've seen this behaviour and I want to figure out if it's an expected behaviour, a bug or something that I'm doing wrong.
Each of my component creates many AWS resources and I would like that the users can access their properties, because in this way they can take the values for the declaration of other resources (from my package or from other ones).
As far as I can, I see that the resource properties created by the pulumi-eks package can be accessed and this is what I'm expecting when using this template.
This is my test with pulumi-eks:
import * as pulumi from "@pulumi/pulumi";
import * as eks from "@pulumi/eks";
const cluster1 = new eks.Cluster("test");
export const id = cluster1.eksCluster.id;
Pulumi results:
% pulumi up -y
Previewing update (dev)
View Live: https://app.pulumi.com/XXX
Type Name Plan
+ pulumi:pulumi:Stack example-cluster-dev create
+ ââ eks:index:Cluster test create
+ ââ eks:index:ServiceRole test-instanceRole create
+ â ââ aws:iam:Role test-instanceRole-role create
+ â ââ aws:iam:RolePolicyAttachment test-instanceRole-3eb088f2 create
+ â ââ aws:iam:RolePolicyAttachment test-instanceRole-e1b295bd create
+ â ââ aws:iam:RolePolicyAttachment test-instanceRole-03516f97 create
+ ââ eks:index:ServiceRole test-eksRole create
+ â ââ aws:iam:Role test-eksRole-role create
+ â ââ aws:iam:RolePolicyAttachment test-eksRole-4b490823 create
+ ââ eks:index:RandomSuffix test-cfnStackName create
+ ââ aws:iam:InstanceProfile test-instanceProfile create
+ ââ aws:ec2:SecurityGroup test-eksClusterSecurityGroup create
+ ââ aws:ec2:SecurityGroupRule test-eksClusterInternetEgressRule create
+ ââ aws:eks:Cluster test-eksCluster create
+ ââ aws:ec2:SecurityGroup test-nodeSecurityGroup create
+ ââ pulumi:providers:kubernetes test-eks-k8s create
+ ââ eks:index:VpcCni test-vpc-cni create
+ ââ aws:ec2:SecurityGroupRule test-eksNodeInternetEgressRule create
+ ââ aws:ec2:SecurityGroupRule test-eksClusterIngressRule create
+ ââ aws:ec2:SecurityGroupRule test-eksNodeClusterIngressRule create
+ ââ aws:ec2:SecurityGroupRule test-eksExtApiServerClusterIngressRule create
+ ââ kubernetes:core/v1:ConfigMap test-nodeAccess create
+ ââ aws:ec2:SecurityGroupRule test-eksNodeIngressRule create
+ ââ aws:ec2:LaunchConfiguration test-nodeLaunchConfiguration create
+ ââ aws:cloudformation:Stack test-nodes create
+ ââ pulumi:providers:kubernetes test-provider create
Outputs:
id: output<string>
Resources:
+ 27 to create
Updating (dev)
View Live: https://app.pulumi.com/XXX
Type Name Status
+ pulumi:pulumi:Stack example-cluster-dev created
+ ââ eks:index:Cluster test created
+ ââ eks:index:ServiceRole test-instanceRole created
+ â ââ aws:iam:Role test-instanceRole-role created
+ â ââ aws:iam:RolePolicyAttachment test-instanceRole-03516f97 created
+ â ââ aws:iam:RolePolicyAttachment test-instanceRole-3eb088f2 created
+ â ââ aws:iam:RolePolicyAttachment test-instanceRole-e1b295bd created
+ ââ eks:index:ServiceRole test-eksRole created
+ â ââ aws:iam:Role test-eksRole-role created
+ â ââ aws:iam:RolePolicyAttachment test-eksRole-4b490823 created
+ ââ eks:index:RandomSuffix test-cfnStackName created
+ ââ aws:ec2:SecurityGroup test-eksClusterSecurityGroup created
+ ââ aws:iam:InstanceProfile test-instanceProfile created
+ ââ aws:ec2:SecurityGroupRule test-eksClusterInternetEgressRule created
+ ââ aws:eks:Cluster test-eksCluster created
+ ââ aws:ec2:SecurityGroup test-nodeSecurityGroup created
+ ââ eks:index:VpcCni test-vpc-cni created
+ ââ pulumi:providers:kubernetes test-eks-k8s created
+ ââ kubernetes:core/v1:ConfigMap test-nodeAccess created
+ ââ aws:ec2:SecurityGroupRule test-eksNodeInternetEgressRule created
+ ââ aws:ec2:SecurityGroupRule test-eksExtApiServerClusterIngressRule created
+ ââ aws:ec2:SecurityGroupRule test-eksNodeClusterIngressRule created
+ ââ aws:ec2:SecurityGroupRule test-eksNodeIngressRule created
+ ââ aws:ec2:SecurityGroupRule test-eksClusterIngressRule created
+ ââ aws:ec2:LaunchConfiguration test-nodeLaunchConfiguration created
+ ââ aws:cloudformation:Stack test-nodes created
+ ââ pulumi:providers:kubernetes test-provider created
Outputs:
**id: "test-eksCluster-6e9e17e"**
Resources:
+ 27 created
Duration: 10m57s
I've notice that the example project is missing the @pulumi/aws
dependency and I suppose this is the reason of Pulumi beliving the bucket
property is has type 'Output
This is the change I'm appling in the package.json:
diff --git a/examples/simple/package.json b/examples/simple/package.json
index 641c4e3..2435e14 100644
--- a/examples/simple/package.json
+++ b/examples/simple/package.json
@@ -4,6 +4,7 @@
"@types/node": "^10.0.0"
},
"dependencies": {
+ "@pulumi/aws": "^5.13.0",
"@pulumi/pulumi": "^3.0.0"
}
}
Installing the dependencies (npm install
) and running pulumi again, the components are created successfully but there is still an issue because the bucket properties are undefined.
The index.ts
:
import * as xyz from "@pulumi/xyz";
const page = new xyz.StaticPage("page", {
indexContent: "<html><body><p>Hello world!</p></body></html>",
});
export const bucket = page.bucket;
export const url = page.websiteUrl;
export const bucketId = page.bucket.id;
export const bucketArn = page.bucket.arn;
export const bucketDomainName = page.bucket.bucketDomainName;
export const bucketRegion = page.bucket.region;
Pulumi up:
% pulumi up -y
Previewing update (test)
View Live: https://app.pulumi.com/XXX
Type Name Plan
+ pulumi:pulumi:Stack simple-mytest create
+ ââ xyz:index:StaticPage page create
+ ââ aws:s3:Bucket page create
+ ââ aws:s3:BucketPolicy bucketPolicy create
+ ââ aws:s3:BucketObject page create
Outputs:
bucket: "urn:pulumi:mytest::simple::xyz:index:StaticPage$aws:s3/bucket:Bucket::page"
url : output<string>
Resources:
+ 5 to create
Updating (test)
View Live: https://app.pulumi.com/XXX
Type Name Status
+ pulumi:pulumi:Stack simple-mytest created
+ ââ xyz:index:StaticPage page created
+ ââ aws:s3:Bucket page created
+ ââ aws:s3:BucketPolicy bucketPolicy created
+ ââ aws:s3:BucketObject page created
Outputs:
bucket: "page-30c0cf2"
url : "page-30c0cf2.s3-website-eu-west-1.amazonaws.com"
Resources:
+ 5 created
Duration: 8s
I believe you will need to register those outputs in the ComponentResource so that Pulumi will not mark it as complete until those outputs are ready.
This code currently only sets bucket
and url
.
Jumping in here =) cause I too have had this same issue! I tried asking in the pulumi slacking channel. Someone suggested checking out https://github.com/pulumi/pulumi-awsx/issues/972 which is similar but didn't work for me.
I think I am in similar situation where I create a aws resource and would like to pass it back as state property for my larger construct and be able to access that resources properties in the client code without passing each property and having to define each one in schema.json. With the ref to the type in schema.json I can see in sdk that the typescript object is "aws:s3/bucket:Bucket" but the actual staticPage.bucket doesn't contain a bucket object it contains a string with bucket's ID. At the end of static page in provider it registers the output.
this.registerOutputs({
bucket,
websiteUrl: bucket.websiteEndpoint,
});
I would expect what the intent here was to register the output bucket as a whole and it's properties not simply the bucketId.
Using the original posters example though I thought you would have to do something similar to the following on the client side because arn wouldn't exist on bucket as bucket is an output. This is the case though b is resolving to a string, the id.
export const bucketArn = page.bucket.apply(b => b.arn);
How should I change the registerOutputs to achieve the above. I tried the following after reading this but it still shows arn doesn't exist on b cause b is a string.
this.registerOutputs({
bucket,
arn: bucket.arn,
websiteUrl: bucket.websiteEndpoint,
});
Looking again, if state.bucket is just going to return a string, id, why set the ref in schema.json.
urn: staticPage.urn,
state: {
bucket: staticPage.bucket,
websiteUrl: staticPage.websiteUrl,
},
};
schema.json
"properties": {
"bucket": {
"$ref": "/aws/v4.0.0/schema.json#/resources/aws:s3%2Fbucket:Bucket",
"description": "The bucket resource."
},
"websiteUrl": {
"type": "string",
"description": "The website URL."
}
},
In this example why are they even doing websiteUrl in schema.json it redundant they have already declared bucket is /aws/v4.0.0/schema.json#/resources/aws:s3%2Fbucket:Bucket then they are defining the string websiteUrl which is property of bucket and equates to the following with more clarity
provider.ts
return {
urn: staticPage.urn,
state: {
bucketId: staticPage.bucket, // here staticPage.bucket is resolving the output to a Id
websiteUrl: staticPage.websiteUrl,
},
};
schema.json
"properties": {
"bucketId": {
"type": "string",
"description": "The bucket resource."
},
"websiteUrl": {
"type": "string",
"description": "The website URL."
}
},
Just really excited to understand so forgive my super long post.
What happened?
I've modified the example project to export the bucket id as output, but pulumi fails to get the bucket.id property.
Steps to reproduce
Just add a line to export the bucketId:
Expected Behavior
The
page.bucket.id
is exported in thebucketId
constant.Actual Behavior
Pulumi fails with the following error:
Output of
pulumi about
Additional context
No response
Contributing
Vote on this issue by adding a đ reaction. To contribute a fix for this issue, leave a comment (and link to your pull request, if you've opened one already).