Skip to content

Commit

Permalink
Merge pull request geckoboard#1 from geckoboard/add-terraform-modules
Browse files Browse the repository at this point in the history
Add terraform modules
  • Loading branch information
BRMatt authored Jan 9, 2019
2 parents c1a18e1 + b988282 commit e4e8a28
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: 2
jobs:
build:
docker:
- image: hashicorp/terraform
steps:
- checkout
- run: apk update && apk add colordiff --no-cache --force-refresh --repository http://dl-cdn.alpinelinux.org/alpine/edge/community/
- run: cd terraform && terraform fmt -diff=true -check=true | colordiff
20 changes: 20 additions & 0 deletions terraform/aws-app-role/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
resource "aws_iam_role" "slash-infra-access" {
name = "${var.role_name}"
assume_role_policy = "${data.aws_iam_policy_document.allow-slash-infra-account-to-assume.json}"

tags = {
CreatedBy = "terraform"
}
}

data "aws_iam_policy_document" "allow-slash-infra-account-to-assume" {
statement {
id = "1"
actions = ["sts:AssumeRole"]

principals {
type = "AWS"
identifiers = ["${var.trusted_aws_account_id}"]
}
}
}
4 changes: 4 additions & 0 deletions terraform/aws-app-role/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
output "iam_role_arn" {
description = "The ARN of the IAM role that will be assumed by slash-infra's IAM user. Useful for attaching additional policies to the role that are specific to your org"
value = "${aws_iam_role.slash-infra-access.arn}"
}
8 changes: 8 additions & 0 deletions terraform/aws-app-role/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
variable "role_name" {
description = "The name of the role to create. This should match the name of the role your IAM user has permission to assume"
default = "SlashInfraAccess"
}

variable "trusted_aws_account_id" {
description = "The ID of the account in which the AWS IAM user for slash-infra lives"
}
22 changes: 22 additions & 0 deletions terraform/aws-app-user/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
resource "aws_iam_user" "app-user" {
name = "${var.username}"
}

resource "aws_iam_user_policy" "allow-assuming-slash-infra-roles" {
name = "allow-assuming-slash-infra-roles"
user = "${aws_iam_user.app-user.name}"

policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowAssumingSlashInfraRoles",
"Effect": "Allow",
"Action": "sts:AssumeRole",
"Resource": "arn:aws:iam::*:role/${var.role_name}"
}
]
}
EOF
}
9 changes: 9 additions & 0 deletions terraform/aws-app-user/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
variable "username" {
description = "This will be the username given to the AWS IAM user"
default = "slash-infra-app"
}

variable "role_name" {
description = "The name of the role your AWS accounts will use. By default this is the only role the user will be allowed to assume"
default = "SlashInfraApp"
}

0 comments on commit e4e8a28

Please sign in to comment.