s4ros icon

terraform-circleci-config.yml

s4ros | PRO | 03/11/19 02:13:29 PM UTC | 0 ⭐ | 451 👁️ | Never ⏰ | []
YAML |

1.51 KB

|

None

|

0 👍

/

0 👎

version: 2.1
 
executors:
  terraform:
    working_directory: ~/repo
    docker:
      - image: hashicorp/terraform:0.11.10
 
  python:
    working_directory: ~/repo
    docker:
      - image: circleci/python:2.7-jessie
 
commands:
  validate-terraform:
    parameters:
      environment:
        type: enum
        description: Environment to check
        enum: ["staging", "production"]
        default: "production"
    steps:
      - attach_workspace:
          at: ~/repo
      - run:
          name: Validate terraform code
          command: |
            cd << parameters.environment >>
            terraform init --input=false -backend-config "bucket=circleci"   -backend-config "region=us-east-1"   -backend-config "key=stackin/production"
            terraform validate
      - persist_to_workspace:
          root: ~/repo
          paths:
            - << parameters.environment >>/.terraform
 
jobs:
  checkout_code:
    executor: python
    steps:
      - checkout
      - persist_to_workspace:
          root: ~/repo
          paths:
            - .
 
  validation-production:
    executor: terraform
    working_directory: ~/repo
    steps:
      - attach_workspace:
          at: ~/repo
      - validate-terraform:
          environment: production
 
workflows:
  version: 2
  validate:
    jobs:
      - checkout_code
      - validation-production:
          requires:
            - checkout_code
          filters:
            branches:
              only: master

Comments