Skip to content

Commit

Permalink
Add sample gitlab ci and circleci config (cloud-ca#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
khos2ow authored Jul 17, 2019
1 parent 1f0f525 commit bace757
Show file tree
Hide file tree
Showing 2 changed files with 139 additions and 0 deletions.
81 changes: 81 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
_defaults: &defaults
docker:
- image: hashicorp/terraform:0.12.4

_run:
setenv: &setenv
name: "Setup Environment"
command: |-
apk add --update make curl
curl -sL https://github.com/cloud-ca/terraform-provider-cloudca/releases/download/v1.5.0/terraform-provider-cloudca_v1.5.0_linux-amd64.zip > terraform-provider-cloudca.zip && \
mkdir -p ~/.terraform.d/plugins && \
unzip -q terraform-provider-cloudca.zip -d ~/.terraform.d/plugins && \
rm terraform-provider-cloudca.zip
terraform --version
make init
version: 2
jobs:
validate:
<<: *defaults
steps:
- run: *setenv
- run:
name: "Validate Terraform configs"
command: make validate

checkfmt:
<<: *defaults
steps:
- run: *setenv
- run:
name: "Check formatting of all tf files"
command: make checkfmt

plan:
<<: *defaults
steps:
- run: *setenv
- run:
name: "Plan the Terraform config"
command: TFPLAN=terraform.tfplan make plan
- save_cache:
key: terraform-tfplan-{{ .Environment.CIRCLE_SHA1 }}
paths:
- terraform.tfplan

apply:
<<: *defaults
steps:
- restore_cache:
key: terraform-tfplan-{{ .Environment.CIRCLE_SHA1 }}
- run: *setenv
- run:
name: "Apply the Terraform config"
command: TFPLAN=terraform.tfplan make apply

workflows:
version: 2
build:
jobs:
- validate:
filters:
tags:
only: /v.*/
- checkfmt:
filters:
tags:
only: /v.*/
- plan:
requires:
- validate
- checkfmt
filters:
tags:
only: /v.*/
- apply:
requires:
- plan
filters:
tags:
only: /v.*/
58 changes: 58 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
image:
name: hashicorp/terraform:0.12.4
entrypoint:
- '/usr/bin/env'
- 'PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'

stages:
- validate
- plan
- deploy

variables:
PLAN: terraform.tfplan

cache:
paths:
- .terraform

before_script:
- apk add --update make curl
- |
curl -sL https://github.com/cloud-ca/terraform-provider-cloudca/releases/download/v1.5.0/terraform-provider-cloudca_v1.5.0_linux-amd64.zip > terraform-provider-cloudca.zip && \
mkdir -p ~/.terraform.d/plugins && \
unzip -q terraform-provider-cloudca.zip -d ~/.terraform.d/plugins && \
rm terraform-provider-cloudca.zip
- terraform --version
- make init

validate:
stage: validate
script:
- make validate

checkfmt:
stage: validate
script:
- make checkfmt

plan:
stage: plan
script:
- TFPLAN=$PLAN make plan
artifacts:
name: plan
paths:
- $PLAN

apply:
stage: deploy
environment:
name: prod
script:
- TFPLAN=$PLAN make apply
dependencies:
- plan
when: manual
only:
- master

0 comments on commit bace757

Please sign in to comment.