The terraform process is designed with least-privilege processes. The initial call is to the "AWS Build Account" with a limited set of access. This in turn results in the least-privilege keys to the associated secondary account. From there the keys are rotated in, a connection is made to the new account and operations run.
For any service that lives atop the main setup, their own IAM policy should be present to operate and should not rely on the DevOps user in the accounts for access rights to the various components required in AWS.
- Create a new programmatic access user in the new account. This user will be utilised for the primary terraform operation for that account.
- Attach the following AWS managed policies:
- AmazonEC2FullAccess
- AmazonEC2RoleforSSM
- AmazonEC2RoleforAWSCodeDeploy
- AWSCodeDeployFullAccess
- AmazonEC2RoleforDataPipelineRole
- AWSCodePipeline_FullAccess
- AmazonEC2RoleforAWSCodeDeployLimited
- Copy the new keys ready to use in the next step.
Store the new keys in the AWS Account - Systems Manager ( SSM ) Parameter Store using the following format:
/gingerco/deploy/dev/{client_name}/deployment_access/access.key
/gingerco/deploy/dev/{client_name}/deployment_access/secret.key
These can then be used for the following step to generate the bucket:
This script is designed to generate the S3 bucket in your new account:
To run the code from your machine:
setup {deployment environment:dev/stage/live} {client name for service prefix} {how to run code: deploy/plan}
For example:
setup dev gingerco plan
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:PutObject",
"s3:GetObject",
"s3:ListBucket",
"s3:DeleteObject",
"s3:GetObjectVersion"
],
"Resource": [
"arn:aws:s3:::{client_name}-terraform",
"arn:aws:s3:::{client_name}-terraform/*"
]
}
]
}
Name it s3-terraform so that you can easily see what it is.
This will allow the user to access and use the folder correctly going forward.
Note: The terraform script to create the bucket does not store the state in S3 ( for obvious reasons ). It is designed as a fire and forget item you can run from your own machine using the new credentials you create for initial account setup.