Skip to content

Commit

Permalink
Release v1.0.1 (#2)
Browse files Browse the repository at this point in the history
* Updates to the README (corrections)
* Add back the geo replications resource
* Fix tests with correct Output variable
* Add back custom_headers block
  • Loading branch information
DanielMabbett authored Mar 18, 2021
1 parent 5586f1d commit 09b388a
Show file tree
Hide file tree
Showing 10 changed files with 99 additions and 55 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/terratest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@
# Module directory
.terraform/

# Locks
*.lock.hcl
*.lock.info
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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}
Expand Down
31 changes: 19 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# terraform-azurerm-network
# terraform-azurerm-container-registry

![terratest](https://github.com/DanielMabbett/terraform-azurerm-container-registry/workflows/terratest/badge.svg)

Expand All @@ -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 = [
Expand All @@ -49,8 +42,18 @@ module "container_environment" {
}
},
]
tags = {
Purpose = "Testing"
Environment = "Test"
}
}
output "container_registry_id" {
value = module.container_environment.container_registry_id
}
```

## Test
Expand Down Expand Up @@ -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)
Expand Down
45 changes: 25 additions & 20 deletions main.tf
Original file line number Diff line number Diff line change
@@ -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" {
Expand All @@ -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
}
16 changes: 16 additions & 0 deletions outputs.tf
Original file line number Diff line number Diff line change
@@ -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
# }
#
24 changes: 13 additions & 11 deletions test/fixture/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand All @@ -38,4 +31,13 @@ module "container_environment" {
}
},
]

tags = {
Purpose = "Testing"
Environment = "Test"
}
}

output "container_registry_id" {
value = module.container_environment.container_registry_id
}
6 changes: 3 additions & 3 deletions test/terrraform_container_registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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")
}
})
Expand Down
8 changes: 5 additions & 3 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

Expand All @@ -39,4 +39,6 @@ variable "webhooks" {
custom_headers = map(string)
}))
default = []
}
}

variable "tags" {}

0 comments on commit 09b388a

Please sign in to comment.