Skip to content

Set up an ECR Repository

This document describes how to create a new Amazon ECR (Elastic Container Registry) repository in the AWS Shared account using the BYM-IKT/SharedKontoInfrastruktur repository.

An ECR repository is used to store container images so that containerized applications can be deployed to AWS.

Steps

Step 1: Clone the repository

git clone git@github.com:BYM-IKT/SharedKontoInfrastruktur.git
cd SharedKontoInfrastruktur

Step 2: Verify application folder

Check if the following folder exists:

./Shared/<application-name>/

  • If the folder exists, continue to step 3.
  • If the folder does not exist, follow the steps below.

Step 2a: Copy the Example Template

Note

This step must be performed in an environment that supports symbolic links.

cd Shared
cp -a eksempel/ <application-name>

Step 2b: Rename Terraform Template Files

Navigate to:

./Shared/<application-name>/eu-west-1/ecr/
Rename the files:

From To
main.tfignore main.tf
state.tfignore state.tf

Step 2c: Replace Template Name

Replace all occurrences of the word eksempel with <application-name> in the following files:

- ./Shared/<application-name>/eu-west-1/environment.tf

- ./Shared/<application-name>/eu-west-1/ecr/main.tf

- ./Shared/<application-name>/eu-west-1/ecr/state.tf

Update the value of the team variable in environment.tf to match the correct team name for the environment.

Expected Folder Structure

Shared/
└── <application-name>/         Renamed folder
    └── eu-west-1/
        ├── ecr/
           ├── main.tf        Renamed and edited
           ├── state.tf       Renamed and edited
           └── ...
        └── environment.tf     Edited

Step 3: Define the ECR Repository Name

Open:

./Shared/<application-name>/eu-west-1/ecr/main.tf
In the locals block, add the needed ECR repository name to the list and replace the Eksempel:
./Shared/kattehotell/eu-west-1/ecr/main.tf
locals {
  kattehotell_repos = toset([
    ...
    "api",
  ])
  account_access = [
    local.accounts["BYM-DP-Kattehotell-Test"].id, 
    local.accounts["BYM-DP-Kattehotell-Prod"].id 
  ]
}

module "kattehotell_ecr" {
  for_each         = local.kattehotell_repos                                    
  source = "git@github.com:BYM-IKT/terraform-aws-ecr.git?ref=v3"
  application_name = "kattehotell"                                    
  service          = each.value
  account_access   = local.account_access 
}

output "kattehotell_ecr_repo" {
  value = module.kattehotell_ecr
}

Step 4: Create a Pull Request

  1. Create a new branch

  2. Commit your changes

  3. Push the branch

  4. Create a Pull Request to master

Step 5: Merge to Master

After the Pull Request is merged into master, the ECR repository is automatically created.

Result

The ECR repository is available at:

<Shared-account-id>.dkr.ecr.eu-west-1.amazonaws.com/<repo-name>