Skip to content

Commit 0e849eb

Browse files
committed
Use account-specific Terraform state bucket names
1 parent 523c835 commit 0e849eb

1 file changed

Lines changed: 21 additions & 9 deletions

File tree

  • assessment/project/guides/terraform-collaboration

assessment/project/guides/terraform-collaboration/main.tex

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,25 +33,28 @@ \section{Overview}
3333
\texttt{.terraform/}, AWS credentials, or Learner Lab tokens.
3434
}
3535

36-
\section{Choose a Region and Bucket Name}
36+
\section{Choose an Account, Region, and Bucket Name}
3737

3838
Your team needs one S3 bucket for Terraform state.
39-
Choose one AWS region and one bucket name before configuring Terraform.
40-
Every team member must use the same region, bucket, and state file path.
39+
Choose one AWS account, one AWS region, and one bucket name before configuring Terraform.
40+
Every team member must use the same account, region, bucket, and state file path.
4141

4242
\begin{code}[numbers=none]{}
43+
AWS account ID: 123456789012
4344
AWS region: us-east-1
44-
S3 state bucket: csse6400-team-00-tfstate-a1b2
45+
S3 state bucket: csse6400-t00-123456789012-us-east-1-tfstate
4546
State file path: taskoverflow/terraform.tfstate
4647
\end{code}
4748

4849
\noindent
50+
Replace \texttt{123456789012} with the AWS account ID from your team's assignment Learner Lab.
4951
Replace \texttt{us-east-1} with the AWS region your team is using.
50-
Replace \texttt{csse6400-team-00-tfstate-a1b2} with your team's actual bucket name.
52+
Replace \texttt{t00} with your team number.
5153

5254
\info{
5355
S3 bucket names are globally unique.
54-
Include your course, team number, and a short unique suffix in the name.
56+
Including the team number, AWS account ID, and AWS region makes collisions unlikely
57+
and helps your team spot accidental account or region mismatches.
5558
}
5659

5760
\section{Step 1: Create the Bucket}
@@ -61,10 +64,17 @@ \section{Step 1: Create the Bucket}
6164
First set your chosen values in the terminal.
6265

6366
\begin{code}[language=shell,numbers=none]{}
64-
export TF_STATE_BUCKET=csse6400-team-00-tfstate-a1b2
6567
export AWS_REGION=us-east-1
68+
export TEAM_NUMBER=00
69+
export AWS_ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)
70+
export TF_STATE_BUCKET="csse6400-t${TEAM_NUMBER}-${AWS_ACCOUNT_ID}-${AWS_REGION}-tfstate"
6671
\end{code}
6772

73+
\warning{
74+
Use the AWS account ID from the shared assignment Learner Lab account that will host the project.
75+
Do not create a separate state bucket in each team member's personal practical lab.
76+
}
77+
6878
\noindent
6979
For \texttt{us-east-1}, use:
7080

@@ -79,10 +89,12 @@ \section{Step 1: Create the Bucket}
7989
\end{code}
8090

8191
\noindent
82-
For other regions, change \texttt{AWS\_REGION} and include a location constraint:
92+
For other regions, set \texttt{AWS\_REGION} before generating the bucket name,
93+
and include a location constraint:
8394

8495
\begin{code}[language=shell,numbers=none]{}
8596
export AWS_REGION=ap-southeast-2
97+
export TF_STATE_BUCKET="csse6400-t${TEAM_NUMBER}-${AWS_ACCOUNT_ID}-${AWS_REGION}-tfstate"
8698
8799
aws s3api create-bucket \
88100
--bucket "$TF_STATE_BUCKET" \
@@ -118,7 +130,7 @@ \section{Step 2: Create Backend Files}
118130
This file tells Terraform which S3 bucket should store the shared state.
119131

120132
\begin{code}[language=terraform,numbers=none]{backend.hcl}
121-
bucket = "csse6400-team-00-tfstate-a1b2"
133+
bucket = "csse6400-t00-123456789012-us-east-1-tfstate"
122134
key = "taskoverflow/terraform.tfstate"
123135
region = "us-east-1"
124136
encrypt = true

0 commit comments

Comments
 (0)