Create and configure subcommands using YAML #5
-
Problem:
Or I can do it in workflows which are a good escape hatch https://github.com/cloudposse/atmos#workflows Or I can use the deep merging from atmos to create my tfvars, the workspace name it generates, and the terraform backend it generates in json and run raw terraform from outside of atmos using choria-io appbuilder. 😄 Ref:
Here's an example using choria-io appbuilder and it has a pretty decent interface On macInstall brew install atmos yq
brew tap choria-io/tap
brew install choria-io/tap/appbuilder Setup mkdir -p ~/Library/Application\ Support/appbuilder/
ln -s $(which appbuilder) /usr/local/bin/atmos-sub
vim ~/Library/Application\ Support/appbuilder/atmos-sub-app.yaml See configuration below On geodesicInstall apt update && apt install -y atmos yq
wget https://github.com/choria-io/appbuilder/releases/download/v0.0.9/appbuilder-0.0.9-amd64.deb
dpkg -i appbuilder-0.0.9-amd64.deb
rm appbuilder-0.0.9-amd64.deb Setup mkdir -p /etc/appbuilder
ln -s $(which appbuilder) /usr/local/bin/atmos-sub
vim /etc/appbuilder/atmos-sub-app.yaml See configuration below Configurationname: atmos-sub
description: atmos
author: https://github.com/choria-io/appbuilder
type: parent
commands:
- name: terraform
description: terraform subcommands
type: parent
commands:
- name: plan
description: plan
arguments:
- name: component
description: Name of the component
required: true
flags:
- name: stack
description: Name of the stack
required: true
short: s
type: exec
script: |
set -x
ATMOS_STACK={{ .Flags.stack | escape }}
ATMOS_COMPONENT={{ .Arguments.component | escape }}
ATMOS_BASE_COMPONENT=$(atmos describe component $ATMOS_COMPONENT --stack=$ATMOS_STACK | yq .metadata.component)
# logic to get the correct terraform workspace
ATMOS_WORKSPACE=$(atmos describe component $ATMOS_COMPONENT --stack $ATMOS_STACK | yq .workspace)
# TODO: make the `rm -f` command safer by replacing it with a `find` and `-delete` command
# The following uses &&s so the command will not continue if a former command fails
atmos terraform generate backend $ATMOS_COMPONENT --stack $ATMOS_STACK \
&& atmos terraform generate varfile $ATMOS_COMPONENT --stack $ATMOS_STACK \
&& rm -f components/terraform/$ATMOS_BASE_COMPONENT/.terraform.lock.hcl \
&& terraform -chdir=components/terraform/$ATMOS_BASE_COMPONENT \
init -reconfigure -upgrade \
&& terraform -chdir=components/terraform/$ATMOS_BASE_COMPONENT \
workspace list \
&& terraform -chdir=components/terraform/$ATMOS_BASE_COMPONENT \
workspace select $ATMOS_WORKSPACE || terraform -chdir=components/terraform/$ATMOS_BASE_COMPONENT workspace new $ATMOS_WORKSPACE \
&& terraform -chdir=components/terraform/$ATMOS_BASE_COMPONENT \
plan -out=$ATMOS_WORKSPACE.planfile -var-file=$ATMOS_WORKSPACE.terraform.tfvars.json This command atmos-sub terraform plan aws-backup-common --stack mgmt-uw2-sandbox Would run the following atmos terraform generate backend aws-backup-common --stack mgmt-uw2-sandbox
terraform -chdir=components/terraform/aws-backup init -reconfigure -upgrade
terraform -chdir=components/terraform/aws-backup workspace list
terraform -chdir=components/terraform/aws-backup workspace select mgmt-uw2-sandbox-aws-backup-common || terraform -chdir=components/terraform/aws-backup workspace new mgmt-uw2-sandbox-aws-backup-common
atmos terraform generate backend aws-backup-common --stack mgmt-uw2-sandbox
atmos terraform generate varfile aws-backup-common --stack mgmt-uw2-sandbox
terraform -chdir=components/terraform/aws-backup plan -out=mgmt-uw2-sandbox-aws-backup-common.planfile -var-file=mgmt-uw2-sandbox-aws-backup-common.terraform.tfvars.json NOTE:
|
Beta Was this translation helpful? Give feedback.
Replies: 0 comments 2 replies
-
This PR cloudposse/atmos#168 should close this feature request but I have not played with the new feature yet. |
Beta Was this translation helpful? Give feedback.
This PR cloudposse/atmos#168 should close this feature request but I have not played with the new feature yet.