-
Notifications
You must be signed in to change notification settings - Fork 9
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
Should we implement Terraform code through AWS CDK? #4
Comments
Good idea! I think it makes for cleaner code and makes the actual intended configuration more readable. Can't think of any downsides |
I'd say the downside could be the following warning on their repo (not that that has stopped us before :P); However, it seems like an excellent way to replace the Jinja templates. For local modules you don't seem to get typing information :-( |
@davidweterings it's still alpha indeed, however aws seems to be pushing CDK quite hard and also collaborating with HashiCorp around terraform-cdk. But let's be careful indeed, before we depend on something that's not maintained anymore. Could you elaborate about the typing information on local modules? Perhaps we should consider supporting both CDK-generated TF JSON, as well as well as HCL-generated JSON? So users always have a fallback. I've tried it with our commercetools terraform provider. Seems pretty straightforward!
{
"language": "python",
"app": "python3 ./main.py",
"terraformProviders": [
"aws@~> 2.0",
"labd/commercetools"
],
"codeMakerOutput": "imports"
}
#!/usr/bin/env python
from constructs import Construct
from cdktf import App, TerraformStack
from imports.commercetools import CommercetoolsProvider, ProjectSettings
from imports.aws import AwsProvider
class MyStack(TerraformStack):
def __init__(self, scope: Construct, ns: str):
super().__init__(scope, ns)
AwsProvider(self, 'aws', region='eu-west-1')
CommercetoolsProvider(self,
"commercetools",
api_url="https://api.europe-west1.gcp.commercetools.com",
client_id="xxxx",
client_secret="xxxxx",
project_key="test-environment-pim",
scopes="manage_extensions:test-environment-pim manage_project_settings:test-environment-pim manage_subscriptions:test-environment-pim manage_api_clients:test-environment-pim manage_project:test-environment-pim manage_stores:test-environment-pim",
token_url="https://auth.europe-west1.gcp.commercetools.com",
)
ProjectSettings(self,
"settings",
countries=["NL", "IE"],
currencies=["EUR"],
languages=["nl", "en"],
messages= {
"enabled": "true",
},
name="Pims test environment",
)
app = App()
MyStack(app, "cdk-commercetools")
app.synth() |
One thing that crossed my mind is wether we would still be able to support terraform modules as components (with HCL code in them) when going down this route. |
I suppose when loading in a module (described in https://github.com/hashicorp/terraform-cdk/blob/master/docs/working-with-cdk-for-terraform/using-providers-and-modules.md#using-modules) it can be an old-fashioned Terraform configuration. |
Ah that seems absolutely usable! |
For reference, see #83 |
Currently we implement infrastructure-as-code through Terraform HCL, using Jinja2 templates to make them dynamic.
Does it make sense to change this to an 'only Python code' implementation, through the use of AWS CDK?
That supports terraform providers since a while:
Perhaps we can discuss pro's and con's?
The text was updated successfully, but these errors were encountered: