forked from alonitac/INTPolybotServiceAWS
-
Notifications
You must be signed in to change notification settings - Fork 0
112 lines (99 loc) · 3.59 KB
/
Copy pathinfra-provisioning-region.yaml
File metadata and controls
112 lines (99 loc) · 3.59 KB
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
102
103
104
105
106
107
108
109
110
111
112
name: Infrastructure Terraform Specific Region
on:
workflow_call:
inputs:
region-code:
required: true
type: string
default: us-east-1
country:
required: true
type: string
state:
required: true
type: string
locality:
required: true
type: string
organization:
required: true
type: string
common_name:
required: true
type: string
environment:
required: true
type: string
default: prod
secrets:
AWS_ACCESS_KEY_ID:
required: true
AWS_SECRET_ACCESS_KEY:
required: true
TELEGRAM_TOKEN:
required: true
jobs:
Terraform:
runs-on: ubuntu-latest
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
OUTPUTS_ARTIFACT_NAME: ${{ inputs.region-code }}-${{ inputs.environment }}-tf-outputs.json
defaults:
run:
working-directory: ./tf_infra
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Setup terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: 1.9.2
- name: Terraform init
run: terraform init
- name: Terraform workspace select
run: terraform workspace select ${{ inputs.region-code }} || terraform workspace new ${{ inputs.region-code }}
- name: Terraform validate
run: terraform validate
# - name: Unlock Terraform
# run: terraform force-unlock -force a3be03e3-b1d3-1ea3-31da-5e8fab8e958d
- name: Terraform plan
run: |
terraform plan \
-var-file=region.${{ inputs.region-code }}.tfvars \
-var "env=${{ inputs.environment }}" \
-var "region=${{ inputs.region-code }}" \
-var "telegram_token_value=${{ secrets.TELEGRAM_TOKEN }}" \
-var "country=${{ inputs.country }}" \
-var "state=${{ inputs.state }}" \
-var "locality=${{ inputs.locality }}" \
-var "organization=${{ inputs.organization }}" \
-var "common_name=${{ inputs.common_name }}" \
-out region.${{ inputs.region-code }}.${{ inputs.environment }}.tfplan
- name: Provision infrastructure
run: terraform apply -auto-approve region.${{ inputs.region-code }}.${{ inputs.environment }}.tfplan
- name: Get terraform output
id: output
run: |
echo "PEM_FILE_PATH=$(terraform output -raw pem_file_path)" >> $GITHUB_ENV
echo "PUB_FILE_PATH=$(terraform output -raw pub_file_path)" >> $GITHUB_ENV
echo "FILE_NAME=$(terraform output -raw key_pair_name)" >> $GITHUB_ENV
terraform output -json > ${{ github.workspace }}/${{ env.OUTPUTS_ARTIFACT_NAME }}
- name: Upload private key as artifact
uses: actions/upload-artifact@v4
with:
name: "${{ inputs.region-code }}-${{ inputs.environment }}-${{ env.FILE_NAME }}.pem"
path: "${{ env.PEM_FILE_PATH }}"
retention-days: 5
- name: Upload public key as artifact
uses: actions/upload-artifact@v4
with:
name: "${{ inputs.region-code }}-${{ inputs.environment }}-${{ env.FILE_NAME }}.pub"
path: "${{ env.PUB_FILE_PATH }}"
retention-days: 5
- name: Upload terraform outputs as artifact
uses: actions/upload-artifact@v4
with:
name: "${{ env.OUTPUTS_ARTIFACT_NAME }}"
path: "${{ github.workspace }}/${{ env.OUTPUTS_ARTIFACT_NAME }}"
retention-days: 5