Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Terraform ECR repositories #47

Merged
merged 1 commit into from
Jul 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions alm/container_registry.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module "joomla_restore_repository" {
source = "ecr"

alm_account_id = "${var.alm_account_id}"
repository_name = "joomla-restore"
}

module "joomla_cron_repository" {
source = "ecr"

alm_account_id = "${var.alm_account_id}"
repository_name = "joomla-cron"
}

module "joomla_nginx_repository" {
source = "ecr"

alm_account_id = "${var.alm_account_id}"
repository_name = "joomla-nginx"
}
28 changes: 28 additions & 0 deletions alm/ecr/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
variable "alm_account_id" {
description = "Account Id of the Application Life Cycle Management network"
}

variable "repository_name" {
description = "Name of the repository to create without the prefix"
}

locals {
policy_file = "${var.alm_account_id == "068920858268" ? "repository_policy.sandbox.json" : "repository_policy.json"}"
}

data "template_file" "repository_policy" {
template = "${file("${path.module}/${local.policy_file}")}"

vars {
alm_account_id = "${var.alm_account_id}"
}
}

resource "aws_ecr_repository" "repository" {
name = "scos/${var.repository_name}"
}

resource "aws_ecr_repository_policy" "restore_policy" {
repository = "${aws_ecr_repository.repository.name}"
policy = "${data.template_file.repository_policy.rendered}"
}
73 changes: 73 additions & 0 deletions alm/ecr/repository_policy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{
"Version": "2008-10-17",
"Statement": [
{
"Sid": "JenkinsUserRegistryAccess",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::${alm_account_id}:user/jenkins_user"
},
"Action": [
"ecr:GetDownloadUrlForLayer",
"ecr:BatchGetImage",
"ecr:BatchCheckLayerAvailability",
"ecr:PutImage",
"ecr:InitiateLayerUpload",
"ecr:UploadLayerPart",
"ecr:CompleteLayerUpload",
"ecr:DescribeRepositories",
"ecr:GetRepositoryPolicy",
"ecr:ListImages",
"ecr:DescribeImages",
"ecr:DeleteRepository",
"ecr:BatchDeleteImage",
"ecr:SetRepositoryPolicy",
"ecr:DeleteRepositoryPolicy",
"ecr:GetLifecyclePolicy",
"ecr:PutLifecyclePolicy",
"ecr:DeleteLifecyclePolicy",
"ecr:GetLifecyclePolicyPreview",
"ecr:StartLifecyclePolicyPreview"
]
},
{
"Sid": "DevPullOnlyRegistryAccess",
"Effect": "Allow",
"Principal": {
"AWS": [
"arn:aws:iam::${alm_account_id}:user/jmorris",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where am I on here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean why are you not on here?
Because we forgot to add you when you joined the team and I copy/pasted the manually created policy for the other repositories into here.

If you’re not Ben, then you’re here so you have rights to pull images from the repository for local development.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or jolson

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both added along with the other new team members.

"arn:aws:iam::${alm_account_id}:user/jdenen",
"arn:aws:iam::${alm_account_id}:user/ksmith",
"arn:aws:iam::${alm_account_id}:user/mchirita",
"arn:aws:iam::${alm_account_id}:root",
"arn:aws:iam::${alm_account_id}:user/smillard",
"arn:aws:iam::${alm_account_id}:user/bschwanitz",
"arn:aws:iam::${alm_account_id}:user/brogers",
"arn:aws:iam::${alm_account_id}:user/cyeater",
"arn:aws:iam::${alm_account_id}:user/jlutz",
"arn:aws:iam::${alm_account_id}:user/oqi",
"arn:aws:iam::${alm_account_id}:user/abhagat",
"arn:aws:iam::${alm_account_id}:user/emoore",
"arn:aws:iam::${alm_account_id}:user/bbalser",
"arn:aws:iam::${alm_account_id}:user/afreeman",
"arn:aws:iam::${alm_account_id}:user/cmcclellan",
"arn:aws:iam::${alm_account_id}:user/rjones",
"arn:aws:iam::${alm_account_id}:user/aganesh",
"arn:aws:iam::${alm_account_id}:user/bcromer",
"arn:aws:iam::${alm_account_id}:user/rboyapati",
"arn:aws:iam::${alm_account_id}:user/amarkley",
"arn:aws:iam::${alm_account_id}:user/bbrewer",
"arn:aws:iam::${alm_account_id}:user/jolson",
"arn:aws:iam::${alm_account_id}:user/plinville"
]
},
"Action": [
"ecr:GetDownloadUrlForLayer",
"ecr:BatchGetImage",
"ecr:BatchCheckLayerAvailability",
"ecr:DescribeImages",
"ecr:DescribeRepositories"
]
}
]
}
34 changes: 34 additions & 0 deletions alm/ecr/repository_policy.sandbox.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"Version": "2008-10-17",
"Statement": [
{
"Sid": "AllTheThings",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::${alm_account_id}:role/admin_role"
},
"Action": [
"ecr:GetDownloadUrlForLayer",
"ecr:BatchGetImage",
"ecr:BatchCheckLayerAvailability",
"ecr:PutImage",
"ecr:InitiateLayerUpload",
"ecr:UploadLayerPart",
"ecr:CompleteLayerUpload",
"ecr:DescribeRepositories",
"ecr:GetRepositoryPolicy",
"ecr:ListImages",
"ecr:DescribeImages",
"ecr:DeleteRepository",
"ecr:BatchDeleteImage",
"ecr:SetRepositoryPolicy",
"ecr:DeleteRepositoryPolicy",
"ecr:GetLifecyclePolicy",
"ecr:PutLifecyclePolicy",
"ecr:DeleteLifecyclePolicy",
"ecr:GetLifecyclePolicyPreview",
"ecr:StartLifecyclePolicyPreview"
]
}
]
}