11#! /usr/bin/env bash
22
33echo " $COMMIT_ID "
4+ CF_LONDON_EXPORTS=$( aws cloudformation list-exports --region eu-west-2 --output json)
5+ ARTIFACT_BUCKET_ARN=$( echo " $CF_LONDON_EXPORTS " | \
6+ jq \
7+ --arg EXPORT_NAME " account-resources-cdk-uk:Bucket:ArtifactsBucket:Arn" \
8+ -r ' .Exports[] | select(.Name == $EXPORT_NAME) | .Value' )
9+ ARTIFACT_BUCKET_NAME=$( echo " $ARTIFACT_BUCKET_ARN " | cut -d: -f6 | cut -d/ -f1)
10+ if [ -z " ${ARTIFACT_BUCKET_NAME} " ]; then
11+ echo " could not retrieve artifact_bucket from aws cloudformation list-exports"
12+ exit 1
13+ fi
414
5- artifact_bucket=$( aws cloudformation list-exports --output json | jq -r ' .Exports[] | select(.Name == "account-resources:ArtifactsBucket") | .Value' | grep -o ' [^:]*$' )
6- export artifact_bucket
7-
8- cloud_formation_execution_role=$( aws cloudformation list-exports --output json | jq -r ' .Exports[] | select(.Name == "ci-resources:CloudFormationExecutionRole") | .Value' )
9- export cloud_formation_execution_role
15+ CLOUD_FORMATION_EXECUTION_ROLE=$( echo " $CF_LONDON_EXPORTS " | \
16+ jq \
17+ --arg EXPORT_NAME " iam-cdk:IAM:CloudFormationExecutionRole:Arn" \
18+ -r ' .Exports[] | select(.Name == $EXPORT_NAME) | .Value' )
19+ if [ -z " ${CLOUD_FORMATION_EXECUTION_ROLE} " ]; then
20+ echo " could not retrieve cloud_formation_execution_role from aws cloudformation list-exports"
21+ exit 1
22+ fi
1023
11- TRUSTSTORE_BUCKET_ARN=$( aws cloudformation describe-stacks --stack-name account-resources --query " Stacks[0].Outputs[?OutputKey=='TrustStoreBucket'].OutputValue" --output text)
24+ TRUSTSTORE_BUCKET_ARN=$( echo " $CF_LONDON_EXPORTS " | \
25+ jq \
26+ --arg EXPORT_NAME " account-resources-cdk-uk:Bucket:TrustStoreBucket:Arn" \
27+ -r ' .Exports[] | select(.Name == $EXPORT_NAME) | .Value' )
1228TRUSTSTORE_BUCKET_NAME=$( echo " ${TRUSTSTORE_BUCKET_ARN} " | cut -d " :" -f 6)
29+ if [ -z " ${TRUSTSTORE_BUCKET_NAME} " ]; then
30+ echo " could not retrieve truststore_bucket from aws cloudformation list-exports"
31+ exit 1
32+ fi
1333LATEST_TRUSTSTORE_VERSION=$( aws s3api list-object-versions --bucket " ${TRUSTSTORE_BUCKET_NAME} " --prefix " ${TRUSTSTORE_FILE} " --query ' Versions[?IsLatest].[VersionId]' --output text)
34+
1435export LATEST_TRUSTSTORE_VERSION
36+ export ARTIFACT_BUCKET_NAME
37+ export CLOUD_FORMATION_EXECUTION_ROLE
1538
1639cd ../../ || exit
1740
@@ -27,11 +50,11 @@ sam deploy \
2750 --stack-name " $STACK_NAME " \
2851 --capabilities CAPABILITY_NAMED_IAM CAPABILITY_AUTO_EXPAND \
2952 --region eu-west-2 \
30- --s3-bucket " $artifact_bucket " \
53+ --s3-bucket " $ARTIFACT_BUCKET_NAME " \
3154 --s3-prefix " $ARTIFACT_BUCKET_PREFIX " \
3255 --config-file samconfig_package_and_deploy.toml \
3356 --no-fail-on-empty-changeset \
34- --role-arn " $cloud_formation_execution_role " \
57+ --role-arn " $CLOUD_FORMATION_EXECUTION_ROLE " \
3558 --no-confirm-changeset \
3659 --force-upload \
3760 --tags " version=$VERSION_NUMBER stack=$STACK_NAME repo=$REPO cfnDriftDetectionGroup=$CFN_DRIFT_DETECTION_GROUP " \
0 commit comments