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

Detect ENV vars in YAML stack config and set them for command execution. Make workspace_key_prefix config DRY #77

Merged
merged 8 commits into from Nov 12, 2021

Conversation

aknysh
Copy link
Member

@aknysh aknysh commented Nov 12, 2021

what

  • Detect ENV vars in YAML stack config and set them for command execution
  • Make workspace_key_prefix config DRY
  • Don't delete the generated terraform varfiles after each command
  • Update tests
  • General cleanup

why

  • Detect ENV vars in YAML stack config and set them for command execution - allow specifying ENV vars in YAML config files. For each component in a stack, ENV vars are deep-merged in this order: global ENV vars, terraform section ENV vars, base component ENV vars, component ENV vars. The when commands are executed, print the final set of ENV vars and set them in the executing shell. This will allow controlling the tools behavior (e.g. Terraform, helmfile) by YAML configs
Command info:
Terraform binary: /usr/local/bin/terraform
Terraform command: plan
Arguments and flags: []
Component: test/test-component-override
Base component: test/test-component
Stack: tenant1/ue2/dev
Working dir: ./examples/complete/components/terraform/test/test-component

Using ENV vars:
TEST_ENV_VAR3=val3-override
TEST_ENV_VAR1=val1-override
TEST_ENV_VAR2=val2
TEST_ENV_VAR4=val4

Executing command:
/usr/local/bin/terraform workspace select tenant1-ue2-dev-test-component-override

Executing command:
/usr/local/bin/terraform plan -var-file tenant1-ue2-dev-test-component-override.terraform.tfvars.json -out tenant1-ue2-dev-test-component-override.planfile
  • Check if backend section has workspace_key_prefix for s3 backend type. If it does not, use the component name instead. It also propagates to remote_state_backend section of s3 type. This will allow to have components catalog files DRY without repeating the same config (which now can be generated automatically by the component names). Components folders are supported and taken into account in the generated workspace_key_prefix. This can be overridden as before per component.

This config

components:
  terraform:
    "test/test-component":
      backend:
        s3:
          workspace_key_prefix: test-test-component
      settings:
        spacelift:
          workspace_enabled: true

is now the same as this

components:
  terraform:
    "test/test-component":
      settings:
        spacelift:
          workspace_enabled: true

and produces the same result (confirmed by the updated tests)

backend:
  workspace_key_prefix: test-test-component
backend_type: s3
remote_state_backend:
  workspace_key_prefix: test-test-component
remote_state_backend_type: s3
  • Don't delete the generated terraform varfiles after each command - sometimes it's useful to be able to run atmos terraform plan and then use the generated varfile and planfile in other terraform commands. The varfile and planfile can be deleted by now supported command tmos terraform clean <component> -s <stack>

@aknysh aknysh added the patch A minor, backward compatible change label Nov 12, 2021
@aknysh aknysh requested review from osterman and Nuru November 12, 2021 13:45
@aknysh aknysh self-assigned this Nov 12, 2021
@aknysh aknysh requested review from a team as code owners November 12, 2021 13:45
@aknysh aknysh changed the title Detect ENV vars in YAML stack config and set them for command execution. Make workspace_key_prefix config DRY Detect ENV vars in YAML stack config and set them for command execution. Make workspace_key_prefix config DRY Nov 12, 2021
@aknysh aknysh merged commit 84e9fd0 into master Nov 12, 2021
@aknysh aknysh deleted the dry-up-backend-section branch November 12, 2021 14:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
patch A minor, backward compatible change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants