forked from SummitRoute/aws_managed_policies
-
-
Notifications
You must be signed in to change notification settings - Fork 32
97 lines (84 loc) · 3.23 KB
/
main.yml
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
name: "[Prod] MAMIP - Infrastructure GitHub Actions"
on:
workflow_dispatch:
push:
tags-ignore:
- "*.*"
branches:
- master
env:
tf_version: "0.13.5"
tf_working_dir: "./automation/tf-fargate"
env: "prod"
project: "mamip"
aws_region: "eu-west-1"
artifacts_bucket: "mamip-artifacts"
jobs:
terraform:
name: "Build & Deploy"
permissions:
id-token: write
contents: write
runs-on: ubuntu-latest
steps:
- name: "Checkout"
uses: actions/checkout@v2
- name: AWS IAM Assume Role
uses: aws-actions/configure-aws-credentials@master
with:
aws-region: ${{ secrets.REGION }}
role-to-assume: ${{ secrets.ROLE_TO_ASSUME }}
role-duration-seconds: 1200
role-session-name: GH-Actions-${{ env.project }}-${{ env.env }}
# - name: Who Am I?
# run: aws sts get-caller-identity
- name: "Terraform Init"
uses: hashicorp/terraform-github-actions@master
with:
tf_actions_version: ${{ env.tf_version }}
tf_actions_subcommand: "init"
tf_actions_working_dir: ${{ env.tf_working_dir }}
tf_actions_comment: false
args: '-backend-config="bucket=${{ secrets.TF_STATE_S3_BUCKET }}" -backend-config="key=mamip/terraform-${{ env.env }}.tfstate"'
# - name: "Terraform Validate"
# uses: hashicorp/terraform-github-actions@master
# with:
# tf_actions_version: ${{ env.tf_version }}
# tf_actions_subcommand: "validate"
# tf_actions_working_dir: ${{ env.tf_working_dir }}
# tf_actions_comment: false
- name: "Terraform Plan"
id: plan
uses: hashicorp/terraform-github-actions@master
with:
tf_actions_version: ${{ env.tf_version }}
tf_actions_subcommand: "plan"
tf_actions_working_dir: ${{ env.tf_working_dir }}
tf_actions_comment: false
args: '-var="env=${{ env.env }}" -var="artifacts_bucket=${{ env.artifacts_bucket }}"'
- name: "Terraform Apply"
if: steps.plan.outputs.tf_actions_plan_has_changes == 'true'
uses: hashicorp/terraform-github-actions@master
with:
tf_actions_version: ${{ env.tf_version }}
tf_actions_subcommand: "apply"
tf_actions_working_dir: ${{ env.tf_working_dir }}
tf_actions_comment: false
args: '-var="env=${{ env.env }}"'
- name: Update runbook artifact
run: aws s3 cp ./automation/runbook-${{ env.env }}.sh 's3://${{ env.project }}-artifacts/${{ env.env }}/runbook.sh'
# - name: Login to Amazon ECR
# id: login-ecr
# uses: aws-actions/amazon-ecr-login@v1
# - name: Build, tag, and push image to Amazon ECR
# env:
# ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
# ECR_REPOSITORY: mamip-ecr-${{ env.env }}
# IMAGE_TAG: ${{ github.sha }}
# run: |
# docker buildx build --platform=linux/arm64 -t mamip-image ./automation/
# docker tag mamip-image $ECR_REGISTRY/$ECR_REPOSITORY
# docker push $ECR_REGISTRY/$ECR_REPOSITORY
- name: Logout of Amazon ECR
if: always()
run: docker logout ${{ steps.login-ecr.outputs.registry }}