11name : " Deploy - Test"
22
3- run-name : " ${{ github.event. inputs.git_ref }}"
3+ run-name : " ${{ inputs.git_ref }}"
44
55on :
66 workflow_dispatch :
@@ -16,54 +16,46 @@ permissions:
1616 contents : read # This is required for actions/checkout
1717
1818jobs :
19- terraform_plan_apply :
20- name : Terraform Plan/Apply (ndr-test )
19+ terraform_plan_apply_base_iam :
20+ name : Terraform Plan/Apply (base_iam )
2121 runs-on : ubuntu-latest
2222 environment : test
2323 steps :
24- - name : Checkout
24+ - name : Checkout branch
2525 uses : actions/checkout@v6
2626 with :
27- ref : ${{ github.event. inputs.git_ref}}
27+ ref : ${{ inputs.git_ref}}
2828
29- - name : Configure AWS Credentials
30- uses : aws- actions/configure-aws-credentials@v6
29+ - name : Apply base_iam
30+ uses : ./.github/ actions/tf-plan-apply
3131 with :
32- role-to-assume : ${{ secrets.AWS_ASSUME_ROLE }}
33- role-skip-session-tagging : true
34- aws-region : ${{ vars.AWS_REGION }}
35- mask-aws-account-id : true
32+ aws_assume_role : arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/test-github-bootstrap
33+ bucket_prefix : " test"
34+ aws_account_id : ${{ secrets.AWS_ACCOUNT_ID }}
35+ aws_region : ${{ vars.AWS_REGION }}
36+ working_directory : " ./base_iam" # Use separate base_iam directory
37+ workspace : ${{ secrets.AWS_WORKSPACE }}
38+ tf_vars_file : ${{ vars.TF_VARS_FILE }}
39+ tf_extra_args : " -var aws_account_id=${{ secrets.AWS_ACCOUNT_ID }}"
3640
37- # Install the latest version of Terraform CLI and configure the Terraform CLI configuration file with a Terraform Cloud user API token
38- - name : Setup Terraform
39- uses : hashicorp/setup-terraform@v4
41+ terraform_plan_apply :
42+ name : Terraform Plan/Apply (ndr-test)
43+ runs-on : ubuntu-latest
44+ needs : terraform_plan_apply_base_iam
45+ environment : test
46+ steps :
47+ - name : Checkout main
48+ uses : actions/checkout@v6
4049 with :
41- terraform_version : 1.14.6
42- terraform_wrapper : false
43-
44- - name : Initialise Terraform
45- id : init
46- run : terraform init -backend-config=backend-test.conf
47- working-directory : ./infrastructure
48- shell : bash
49-
50- - name : Select Terraform Workspace
51- id : workspace
52- run : terraform workspace select -or-create ${{ secrets.AWS_WORKSPACE }}
53- working-directory : ./infrastructure
54- shell : bash
55-
56- - name : Check Terraform Formatting
57- run : terraform fmt -check
58- working-directory : ./infrastructure
59-
60- - name : Run Terraform Plan
61- id : plan
62- run : |
63- terraform plan -input=false -no-color -var-file="${{vars.TF_VARS_FILE}}" -out tf.plan
64- working-directory : ./infrastructure
65- shell : bash
50+ ref : ${{ github.event.inputs.git_ref}}
6651
67- - name : Run Terraform Apply
68- run : terraform apply -auto-approve -input=false tf.plan
69- working-directory : ./infrastructure
52+ - name : Apply Main
53+ uses : ./.github/actions/tf-plan-apply
54+ with :
55+ # use newly created role
56+ aws_assume_role : arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/${{ secrets.AWS_WORKSPACE }}-github-actions-role
57+ bucket_prefix : " test"
58+ aws_account_id : ${{ secrets.AWS_ACCOUNT_ID }}
59+ aws_region : ${{ vars.AWS_REGION }}
60+ workspace : ${{ secrets.AWS_WORKSPACE }}
61+ tf_vars_file : ${{ vars.TF_VARS_FILE }}
0 commit comments