@@ -31,39 +31,90 @@ Install the dependencies:
3131* [ Terraform] ( https://www.terraform.io/downloads.html ) .
3232* [ Docker] ( https://docs.docker.com/engine/install/ ) .
3333
34- Set the AWS Account credentials using SSO:
34+ Set the AWS Account credentials using SSO, e.g. :
3535
3636``` bash
37+ # set the account credentials.
38+ # NB the aws cli stores these at ~/.aws/config.
39+ # NB this is equivalent to manually configuring SSO using aws configure sso.
40+ # see https://docs.aws.amazon.com/cli/latest/userguide/sso-configure-profile-token.html#sso-configure-profile-token-manual
41+ # see https://docs.aws.amazon.com/cli/latest/userguide/sso-configure-profile-token.html#sso-configure-profile-token-auto-sso
42+ cat > secrets.sh << 'EOF '
3743# set the environment variables to use a specific profile.
38- # e.g. use the pattern <aws-sso-session-name>-<aws-account-name>-<aws-account-role>-<aws-account-id>
39- export AWS_PROFILE=example-dev-AdministratorAccess-123456
44+ # NB use aws configure sso to configure these manually.
45+ # e.g. use the pattern <aws-sso-session>-<aws-account-id>-<aws-role-name>
46+ export aws_sso_session='example'
47+ export aws_sso_start_url='https://example.awsapps.com/start'
48+ export aws_sso_region='eu-west-1'
49+ export aws_sso_account_id='123456'
50+ export aws_sso_role_name='AdministratorAccess'
51+ export AWS_PROFILE="$aws_sso_session-$aws_sso_account_id-$aws_sso_role_name"
4052unset AWS_ACCESS_KEY_ID
4153unset AWS_SECRET_ACCESS_KEY
4254unset AWS_DEFAULT_REGION
43- # set the account credentials.
44- # see https://docs.aws.amazon.com/cli/latest/userguide/sso-configure-profile-token.html#sso-configure-profile-token-auto-sso
45- aws configure sso
46- # dump the configured profile and sso-session.
47- cat ~ /.aws/config
55+ # configure the ~/.aws/config file.
56+ # NB unfortunately, I did not find a way to create the [sso-session] section
57+ # inside the ~/.aws/config file using the aws cli. so, instead, manage that
58+ # file using python.
59+ python3 <<'PY_EOF'
60+ import configparser
61+ import os
62+ aws_sso_session = os.getenv('aws_sso_session')
63+ aws_sso_start_url = os.getenv('aws_sso_start_url')
64+ aws_sso_region = os.getenv('aws_sso_region')
65+ aws_sso_account_id = os.getenv('aws_sso_account_id')
66+ aws_sso_role_name = os.getenv('aws_sso_role_name')
67+ aws_profile = os.getenv('AWS_PROFILE')
68+ config = configparser.ConfigParser()
69+ aws_config_directory_path = os.path.expanduser('~/.aws')
70+ aws_config_path = os.path.join(aws_config_directory_path, 'config')
71+ if os.path.exists(aws_config_path):
72+ config.read(aws_config_path)
73+ config[f'sso-session {aws_sso_session}'] = {
74+ 'sso_start_url': aws_sso_start_url,
75+ 'sso_region': aws_sso_region,
76+ 'sso_registration_scopes': 'sso:account:access',
77+ }
78+ config[f'profile {aws_profile}'] = {
79+ 'sso_session': aws_sso_session,
80+ 'sso_account_id': aws_sso_account_id,
81+ 'sso_role_name': aws_sso_role_name,
82+ 'region': aws_sso_region,
83+ }
84+ os.makedirs(aws_config_directory_path, mode=0o700, exist_ok=True)
85+ with open(aws_config_path, 'w') as f:
86+ config.write(f)
87+ PY_EOF
88+ unset aws_sso_start_url
89+ unset aws_sso_region
90+ unset aws_sso_session
91+ unset aws_sso_account_id
92+ unset aws_sso_role_name
4893# show the user, user amazon resource name (arn), and the account id, of the
4994# profile set in the AWS_PROFILE environment variable.
95+ if ! aws sts get-caller-identity >/dev/null 2>&1; then
96+ aws sso login
97+ fi
5098aws sts get-caller-identity
99+ EOF
51100```
52101
53- Or, set the AWS Account credentials using an Access Key:
102+ Or, set the AWS Account credentials using an Access Key, e.g. :
54103
55104``` bash
56105# set the account credentials.
57106# NB get these from your aws account iam console.
58107# see Managing access keys (console) at
59108# https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_access-keys.html#Using_CreateAccessKey
109+ cat > secrets.sh << 'EOF '
60110export AWS_ACCESS_KEY_ID='TODO'
61111export AWS_SECRET_ACCESS_KEY='TODO'
62112unset AWS_PROFILE
63113# set the default region.
64114export AWS_DEFAULT_REGION='eu-west-1'
65115# show the user, user amazon resource name (arn), and the account id.
66116aws sts get-caller-identity
117+ EOF
67118```
68119
69120Review the [ ` inputs.tf ` ] ( inputs.tf ) file.
@@ -77,6 +128,10 @@ terraform init -lockfile=readonly
77128Deploy the example:
78129
79130``` bash
131+ export CHECKPOINT_DISABLE=' 1'
132+ export TF_LOG=' DEBUG' # TRACE, DEBUG, INFO, WARN or ERROR.
133+ export TF_LOG_PATH=' terraform.log'
134+ rm -f " $TF_LOG_PATH "
80135terraform apply
81136```
82137
0 commit comments