From 2c46465d6e88c09082aec5d350e73020074dee6d Mon Sep 17 00:00:00 2001 From: David Sibley Date: Mon, 7 Aug 2023 13:02:12 +0100 Subject: [PATCH 1/8] added variable and condition for creating tfvars when parsing non-core accounts --- scripts/provision-environment-directories.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/provision-environment-directories.sh b/scripts/provision-environment-directories.sh index 985c87c0b..5f103dbe4 100755 --- a/scripts/provision-environment-directories.sh +++ b/scripts/provision-environment-directories.sh @@ -33,6 +33,7 @@ provision_environment_directories() { networking_definitions=$(jq -n '[ inputs | { subnet_sets: .cidr.subnet_sets | to_entries | map_values(.value + { set: .key, "business-unit": input_filename | ltrimstr("environments-networks/") | rtrimstr(".json") | split("-")[0] } ) } ]' "$networkdir"/*.json) for file in ${environments}/*.json; do + account_type=$(jq -r '."account-type"' "$file") application_name=$(basename "$file" .json) directory=$basedir/$application_name @@ -77,7 +78,10 @@ provision_environment_directories() { RAW_OUTPUT=`jq -n --arg APPLICATION_NAME "$application_name" '{ "business-unit": "", "set": "", "application": $APPLICATION_NAME }'` fi # wrap raw json output with a header and store the result in the applications folder - jq -rn --argjson DATA "${RAW_OUTPUT}" '{ networking: [ $DATA ] }' > "$directory"/networking.auto.tfvars.json + # Only populate networking.auto.tfvars.json if account type is not core + if [ "$account_type" != "core" ]; then + jq -rn --argjson DATA "${RAW_OUTPUT}" '{ networking: [ $DATA ] }' > "$directory"/networking.auto.tfvars.json + fi done } From ce206d5a3c7e63e9799514f359bf4c3f2c8420b0 Mon Sep 17 00:00:00 2001 From: David Sibley Date: Mon, 7 Aug 2023 13:10:09 +0100 Subject: [PATCH 2/8] removed core account tfvars, added conditional logic to provision-member-directories.sh for consistency --- scripts/provision-member-directories.sh | 7 ++++++- .../core-logging/networking.auto.tfvars.json | 9 --------- .../core-network-services/networking.auto.tfvars.json | 9 --------- .../core-sandbox/networking.auto.tfvars.json | 9 --------- .../core-security/networking.auto.tfvars.json | 9 --------- .../core-shared-services/networking.auto.tfvars.json | 9 --------- .../environments/core-vpc/networking.auto.tfvars.json | 9 --------- 7 files changed, 6 insertions(+), 55 deletions(-) delete mode 100644 terraform/environments/core-logging/networking.auto.tfvars.json delete mode 100644 terraform/environments/core-network-services/networking.auto.tfvars.json delete mode 100644 terraform/environments/core-sandbox/networking.auto.tfvars.json delete mode 100644 terraform/environments/core-security/networking.auto.tfvars.json delete mode 100644 terraform/environments/core-shared-services/networking.auto.tfvars.json delete mode 100644 terraform/environments/core-vpc/networking.auto.tfvars.json diff --git a/scripts/provision-member-directories.sh b/scripts/provision-member-directories.sh index b529a1228..aa088ab96 100755 --- a/scripts/provision-member-directories.sh +++ b/scripts/provision-member-directories.sh @@ -45,6 +45,8 @@ provision_environment_directories() { echo "This is file: $file" application_name=$(basename "$file" .json) echo "This is the application name: $application_name" + account_type=$(jq -r '."account-type"' "$file") + echo "This is a " $account_type " account" directory=$basedir/$application_name echo "This is the directory: $directory" account_type=$(jq -r '."account-type"' ${environment_json_dir}/${application_name}.json) @@ -93,7 +95,10 @@ provision_environment_directories() { RAW_OUTPUT=`jq -n --arg APPLICATION_NAME "$application_name" '{ "business-unit": "", "set": "", "application": $APPLICATION_NAME }'` fi # wrap raw json output with a header and store the result in the applications folder - jq -rn --argjson DATA "${RAW_OUTPUT}" '{ networking: [ $DATA ] }' > "$directory"/networking.auto.tfvars.json + # Only populate networking.auto.tfvars.json if account type is not core + if [ "$account_type" != "core" ]; then + jq -rn --argjson DATA "${RAW_OUTPUT}" '{ networking: [ $DATA ] }' > "$directory"/networking.auto.tfvars.json + fi done } diff --git a/terraform/environments/core-logging/networking.auto.tfvars.json b/terraform/environments/core-logging/networking.auto.tfvars.json deleted file mode 100644 index 71479590f..000000000 --- a/terraform/environments/core-logging/networking.auto.tfvars.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "networking": [ - { - "business-unit": "", - "set": "", - "application": "core-logging" - } - ] -} diff --git a/terraform/environments/core-network-services/networking.auto.tfvars.json b/terraform/environments/core-network-services/networking.auto.tfvars.json deleted file mode 100644 index 3c0c3b82d..000000000 --- a/terraform/environments/core-network-services/networking.auto.tfvars.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "networking": [ - { - "business-unit": "", - "set": "", - "application": "core-network-services" - } - ] -} diff --git a/terraform/environments/core-sandbox/networking.auto.tfvars.json b/terraform/environments/core-sandbox/networking.auto.tfvars.json deleted file mode 100644 index e03cf2abb..000000000 --- a/terraform/environments/core-sandbox/networking.auto.tfvars.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "networking": [ - { - "business-unit": "", - "set": "", - "application": "core-sandbox" - } - ] -} diff --git a/terraform/environments/core-security/networking.auto.tfvars.json b/terraform/environments/core-security/networking.auto.tfvars.json deleted file mode 100644 index c525f5023..000000000 --- a/terraform/environments/core-security/networking.auto.tfvars.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "networking": [ - { - "business-unit": "", - "set": "", - "application": "core-security" - } - ] -} diff --git a/terraform/environments/core-shared-services/networking.auto.tfvars.json b/terraform/environments/core-shared-services/networking.auto.tfvars.json deleted file mode 100644 index 1305d8b44..000000000 --- a/terraform/environments/core-shared-services/networking.auto.tfvars.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "networking": [ - { - "business-unit": "", - "set": "", - "application": "core-shared-services" - } - ] -} diff --git a/terraform/environments/core-vpc/networking.auto.tfvars.json b/terraform/environments/core-vpc/networking.auto.tfvars.json deleted file mode 100644 index bcc6f1ce1..000000000 --- a/terraform/environments/core-vpc/networking.auto.tfvars.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "networking": [ - { - "business-unit": "", - "set": "", - "application": "core-vpc" - } - ] -} From 57f30ae04a15e3ce768ab9bbe0fac2add6cb0b86 Mon Sep 17 00:00:00 2001 From: David Sibley Date: Mon, 7 Aug 2023 13:45:57 +0100 Subject: [PATCH 3/8] removed local value from core-sandbox now tfvars has been removed --- terraform/environments/core-sandbox/locals.tf | 2 -- 1 file changed, 2 deletions(-) diff --git a/terraform/environments/core-sandbox/locals.tf b/terraform/environments/core-sandbox/locals.tf index 7aeb1f433..0553148f8 100644 --- a/terraform/environments/core-sandbox/locals.tf +++ b/terraform/environments/core-sandbox/locals.tf @@ -20,8 +20,6 @@ locals { owner = "Modernisation Platform: modernisation-platform@digital.justice.gov.uk" } - json_data = jsondecode(file("networking.auto.tfvars.json")) - acm_pca = [substr(terraform.workspace, length(local.application_name), length(terraform.workspace)) == "-production" || substr(terraform.workspace, length(local.application_name), length(terraform.workspace)) == "-preproduction" ? "acm-pca-live" : "acm-pca-non-live"] } From a47ffd8402e8a0298ffe25fbc7feee996eb4034c Mon Sep 17 00:00:00 2001 From: David Sibley Date: Tue, 8 Aug 2023 09:52:05 +0100 Subject: [PATCH 4/8] removed unused module, amended base_variables to accomodate removal of networking.auto.terraform.tfvars --- .../core-sandbox/base_variables.tf | 3 +- .../environments/core-sandbox/playground.tf | 29 +++---------------- .../environments/sprinkler/base_variables.old | 5 ---- 3 files changed, 6 insertions(+), 31 deletions(-) delete mode 100644 terraform/environments/sprinkler/base_variables.old diff --git a/terraform/environments/core-sandbox/base_variables.tf b/terraform/environments/core-sandbox/base_variables.tf index 9a658f2ff..f29d3130a 100644 --- a/terraform/environments/core-sandbox/base_variables.tf +++ b/terraform/environments/core-sandbox/base_variables.tf @@ -19,6 +19,7 @@ variable "account_name" { variable "networking" { - type = list(any) + type = list(any) + default = [{}] } diff --git a/terraform/environments/core-sandbox/playground.tf b/terraform/environments/core-sandbox/playground.tf index bc2835c9a..886e9b447 100644 --- a/terraform/environments/core-sandbox/playground.tf +++ b/terraform/environments/core-sandbox/playground.tf @@ -1,32 +1,11 @@ data "aws_caller_identity" "current" {} -module "ram-principal-association" { - - count = (var.networking[0].set == "") ? 0 : 1 - - source = "../../modules/ram-principal-association" - - providers = { - aws.share-acm = aws.core-network-services - aws.share-host = aws.core-vpc - aws.share-tenant = aws - } - principal = data.aws_caller_identity.current.account_id - vpc_name = var.networking[0].business-unit - subnet_set = var.networking[0].set - acm_pca = "acm-pca-${local.is_live[0]}" - environment = local.environment - -} - data "aws_ami_ids" "example" { owners = ["self"] - name_regex = "^(?!oracle-linux-5.11)*" - # filter { - # name = "name" - # values = ["oracle-linux-5.11*"] - # } - + filter { + name = "name" + values = ["oracle-linux-5.11*"] + } } output "amis" { diff --git a/terraform/environments/sprinkler/base_variables.old b/terraform/environments/sprinkler/base_variables.old deleted file mode 100644 index d196e7a5f..000000000 --- a/terraform/environments/sprinkler/base_variables.old +++ /dev/null @@ -1,5 +0,0 @@ -variable "networking" { - - type = list(any) - -} \ No newline at end of file From 4719afdccf5446ab665329335696c63c36577006 Mon Sep 17 00:00:00 2001 From: David Sibley Date: Tue, 8 Aug 2023 09:55:29 +0100 Subject: [PATCH 5/8] expanded the blank default in base_variables.tf --- terraform/environments/core-sandbox/base_variables.tf | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/terraform/environments/core-sandbox/base_variables.tf b/terraform/environments/core-sandbox/base_variables.tf index f29d3130a..f3b38d1c4 100644 --- a/terraform/environments/core-sandbox/base_variables.tf +++ b/terraform/environments/core-sandbox/base_variables.tf @@ -20,6 +20,12 @@ variable "account_name" { variable "networking" { type = list(any) - default = [{}] + default = [ + { + "business-unit": "", + "set": "", + "application": "" + } + ] } From 85a0a5d60f041d8f16d0681e04e5017a2a2261ee Mon Sep 17 00:00:00 2001 From: David Sibley Date: Tue, 8 Aug 2023 09:59:49 +0100 Subject: [PATCH 6/8] amended base_variables again to accommodate removal of networking.auto.terraform.tfvars --- terraform/environments/core-sandbox/base_variables.tf | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/terraform/environments/core-sandbox/base_variables.tf b/terraform/environments/core-sandbox/base_variables.tf index f3b38d1c4..08792b562 100644 --- a/terraform/environments/core-sandbox/base_variables.tf +++ b/terraform/environments/core-sandbox/base_variables.tf @@ -18,14 +18,12 @@ variable "account_name" { variable "networking" { - type = list(any) default = [ { "business-unit": "", "set": "", - "application": "" + "application": "core-sandbox" } ] - } From cdba620e19c19b68d3da22d4fdfe3551e9aaff58 Mon Sep 17 00:00:00 2001 From: David Sibley Date: Tue, 8 Aug 2023 10:17:52 +0100 Subject: [PATCH 7/8] added defaults to base_variables for core-vpc --- terraform/environments/core-vpc/base_variables.tf | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/terraform/environments/core-vpc/base_variables.tf b/terraform/environments/core-vpc/base_variables.tf index d196e7a5f..2ad5c4800 100644 --- a/terraform/environments/core-vpc/base_variables.tf +++ b/terraform/environments/core-vpc/base_variables.tf @@ -1,5 +1,10 @@ variable "networking" { - type = list(any) - + default = [ + { + "business-unit": "", + "set": "", + "application": "core-vpc" + } + ] } \ No newline at end of file From 7ac10f952f48c8fe1c65f76f0674e7e26b07fd68 Mon Sep 17 00:00:00 2001 From: David Sibley Date: Tue, 8 Aug 2023 10:49:39 +0100 Subject: [PATCH 8/8] added defaults to base_variables.tf for all core environments --- terraform/environments/core-logging/base_variables.tf | 9 +++++++-- .../environments/core-network-services/base_variables.tf | 9 +++++++-- terraform/environments/core-security/base_variables.tf | 9 +++++++-- .../environments/core-shared-services/base_variables.tf | 9 +++++++-- 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/terraform/environments/core-logging/base_variables.tf b/terraform/environments/core-logging/base_variables.tf index d196e7a5f..649c58e86 100644 --- a/terraform/environments/core-logging/base_variables.tf +++ b/terraform/environments/core-logging/base_variables.tf @@ -1,5 +1,10 @@ variable "networking" { - type = list(any) - + default = [ + { + "business-unit": "", + "set": "", + "application": "core-logging" + } + ] } \ No newline at end of file diff --git a/terraform/environments/core-network-services/base_variables.tf b/terraform/environments/core-network-services/base_variables.tf index d196e7a5f..e34b20123 100644 --- a/terraform/environments/core-network-services/base_variables.tf +++ b/terraform/environments/core-network-services/base_variables.tf @@ -1,5 +1,10 @@ variable "networking" { - type = list(any) - + default = [ + { + "business-unit": "", + "set": "", + "application": "core-network-services" + } + ] } \ No newline at end of file diff --git a/terraform/environments/core-security/base_variables.tf b/terraform/environments/core-security/base_variables.tf index d196e7a5f..82cb38ab5 100644 --- a/terraform/environments/core-security/base_variables.tf +++ b/terraform/environments/core-security/base_variables.tf @@ -1,5 +1,10 @@ variable "networking" { - type = list(any) - + default = [ + { + "business-unit": "", + "set": "", + "application": "core-security" + } + ] } \ No newline at end of file diff --git a/terraform/environments/core-shared-services/base_variables.tf b/terraform/environments/core-shared-services/base_variables.tf index 32a061a5f..d0cd835f4 100644 --- a/terraform/environments/core-shared-services/base_variables.tf +++ b/terraform/environments/core-shared-services/base_variables.tf @@ -1,7 +1,12 @@ variable "networking" { - type = list(any) - + default = [ + { + "business-unit": "", + "set": "", + "application": "core-shared-services" + } + ] } variable "app_name" {