From 4f957cb0e6e55309f87412307d3e13725fe2d678 Mon Sep 17 00:00:00 2001 From: Warren Brown Date: Wed, 8 Jul 2020 08:53:10 -0500 Subject: [PATCH 01/38] chore: added github actions --- .github/workflows/pre-commit.yaml | 12 ++--- .github/workflows/terraform.yaml | 87 +++++++++++-------------------- 2 files changed, 35 insertions(+), 64 deletions(-) diff --git a/.github/workflows/pre-commit.yaml b/.github/workflows/pre-commit.yaml index 1dbad09..fa60bf0 100644 --- a/.github/workflows/pre-commit.yaml +++ b/.github/workflows/pre-commit.yaml @@ -2,6 +2,8 @@ name: pre-commit on: pull_request: + push: + branches: [develop] jobs: run-all: @@ -9,24 +11,20 @@ jobs: steps: - uses: actions/checkout@v1 - uses: actions/setup-python@v1 - - name: setup python run: echo "::set-env name=PY::$(python --version --version | sha256sum | cut -d' ' -f1)" - - name: setup tflint run: |- sudo apt-get install unzip -y - curl -L "$(curl -Ls https://api.github.com/repos/terraform-linters/tflint/releases/latest | grep -o -E "https://.+?_linux_amd64.*zip")" > tflint.zip + curl -L "$(curl -s https://api.github.com/repos/terraform-linters/tflint/releases/latest | grep -o -E "https://.+?_linux_amd64.*zip")" > tflint.zip sudo unzip -o tflint.zip -d /usr/bin sudo chmod +x /usr/bin/tflint - name: setup terraform_docs - run: curl -L "$(curl -Ls https://api.github.com/repos/segmentio/terraform-docs/releases/latest | grep -o -E "https://.+?-linux-amd64")" > terraform-docs && chmod +x terraform-docs && sudo mv terraform-docs /usr/bin/ - + run: curl -L "$(curl -s https://api.github.com/repos/segmentio/terraform-docs/releases/latest | grep -o -E "https://.+?-linux-amd64")" > terraform-docs && chmod +x terraform-docs && sudo mv terraform-docs /usr/bin/ - uses: actions/cache@v1 with: path: ~/.cache/pre-commit key: pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }} - - uses: pre-commit/action@v1.0.1 with: - token: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file + token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/terraform.yaml b/.github/workflows/terraform.yaml index c1eec8b..9bc09a4 100644 --- a/.github/workflows/terraform.yaml +++ b/.github/workflows/terraform.yaml @@ -4,66 +4,39 @@ on: - pull_request jobs: - terraform: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Set - Env Vars - id: setting_dev_env - env: - WORKING_DIRECTORY: ./test - run: | - echo Setting up enironment variables. - echo "::set-env name=WORKING_DIRECTORY::$WORKING_DIRECTORY" - - - name: Install terraform - uses: hashicorp/setup-terraform@v1 - - - name: Terraform Init - id: init - run: terraform init - working-directory: ${{env.WORKING_DIRECTORY}} - - - name: Terraform Validate - id: validate - run: terraform validate -no-color - working-directory: ${{env.WORKING_DIRECTORY}} - - - name: Terraform Plan - id: plan - run: terraform plan -no-color - continue-on-error: true - working-directory: ${{env.WORKING_DIRECTORY}} - - - uses: actions/github-script@0.9.0 - if: github.event_name == 'pull_request' - env: - PLAN: "terraform\n${{ steps.plan.outputs.stdout }}" - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - script: | - const tfInitStatus = ${{steps.init.outputs.exitcode == 0}} ? ':white_check_mark:' : ':x:' - const tfValidationStatus = ${{steps.validate.outputs.exitcode == 0}} ? ':white_check_mark:' : ':x:' - const tfPlanStatus = ${{steps.plan.outputs.exitcode == 0}} ? ':white_check_mark:' : ':x:' + security: - const output = `${tfInitStatus} Terraform Initialization - ${tfValidationStatus} Terraform Validation - ${tfPlanStatus} Terraform Plan + runs-on: ubuntu-latest -
Show Plan + steps: + - uses: actions/checkout@v2 + - name: Terraform security scan + uses: triat/terraform-security-scan@v1.1 - \`\`\`${process.env.PLAN}\`\`\` + check_format: + runs-on: ubuntu-latest + name: Check terraform file are formatted correctly + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + steps: + - name: Checkout + uses: actions/checkout@v2 -
+ - name: terraform fmt + uses: dflook/terraform-fmt@1 + with: + path: my-terraform-config - *User*: @${{ github.actor }} - *Action*: \`${{ github.event_name }}\` - *Working Directory*: \`${{ env.WORKING_DIRECTORY }}\` - *Workflow*: \`${{ github.workflow }}\``; + run_plan: + runs-on: ubuntu-latest + name: Check terraform file are formatted correctly + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + steps: + - name: Checkout + uses: actions/checkout@v2 - github.issues.createComment({ - issue_number: context.issue.number, - owner: context.repo.owner, - repo: context.repo.repo, - body: output - }) + - name: terraform fmt + uses: dflook/terraform-plan + with: + path: my-terraform-config \ No newline at end of file From 212095123eebd9d16d06ba8942461582dfe7f9a9 Mon Sep 17 00:00:00 2001 From: Warren Brown Date: Wed, 8 Jul 2020 09:40:27 -0500 Subject: [PATCH 02/38] chore: updated terraform.yaml --- .github/workflows/pre-commit.yaml | 2 +- .github/workflows/terraform.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pre-commit.yaml b/.github/workflows/pre-commit.yaml index fa60bf0..210e96c 100644 --- a/.github/workflows/pre-commit.yaml +++ b/.github/workflows/pre-commit.yaml @@ -20,7 +20,7 @@ jobs: sudo unzip -o tflint.zip -d /usr/bin sudo chmod +x /usr/bin/tflint - name: setup terraform_docs - run: curl -L "$(curl -s https://api.github.com/repos/segmentio/terraform-docs/releases/latest | grep -o -E "https://.+?-linux-amd64")" > terraform-docs && chmod +x terraform-docs && sudo mv terraform-docs /usr/bin/ + run: curl -L "$(curl -Ls https://api.github.com/repos/segmentio/terraform-docs/releases/latest | grep -o -E "https://.+?-linux-amd64")" > terraform-docs && chmod +x terraform-docs && sudo mv terraform-docs /usr/bin/ - uses: actions/cache@v1 with: path: ~/.cache/pre-commit diff --git a/.github/workflows/terraform.yaml b/.github/workflows/terraform.yaml index 9bc09a4..d504f0c 100644 --- a/.github/workflows/terraform.yaml +++ b/.github/workflows/terraform.yaml @@ -37,6 +37,6 @@ jobs: uses: actions/checkout@v2 - name: terraform fmt - uses: dflook/terraform-plan + uses: dflook/terraform-plan@v1 with: path: my-terraform-config \ No newline at end of file From 2e1939322f922ad1496c053c9e80b34c526edbda Mon Sep 17 00:00:00 2001 From: Warren Brown Date: Wed, 8 Jul 2020 09:53:34 -0500 Subject: [PATCH 03/38] chore: updated path for worklfow --- .github/workflows/terraform.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/terraform.yaml b/.github/workflows/terraform.yaml index d504f0c..044385c 100644 --- a/.github/workflows/terraform.yaml +++ b/.github/workflows/terraform.yaml @@ -23,9 +23,9 @@ jobs: uses: actions/checkout@v2 - name: terraform fmt - uses: dflook/terraform-fmt@1 + uses: dflook/terraform-fmt@v1 with: - path: my-terraform-config + path: terraform run_plan: runs-on: ubuntu-latest @@ -39,4 +39,4 @@ jobs: - name: terraform fmt uses: dflook/terraform-plan@v1 with: - path: my-terraform-config \ No newline at end of file + path: terraform \ No newline at end of file From c7da091f8e0e98ed798f6540e9b5e66354ad7a50 Mon Sep 17 00:00:00 2001 From: Warren Brown Date: Sun, 12 Jul 2020 08:19:41 -0500 Subject: [PATCH 04/38] Apply suggestions from code review Co-authored-by: John C. Bland II --- .github/workflows/pre-commit.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pre-commit.yaml b/.github/workflows/pre-commit.yaml index 210e96c..2f457ee 100644 --- a/.github/workflows/pre-commit.yaml +++ b/.github/workflows/pre-commit.yaml @@ -16,7 +16,7 @@ jobs: - name: setup tflint run: |- sudo apt-get install unzip -y - curl -L "$(curl -s https://api.github.com/repos/terraform-linters/tflint/releases/latest | grep -o -E "https://.+?_linux_amd64.*zip")" > tflint.zip + curl -L "$(curl -Ls https://api.github.com/repos/terraform-linters/tflint/releases/latest | grep -o -E "https://.+?_linux_amd64.*zip")" > tflint.zip sudo unzip -o tflint.zip -d /usr/bin sudo chmod +x /usr/bin/tflint - name: setup terraform_docs From 4c4875f2e66616cd8c1d025107f455940c5b5459 Mon Sep 17 00:00:00 2001 From: Warren Brown Date: Sun, 12 Jul 2020 08:33:40 -0500 Subject: [PATCH 05/38] chore: added pr-labeler to workflows --- .github/workflows/pr-labeler.yaml | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 .github/workflows/pr-labeler.yaml diff --git a/.github/workflows/pr-labeler.yaml b/.github/workflows/pr-labeler.yaml new file mode 100644 index 0000000..8059390 --- /dev/null +++ b/.github/workflows/pr-labeler.yaml @@ -0,0 +1,12 @@ +name: PR Labeler +on: + pull_request: + types: [opened] + +jobs: + pr-labeler: + runs-on: ubuntu-latest + steps: + - uses: TimonVS/pr-labeler-action@v3 + with: + configuration-path: .github/pr-labeler.yml # optional, .github/pr-labeler.yml is the default value \ No newline at end of file From 2ab620f2765608d8dd41d077564900656f8ff14a Mon Sep 17 00:00:00 2001 From: Warren Brown Date: Sun, 12 Jul 2020 08:37:29 -0500 Subject: [PATCH 06/38] chore: added config file for pr labeler --- .github/pr-labeler.yml | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 .github/pr-labeler.yml diff --git a/.github/pr-labeler.yml b/.github/pr-labeler.yml new file mode 100644 index 0000000..cb2dd69 --- /dev/null +++ b/.github/pr-labeler.yml @@ -0,0 +1,4 @@ +feature: ['feature/*', 'feat/*'] +fix: fix/* +chore: chore/* +fixed-branch: fixed-branch-name \ No newline at end of file From 42689815243dd1904ffbaa75a7bb769861f34946 Mon Sep 17 00:00:00 2001 From: Warren Brown Date: Sun, 12 Jul 2020 09:14:28 -0500 Subject: [PATCH 07/38] udated terrafrom.yaml workflow --- .github/workflows/terraform.yaml | 78 ++++++++++++++++++-------------- main.tf | 26 +++++++++++ 2 files changed, 70 insertions(+), 34 deletions(-) create mode 100644 main.tf diff --git a/.github/workflows/terraform.yaml b/.github/workflows/terraform.yaml index 044385c..b79636b 100644 --- a/.github/workflows/terraform.yaml +++ b/.github/workflows/terraform.yaml @@ -4,39 +4,49 @@ on: - pull_request jobs: - security: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - name: Terraform security scan - uses: triat/terraform-security-scan@v1.1 - - check_format: + terraform: runs-on: ubuntu-latest - name: Check terraform file are formatted correctly - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} steps: - - name: Checkout - uses: actions/checkout@v2 - - - name: terraform fmt - uses: dflook/terraform-fmt@v1 - with: - path: terraform - - run_plan: - runs-on: ubuntu-latest - name: Check terraform file are formatted correctly - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - steps: - - name: Checkout - uses: actions/checkout@v2 - - - name: terraform fmt - uses: dflook/terraform-plan@v1 - with: - path: terraform \ No newline at end of file + - uses: actions/checkout@v2 + - name: Install terraform + uses: hashicorp/setup-terraform@v1 + + - name: Terraform Init + id: init + run: terraform init + + - name: Terraform Validate + id: validate + run: terraform validate -no-color + + - name: Terraform Plan + id: plan + run: terraform plan -no-color + continue-on-error: true + + - uses: actions/github-script@0.9.0 + if: github.event_name == 'pull_request' + env: + PLAN: "terraform\n${{ steps.plan.outputs.stdout }}" + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const output = `#### Terraform Format and Style 🖌\`${{ steps.fmt.outcome }}\` + #### Terraform Initialization ⚙️\`${{ steps.init.outcome }}\` + #### Terraform Validation 🤖${{ steps.validate.outputs.stdout }} + #### Terraform Plan 📖\`${{ steps.plan.outcome }}\` + +
Show Plan + + \`\`\`${process.env.PLAN}\`\`\` + +
+ + *Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`, Working Directory: \`${{ env.tf_actions_working_dir }}\`, Workflow: \`${{ github.workflow }}\`*`; + + github.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: output + }) \ No newline at end of file diff --git a/main.tf b/main.tf new file mode 100644 index 0000000..ba9ed5a --- /dev/null +++ b/main.tf @@ -0,0 +1,26 @@ +locals { + application_name = "academy" + db_username = "${local.application_name}dba" +} + +data "aws_availability_zones" "this" { + state = "available" +} + +module "default_tags" { + source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=0.16.0" + + tags = { + "Application" = "testapplication", + "Customer" = "testcustomer", + "Environment" = "testde" + } +} + +module "label" { + source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=0.16.0" + + namespace = "app" + name = "dev" + stage = "localapplication" +} From 5d56272eb168fb3dde7a6983da9d792eaf655ade Mon Sep 17 00:00:00 2001 From: Warren Brown Date: Sun, 12 Jul 2020 09:19:57 -0500 Subject: [PATCH 08/38] updated terrafrom.yaml workflow --- main.tf | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/main.tf b/main.tf index ba9ed5a..ab088ad 100644 --- a/main.tf +++ b/main.tf @@ -1,3 +1,7 @@ +provider "aws" { + region = "us-west-2" +} + locals { application_name = "academy" db_username = "${local.application_name}dba" From 4f0845ad3fd96d2c0000b514b332adbe1dae2773 Mon Sep 17 00:00:00 2001 From: Warren Brown Date: Sun, 12 Jul 2020 10:20:09 -0500 Subject: [PATCH 09/38] chore: removed main.tf it was not needed --- main.tf | 30 ------------------------------ 1 file changed, 30 deletions(-) delete mode 100644 main.tf diff --git a/main.tf b/main.tf deleted file mode 100644 index ab088ad..0000000 --- a/main.tf +++ /dev/null @@ -1,30 +0,0 @@ -provider "aws" { - region = "us-west-2" -} - -locals { - application_name = "academy" - db_username = "${local.application_name}dba" -} - -data "aws_availability_zones" "this" { - state = "available" -} - -module "default_tags" { - source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=0.16.0" - - tags = { - "Application" = "testapplication", - "Customer" = "testcustomer", - "Environment" = "testde" - } -} - -module "label" { - source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=0.16.0" - - namespace = "app" - name = "dev" - stage = "localapplication" -} From 9325d4b6d978388fbac796a383dc9839b2602084 Mon Sep 17 00:00:00 2001 From: Warren Brown Date: Fri, 17 Jul 2020 17:06:55 -0500 Subject: [PATCH 10/38] chore: made updated changes to workflows --- .github/pr-labeler.yml | 4 ---- .github/workflows/pr-labeler.yaml | 12 ------------ .github/workflows/pre-commit.yaml | 8 +++++--- .github/workflows/terraform.yaml | 29 +++++++++++++++++++++++------ 4 files changed, 28 insertions(+), 25 deletions(-) delete mode 100644 .github/pr-labeler.yml delete mode 100644 .github/workflows/pr-labeler.yaml diff --git a/.github/pr-labeler.yml b/.github/pr-labeler.yml deleted file mode 100644 index cb2dd69..0000000 --- a/.github/pr-labeler.yml +++ /dev/null @@ -1,4 +0,0 @@ -feature: ['feature/*', 'feat/*'] -fix: fix/* -chore: chore/* -fixed-branch: fixed-branch-name \ No newline at end of file diff --git a/.github/workflows/pr-labeler.yaml b/.github/workflows/pr-labeler.yaml deleted file mode 100644 index 8059390..0000000 --- a/.github/workflows/pr-labeler.yaml +++ /dev/null @@ -1,12 +0,0 @@ -name: PR Labeler -on: - pull_request: - types: [opened] - -jobs: - pr-labeler: - runs-on: ubuntu-latest - steps: - - uses: TimonVS/pr-labeler-action@v3 - with: - configuration-path: .github/pr-labeler.yml # optional, .github/pr-labeler.yml is the default value \ No newline at end of file diff --git a/.github/workflows/pre-commit.yaml b/.github/workflows/pre-commit.yaml index 2f457ee..1dbad09 100644 --- a/.github/workflows/pre-commit.yaml +++ b/.github/workflows/pre-commit.yaml @@ -2,8 +2,6 @@ name: pre-commit on: pull_request: - push: - branches: [develop] jobs: run-all: @@ -11,8 +9,10 @@ jobs: steps: - uses: actions/checkout@v1 - uses: actions/setup-python@v1 + - name: setup python run: echo "::set-env name=PY::$(python --version --version | sha256sum | cut -d' ' -f1)" + - name: setup tflint run: |- sudo apt-get install unzip -y @@ -21,10 +21,12 @@ jobs: sudo chmod +x /usr/bin/tflint - name: setup terraform_docs run: curl -L "$(curl -Ls https://api.github.com/repos/segmentio/terraform-docs/releases/latest | grep -o -E "https://.+?-linux-amd64")" > terraform-docs && chmod +x terraform-docs && sudo mv terraform-docs /usr/bin/ + - uses: actions/cache@v1 with: path: ~/.cache/pre-commit key: pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }} + - uses: pre-commit/action@v1.0.1 with: - token: ${{ secrets.GITHUB_TOKEN }} + token: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/terraform.yaml b/.github/workflows/terraform.yaml index b79636b..c1eec8b 100644 --- a/.github/workflows/terraform.yaml +++ b/.github/workflows/terraform.yaml @@ -8,21 +8,32 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 + - name: Set - Env Vars + id: setting_dev_env + env: + WORKING_DIRECTORY: ./test + run: | + echo Setting up enironment variables. + echo "::set-env name=WORKING_DIRECTORY::$WORKING_DIRECTORY" + - name: Install terraform uses: hashicorp/setup-terraform@v1 - name: Terraform Init id: init run: terraform init + working-directory: ${{env.WORKING_DIRECTORY}} - name: Terraform Validate id: validate run: terraform validate -no-color + working-directory: ${{env.WORKING_DIRECTORY}} - name: Terraform Plan id: plan run: terraform plan -no-color continue-on-error: true + working-directory: ${{env.WORKING_DIRECTORY}} - uses: actions/github-script@0.9.0 if: github.event_name == 'pull_request' @@ -31,10 +42,13 @@ jobs: with: github-token: ${{ secrets.GITHUB_TOKEN }} script: | - const output = `#### Terraform Format and Style 🖌\`${{ steps.fmt.outcome }}\` - #### Terraform Initialization ⚙️\`${{ steps.init.outcome }}\` - #### Terraform Validation 🤖${{ steps.validate.outputs.stdout }} - #### Terraform Plan 📖\`${{ steps.plan.outcome }}\` + const tfInitStatus = ${{steps.init.outputs.exitcode == 0}} ? ':white_check_mark:' : ':x:' + const tfValidationStatus = ${{steps.validate.outputs.exitcode == 0}} ? ':white_check_mark:' : ':x:' + const tfPlanStatus = ${{steps.plan.outputs.exitcode == 0}} ? ':white_check_mark:' : ':x:' + + const output = `${tfInitStatus} Terraform Initialization + ${tfValidationStatus} Terraform Validation + ${tfPlanStatus} Terraform Plan
Show Plan @@ -42,11 +56,14 @@ jobs:
- *Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`, Working Directory: \`${{ env.tf_actions_working_dir }}\`, Workflow: \`${{ github.workflow }}\`*`; + *User*: @${{ github.actor }} + *Action*: \`${{ github.event_name }}\` + *Working Directory*: \`${{ env.WORKING_DIRECTORY }}\` + *Workflow*: \`${{ github.workflow }}\``; github.issues.createComment({ issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, body: output - }) \ No newline at end of file + }) From 177253d852f9d1d476b9b144db5a75b2a04b88e4 Mon Sep 17 00:00:00 2001 From: Warren Brown Date: Wed, 8 Jul 2020 09:17:34 -0500 Subject: [PATCH 11/38] chore: added workspace module --- modules/workspace/data.tf | 23 +++++++++++ modules/workspace/main.tf | 75 ++++++++++++++++++++++++++++++++++ modules/workspace/outputs.tf | 4 ++ modules/workspace/variables.tf | 71 ++++++++++++++++++++++++++++++++ modules/workspace/version.tf | 4 ++ 5 files changed, 177 insertions(+) create mode 100644 modules/workspace/data.tf create mode 100644 modules/workspace/main.tf create mode 100644 modules/workspace/outputs.tf create mode 100644 modules/workspace/variables.tf create mode 100644 modules/workspace/version.tf diff --git a/modules/workspace/data.tf b/modules/workspace/data.tf new file mode 100644 index 0000000..158a7d7 --- /dev/null +++ b/modules/workspace/data.tf @@ -0,0 +1,23 @@ +data "aws_kms_secrets" "vars" { + secret { + name = "aws_access_key_id" + payload = var.aws_access_key_id + + context = { + // TODO ADD ACCESS KEY ID + account = "", + type = "access-key" + } + } + + secret { + name = "aws_secret_access_key" + payload = var.aws_secret_access_key + + context = { + // TODO ADD SECRET ACCESS KEY + account = "", + type = "secret-key" + } + } +} diff --git a/modules/workspace/main.tf b/modules/workspace/main.tf new file mode 100644 index 0000000..34f6f63 --- /dev/null +++ b/modules/workspace/main.tf @@ -0,0 +1,75 @@ +data "tfe_ssh_key" "github" { + name = "github" + organization = var.organization +} + +resource "tfe_workspace" "workspace" { + name = var.name + organization = var.organization + + auto_apply = var.auto_apply + file_triggers_enabled = true + queue_all_runs = true + ssh_key_id = data.tfe_ssh_key.github.id + terraform_version = var.terraform_version + working_directory = var.working_directory + + vcs_repo { + identifier = var.repo + branch = var.branch + ingress_submodules = false + oauth_token_id = var.oauth_token_id + } +} + +resource "tfe_variable" "aws_access_key" { + key = "AWS_ACCESS_KEY_ID" + value = trimspace(data.aws_kms_secrets.vars.plaintext["aws_access_key_id"]) + category = "env" + workspace_id = tfe_workspace.workspace.id +} + +resource "tfe_variable" "aws_secret_access_key" { + key = "AWS_SECRET_ACCESS_KEY" + value = trimspace(data.aws_kms_secrets.vars.plaintext["aws_secret_access_key"]) + category = "env" + sensitive = "true" + workspace_id = tfe_workspace.workspace.id +} + +resource "tfe_variable" "aws_default_region" { + key = "AWS_DEFAULT_REGION" + value = var.aws_default_region + category = "env" + workspace_id = tfe_workspace.workspace.id +} + +resource "tfe_variable" "secrets" { + for_each = var.custom_secrets + + key = each.key + value = each.value + category = "terraform" + sensitive = true + workspace_id = tfe_workspace.workspace.id +} + +resource "tfe_variable" "vars" { + for_each = var.custom_variables + + key = each.key + value = each.value + category = "terraform" + workspace_id = tfe_workspace.workspace.id +} + +resource "tfe_variable" "hcl_vars" { + for_each = var.custom_hcl_vars + + key = each.key + hcl = true + value = each.value + category = "terraform" + workspace_id = tfe_workspace.workspace.id +} + diff --git a/modules/workspace/outputs.tf b/modules/workspace/outputs.tf new file mode 100644 index 0000000..fb6de8a --- /dev/null +++ b/modules/workspace/outputs.tf @@ -0,0 +1,4 @@ +output "name" { + description = "The name of the workspace." + value = var.name +} \ No newline at end of file diff --git a/modules/workspace/variables.tf b/modules/workspace/variables.tf new file mode 100644 index 0000000..16a5128 --- /dev/null +++ b/modules/workspace/variables.tf @@ -0,0 +1,71 @@ +// TFC Config + +variable "auto_apply" { + default = false + description = "Whether to automatically apply changes when a Terraform plan is successful. Defaults to false." +} + +variable "name" { + description = "Name of the workspace." +} + +variable "organization" { + description = "The name of the organization the workspace is under." +} + +variable "oauth_token_id" { + description = "The OAuth token id for the VCS provider." +} + +variable "terraform_version" { + default = "latest" + description = "The version of Terraform to use for this workspace. Defaults to the latest available version." +} + +// VCS + +variable "repo" { + description = "A reference to your VCS repository in the format :org/:repo where :org and :repo refer to the organization and repository in your VCS provider." +} + +variable "branch" { + description = "The repository branch that Terraform will execute from. Default to master." +} + +variable "working_directory" { + description = "A relative path that Terraform will execute within. Defaults to the root of your repository." +} + +// App Vars + +variable "aws_access_key_id" { + description = "AWS Access Key for access to AWS" + default = "" +} + +variable "aws_secret_access_key" { + description = "AWS Secret Key for access to AWS" + default = "" +} + +variable "aws_default_region" { + description = "AWS default region" + default = "" +} + +variable "custom_secrets" { + default = {} + description = "A map of custom secrets." + type = map +} + +variable "custom_variables" { + default = {} + description = "A map of custom variables." + type = map +} + +variable "custom_hcl_vars" { + type = map + default = {} +} \ No newline at end of file diff --git a/modules/workspace/version.tf b/modules/workspace/version.tf new file mode 100644 index 0000000..ac97c6a --- /dev/null +++ b/modules/workspace/version.tf @@ -0,0 +1,4 @@ + +terraform { + required_version = ">= 0.12" +} From eb45e066a6045c1714d0dae09c721931e17287d0 Mon Sep 17 00:00:00 2001 From: Warren Brown Date: Wed, 8 Jul 2020 14:30:06 -0500 Subject: [PATCH 12/38] chore: adderd pertaining terraform files to repo --- config.tf | 14 ++++++++++++++ default.auto.tfvars | 12 ++++++++++++ variables.tf | 31 +++++++++++++++++++++++++++++++ versions.tf | 3 +++ 4 files changed, 60 insertions(+) create mode 100644 config.tf create mode 100644 default.auto.tfvars create mode 100644 variables.tf create mode 100644 versions.tf diff --git a/config.tf b/config.tf new file mode 100644 index 0000000..64d7cf7 --- /dev/null +++ b/config.tf @@ -0,0 +1,14 @@ +terraform { + backend "remote" { + hostname = "app.terraform.io" + organization = "katapultmedia" + + workspaces { + name = "katapultmedia-tfc" + } + } +} + +provider "tfe" { + token = var.tfe_token +} diff --git a/default.auto.tfvars b/default.auto.tfvars new file mode 100644 index 0000000..04e5fc9 --- /dev/null +++ b/default.auto.tfvars @@ -0,0 +1,12 @@ +application_name = "" + +aws_access_key_id = "" +aws_default_region = "" +aws_secret_access_key = "" + +oauth_token_id = "" +// Todo add organa +organization = "" + + +vcs_repo = "katapultmedia/terraform-tfc-workspace" diff --git a/variables.tf b/variables.tf new file mode 100644 index 0000000..d201483 --- /dev/null +++ b/variables.tf @@ -0,0 +1,31 @@ +variable "application_name" { + description = "The name of the application" +} + +variable "aws_access_key_id" { + description = "AWS access key for the created workspaces" +} + +variable "aws_default_region" { + description = "AWS default region for the created workspaces" +} + +variable "aws_secret_access_key" { + description = "AWS secret key for the created workspaces" +} + +variable "organization" { + description = "The name of the organization the application belongs to." +} + +variable "oauth_token_id" { + description = "The OAuth token id for the VCS provider." +} + +variable "tfe_token" { + default = "" +} + +variable "vcs_repo" { + description = "The VCS repo where the Terraform exists." +} diff --git a/versions.tf b/versions.tf new file mode 100644 index 0000000..d9b6f79 --- /dev/null +++ b/versions.tf @@ -0,0 +1,3 @@ +terraform { + required_version = ">= 0.12" +} From f4d83614273c496580c8b9c07d35c5ee219d9a0f Mon Sep 17 00:00:00 2001 From: Warren Brown Date: Fri, 10 Jul 2020 09:22:33 -0500 Subject: [PATCH 13/38] chore: updated terraform files for module --- config.tf | 14 ---- main.tf | 24 +++++++ modules/workspace/data.tf | 23 ------- modules/workspace/main.tf | 75 ---------------------- modules/workspace/variables.tf | 71 -------------------- modules/workspace/version.tf | 4 -- modules/workspace/outputs.tf => outputs.tf | 0 variables.tf | 57 +++++++++++----- versions.tf | 7 +- 9 files changed, 70 insertions(+), 205 deletions(-) delete mode 100644 config.tf create mode 100644 main.tf delete mode 100644 modules/workspace/data.tf delete mode 100644 modules/workspace/main.tf delete mode 100644 modules/workspace/variables.tf delete mode 100644 modules/workspace/version.tf rename modules/workspace/outputs.tf => outputs.tf (100%) diff --git a/config.tf b/config.tf deleted file mode 100644 index 64d7cf7..0000000 --- a/config.tf +++ /dev/null @@ -1,14 +0,0 @@ -terraform { - backend "remote" { - hostname = "app.terraform.io" - organization = "katapultmedia" - - workspaces { - name = "katapultmedia-tfc" - } - } -} - -provider "tfe" { - token = var.tfe_token -} diff --git a/main.tf b/main.tf new file mode 100644 index 0000000..a484744 --- /dev/null +++ b/main.tf @@ -0,0 +1,24 @@ +data "tfe_ssh_key" "github" { + name = "github" + organization = var.organization +} + +resource "tfe_workspace" "workspace" { + name = var.name + organization = var.organization + + auto_apply = var.auto_apply + file_triggers_enabled = true + queue_all_runs = true + ssh_key_id = data.tfe_ssh_key.github.id + terraform_version = var.terraform_version + working_directory = var.working_directory + + vcs_repo { + identifier = var.repo + branch = var.branch + ingress_submodules = false + oauth_token_id = var.oauth_token_id + } +} + diff --git a/modules/workspace/data.tf b/modules/workspace/data.tf deleted file mode 100644 index 158a7d7..0000000 --- a/modules/workspace/data.tf +++ /dev/null @@ -1,23 +0,0 @@ -data "aws_kms_secrets" "vars" { - secret { - name = "aws_access_key_id" - payload = var.aws_access_key_id - - context = { - // TODO ADD ACCESS KEY ID - account = "", - type = "access-key" - } - } - - secret { - name = "aws_secret_access_key" - payload = var.aws_secret_access_key - - context = { - // TODO ADD SECRET ACCESS KEY - account = "", - type = "secret-key" - } - } -} diff --git a/modules/workspace/main.tf b/modules/workspace/main.tf deleted file mode 100644 index 34f6f63..0000000 --- a/modules/workspace/main.tf +++ /dev/null @@ -1,75 +0,0 @@ -data "tfe_ssh_key" "github" { - name = "github" - organization = var.organization -} - -resource "tfe_workspace" "workspace" { - name = var.name - organization = var.organization - - auto_apply = var.auto_apply - file_triggers_enabled = true - queue_all_runs = true - ssh_key_id = data.tfe_ssh_key.github.id - terraform_version = var.terraform_version - working_directory = var.working_directory - - vcs_repo { - identifier = var.repo - branch = var.branch - ingress_submodules = false - oauth_token_id = var.oauth_token_id - } -} - -resource "tfe_variable" "aws_access_key" { - key = "AWS_ACCESS_KEY_ID" - value = trimspace(data.aws_kms_secrets.vars.plaintext["aws_access_key_id"]) - category = "env" - workspace_id = tfe_workspace.workspace.id -} - -resource "tfe_variable" "aws_secret_access_key" { - key = "AWS_SECRET_ACCESS_KEY" - value = trimspace(data.aws_kms_secrets.vars.plaintext["aws_secret_access_key"]) - category = "env" - sensitive = "true" - workspace_id = tfe_workspace.workspace.id -} - -resource "tfe_variable" "aws_default_region" { - key = "AWS_DEFAULT_REGION" - value = var.aws_default_region - category = "env" - workspace_id = tfe_workspace.workspace.id -} - -resource "tfe_variable" "secrets" { - for_each = var.custom_secrets - - key = each.key - value = each.value - category = "terraform" - sensitive = true - workspace_id = tfe_workspace.workspace.id -} - -resource "tfe_variable" "vars" { - for_each = var.custom_variables - - key = each.key - value = each.value - category = "terraform" - workspace_id = tfe_workspace.workspace.id -} - -resource "tfe_variable" "hcl_vars" { - for_each = var.custom_hcl_vars - - key = each.key - hcl = true - value = each.value - category = "terraform" - workspace_id = tfe_workspace.workspace.id -} - diff --git a/modules/workspace/variables.tf b/modules/workspace/variables.tf deleted file mode 100644 index 16a5128..0000000 --- a/modules/workspace/variables.tf +++ /dev/null @@ -1,71 +0,0 @@ -// TFC Config - -variable "auto_apply" { - default = false - description = "Whether to automatically apply changes when a Terraform plan is successful. Defaults to false." -} - -variable "name" { - description = "Name of the workspace." -} - -variable "organization" { - description = "The name of the organization the workspace is under." -} - -variable "oauth_token_id" { - description = "The OAuth token id for the VCS provider." -} - -variable "terraform_version" { - default = "latest" - description = "The version of Terraform to use for this workspace. Defaults to the latest available version." -} - -// VCS - -variable "repo" { - description = "A reference to your VCS repository in the format :org/:repo where :org and :repo refer to the organization and repository in your VCS provider." -} - -variable "branch" { - description = "The repository branch that Terraform will execute from. Default to master." -} - -variable "working_directory" { - description = "A relative path that Terraform will execute within. Defaults to the root of your repository." -} - -// App Vars - -variable "aws_access_key_id" { - description = "AWS Access Key for access to AWS" - default = "" -} - -variable "aws_secret_access_key" { - description = "AWS Secret Key for access to AWS" - default = "" -} - -variable "aws_default_region" { - description = "AWS default region" - default = "" -} - -variable "custom_secrets" { - default = {} - description = "A map of custom secrets." - type = map -} - -variable "custom_variables" { - default = {} - description = "A map of custom variables." - type = map -} - -variable "custom_hcl_vars" { - type = map - default = {} -} \ No newline at end of file diff --git a/modules/workspace/version.tf b/modules/workspace/version.tf deleted file mode 100644 index ac97c6a..0000000 --- a/modules/workspace/version.tf +++ /dev/null @@ -1,4 +0,0 @@ - -terraform { - required_version = ">= 0.12" -} diff --git a/modules/workspace/outputs.tf b/outputs.tf similarity index 100% rename from modules/workspace/outputs.tf rename to outputs.tf diff --git a/variables.tf b/variables.tf index d201483..55265d0 100644 --- a/variables.tf +++ b/variables.tf @@ -1,31 +1,56 @@ -variable "application_name" { - description = "The name of the application" -} - -variable "aws_access_key_id" { - description = "AWS access key for the created workspaces" -} +// TFC Config -variable "aws_default_region" { - description = "AWS default region for the created workspaces" +variable "auto_apply" { + default = false + description = "Whether to automatically apply changes when a Terraform plan is successful. Defaults to false." } -variable "aws_secret_access_key" { - description = "AWS secret key for the created workspaces" +variable "name" { + description = "Name of the workspace." } variable "organization" { - description = "The name of the organization the application belongs to." + description = "The name of the organization the workspace is under." } variable "oauth_token_id" { description = "The OAuth token id for the VCS provider." } -variable "tfe_token" { - default = "" +variable "terraform_version" { + default = "latest" + description = "The version of Terraform to use for this workspace. Defaults to the latest available version." +} + +// VCS + +variable "repo" { + description = "A reference to your VCS repository in the format :org/:repo where :org and :repo refer to the organization and repository in your VCS provider." +} + +variable "branch" { + description = "The repository branch that Terraform will execute from. Default to master." +} + +variable "working_directory" { + description = "A relative path that Terraform will execute within. Defaults to the root of your repository." } -variable "vcs_repo" { - description = "The VCS repo where the Terraform exists." +// App Vars + +variable "secrets" { + default = {} + description = "A map of custom secrets." + type = map } + +variable "variables" { + default = {} + description = "A map of custom variables." + type = map +} + +variable "hcl_vars" { + type = map + default = {} +} \ No newline at end of file diff --git a/versions.tf b/versions.tf index d9b6f79..6eff086 100644 --- a/versions.tf +++ b/versions.tf @@ -1,3 +1,6 @@ terraform { - required_version = ">= 0.12" -} + required_version = ">= 0.12.0" + required_providers { + + } +} \ No newline at end of file From 717d923cdc63c9e9321b236d021717f4a982ee9f Mon Sep 17 00:00:00 2001 From: pre-commit Date: Sun, 12 Jul 2020 15:46:01 +0000 Subject: [PATCH 14/38] pre-commit fixes --- README.md | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/README.md b/README.md index 05f1951..a86c830 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,47 @@ # terraform-tfc-workspace +<<<<<<< HEAD A Terraform module to easily create workspaces in Terraform Cloud. +======= + +## Requirements + +| Name | Version | +|------|---------| +| terraform | >= 0.12.0 | + +## Providers + +| Name | Version | +|------|---------| +| tfe | n/a | +>>>>>>> pre-commit fixes ## Inputs +<<<<<<< HEAD + +======= +| Name | Description | Type | Default | Required | +|------|-------------|------|---------|:--------:| +| auto\_apply | Whether to automatically apply changes when a Terraform plan is successful. Defaults to false. | `bool` | `false` | no | +| branch | The repository branch that Terraform will execute from. Default to master. | `any` | n/a | yes | +| hcl\_vars | n/a | `map` | `{}` | no | +| name | Name of the workspace. | `any` | n/a | yes | +| oauth\_token\_id | The OAuth token id for the VCS provider. | `any` | n/a | yes | +| organization | The name of the organization the workspace is under. | `any` | n/a | yes | +| repo | A reference to your VCS repository in the format :org/:repo where :org and :repo refer to the organization and repository in your VCS provider. | `any` | n/a | yes | +| secrets | A map of custom secrets. | `map` | `{}` | no | +| terraform\_version | The version of Terraform to use for this workspace. Defaults to the latest available version. | `string` | `"latest"` | no | +| variables | A map of custom variables. | `map` | `{}` | no | +| working\_directory | A relative path that Terraform will execute within. Defaults to the root of your repository. | `any` | n/a | yes | + +## Outputs + +| Name | Description | +|------|-------------| +| name | The name of the workspace. | + +>>>>>>> pre-commit fixes From cb7440ac7565456da2349005735366169e5253a9 Mon Sep 17 00:00:00 2001 From: Warren Brown Date: Sun, 12 Jul 2020 11:01:53 -0500 Subject: [PATCH 15/38] chore: added correct terraform version to terraform workflow --- .github/workflows/terraform.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/terraform.yaml b/.github/workflows/terraform.yaml index c1eec8b..8b38d22 100644 --- a/.github/workflows/terraform.yaml +++ b/.github/workflows/terraform.yaml @@ -18,6 +18,8 @@ jobs: - name: Install terraform uses: hashicorp/setup-terraform@v1 + with: + terraform_version: 0.12.0 - name: Terraform Init id: init From d2689ee5581b7b5b69a516da609fde19be80986d Mon Sep 17 00:00:00 2001 From: Warren Brown Date: Mon, 13 Jul 2020 11:30:58 -0500 Subject: [PATCH 16/38] chore: removed validate step in terraform workflow --- .github/workflows/terraform.yaml | 33 ++++++-------------------------- 1 file changed, 6 insertions(+), 27 deletions(-) diff --git a/.github/workflows/terraform.yaml b/.github/workflows/terraform.yaml index 8b38d22..3b96c32 100644 --- a/.github/workflows/terraform.yaml +++ b/.github/workflows/terraform.yaml @@ -8,14 +8,6 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - name: Set - Env Vars - id: setting_dev_env - env: - WORKING_DIRECTORY: ./test - run: | - echo Setting up enironment variables. - echo "::set-env name=WORKING_DIRECTORY::$WORKING_DIRECTORY" - - name: Install terraform uses: hashicorp/setup-terraform@v1 with: @@ -24,18 +16,11 @@ jobs: - name: Terraform Init id: init run: terraform init - working-directory: ${{env.WORKING_DIRECTORY}} - - - name: Terraform Validate - id: validate - run: terraform validate -no-color - working-directory: ${{env.WORKING_DIRECTORY}} - name: Terraform Plan id: plan run: terraform plan -no-color continue-on-error: true - working-directory: ${{env.WORKING_DIRECTORY}} - uses: actions/github-script@0.9.0 if: github.event_name == 'pull_request' @@ -44,13 +29,10 @@ jobs: with: github-token: ${{ secrets.GITHUB_TOKEN }} script: | - const tfInitStatus = ${{steps.init.outputs.exitcode == 0}} ? ':white_check_mark:' : ':x:' - const tfValidationStatus = ${{steps.validate.outputs.exitcode == 0}} ? ':white_check_mark:' : ':x:' - const tfPlanStatus = ${{steps.plan.outputs.exitcode == 0}} ? ':white_check_mark:' : ':x:' - - const output = `${tfInitStatus} Terraform Initialization - ${tfValidationStatus} Terraform Validation - ${tfPlanStatus} Terraform Plan + const output = `#### Terraform Format and Style 🖌\`${{ steps.fmt.outcome }}\` + #### Terraform Initialization ⚙️\`${{ steps.init.outcome }}\` + #### Terraform Validation 🤖${{ steps.validate.outputs.stdout }} + #### Terraform Plan 📖\`${{ steps.plan.outcome }}\`
Show Plan @@ -58,14 +40,11 @@ jobs:
- *User*: @${{ github.actor }} - *Action*: \`${{ github.event_name }}\` - *Working Directory*: \`${{ env.WORKING_DIRECTORY }}\` - *Workflow*: \`${{ github.workflow }}\``; + *Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`, Working Directory: \`${{ env.tf_actions_working_dir }}\`, Workflow: \`${{ github.workflow }}\`*`; github.issues.createComment({ issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, body: output - }) + }) \ No newline at end of file From 42ac6f7324f92526c10e59c20086e1528372f3e0 Mon Sep 17 00:00:00 2001 From: Warren Brown Date: Fri, 17 Jul 2020 17:30:59 -0500 Subject: [PATCH 17/38] chore: updated Readme --- README.md | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index a86c830..aa9c731 100644 --- a/README.md +++ b/README.md @@ -4,23 +4,35 @@ A Terraform module to easily create workspaces in Terraform Cloud. ======= -## Requirements - -| Name | Version | -|------|---------| -| terraform | >= 0.12.0 | - + ## Providers | Name | Version | |------|---------| | tfe | n/a | ->>>>>>> pre-commit fixes - ## Inputs -<<<<<<< HEAD +| Name | Description | Type | Default | Required | +|------|-------------|------|---------|:-----:| +| auto\_apply | Whether to automatically apply changes when a Terraform plan is successful. Defaults to false. | `bool` | `false` | no | +| branch | The repository branch that Terraform will execute from. Default to master. | `any` | n/a | yes | +| hcl\_vars | n/a | `map` | `{}` | no | +| name | Name of the workspace. | `any` | n/a | yes | +| oauth\_token\_id | The OAuth token id for the VCS provider. | `any` | n/a | yes | +| organization | The name of the organization the workspace is under. | `any` | n/a | yes | +| repo | A reference to your VCS repository in the format :org/:repo where :org and :repo refer to the organization and repository in your VCS provider. | `any` | n/a | yes | +| secrets | A map of custom secrets. | `map` | `{}` | no | +| terraform\_version | The version of Terraform to use for this workspace. Defaults to the latest available version. | `string` | `"latest"` | no | +| variables | A map of custom variables. | `map` | `{}` | no | +| working\_directory | A relative path that Terraform will execute within. Defaults to the root of your repository. | `any` | n/a | yes | + +## Outputs + +| Name | Description | +|------|-------------| +| name | The name of the workspace. | + ======= | Name | Description | Type | Default | Required | From b75fd9e3fff45459c7c51f1042553d55945cc8c0 Mon Sep 17 00:00:00 2001 From: Warren Brown Date: Sun, 19 Jul 2020 11:49:05 -0500 Subject: [PATCH 18/38] chore: updated readme and added required providers to module --- README.md | 28 +--------------------------- default.auto.tfvars | 3 +-- main.tf | 5 ----- variables.tf | 4 ++++ versions.tf | 2 +- 5 files changed, 7 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index aa9c731..11151f7 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,5 @@ # terraform-tfc-workspace -<<<<<<< HEAD -A Terraform module to easily create workspaces in Terraform Cloud. -======= - ## Providers @@ -17,6 +13,7 @@ A Terraform module to easily create workspaces in Terraform Cloud. |------|-------------|------|---------|:-----:| | auto\_apply | Whether to automatically apply changes when a Terraform plan is successful. Defaults to false. | `bool` | `false` | no | | branch | The repository branch that Terraform will execute from. Default to master. | `any` | n/a | yes | +| github\_tfe\_ssh\_key | The github ssh key for tfe | `any` | n/a | yes | | hcl\_vars | n/a | `map` | `{}` | no | | name | Name of the workspace. | `any` | n/a | yes | | oauth\_token\_id | The OAuth token id for the VCS provider. | `any` | n/a | yes | @@ -34,26 +31,3 @@ A Terraform module to easily create workspaces in Terraform Cloud. | name | The name of the workspace. | -======= -| Name | Description | Type | Default | Required | -|------|-------------|------|---------|:--------:| -| auto\_apply | Whether to automatically apply changes when a Terraform plan is successful. Defaults to false. | `bool` | `false` | no | -| branch | The repository branch that Terraform will execute from. Default to master. | `any` | n/a | yes | -| hcl\_vars | n/a | `map` | `{}` | no | -| name | Name of the workspace. | `any` | n/a | yes | -| oauth\_token\_id | The OAuth token id for the VCS provider. | `any` | n/a | yes | -| organization | The name of the organization the workspace is under. | `any` | n/a | yes | -| repo | A reference to your VCS repository in the format :org/:repo where :org and :repo refer to the organization and repository in your VCS provider. | `any` | n/a | yes | -| secrets | A map of custom secrets. | `map` | `{}` | no | -| terraform\_version | The version of Terraform to use for this workspace. Defaults to the latest available version. | `string` | `"latest"` | no | -| variables | A map of custom variables. | `map` | `{}` | no | -| working\_directory | A relative path that Terraform will execute within. Defaults to the root of your repository. | `any` | n/a | yes | - -## Outputs - -| Name | Description | -|------|-------------| -| name | The name of the workspace. | - - ->>>>>>> pre-commit fixes diff --git a/default.auto.tfvars b/default.auto.tfvars index 04e5fc9..14f4cb0 100644 --- a/default.auto.tfvars +++ b/default.auto.tfvars @@ -5,8 +5,7 @@ aws_default_region = "" aws_secret_access_key = "" oauth_token_id = "" -// Todo add organa -organization = "" +organization = "" vcs_repo = "katapultmedia/terraform-tfc-workspace" diff --git a/main.tf b/main.tf index a484744..b43d994 100644 --- a/main.tf +++ b/main.tf @@ -1,8 +1,3 @@ -data "tfe_ssh_key" "github" { - name = "github" - organization = var.organization -} - resource "tfe_workspace" "workspace" { name = var.name organization = var.organization diff --git a/variables.tf b/variables.tf index 55265d0..81a2eea 100644 --- a/variables.tf +++ b/variables.tf @@ -36,6 +36,10 @@ variable "working_directory" { description = "A relative path that Terraform will execute within. Defaults to the root of your repository." } +variable "github_tfe_ssh_key" { + description = "The github ssh key for tfe" +} + // App Vars variable "secrets" { diff --git a/versions.tf b/versions.tf index 6eff086..4de4e26 100644 --- a/versions.tf +++ b/versions.tf @@ -1,6 +1,6 @@ terraform { required_version = ">= 0.12.0" required_providers { - + aws = "~> 2.0" } } \ No newline at end of file From e0c12bc47d8331409c05f838e1354e103243d9eb Mon Sep 17 00:00:00 2001 From: Warren Brown Date: Sun, 19 Jul 2020 12:03:48 -0500 Subject: [PATCH 19/38] chore: updated ssh_key_id value --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index b43d994..47e67db 100644 --- a/main.tf +++ b/main.tf @@ -5,7 +5,7 @@ resource "tfe_workspace" "workspace" { auto_apply = var.auto_apply file_triggers_enabled = true queue_all_runs = true - ssh_key_id = data.tfe_ssh_key.github.id + ssh_key_id = var.github_tfe_ssh_key terraform_version = var.terraform_version working_directory = var.working_directory From 9ec13658ddbcf5c9f18cfc3d59cb5182b2955413 Mon Sep 17 00:00:00 2001 From: pre-commit Date: Sun, 19 Jul 2020 17:05:26 +0000 Subject: [PATCH 20/38] pre-commit fixes --- README.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 11151f7..cb1aec4 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,13 @@ # terraform-tfc-workspace +## Requirements + +| Name | Version | +|------|---------| +| terraform | >= 0.12.0 | +| aws | ~> 2.0 | + ## Providers | Name | Version | @@ -10,7 +17,7 @@ ## Inputs | Name | Description | Type | Default | Required | -|------|-------------|------|---------|:-----:| +|------|-------------|------|---------|:--------:| | auto\_apply | Whether to automatically apply changes when a Terraform plan is successful. Defaults to false. | `bool` | `false` | no | | branch | The repository branch that Terraform will execute from. Default to master. | `any` | n/a | yes | | github\_tfe\_ssh\_key | The github ssh key for tfe | `any` | n/a | yes | From 256c1d55b509635afaaec699cdccdd9e53c48659 Mon Sep 17 00:00:00 2001 From: Warren Brown Date: Sun, 19 Jul 2020 12:11:05 -0500 Subject: [PATCH 21/38] chore: added testing module to test folder and updated terraform.yaml --- .github/workflows/terraform.yaml | 35 ++++++++++++++++++++++++-------- test/main.tf | 4 ++-- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/.github/workflows/terraform.yaml b/.github/workflows/terraform.yaml index 3b96c32..c1eec8b 100644 --- a/.github/workflows/terraform.yaml +++ b/.github/workflows/terraform.yaml @@ -8,19 +8,32 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 + - name: Set - Env Vars + id: setting_dev_env + env: + WORKING_DIRECTORY: ./test + run: | + echo Setting up enironment variables. + echo "::set-env name=WORKING_DIRECTORY::$WORKING_DIRECTORY" + - name: Install terraform uses: hashicorp/setup-terraform@v1 - with: - terraform_version: 0.12.0 - name: Terraform Init id: init run: terraform init + working-directory: ${{env.WORKING_DIRECTORY}} + + - name: Terraform Validate + id: validate + run: terraform validate -no-color + working-directory: ${{env.WORKING_DIRECTORY}} - name: Terraform Plan id: plan run: terraform plan -no-color continue-on-error: true + working-directory: ${{env.WORKING_DIRECTORY}} - uses: actions/github-script@0.9.0 if: github.event_name == 'pull_request' @@ -29,10 +42,13 @@ jobs: with: github-token: ${{ secrets.GITHUB_TOKEN }} script: | - const output = `#### Terraform Format and Style 🖌\`${{ steps.fmt.outcome }}\` - #### Terraform Initialization ⚙️\`${{ steps.init.outcome }}\` - #### Terraform Validation 🤖${{ steps.validate.outputs.stdout }} - #### Terraform Plan 📖\`${{ steps.plan.outcome }}\` + const tfInitStatus = ${{steps.init.outputs.exitcode == 0}} ? ':white_check_mark:' : ':x:' + const tfValidationStatus = ${{steps.validate.outputs.exitcode == 0}} ? ':white_check_mark:' : ':x:' + const tfPlanStatus = ${{steps.plan.outputs.exitcode == 0}} ? ':white_check_mark:' : ':x:' + + const output = `${tfInitStatus} Terraform Initialization + ${tfValidationStatus} Terraform Validation + ${tfPlanStatus} Terraform Plan
Show Plan @@ -40,11 +56,14 @@ jobs:
- *Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`, Working Directory: \`${{ env.tf_actions_working_dir }}\`, Workflow: \`${{ github.workflow }}\`*`; + *User*: @${{ github.actor }} + *Action*: \`${{ github.event_name }}\` + *Working Directory*: \`${{ env.WORKING_DIRECTORY }}\` + *Workflow*: \`${{ github.workflow }}\``; github.issues.createComment({ issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, body: output - }) \ No newline at end of file + }) diff --git a/test/main.tf b/test/main.tf index a4149de..31020df 100644 --- a/test/main.tf +++ b/test/main.tf @@ -2,6 +2,6 @@ provider "aws" { region = "us-west-2" } -resource "null_resource" "test1" { - +module "core" { + source = "../" } From cded1530fb18ef915f56f412c75ba94e2639c247 Mon Sep 17 00:00:00 2001 From: Warren Brown Date: Sun, 19 Jul 2020 12:20:21 -0500 Subject: [PATCH 22/38] chore: updated test/main.tf --- README.md | 9 +-------- test/main.tf | 8 ++++++++ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index cb1aec4..11151f7 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,6 @@ # terraform-tfc-workspace -## Requirements - -| Name | Version | -|------|---------| -| terraform | >= 0.12.0 | -| aws | ~> 2.0 | - ## Providers | Name | Version | @@ -17,7 +10,7 @@ ## Inputs | Name | Description | Type | Default | Required | -|------|-------------|------|---------|:--------:| +|------|-------------|------|---------|:-----:| | auto\_apply | Whether to automatically apply changes when a Terraform plan is successful. Defaults to false. | `bool` | `false` | no | | branch | The repository branch that Terraform will execute from. Default to master. | `any` | n/a | yes | | github\_tfe\_ssh\_key | The github ssh key for tfe | `any` | n/a | yes | diff --git a/test/main.tf b/test/main.tf index 31020df..cfcd86a 100644 --- a/test/main.tf +++ b/test/main.tf @@ -4,4 +4,12 @@ provider "aws" { module "core" { source = "../" + + organization = "organization-test" + branch = "githubbranch-test" + github_tfe_ssh_key = "test-ssh-key" + working_directory = "tfe-workspace-working-dir" + name = "tfe-test-workspace" + oauth_token_id = "alkasiopejk" + repo = "tst-repo" } From 04d1e9f2ad3b08747ba5371dc761477864f40b4f Mon Sep 17 00:00:00 2001 From: pre-commit Date: Sun, 19 Jul 2020 17:21:06 +0000 Subject: [PATCH 23/38] pre-commit fixes --- README.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 11151f7..cb1aec4 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,13 @@ # terraform-tfc-workspace +## Requirements + +| Name | Version | +|------|---------| +| terraform | >= 0.12.0 | +| aws | ~> 2.0 | + ## Providers | Name | Version | @@ -10,7 +17,7 @@ ## Inputs | Name | Description | Type | Default | Required | -|------|-------------|------|---------|:-----:| +|------|-------------|------|---------|:--------:| | auto\_apply | Whether to automatically apply changes when a Terraform plan is successful. Defaults to false. | `bool` | `false` | no | | branch | The repository branch that Terraform will execute from. Default to master. | `any` | n/a | yes | | github\_tfe\_ssh\_key | The github ssh key for tfe | `any` | n/a | yes | From 4f959fa2f81e4f5c06b4d204da45ba239f123472 Mon Sep 17 00:00:00 2001 From: Warren Brown Date: Mon, 20 Jul 2020 16:28:41 -0500 Subject: [PATCH 24/38] chore: removed tf.vars file --- default.auto.tfvars | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 default.auto.tfvars diff --git a/default.auto.tfvars b/default.auto.tfvars deleted file mode 100644 index 14f4cb0..0000000 --- a/default.auto.tfvars +++ /dev/null @@ -1,11 +0,0 @@ -application_name = "" - -aws_access_key_id = "" -aws_default_region = "" -aws_secret_access_key = "" - -oauth_token_id = "" -organization = "" - - -vcs_repo = "katapultmedia/terraform-tfc-workspace" From 2ada61b9496f7f3ff023a72d2fccc6a9d207fd6d Mon Sep 17 00:00:00 2001 From: Warren Brown Date: Mon, 20 Jul 2020 16:48:24 -0500 Subject: [PATCH 25/38] chore: added tfe to required providers --- README.md | 11 ++--------- versions.tf | 2 +- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index cb1aec4..41bc80e 100644 --- a/README.md +++ b/README.md @@ -1,23 +1,16 @@ # terraform-tfc-workspace -## Requirements - -| Name | Version | -|------|---------| -| terraform | >= 0.12.0 | -| aws | ~> 2.0 | - ## Providers | Name | Version | |------|---------| -| tfe | n/a | +| tfe | ~> 0.15.0 | ## Inputs | Name | Description | Type | Default | Required | -|------|-------------|------|---------|:--------:| +|------|-------------|------|---------|:-----:| | auto\_apply | Whether to automatically apply changes when a Terraform plan is successful. Defaults to false. | `bool` | `false` | no | | branch | The repository branch that Terraform will execute from. Default to master. | `any` | n/a | yes | | github\_tfe\_ssh\_key | The github ssh key for tfe | `any` | n/a | yes | diff --git a/versions.tf b/versions.tf index 4de4e26..12babb1 100644 --- a/versions.tf +++ b/versions.tf @@ -1,6 +1,6 @@ terraform { required_version = ">= 0.12.0" required_providers { - aws = "~> 2.0" + tfe = "~> 0.15.0" } } \ No newline at end of file From a15118880aed5a85b49ea84b3656864bce2adb83 Mon Sep 17 00:00:00 2001 From: pre-commit Date: Mon, 20 Jul 2020 21:49:25 +0000 Subject: [PATCH 26/38] pre-commit fixes --- README.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 41bc80e..7a32c49 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,13 @@ # terraform-tfc-workspace +## Requirements + +| Name | Version | +|------|---------| +| terraform | >= 0.12.0 | +| tfe | ~> 0.15.0 | + ## Providers | Name | Version | @@ -10,7 +17,7 @@ ## Inputs | Name | Description | Type | Default | Required | -|------|-------------|------|---------|:-----:| +|------|-------------|------|---------|:--------:| | auto\_apply | Whether to automatically apply changes when a Terraform plan is successful. Defaults to false. | `bool` | `false` | no | | branch | The repository branch that Terraform will execute from. Default to master. | `any` | n/a | yes | | github\_tfe\_ssh\_key | The github ssh key for tfe | `any` | n/a | yes | From 1ac6927753124cecfa1c0f54b788e35d4d6f636f Mon Sep 17 00:00:00 2001 From: Warren Brown Date: Mon, 20 Jul 2020 16:58:04 -0500 Subject: [PATCH 27/38] chore: added tfe provider to test/main.tf --- test/main.tf | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/main.tf b/test/main.tf index cfcd86a..f5b1fc8 100644 --- a/test/main.tf +++ b/test/main.tf @@ -1,5 +1,7 @@ -provider "aws" { - region = "us-west-2" +variable "tfe_token" {} + +provider "tfe" { + token = var.tfe_token } module "core" { From ccb95b00068236b66c29846d0aeb92de8bbbb4b6 Mon Sep 17 00:00:00 2001 From: Warren Brown Date: Tue, 21 Jul 2020 15:50:43 -0500 Subject: [PATCH 28/38] chore: changed varibles --- README.md | 11 ++--------- main.tf | 2 +- test/config.tf | 14 ++++++++++++++ test/main.tf | 23 ++++++++++++----------- variables.tf | 2 +- 5 files changed, 30 insertions(+), 22 deletions(-) create mode 100644 test/config.tf diff --git a/README.md b/README.md index 7a32c49..2d0b89f 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,6 @@ # terraform-tfc-workspace -## Requirements - -| Name | Version | -|------|---------| -| terraform | >= 0.12.0 | -| tfe | ~> 0.15.0 | - ## Providers | Name | Version | @@ -17,16 +10,16 @@ ## Inputs | Name | Description | Type | Default | Required | -|------|-------------|------|---------|:--------:| +|------|-------------|------|---------|:-----:| | auto\_apply | Whether to automatically apply changes when a Terraform plan is successful. Defaults to false. | `bool` | `false` | no | | branch | The repository branch that Terraform will execute from. Default to master. | `any` | n/a | yes | -| github\_tfe\_ssh\_key | The github ssh key for tfe | `any` | n/a | yes | | hcl\_vars | n/a | `map` | `{}` | no | | name | Name of the workspace. | `any` | n/a | yes | | oauth\_token\_id | The OAuth token id for the VCS provider. | `any` | n/a | yes | | organization | The name of the organization the workspace is under. | `any` | n/a | yes | | repo | A reference to your VCS repository in the format :org/:repo where :org and :repo refer to the organization and repository in your VCS provider. | `any` | n/a | yes | | secrets | A map of custom secrets. | `map` | `{}` | no | +| ssh\_key | The github ssh key for tfe | `any` | n/a | yes | | terraform\_version | The version of Terraform to use for this workspace. Defaults to the latest available version. | `string` | `"latest"` | no | | variables | A map of custom variables. | `map` | `{}` | no | | working\_directory | A relative path that Terraform will execute within. Defaults to the root of your repository. | `any` | n/a | yes | diff --git a/main.tf b/main.tf index 47e67db..970589d 100644 --- a/main.tf +++ b/main.tf @@ -5,7 +5,7 @@ resource "tfe_workspace" "workspace" { auto_apply = var.auto_apply file_triggers_enabled = true queue_all_runs = true - ssh_key_id = var.github_tfe_ssh_key + ssh_key_id = var.ssh_key terraform_version = var.terraform_version working_directory = var.working_directory diff --git a/test/config.tf b/test/config.tf new file mode 100644 index 0000000..07df49f --- /dev/null +++ b/test/config.tf @@ -0,0 +1,14 @@ +terraform { + backend "remote" { + hostname = "app.terraform.io" + organization = "km-sandbox" + + workspaces { + name = "terraform-tfc-workspace" + } + } +} + +provider "tfe" { + token = var.tfe_token +} \ No newline at end of file diff --git a/test/main.tf b/test/main.tf index f5b1fc8..461cf3a 100644 --- a/test/main.tf +++ b/test/main.tf @@ -1,17 +1,18 @@ -variable "tfe_token" {} - -provider "tfe" { - token = var.tfe_token +variable "tfe_token" { + default = "" +} +variable "ssh_key" { + default = "" } module "core" { source = "../" - organization = "organization-test" - branch = "githubbranch-test" - github_tfe_ssh_key = "test-ssh-key" - working_directory = "tfe-workspace-working-dir" - name = "tfe-test-workspace" - oauth_token_id = "alkasiopejk" - repo = "tst-repo" + organization = "organization-test" + branch = "master" + ssh_key = var.ssh_key + working_directory = "/test" + name = "terraform-tfc-workspace" + oauth_token_id = "alkasiopejk" + repo = "katapultmedia/terraform-tfc-workspace" } diff --git a/variables.tf b/variables.tf index 81a2eea..60445a9 100644 --- a/variables.tf +++ b/variables.tf @@ -36,7 +36,7 @@ variable "working_directory" { description = "A relative path that Terraform will execute within. Defaults to the root of your repository." } -variable "github_tfe_ssh_key" { +variable "ssh_key" { description = "The github ssh key for tfe" } From ae3f970c26c722e1feb0958fde71e72e303bc575 Mon Sep 17 00:00:00 2001 From: pre-commit Date: Tue, 21 Jul 2020 20:54:06 +0000 Subject: [PATCH 29/38] pre-commit fixes --- README.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2d0b89f..ce5b615 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,13 @@ # terraform-tfc-workspace +## Requirements + +| Name | Version | +|------|---------| +| terraform | >= 0.12.0 | +| tfe | ~> 0.15.0 | + ## Providers | Name | Version | @@ -10,7 +17,7 @@ ## Inputs | Name | Description | Type | Default | Required | -|------|-------------|------|---------|:-----:| +|------|-------------|------|---------|:--------:| | auto\_apply | Whether to automatically apply changes when a Terraform plan is successful. Defaults to false. | `bool` | `false` | no | | branch | The repository branch that Terraform will execute from. Default to master. | `any` | n/a | yes | | hcl\_vars | n/a | `map` | `{}` | no | From 3a026cbb83b54393c52cbe62b14b4aabe0150cf9 Mon Sep 17 00:00:00 2001 From: Warren Brown Date: Mon, 10 Aug 2020 12:58:06 -0500 Subject: [PATCH 30/38] chore: removed provider from config file --- test/config.tf | 4 ---- 1 file changed, 4 deletions(-) diff --git a/test/config.tf b/test/config.tf index 07df49f..3ea49b6 100644 --- a/test/config.tf +++ b/test/config.tf @@ -7,8 +7,4 @@ terraform { name = "terraform-tfc-workspace" } } -} - -provider "tfe" { - token = var.tfe_token } \ No newline at end of file From 0e4241bc7cf335e41557de2c2b6c279e36e95ff9 Mon Sep 17 00:00:00 2001 From: Warren Brown Date: Mon, 10 Aug 2020 13:01:21 -0500 Subject: [PATCH 31/38] chore: added TFE token to terraform workflow --- .github/workflows/terraform.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/terraform.yaml b/.github/workflows/terraform.yaml index c1eec8b..de295fe 100644 --- a/.github/workflows/terraform.yaml +++ b/.github/workflows/terraform.yaml @@ -18,6 +18,8 @@ jobs: - name: Install terraform uses: hashicorp/setup-terraform@v1 + with: + cli_config_credentials_token: ${{ secrets.TFE_TOKEN }} - name: Terraform Init id: init From ef984e19d6591855d5ea1280a758c09e0a84c3a3 Mon Sep 17 00:00:00 2001 From: Warren Brown Date: Mon, 10 Aug 2020 13:10:51 -0500 Subject: [PATCH 32/38] chore: updated TFE token --- README.md | 9 +-------- test/config.tf | 4 ++++ 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index ce5b615..2d0b89f 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,6 @@ # terraform-tfc-workspace -## Requirements - -| Name | Version | -|------|---------| -| terraform | >= 0.12.0 | -| tfe | ~> 0.15.0 | - ## Providers | Name | Version | @@ -17,7 +10,7 @@ ## Inputs | Name | Description | Type | Default | Required | -|------|-------------|------|---------|:--------:| +|------|-------------|------|---------|:-----:| | auto\_apply | Whether to automatically apply changes when a Terraform plan is successful. Defaults to false. | `bool` | `false` | no | | branch | The repository branch that Terraform will execute from. Default to master. | `any` | n/a | yes | | hcl\_vars | n/a | `map` | `{}` | no | diff --git a/test/config.tf b/test/config.tf index 3ea49b6..07df49f 100644 --- a/test/config.tf +++ b/test/config.tf @@ -7,4 +7,8 @@ terraform { name = "terraform-tfc-workspace" } } +} + +provider "tfe" { + token = var.tfe_token } \ No newline at end of file From 1489dbfc19216d54820f6db6592d16e7e5cb8ea4 Mon Sep 17 00:00:00 2001 From: pre-commit Date: Mon, 10 Aug 2020 18:11:35 +0000 Subject: [PATCH 33/38] pre-commit fixes --- README.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2d0b89f..ce5b615 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,13 @@ # terraform-tfc-workspace +## Requirements + +| Name | Version | +|------|---------| +| terraform | >= 0.12.0 | +| tfe | ~> 0.15.0 | + ## Providers | Name | Version | @@ -10,7 +17,7 @@ ## Inputs | Name | Description | Type | Default | Required | -|------|-------------|------|---------|:-----:| +|------|-------------|------|---------|:--------:| | auto\_apply | Whether to automatically apply changes when a Terraform plan is successful. Defaults to false. | `bool` | `false` | no | | branch | The repository branch that Terraform will execute from. Default to master. | `any` | n/a | yes | | hcl\_vars | n/a | `map` | `{}` | no | From c293914622648aca0d15c29058a3cde41923d99f Mon Sep 17 00:00:00 2001 From: Warren Brown Date: Tue, 8 Sep 2020 07:50:50 -0500 Subject: [PATCH 34/38] chore: Added outputs for workspace resource --- README.md | 17 +++++++++-------- main.tf | 11 +++++------ outputs.tf | 30 ++++++++++++++++++++++++++++++ variables.tf | 8 ++++++++ 4 files changed, 52 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index ce5b615..121c7fd 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,6 @@ # terraform-tfc-workspace -## Requirements - -| Name | Version | -|------|---------| -| terraform | >= 0.12.0 | -| tfe | ~> 0.15.0 | - ## Providers | Name | Version | @@ -17,13 +10,15 @@ ## Inputs | Name | Description | Type | Default | Required | -|------|-------------|------|---------|:--------:| +|------|-------------|------|---------|:-----:| | auto\_apply | Whether to automatically apply changes when a Terraform plan is successful. Defaults to false. | `bool` | `false` | no | | branch | The repository branch that Terraform will execute from. Default to master. | `any` | n/a | yes | +| file\_triggers\_enabled | n/a | `bool` | `true` | no | | hcl\_vars | n/a | `map` | `{}` | no | | name | Name of the workspace. | `any` | n/a | yes | | oauth\_token\_id | The OAuth token id for the VCS provider. | `any` | n/a | yes | | organization | The name of the organization the workspace is under. | `any` | n/a | yes | +| queue\_all\_runs | n/a | `bool` | `true` | no | | repo | A reference to your VCS repository in the format :org/:repo where :org and :repo refer to the organization and repository in your VCS provider. | `any` | n/a | yes | | secrets | A map of custom secrets. | `map` | `{}` | no | | ssh\_key | The github ssh key for tfe | `any` | n/a | yes | @@ -35,6 +30,12 @@ | Name | Description | |------|-------------| +| auto\_apply | Whether to automatically apply changes when a Terraform plan is successful. Defaults to false. | +| branch | The repository branch that Terraform will execute from. Default to master. | +| identifier | A reference to your VCS repository in the format :org/:repo where :org and :repo refer to the organization and repository in your VCS provider. | | name | The name of the workspace. | +| organization | The name of the organization the workspace is under. | +| terraform\_version | The version of Terraform to use for this workspace. Defaults to the latest available version. | +| working\_directory | A relative path that Terraform will execute within. Defaults to the root of your repository. | diff --git a/main.tf b/main.tf index 970589d..fc88387 100644 --- a/main.tf +++ b/main.tf @@ -2,12 +2,11 @@ resource "tfe_workspace" "workspace" { name = var.name organization = var.organization - auto_apply = var.auto_apply - file_triggers_enabled = true - queue_all_runs = true - ssh_key_id = var.ssh_key - terraform_version = var.terraform_version - working_directory = var.working_directory + auto_apply = var.auto_apply + + ssh_key_id = var.ssh_key + terraform_version = var.terraform_version + working_directory = var.working_directory vcs_repo { identifier = var.repo diff --git a/outputs.tf b/outputs.tf index fb6de8a..ed7050a 100644 --- a/outputs.tf +++ b/outputs.tf @@ -1,4 +1,34 @@ output "name" { description = "The name of the workspace." value = var.name +} + +output "organization" { + description = "The name of the organization the workspace is under." + value = var.organization +} + +output "auto_apply" { + description = "Whether to automatically apply changes when a Terraform plan is successful. Defaults to false." + value = var.auto_apply +} + +output "terraform_version" { + description = "The version of Terraform to use for this workspace. Defaults to the latest available version." + value = var.terraform_version +} + +output "working_directory" { + description = "A relative path that Terraform will execute within. Defaults to the root of your repository." + value = var.working_directory +} + +output "identifier" { + description = "A reference to your VCS repository in the format :org/:repo where :org and :repo refer to the organization and repository in your VCS provider." + value = var.repo +} + +output "branch" { + description = "The repository branch that Terraform will execute from. Default to master." + value = var.branch } \ No newline at end of file diff --git a/variables.tf b/variables.tf index 60445a9..20d3bfc 100644 --- a/variables.tf +++ b/variables.tf @@ -57,4 +57,12 @@ variable "variables" { variable "hcl_vars" { type = map default = {} +} + +variable "file_triggers_enabled" { + default = true +} + +variable "queue_all_runs" { + default = true } \ No newline at end of file From bff439ea0e4aaadd008178eddc650af8bb1adc99 Mon Sep 17 00:00:00 2001 From: pre-commit Date: Tue, 8 Sep 2020 12:51:33 +0000 Subject: [PATCH 35/38] pre-commit fixes --- README.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 121c7fd..d8086ec 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,13 @@ # terraform-tfc-workspace +## Requirements + +| Name | Version | +|------|---------| +| terraform | >= 0.12.0 | +| tfe | ~> 0.15.0 | + ## Providers | Name | Version | @@ -10,7 +17,7 @@ ## Inputs | Name | Description | Type | Default | Required | -|------|-------------|------|---------|:-----:| +|------|-------------|------|---------|:--------:| | auto\_apply | Whether to automatically apply changes when a Terraform plan is successful. Defaults to false. | `bool` | `false` | no | | branch | The repository branch that Terraform will execute from. Default to master. | `any` | n/a | yes | | file\_triggers\_enabled | n/a | `bool` | `true` | no | From 96b49a1ea1b4174b8e85fd40fc488189c79fa01d Mon Sep 17 00:00:00 2001 From: Warren Brown Date: Tue, 8 Sep 2020 07:57:18 -0500 Subject: [PATCH 36/38] chore: fixed new variables --- README.md | 1 + main.tf | 13 +++++++------ variables.tf | 4 ++++ 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index d8086ec..3952646 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,7 @@ | branch | The repository branch that Terraform will execute from. Default to master. | `any` | n/a | yes | | file\_triggers\_enabled | n/a | `bool` | `true` | no | | hcl\_vars | n/a | `map` | `{}` | no | +| ingress\_submodules | n/a | `bool` | `false` | no | | name | Name of the workspace. | `any` | n/a | yes | | oauth\_token\_id | The OAuth token id for the VCS provider. | `any` | n/a | yes | | organization | The name of the organization the workspace is under. | `any` | n/a | yes | diff --git a/main.tf b/main.tf index fc88387..a1d02e8 100644 --- a/main.tf +++ b/main.tf @@ -2,16 +2,17 @@ resource "tfe_workspace" "workspace" { name = var.name organization = var.organization - auto_apply = var.auto_apply - - ssh_key_id = var.ssh_key - terraform_version = var.terraform_version - working_directory = var.working_directory + auto_apply = var.auto_apply + file_triggers_enabled = var.file_triggers_enabled + queue_all_runs = var.queue_all_runs + ssh_key_id = var.ssh_key + terraform_version = var.terraform_version + working_directory = var.working_directory vcs_repo { identifier = var.repo branch = var.branch - ingress_submodules = false + ingress_submodules = var.ingress_submodules oauth_token_id = var.oauth_token_id } } diff --git a/variables.tf b/variables.tf index 20d3bfc..fd9988e 100644 --- a/variables.tf +++ b/variables.tf @@ -32,6 +32,10 @@ variable "branch" { description = "The repository branch that Terraform will execute from. Default to master." } +variable "ingress_submodules" { + default = false +} + variable "working_directory" { description = "A relative path that Terraform will execute within. Defaults to the root of your repository." } From bce44a4a0f4ddabba346d299696e736cf4ae5d61 Mon Sep 17 00:00:00 2001 From: Warren Brown Date: Tue, 8 Sep 2020 08:26:03 -0500 Subject: [PATCH 37/38] chore: added provider to test/main.tf --- README.md | 9 +-------- test/main.tf | 4 ++++ 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 3952646..9d4db7a 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,6 @@ # terraform-tfc-workspace -## Requirements - -| Name | Version | -|------|---------| -| terraform | >= 0.12.0 | -| tfe | ~> 0.15.0 | - ## Providers | Name | Version | @@ -17,7 +10,7 @@ ## Inputs | Name | Description | Type | Default | Required | -|------|-------------|------|---------|:--------:| +|------|-------------|------|---------|:-----:| | auto\_apply | Whether to automatically apply changes when a Terraform plan is successful. Defaults to false. | `bool` | `false` | no | | branch | The repository branch that Terraform will execute from. Default to master. | `any` | n/a | yes | | file\_triggers\_enabled | n/a | `bool` | `true` | no | diff --git a/test/main.tf b/test/main.tf index 461cf3a..b25b35a 100644 --- a/test/main.tf +++ b/test/main.tf @@ -1,3 +1,7 @@ +provider "aws" { + region = "us-west-1" +} + variable "tfe_token" { default = "" } From 1f188b7baef8fbd0a071681f09b033cca147d3bd Mon Sep 17 00:00:00 2001 From: pre-commit Date: Tue, 8 Sep 2020 13:26:57 +0000 Subject: [PATCH 38/38] pre-commit fixes --- README.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9d4db7a..3952646 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,13 @@ # terraform-tfc-workspace +## Requirements + +| Name | Version | +|------|---------| +| terraform | >= 0.12.0 | +| tfe | ~> 0.15.0 | + ## Providers | Name | Version | @@ -10,7 +17,7 @@ ## Inputs | Name | Description | Type | Default | Required | -|------|-------------|------|---------|:-----:| +|------|-------------|------|---------|:--------:| | auto\_apply | Whether to automatically apply changes when a Terraform plan is successful. Defaults to false. | `bool` | `false` | no | | branch | The repository branch that Terraform will execute from. Default to master. | `any` | n/a | yes | | file\_triggers\_enabled | n/a | `bool` | `true` | no |