Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(core): stack.exportValue() does not work with ref parameters #13002

Closed
juanqui opened this issue Feb 12, 2021 · 4 comments · Fixed by #13052
Closed

(core): stack.exportValue() does not work with ref parameters #13002

juanqui opened this issue Feb 12, 2021 · 4 comments · Fixed by #13052
Assignees
Labels
@aws-cdk/core Related to core CDK functionality bug This issue is a bug. needs-triage This issue or PR still needs to be triaged.

Comments

@juanqui
Copy link

juanqui commented Feb 12, 2021

The new stack.exportValue() feature introduced in #12778 does not seem to work with resource parameters that would be referenced by Ref rather than GetAtt.

Reproduction Steps

const someSampleRole = new iam.Role(this, 'SomeSampleRole', {});
this.exportValue(someSampleRole.roleName);

Results in: Error: exportValue: either supply 'name' or make sure to export a resource attribute (like 'bucket.bucketName')

What did you expect to happen?

Trying to break a deadly embrace where I used the roleName and roleArn in another stack. The roleArn is a GetAtt and the roleName is actually a Ref. The roleArn worked great, but roleName will not synthesize without me specifying the full export name which looks something like STACK_NAME:ExportsOutputRefSomeSampleRole1D3A83A01C1B4250.

What actually happened?

Error: Error: exportValue: either supply 'name' or make sure to export a resource attribute (like 'bucket.bucketName')

Environment

  • CDK CLI Version : 1.88.0
  • Framework Version: 1.88.0
  • Node.js Version: v10.23.2
  • OS : Amazon Linux 2
  • Language (Version): TypeScript (3.8.3)

Other

N/A


This is 🐛 Bug Report

@juanqui juanqui added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Feb 12, 2021
@github-actions github-actions bot added the @aws-cdk/core Related to core CDK functionality label Feb 12, 2021
@skinny85
Copy link
Contributor

Confirming I was able to reproduce it, using an @aws-cdk/aws-s3 Bucket's bucketName attribute, which fails with this pretty ironic message:

exportValue: either supply 'name' or make sure to export a resource attribute (like 'bucket.bucketName')

@skinny85
Copy link
Contributor

Actually, same error happens when trying to use bucketArn.

@rix0rrr
Copy link
Contributor

rix0rrr commented Feb 15, 2021

Cool. It's the physicalName system that's messing us up here, which is wrapping the Reference token in a Lazy 😡

rix0rrr added a commit that referenced this issue Feb 15, 2021
Most L2 resources employ the "PhysicalName" protocol, which checks usage of
resource names across environment borders, and can automatically turn
auto-named resources into physically-named resources if the situation calls for
it.

Unfortunately, this wrapped token is a generic IResolvable, not a Reference,
and so did not work with the `exportValue()` automatic reference detection.

Make the token returned by `getResourceNameAttribute()` etc. a `Reference`
that mimics the underlying `Reference` to make this work out.

Fixes #13002, fixes #12918.
@mergify mergify bot closed this as completed in #13052 Feb 16, 2021
mergify bot pushed a commit that referenced this issue Feb 16, 2021
Most L2 resources employ the "PhysicalName" protocol, which checks usage of
resource names across environment borders, and can automatically turn
auto-named resources into physically-named resources if the situation calls for
it.

Unfortunately, this wrapped token is a generic IResolvable, not a Reference,
and so did not work with the `exportValue()` automatic reference detection.

Make the token returned by `getResourceNameAttribute()` etc. a `Reference`
that mimics the underlying `Reference` to make this work out.

Fixes #13002, fixes #12918.


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

NovakGu pushed a commit to NovakGu/aws-cdk that referenced this issue Feb 18, 2021
Most L2 resources employ the "PhysicalName" protocol, which checks usage of
resource names across environment borders, and can automatically turn
auto-named resources into physically-named resources if the situation calls for
it.

Unfortunately, this wrapped token is a generic IResolvable, not a Reference,
and so did not work with the `exportValue()` automatic reference detection.

Make the token returned by `getResourceNameAttribute()` etc. a `Reference`
that mimics the underlying `Reference` to make this work out.

Fixes aws#13002, fixes aws#12918.


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
eladb pushed a commit that referenced this issue Feb 22, 2021
Most L2 resources employ the "PhysicalName" protocol, which checks usage of
resource names across environment borders, and can automatically turn
auto-named resources into physically-named resources if the situation calls for
it.

Unfortunately, this wrapped token is a generic IResolvable, not a Reference,
and so did not work with the `exportValue()` automatic reference detection.

Make the token returned by `getResourceNameAttribute()` etc. a `Reference`
that mimics the underlying `Reference` to make this work out.

Fixes #13002, fixes #12918.


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/core Related to core CDK functionality bug This issue is a bug. needs-triage This issue or PR still needs to be triaged.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants