Skip to content

Commit e191628

Browse files
authored
fix: init_tf_backend_aws hiding errors not matching know patterns (#72)
1 parent 9f5bbf3 commit e191628

1 file changed

Lines changed: 31 additions & 27 deletions

File tree

init_tf_backend_aws.sh

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -91,25 +91,26 @@ fi
9191

9292
# Management of the creation of the s3 bucket.
9393
#
94-
res=$(aws s3api create-bucket --bucket ${NAME} \
95-
--region ${REGION} \
96-
--create-bucket-configuration LocationConstraint=${REGION} \
97-
--acl private 2>&1)
98-
9994
echo "Creating bucket : ${NAME}"
100-
case $res in
101-
*"BucketAlreadyOwnedByYou"*)
102-
echo "Bucket already owned !"
103-
;;
104-
*"BucketAlreadyExists"*)
105-
echo "Bucket already exists !"
106-
exit 1
107-
;;
108-
\S)
109-
echo ${res}
110-
exit 1
111-
;;
112-
esac
95+
res=$(aws s3api create-bucket --bucket ${NAME} \
96+
--region ${REGION} \
97+
--create-bucket-configuration LocationConstraint=${REGION} \
98+
--acl private 2>&1)
99+
if [ $? -ne 0 ]; then
100+
case $res in
101+
*"BucketAlreadyOwnedByYou"*)
102+
echo "Bucket already owned !"
103+
;;
104+
*"BucketAlreadyExists"*)
105+
echo "Bucket already exists !"
106+
exit 1
107+
;;
108+
*)
109+
echo "Error: ${res}"
110+
exit 1
111+
;;
112+
esac
113+
fi
113114

114115
# Management of the bucket public access block configuration.
115116
#
@@ -139,13 +140,16 @@ if [ "$CREATE_DYNAMODB" == true ]; then
139140
--key-schema AttributeName=LockID,KeyType=HASH \
140141
--billing-mode PAY_PER_REQUEST 2>&1)
141142

142-
case $res in
143-
*"ResourceInUseException"*)
144-
echo "DynamoDB table already owned !"
145-
;;
146-
\S)
147-
echo ${res}
148-
exit 1
149-
;;
150-
esac
143+
if [ $? -ne 0 ]; then
144+
case $res in
145+
*"ResourceInUseException"*)
146+
echo "DynamoDB table already owned !"
147+
exit 1
148+
;;
149+
*)
150+
echo "Error: ${res}"
151+
exit 1
152+
;;
153+
esac
154+
fi
151155
fi

0 commit comments

Comments
 (0)