-
Notifications
You must be signed in to change notification settings - Fork 27
101 lines (83 loc) · 3.11 KB
/
terraform-aws-ec2-4.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
name: "Terraform Pipeline Provision EC2"
on:
push:
branches: ['master' , 'main']
pull_request:
branches: ['master', 'main']
permissions:
contents: write
env:
# verbosity setting for Terraform log
TF_LOG: INFO
# Credentials for deployment to AWS
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
TF_CLOUD_ORGANIZATION: "prodxcloud"
TF_WORKSPACE: "prodxcloud"
TF_API_TOKEN: ${{ secrets.TF_API_TOKEN}}
CONFIG_DIRECTORY: "./deployments/terraform/terraform-aws-ec2-tf/terraform/"
jobs:
terraform:
name: "Terraform Pipeline Provision EC2 with S3 Bucket"
runs-on: ubuntu-latest
defaults:
run:
shell: bash
# We keep Terraform files in the terraform directory.
working-directory: ./deployments/terraform/terraform-aws-ec2-tf/terraform
steps:
- name: Checkout the repository to the runner
uses: actions/checkout@v2
- name: Setup Terraform with specified version on the runner
uses: hashicorp/setup-terraform@v2
with:
terraform_version: 1.3.0
- name: Terraform init
id: init
run: terraform init -lock=false
# env:
# TF_CLI_ARGS_init: '-backend-config="token=${{ secrets.TF_API_TOKEN }}"'
- name: Terraform format
id: fmt
run: terraform fmt
- name: Terraform validate
id: validate
run: terraform validate
env:
GITHUB_TOKEN: ${{ secrets.G_TOKEN}}
TFE_TOKEN: ${{ secrets.TF_API_TOKEN }}
# - uses: actions/github-script@v6
# # if: github.event_name == 'pull_request'
# env:
# PLAN: "terraform\n${{ steps.plan.outputs.stdout }}"
# with:
# script: |
# const output = `#### Terraform Format and Style 🖌\`${{ steps.fmt.outcome }}\`
# #### Terraform Initialization ⚙️\`${{ steps.init.outcome }}\`
# #### Terraform Validation 🤖\`${{ steps.validate.outcome }}\`
# #### Terraform Plan 📖\`${{ steps.plan.outcome }}\`
# <details><summary>Show Plan</summary>
# \`\`\`\n
# ${process.env.PLAN}
# \`\`\`
# </details>
# *Pushed by: @${{ github.actor }}, Action: \`${{ github.event_name }}\`*`;
# github.rest.issues.createComment({
# issue_number: context.issue.number,
# owner: context.repo.owner,
# repo: context.repo.repo,
# body: output
# })
# - name: Terraform Plan Status
# if: steps.plan.outcome == 'failure'
# run: exit 1
- name: Terraform Apply
# if: github.ref == 'refs/heads/master' && github.event_name == 'push'
run: terraform apply -auto-approve -input=false -lock=false
# env:
# TFE_TOKEN: ${{ secrets.TF_API_TOKEN }}
# - name: Terraform Destroy All Resources
# # if: github.ref == 'refs/heads/master' && github.event_name == 'push'
# run: terraform destroy -auto-approve -input=false -lock=false
# env:
# TFE_TOKEN: ${{ secrets.TF_API_TOKEN }}