Skip to content

Commit 5a38f8a

Browse files
authored
Tf state file name delete bug (#51)
* Fixing bug - initial commit * Debugging * Debugging v2 * Fix EFS_ENABLE flag * Remove debugging messages
1 parent afd8611 commit 5a38f8a

File tree

5 files changed

+60
-5
lines changed

5 files changed

+60
-5
lines changed

operations/_scripts/deploy/deploy.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ fi
2626
if [[ $(alpha_only "$AWS_EFS_CREATE") == true ]] || [[ $(alpha_only "$AWS_EFS_CREATE_HA") == true ]] || [ -n "$AWS_EFS_FS_ID" ]; then
2727
export AWS_EFS_ENABLE="true"
2828
else
29-
export AWS_EFS_ENABLE="false"
29+
export AWS_EFS_ENABLE="" # Intentional, being consistent with the rest of incoming vars
3030
fi
3131

3232
# Generate Github identifiers vars

operations/_scripts/generate/generate_bitops_config.sh

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,25 @@ function check_aws_bucket_for_file() {
3737
return $?
3838
}
3939

40+
function generate_tf_state_file_name () {
41+
if [ -n "$TF_STATE_FILE_NAME" ]; then
42+
filename="$TF_STATE_FILE_NAME"
43+
else
44+
filename="tf-state-$1"
45+
fi
46+
47+
if [ -n "$TF_STATE_FILE_NAME_APPEND" ]; then
48+
filename="${filename}-${TF_STATE_FILE_NAME_APPEND}"
49+
fi
50+
echo $filename
51+
}
52+
4053
function check_statefile() {
4154
provider="$1"
4255
bucket="$TF_STATE_BUCKET"
4356
commons_module="$2"
4457
if [[ "$provider" == "aws" ]]; then
45-
check_aws_bucket_for_file $bucket "tf-state-$commons_module"
58+
check_aws_bucket_for_file $bucket $(generate_tf_state_file_name $commons_module)
4659
return $?
4760
fi
4861
}

operations/deployment/terraform/aws/bitops.after-deploy.d/delete-tf-state-bucket.sh

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,21 @@
44

55
echo ""
66

7-
tf_state_file="tf-state-aws"
87
bucket="$TF_STATE_BUCKET"
8+
commons_module="aws"
9+
10+
function generate_tf_state_file_name () {
11+
if [ -n "$TF_STATE_FILE_NAME" ]; then
12+
filename="$TF_STATE_FILE_NAME"
13+
else
14+
filename="tf-state-$1"
15+
fi
16+
17+
if [ -n "$TF_STATE_FILE_NAME_APPEND" ]; then
18+
filename="${filename}-${TF_STATE_FILE_NAME_APPEND}"
19+
fi
20+
echo $filename
21+
}
922

1023
function check_aws_bucket_for_file() {
1124
bucket="$1"
@@ -14,6 +27,7 @@ function check_aws_bucket_for_file() {
1427
return $?
1528
}
1629

30+
tf_state_file=$(generate_tf_state_file_name $commons_module)
1731

1832
if [[ "$BITOPS_TERRAFORM_COMMAND" == "destroy" ]]; then
1933
if check_aws_bucket_for_file $bucket "$tf_state_file"; then

operations/deployment/terraform/ecr/bitops.after-deploy.d/delete-tf-state-bucket.sh

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,21 @@
44

55
echo ""
66

7-
tf_state_file="tf-state-aws"
87
bucket="$TF_STATE_BUCKET"
8+
commons_module="ecr"
9+
10+
function generate_tf_state_file_name () {
11+
if [ -n "$TF_STATE_FILE_NAME" ]; then
12+
filename="$TF_STATE_FILE_NAME"
13+
else
14+
filename="tf-state-$1"
15+
fi
16+
17+
if [ -n "$TF_STATE_FILE_NAME_APPEND" ]; then
18+
filename="${filename}-${TF_STATE_FILE_NAME_APPEND}"
19+
fi
20+
echo $filename
21+
}
922

1023
function check_aws_bucket_for_file() {
1124
bucket="$1"
@@ -14,6 +27,7 @@ function check_aws_bucket_for_file() {
1427
return $?
1528
}
1629

30+
tf_state_file=$(generate_tf_state_file_name $commons_module)
1731

1832
if [[ "$BITOPS_TERRAFORM_COMMAND" == "destroy" ]]; then
1933
if check_aws_bucket_for_file $bucket "$tf_state_file"; then

operations/deployment/terraform/eks/bitops.after-deploy.d/delete-tf-state-bucket.sh

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,21 @@
44

55
echo ""
66

7-
tf_state_file="tf-state-eks"
87
bucket="$TF_STATE_BUCKET"
8+
commons_module="eks"
9+
10+
function generate_tf_state_file_name () {
11+
if [ -n "$TF_STATE_FILE_NAME" ]; then
12+
filename="$TF_STATE_FILE_NAME"
13+
else
14+
filename="tf-state-$1"
15+
fi
16+
17+
if [ -n "$TF_STATE_FILE_NAME_APPEND" ]; then
18+
filename="${filename}-${TF_STATE_FILE_NAME_APPEND}"
19+
fi
20+
echo $filename
21+
}
922

1023
function check_aws_bucket_for_file() {
1124
bucket="$1"
@@ -14,6 +27,7 @@ function check_aws_bucket_for_file() {
1427
return $?
1528
}
1629

30+
tf_state_file=$(generate_tf_state_file_name $commons_module)
1731

1832
if [[ "$BITOPS_TERRAFORM_COMMAND" == "destroy" ]]; then
1933
if check_aws_bucket_for_file $bucket "$tf_state_file"; then

0 commit comments

Comments
 (0)