Skip to content

Commit

Permalink
Add projects from root stage. Add account project (#10)
Browse files Browse the repository at this point in the history
* Add projects from `root` stage. Add `account` project

* Rename to `accounts`

* Add `account-dns`

* Update `accounts` and `iam` projects
  • Loading branch information
aknysh authored Jun 8, 2018
1 parent 955e3d0 commit a76b963
Show file tree
Hide file tree
Showing 37 changed files with 437 additions and 44 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ This is a collection of reusable root modules for CloudPosse AWS accounts.
Use the `terraform-root-modules` Docker image as the base image in the application `Dockerfile`, and copy the modules from `/aws` folder into `/conf` folder

```dockerfile
FROM cloudposse/terraform-root-modules:0.1.6 as terraform-root-modules
FROM cloudposse/terraform-root-modules:0.2.2 as terraform-root-modules

FROM cloudposse/geodesic:0.9.16
FROM cloudposse/geodesic:0.9.18

# Copy root modules into /conf folder
COPY --from=terraform-root-modules /aws/ /conf/
Expand Down
43 changes: 43 additions & 0 deletions aws/account-dns/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
terraform {
required_version = ">= 0.11.2"

backend "s3" {}
}

variable "aws_assume_role_arn" {
type = "string"
}

variable "domain_name" {
type = "string"
description = "Domain name"
}

provider "aws" {
assume_role {
role_arn = "${var.aws_assume_role_arn}"
}
}

resource "aws_route53_zone" "dns_zone" {
name = "${var.domain_name}"
}

resource "aws_route53_record" "dns_zone_soa" {
zone_id = "${aws_route53_zone.dns_zone.id}"
name = "${aws_route53_zone.dns_zone.name}"
type = "SOA"
ttl = "60"

records = [
"${aws_route53_zone.dns_zone.name_servers.0}. awsdns-hostmaster.amazon.com. 1 7200 900 1209600 86400",
]
}

output "zone_id" {
value = "${aws_route53_zone.dns_zone.zone_id}"
}

output "name_servers" {
value = "${aws_route53_zone.dns_zone.name_servers}"
}
File renamed without changes.
2 changes: 2 additions & 0 deletions aws/accounts/audit.auto.tfvars.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
audit_account_name="audit"
audit_account_email="[email protected]"
21 changes: 21 additions & 0 deletions aws/accounts/audit.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
variable "audit_account_name" {
type = "string"
description = "Audit account name"
default = "audit"
}

variable "audit_account_email" {
type = "string"
description = "Audit account email"
}

resource "aws_organizations_account" "audit" {
name = "${var.audit_account_name}"
email = "${var.audit_account_email}"
iam_user_access_to_billing = "${var.account_iam_user_access_to_billing}"
role_name = "${var.account_role_name}"
}

output "audit_account_arn" {
value = "${aws_organizations_account.audit.arn}"
}
2 changes: 2 additions & 0 deletions aws/accounts/dev.auto.tfvars.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dev_account_name="dev"
dev_account_email="[email protected]"
21 changes: 21 additions & 0 deletions aws/accounts/dev.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
variable "dev_account_name" {
type = "string"
description = "Dev account name"
default = "dev"
}

variable "dev_account_email" {
type = "string"
description = "Dev account email"
}

resource "aws_organizations_account" "dev" {
name = "${var.dev_account_name}"
email = "${var.dev_account_email}"
iam_user_access_to_billing = "${var.account_iam_user_access_to_billing}"
role_name = "${var.account_role_name}"
}

output "dev_account_arn" {
value = "${aws_organizations_account.dev.arn}"
}
27 changes: 27 additions & 0 deletions aws/accounts/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
terraform {
required_version = ">= 0.11.2"

backend "s3" {}
}

variable "aws_assume_role_arn" {
type = "string"
}

variable "account_role_name" {
type = "string"
description = "IAM role that Organization automatically preconfigures in the new member account"
default = "OrganizationAccountAccessRole"
}

variable "account_iam_user_access_to_billing" {
type = "string"
description = "If set to `ALLOW`, the new account enables IAM users to access account billing information if they have the required permissions. If set to `DENY`, then only the root user of the new account can access account billing information"
default = "DENY"
}

provider "aws" {
assume_role {
role_arn = "${var.aws_assume_role_arn}"
}
}
2 changes: 2 additions & 0 deletions aws/accounts/prod.auto.tfvars.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
prod_account_name="prod"
prod_account_email="[email protected]"
21 changes: 21 additions & 0 deletions aws/accounts/prod.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
variable "prod_account_name" {
type = "string"
description = "Production account name"
default = "prod"
}

variable "prod_account_email" {
type = "string"
description = "Production account email"
}

resource "aws_organizations_account" "prod" {
name = "${var.prod_account_name}"
email = "${var.prod_account_email}"
iam_user_access_to_billing = "${var.account_iam_user_access_to_billing}"
role_name = "${var.account_role_name}"
}

output "prod_account_arn" {
value = "${aws_organizations_account.prod.arn}"
}
2 changes: 2 additions & 0 deletions aws/accounts/staging.auto.tfvars.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
staging_account_name="staging"
staging_account_email="[email protected]"
21 changes: 21 additions & 0 deletions aws/accounts/staging.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
variable "staging_account_name" {
type = "string"
description = "Staging account name"
default = "staging"
}

variable "staging_account_email" {
type = "string"
description = "Staging account email"
}

resource "aws_organizations_account" "staging" {
name = "${var.staging_account_name}"
email = "${var.staging_account_email}"
iam_user_access_to_billing = "${var.account_iam_user_access_to_billing}"
role_name = "${var.account_role_name}"
}

output "staging_account_arn" {
value = "${aws_organizations_account.staging.arn}"
}
4 changes: 3 additions & 1 deletion aws/acm-cloudfront/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ terraform {
backend "s3" {}
}

variable "aws_assume_role_arn" {}
variable "aws_assume_role_arn" {
type = "string"
}

provider "aws" {
# CloudFront certs must be created in the `aws-east-1` region, even if your origin is in a different one
Expand Down
32 changes: 0 additions & 32 deletions aws/dns/main.tf

This file was deleted.

7 changes: 0 additions & 7 deletions aws/dns/outputs.tf

This file was deleted.

2 changes: 2 additions & 0 deletions aws/iam/audit.auto.tfvars.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
audit_account_id=""
audit_account_user_names=["", "",]
19 changes: 19 additions & 0 deletions aws/iam/audit.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
variable "audit_account_id" {
type = "string"
description = "Audit account ID"
}

variable "audit_account_user_names" {
type = "list"
description = "IAM user names to grant access to Audit account"
}

# Provision group access to audit account. Careful! Very few people, if any should have access to this account.
module "organization_access_group_audit" {
source = "git::https://github.com/cloudposse/terraform-aws-organization-access-group.git?ref=tags/0.1.2"
namespace = "${var.namespace}"
stage = "audit"
name = "admin"
user_names = ["${var.audit_account_user_names}"]
member_account_id = "${var.audit_account_id}"
}
2 changes: 2 additions & 0 deletions aws/iam/dev.auto.tfvars.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dev_account_id=""
dev_account_user_names=["", "",]
19 changes: 19 additions & 0 deletions aws/iam/dev.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
variable "dev_account_id" {
type = "string"
description = "Dev account ID"
}

variable "dev_account_user_names" {
type = "list"
description = "IAM user names to grant access to Dev account"
}

# Provision group access to dev account
module "organization_access_group_dev" {
source = "git::https://github.com/cloudposse/terraform-aws-organization-access-group.git?ref=tags/0.1.2"
namespace = "${var.namespace}"
stage = "dev"
name = "admin"
user_names = ["${var.dev_account_user_names}"]
member_account_id = "${var.dev_account_id}"
}
20 changes: 20 additions & 0 deletions aws/iam/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
terraform {
required_version = ">= 0.11.2"

backend "s3" {}
}

variable "aws_assume_role_arn" {
type = "string"
}

variable "namespace" {
type = "string"
description = "Namespace (e.g. `cp` or `cloudposse`)"
}

provider "aws" {
assume_role {
role_arn = "${var.aws_assume_role_arn}"
}
}
2 changes: 2 additions & 0 deletions aws/iam/prod.auto.tfvars.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
prod_account_id=""
prod_account_user_names=["", "",]
19 changes: 19 additions & 0 deletions aws/iam/prod.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
variable "prod_account_id" {
type = "string"
description = "Production account ID"
}

variable "prod_account_user_names" {
type = "list"
description = "IAM user names to grant access to Production account"
}

# Provision group access to production account
module "organization_access_group_prod" {
source = "git::https://github.com/cloudposse/terraform-aws-organization-access-group.git?ref=tags/0.1.2"
namespace = "${var.namespace}"
stage = "prod"
name = "admin"
user_names = ["${var.prod_account_user_names}"]
member_account_id = "${var.prod_account_id}"
}
2 changes: 2 additions & 0 deletions aws/iam/root.auto.tfvars.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
root_account_admin_user_names=["", "",]
root_account_readonly_user_names=["", "",]
21 changes: 21 additions & 0 deletions aws/iam/root.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
variable "root_account_admin_user_names" {
type = "list"
description = "IAM user names to grant admin access to Root account"
}

variable "root_account_readonly_user_names" {
type = "list"
description = "IAM user names to grant readonly access to Root account"
default = []
}

# Provision group access to root account with MFA
module "organization_access_group_root" {
source = "git::https://github.com/cloudposse/terraform-aws-iam-assumed-roles.git?ref=tags/0.2.0"
namespace = "${var.namespace}"
stage = "root"
admin_name = "admin"
readonly_name = "readonly"
admin_user_names = ["${var.root_account_admin_user_names}"]
readonly_user_names = ["${var.root_account_readonly_user_names}"]
}
2 changes: 2 additions & 0 deletions aws/iam/staging.auto.tfvars.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
staging_account_id=""
staging_account_user_names=["", "",]
19 changes: 19 additions & 0 deletions aws/iam/staging.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
variable "staging_account_id" {
type = "string"
description = "Staging account ID"
}

variable "staging_account_user_names" {
type = "list"
description = "IAM user names to grant access to Staging account"
}

# Provision group access to staging account
module "organization_access_group_staging" {
source = "git::https://github.com/cloudposse/terraform-aws-organization-access-group.git?ref=tags/0.1.2"
namespace = "${var.namespace}"
stage = "staging"
name = "admin"
user_names = ["${var.staging_account_user_names}"]
member_account_id = "${var.staging_account_id}"
}
2 changes: 1 addition & 1 deletion aws/kops-aws-platform/terraform.tfvars.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace="cp"
stage="staging"
region="us-west-2"
zone_name="us-west-2.cloudposse.co"
zone_name="us-west-2.staging.cloudposse.co"
2 changes: 1 addition & 1 deletion aws/organization/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ variable "aws_assume_role_arn" {
variable "organization_feature_set" {
type = "string"
default = "ALL"
description = "Specify `ALL` (default) or `CONSOLIDATED_BILLING`"
description = "`ALL` (default) or `CONSOLIDATED_BILLING`"
}

provider "aws" {
Expand Down
Loading

0 comments on commit a76b963

Please sign in to comment.