Skip to content

Commit b0c5bdc

Browse files
author
AWS
committed
Release: 1.5.1
1 parent 0e0c00d commit b0c5bdc

File tree

3 files changed

+96
-86
lines changed

3 files changed

+96
-86
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.5.0
1+
1.5.1

modules/aft-customizations/buildspecs/aft-account-customizations-terraform.yml

Lines changed: 94 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -23,112 +23,122 @@ phases:
2323
- |
2424
CUSTOMIZATION=$(aws dynamodb get-item --table-name aft-request-metadata --key "{\"id\": {\"S\": \"$VENDED_ACCOUNT_ID\"}}" --attributes-to-get "account_customizations_name" | jq --raw-output ".Item.account_customizations_name.S")
2525
26-
# Check if customization directory exists
26+
# Check if customization directory exists
2727
- |
28-
if [[ ! -d "$DEFAULT_PATH/$CUSTOMIZATION" ]]; then
29-
echo "${CUSTOMIZATION} directory does not exist"
30-
exit 1
31-
else
28+
if [[ ! -z "$CUSTOMIZATION" ]]; then
29+
if [[ ! -d "$DEFAULT_PATH/$CUSTOMIZATION" ]]; then
30+
echo "Error: ${CUSTOMIZATION} directory does not exist"
31+
exit 1
32+
fi
33+
3234
echo "Found customization" $CUSTOMIZATION
33-
fi
34-
35-
# Configure Development SSH Key
36-
- |
37-
ssh_key_parameter=$(aws ssm get-parameter --name /aft/config/aft-ssh-key --with-decryption 2> /dev/null || echo "None")
38-
if [[ $ssh_key_parameter != "None" ]]; then
39-
ssh_key=$(jq --raw-output ".Parameter.Value" <<< $ssh_key_parameter)
40-
mkdir -p ~/.ssh
41-
echo "Host *" >> ~/.ssh/config
42-
echo "StrictHostKeyChecking no" >> ~/.ssh/config
43-
echo "UserKnownHostsFile=/dev/null" >> ~/.ssh/config
44-
echo "$ssh_key" > ~/.ssh/ssh_key
45-
echo -e "\n\n" >> ~/.ssh/ssh_key
46-
chmod 600 ~/.ssh/ssh_key
47-
eval "$(ssh-agent -s)"
48-
ssh-add ~/.ssh/ssh_key
49-
fi
5035
51-
# Clone AFT
52-
- AWS_MODULE_SOURCE=$(aws ssm get-parameter --name "/aft/config/aft-pipeline-code-source/repo-url" --query "Parameter.Value" --output text)
53-
- AWS_MODULE_GIT_REF=$(aws ssm get-parameter --name "/aft/config/aft-pipeline-code-source/repo-git-ref" --query "Parameter.Value" --output text)
54-
- git config --global credential.helper '!aws codecommit credential-helper $@'
55-
- git config --global credential.UseHttpPath true
56-
- git clone --quiet -b $AWS_MODULE_GIT_REF $AWS_MODULE_SOURCE aws-aft-core-framework
36+
# Configure Development SSH Key
37+
ssh_key_parameter=$(aws ssm get-parameter --name /aft/config/aft-ssh-key --with-decryption 2> /dev/null || echo "None")
38+
39+
if [[ $ssh_key_parameter != "None" ]]; then
40+
ssh_key=$(jq --raw-output ".Parameter.Value" <<< $ssh_key_parameter)
41+
mkdir -p ~/.ssh
42+
echo "Host *" >> ~/.ssh/config
43+
echo "StrictHostKeyChecking no" >> ~/.ssh/config
44+
echo "UserKnownHostsFile=/dev/null" >> ~/.ssh/config
45+
echo "$ssh_key" > ~/.ssh/ssh_key
46+
echo -e "\n\n" >> ~/.ssh/ssh_key
47+
chmod 600 ~/.ssh/ssh_key
48+
eval "$(ssh-agent -s)"
49+
ssh-add ~/.ssh/ssh_key
50+
fi
5751
58-
# Install AFT Python Dependencies
59-
- python3 -m venv $DEFAULT_PATH/aft-venv
60-
- $DEFAULT_PATH/aft-venv/bin/pip install pip==22.1.2
61-
- $DEFAULT_PATH/aft-venv/bin/pip install jinja2-cli==0.7.0 Jinja2==3.0.1 MarkupSafe==2.0.1 boto3==1.18.56 requests==2.26.0
52+
# Clone AFT
53+
AWS_MODULE_SOURCE=$(aws ssm get-parameter --name "/aft/config/aft-pipeline-code-source/repo-url" --query "Parameter.Value" --output text)
54+
AWS_MODULE_GIT_REF=$(aws ssm get-parameter --name "/aft/config/aft-pipeline-code-source/repo-git-ref" --query "Parameter.Value" --output text)
55+
git config --global credential.helper '!aws codecommit credential-helper $@'
56+
git config --global credential.UseHttpPath true
57+
git clone --quiet -b $AWS_MODULE_GIT_REF $AWS_MODULE_SOURCE aws-aft-core-framework
6258
63-
# Install API Helper Python Dependencies
64-
- python3 -m venv $DEFAULT_PATH/api-helpers-venv
65-
- $DEFAULT_PATH/api-helpers-venv/bin/pip install -r ./$CUSTOMIZATION/api_helpers/python/requirements.txt
59+
# Install AFT Python Dependencies
60+
python3 -m venv $DEFAULT_PATH/aft-venv
61+
$DEFAULT_PATH/aft-venv/bin/pip install pip==22.1.2
62+
$DEFAULT_PATH/aft-venv/bin/pip install jinja2-cli==0.7.0 Jinja2==3.0.1 MarkupSafe==2.0.1 boto3==1.18.56 requests==2.26.0
6663
67-
# Mark helper scripts as executable
68-
- chmod +x $DEFAULT_PATH/$CUSTOMIZATION/api_helpers/pre-api-helpers.sh
69-
- chmod +x $DEFAULT_PATH/$CUSTOMIZATION/api_helpers/post-api-helpers.sh
64+
# Install API Helper Python Dependencies
65+
python3 -m venv $DEFAULT_PATH/api-helpers-venv
66+
$DEFAULT_PATH/api-helpers-venv/bin/pip install -r $DEFAULT_PATH/$CUSTOMIZATION/api_helpers/python/requirements.txt
7067
71-
# Generate session profiles
72-
- chmod +x $DEFAULT_PATH/aws-aft-core-framework/sources/scripts/creds.sh
73-
- $DEFAULT_PATH/aws-aft-core-framework/sources/scripts/creds.sh
68+
# Mark helper scripts as executable
69+
chmod +x $DEFAULT_PATH/$CUSTOMIZATION/api_helpers/pre-api-helpers.sh
70+
chmod +x $DEFAULT_PATH/$CUSTOMIZATION/api_helpers/post-api-helpers.sh
71+
72+
# Generate session profiles
73+
chmod +x $DEFAULT_PATH/aws-aft-core-framework/sources/scripts/creds.sh
74+
$DEFAULT_PATH/aws-aft-core-framework/sources/scripts/creds.sh
75+
fi
7476
7577
7678
pre_build:
7779
on-failure: ABORT
7880
commands:
79-
- source $DEFAULT_PATH/api-helpers-venv/bin/activate
80-
- export AWS_PROFILE=aft-target
81-
- $DEFAULT_PATH/$CUSTOMIZATION/api_helpers/pre-api-helpers.sh
82-
- unset AWS_PROFILE
81+
- |
82+
if [[ ! -z "$CUSTOMIZATION" ]]; then
83+
source $DEFAULT_PATH/api-helpers-venv/bin/activate
84+
export AWS_PROFILE=aft-target
85+
$DEFAULT_PATH/$CUSTOMIZATION/api_helpers/pre-api-helpers.sh
86+
unset AWS_PROFILE
87+
fi
8388
8489
build:
8590
on-failure: ABORT
8691
commands:
8792
# Apply Customizations
88-
- source $DEFAULT_PATH/aft-venv/bin/activate
8993
- |
90-
if [ $TF_DISTRIBUTION = "oss" ]; then
91-
TF_BACKEND_REGION=$(aws ssm get-parameter --name "/aft/config/oss-backend/primary-region" --query "Parameter.Value" --output text)
92-
TF_KMS_KEY_ID=$(aws ssm get-parameter --name "/aft/config/oss-backend/kms-key-id" --query "Parameter.Value" --output text)
93-
TF_DDB_TABLE=$(aws ssm get-parameter --name "/aft/config/oss-backend/table-id" --query "Parameter.Value" --output text)
94-
TF_S3_BUCKET=$(aws ssm get-parameter --name "/aft/config/oss-backend/bucket-id" --query "Parameter.Value" --output text)
95-
TF_S3_KEY=$VENDED_ACCOUNT_ID-aft-account-customizations/terraform.tfstate
94+
if [[ ! -z "$CUSTOMIZATION" ]]; then
95+
source $DEFAULT_PATH/aft-venv/bin/activate
96+
if [ $TF_DISTRIBUTION = "oss" ]; then
97+
TF_BACKEND_REGION=$(aws ssm get-parameter --name "/aft/config/oss-backend/primary-region" --query "Parameter.Value" --output text)
98+
TF_KMS_KEY_ID=$(aws ssm get-parameter --name "/aft/config/oss-backend/kms-key-id" --query "Parameter.Value" --output text)
99+
TF_DDB_TABLE=$(aws ssm get-parameter --name "/aft/config/oss-backend/table-id" --query "Parameter.Value" --output text)
100+
TF_S3_BUCKET=$(aws ssm get-parameter --name "/aft/config/oss-backend/bucket-id" --query "Parameter.Value" --output text)
101+
TF_S3_KEY=$VENDED_ACCOUNT_ID-aft-account-customizations/terraform.tfstate
96102
97-
cd /tmp
98-
echo "Installing Terraform"
99-
curl -q -o terraform_${TF_VERSION}_linux_amd64.zip https://releases.hashicorp.com/terraform/${TF_VERSION}/terraform_${TF_VERSION}_linux_amd64.zip
100-
mkdir -p /opt/aft/bin
101-
unzip -q -o terraform_${TF_VERSION}_linux_amd64.zip
102-
mv terraform /opt/aft/bin
103-
/opt/aft/bin/terraform --version
103+
cd /tmp
104+
echo "Installing Terraform"
105+
curl -q -o terraform_${TF_VERSION}_linux_amd64.zip https://releases.hashicorp.com/terraform/${TF_VERSION}/terraform_${TF_VERSION}_linux_amd64.zip
106+
mkdir -p /opt/aft/bin
107+
unzip -q -o terraform_${TF_VERSION}_linux_amd64.zip
108+
mv terraform /opt/aft/bin
109+
/opt/aft/bin/terraform --version
104110
105-
cd $DEFAULT_PATH/$CUSTOMIZATION/terraform
106-
for f in *.jinja; do jinja2 $f -D timestamp="$TIMESTAMP" -D tf_distribution_type=$TF_DISTRIBUTION -D provider_region=$CT_MGMT_REGION -D region=$TF_BACKEND_REGION -D aft_admin_role_arn=$AFT_EXEC_ROLE_ARN -D target_admin_role_arn=$VENDED_EXEC_ROLE_ARN -D bucket=$TF_S3_BUCKET -D key=$TF_S3_KEY -D dynamodb_table=$TF_DDB_TABLE -D kms_key_id=$TF_KMS_KEY_ID >> ./$(basename $f .jinja).tf; done
107-
for f in *.tf; do echo "\n \n"; echo $f; cat $f; done
108-
109-
cd $DEFAULT_PATH/$CUSTOMIZATION/terraform
110-
export AWS_PROFILE=aft-management-admin
111-
/opt/aft/bin/terraform init
112-
/opt/aft/bin/terraform apply --auto-approve
113-
else
114-
TF_BACKEND_REGION=$(aws ssm get-parameter --name "/aft/config/oss-backend/primary-region" --query "Parameter.Value" --output text)
115-
TF_ORG_NAME=$(aws ssm get-parameter --name "/aft/config/terraform/org-name" --query "Parameter.Value" --output text)
116-
TF_TOKEN=$(aws ssm get-parameter --name "/aft/config/terraform/token" --with-decryption --query "Parameter.Value" --output text)
117-
TF_ENDPOINT=$(aws ssm get-parameter --name "/aft/config/terraform/api-endpoint" --query "Parameter.Value" --output text)
118-
TF_WORKSPACE_NAME=$VENDED_ACCOUNT_ID-aft-account-customizations
119-
TF_CONFIG_PATH="./temp_configuration_file.tar.gz"
111+
cd $DEFAULT_PATH/$CUSTOMIZATION/terraform
112+
for f in *.jinja; do jinja2 $f -D timestamp="$TIMESTAMP" -D tf_distribution_type=$TF_DISTRIBUTION -D provider_region=$CT_MGMT_REGION -D region=$TF_BACKEND_REGION -D aft_admin_role_arn=$AFT_EXEC_ROLE_ARN -D target_admin_role_arn=$VENDED_EXEC_ROLE_ARN -D bucket=$TF_S3_BUCKET -D key=$TF_S3_KEY -D dynamodb_table=$TF_DDB_TABLE -D kms_key_id=$TF_KMS_KEY_ID >> ./$(basename $f .jinja).tf; done
113+
for f in *.tf; do echo "\n \n"; echo $f; cat $f; done
114+
115+
cd $DEFAULT_PATH/$CUSTOMIZATION/terraform
116+
export AWS_PROFILE=aft-management-admin
117+
/opt/aft/bin/terraform init
118+
/opt/aft/bin/terraform apply --auto-approve
119+
else
120+
TF_BACKEND_REGION=$(aws ssm get-parameter --name "/aft/config/oss-backend/primary-region" --query "Parameter.Value" --output text)
121+
TF_ORG_NAME=$(aws ssm get-parameter --name "/aft/config/terraform/org-name" --query "Parameter.Value" --output text)
122+
TF_TOKEN=$(aws ssm get-parameter --name "/aft/config/terraform/token" --with-decryption --query "Parameter.Value" --output text)
123+
TF_ENDPOINT=$(aws ssm get-parameter --name "/aft/config/terraform/api-endpoint" --query "Parameter.Value" --output text)
124+
TF_WORKSPACE_NAME=$VENDED_ACCOUNT_ID-aft-account-customizations
125+
TF_CONFIG_PATH="./temp_configuration_file.tar.gz"
120126
121-
cd $DEFAULT_PATH/$CUSTOMIZATION/terraform
122-
for f in *.jinja; do jinja2 $f -D timestamp="$TIMESTAMP" -D provider_region=$CT_MGMT_REGION -D tf_distribution_type=$TF_DISTRIBUTION -D aft_admin_role_arn=$AFT_EXEC_ROLE_ARN -D target_admin_role_arn=$VENDED_EXEC_ROLE_ARN -D terraform_org_name=$TF_ORG_NAME -D terraform_workspace_name=$TF_WORKSPACE_NAME >> ./$(basename $f .jinja).tf; done
123-
for f in *.tf; do echo "\n \n"; echo $f; cat $f; done
124-
125-
cd $DEFAULT_PATH/$CUSTOMIZATION
126-
tar -czf temp_configuration_file.tar.gz -C terraform --exclude .git --exclude venv .
127-
python3 $DEFAULT_PATH/aws-aft-core-framework/sources/scripts/workspace_manager.py --operation "deploy" --organization_name $TF_ORG_NAME --workspace_name $TF_WORKSPACE_NAME --assume_role_arn $AFT_ADMIN_ROLE_ARN --assume_role_session_name $ROLE_SESSION_NAME --api_endpoint $TF_ENDPOINT --api_token $TF_TOKEN --terraform_version $TF_VERSION --config_file $TF_CONFIG_PATH
127+
cd $DEFAULT_PATH/$CUSTOMIZATION/terraform
128+
for f in *.jinja; do jinja2 $f -D timestamp="$TIMESTAMP" -D provider_region=$CT_MGMT_REGION -D tf_distribution_type=$TF_DISTRIBUTION -D aft_admin_role_arn=$AFT_EXEC_ROLE_ARN -D target_admin_role_arn=$VENDED_EXEC_ROLE_ARN -D terraform_org_name=$TF_ORG_NAME -D terraform_workspace_name=$TF_WORKSPACE_NAME >> ./$(basename $f .jinja).tf; done
129+
for f in *.tf; do echo "\n \n"; echo $f; cat $f; done
130+
131+
cd $DEFAULT_PATH/$CUSTOMIZATION
132+
tar -czf temp_configuration_file.tar.gz -C terraform --exclude .git --exclude venv .
133+
python3 $DEFAULT_PATH/aws-aft-core-framework/sources/scripts/workspace_manager.py --operation "deploy" --organization_name $TF_ORG_NAME --workspace_name $TF_WORKSPACE_NAME --assume_role_arn $AFT_ADMIN_ROLE_ARN --assume_role_session_name $ROLE_SESSION_NAME --api_endpoint $TF_ENDPOINT --api_token $TF_TOKEN --terraform_version $TF_VERSION --config_file $TF_CONFIG_PATH
134+
fi
128135
fi
129136
post_build:
130137
on-failure: ABORT
131138
commands:
132-
- source $DEFAULT_PATH/api-helpers-venv/bin/activate
133-
- export AWS_PROFILE=aft-target
134-
- $DEFAULT_PATH/$CUSTOMIZATION/api_helpers/post-api-helpers.sh
139+
- |
140+
if [[ ! -z "$CUSTOMIZATION" ]]; then
141+
source $DEFAULT_PATH/api-helpers-venv/bin/activate
142+
export AWS_PROFILE=aft-target
143+
$DEFAULT_PATH/$CUSTOMIZATION/api_helpers/post-api-helpers.sh
144+
fi

modules/aft-customizations/buildspecs/aft-global-customizations-terraform.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ phases:
5454

5555
# Install API Helper Python Dependencies
5656
- python3 -m venv $DEFAULT_PATH/api-helpers-venv
57-
- $DEFAULT_PATH/api-helpers-venv/bin/pip install -r ./api_helpers/python/requirements.txt
57+
- $DEFAULT_PATH/api-helpers-venv/bin/pip install -r $DEFAULT_PATH/api_helpers/python/requirements.txt
5858

5959
# Mark helper scripts as executable
6060
- chmod +x $DEFAULT_PATH/api_helpers/pre-api-helpers.sh

0 commit comments

Comments
 (0)