diff --git a/.github/workflows/terratest.yml b/.github/workflows/terratest.yml index 471405d..31e854d 100644 --- a/.github/workflows/terratest.yml +++ b/.github/workflows/terratest.yml @@ -7,7 +7,7 @@ on: branches: [ master ] env: - TERRAFORM_VERSION: 0.13.0 + TERRAFORM_VERSION: 0.14.4 IMAGE_NAME: azure-containerregistry-module ARM_SUBSCRIPTION_ID: ${{ secrets.ARM_SUBSCRIPTION_ID }} ARM_CLIENT_ID: ${{ secrets.ARM_CLIENT_ID }} @@ -24,11 +24,11 @@ jobs: with: ruby-version: 2.7 - name: build - if: github.event == 'push' run: | docker build --build-arg BUILD_TERRAFORM_VERSION=${TERRAFORM_VERSION} -t ${IMAGE_NAME} . docker run ${IMAGE_NAME} rake build - name: full + if: github.event == 'push' run: | docker build --build-arg BUILD_TERRAFORM_VERSION=${TERRAFORM_VERSION} --build-arg BUILD_ARM_SUBSCRIPTION_ID=$ARM_SUBSCRIPTION_ID --build-arg BUILD_ARM_CLIENT_ID=$ARM_CLIENT_ID --build-arg BUILD_ARM_CLIENT_SECRET=$ARM_CLIENT_SECRET --build-arg BUILD_ARM_TENANT_ID=$ARM_TENANT_ID -t ${IMAGE_NAME} . docker run ${IMAGE_NAME} rake full diff --git a/.gitignore b/.gitignore index 98c2a94..2965a85 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,6 @@ # Module directory .terraform/ +# Locks +*.lock.hcl +*.lock.info \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index fb3e0ed..09fca23 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +# 1.0.1 (2021-18-03) + +### Features + +* Updates to the README (corrections) +* Add back the geo replications resource +* Fix tests with correct Output variable +* Add back custom_headers block + # 0.1.0 (2020-10-05) ### Features diff --git a/Dockerfile b/Dockerfile index 58b2aa9..c5448ab 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ # Pull the base image with given version. -ARG BUILD_TERRAFORM_VERSION="0.13.0" +ARG BUILD_TERRAFORM_VERSION="0.14.4" FROM mcr.microsoft.com/terraform-test:${BUILD_TERRAFORM_VERSION} ARG MODULE_NAME="terraform-azurerm-network" @@ -21,9 +21,9 @@ ENV ARM_TEST_LOCATION=${BUILD_ARM_TEST_LOCATION} ENV ARM_TEST_LOCATION_ALT=${BUILD_ARM_TEST_LOCATION_ALT} # Set work directory. -RUN mkdir /go -RUN mkdir /go/bin -RUN mkdir /go/src +# RUN mkdir /go # Now supplied in v0.14.4 onwards of mcr.microsoft.com/terraform-test +# RUN mkdir /go/bin +# RUN mkdir /go/src RUN mkdir /go/src/${MODULE_NAME} COPY . /go/src/${MODULE_NAME} WORKDIR /go/src/${MODULE_NAME} diff --git a/README.md b/README.md index b1306b5..2ff2a53 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# terraform-azurerm-network +# terraform-azurerm-container-registry ![terratest](https://github.com/DanielMabbett/terraform-azurerm-container-registry/workflows/terratest/badge.svg) @@ -21,20 +21,13 @@ variable "location" { default = "north europe" } -resource "azurerm_resource_group" "test" { - name = "acct-${random_id.rg_name.hex}" - location = var.location -} - module "container_environment" { source = "../.." - depends_on = [azurerm_resource_group.test] - - name = "acctestcr" - resource_group_name = "rg-container-registry-test" - location = "north europe" - sku = "premium" + name = "acctacr${random_id.rg_name.hex}" + resource_group_name = "rg-acct-acr-${random_id.rg_name.hex}" + location = "North Europe" + sku = "Premium" enable_admin = false webhooks = [ @@ -49,8 +42,18 @@ module "container_environment" { } }, ] + + tags = { + Purpose = "Testing" + Environment = "Test" + } } +output "container_registry_id" { + value = module.container_environment.container_registry_id +} + + ``` ## Test @@ -125,6 +128,10 @@ This runs the full tests: docker run --rm azure-network /bin/bash -c "bundle install && rake full" ``` +## Contributing + +We welcome contributors! + ## Authors Originally created by [Daniel Mabbett](http://github.com/danielmabbett) diff --git a/main.tf b/main.tf index eb997a8..182168b 100644 --- a/main.tf +++ b/main.tf @@ -1,23 +1,30 @@ resource "azurerm_resource_group" "group" { name = var.resource_group_name location = var.location + tags = var.tags } -locals { - standard_tags = { - Component = "user-service" - Environment = "production" - } +resource "azurerm_container_registry" "registry" { + count = var.georeplication_locations == [] ? 1 : 0 + + name = var.name + resource_group_name = azurerm_resource_group.group.name + location = azurerm_resource_group.group.location + sku = var.sku + admin_enabled = var.enable_admin + tags = var.tags } -resource "azurerm_container_registry" "registry" { - name = var.name - resource_group_name = azurerm_resource_group.group.name - location = azurerm_resource_group.group.location - sku = var.sku - admin_enabled = var.enable_admin - // georeplication_locations = "${var.georeplications}" +resource "azurerm_container_registry" "registry_georeplicated" { + count = var.georeplication_locations != [] ? 1 : 0 + name = var.name + resource_group_name = azurerm_resource_group.group.name + location = azurerm_resource_group.group.location + sku = var.sku + admin_enabled = var.enable_admin + georeplication_locations = var.georeplication_locations + tags = var.tags } resource "azurerm_container_registry_webhook" "webhooks" { @@ -27,14 +34,12 @@ resource "azurerm_container_registry_webhook" "webhooks" { name = each.value.name resource_group_name = azurerm_resource_group.group.name - registry_name = azurerm_container_registry.registry.name + registry_name = var.georeplication_locations == [] ? azurerm_container_registry.registry[0].name : azurerm_container_registry.registry_georeplicated[0].name location = azurerm_resource_group.group.location - service_uri = each.value.service_uri # "https://mywebhookreceiver.example/mytag" - status = each.value.status # "enabled" - scope = each.value.scope # "mytag:*" - actions = each.value.actions # ["push"] - # custom_headers = { - # "Content-Type" = "application/json" - # } + service_uri = each.value.service_uri + status = each.value.status + scope = each.value.scope + actions = each.value.actions + custom_headers = each.value.custom_headers } \ No newline at end of file diff --git a/outputs.tf b/outputs.tf new file mode 100644 index 0000000..47fa277 --- /dev/null +++ b/outputs.tf @@ -0,0 +1,16 @@ +output "container_registry_id" { + description = "The ID for the Azure Container Registry" + value = var.georeplication_locations == [] ? azurerm_container_registry.registry[0].id : azurerm_container_registry.registry_georeplicated[0].id + # value = azurerm_container_registry.registry.id +} + +# output "container_registry_location" { +# description = "The location for the Azure Container Registry" +# value = azurerm_container_registry.registry.location +# } +# +# output "container_registry_name" { +# description = "The name for the Azure Container Registry" +# value = azurerm_container_registry.registry.name +# } +# \ No newline at end of file diff --git a/test/fixture/main.tf b/test/fixture/main.tf index 7032dce..4cf1b73 100644 --- a/test/fixture/main.tf +++ b/test/fixture/main.tf @@ -10,20 +10,13 @@ variable "location" { default = "north europe" } -resource "azurerm_resource_group" "test" { - name = "acct-${random_id.rg_name.hex}" - location = var.location -} - module "container_environment" { source = "../.." - depends_on = [azurerm_resource_group.test] - - name = "acctestcr" - resource_group_name = "rg-container-registry-test" - location = "north europe" - sku = "premium" + name = "acctacr${random_id.rg_name.hex}" + resource_group_name = "rg-acct-acr-${random_id.rg_name.hex}" + location = "North Europe" + sku = "Premium" enable_admin = false webhooks = [ @@ -38,4 +31,13 @@ module "container_environment" { } }, ] + + tags = { + Purpose = "Testing" + Environment = "Test" + } +} + +output "container_registry_id" { + value = module.container_environment.container_registry_id } diff --git a/test/terrraform_container_registry_test.go b/test/terrraform_container_registry_test.go index 642b9ab..30e3f2b 100644 --- a/test/terrraform_container_registry_test.go +++ b/test/terrraform_container_registry_test.go @@ -4,7 +4,7 @@ import ( "testing" "github.com/gruntwork-io/terratest/modules/terraform" - "github.com/gruntwork-io/terratest/modules/test-structure" + test_structure "github.com/gruntwork-io/terratest/modules/test-structure" ) func TestTerraformNetwork(t *testing.T) { @@ -27,8 +27,8 @@ func TestTerraformNetwork(t *testing.T) { test_structure.RunTestStage(t, "validate", func() { terraformOptions := test_structure.LoadTerraformOptions(t, fixtureFolder) - vnetID := terraform.Output(t, terraformOptions, "vnet_id") - if len(vnetID) <= 0 { + registryID := terraform.Output(t, terraformOptions, "container_registry_id") + if len(registryID) <= 0 { t.Fatal("Wrong output") } }) diff --git a/variables.tf b/variables.tf index e04a831..a7a591e 100644 --- a/variables.tf +++ b/variables.tf @@ -23,8 +23,8 @@ variable "enable_admin" { description = "Enable admin for the Azure Container Registry" } -variable "georeplications" { - default = "" +variable "georeplication_locations" { + default = [] description = "Georeplication regions for the Azure Container Registry" } @@ -39,4 +39,6 @@ variable "webhooks" { custom_headers = map(string) })) default = [] -} \ No newline at end of file +} + +variable "tags" {}