File tree 3 files changed +365
-20
lines changed 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 {
10
10
}
11
11
12
12
provider "aws" {
13
- region = " ${ var . aws_region } "
13
+ region = var. aws_region
14
14
}
15
15
16
16
module "bootstrap" {
17
17
source = " trussworks/bootstrap/aws"
18
18
19
- region = " ${ var . aws_region } "
20
- account_alias = " ${ var . account_alias } "
19
+ region = var. aws_region
20
+ account_alias = var. account_alias
21
21
dynamodb_table_name = " ${ var . account_alias } -state-lock"
22
22
}
23
23
24
24
data "aws_caller_identity" "current" {}
25
25
26
26
output "account_id" {
27
- value = " ${ data . aws_caller_identity . current . account_id } "
27
+ value = data. aws_caller_identity . current . account_id
28
28
}
29
29
30
30
output "arn" {
31
- value = " ${ data . aws_caller_identity . current . arn } "
31
+ value = data. aws_caller_identity . current . arn
32
32
}
33
33
34
34
output "user_id" {
35
- value = " ${ data . aws_caller_identity . current . user_id } "
35
+ value = data. aws_caller_identity . current . user_id
36
36
}
37
37
38
38
output "backend_details" {
39
39
description = " Details of the S3 bucket and DynamoDB tables created for backend"
40
- value = " ${ module . bootstrap } "
40
+ value = module. bootstrap
41
41
}
You can’t perform that action at this time.
0 commit comments