This repository has been archived by the owner on Feb 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from wellcometrust/add-route53-hosted-zone
Add route 52 cross account hosted zone module
- Loading branch information
Showing
5 changed files
with
119 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# TCAR53HZRP! | ||
## Terraform Cross Account Route53 Hosted Zone Role Policy | ||
|
||
Terraform module for sharing Route53 hosted zones between accounts. | ||
|
||
You might want to use this if you have multiple AWS accounts with one account looking after all hosted zones, but you have developers working in another account who want to update a particular hosted zone. | ||
|
||
## Usage | ||
|
||
Create a Terraform module like this in your existing infrastructure description. | ||
|
||
```tf | ||
module "my_route53_iam_role" { | ||
source = "git::https://github.com/wellcometrust/terraform.git//terraform/route53_cross_account_hosted_zone?ref=v1.0.4" | ||
account_id = "4w54cc0un71d" | ||
hosted_zone_id = "H0573DZ0N31D" | ||
role_name = "my_role_name" | ||
} | ||
``` | ||
|
||
Consumers of the role can use a link like the following to switch roles in their console: | ||
|
||
` | ||
https://signin.aws.amazon.com/switchrole?account=my_account_name&roleName=my_role_name | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
output "aws_iam_role_arn" { | ||
value = "${aws_iam_role.role.arn}" | ||
} | ||
|
||
output "aws_iam_role_uid" { | ||
value = "${aws_iam_role.role.unique_id}" | ||
} | ||
|
||
output "aws_iam_role_create_date" { | ||
value = "${aws_iam_role.role.create_date}" | ||
} | ||
|
||
output "aws_iam_role_policy_id" { | ||
value = "${aws_iam_role_policy.policy.id}" | ||
} | ||
|
||
output "aws_iam_role_policy_name" { | ||
value = "${aws_iam_role_policy.policy.name}" | ||
} | ||
|
||
output "aws_iam_role_policy_policy" { | ||
value = "${aws_iam_role_policy.policy.policy}" | ||
} | ||
|
||
output "aws_iam_role_policy_role" { | ||
value = "${aws_iam_role_policy.policy.role}" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
resource "aws_iam_role_policy" "policy" { | ||
name = "${var.role_name}-route53-policy" | ||
role = "${aws_iam_role.role.id}" | ||
|
||
policy = <<EOF | ||
{ | ||
"Version": "2012-10-17", | ||
"Statement": [ | ||
{ | ||
"Effect": "Allow", | ||
"Action": [ | ||
"route53:ListHostedZones" | ||
], | ||
"Resource": "*" | ||
}, | ||
{ | ||
"Effect": "Allow", | ||
"Action": [ | ||
"route53:GetHostedZone" | ||
], | ||
"Resource": "arn:aws:route53:::hostedzone/${var.hosted_zone_id}" | ||
}, | ||
{ | ||
"Effect": "Allow", | ||
"Action": [ | ||
"route53:ListResourceRecordSets" | ||
], | ||
"Resource": "arn:aws:route53:::hostedzone/${var.hosted_zone_id}" | ||
}, | ||
{ | ||
"Effect": "Allow", | ||
"Action": [ | ||
"route53:ChangeResourceRecordSets" | ||
], | ||
"Resource": "arn:aws:route53:::hostedzone/${var.hosted_zone_id}" | ||
} | ||
] | ||
} | ||
EOF | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
resource "aws_iam_role" "role" { | ||
name = "${var.role_name}" | ||
|
||
assume_role_policy = <<EOF | ||
{ | ||
"Version": "2012-10-17", | ||
"Statement": { | ||
"Effect": "Allow", | ||
"Principal": { | ||
"AWS": "arn:aws:iam::${var.account_id}:root" | ||
}, | ||
"Action": "sts:AssumeRole" | ||
} | ||
} | ||
EOF | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
variable "role_name" { | ||
description = "Unique name of role to create" | ||
} | ||
|
||
variable "account_id" { | ||
description = "ID of account to trust" | ||
} | ||
|
||
variable "hosted_zone_id" { | ||
description = "ID of hosted zone to make available" | ||
} |