-
Notifications
You must be signed in to change notification settings - Fork 85
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
Context provider for cross-account CFN stack outputs #226
Comments
Any news about that ? We are Stuck on our App migration without that feature and have to use Workarounds like a dirty I'm very surprised that an important feature like that is not native with CDK. |
Hi @eladb ! |
The best solution I can offer at this point is to use well-known physical names for resources in different accounts. If you assign the value |
Copying @skinny85 |
Hi @eladb and thanks for your reply. Not sure to understand how
Now, I want to create a R53 Record (targeting ApplicationLoadBalancerPrivate.loadBalancerDnsName) in Stack B but in another Account B. |
@Cloudrage you should be able to simply reference Something like this (sketch): const ENV1 = { account: '11111', region: 'us-east-1' };
const ENV2 = { account: '2222', region: 'eu-west-2' };
class ProducerStack extends Stack {
public readonly alb: ApplicationLoadBalancer;
constructor(scope: Construct, id: string) {
super(scope, id, { env: ENV1 });
this.alb = new elbv2.ApplicationLoadBalancer(this, 'ApplicationLoadBalancerPrivate', {
loadBalancerName: cdk.PhysicalName.GENERATE_IF_NEEDED,
});
}
}
interface ConsumerStackProps {
readonly alb: ApplicationLoadBalancer;
}
class ConsumerStack extends Stack {
constructor(scope: Construct, id: string, props: ConsumerStackProps) {
super(scope, id, { env: ENV2 });
new route53.ARecord(this, 'AliasRecord', {
zone,
target: route53.RecordTarget.fromAlias(new alias.LoadBalancerTarget(props.alb)),
});
}
}
const producer = new ProducerStack(app, 'producer');
const consumer = new ConsumerStack(app, 'consumer', {
alb: producer.alb
}); Let me know if this helps/works :-) |
Understood @eladb. But in your sketch : And is it possible to set PhysicalName and not use generated one ? I think it'll be a good alternative to be able to get Cross-Account Cfn Outputs with CDK (or SSM parameters maybe ?) |
It's supposed to be Yes you could just use any value for physical name. The nice thing about auto_generate is that if this resource is not referenced across environments, it will not use an explicit name. It will also generate a name that is unique for your app. But otherwise feel free to just assign any name. |
How to set up a physical name with class PhysicalName ?
It means that if I set up I've tested that workaround (with & without PhysicalName.GENERATE_IF_NEEDED) but it seems that I've made something wrong : |
@Cloudrage you're right. It turns out there's some logic missing from Do you mind creating us a bug for it in the main CDK repo? Thanks! |
Made it as you can see @skinny85 , thanks to you. To go back to the intial request, I think the best way is to provide a native solution to retrieve these outputs/references between Cross Account Stacks directly. |
Thanks @Cloudrage ! We will get those fixed. |
I also have a few use case.. one right now i am looking at when trying to delegate dns to a hostedZone in another account. |
Same for me, not found an easy and beautifful way to do that; again, the only workaround "viable" I've found is to use output-file. |
Duplicate #161 |
Hi there,
It'll be a must have to be able to retrieve Stacks outputs from Cloudformation cross-accounts natively with CDK.
Not using Exports, because they have some limitations :
Use Case
Try to imagine :
You can't simply do that with CDK.
This issue is the same with multiple resources created on another Account, like R53, IAM, EndpointServices...
Proposed Solution
Create a native "resolver" and an assume role feature like the "cdk-assume-role-plugin" (ok that last point is another feature request :p) !
I try to merge from Sceptre (Troposphere) to CDK but I have to admit that actually CDK can't cover & offer a full alternative.
For example, to cover that we use a resolver doing a simple describe (example) :
So, in the code we just have to put the Arn of the Role to assume on the Account A, the Name of the Stack & the Cfn Output; like that :
With CDK :
The Arn can for example be in cdk.json as variable and retrieved with a "tryGetContext".
Name of the Stack ? Easy with "stackName", like the "env" or "description".
The Output ? Easy again, created with the Stack with "CfnOutput".
Other
I've created a Custom solution to be able to do that with CDK :
Ok, but now, my code can't work from scratch if I want to build all my PRD environment for example; yes, I have of course errors because my output file is not created yet...
So what ? I have to hardcode the Arn of the Key to create my ASG Grant ? Don't even think about it
When a CMK is needed with some resources I've created, I've set the Alias Arn instead of the Key; that way, I can easily name it and set it in my code.
But CreateGrant need the Key Arn & it's not possible to bypass that.
Regards,
MG
This is a 🚀 Feature Request
The text was updated successfully, but these errors were encountered: