I normally write all of my Terraform manually in HCL. However, I have a complex setup for some of my infra that is cumbersome and hard to maintain with manual HCL. Ideally I could generate the Terraform into its own module and then consume it as such. CDKTF looks like a great solution, and it even says “CDKTF can generate modules that HCL Terraform projects can use in their configurations.” (HCL Interoperability | Terraform by HashiCorp)
I have a testing setup, but I am unable to fully make it work without manually modifying the output JSON. My infra needs the AWS provider, but it needs it in multiple regions. I accomplish this manually by setting configuration aliases, but I cannot find a way via CDKTF to do this. My output JSON looks like:
{
"//": {
"metadata": {
"backend": "local",
"stackName": "testing",
"version": "0.12.0"
},
"outputs": {}
},
"provider": {
"aws": [
{
"alias": "us-east-1",
"region": "us-east-1"
},
{
"alias": "us-east-2",
"region": "us-east-2"
}
]
},
"resource": {
"tgw-us-east-1": {
"< removed for shorter sample >": null,
"provider": "aws.us-east-1"
},
"tgw-us-east-2": {
"< removed for shorter sample >": null,
"provider": "aws.us-east-2"
}
}
},
"terraform": {
"backend": { "< removed for shorter sample >": null },
"required_providers": {
"aws": {
"source": "hashicorp/aws",
"version": "4.32.0"
}
}
}
}
To make it work as a module I have to:
- delete
.provider
- delete
.terraform.backend
- setup
.terraform.required_providers["aws"].configuration_aliases
with an array of aliases:["aws.us-east-1", "aws.us-east-2"]
Without those modifications I cannot use it properly as a module. Am I missing something when setting up my CDKTF code? Or when running synth? Ideally I would not have to take the steps mentioned above to make it work as a module.