File tree Expand file tree Collapse file tree 5 files changed +55
-17
lines changed
tests/workflows/test-validate Expand file tree Collapse file tree 5 files changed +55
-17
lines changed Original file line number Diff line number Diff line change 8787
8888 git_no_credentials :
8989 runs-on : ubuntu-latest
90- name : git_http no creds
90+ name : git+http no creds
9191 steps :
9292 - name : Checkout
9393 uses : actions/checkout@v2
Original file line number Diff line number Diff line change 5252
5353 validate_workspace :
5454 runs-on : ubuntu-latest
55- name : Use workspace name during validationg
55+ name : Use workspace name during validation
5656 steps :
5757 - name : Checkout
5858 uses : actions/checkout@v2
8787 echo "::error:: failure-reason not set correctly"
8888 exit 1
8989 fi
90+
91+ validate_remote_workspace :
92+ runs-on : ubuntu-latest
93+ name : Use workspace name during validation
94+ steps :
95+ - name : Checkout
96+ uses : actions/checkout@v2
97+
98+ - name : validate prod
99+ uses : ./terraform-validate
100+ with :
101+ path : tests/workflows/test-validate/workspace_eval_remote
102+ workspace : prod
Original file line number Diff line number Diff line change @@ -11,12 +11,18 @@ setup
1111# How do you get a full validation report? You can't.
1212
1313# terraform.workspace will be evaluated during a validate, but it is not initialized properly.
14- # Pass through the workspace input, even if it doesn't make sense for some backends.
14+ # Pass through the workspace input, except for remote backend where it should be 'default'
15+
16+ if [[ " $TERRAFORM_BACKEND_TYPE " == " remote" ]]; then
17+ TF_WORKSPACE=" default"
18+ else
19+ TF_WORKSPACE=" $INPUT_WORKSPACE "
20+ fi
1521
1622init || true
1723
18- if ! (cd " $INPUT_PATH " && TF_WORKSPACE=" $INPUT_WORKSPACE " terraform validate -json | convert_validate_report " $INPUT_PATH " ); then
19- (cd " $INPUT_PATH " && TF_WORKSPACE=" $INPUT_WORKSPACE " terraform validate)
24+ if ! (cd " $INPUT_PATH " && TF_WORKSPACE=" $TF_WORKSPACE " terraform validate -json | convert_validate_report " $INPUT_PATH " ); then
25+ (cd " $INPUT_PATH " && TF_WORKSPACE=" $TF_WORKSPACE " terraform validate)
2026else
2127 echo -e " \033[1;32mSuccess!\033[0m The configuration is valid"
2228fi
Original file line number Diff line number Diff line change @@ -22,15 +22,3 @@ provider "aws" {
2222resource "aws_s3_bucket" "bucket" {
2323 bucket = " hello"
2424}
25-
26- terraform {
27- backend "remote" {
28- hostname = " app.terraform.io"
29- organization = " flooktech"
30-
31- workspaces {
32- name = " banana"
33- }
34- }
35- }
36-
Original file line number Diff line number Diff line change 1+ locals {
2+ aws_provider_config = {
3+ default = {
4+ region = " ..."
5+ account_id = " ..."
6+ profile = " ..."
7+ }
8+ }
9+ }
10+
11+ provider "aws" {
12+ region = local. aws_provider_config [terraform . workspace ]. region
13+ profile = local. aws_provider_config [terraform . workspace ]. profile
14+ allowed_account_ids = [local . aws_provider_config [terraform . workspace ]. account_id ]
15+ }
16+
17+ resource "aws_s3_bucket" "bucket" {
18+ bucket = " hello"
19+ }
20+
21+ terraform {
22+ backend "remote" {
23+ hostname = " app.terraform.io"
24+ organization = " flooktech"
25+
26+ workspaces {
27+ name = " banana"
28+ }
29+ }
30+ }
31+
You can’t perform that action at this time.
0 commit comments