Reputation: 13
I am trying to add specific options to the cdktf terraform commands with python : Actually, I want to specify the environment that can contain: prod , dev , test when calling cdktf synth or deploy, so it will look like this: cdktf synth/deploy -environment "prod".
I was thinking of python argparse :
import argparse
class MyStack(TerraformStack):
def __init__(self, scope: Construct, id: str):
super().__init__(scope, id)
parser = argparse.ArgumentParser()
# Add the product and stage options
parser.add_argument('-environment', type=str, help='The environment name')
# Parse the command-line arguments
args = parser.parse_args()
# and then use the environment when calling aws resource
and I don't understand why cdktf can't parse these options in my main.py to be honest it's a lot of abstractions and a lack of documentation.
Thank you
Upvotes: 0
Views: 705
Reputation: 11
I don't think this will work. You're trying to pass arguments to the cdktf program which may or may not pass those extra args to the underlying program.
Something that would work is passing extra args as environment variables i.e. ENVIRONMENT="prod" cdktf synth/deploy
and modify your code to read these.
Another option is to use terraform variables and again pass them as environment variables as documented here: https://developer.hashicorp.com/terraform/cdktf/concepts/variables-and-outputs#passing-input-variables-to-cdktf
Upvotes: 1