Skip to content

Commit 4d5e43d

Browse files
authored
Merge pull request #48 from bitovi/feature/bitops-env-vars
Bypass BITOPS_ extra ENV vars to Docker run
2 parents 147caaa + b2c0ede commit 4d5e43d

File tree

7 files changed

+46
-58
lines changed

7 files changed

+46
-58
lines changed

README.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,30 @@ For some specific resources, we have a `32` characters limit. If the identifier
9797
Bucket names can be made of up to 63 characters. If the length allows us to add `-tf-state`, we will do so. If not, a simple `-tf` will be added.
9898

9999
## Made with BitOps
100-
[BitOps](https://bitops.sh/) allows you to define Infrastructure-as-Code for multiple tools in a central place. This action uses BitOps [Operations Repository Structure](https://bitops.sh/operations-repo-structure/) to organize the necessary Terraform and Ansible steps, create infrastructure and deploy to it.
100+
[BitOps](https://bitops.sh/) allows you to define Infrastructure-as-Code for multiple tools in a central place. This action uses BitOps Docker container with prebuilt deployment tools and [Operations Repository Structure](https://bitops.sh/operations-repo-structure/) to organize the necessary Terraform and Ansible steps, create infrastructure and deploy to it.
101+
102+
### Extra BitOps Configuration
103+
You can pass additional `BITOPS_` ENV variables to adjust the deployment behavior.
104+
```yaml
105+
- name: Deploy StackStorm to AWS (dry-run)
106+
uses: bitovi/github-actions-deploy-stackstorm@main
107+
env:
108+
# Extra BitOps configuration:
109+
BITOPS_LOGGING_LEVEL: INFO
110+
# Extra Terraform configuration:
111+
# https://bitops.sh/tool-configuration/configuration-terraform/#terraform-bitops-schema
112+
BITOPS_TERRAFORM_SKIP_DEPLOY: true
113+
# Extra Ansible configuration:
114+
# https://bitops.sh/tool-configuration/configuration-ansible/#cli-configuration
115+
BITOPS_ANSIBLE_DRYRUN: true
116+
with:
117+
aws_default_region: us-east-1
118+
aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }}
119+
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
120+
st2_auth_username: ${{ secrets.ST2_AUTH_USERNAME }}
121+
st2_auth_password: ${{ secrets.ST2_AUTH_PASSWORD}}
122+
```
123+
In this example, we instruct BitOps to run a `terraform plan` instead of `terraform apply` and to run Ansible in `--check` mode, additionally, we set the BitOps container logging level to `DEBUG`.
101124

102125
## Future
103126
In the future, this action may support more cloud providers (via [BitOps Plugins](https://bitops.sh/plugins/) like [AWS](https://github.com/bitops-plugins/aws)) such as:

action.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,6 @@ runs:
9696
# Skip ansible deployment if deploying only infrastructure
9797
ANSIBLE_SKIP_DEPLOY: ${{ inputs.infrastructure_only }}
9898

99-
BITOPS_FAST_FAIL: "true"
100-
10199
# ST2 config
102100
ST2_AUTH_USERNAME: ${{ inputs.st2_auth_username }}
103101
ST2_AUTH_PASSWORD: ${{ inputs.st2_auth_password }}

operations/_scripts/deploy/deploy.sh

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,46 +29,39 @@ export LB_LOGS_BUCKET="$(/bin/bash $GITHUB_ACTION_PATH/operations/_scripts/gener
2929
# Generate app repo
3030
/bin/bash $GITHUB_ACTION_PATH/operations/_scripts/generate/generate_app_repo.sh
3131

32-
# Generate bitops config
33-
/bin/bash $GITHUB_ACTION_PATH/operations/_scripts/generate/generate_bitops_config.sh
34-
3532
# Generate `00_acm_create`
3633
if [[ "$CREATE_DOMAIN" == "true" ]]; then
3734
/bin/bash $GITHUB_ACTION_PATH/operations/_scripts/generate/generate_acm_tf.sh
3835
fi
3936

40-
TERRAFORM_COMMAND=""
41-
TERRAFORM_DESTROY=""
4237
if [ "$STACK_DESTROY" == "true" ]; then
43-
TERRAFORM_COMMAND="destroy"
44-
TERRAFORM_DESTROY="true"
45-
ANSIBLE_SKIP_DEPLOY="true"
38+
export BITOPS_TERRAFORM_STACK_ACTION="destroy"
39+
export BITOPS_ANSIBLE_SKIP_DEPLOY="true"
4640
fi
4741

4842
if [[ "$GHA_TESTING" == "true" ]]; then
4943
echo "Quitting before BitOps invoke"
5044
exit 1
5145
fi
5246

47+
# Bypass all the 'BITOPS_' ENV vars to docker
48+
DOCKER_EXTRA_ARGS=""
49+
for i in $(env | grep BITOPS_); do
50+
DOCKER_EXTRA_ARGS="${DOCKER_EXTRA_ARGS} -e ${i}"
51+
done
52+
5353
echo "Running BitOps for env: $BITOPS_ENVIRONMENT"
5454
docker run --rm --name bitops \
5555
-e AWS_ACCESS_KEY_ID="${AWS_ACCESS_KEY_ID}" \
5656
-e AWS_SECRET_ACCESS_KEY="${AWS_SECRET_ACCESS_KEY}" \
5757
-e AWS_SESSION_TOKEN="${AWS_SESSION_TOKEN}" \
5858
-e AWS_DEFAULT_REGION="${AWS_DEFAULT_REGION}" \
59-
-e BITOPS_ENVIRONMENT="${BITOPS_ENVIRONMENT}" \
60-
-e SKIP_DEPLOY_TERRAFORM="${SKIP_DEPLOY_TERRAFORM}" \
61-
-e SKIP_DEPLOY_HELM="${SKIP_DEPLOY_HELM}" \
62-
-e BITOPS_TERRAFORM_COMMAND="${TERRAFORM_COMMAND}" \
63-
-e TERRAFORM_DESTROY="${TERRAFORM_DESTROY}" \
64-
-e ANSIBLE_SKIP_DEPLOY="${ANSIBLE_SKIP_DEPLOY}" \
6559
-e TF_STATE_BUCKET="${TF_STATE_BUCKET}" \
6660
-e TF_STATE_BUCKET_DESTROY="${TF_STATE_BUCKET_DESTROY}" \
67-
-e DEFAULT_FOLDER_NAME="_default" \
6861
-e CREATE_VPC="${CREATE_VPC}" \
69-
-e BITOPS_FAST_FAIL="${BITOPS_FAST_FAIL}" \
7062
-e ST2_AUTH_USERNAME="${ST2_AUTH_USERNAME}" \
7163
-e ST2_AUTH_PASSWORD="${ST2_AUTH_PASSWORD}" \
7264
-e ST2_PACKS="${ST2_PACKS}" \
65+
${DOCKER_EXTRA_ARGS} \
7366
-v $(echo $GITHUB_ACTION_PATH)/operations:/opt/bitops_deployment \
74-
bitovi/bitops:2.3.0
67+
bitovi/bitops:2.4.0

operations/_scripts/generate/generate_bitops_config.sh

Lines changed: 0 additions & 23 deletions
This file was deleted.
Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1+
# https://github.com/bitops-plugins/ansible
12
ansible:
2-
cli:
3-
main-playbook: playbook.yml
4-
# todo: (currently handled via vars/st2.yaml)
5-
# extra-vars: "@extra-vars.yaml"
6-
options:
7-
dryrun: false
3+
cli:
4+
main-playbook: playbook.yml
5+
options: {}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#!/bin/bash
22

3-
if [[ $TERRAFORM_DESTROY = true ]] && [[ $TF_STATE_BUCKET_DESTROY = true ]]; then
3+
if [[ $TERRAFORM_COMMAND = "destroy" ]] && [[ $TF_STATE_BUCKET_DESTROY = true ]]; then
44
echo "Destroying S3 buket --> $TF_STATE_BUCKET"
55
aws s3 rb s3://$TF_STATE_BUCKET --force
6-
else
7-
if [[ $TERRAFORM_DESTROY != true ]] && [[ $TF_STATE_BUCKET_DESTROY = true ]]; then
8-
echo "TF_STATE_BUCKET_DESTROY set to true, but TERRAFORM_DESTROY wasn't. Not destroying the state bucket ($TF_STATE_BUCKET)"
6+
else
7+
if [[ $TERRAFORM_COMMAND != "destroy" ]] && [[ $TF_STATE_BUCKET_DESTROY = true ]]; then
8+
echo "TF_STATE_BUCKET_DESTROY set to true, but Terraform action wasn't 'destroy'. Not destroying the state bucket ($TF_STATE_BUCKET)"
99
fi
1010
fi
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
1+
# https://github.com/bitops-plugins/terraform
22
terraform:
3-
cli:
4-
stack-action: apply
5-
options: {}
6-
3+
cli:
4+
stack-action: apply
5+
options: {}

0 commit comments

Comments
 (0)