-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_terraform_backend.sh
21 lines (20 loc) · 1.11 KB
/
create_terraform_backend.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/bin/bash
DYNAMODB_NAME=$1
BUCKET_NAME=$2
AWS_REGION=$3
DB=$(aws dynamodb describe-table --table-name $DYNAMODB_NAME --output text --query 'Table.TableName' || true)
if [ -z "$DB" ]; then
aws dynamodb create-table --table-name $DYNAMODB_NAME --output text --attribute-definitions AttributeName=LockID,AttributeType=S --key-schema AttributeName=LockID,KeyType=HASH --provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5
echo "$DYNAMODB_NAME created"
else
echo "$DYNAMODB_NAME already exists"
fi
BUCKET=$(aws s3 ls s3://$BUCKET_NAME || true)
if [ -z "$BUCKET" ]; then
aws s3api create-bucket –bucket $BUCKET_NAME --output text –region $AWS_REGION –create-bucket-configuration LocationConstraint=$AWS_REGION
aws s3api put-bucket-encryption –bucket $BUCKET_NAME --output text –server-side-encryption-configuration "{\'Rules\': [{\'ApplyServerSideEncryptionByDefault\':{\'SSEAlgorithm\': \'AES256\'}}]}"
aws s3api put-bucket-versioning --bucket $BUCKET_NAME --output text --versioning-configuration Status=Enabled
echo "$BUCKET_NAME created"
else
echo "$BUCKET_NAME already exists"
fi