-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.travis.yml
44 lines (40 loc) · 1.58 KB
/
.travis.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
# Define environment
dist: focal # Ubuntu 20.04
language: bash
# Only build pushes to main branch
branches:
only:
- main
# Export variables
env:
- tf_version=1.0.5 tf_init_cli_options="-input=false" tf_validation_cli_options="" tf_plan_cli_options="-lock=false -input=false" tf_apply_cli_options="-auto-approve -input=false"
# Install dependencies
before_install:
- wget https://releases.hashicorp.com/terraform/"$tf_version"/terraform_"$tf_version"_linux_amd64.zip
- unzip terraform_"$tf_version"_linux_amd64.zip
- sudo mv terraform /usr/local/bin/
- rm terraform_"$tf_version"_linux_amd64.zip
- export AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}
- export AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}
- export AWS_DEFAULT_REGION=${AWS_DEFAULT_REGION}
# Terraform Plan and Apply
# Plan only on pull requests, Apply on merged code
jobs:
include:
- stage: terraform plan
# Only run terraform validate and plan state if within a pull request
if: type IN (pull_request, api)
script:
- echo "Validating Terraform fmt"
- terraform fmt -recursive -check
- echo "Pull request detected, creating change plan"
- terraform init $tf_init_cli_options
- terraform validate $tf_validation_cli_options
- terraform plan $tf_plan_cli_options
- stage: terraform apply
# Only run terraform apply stage if outside of a pull request
if: type IN (push) and branch = main
script:
- echo "Merge detected, executing changes"
- terraform init $tf_init_cli_options
- terraform apply $tf_apply_cli_options