-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(DMVP-2224): fix backslash issue in generated code and made variab…
…les optional
- Loading branch information
1 parent
5d8ea12
commit 84a8da6
Showing
15 changed files
with
203 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
locals { | ||
module_path = path.module | ||
file_contents = file("${path.module}/../../../tests/debug-escape-issue/example-infra/module-3.yaml") | ||
yaml = yamldecode(local.file_contents) | ||
|
||
variables = local.yaml.variables | ||
modules = local.yaml.linked_workspaces | ||
modules_string = join("|", local.modules) | ||
|
||
# "${module-1.variable-1}" # => "${data.tfe_outputs.this["module-1"].values.variable-1}" | ||
# module-1 => data.tfe_outputs.this["module-1"].values | ||
# result: "${data.tfe_outputs.this[\"module-1\"].values.result.variable-1}" | ||
|
||
modules_with_values = { | ||
for value in local.modules : value => "data.tfe_outputs.this[\"${value}\"].values" | ||
} | ||
|
||
variables_encoded = { | ||
for key, value in local.variables : key => jsonencode(value) | ||
} | ||
|
||
# variables_example = { | ||
# "variable-1" = "\"${module-1.variable-1}\"" | ||
# "variable-2" = "\"something ${module-1.variable-1} and ${module-2.variable-1} else\"" | ||
# "variable-3" = "\"module 2 ${module-2.variable-1} else\"" | ||
# "variable-4" = "\"module 1 ${module-1.variable-1} else\"" | ||
# "variable-7" = "\"module 1 ${module-3.variable-1} else\"" | ||
# "variable-list-5" = "[\"module 2 ${module-2.variable-1} else\",\"module 1 ${module-1.variable-1} else\"]" | ||
# "variable-object-6" = "{\"module 2 ${module-2.variable-1} else\":\"module 1 ${module-1.variable-1} else\"}" | ||
# } | ||
whatever = "/(module-1|module-2|module-3)/data.tfe_outputs.this[\"$1\"].values" | ||
# modules_example = { | ||
# "module-1" = "data.tfe_outputs.this[\"module-1\"].values" | ||
# "module-2" = "data.tfe_outputs.this[\"module-2\"].values" | ||
# } | ||
|
||
variables_replaced = { | ||
for key, value in local.variables_encoded : key => replace(value, "/(${local.modules_string})/", "data.tfe_outputs.this[\\\"$1\\\"].values") | ||
# reduce(str, [for k, v in local.replacements : {search = k, replace = v}], | ||
# function(acc, values) { | ||
# replace(acc, values.search, values.replace) | ||
# } | ||
# ) | ||
} | ||
|
||
variables_final = { | ||
for key, value in local.variables_replaced : key => jsondecode(value) | ||
} | ||
|
||
json = jsondecode("\"a\\\"b\"") | ||
|
||
contents = templatefile("template.tftpl", { | ||
variables = local.variables_final | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
asdqwe | ||
|
||
%{ for key, value in variables } | ||
${key} = ${replace(jsonencode(value), "\\", "")}%{ endfor ~} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,14 @@ | ||
run: | ||
mkdir _tfc | ||
cd _tfc && \ | ||
terraform init \ | ||
-backend-config="organization=dasmeta-testing" \ | ||
-backend-config="workspaces.name=testing-infrastructure" \ | ||
-from-module="github.com/dasmeta/terraform-tfe-cloud.git?ref=DMVP-2598-simplify-tfe-use" | ||
run-via-docker: | ||
docker run -it \ | ||
-v $(pwd):/build \ | ||
-e GIT_TOKEN="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" \ | ||
-e TERRAFORM_CLOUD_TOKEN="ojODA5TvvwpL1A.atlasv1.6ifl0D5Q3zaonS3GPc5aXSLo4HWxCScaXf3u0sSVy4Eb4I62HAcs75W9l4EO9iBkFyE" \ | ||
-e AWS_ACCESS_KEY_ID="54567898656" \ | ||
-e AWS_SECRET_ACCESS_KEY="54567898656" \ | ||
-e AWS_DEFAULT_REGION="54567898656" \ | ||
dasmeta/meta create | ||
|
||
export TF_VAR_git_token=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 | ||
export TF_VAR_tfc_token=ojODA5TvvwpL1A.atlasv1.6ifl0D5Q3zaonS3GPc5aXSLo4HWxCScaXf3u0sSVy4Eb4I62HAcs75W9l4EO9iBkFyE | ||
export TFE_TOKEN=ojODA5TvvwpL1A.atlasv1.6ifl0D5Q3zaonS3GPc5aXSLo4HWxCScaXf3u0sSVy4Eb4I62HAcs75W9l4EO9iBkFyE | ||
export TF_TOKEN_app_terraform_io=ojODA5TvvwpL1A.atlasv1.6ifl0D5Q3zaonS3GPc5aXSLo4HWxCScaXf3u0sSVy4Eb4I62HAcs75W9l4EO9iBkFyE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
terraform { | ||
cloud { | ||
organization = "dasmeta-testing" | ||
workspaces { | ||
name = "terraform-tfe-cloud-test" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
variable "tfc_token" {} | ||
variable "git_token" {} | ||
|
||
module "basic" { | ||
source = "../.." | ||
|
||
org = "dasmeta-testing" | ||
token = var.tfc_token | ||
|
||
rootdir = "_terraform" | ||
targetdir = "_terraform" | ||
yamldir = "." | ||
|
||
git_provider = "github" | ||
git_org = "dasmeta-testing" | ||
git_repo = "test-infrastructure" | ||
git_token = var.git_token | ||
|
||
aws = { | ||
access_key_id = "" | ||
secret_access_key = "" | ||
default_region = "" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
source: dasmeta/null/empty | ||
version: 1.2.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
source: dasmeta/null/empty | ||
version: 1.2.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
source: dasmeta/null/empty | ||
version: 1.2.1 | ||
variables: | ||
static: "Vahagn" | ||
variable-1: "Vahagn ${module-1.variable-1}" # => "Vahagn ${data.tfe_outputs.this["module-1"].values.variable-1}" | ||
# module-1 => data.tfe_outputs.this["module-1"].values | ||
# result: "${data.tfe_outputs.this[\"module-1\"].values.result.variable-1}" | ||
variable-2: "something ${module-1.variable-1} and ${module-2.variable-1} else" | ||
variable-3: "module 2 ${module-2.variable-1} else" | ||
variable-4: "module 1 ${module-1.variable-1} else" | ||
variable-list-5: [ | ||
"module 2 ${module-2.variable-1} else", | ||
"module 1 ${module-1.variable-1} else" | ||
] | ||
variable-object-6: { | ||
"module 2 ${module-2.variable-1} else": "module 1 ${module-1.variable-1} else" | ||
} | ||
variable-7: "module 1 ${module-3.variable-1} else" # => "module 1 ${module-3.variable-1} else" | ||
linked_workspaces: | ||
- module-1 | ||
- module-2 | ||
- 1-environments/dev-1/eks | ||
providers: | ||
- name: kubernetes | ||
version: ~> 2.23 | ||
module_nested_provider: true | ||
source: "hashicorp/kubernetes" | ||
variables: | ||
cluster_ca_certificate: ${1-environments/dev-1/eks.cluster_certificate} | ||
host: ${1-environments/dev-1/eks.cluster_host} | ||
token: ${1-environments/dev-1/eks.cluster_token} | ||
blocks: | ||
exec: | ||
api_version: "client.authentication.k8s.io/v1beta1" | ||
args: | ||
- "eks" | ||
- "--region" | ||
- "eu-central-1" | ||
- "get-token" | ||
- "--cluster-name" | ||
- ${1-environments/dev-1/eks.cluster_name} | ||
command: "aws" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
terraform { | ||
cloud { | ||
organization = "dasmeta-testing" | ||
workspaces { | ||
name = "terraform-tfe-cloud-test" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
variable "tfc_token" {} | ||
variable "git_token" {} | ||
|
||
module "basic" { | ||
source = "../.." | ||
|
||
org = "dasmeta-testing" | ||
token = var.tfc_token | ||
|
||
rootdir = "_terraform" | ||
targetdir = "_terraform" | ||
yamldir = "." | ||
|
||
git_provider = "github" | ||
git_org = "dasmeta-testing" | ||
git_repo = "test-infrastructure" | ||
git_token = var.git_token | ||
|
||
aws = { | ||
access_key_id = "" | ||
secret_access_key = "" | ||
default_region = "" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters