File tree Expand file tree Collapse file tree 3 files changed +365
-20
lines changed Expand file tree Collapse file tree 3 files changed +365
-20
lines changed Original file line number Diff line number Diff line change 1+ /*
2+ We use jenkins to automate deployment with Terraform. Jenkins
3+ is set up in a different AWS account.
4+
5+ This group of IAM resources allow jenkins to assume a role needed
6+ to deploy resources (and make changes to backend).
7+ */
8+
9+ data "aws_iam_policy_document" "terraform_backend_account_policy" {
10+ statement {
11+ effect = " Allow"
12+
13+ principals {
14+ type = " AWS"
15+ identifiers = [" arn:aws:iam::191447213457:role/jenkins-role" ]
16+ }
17+
18+ actions = [" sts:AssumeRole" ]
19+ }
20+ }
21+
22+ resource "aws_iam_role" "terraform_backend_role" {
23+ name = " terraform_sandbox_backend_admin"
24+ assume_role_policy = data. aws_iam_policy_document . terraform_backend_account_policy . json
25+ }
26+
27+ data "aws_iam_policy_document" "terraform_backend_role_policy_document" {
28+ statement {
29+ effect = " Allow"
30+
31+ actions = [" s3:*" ]
32+ resources = [" arn:aws:s3:::${ module . bootstrap . state_bucket } /*" ]
33+ }
34+ }
35+
36+ resource "aws_iam_policy" "terraform_backend_role_policy" {
37+ name = " terraform-backend-role-policy"
38+ policy = data. aws_iam_policy_document . terraform_backend_role_policy_document . json
39+ }
40+
41+ resource "aws_iam_role_policy_attachment" "terraform_backend_attachment" {
42+ role = aws_iam_role. terraform_backend_role . name
43+ policy_arn = aws_iam_policy. terraform_backend_role_policy . arn
44+ }
Original file line number Diff line number Diff line change @@ -10,32 +10,32 @@ terraform {
1010}
1111
1212provider "aws" {
13- region = " ${ var . aws_region } "
13+ region = var. aws_region
1414}
1515
1616module "bootstrap" {
1717 source = " trussworks/bootstrap/aws"
1818
19- region = " ${ var . aws_region } "
20- account_alias = " ${ var . account_alias } "
19+ region = var. aws_region
20+ account_alias = var. account_alias
2121 dynamodb_table_name = " ${ var . account_alias } -state-lock"
2222}
2323
2424data "aws_caller_identity" "current" {}
2525
2626output "account_id" {
27- value = " ${ data . aws_caller_identity . current . account_id } "
27+ value = data. aws_caller_identity . current . account_id
2828}
2929
3030output "arn" {
31- value = " ${ data . aws_caller_identity . current . arn } "
31+ value = data. aws_caller_identity . current . arn
3232}
3333
3434output "user_id" {
35- value = " ${ data . aws_caller_identity . current . user_id } "
35+ value = data. aws_caller_identity . current . user_id
3636}
3737
3838output "backend_details" {
3939 description = " Details of the S3 bucket and DynamoDB tables created for backend"
40- value = " ${ module . bootstrap } "
40+ value = module. bootstrap
4141}
You can’t perform that action at this time.
0 commit comments