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

Strip '_' character from 'title' to avoid illegal character in IAM role policy. #1

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
31 changes: 28 additions & 3 deletions ecr.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,32 @@
resource "aws_ecr_repository" "image" {
name = "${var.name}"
name = var.name

tags {
Project = "${local.project}"
tags = {
Project = local.project
}
}

# Only keep last 30 images
resource "aws_ecr_lifecycle_policy" "cleanup" {
repository = aws_ecr_repository.image.name

policy = <<END_OF_POLICY
{
"rules": [
{
"rulePriority": 1,
"description": "Keep last 30 images",
"selection": {
"tagStatus": "any",
"countType": "imageCountMoreThan",
"countNumber": 30
},
"action": {
"type": "expire"
}
}
]
}
END_OF_POLICY

}
9 changes: 5 additions & 4 deletions outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@ output "ecr_host" {
}

output "ecr_repo" {
value = "${aws_ecr_repository.image.name}"
value = aws_ecr_repository.image.name
}

output "ecr_repository_url" {
value = "${aws_ecr_repository.image.repository_url}"
value = aws_ecr_repository.image.repository_url
}

output "ecr_repo_rw_policy" {
value = "${data.aws_iam_policy_document.allow_manage_docker_repo.json}"
value = data.aws_iam_policy_document.allow_manage_docker_repo.json
}

output "ecr_repo_ro_policy" {
value = "${data.aws_iam_policy_document.allow_fetch_images_from_repo.json}"
value = data.aws_iam_policy_document.allow_fetch_images_from_repo.json
}

15 changes: 9 additions & 6 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ variable "project" {
description = "Project tag."
}

data "aws_region" "current" {}
data "aws_region" "current" {
}

locals {
name = "${var.name}"
region = "${data.aws_region.current.name}"
project = "${var.project}"
title = "${title(replace(replace(local.name, "-", "" ), " ", ""))}"
}
name = var.name
region = data.aws_region.current.name
project = var.project
title = title(
replace(replace(replace(local.name, "-", ""), " ", ""), "_", ""),
)
}
4 changes: 4 additions & 0 deletions versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

terraform {
required_version = ">= 0.12"
}