Skip to content
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

Stack-action vs. action variables (TERRAFORM_APPLY | DESTROY) #14

Open
LeoDiazL opened this issue Nov 4, 2022 · 5 comments
Open

Stack-action vs. action variables (TERRAFORM_APPLY | DESTROY) #14

LeoDiazL opened this issue Nov 4, 2022 · 5 comments
Labels
bug Something isn't working enhancement New feature or request

Comments

@LeoDiazL
Copy link
Contributor

LeoDiazL commented Nov 4, 2022

As it is right now, you can define a stack-action and yet pass TERRAFORM_APPLY / TERRAFORM_DESTROY as an environment variable. Hence, you could create the environment and destroy it in the same run.

The idea would be to:

  • Sanitize options. Make sure only one of them is chosen. (What should we do if stack-action collides with TERRAFORM_* ?)
  • Run through a case statement, avoiding unnecessary validations and keeping the code cleaner.
  • Print warning for the environment variables we want to remove in the future ( if we want to. 😄 )
@PhillypHenning
Copy link
Contributor

Keep variables
If we keep the variables as override then we should update them to use a _OVERRIDE postfix

Remove variables
If we remove the variables, it just locks the actions to only be set using the stack action which I think is a positive for keeping things standardized.

Additional considerations
Cloudformation
Cloudformation uses the stack-action however doesn't have an override.

if [[ "${CFN_STACK_ACTION}" == "deploy" ]] || [[ "${CFN_STACK_ACTION}" == "Deploy" ]]; then
  echo "Running Cloudformation Deploy Stack"
  bash $CLOUDFORMATION_ROOT_SCRIPTS/scripts/cloudformation_deploy.sh "$CFN_TEMPLATE_FILENAME" "$CFN_PARAMS_FLAG" "$CFN_TEMPLATE_PARAMS_FILENAME" "$CFN_STACK_NAME" "$CFN_CAPABILITY" "$CFN_TEMPLATE_S3_BUCKET" "$CFN_S3_PREFIX"
fi

if [[ "${CFN_STACK_ACTION}" == "delete" ]] || [[ "${CFN_STACK_ACTION}" == "Delete" ]]; then
  echo "Running Cloudformation Delete Stack"
  bash $CLOUDFORMATION_ROOT_SCRIPTS/scripts/cloudformation_delete.sh "$CFN_STACK_NAME"
fi

@PhillypHenning
Copy link
Contributor

My suggestion would be to use only stack-action, remove the terraform TERRAFORM_(APPLY|DESTORY) variables

@arm4b arm4b added the bug Something isn't working label Nov 7, 2022
@arm4b
Copy link
Member

arm4b commented Nov 8, 2022

Good find!

+1 to catching the corner cases + proper error reporting.
Eg. you can pass ENV_A, ENV_B, but not both and allow one action based on merged config + ENV results, but not both.

Also I think it's OK that the ENV variable overrides the setting coming from config.
For instance, in Ansible there's a level of precedence when evaluating CLI params, vs config vs ENV where the ENV value come as a highest priority and overrides everything else.

@arm4b arm4b added the enhancement New feature or request label Nov 8, 2022
@arm4b
Copy link
Member

arm4b commented Nov 8, 2022

I also understand that having an ENV var counterpart to the config setting is helpful when using BitOps in CI/CD and pipeline runners. This way ENV value could be changed on fly depending on context without relying on the whole config file.

@mickmcgrath13
Copy link
Contributor

My suggestion would be to use only stack-action, remove the terraform TERRAFORM_(APPLY|DESTORY) variables
this might be a breaking change (would at least need to be highlighted in migration docs for repos that are using those vars.

I agree with @armab that it's nice to be able to specify env vars in the pipeline config to drive behavior

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants