From 9def098d4cec9ef8a33e29f5d3461494a715151f Mon Sep 17 00:00:00 2001 From: Ankit Bhardwaj Date: Tue, 3 Sep 2024 18:21:13 +0530 Subject: [PATCH] INFRA-3721 | Ankit Bhardwaj | fix test --- .../aurora-db-tf/deploy.sh | 23 +++--- .../aws-roles-tf/deploy.sh | 36 ++++----- .../aws-s3-bucket-tf/deploy.sh | 25 ++++--- .../document-db-tf/deploy.sh | 25 ++++--- .../dynamo-db-tf/deploy.sh | 17 +++-- .../elastic-cache-tf/deploy.sh | 26 +++---- .../sample_infra_manifest/rds-tf/deploy.sh | 32 ++++---- .../modify-version/11__to__13.sh | 12 ++- .../aurora-db-tf/deploy.sh | 23 +++--- .../aws-roles-tf/deploy.sh | 36 ++++----- .../aws-s3-bucket-tf/deploy.sh | 25 ++++--- .../document-db-tf/deploy.sh | 25 ++++--- .../dynamo-db-tf/deploy.sh | 17 +++-- .../elastic-cache-tf/deploy.sh | 26 +++---- .../sample_infra_manifest_2/rds-tf/deploy.sh | 32 ++++---- .../modify-version/11__to__13.sh | 12 ++- .../aurora-db-tf/deploy.sh | 23 +++--- .../aws-roles-tf/deploy.sh | 36 ++++----- .../aws-s3-bucket-tf/deploy.sh | 25 ++++--- .../document-db-tf/deploy.sh | 25 ++++--- .../dynamo-db-tf/deploy.sh | 17 +++-- .../elastic-cache-tf/deploy.sh | 26 +++---- .../rds-tf/deploy.sh | 32 ++++---- .../modify-version/11__to__13.sh | 12 ++- .../expected_output/aws-roles-tf/deploy.sh | 21 ++++++ .../expected_output/aws-roles-tf/main.tf | 17 +++++ .../aws-s3-bucket-tf/deploy.sh | 15 ++++ .../expected_output/aws-s3-bucket-tf/main.tf | 16 ++++ .../m1_basic/expected_output/rds-tf/deploy.sh | 17 +++++ .../m1_basic/expected_output/rds-tf/main.tf | 57 ++++++++++++++ testdata/m1_basic/sample_infra_manifest.json | 74 +++++++++++++++++++ 31 files changed, 538 insertions(+), 267 deletions(-) create mode 100755 testdata/m1_basic/expected_output/aws-roles-tf/deploy.sh create mode 100755 testdata/m1_basic/expected_output/aws-roles-tf/main.tf create mode 100755 testdata/m1_basic/expected_output/aws-s3-bucket-tf/deploy.sh create mode 100755 testdata/m1_basic/expected_output/aws-s3-bucket-tf/main.tf create mode 100755 testdata/m1_basic/expected_output/rds-tf/deploy.sh create mode 100755 testdata/m1_basic/expected_output/rds-tf/main.tf create mode 100644 testdata/m1_basic/sample_infra_manifest.json diff --git a/testdata/expected_output/sample_infra_manifest/aurora-db-tf/deploy.sh b/testdata/expected_output/sample_infra_manifest/aurora-db-tf/deploy.sh index 976dadc..069ba0c 100755 --- a/testdata/expected_output/sample_infra_manifest/aurora-db-tf/deploy.sh +++ b/testdata/expected_output/sample_infra_manifest/aurora-db-tf/deploy.sh @@ -1,13 +1,18 @@ #!/bin/sh -set -xe +set -e -additional_terraform_options="" -additional_terraform_options="${additional_terraform_options} -auto-approve" +function echo_and_run { + echo "Running command: $*" + eval "$*" +} -terraform119 init -terraform119 workspace select nonprod.np.navi-tech.in || terraform119 workspace new nonprod.np.navi-tech.in -terraform_action=apply -terraform119 $terraform_action -target=module.rds.data.aws_subnet_ids.command_private_subnets $additional_terraform_options -terraform119 $terraform_action -target=module.rds.module.rds_aurora_instance $additional_terraform_options -terraform119 $terraform_action -target=module.rds.module.postgres_db $additional_terraform_options +echo_and_run 'additional_terraform_options=""' +echo_and_run 'additional_terraform_options="${additional_terraform_options} -auto-approve"' + +echo_and_run "terraform119 init" +echo_and_run "terraform119 workspace select nonprod.np.navi-tech.in || terraform119 workspace new nonprod.np.navi-tech.in" +echo_and_run "terraform_action=apply" +echo_and_run "terraform119 $terraform_action -target=module.rds.data.aws_subnet_ids.command_private_subnets $additional_terraform_options" +echo_and_run "terraform119 $terraform_action -target=module.rds.module.rds_aurora_instance $additional_terraform_options" +echo_and_run "terraform119 $terraform_action -target=module.rds.module.postgres_db $additional_terraform_options" diff --git a/testdata/expected_output/sample_infra_manifest/aws-roles-tf/deploy.sh b/testdata/expected_output/sample_infra_manifest/aws-roles-tf/deploy.sh index f958199..4ff7d5d 100755 --- a/testdata/expected_output/sample_infra_manifest/aws-roles-tf/deploy.sh +++ b/testdata/expected_output/sample_infra_manifest/aws-roles-tf/deploy.sh @@ -1,29 +1,31 @@ #!/bin/sh # exit when any command fails -set -xe +set -e -additional_terraform_options="" -additional_kube_options="" -terraform_action=apply -additional_terraform_options="${additional_terraform_options} -auto-approve" +function echo_and_run { + echo "Running command: $*" + eval "$*" +} + +echo_and_run 'additional_terraform_options=""' +echo_and_run 'additional_kube_options=""' +echo_and_run "terraform_action=apply" +echo_and_run 'additional_terraform_options="${additional_terraform_options} -auto-approve"' -terraform init -terraform workspace select nonprod.np.navi-tech.in || terraform workspace new nonprod.np.navi-tech.in +echo_and_run "terraform init" +echo_and_run "terraform workspace select nonprod.np.navi-tech.in || terraform workspace new nonprod.np.navi-tech.in" -providers=$(terraform providers | grep 'registry.terraform.io/-' | awk -F "[" '{print $2}' | sed 's/.$//') +echo_and_run "providers=$(terraform providers | grep 'registry.terraform.io/-' | awk -F '[' '{print $2}' | sed 's/.$//')" printf '\n' for provider in $providers; do correct_provider="${provider//-/hashicorp}" - echo "executing" - echo "terraform state replace-provider -auto-approve $provider $correct_provider" - terraform state replace-provider -auto-approve "$provider" "$correct_provider" + echo_and_run 'terraform state replace-provider -auto-approve "$provider" "$correct_provider"' done -printf '\n' -kubectl config use-context nonprod.np.navi-tech.in -namespace=dev-3p -filename=foo-navi-service-dev.yaml -terraform $terraform_action $additional_terraform_options -kubectl apply -f $filename -n $namespace $additional_kube_options +echo_and_run "kubectl config use-context nonprod.np.navi-tech.in" +echo_and_run "namespace=dev-3p" +echo_and_run 'filename=foo-navi-service-dev.yaml' +echo_and_run "terraform $terraform_action $additional_terraform_options" +echo_and_run "kubectl apply -f $filename -n $namespace $additional_kube_options" diff --git a/testdata/expected_output/sample_infra_manifest/aws-s3-bucket-tf/deploy.sh b/testdata/expected_output/sample_infra_manifest/aws-s3-bucket-tf/deploy.sh index 74645af..be3e791 100755 --- a/testdata/expected_output/sample_infra_manifest/aws-s3-bucket-tf/deploy.sh +++ b/testdata/expected_output/sample_infra_manifest/aws-s3-bucket-tf/deploy.sh @@ -1,25 +1,26 @@ #!/bin/sh # exit when any command fails -set -xe +set -e -additional_terraform_options="" +function echo_and_run { + echo "Running command: $*" + eval "$*" +} + +echo_and_run 'additional_terraform_options=""' terraform_action=apply -additional_terraform_options="${additional_terraform_options} -auto-approve" +echo_and_run 'additional_terraform_options="${additional_terraform_options} -auto-approve"' -terraform init -terraform workspace select nonprod.np.navi-tech.in || terraform workspace new nonprod.np.navi-tech.in +echo_and_run "terraform init" +echo_and_run "terraform workspace select nonprod.np.navi-tech.in || terraform workspace new nonprod.np.navi-tech.in" -providers=$(terraform providers | grep 'registry.terraform.io/-' | awk -F "[" '{print $2}' | sed 's/.$//') -printf '\n' +echo_and_run "providers=$(terraform providers | grep 'registry.terraform.io/-' | awk -F '[' '{print $2}' | sed 's/.$//')" for provider in $providers; do correct_provider="${provider//-/hashicorp}" - echo "executing" - echo "terraform state replace-provider -auto-approve $provider $correct_provider" - terraform state replace-provider -auto-approve "$provider" "$correct_provider" + echo_and_run 'terraform state replace-provider -auto-approve "$provider" "$correct_provider"' done -printf '\n' -terraform $terraform_action $additional_terraform_options +echo_and_run "terraform $terraform_action $additional_terraform_options" diff --git a/testdata/expected_output/sample_infra_manifest/document-db-tf/deploy.sh b/testdata/expected_output/sample_infra_manifest/document-db-tf/deploy.sh index 95e19e8..f86dd99 100755 --- a/testdata/expected_output/sample_infra_manifest/document-db-tf/deploy.sh +++ b/testdata/expected_output/sample_infra_manifest/document-db-tf/deploy.sh @@ -1,24 +1,25 @@ #!/bin/sh -set -xe +set -e -additional_terraform_options="" +function echo_and_run { + echo "Running command: $*" + eval "$*" +} + +echo_and_run 'additional_terraform_options=""' terraform_action=apply -additional_terraform_options="${additional_terraform_options} -auto-approve" +echo_and_run 'additional_terraform_options="${additional_terraform_options} -auto-approve"' -terraform init -terraform workspace select nonprod.np.navi-tech.in || terraform workspace new nonprod.np.navi-tech.in +echo_and_run 'terraform init' +echo_and_run 'terraform workspace select nonprod.np.navi-tech.in || terraform workspace new nonprod.np.navi-tech.in' -providers=$(terraform providers | grep 'registry.terraform.io/-' | awk -F "[" '{print $2}' | sed 's/.$//') -printf '\n' +echo_and_run "providers=$(terraform providers | grep 'registry.terraform.io/-' | awk -F '[' '{print $2}' | sed 's/.$//')" for provider in $providers; do correct_provider="${provider//-/hashicorp}" - echo "executing" - echo "terraform state replace-provider -auto-approve $provider $correct_provider" - terraform state replace-provider -auto-approve "$provider" "$correct_provider" + echo_and_run 'terraform state replace-provider -auto-approve "$provider" "$correct_provider"' done -printf '\n' -terraform $terraform_action $additional_terraform_options +echo_and_run "terraform $terraform_action $additional_terraform_options" diff --git a/testdata/expected_output/sample_infra_manifest/dynamo-db-tf/deploy.sh b/testdata/expected_output/sample_infra_manifest/dynamo-db-tf/deploy.sh index 7b06bb5..db48772 100755 --- a/testdata/expected_output/sample_infra_manifest/dynamo-db-tf/deploy.sh +++ b/testdata/expected_output/sample_infra_manifest/dynamo-db-tf/deploy.sh @@ -1,13 +1,18 @@ #!/bin/sh -set -xe +set -e -additional_terraform_options="" +function echo_and_run { + echo "Running command: $*" + eval "$*" +} + +echo_and_run 'additional_terraform_options=""' terraform_action=apply -additional_terraform_options="${additional_terraform_options} -auto-approve" +echo_and_run 'additional_terraform_options="${additional_terraform_options} -auto-approve"' -terraform init -terraform workspace select nonprod.np.navi-tech.in || terraform workspace new nonprod.np.navi-tech.in -terraform $terraform_action $additional_terraform_options +echo_and_run "terraform init" +echo_and_run "terraform workspace select nonprod.np.navi-tech.in || terraform workspace new nonprod.np.navi-tech.in" +echo_and_run "terraform $terraform_action $additional_terraform_options" diff --git a/testdata/expected_output/sample_infra_manifest/elastic-cache-tf/deploy.sh b/testdata/expected_output/sample_infra_manifest/elastic-cache-tf/deploy.sh index 502dc58..dddc93f 100755 --- a/testdata/expected_output/sample_infra_manifest/elastic-cache-tf/deploy.sh +++ b/testdata/expected_output/sample_infra_manifest/elastic-cache-tf/deploy.sh @@ -1,25 +1,23 @@ #!/bin/sh -set -xe +set -e +function echo_and_run { + echo "Running command: $*" + eval "$*" +} -additional_terraform_options="" +echo_and_run 'additional_terraform_options=""' terraform_action=apply -additional_terraform_options="${additional_terraform_options} -auto-approve" +echo_and_run 'additional_terraform_options="${additional_terraform_options} -auto-approve"' -terraform init -terraform workspace select nonprod.np.navi-tech.in || terraform workspace new nonprod.np.navi-tech.in +echo_and_run "terraform init" +echo_and_run "terraform workspace select nonprod.np.navi-tech.in || terraform workspace new nonprod.np.navi-tech.in" -providers=$(terraform providers | grep 'registry.terraform.io/-' | awk -F "[" '{print $2}' | sed 's/.$//') -printf '\n' +echo_and_run "providers=$(terraform providers | grep 'registry.terraform.io/-' | awk -F '[' '{print $2}' | sed 's/.$//')" for provider in $providers; do correct_provider="${provider//-/hashicorp}" - echo "executing" - echo "terraform state replace-provider -auto-approve $provider $correct_provider" - terraform state replace-provider -auto-approve "$provider" "$correct_provider" + echo_and_run 'terraform state replace-provider -auto-approve "$provider" "$correct_provider"' done -printf '\n' - - -terraform $terraform_action $additional_terraform_options +echo_and_run "terraform $terraform_action $additional_terraform_options" diff --git a/testdata/expected_output/sample_infra_manifest/rds-tf/deploy.sh b/testdata/expected_output/sample_infra_manifest/rds-tf/deploy.sh index 9cfc944..561b3e2 100755 --- a/testdata/expected_output/sample_infra_manifest/rds-tf/deploy.sh +++ b/testdata/expected_output/sample_infra_manifest/rds-tf/deploy.sh @@ -1,6 +1,12 @@ #!/bin/sh -set -xe +set -e + +function echo_and_run { + echo "Running command: $*" + eval "$*" +} + function state_migration() { # remove option group from terraform state as option group api is removed by aws for postgres and we can't delete option group as its used by snapshot. @@ -14,30 +20,26 @@ function state_migration() { } additional_terraform_options="" -additional_terraform_options="${additional_terraform_options} -auto-approve" +echo_and_run 'additional_terraform_options="${additional_terraform_options} -auto-approve"' -terraform init -terraform workspace select nonprod.np.navi-tech.in || terraform workspace new nonprod.np.navi-tech.in +echo_and_run "terraform init" +echo_and_run "terraform workspace select nonprod.np.navi-tech.in || terraform workspace new nonprod.np.navi-tech.in" -providers=$(terraform providers | grep 'registry.terraform.io/-' | awk -F "[" '{print $2}' | sed 's/.$//') -printf '\n' +echo_and_run "providers=$(terraform providers | grep 'registry.terraform.io/-' | awk -F '[' '{print $2}' | sed 's/.$//')" for provider in $providers; do if echo "$provider" | grep -q "postgres"; then correct_provider="${provider//-/cyrilgdn}" else correct_provider="${provider//-/hashicorp}" fi - echo "executing" - echo "terraform state replace-provider -auto-approve $provider $correct_provider" - terraform state replace-provider -auto-approve "$provider" "$correct_provider" + echo_and_run 'terraform state replace-provider -auto-approve "$provider" "$correct_provider"' done -printf '\n' -terraform state list | grep 'module.rds.module.postgres_db.postgresql_database.this' && terraform state rm 'module.rds.module.postgres_db.postgresql_database.this' +echo_and_run "(terraform state list | grep 'module.rds.module.postgres_db.postgresql_database.this' && terraform state rm 'module.rds.module.postgres_db.postgresql_database.this') || true" state_migration -terraform_action=apply -terraform $terraform_action -target=module.rds.data.aws_subnet_ids.command_private_subnets -target=module.rds.data.aws_subnets.command_private_subnets $additional_terraform_options -terraform $terraform_action -target=module.rds.module.rds_instance -target=module.rds.module.rds_instance_replica $additional_terraform_options -terraform $terraform_action -target=module.rds.module.postgres_db $additional_terraform_options +echo_and_run "terraform_action=apply" +echo_and_run "terraform $terraform_action -target=module.rds.data.aws_subnet_ids.command_private_subnets -target=module.rds.data.aws_subnets.command_private_subnets $additional_terraform_options" +echo_and_run "terraform $terraform_action -target=module.rds.module.rds_instance -target=module.rds.module.rds_instance_replica $additional_terraform_options" +echo_and_run "terraform $terraform_action -target=module.rds.module.postgres_db $additional_terraform_options" # TODO: remove -target=module.rds.data.aws_subnet_ids.command_private_subnets once terraform rds migration(specific storage_type for rds -> gp3) is complete [7 September 2023] diff --git a/testdata/expected_output/sample_infra_manifest/rds-tf/scripts/pre-terraform-apply/modify-version/11__to__13.sh b/testdata/expected_output/sample_infra_manifest/rds-tf/scripts/pre-terraform-apply/modify-version/11__to__13.sh index 5096e65..9e0bede 100755 --- a/testdata/expected_output/sample_infra_manifest/rds-tf/scripts/pre-terraform-apply/modify-version/11__to__13.sh +++ b/testdata/expected_output/sample_infra_manifest/rds-tf/scripts/pre-terraform-apply/modify-version/11__to__13.sh @@ -91,7 +91,7 @@ EOF } check_lag_status() { - LAG_STATUS_QUERY="SELECT ${slot_name}, restart_lsn - '0/0' AS lsn_on_rs, pg_current_wal_lsn() - '0/0' AS curr_wal_lsn, pg_wal_lsn_diff(pg_current_wal_lsn(), restart_lsn) AS lsn_lag, active FROM pg_replication_slots" + LAG_STATUS_QUERY="SELECT slot_name, restart_lsn - '0/0' AS lsn_on_rs, pg_current_wal_lsn() - '0/0' AS curr_wal_lsn, pg_wal_lsn_diff(pg_current_wal_lsn(), restart_lsn) AS lsn_lag, active FROM pg_replication_slots" while true; do lag=$( @@ -108,11 +108,11 @@ print(lag) EOF ) - if [ "${lag}" -le 10 ]; then - echo "Lag has become 0, proceeding ahead" + if [ "${lag}" -le 10000 ]; then + echo "Lag has become less than 10000, proceeding ahead" break else - echo "Lag has not become 0, waiting" + echo "Lag has not become 10000, waiting" sleep 10 fi done @@ -150,6 +150,10 @@ EOF } parse_connector_config +if [ $? != 0 ]; then + echo "Could not parse connector config, exiting" + exit 0 +fi set_database_in_read_only wait_untill_database_ready #-----------------------------------------DATABASE is considered ready after this------------ diff --git a/testdata/expected_output/sample_infra_manifest_2/aurora-db-tf/deploy.sh b/testdata/expected_output/sample_infra_manifest_2/aurora-db-tf/deploy.sh index 47839b2..3c9e2b8 100755 --- a/testdata/expected_output/sample_infra_manifest_2/aurora-db-tf/deploy.sh +++ b/testdata/expected_output/sample_infra_manifest_2/aurora-db-tf/deploy.sh @@ -1,13 +1,18 @@ #!/bin/sh -set -xe +set -e -additional_terraform_options="" -additional_terraform_options="${additional_terraform_options} -auto-approve" +function echo_and_run { + echo "Running command: $*" + eval "$*" +} -terraform119 init -terraform119 workspace select aps1.np.navi-gi.in || terraform119 workspace new aps1.np.navi-gi.in -terraform_action=apply -terraform119 $terraform_action -target=module.rds.data.aws_subnet_ids.command_private_subnets $additional_terraform_options -terraform119 $terraform_action -target=module.rds.module.rds_aurora_instance $additional_terraform_options -terraform119 $terraform_action -target=module.rds.module.postgres_db $additional_terraform_options +echo_and_run 'additional_terraform_options=""' +echo_and_run 'additional_terraform_options="${additional_terraform_options} -auto-approve"' + +echo_and_run "terraform119 init" +echo_and_run "terraform119 workspace select aps1.np.navi-gi.in || terraform119 workspace new aps1.np.navi-gi.in" +echo_and_run "terraform_action=apply" +echo_and_run "terraform119 $terraform_action -target=module.rds.data.aws_subnet_ids.command_private_subnets $additional_terraform_options" +echo_and_run "terraform119 $terraform_action -target=module.rds.module.rds_aurora_instance $additional_terraform_options" +echo_and_run "terraform119 $terraform_action -target=module.rds.module.postgres_db $additional_terraform_options" diff --git a/testdata/expected_output/sample_infra_manifest_2/aws-roles-tf/deploy.sh b/testdata/expected_output/sample_infra_manifest_2/aws-roles-tf/deploy.sh index baa0336..4c78399 100755 --- a/testdata/expected_output/sample_infra_manifest_2/aws-roles-tf/deploy.sh +++ b/testdata/expected_output/sample_infra_manifest_2/aws-roles-tf/deploy.sh @@ -1,29 +1,31 @@ #!/bin/sh # exit when any command fails -set -xe +set -e -additional_terraform_options="" -additional_kube_options="" -terraform_action=apply -additional_terraform_options="${additional_terraform_options} -auto-approve" +function echo_and_run { + echo "Running command: $*" + eval "$*" +} + +echo_and_run 'additional_terraform_options=""' +echo_and_run 'additional_kube_options=""' +echo_and_run "terraform_action=apply" +echo_and_run 'additional_terraform_options="${additional_terraform_options} -auto-approve"' -terraform init -terraform workspace select aps1.np.navi-gi.in || terraform workspace new aps1.np.navi-gi.in +echo_and_run "terraform init" +echo_and_run "terraform workspace select aps1.np.navi-gi.in || terraform workspace new aps1.np.navi-gi.in" -providers=$(terraform providers | grep 'registry.terraform.io/-' | awk -F "[" '{print $2}' | sed 's/.$//') +echo_and_run "providers=$(terraform providers | grep 'registry.terraform.io/-' | awk -F '[' '{print $2}' | sed 's/.$//')" printf '\n' for provider in $providers; do correct_provider="${provider//-/hashicorp}" - echo "executing" - echo "terraform state replace-provider -auto-approve $provider $correct_provider" - terraform state replace-provider -auto-approve "$provider" "$correct_provider" + echo_and_run 'terraform state replace-provider -auto-approve "$provider" "$correct_provider"' done -printf '\n' -kubectl config use-context aps1.np.navi-gi.in -namespace=dev-3p -filename=foo-navi-service-dev.yaml -terraform $terraform_action $additional_terraform_options -kubectl apply -f $filename -n $namespace $additional_kube_options +echo_and_run "kubectl config use-context aps1.np.navi-gi.in" +echo_and_run "namespace=dev-3p" +echo_and_run 'filename=foo-navi-service-dev.yaml' +echo_and_run "terraform $terraform_action $additional_terraform_options" +echo_and_run "kubectl apply -f $filename -n $namespace $additional_kube_options" diff --git a/testdata/expected_output/sample_infra_manifest_2/aws-s3-bucket-tf/deploy.sh b/testdata/expected_output/sample_infra_manifest_2/aws-s3-bucket-tf/deploy.sh index 3e2ac44..38cf227 100755 --- a/testdata/expected_output/sample_infra_manifest_2/aws-s3-bucket-tf/deploy.sh +++ b/testdata/expected_output/sample_infra_manifest_2/aws-s3-bucket-tf/deploy.sh @@ -1,25 +1,26 @@ #!/bin/sh # exit when any command fails -set -xe +set -e -additional_terraform_options="" +function echo_and_run { + echo "Running command: $*" + eval "$*" +} + +echo_and_run 'additional_terraform_options=""' terraform_action=apply -additional_terraform_options="${additional_terraform_options} -auto-approve" +echo_and_run 'additional_terraform_options="${additional_terraform_options} -auto-approve"' -terraform init -terraform workspace select aps1.np.navi-gi.in || terraform workspace new aps1.np.navi-gi.in +echo_and_run "terraform init" +echo_and_run "terraform workspace select aps1.np.navi-gi.in || terraform workspace new aps1.np.navi-gi.in" -providers=$(terraform providers | grep 'registry.terraform.io/-' | awk -F "[" '{print $2}' | sed 's/.$//') -printf '\n' +echo_and_run "providers=$(terraform providers | grep 'registry.terraform.io/-' | awk -F '[' '{print $2}' | sed 's/.$//')" for provider in $providers; do correct_provider="${provider//-/hashicorp}" - echo "executing" - echo "terraform state replace-provider -auto-approve $provider $correct_provider" - terraform state replace-provider -auto-approve "$provider" "$correct_provider" + echo_and_run 'terraform state replace-provider -auto-approve "$provider" "$correct_provider"' done -printf '\n' -terraform $terraform_action $additional_terraform_options +echo_and_run "terraform $terraform_action $additional_terraform_options" diff --git a/testdata/expected_output/sample_infra_manifest_2/document-db-tf/deploy.sh b/testdata/expected_output/sample_infra_manifest_2/document-db-tf/deploy.sh index 561723a..300a079 100755 --- a/testdata/expected_output/sample_infra_manifest_2/document-db-tf/deploy.sh +++ b/testdata/expected_output/sample_infra_manifest_2/document-db-tf/deploy.sh @@ -1,24 +1,25 @@ #!/bin/sh -set -xe +set -e -additional_terraform_options="" +function echo_and_run { + echo "Running command: $*" + eval "$*" +} + +echo_and_run 'additional_terraform_options=""' terraform_action=apply -additional_terraform_options="${additional_terraform_options} -auto-approve" +echo_and_run 'additional_terraform_options="${additional_terraform_options} -auto-approve"' -terraform init -terraform workspace select aps1.np.navi-gi.in || terraform workspace new aps1.np.navi-gi.in +echo_and_run 'terraform init' +echo_and_run 'terraform workspace select aps1.np.navi-gi.in || terraform workspace new aps1.np.navi-gi.in' -providers=$(terraform providers | grep 'registry.terraform.io/-' | awk -F "[" '{print $2}' | sed 's/.$//') -printf '\n' +echo_and_run "providers=$(terraform providers | grep 'registry.terraform.io/-' | awk -F '[' '{print $2}' | sed 's/.$//')" for provider in $providers; do correct_provider="${provider//-/hashicorp}" - echo "executing" - echo "terraform state replace-provider -auto-approve $provider $correct_provider" - terraform state replace-provider -auto-approve "$provider" "$correct_provider" + echo_and_run 'terraform state replace-provider -auto-approve "$provider" "$correct_provider"' done -printf '\n' -terraform $terraform_action $additional_terraform_options +echo_and_run "terraform $terraform_action $additional_terraform_options" diff --git a/testdata/expected_output/sample_infra_manifest_2/dynamo-db-tf/deploy.sh b/testdata/expected_output/sample_infra_manifest_2/dynamo-db-tf/deploy.sh index d389344..c44ac9b 100755 --- a/testdata/expected_output/sample_infra_manifest_2/dynamo-db-tf/deploy.sh +++ b/testdata/expected_output/sample_infra_manifest_2/dynamo-db-tf/deploy.sh @@ -1,13 +1,18 @@ #!/bin/sh -set -xe +set -e -additional_terraform_options="" +function echo_and_run { + echo "Running command: $*" + eval "$*" +} + +echo_and_run 'additional_terraform_options=""' terraform_action=apply -additional_terraform_options="${additional_terraform_options} -auto-approve" +echo_and_run 'additional_terraform_options="${additional_terraform_options} -auto-approve"' -terraform init -terraform workspace select aps1.np.navi-gi.in || terraform workspace new aps1.np.navi-gi.in -terraform $terraform_action $additional_terraform_options +echo_and_run "terraform init" +echo_and_run "terraform workspace select aps1.np.navi-gi.in || terraform workspace new aps1.np.navi-gi.in" +echo_and_run "terraform $terraform_action $additional_terraform_options" diff --git a/testdata/expected_output/sample_infra_manifest_2/elastic-cache-tf/deploy.sh b/testdata/expected_output/sample_infra_manifest_2/elastic-cache-tf/deploy.sh index 8468f15..983c006 100755 --- a/testdata/expected_output/sample_infra_manifest_2/elastic-cache-tf/deploy.sh +++ b/testdata/expected_output/sample_infra_manifest_2/elastic-cache-tf/deploy.sh @@ -1,25 +1,23 @@ #!/bin/sh -set -xe +set -e +function echo_and_run { + echo "Running command: $*" + eval "$*" +} -additional_terraform_options="" +echo_and_run 'additional_terraform_options=""' terraform_action=apply -additional_terraform_options="${additional_terraform_options} -auto-approve" +echo_and_run 'additional_terraform_options="${additional_terraform_options} -auto-approve"' -terraform init -terraform workspace select aps1.np.navi-gi.in || terraform workspace new aps1.np.navi-gi.in +echo_and_run "terraform init" +echo_and_run "terraform workspace select aps1.np.navi-gi.in || terraform workspace new aps1.np.navi-gi.in" -providers=$(terraform providers | grep 'registry.terraform.io/-' | awk -F "[" '{print $2}' | sed 's/.$//') -printf '\n' +echo_and_run "providers=$(terraform providers | grep 'registry.terraform.io/-' | awk -F '[' '{print $2}' | sed 's/.$//')" for provider in $providers; do correct_provider="${provider//-/hashicorp}" - echo "executing" - echo "terraform state replace-provider -auto-approve $provider $correct_provider" - terraform state replace-provider -auto-approve "$provider" "$correct_provider" + echo_and_run 'terraform state replace-provider -auto-approve "$provider" "$correct_provider"' done -printf '\n' - - -terraform $terraform_action $additional_terraform_options +echo_and_run "terraform $terraform_action $additional_terraform_options" diff --git a/testdata/expected_output/sample_infra_manifest_2/rds-tf/deploy.sh b/testdata/expected_output/sample_infra_manifest_2/rds-tf/deploy.sh index 35a5ce3..ff8639d 100755 --- a/testdata/expected_output/sample_infra_manifest_2/rds-tf/deploy.sh +++ b/testdata/expected_output/sample_infra_manifest_2/rds-tf/deploy.sh @@ -1,6 +1,12 @@ #!/bin/sh -set -xe +set -e + +function echo_and_run { + echo "Running command: $*" + eval "$*" +} + function state_migration() { # remove option group from terraform state as option group api is removed by aws for postgres and we can't delete option group as its used by snapshot. @@ -14,30 +20,26 @@ function state_migration() { } additional_terraform_options="" -additional_terraform_options="${additional_terraform_options} -auto-approve" +echo_and_run 'additional_terraform_options="${additional_terraform_options} -auto-approve"' -terraform init -terraform workspace select aps1.np.navi-gi.in || terraform workspace new aps1.np.navi-gi.in +echo_and_run "terraform init" +echo_and_run "terraform workspace select aps1.np.navi-gi.in || terraform workspace new aps1.np.navi-gi.in" -providers=$(terraform providers | grep 'registry.terraform.io/-' | awk -F "[" '{print $2}' | sed 's/.$//') -printf '\n' +echo_and_run "providers=$(terraform providers | grep 'registry.terraform.io/-' | awk -F '[' '{print $2}' | sed 's/.$//')" for provider in $providers; do if echo "$provider" | grep -q "postgres"; then correct_provider="${provider//-/cyrilgdn}" else correct_provider="${provider//-/hashicorp}" fi - echo "executing" - echo "terraform state replace-provider -auto-approve $provider $correct_provider" - terraform state replace-provider -auto-approve "$provider" "$correct_provider" + echo_and_run 'terraform state replace-provider -auto-approve "$provider" "$correct_provider"' done -printf '\n' -terraform state list | grep 'module.rds.module.postgres_db.postgresql_database.this' && terraform state rm 'module.rds.module.postgres_db.postgresql_database.this' +echo_and_run "(terraform state list | grep 'module.rds.module.postgres_db.postgresql_database.this' && terraform state rm 'module.rds.module.postgres_db.postgresql_database.this') || true" state_migration -terraform_action=apply -terraform $terraform_action -target=module.rds.data.aws_subnet_ids.command_private_subnets -target=module.rds.data.aws_subnets.command_private_subnets $additional_terraform_options -terraform $terraform_action -target=module.rds.module.rds_instance -target=module.rds.module.rds_instance_replica $additional_terraform_options -terraform $terraform_action -target=module.rds.module.postgres_db $additional_terraform_options +echo_and_run "terraform_action=apply" +echo_and_run "terraform $terraform_action -target=module.rds.data.aws_subnet_ids.command_private_subnets -target=module.rds.data.aws_subnets.command_private_subnets $additional_terraform_options" +echo_and_run "terraform $terraform_action -target=module.rds.module.rds_instance -target=module.rds.module.rds_instance_replica $additional_terraform_options" +echo_and_run "terraform $terraform_action -target=module.rds.module.postgres_db $additional_terraform_options" # TODO: remove -target=module.rds.data.aws_subnet_ids.command_private_subnets once terraform rds migration(specific storage_type for rds -> gp3) is complete [7 September 2023] diff --git a/testdata/expected_output/sample_infra_manifest_2/rds-tf/scripts/pre-terraform-apply/modify-version/11__to__13.sh b/testdata/expected_output/sample_infra_manifest_2/rds-tf/scripts/pre-terraform-apply/modify-version/11__to__13.sh index ec4801d..4bcaf7e 100755 --- a/testdata/expected_output/sample_infra_manifest_2/rds-tf/scripts/pre-terraform-apply/modify-version/11__to__13.sh +++ b/testdata/expected_output/sample_infra_manifest_2/rds-tf/scripts/pre-terraform-apply/modify-version/11__to__13.sh @@ -91,7 +91,7 @@ EOF } check_lag_status() { - LAG_STATUS_QUERY="SELECT ${slot_name}, restart_lsn - '0/0' AS lsn_on_rs, pg_current_wal_lsn() - '0/0' AS curr_wal_lsn, pg_wal_lsn_diff(pg_current_wal_lsn(), restart_lsn) AS lsn_lag, active FROM pg_replication_slots" + LAG_STATUS_QUERY="SELECT slot_name, restart_lsn - '0/0' AS lsn_on_rs, pg_current_wal_lsn() - '0/0' AS curr_wal_lsn, pg_wal_lsn_diff(pg_current_wal_lsn(), restart_lsn) AS lsn_lag, active FROM pg_replication_slots" while true; do lag=$( @@ -108,11 +108,11 @@ print(lag) EOF ) - if [ "${lag}" -le 10 ]; then - echo "Lag has become 0, proceeding ahead" + if [ "${lag}" -le 10000 ]; then + echo "Lag has become less than 10000, proceeding ahead" break else - echo "Lag has not become 0, waiting" + echo "Lag has not become 10000, waiting" sleep 10 fi done @@ -150,6 +150,10 @@ EOF } parse_connector_config +if [ $? != 0 ]; then + echo "Could not parse connector config, exiting" + exit 0 +fi set_database_in_read_only wait_untill_database_ready #-----------------------------------------DATABASE is considered ready after this------------ diff --git a/testdata/expected_output/sample_infra_manifest_flink/aurora-db-tf/deploy.sh b/testdata/expected_output/sample_infra_manifest_flink/aurora-db-tf/deploy.sh index 47839b2..3c9e2b8 100755 --- a/testdata/expected_output/sample_infra_manifest_flink/aurora-db-tf/deploy.sh +++ b/testdata/expected_output/sample_infra_manifest_flink/aurora-db-tf/deploy.sh @@ -1,13 +1,18 @@ #!/bin/sh -set -xe +set -e -additional_terraform_options="" -additional_terraform_options="${additional_terraform_options} -auto-approve" +function echo_and_run { + echo "Running command: $*" + eval "$*" +} -terraform119 init -terraform119 workspace select aps1.np.navi-gi.in || terraform119 workspace new aps1.np.navi-gi.in -terraform_action=apply -terraform119 $terraform_action -target=module.rds.data.aws_subnet_ids.command_private_subnets $additional_terraform_options -terraform119 $terraform_action -target=module.rds.module.rds_aurora_instance $additional_terraform_options -terraform119 $terraform_action -target=module.rds.module.postgres_db $additional_terraform_options +echo_and_run 'additional_terraform_options=""' +echo_and_run 'additional_terraform_options="${additional_terraform_options} -auto-approve"' + +echo_and_run "terraform119 init" +echo_and_run "terraform119 workspace select aps1.np.navi-gi.in || terraform119 workspace new aps1.np.navi-gi.in" +echo_and_run "terraform_action=apply" +echo_and_run "terraform119 $terraform_action -target=module.rds.data.aws_subnet_ids.command_private_subnets $additional_terraform_options" +echo_and_run "terraform119 $terraform_action -target=module.rds.module.rds_aurora_instance $additional_terraform_options" +echo_and_run "terraform119 $terraform_action -target=module.rds.module.postgres_db $additional_terraform_options" diff --git a/testdata/expected_output/sample_infra_manifest_flink/aws-roles-tf/deploy.sh b/testdata/expected_output/sample_infra_manifest_flink/aws-roles-tf/deploy.sh index 6463548..f4393b0 100755 --- a/testdata/expected_output/sample_infra_manifest_flink/aws-roles-tf/deploy.sh +++ b/testdata/expected_output/sample_infra_manifest_flink/aws-roles-tf/deploy.sh @@ -1,29 +1,31 @@ #!/bin/sh # exit when any command fails -set -xe +set -e -additional_terraform_options="" -additional_kube_options="" -terraform_action=apply -additional_terraform_options="${additional_terraform_options} -auto-approve" +function echo_and_run { + echo "Running command: $*" + eval "$*" +} + +echo_and_run 'additional_terraform_options=""' +echo_and_run 'additional_kube_options=""' +echo_and_run "terraform_action=apply" +echo_and_run 'additional_terraform_options="${additional_terraform_options} -auto-approve"' -terraform init -terraform workspace select aps1.np.navi-gi.in || terraform workspace new aps1.np.navi-gi.in +echo_and_run "terraform init" +echo_and_run "terraform workspace select aps1.np.navi-gi.in || terraform workspace new aps1.np.navi-gi.in" -providers=$(terraform providers | grep 'registry.terraform.io/-' | awk -F "[" '{print $2}' | sed 's/.$//') +echo_and_run "providers=$(terraform providers | grep 'registry.terraform.io/-' | awk -F '[' '{print $2}' | sed 's/.$//')" printf '\n' for provider in $providers; do correct_provider="${provider//-/hashicorp}" - echo "executing" - echo "terraform state replace-provider -auto-approve $provider $correct_provider" - terraform state replace-provider -auto-approve "$provider" "$correct_provider" + echo_and_run 'terraform state replace-provider -auto-approve "$provider" "$correct_provider"' done -printf '\n' -kubectl config use-context aps1.np.navi-gi.in -namespace=flink -filename=foo-navi-service-dev.yaml -terraform $terraform_action $additional_terraform_options -kubectl apply -f $filename -n $namespace $additional_kube_options +echo_and_run "kubectl config use-context aps1.np.navi-gi.in" +echo_and_run "namespace=flink" +echo_and_run 'filename=foo-navi-service-dev.yaml' +echo_and_run "terraform $terraform_action $additional_terraform_options" +echo_and_run "kubectl apply -f $filename -n $namespace $additional_kube_options" diff --git a/testdata/expected_output/sample_infra_manifest_flink/aws-s3-bucket-tf/deploy.sh b/testdata/expected_output/sample_infra_manifest_flink/aws-s3-bucket-tf/deploy.sh index 3e2ac44..38cf227 100755 --- a/testdata/expected_output/sample_infra_manifest_flink/aws-s3-bucket-tf/deploy.sh +++ b/testdata/expected_output/sample_infra_manifest_flink/aws-s3-bucket-tf/deploy.sh @@ -1,25 +1,26 @@ #!/bin/sh # exit when any command fails -set -xe +set -e -additional_terraform_options="" +function echo_and_run { + echo "Running command: $*" + eval "$*" +} + +echo_and_run 'additional_terraform_options=""' terraform_action=apply -additional_terraform_options="${additional_terraform_options} -auto-approve" +echo_and_run 'additional_terraform_options="${additional_terraform_options} -auto-approve"' -terraform init -terraform workspace select aps1.np.navi-gi.in || terraform workspace new aps1.np.navi-gi.in +echo_and_run "terraform init" +echo_and_run "terraform workspace select aps1.np.navi-gi.in || terraform workspace new aps1.np.navi-gi.in" -providers=$(terraform providers | grep 'registry.terraform.io/-' | awk -F "[" '{print $2}' | sed 's/.$//') -printf '\n' +echo_and_run "providers=$(terraform providers | grep 'registry.terraform.io/-' | awk -F '[' '{print $2}' | sed 's/.$//')" for provider in $providers; do correct_provider="${provider//-/hashicorp}" - echo "executing" - echo "terraform state replace-provider -auto-approve $provider $correct_provider" - terraform state replace-provider -auto-approve "$provider" "$correct_provider" + echo_and_run 'terraform state replace-provider -auto-approve "$provider" "$correct_provider"' done -printf '\n' -terraform $terraform_action $additional_terraform_options +echo_and_run "terraform $terraform_action $additional_terraform_options" diff --git a/testdata/expected_output/sample_infra_manifest_flink/document-db-tf/deploy.sh b/testdata/expected_output/sample_infra_manifest_flink/document-db-tf/deploy.sh index 561723a..300a079 100755 --- a/testdata/expected_output/sample_infra_manifest_flink/document-db-tf/deploy.sh +++ b/testdata/expected_output/sample_infra_manifest_flink/document-db-tf/deploy.sh @@ -1,24 +1,25 @@ #!/bin/sh -set -xe +set -e -additional_terraform_options="" +function echo_and_run { + echo "Running command: $*" + eval "$*" +} + +echo_and_run 'additional_terraform_options=""' terraform_action=apply -additional_terraform_options="${additional_terraform_options} -auto-approve" +echo_and_run 'additional_terraform_options="${additional_terraform_options} -auto-approve"' -terraform init -terraform workspace select aps1.np.navi-gi.in || terraform workspace new aps1.np.navi-gi.in +echo_and_run 'terraform init' +echo_and_run 'terraform workspace select aps1.np.navi-gi.in || terraform workspace new aps1.np.navi-gi.in' -providers=$(terraform providers | grep 'registry.terraform.io/-' | awk -F "[" '{print $2}' | sed 's/.$//') -printf '\n' +echo_and_run "providers=$(terraform providers | grep 'registry.terraform.io/-' | awk -F '[' '{print $2}' | sed 's/.$//')" for provider in $providers; do correct_provider="${provider//-/hashicorp}" - echo "executing" - echo "terraform state replace-provider -auto-approve $provider $correct_provider" - terraform state replace-provider -auto-approve "$provider" "$correct_provider" + echo_and_run 'terraform state replace-provider -auto-approve "$provider" "$correct_provider"' done -printf '\n' -terraform $terraform_action $additional_terraform_options +echo_and_run "terraform $terraform_action $additional_terraform_options" diff --git a/testdata/expected_output/sample_infra_manifest_flink/dynamo-db-tf/deploy.sh b/testdata/expected_output/sample_infra_manifest_flink/dynamo-db-tf/deploy.sh index d389344..c44ac9b 100755 --- a/testdata/expected_output/sample_infra_manifest_flink/dynamo-db-tf/deploy.sh +++ b/testdata/expected_output/sample_infra_manifest_flink/dynamo-db-tf/deploy.sh @@ -1,13 +1,18 @@ #!/bin/sh -set -xe +set -e -additional_terraform_options="" +function echo_and_run { + echo "Running command: $*" + eval "$*" +} + +echo_and_run 'additional_terraform_options=""' terraform_action=apply -additional_terraform_options="${additional_terraform_options} -auto-approve" +echo_and_run 'additional_terraform_options="${additional_terraform_options} -auto-approve"' -terraform init -terraform workspace select aps1.np.navi-gi.in || terraform workspace new aps1.np.navi-gi.in -terraform $terraform_action $additional_terraform_options +echo_and_run "terraform init" +echo_and_run "terraform workspace select aps1.np.navi-gi.in || terraform workspace new aps1.np.navi-gi.in" +echo_and_run "terraform $terraform_action $additional_terraform_options" diff --git a/testdata/expected_output/sample_infra_manifest_flink/elastic-cache-tf/deploy.sh b/testdata/expected_output/sample_infra_manifest_flink/elastic-cache-tf/deploy.sh index 8468f15..983c006 100755 --- a/testdata/expected_output/sample_infra_manifest_flink/elastic-cache-tf/deploy.sh +++ b/testdata/expected_output/sample_infra_manifest_flink/elastic-cache-tf/deploy.sh @@ -1,25 +1,23 @@ #!/bin/sh -set -xe +set -e +function echo_and_run { + echo "Running command: $*" + eval "$*" +} -additional_terraform_options="" +echo_and_run 'additional_terraform_options=""' terraform_action=apply -additional_terraform_options="${additional_terraform_options} -auto-approve" +echo_and_run 'additional_terraform_options="${additional_terraform_options} -auto-approve"' -terraform init -terraform workspace select aps1.np.navi-gi.in || terraform workspace new aps1.np.navi-gi.in +echo_and_run "terraform init" +echo_and_run "terraform workspace select aps1.np.navi-gi.in || terraform workspace new aps1.np.navi-gi.in" -providers=$(terraform providers | grep 'registry.terraform.io/-' | awk -F "[" '{print $2}' | sed 's/.$//') -printf '\n' +echo_and_run "providers=$(terraform providers | grep 'registry.terraform.io/-' | awk -F '[' '{print $2}' | sed 's/.$//')" for provider in $providers; do correct_provider="${provider//-/hashicorp}" - echo "executing" - echo "terraform state replace-provider -auto-approve $provider $correct_provider" - terraform state replace-provider -auto-approve "$provider" "$correct_provider" + echo_and_run 'terraform state replace-provider -auto-approve "$provider" "$correct_provider"' done -printf '\n' - - -terraform $terraform_action $additional_terraform_options +echo_and_run "terraform $terraform_action $additional_terraform_options" diff --git a/testdata/expected_output/sample_infra_manifest_flink/rds-tf/deploy.sh b/testdata/expected_output/sample_infra_manifest_flink/rds-tf/deploy.sh index 35a5ce3..ff8639d 100755 --- a/testdata/expected_output/sample_infra_manifest_flink/rds-tf/deploy.sh +++ b/testdata/expected_output/sample_infra_manifest_flink/rds-tf/deploy.sh @@ -1,6 +1,12 @@ #!/bin/sh -set -xe +set -e + +function echo_and_run { + echo "Running command: $*" + eval "$*" +} + function state_migration() { # remove option group from terraform state as option group api is removed by aws for postgres and we can't delete option group as its used by snapshot. @@ -14,30 +20,26 @@ function state_migration() { } additional_terraform_options="" -additional_terraform_options="${additional_terraform_options} -auto-approve" +echo_and_run 'additional_terraform_options="${additional_terraform_options} -auto-approve"' -terraform init -terraform workspace select aps1.np.navi-gi.in || terraform workspace new aps1.np.navi-gi.in +echo_and_run "terraform init" +echo_and_run "terraform workspace select aps1.np.navi-gi.in || terraform workspace new aps1.np.navi-gi.in" -providers=$(terraform providers | grep 'registry.terraform.io/-' | awk -F "[" '{print $2}' | sed 's/.$//') -printf '\n' +echo_and_run "providers=$(terraform providers | grep 'registry.terraform.io/-' | awk -F '[' '{print $2}' | sed 's/.$//')" for provider in $providers; do if echo "$provider" | grep -q "postgres"; then correct_provider="${provider//-/cyrilgdn}" else correct_provider="${provider//-/hashicorp}" fi - echo "executing" - echo "terraform state replace-provider -auto-approve $provider $correct_provider" - terraform state replace-provider -auto-approve "$provider" "$correct_provider" + echo_and_run 'terraform state replace-provider -auto-approve "$provider" "$correct_provider"' done -printf '\n' -terraform state list | grep 'module.rds.module.postgres_db.postgresql_database.this' && terraform state rm 'module.rds.module.postgres_db.postgresql_database.this' +echo_and_run "(terraform state list | grep 'module.rds.module.postgres_db.postgresql_database.this' && terraform state rm 'module.rds.module.postgres_db.postgresql_database.this') || true" state_migration -terraform_action=apply -terraform $terraform_action -target=module.rds.data.aws_subnet_ids.command_private_subnets -target=module.rds.data.aws_subnets.command_private_subnets $additional_terraform_options -terraform $terraform_action -target=module.rds.module.rds_instance -target=module.rds.module.rds_instance_replica $additional_terraform_options -terraform $terraform_action -target=module.rds.module.postgres_db $additional_terraform_options +echo_and_run "terraform_action=apply" +echo_and_run "terraform $terraform_action -target=module.rds.data.aws_subnet_ids.command_private_subnets -target=module.rds.data.aws_subnets.command_private_subnets $additional_terraform_options" +echo_and_run "terraform $terraform_action -target=module.rds.module.rds_instance -target=module.rds.module.rds_instance_replica $additional_terraform_options" +echo_and_run "terraform $terraform_action -target=module.rds.module.postgres_db $additional_terraform_options" # TODO: remove -target=module.rds.data.aws_subnet_ids.command_private_subnets once terraform rds migration(specific storage_type for rds -> gp3) is complete [7 September 2023] diff --git a/testdata/expected_output/sample_infra_manifest_flink/rds-tf/scripts/pre-terraform-apply/modify-version/11__to__13.sh b/testdata/expected_output/sample_infra_manifest_flink/rds-tf/scripts/pre-terraform-apply/modify-version/11__to__13.sh index ec4801d..4bcaf7e 100755 --- a/testdata/expected_output/sample_infra_manifest_flink/rds-tf/scripts/pre-terraform-apply/modify-version/11__to__13.sh +++ b/testdata/expected_output/sample_infra_manifest_flink/rds-tf/scripts/pre-terraform-apply/modify-version/11__to__13.sh @@ -91,7 +91,7 @@ EOF } check_lag_status() { - LAG_STATUS_QUERY="SELECT ${slot_name}, restart_lsn - '0/0' AS lsn_on_rs, pg_current_wal_lsn() - '0/0' AS curr_wal_lsn, pg_wal_lsn_diff(pg_current_wal_lsn(), restart_lsn) AS lsn_lag, active FROM pg_replication_slots" + LAG_STATUS_QUERY="SELECT slot_name, restart_lsn - '0/0' AS lsn_on_rs, pg_current_wal_lsn() - '0/0' AS curr_wal_lsn, pg_wal_lsn_diff(pg_current_wal_lsn(), restart_lsn) AS lsn_lag, active FROM pg_replication_slots" while true; do lag=$( @@ -108,11 +108,11 @@ print(lag) EOF ) - if [ "${lag}" -le 10 ]; then - echo "Lag has become 0, proceeding ahead" + if [ "${lag}" -le 10000 ]; then + echo "Lag has become less than 10000, proceeding ahead" break else - echo "Lag has not become 0, waiting" + echo "Lag has not become 10000, waiting" sleep 10 fi done @@ -150,6 +150,10 @@ EOF } parse_connector_config +if [ $? != 0 ]; then + echo "Could not parse connector config, exiting" + exit 0 +fi set_database_in_read_only wait_untill_database_ready #-----------------------------------------DATABASE is considered ready after this------------ diff --git a/testdata/m1_basic/expected_output/aws-roles-tf/deploy.sh b/testdata/m1_basic/expected_output/aws-roles-tf/deploy.sh new file mode 100755 index 0000000..4ef57c7 --- /dev/null +++ b/testdata/m1_basic/expected_output/aws-roles-tf/deploy.sh @@ -0,0 +1,21 @@ +#!/bin/sh + +# exit when any command fails +set -e + +additional_terraform_options="" +additional_kube_options="" + +terraform_action=${1:-apply} +if [ $terraform_action == "apply" ];then + additional_terraform_options="${additional_terraform_options} -auto-approve" +else + additional_kube_options="${additional_kube_options} --dry-run" +fi + +terraform init +terraform workspace select nonprod.np.navi-tech.in || terraform workspace new nonprod.np.navi-tech.in +terraform $terraform_action $additional_terraform_options + +kubectl config use-context ${CLUSTER} +kubectl apply -f foo-navi-service-dev.yaml -n ${NAMESPACE} $additional_kube_options diff --git a/testdata/m1_basic/expected_output/aws-roles-tf/main.tf b/testdata/m1_basic/expected_output/aws-roles-tf/main.tf new file mode 100755 index 0000000..f41de08 --- /dev/null +++ b/testdata/m1_basic/expected_output/aws-roles-tf/main.tf @@ -0,0 +1,17 @@ +terraform { + backend "s3" { + bucket = "navi-bank-terraform-nonprod-state" + region = "ap-south-1" + key = "service-iam-roles" + workspace_key_prefix = "iamroles/dev/foo-navi-service" + profile = "nonprod" + acl = "bucket-owner-full-control" + } +} + +module "iam-role" { + source = "git::ssh://git@github.cmd.navi-tech.in/navi-infra/iam-roles.git?ref=cef39cc18b5dd3095cf6969dabfe1cfe09500390" + environment = "dev" + service_role = {"policies":[{"actions":["s3:GetObject","s3:PutObject"],"resource":"arn:aws:s3:::navi-e3e2a9bfd88566b05001b02a3f51d286/*"},{"actions":["s3:GetObject","s3:PutObject"],"resource":"*"},{"actions":["sns:Publish","sns:SetSMSAttributes"],"resource":"arn:aws:s3:::arn:aws:s3:::test-bucket-to-be-deleted/*"}]} + role_name = "foo-navi-service" +} diff --git a/testdata/m1_basic/expected_output/aws-s3-bucket-tf/deploy.sh b/testdata/m1_basic/expected_output/aws-s3-bucket-tf/deploy.sh new file mode 100755 index 0000000..739ff87 --- /dev/null +++ b/testdata/m1_basic/expected_output/aws-s3-bucket-tf/deploy.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +# exit when any command fails +set -e + +additional_terraform_options="" +terraform_action=${1:-apply} + +if [ $terraform_action == "apply" ];then + additional_terraform_options="${additional_terraform_options} -auto-approve" +fi + +terraform init +terraform workspace select nonprod.np.navi-tech.in || terraform workspace new nonprod.np.navi-tech.in +terraform $terraform_action $additional_terraform_options diff --git a/testdata/m1_basic/expected_output/aws-s3-bucket-tf/main.tf b/testdata/m1_basic/expected_output/aws-s3-bucket-tf/main.tf new file mode 100755 index 0000000..6b23c2a --- /dev/null +++ b/testdata/m1_basic/expected_output/aws-s3-bucket-tf/main.tf @@ -0,0 +1,16 @@ +terraform { + backend "s3" { + bucket = "navi-bank-terraform-nonprod-state" + region = "ap-south-1" + key = "s3-buckets" + workspace_key_prefix = "s3-buckets/dev/foo-navi-service" + profile = "nonprod" + acl = "bucket-owner-full-control" + } +} + +module "s3-buckets" { + source = "git::ssh://git@github.cmd.navi-tech.in/navi-infra/aws-s3-bucket.git?ref=fd40ccc2a8f4a97029612e618b9d09902ceecfe3" + s3_buckets = [{"anonymizedBucketName":"navi-bucket-test-1","bucketTag":"customer-uploads","lifecycleRules":null},{"anonymizedBucketName":"navi-bucket-test-2","bucketTag":"document-uploads","lifecycleRules":[{"expiration":{"days":1,"storageClass":""}}]}] + environment = "dev" +} diff --git a/testdata/m1_basic/expected_output/rds-tf/deploy.sh b/testdata/m1_basic/expected_output/rds-tf/deploy.sh new file mode 100755 index 0000000..729b7aa --- /dev/null +++ b/testdata/m1_basic/expected_output/rds-tf/deploy.sh @@ -0,0 +1,17 @@ +#!/bin/sh + +set -e + +additional_terraform_options="" +terraform_action=${1:-apply} + +if [ $terraform_action == "apply" ];then + additional_terraform_options="${additional_terraform_options} -auto-approve" +fi + +terraform init +terraform workspace select nonprod.np.navi-tech.in || terraform workspace new nonprod.np.navi-tech.in +terraform $terraform_action -target=module.rds.data.aws_subnet_ids.command_private_subnets $additional_terraform_options +terraform $terraform_action -target=module.rds.module.rds_instance $additional_terraform_options +terraform $terraform_action -target=module.rds.module.rds_instance_replica $additional_terraform_options +terraform $terraform_action -target=module.rds.module.postgres_db $additional_terraform_options diff --git a/testdata/m1_basic/expected_output/rds-tf/main.tf b/testdata/m1_basic/expected_output/rds-tf/main.tf new file mode 100755 index 0000000..87da3da --- /dev/null +++ b/testdata/m1_basic/expected_output/rds-tf/main.tf @@ -0,0 +1,57 @@ +terraform { + backend "s3" { + bucket = "navi-bank-terraform-command-state" + region = "ap-south-1" + key = "rds" + workspace_key_prefix = "rds-states/foo-service" + profile = "cmd" + acl = "bucket-owner-full-control" + } +} + +module "rds" { + source = "git::ssh://git@github.cmd.navi-tech.in/navi-infra/rds.git?ref=1fc10877a1d9d009ca892208f7f89f669e7634cc" + environment = "dev" + instance_name = "foo-service" + password = "foo_service_password" + user = "foo_service_user" + name = "foo" + + monitoring_password = "" + monitoring_user = "" + + databases = ["foo_service"] + database_tags = { + Team = "Infra" + medici-app = "foo-navi-service" + medici-owner = "Infra" + medici-environment = "dev" + } + + team = "Infra" + size = 7 + db_extensions = ["pgcrypto"] + readonly_user = "foo_readonly_user" + readonly_password = "foo_readonly_password" + backup_retention_period = 7 + multi_az = true + read_replica_instance_class = "db.t3.micro" + read_replica_performance_insights_enabled = true + parameters = [ + { + name = "rds.logical_replication" + value = "1" + apply_method = "pending-reboot" + } + ] + cpu_utilization_alarm_threshold = "70" + cpucredit_balance_alarm_threshold = "120" + burst_balance_alarm_threshold = "85" + db_connections_alarm_threshold = "200" + queue_depth_alarm_threshold = "20" + free_storage_space_percent = 90 + freeable_memory_threshold = 150 + read_latency_alarm_threshold = "0.5" + write_latency_alarm_threshold = "0.5" + +} diff --git a/testdata/m1_basic/sample_infra_manifest.json b/testdata/m1_basic/sample_infra_manifest.json new file mode 100644 index 0000000..7a0be53 --- /dev/null +++ b/testdata/m1_basic/sample_infra_manifest.json @@ -0,0 +1,74 @@ +{ + "extraResources": { + "environment": "dev", + "database": { + "instanceName": "foo-service", + "user": "foo_service_user", + "password": "foo_service_password", + "sizeInGb": 7, + "dbNames": ["foo_service"], + "dbExtensions": ["pgcrypto"], + "readonlyUser": "foo_readonly_user", + "readonlyPassword": "foo_readonly_password", + "applyImmediately": false, + "performanceInsightsEnabled": false, + "readReplica": { + "awsInstanceClass": "db.t3.micro", + "performanceInsightsEnabled": true + }, + "parameters": { + "rds.logical_replication": "1" + }, + "rdsAlertThresholds": { + "cpuUtilization": 70, + "cpuCreditBalance": 120, + "burstBalance": 85, + "dbConnections": 200, + "queueDepth": 20, + "freeStorageSpacePercent": 90, + "freeMemoryTooLowInMB": 150, + "readLatency": 0.5, + "writeLatency": 0.5 + } + }, + "aws_access": { + "policies": [ + { + "actions": ["s3:GetObject", "s3:PutObject"], + "resource": "arn:aws:s3:::navi-e3e2a9bfd88566b05001b02a3f51d286/*" + }, + { + "actions": ["s3:GetObject", "s3:PutObject"], + "resource": "*" + }, + { + "resource": "arn:aws:s3:::arn:aws:s3:::test-bucket-to-be-deleted/*", + "actions": ["sns:Publish", "sns:SetSMSAttributes"] + } + ] + }, + "s3_buckets": [ + { + "anonymizedBucketName": "navi-bucket-test-1", + "bucketTag": "customer-uploads" + }, + { + "anonymizedBucketName": "navi-bucket-test-2", + "bucketTag": "document-uploads", + "lifecycleRules": [ + { + "expiration": { + "days": 1 + } + } + ] + } + ] + }, + "team": { + "name": "Infra" + }, + "deployment": { + "name": "foo" + } +}