Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
badra001 committed Aug 19, 2022
1 parent 8f21a17 commit 56854b5
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 76 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Versions

* v1.0.0 -- {{ yyyy-mm-dd }}
## v 1.x

* 1.0.0 -- 2022-08-18
- initial creation

4 changes: 2 additions & 2 deletions availabilty_zones.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ data "aws_availability_zones" "zones" {
}

data "aws_availability_zone" "zone" {
count = length(data.aws_availability_zones.zones.names)
count = toset(data.aws_availability_zones.zones.names)
state = "available"
name = data.aws_availability_zones.zones.names[count.index]
name = each.key
}

output "availability_zone_names" {
Expand Down
2 changes: 2 additions & 0 deletions copy_image.sh → bin/copy_image.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash

VERSION="1.0.0"

###############################################################################
# This script uses skopeo to copy a docker image from one repository to
# another. The primary intent is to copy the image from a public repository
Expand Down
16 changes: 7 additions & 9 deletions copy_images.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ data "aws_ecr_authorization_token" "token" {}
# dice-centurion

locals {
repo_parent_name = format("%v", var.app_name)
ecr_region = var.ecr_region == null ? local.region : var.ecr_region
repo_parent_name = format("%v", var.application_name)
region = var.region == null ? local.region : var.region

account_ecr_registry = format("%v.dkr.ecr.%v.amazonaws.com", local.account_id, local.ecr_region)
account_ecr = format("%v/%v", local.account_ecr_registry, local.repo_parent_name)

images = { for i in var.image_config : format("%v#%v", i.name, i.tag) =>
merge(i, tomap({
key = format("%v#%v", i.name, i.tag),
source_full_path = format("%v/%v:%v", i.source_registry, i.source_image, element(compact(concat([lookup(i,"source_tag",null)],[i.tag])),0)),
source_full_path = format("%v/%v:%v", i.source_registry, i.source_image, element(compact(concat([lookup(i, "source_tag", null)], [i.tag])), 0)),
dest_registry = local.account_ecr_registry,
dest_full_path = i.repo_path != null ? format("%v/%v/%v/%v:%v", local.account_ecr_registry, local.repo_parent_name, i.repo_path, i.name, i.tag) : format("%v/%v/%v:%v", local.account_ecr_registry, local.repo_parent_name, i.name, i.tag),
dest_repository = i.repo_path != null ? format("%v/%v/%v", local.repo_parent_name, i.repo_path, i.name) : format("%v/%v", local.repo_parent_name, i.name),
Expand All @@ -33,13 +33,11 @@ resource "null_resource" "copy_images" {
for_each = { for image in local.images : image.key => image if image.enabled }

provisioner "local-exec" {
command = "${path.module}/copy_image.sh"
command = "${path.module}/bin/copy_image.sh"
environment = {
AWS_PROFILE = var.profile
AWS_REGION = local.ecr_region
# SOURCE_IMAGE = format("%v:%v", each.value.image, each.value.tag)
SOURCE_IMAGE = each.value.source_full_path
# DESTINATION_IMAGE = format("%v/%v:%v", local.account_ecr, each.value.name, each.value.tag)
AWS_PROFILE = var.profile
AWS_REGION = local.ecr_region
SOURCE_IMAGE = each.value.source_full_path
DESTINATION_IMAGE = each.value.dest_full_path
SOURCE_USERNAME = var.source_username == null ? "" : var.source_username
SOURCE_PASSWORD = var.source_password == null ? "" : var.source_password
Expand Down
4 changes: 2 additions & 2 deletions create-apps-ecr.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
locals {
application_list = var.application_list
ecr_repo_list = { for app in local.application_list : app => format("%v/%v", var.app_name, app) }
ecr_repo_list = { for app in local.application_list : app => format("%v/%v", var.application_name, app) }
}

resource "aws_ecr_repository" "apps_repos" {
Expand All @@ -21,7 +21,7 @@ resource "aws_ecr_repository" "apps_repos" {
local.base_tags,
var.application_tags,
tomap({
"Name" = format("ecr_%v/%v", var.app_name, each.key)
"Name" = format("ecr_%v/%v", var.application_name, each.key)
"Environment" = "application"
}),
)
Expand Down
2 changes: 2 additions & 0 deletions data.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ data "aws_arn" "current" {
}

data "aws_region" "current" {}

data "aws_iam_account_alias" "current" {}
17 changes: 0 additions & 17 deletions images.json

This file was deleted.

11 changes: 8 additions & 3 deletions locals.tf.initial → locals.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
locals {
account_id = var.account_id != "" ? var.account_id : data.aws_caller_identity.current.account_id
account_environment = data.aws_arn.current.partition == "aws-us-gov" ? "gov" : "ew"

base_tags = {
"boc:tf_module_version" = local._module_version
"boc:tf_module_name" = local._module_name
"boc:created_by" = "terraform"
}

account_id = var.account_id != "" ? var.account_id : data.aws_caller_identity.current.account_id
_account_alias = var.account_alias == null || var.account_alias == "" ? data.aws_iam_account_alias.current.account_alias : var.account_alias
account_alias = replace(local._account_alias, "do2", "do1")
account_environment = data.aws_arn.current.partition == "aws-us-gov" ? "gov" : "ew"

region = data.aws_region.current.name
}
28 changes: 0 additions & 28 deletions prefixes.tf

This file was deleted.

2 changes: 1 addition & 1 deletion settings.auto.tfvars.sample
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
app_name = "adsd-cumulus"
application_name = "adsd-cumulus"
ecr_region = "us-gov-east-1"
#destination_password = ""
#destination_username = ""
Expand Down
5 changes: 0 additions & 5 deletions variables.common.availability_zones.tf

This file was deleted.

14 changes: 7 additions & 7 deletions variables.ecr.tf → variables.tf
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
variable "app_name" {
variable "application_name" {
description = "Appliication name, usually {org}-{project}, which is likely a prefix to the EKS cluster name"
type = string
type = string
}

variable "application_list" {
description = "List of application repositories to create for /{app_name}/{image_name} for those not in image_config"
description = "List of application repositories to create for /{application_name}/{image_name} for those not in image_config"
type = list(string)
default = []
}

variable "ecr_region" {
variable "region" {
description = "Region in which to create the ECR repositories (default of current region)"
type = string
default = null
type = string
default = null
}

variable "image_config" {
description = "List of image configuration objects to copy from NRC to DST"
description = "List of image configuration objects to copy from SOURCE to DESTINATION"
type = list(object({
name = string,
tag = string,
Expand Down
3 changes: 2 additions & 1 deletion version.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
locals {
_module_version = "0.0.0"
_module_name = "aws-ecr-copy-images"
_module_version = "1.0.0"
}

0 comments on commit 56854b5

Please sign in to comment.