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
- Loading branch information
1 parent
df965a8
commit 108c20c
Showing
24 changed files
with
1,095 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,66 @@ | ||
# 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 following commands: | ||
|
||
```bash | ||
# Ensure your local CLI is authenticated with ECR | ||
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin <account-id>.dkr.ecr.us-east-1.amazonaws.com | ||
|
||
# Dockerhub pull through cache and repo creation | ||
docker pull <account-id>.dkr.ecr.us-east-1.amazonaws.com/dockerhub/library/nginx:latest | ||
|
||
# Public ECR pull through cache and repo creation | ||
docker pull <account-id>.dkr.ecr.us-east-1.amazonaws.com/public-ecr/docker/library/nginx:latest | ||
``` | ||
|
||
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. | ||
|
||
<!-- 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 | ||
|
||
No outputs. | ||
<!-- 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 = "public-ecr" | ||
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 = "dockerhub" | ||
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 | ||
} |
Empty file.
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.