generated from clowdhaus/terraform-aws-module-template
-
-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add support for repository creation template (#46)
* feat: Add support for repository creation template * chore: Fix example after another round of validation
- Loading branch information
1 parent
df965a8
commit 4e93036
Showing
24 changed files
with
1,119 additions
and
17 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
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
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# Terraform AWS ECR Examples | ||
# Terraform Amazon ECR Examples | ||
|
||
- [Complete](https://github.com/terraform-aws-modules/terraform-aws-ecr/tree/master/examples/complete) | ||
- [Repository Template](https://github.com/terraform-aws-modules/terraform-aws-ecr/tree/master/examples/repository-template) |
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
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 |
---|---|---|
|
@@ -4,7 +4,7 @@ terraform { | |
required_providers { | ||
aws = { | ||
source = "hashicorp/aws" | ||
version = ">= 5.37" | ||
version = ">= 5.61" | ||
} | ||
} | ||
} |
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,62 @@ | ||
# Amazon ECR Repository Template Example | ||
|
||
## Usage | ||
|
||
To run this example you need to execute: | ||
|
||
```bash | ||
$ terraform init | ||
$ terraform plan | ||
$ terraform apply | ||
``` | ||
|
||
You can validate this example by running the commands generated in the `example_docker_pull_commands` output value. | ||
|
||
Note that this example may create resources which will incur monetary charges on your AWS bill. Run `terraform destroy` when you no longer need these resources. | ||
|
||
If you validate the example by using the pull-through cache, you will need to manually clean up these repositories within ECR since they are not manage by Terraform. | ||
|
||
<!-- BEGIN_TF_DOCS --> | ||
## Requirements | ||
|
||
| Name | Version | | ||
|------|---------| | ||
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 | | ||
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.61 | | ||
|
||
## Providers | ||
|
||
| Name | Version | | ||
|------|---------| | ||
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.61 | | ||
|
||
## Modules | ||
|
||
| Name | Source | Version | | ||
|------|--------|---------| | ||
| <a name="module_disabled"></a> [disabled](#module\_disabled) | ../../modules/repository-template | n/a | | ||
| <a name="module_dockerhub_pull_through_cache_repository_template"></a> [dockerhub\_pull\_through\_cache\_repository\_template](#module\_dockerhub\_pull\_through\_cache\_repository\_template) | ../../modules/repository-template | n/a | | ||
| <a name="module_public_ecr_pull_through_cache_repository_template"></a> [public\_ecr\_pull\_through\_cache\_repository\_template](#module\_public\_ecr\_pull\_through\_cache\_repository\_template) | ../../modules/repository-template | n/a | | ||
| <a name="module_secrets_manager_dockerhub_credentials"></a> [secrets\_manager\_dockerhub\_credentials](#module\_secrets\_manager\_dockerhub\_credentials) | terraform-aws-modules/secrets-manager/aws | ~> 1.0 | | ||
|
||
## Resources | ||
|
||
| Name | Type | | ||
|------|------| | ||
| [aws_caller_identity.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source | | ||
|
||
## Inputs | ||
|
||
No inputs. | ||
|
||
## Outputs | ||
|
||
| Name | Description | | ||
|------|-------------| | ||
| <a name="output_example_docker_pull_commands"></a> [example\_docker\_pull\_commands](#output\_example\_docker\_pull\_commands) | Example docker pull commands to test and validate the example | | ||
| <a name="output_iam_role_arn"></a> [iam\_role\_arn](#output\_iam\_role\_arn) | IAM role ARN | | ||
| <a name="output_iam_role_name"></a> [iam\_role\_name](#output\_iam\_role\_name) | IAM role name | | ||
| <a name="output_iam_role_unique_id"></a> [iam\_role\_unique\_id](#output\_iam\_role\_unique\_id) | Stable and unique string identifying the IAM role | | ||
<!-- END_TF_DOCS --> | ||
|
||
Apache-2.0 Licensed. See [LICENSE](https://github.com/terraform-aws-modules/terraform-aws-ecr/blob/master/LICENSE). |
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,113 @@ | ||
provider "aws" { | ||
region = local.region | ||
} | ||
|
||
locals { | ||
region = "us-east-1" | ||
name = "ecr-ex-${basename(path.cwd)}" | ||
|
||
account_id = data.aws_caller_identity.current.account_id | ||
|
||
tags = { | ||
Name = local.name | ||
Example = local.name | ||
Repository = "https://github.com/terraform-aws-modules/terraform-aws-ecr" | ||
} | ||
} | ||
|
||
data "aws_caller_identity" "current" {} | ||
|
||
################################################################################ | ||
# ECR Repository Template | ||
################################################################################ | ||
|
||
module "public_ecr_pull_through_cache_repository_template" { | ||
source = "../../modules/repository-template" | ||
|
||
# Template | ||
description = "Pull through cache repository template for Public ECR artifacts" | ||
prefix = "ecr-public" | ||
resource_tags = local.tags | ||
lifecycle_policy = jsonencode({ | ||
rules = [ | ||
{ | ||
rulePriority = 1, | ||
description = "Keep last 30 images", | ||
selection = { | ||
tagStatus = "tagged", | ||
tagPrefixList = ["v"], | ||
countType = "imageCountMoreThan", | ||
countNumber = 30 | ||
}, | ||
action = { | ||
type = "expire" | ||
} | ||
} | ||
] | ||
}) | ||
|
||
# Pull through cache rule | ||
create_pull_through_cache_rule = true | ||
upstream_registry_url = "public.ecr.aws" | ||
|
||
tags = local.tags | ||
} | ||
|
||
module "dockerhub_pull_through_cache_repository_template" { | ||
source = "../../modules/repository-template" | ||
|
||
# Template | ||
description = "Pull through cache repository template for Dockerhub artifacts" | ||
prefix = "docker-hub" | ||
resource_tags = local.tags | ||
|
||
# Pull through cache rule | ||
create_pull_through_cache_rule = true | ||
upstream_registry_url = "registry-1.docker.io" | ||
credential_arn = module.secrets_manager_dockerhub_credentials.secret_arn | ||
|
||
tags = local.tags | ||
} | ||
|
||
module "disabled" { | ||
source = "../../modules/repository-template" | ||
|
||
create = false | ||
} | ||
|
||
################################################################################ | ||
# Supporting Resources | ||
################################################################################ | ||
|
||
module "secrets_manager_dockerhub_credentials" { | ||
source = "terraform-aws-modules/secrets-manager/aws" | ||
version = "~> 1.0" | ||
|
||
# Secret names must contain 1-512 Unicode characters and be prefixed with ecr-pullthroughcache/ | ||
name_prefix = "ecr-pullthroughcache/dockerhub-credentials" | ||
description = "Dockerhub credentials" | ||
|
||
# For example only | ||
recovery_window_in_days = 0 | ||
secret_string = jsonencode({ | ||
username = "example" | ||
accessToken = "YouShouldNotStoreThisInPlainText" | ||
}) | ||
|
||
# Policy | ||
create_policy = true | ||
block_public_policy = true | ||
policy_statements = { | ||
read = { | ||
sid = "AllowAccountRead" | ||
principals = [{ | ||
type = "AWS" | ||
identifiers = ["arn:aws:iam::${local.account_id}:root"] | ||
}] | ||
actions = ["secretsmanager:GetSecretValue"] | ||
resources = ["*"] | ||
} | ||
} | ||
|
||
tags = local.tags | ||
} |
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,28 @@ | ||
output "iam_role_name" { | ||
description = "IAM role name" | ||
value = module.dockerhub_pull_through_cache_repository_template.iam_role_name | ||
} | ||
|
||
output "iam_role_arn" { | ||
description = "IAM role ARN" | ||
value = module.dockerhub_pull_through_cache_repository_template.iam_role_arn | ||
} | ||
|
||
output "iam_role_unique_id" { | ||
description = "Stable and unique string identifying the IAM role" | ||
value = module.public_ecr_pull_through_cache_repository_template.iam_role_unique_id | ||
} | ||
|
||
output "example_docker_pull_commands" { | ||
description = "Example docker pull commands to test and validate the example" | ||
value = <<-EOT | ||
# Ensure your local CLI is authenticated with ECR | ||
aws ecr get-login-password --region ${local.region} | docker login --username AWS --password-stdin ${local.account_id}.dkr.ecr.${local.region}.amazonaws.com | ||
# Dockerhub pull through cache and repo creation | ||
docker pull ${local.account_id}.dkr.ecr.${local.region}.amazonaws.com/docker-hub/library/nginx:latest | ||
# Public ECR pull through cache and repo creation | ||
docker pull ${local.account_id}.dkr.ecr.${local.region}.amazonaws.com/ecr-public/docker/library/nginx:latest | ||
EOT | ||
} |
Empty file.
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,10 @@ | ||
terraform { | ||
required_version = ">= 1.0" | ||
|
||
required_providers { | ||
aws = { | ||
source = "hashicorp/aws" | ||
version = ">= 5.61" | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -84,7 +84,6 @@ data "aws_iam_policy_document" "repository" { | |
|
||
values = var.repository_lambda_read_access_arns | ||
} | ||
|
||
} | ||
} | ||
|
||
|
Oops, something went wrong.