https://github.com/sterliakov/terraform-aws-ecr-image
Simple curl-based terraform module to push a dummy ECR image to streamline ECR+Lambda terraform deployments
https://github.com/sterliakov/terraform-aws-ecr-image
aws aws-ecr aws-lambda terraform terraform-module
Last synced: 3 months ago
JSON representation
Simple curl-based terraform module to push a dummy ECR image to streamline ECR+Lambda terraform deployments
- Host: GitHub
- URL: https://github.com/sterliakov/terraform-aws-ecr-image
- Owner: sterliakov
- License: apache-2.0
- Created: 2024-11-03T17:04:57.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2025-03-10T21:03:05.000Z (4 months ago)
- Last Synced: 2025-03-10T21:33:42.292Z (4 months ago)
- Topics: aws, aws-ecr, aws-lambda, terraform, terraform-module
- Language: Shell
- Homepage:
- Size: 52.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Temporary ECR image


---
## PURPOSE
When AWS Lambda is deployed with container `image` source, that image must already
exist. This makes deployment of such a function with terraform complicated: first
`terraform apply` should create a ECR repository, then some other CI pipeline
should build and push an image, and only then a lambda can be created.This module streamlines this process by pushing some tiny image as a placeholder.
Idea and the initial code was borrowed from
[this StackOverflow answer](https://stackoverflow.com/a/78501527/14401160),
but the implementation was significantly rewritten.## USAGE
Push a dummy Alpine image to a newly created ECR repository:
```terraform
provider "aws" {
region = "us-east-2"
}
provider "aws" {
region = "us-east-1"
alias = "aws.virginia"
}resource "aws_ecr_repository" "example" {
name = "example"
}module "ecr_repo_image" {
source = "sterliakov/ecr-image/aws"
version = "0.2.0"
providers = {
aws.main = aws
aws.virginia = aws.virginia
}push_ecr_is_public = false
push_repo_fqdn = replace(aws_ecr_repository.example.repository_url, "//.*$/", "") # remove everything after first slash
push_repo_name = aws_ecr_repository.example.name
push_image_tag = "deployed"
}
```## NOTES
* This module needs two provider aliases: `aws.main` and `aws.virginia`. They
may refer to the same provider. `aws.virginia` must be in `us-east-1` region.
`aws.main` should be the provider for region where your repository is located.
* This module only works under Linux.
* Destroying this module does not remove the pushed image from the repository. Consider
setting `force_delete = True` on the `aws_ecr_repository` resource if you
want to remove the repository with terraform later.
* This module needs `curl` and `jq` on `PATH`. If `jq` are missing, it will fetch
and install `jq 1.7.1` locally for the appropriate architecture.## EXAMPLES
- [Lambda](examples/lambda) - Deploy a dummy image for Lambda (5 MB alpine by default)
## Inputs
| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| [pull\_ecr\_is\_public](#input\_pull\_ecr\_is\_public) | If the ECR repo we're pulling from is public (vs. private) | `bool` | `true` | no |
| [pull\_image\_arch](#input\_pull\_image\_arch) | The arch of the image we're pulling, e.g. amd64 | `string` | `"amd64"` | no |
| [pull\_image\_tag](#input\_pull\_image\_tag) | The tag of the image we're pulling, e.g. latest | `string` | `"3.20.3"` | no |
| [pull\_repo\_fqdn](#input\_pull\_repo\_fqdn) | The FQDN of the ECR repo we're pulling from, e.g. public.ecr.aws | `string` | `"public.ecr.aws"` | no |
| [pull\_repo\_name](#input\_pull\_repo\_name) | The name of the ECR repo we're pulling from, e.g. my-repo | `string` | `"docker/library/alpine"` | no |
| [push\_ecr\_is\_public](#input\_push\_ecr\_is\_public) | If the ECR repo we're pushing to is public (vs. private) | `bool` | `false` | no |
| [push\_image\_tag](#input\_push\_image\_tag) | The tag of the image we're pushing, e.g. latest | `string` | n/a | yes |
| [push\_repo\_fqdn](#input\_push\_repo\_fqdn) | The FQDN of the ECR repo we're pushing to, e.g. 012345678910.dkr.ecr..amazonaws.com | `string` | n/a | yes |
| [push\_repo\_name](#input\_push\_repo\_name) | The name of the ECR repo we're pushing to, e.g. my-repo | `string` | n/a | yes |## Modules
No modules.
## Outputs
No outputs.
## Providers
| Name | Version |
|------|---------|
| [aws.main](#provider\_aws.main) | >= 5.40.0 |
| [aws.virginia](#provider\_aws.virginia) | >= 5.40.0 |
| [terraform](#provider\_terraform) | n/a |## Requirements
| Name | Version |
|------|---------|
| [terraform](#requirement\_terraform) | >= 1.7.0 |
| [aws](#requirement\_aws) | >= 5.40.0 |## Resources
| Name | Type |
|------|------|
| [terraform_data.ecr_repo_image](https://registry.terraform.io/providers/hashicorp/terraform/latest/docs/resources/data) | resource |
| [aws_ecr_authorization_token.token](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ecr_authorization_token) | data source |
| [aws_ecrpublic_authorization_token.token](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ecrpublic_authorization_token) | data source |## CONTRIBUTING
Contributions are very welcomed!
Start by reviewing [contribution guide](CONTRIBUTING.md) and our [code of conduct](CODE_OF_CONDUCT.md). After that, start coding and ship your changes by creating a new PR.
## LICENSE
Apache 2 Licensed. See [LICENSE](LICENSE) for full details.