I am using CDKTF and python for a project where I am generating JSON output that will be interpreted by Terraform.
I have a use case where I need to send in multiple aliased AWS providers. I am able to specify a single provider to the stack by using the add_provider method but I cannot add a secondary aliased provider without using add_override.
Is there a way for me to do this without getting name conflicts in the keys where CDKTF gives an error that I am specifying the aws key twice.
Basically I am asking if there is a way for me to specify the key I use when specifying the keys in providers so that I get something like:
"providers": {
"aws": "aws.account-one",
"aws.two": "aws.account-two"
}
Kindly let me know if I am doing this wrong.
Thanks in advance.
With CDKTF you can specify multiple providers like this:
class MyStack extends TerraformStack {
constructor(scope: Construct, ns: string) {
super(scope, ns);
new AwsProvider(this, "aws", {
region: "eu-central-1",
});
const provider = new AwsProvider(this, "aws.two", {
region: "us-east-1",
alias: "aws.two",
});
// this cert is created in the us-central-1 region
// it defaults to the provider without an alias
new acm.AcmCertificate(this, "cert", {
domainName: "cdktf.com",
validationMethod: "DNS",
});
// this cert is created in the us-east-1 region
const cert = new acm.AcmCertificate(this, "cert", {
domainName: "example.com",
validationMethod: "DNS",
provider,
});
}
}
This is documented in the examples: https://github.com/hashicorp/terraform-cdk/blob/main/examples/typescript/aws-cloudfront-proxy/main.ts
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With