1
+ # This workflow installs the latest version of Terraform CLI and configures the Terraform CLI configuration file
2
+ # with an API token for Terraform Cloud (app.terraform.io). On pull request events, this workflow will run
3
+ # `terraform init`, `terraform fmt`, and `terraform plan` (speculative plan via Terraform Cloud). On push events
4
+ # to the main branch, `terraform apply` will be executed.
5
+ #
6
+ # Documentation for `hashicorp/setup-terraform` is located here: https://github.com/hashicorp/setup-terraform
7
+ #
8
+ # To use this workflow, you will need to complete the following setup steps.
9
+ #
10
+ # 1. Create a `main.tf` file in the root of this repository with the `remote` backend and one or more resources defined.
11
+ # Example `main.tf`:
12
+ # # The configuration for the `remote` backend.
13
+ # terraform {
14
+ # backend "remote" {
15
+ # # The name of your Terraform Cloud organization.
16
+ # organization = "example-organization"
17
+ #
18
+ # # The name of the Terraform Cloud workspace to store Terraform state files in.
19
+ # workspaces {
20
+ # name = "example-workspace"
21
+ # }
22
+ # }
23
+ # }
24
+ #
25
+ # # An example resource that does nothing.
26
+ # resource "null_resource" "example" {
27
+ # triggers = {
28
+ # value = "A example resource that does nothing!"
29
+ # }
30
+ # }
31
+ #
32
+ #
33
+ # 2. Generate a Terraform Cloud user API token and store it as a GitHub secret (e.g. TF_API_TOKEN) on this repository.
34
+ # Documentation:
35
+ # - https://www.terraform.io/docs/cloud/users-teams-organizations/api-tokens.html
36
+ # - https://help.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets
37
+ #
38
+ # 3. Reference the GitHub secret in step using the `hashicorp/setup-terraform` GitHub Action.
39
+ # Example:
40
+ # - name: Setup Terraform
41
+ # uses: hashicorp/setup-terraform@v1
42
+ # with:
43
+ # cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }}
44
+
45
+ name : ' Terraform'
46
+
47
+ on :
48
+ push :
49
+ branches :
50
+ - main
51
+ pull_request :
52
+
53
+ jobs :
54
+ terraform :
55
+ name : ' Terraform'
56
+ runs-on : ubuntu-latest
57
+ environment : production
58
+ env :
59
+ ARM_CLIENT_ID : ${{ secrets.AZURE_AD_CIENT_ID }}
60
+ ARM_CLIENT_SECRET : ${{ secrets.AZURE_AD_CLIENT_SECRET }}
61
+ ARM_SUBSCRIPTION_ID : ${{ secrets.AZURE_AD_SUBSCRIPTION_ID }}
62
+ ARM_TENANT_ID : ${{ secrets.AZURE_AD_TENANT_ID }}
63
+ TF_VAR_CERTIFICATE : ${{ secrets.PRIMARY_APP_ID_CERT }}
64
+ AWS_DEFAULT_REGION : " us-east-1"
65
+ AWS_ACCESS_KEY_ID : ${{ secrets.S3_ACCESS_KEY_ID }}
66
+ AWS_SECRET_ACCESS_KEY : ${{ secrets.S3_SECRET_ACCESS_KEY }}
67
+
68
+ # Use the Bash shell regardless whether the GitHub Actions runner is ubuntu-latest, macos-latest, or windows-latest
69
+ defaults :
70
+ run :
71
+ shell : bash
72
+
73
+ steps :
74
+ - name : Checkout
75
+ uses : actions/checkout@v2
76
+
77
+ - name : Setup Terraform
78
+ uses : hashicorp/setup-terraform@v1
79
+ with :
80
+ # terraform_version: 0.13.0:
81
+ cli_config_credentials_token : ${{ secrets.TF_API_TOKEN }}
82
+
83
+ - name : Terraform Format
84
+ id : fmt
85
+ run : terraform -chdir=scripts fmt -check
86
+
87
+ - name : Terraform Init
88
+ id : init
89
+ run : terraform -chdir=scripts init
90
+
91
+ - name : Terraform Validate
92
+ id : validate
93
+ run : terraform -chdir=scripts validate -no-color
94
+
95
+ - name : Terraform Plan
96
+ id : plan
97
+ if : github.event_name == 'pull_request'
98
+ run : terraform -chdir=scripts plan -no-color -var "resourcesuffix=dev" -var "backend_account_key=${{ secrets.TF_BACKEND_KEY }}"
99
+
100
+
101
+ - name : Taint the connector instance
102
+ if : github.ref == 'refs/heads/main' && github.event_name == 'push'
103
+ run : terraform -chdir=scripts taint azurerm_container_group.connector-instance
104
+ continue-on-error : true
105
+
106
+ - name : Terraform Apply
107
+ if : github.ref == 'refs/heads/main' && github.event_name == 'push'
108
+ run : terraform -chdir=scripts apply -var "resourcesuffix=dev" -var "backend_account_key=${{ secrets.TF_BACKEND_KEY }}" -auto-approve
0 commit comments