MitocGroup / recink

REciNK - Rethink Continuous Integration for JavaScript Applications
https://www.npmjs.org/package/recink
Mozilla Public License 2.0
14 stars 5 forks source link

Add support for terraform workspace #107

Closed eistrati closed 6 years ago

eistrati commented 6 years ago

Reference: https://www.terraform.io/docs/state/workspaces.html

Config example:

your_tf_script_name:
  root: './your_tf_script_path'
  terraform:
    plan: true
    apply: false
    destroy: false
    var-files:
      - prod.tfvars
      - common.tfvars
    vars:
      region: 'us-west-2'
    current-workspace: default
    available-workspaces:
      dev:
        plan: true
        apply: true
        destroy: true
        var-files:
          - dev.tfvars
          - common.tfvars
      test:
        plan: true
        apply: true
        destroy: true
        var-files:
          - test.tfvars
          - common.tfvars
      stage:
        plan: true
        apply: true
        destroy: false
        var-files:
          - stage.tfvars
          - common.tfvars

CLI example:

recink run terraform -vv \
  --include-modules="your_tf_script_name"\
  --tf-workspace="dev"\
  --tf-version="0.11.0"\
  --tf-varfiles="dev.tfvars,common.tfvars"\
  --tf-vars="region:\"${region}\"\
,account_name:${account_name}\
,account_id:${account_id}\
,vpc_id:${vpc_id}\
,vpc_cidr:${vpc_cidr}"

Clarification:

  1. --tf-workspace="dev" <==> --custom-config="your_tf_script_name.terraform.current-workspace:dev"
  2. --tf-version="0.11.0" <==> --custom-config="$.terraform.version:0.11.0"
  3. --include-modules or --exclude-modules && --tf-version="0.11.0" <==> --custom-config="module1.terraform.version:0.11.0,module2.terraform.version:0.11.0,..."
  4. --tf-varfiles="v0,v1,..." <==> --custom-config="$.terraform.var-files.0:v0,$.terraform.var-files.1:v1,..."
  5. --include-modules or --exclude-modules && --tf-varfiles="v0,v1,..." <==> --custom-config="module1.terraform.var-files.0:v0,module1.terraform.var-files.1:v1,...,module2.terraform.var-files.0:v0,module2.terraform.var-files.1:v1,..."
dvirtosu commented 6 years ago

Intresting task, but workspace work only in version > 0.11.0 (tested), declared minimal version is 0.10, but in this version TF have some bugs. Before working with the "workspace", we will check the version.

avozicov commented 6 years ago

Task is still in progress and assigned to @ddimitrioglo after Hands-on session on 23.01.2017

avozicov commented 6 years ago

Test Failed

screen shot 2018-02-05 at 12 14 28
---
$:
  preprocess:
    '$.terraform.vars.access_key': 'eval'
    '$.terraform.vars.secret_key': 'eval'
    '$.terraform.vars.region': 'eval'
  emit:
    pattern:
      - /.+\.js$/i
    ignore:
      - /^(.*\/)?node_modules(\/?$)?/i
  terraform:
    resource: '.resource'
    use-cache: false
    plan: true
    apply: false
    destroy: false
    vars:
      access_key: 'process.env.AWS_ACCESS_KEY_ID'
      secret_key: 'process.env.AWS_SECRET_ACCESS_KEY'
      region: 'process.env.AWS_DEFAULT_REGION'

steam-ec2-create:
  root: './'
  terraform:
    version: '0.11.0'
    plan: false
    apply: false
    destroy: false
    current-workspace: default
    available-workspaces:
      prod:
        plan: true
        apply: false
        destroy: false
        var-files:
          - terraform.tfvars
    test:
      mapping: './tests/mapping.json'
      plan: './tests/unit/'
      apply: './tests/e2e/'
      e2e:
        testcafe:
          screenshot:
            enabled: true
            take-on-fail: true
            path: './tests/e2e/'
          browsers:
            - firefox 
eistrati commented 6 years ago

Checked.