Creates an ECR repository and pushes a container image using local bash scripts.
The following programs must be available on the PATH
to be able to run the
local scripts:
bash
docker
aws
find
sort
md5sum
Example:
module "ecr_image" {
source = "github.com/andreswebs/terraform-aws-ecr-image"
ecr_namespace = "yourorg"
image_suffix = "yourimage"
image_source_path = "./your-image-code"
}
The push.bash script uses docker
by default to build and push the container image.
It is possible to use a different command, by setting the DOCKER_CMD
environment variable before running the terraform
commands.
Examples:
export DOCKER_CMD='podman'
terraform apply
export DOCKER_CMD=`lima nerdctl`
terraform apply
Name | Description | Type | Default | Required |
---|---|---|---|---|
ecr_namespace | (Optional) A namespace prefixed to the ECR repository name, e.g. 'my-namespace' in my-namespace/my-repo | string |
null |
no |
hash_script | (Optional) Path to a custom script to generate a hash of source contents | string |
"" |
no |
image_default_tag | Default tag to use for the container image | string |
"latest" |
no |
image_force_delete | (Optional) Force delete image? | bool |
false |
no |
image_source_path | Path to the image source code | string |
n/a | yes |
image_suffix | Suffix used to name the container image, e.g. 'my-repo' in my-namespace/my-repo | string |
n/a | yes |
image_tag_mutability | Image tag immutability. Must be one of MUTABLE or IMMUTABLE | string |
"MUTABLE" |
no |
lifecycle_policy | Repository lifecycle policy. A default will be used if not provided | string |
null |
no |
push_script | (Optional) Path to a custom script to build and push the container image | string |
"" |
no |
scan_on_push | Scan image on push? | bool |
true |
no |
No modules.
Name | Description |
---|---|
ecr_repository | The AWS ECR Repository resource |
image_hash | Hash of the image source code, applied as a tag to the container image |
image_uri | Image URI |
repository_url | ECR repository URL |
Name | Version |
---|---|
aws | ~> 4.50 |
external | ~> 2.3 |
null | ~> 3.2 |
Name | Version |
---|---|
aws | ~> 4.50 |
external | ~> 2.3 |
null | ~> 3.2 |
Name | Type |
---|---|
aws_ecr_lifecycle_policy.this | resource |
aws_ecr_repository.this | resource |
null_resource.push | resource |
external_external.hash | data source |
Andre Silva - @andreswebs
This project is licensed under the Unlicense.
The code for pushing images to ECR (under scripts/
) was based on: