Skip to content

Instantly share code, notes, and snippets.

@briceburg
Last active March 21, 2023 18:45
Show Gist options
  • Save briceburg/f9e256f98e6cafed4b34e004f4c095da to your computer and use it in GitHub Desktop.
Save briceburg/f9e256f98e6cafed4b34e004f4c095da to your computer and use it in GitHub Desktop.
Terraform ECR authentication
resource "aws_ecr_repository" "repo" {
name = "foo"
}
data "aws_ecr_authorization_token" "repo" {}
#
# providers.tf
#
terraform {
required_providers {
docker = {
source = "kreuzwerker/docker"
version = "3.0.1"
}
}
}
# https://registry.terraform.io/providers/kreuzwerker/docker/latest/docs
provider "docker" {
registry_auth {
address = split("/", aws_ecr_repository.repo.repository_url)[0]
username = data.aws_ecr_authorization_token.repo.user_name
password = data.aws_ecr_authorization_token.repo.password
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment