From 56a3d8dc4ec7fd7cb3e401782a3d6cb2ebac3512 Mon Sep 17 00:00:00 2001 From: Julien Corioland Date: Fri, 15 Jan 2021 13:47:11 +0100 Subject: [PATCH] Update to terraform 0.14 (#14) * update module to terraform 0.14 * update CI to terraform 0.14 / golang 1.14 (using custom test Docker image) * update Azure pipeline --- .gitignore | 1 + Dockerfile | 9 +++---- azure-pipeline.yaml | 11 +++++---- provider.tf | 3 --- test/azure_devops_agent_aci_test.go | 2 ++ test/fixture/linux-agents-import-rg/main.tf | 7 +++--- .../linux-agents-import-rg/provider.tf | 9 +++++++ .../linux-agents-import-rg/variables.tf | 16 ++++++------- .../linux-agents-private-registry/provider.tf | 9 +++++++ .../variables.tf | 22 ++++++++--------- test/fixture/linux-agents-vnet/main.tf | 13 +++++----- test/fixture/linux-agents-vnet/provider.tf | 9 +++++++ test/fixture/linux-agents-vnet/variables.tf | 16 ++++++------- test/fixture/linux-agents/main.tf | 6 ++--- test/fixture/linux-agents/provider.tf | 9 +++++++ test/fixture/linux-agents/variables.tf | 16 ++++++------- test/fixture/linux-and-windows-agents/main.tf | 6 ++--- .../linux-and-windows-agents/provider.tf | 9 +++++++ .../linux-and-windows-agents/variables.tf | 22 ++++++++--------- variables.tf | 24 +++++++++---------- 20 files changed, 133 insertions(+), 86 deletions(-) delete mode 100644 provider.tf diff --git a/.gitignore b/.gitignore index 5a6b76e..b9b796d 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ **/.terraform/* terraform.tfstate.d/ logs/ +.terraform.lock.hcl # Variable files terraform.tfvars diff --git a/Dockerfile b/Dockerfile index 977c3e4..91c54da 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ # Pull the base image with given version. -ARG BUILD_TERRAFORM_VERSION="0.12.20" -FROM mcr.microsoft.com/terraform-test:${BUILD_TERRAFORM_VERSION} +ARG BUILD_TERRAFORM_VERSION="0.14.4" +FROM jcorioland/terraform-test:${BUILD_TERRAFORM_VERSION} ARG MODULE_NAME="terraform-azure-devops-eagent-aci" @@ -21,10 +21,7 @@ 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/src/${MODULE_NAME} +RUN mkdir -p /go/src/${MODULE_NAME} COPY . /go/src/${MODULE_NAME} WORKDIR /go/src/${MODULE_NAME} diff --git a/azure-pipeline.yaml b/azure-pipeline.yaml index 9433ce9..bedb7b2 100644 --- a/azure-pipeline.yaml +++ b/azure-pipeline.yaml @@ -1,15 +1,18 @@ # Azure Pipeline that runs module integration tests -trigger: none +trigger: +- master +pr: +- master variables: - group: AzureDevOpsACI.Secrets - name: dockerImage value: 'terraform-azure-devops-aci' - name: terraformVersion - value: 0.12.25 + value: 0.14.4 - name: vmImage - value: ubuntu-latest + value: ubuntu-18.04 - name: serviceConnection value: "terraform-azure-devops-aci" @@ -43,7 +46,7 @@ stages: repository: $(dockerImage) dockerfile: '$(System.DefaultWorkingDirectory)/Dockerfile' buildContext: $(System.DefaultWorkingDirectory) - arguments: --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) + arguments: --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) --build-arg BUILD_TERRAFORM_VERSION=$(terraformVersion) tags: | $(Build.BuildId) - script: | diff --git a/provider.tf b/provider.tf deleted file mode 100644 index 615cb43..0000000 --- a/provider.tf +++ /dev/null @@ -1,3 +0,0 @@ -provider "azurerm" { - features {} -} \ No newline at end of file diff --git a/test/azure_devops_agent_aci_test.go b/test/azure_devops_agent_aci_test.go index a204c14..223f0be 100644 --- a/test/azure_devops_agent_aci_test.go +++ b/test/azure_devops_agent_aci_test.go @@ -94,6 +94,8 @@ func TestDeployAzureDevOpsLinuxAgentsInVirtualNetwork(t *testing.T) { devopsPoolName := os.Getenv("TF_VAR_azure_devops_pool_name") testPoolName := fmt.Sprintf("%s-%s", devopsPoolName, randomSuffix) os.Setenv("TF_VAR_azure_devops_pool_name", testPoolName) + // reset env var after test + defer os.Setenv("TF_VAR_azure_devops_pool_name", devopsPoolName) devopsOrganizationName := os.Getenv("TF_VAR_azure_devops_org_name") devopsPersonalAccessToken := os.Getenv("TF_VAR_azure_devops_personal_access_token") diff --git a/test/fixture/linux-agents-import-rg/main.tf b/test/fixture/linux-agents-import-rg/main.tf index ac8caaf..3a41940 100644 --- a/test/fixture/linux-agents-import-rg/main.tf +++ b/test/fixture/linux-agents-import-rg/main.tf @@ -4,9 +4,9 @@ resource "azurerm_resource_group" "rg" { } module "aci-devops-agent" { - source = "../../../" - enable_vnet_integration = false - create_resource_group = false + source = "../../../" + enable_vnet_integration = false + create_resource_group = false linux_agents_configuration = { agent_name_prefix = "linuxagent-${var.random_suffix}" count = var.agents_count @@ -20,4 +20,5 @@ module "aci-devops-agent" { location = azurerm_resource_group.rg.location azure_devops_org_name = var.azure_devops_org_name azure_devops_personal_access_token = var.azure_devops_personal_access_token + depends_on = [azurerm_resource_group.rg] } \ No newline at end of file diff --git a/test/fixture/linux-agents-import-rg/provider.tf b/test/fixture/linux-agents-import-rg/provider.tf index 615cb43..49f3ab5 100644 --- a/test/fixture/linux-agents-import-rg/provider.tf +++ b/test/fixture/linux-agents-import-rg/provider.tf @@ -1,3 +1,12 @@ +terraform { + required_providers { + azurerm = { + source = "hashicorp/azurerm" + version = ">= 2.0" + } + } +} + provider "azurerm" { features {} } \ No newline at end of file diff --git a/test/fixture/linux-agents-import-rg/variables.tf b/test/fixture/linux-agents-import-rg/variables.tf index a4ab247..462e34d 100644 --- a/test/fixture/linux-agents-import-rg/variables.tf +++ b/test/fixture/linux-agents-import-rg/variables.tf @@ -1,43 +1,43 @@ -variable azure_devops_org_name { +variable "azure_devops_org_name" { type = string description = "The name of the Azure DevOps organization in which the containerized agents will be deployed (e.g. https://dev.azure.com/YOUR_ORGANIZATION_NAME, must exist)" } -variable azure_devops_pool_name { +variable "azure_devops_pool_name" { type = string description = "The name of the Azure DevOps agent pool in which the containerized agents will be deployed (must exist)" } -variable azure_devops_personal_access_token { +variable "azure_devops_personal_access_token" { type = string description = "The personal access token to use to connect to Azure DevOps (see https://docs.microsoft.com/en-us/azure/devops/pipelines/agents/v2-windows?view=azure-devops#permissions)" } -variable location { +variable "location" { type = string description = "The Azure location to use" default = "westeurope" } -variable agent_docker_image { +variable "agent_docker_image" { type = string description = "The Docker image to use for the Linux agent" default = "jcorioland/aci-devops-agent" } -variable agent_docker_tag { +variable "agent_docker_tag" { type = string description = "The Docker tag to use for the Linux agent" default = "0.2-linux" } -variable agents_count { +variable "agents_count" { type = number description = "The number of agents to create" default = 2 } -variable random_suffix { +variable "random_suffix" { type = number description = "A random suffix for resources generated during the test" } \ No newline at end of file diff --git a/test/fixture/linux-agents-private-registry/provider.tf b/test/fixture/linux-agents-private-registry/provider.tf index 615cb43..49f3ab5 100644 --- a/test/fixture/linux-agents-private-registry/provider.tf +++ b/test/fixture/linux-agents-private-registry/provider.tf @@ -1,3 +1,12 @@ +terraform { + required_providers { + azurerm = { + source = "hashicorp/azurerm" + version = ">= 2.0" + } + } +} + provider "azurerm" { features {} } \ No newline at end of file diff --git a/test/fixture/linux-agents-private-registry/variables.tf b/test/fixture/linux-agents-private-registry/variables.tf index 72a582d..0bad889 100644 --- a/test/fixture/linux-agents-private-registry/variables.tf +++ b/test/fixture/linux-agents-private-registry/variables.tf @@ -1,58 +1,58 @@ -variable azure_devops_org_name { +variable "azure_devops_org_name" { type = string description = "The name of the Azure DevOps organization in which the containerized agents will be deployed (e.g. https://dev.azure.com/YOUR_ORGANIZATION_NAME, must exist)" } -variable azure_devops_pool_name { +variable "azure_devops_pool_name" { type = string description = "The name of the Azure DevOps agent pool in which the containerized agents will be deployed (must exist)" } -variable azure_devops_personal_access_token { +variable "azure_devops_personal_access_token" { type = string description = "The personal access token to use to connect to Azure DevOps (see https://docs.microsoft.com/en-us/azure/devops/pipelines/agents/v2-windows?view=azure-devops#permissions)" } -variable location { +variable "location" { type = string description = "The Azure location to use" default = "westeurope" } -variable agent_docker_image { +variable "agent_docker_image" { type = string description = "The Docker image to use for the Linux agent" default = "jcorioland/aci-devops-agent" } -variable agent_docker_tag { +variable "agent_docker_tag" { type = string description = "The Docker tag to use for the Linux agent" default = "0.2-linux" } -variable agents_count { +variable "agents_count" { type = number description = "The number of agents to create" default = 2 } -variable random_suffix { +variable "random_suffix" { type = number description = "A random suffix for resources generated during the test" } -variable docker_registry_url { +variable "docker_registry_url" { type = string description = "The server URL of the Docker private registry" } -variable docker_registry_username { +variable "docker_registry_username" { type = string description = "The username of the Docker private registry" } -variable docker_registry_password { +variable "docker_registry_password" { type = string description = "The password of the Docker private registry" } \ No newline at end of file diff --git a/test/fixture/linux-agents-vnet/main.tf b/test/fixture/linux-agents-vnet/main.tf index 6753608..d7c527d 100644 --- a/test/fixture/linux-agents-vnet/main.tf +++ b/test/fixture/linux-agents-vnet/main.tf @@ -27,12 +27,12 @@ resource "azurerm_subnet" "aci-subnet" { } module "aci-devops-agent" { - source = "../../../" - enable_vnet_integration = true - create_resource_group = true - vnet_resource_group_name = azurerm_resource_group.vnet-rg.name - vnet_name = azurerm_virtual_network.vnet.name - subnet_name = azurerm_subnet.aci-subnet.name + source = "../../../" + enable_vnet_integration = true + create_resource_group = true + vnet_resource_group_name = azurerm_resource_group.vnet-rg.name + vnet_name = azurerm_virtual_network.vnet.name + subnet_name = azurerm_subnet.aci-subnet.name linux_agents_configuration = { agent_name_prefix = "linuxagent-${var.random_suffix}" count = var.agents_count @@ -46,4 +46,5 @@ module "aci-devops-agent" { location = var.location azure_devops_org_name = var.azure_devops_org_name azure_devops_personal_access_token = var.azure_devops_personal_access_token + depends_on = [azurerm_subnet.aci-subnet] } \ No newline at end of file diff --git a/test/fixture/linux-agents-vnet/provider.tf b/test/fixture/linux-agents-vnet/provider.tf index 615cb43..49f3ab5 100644 --- a/test/fixture/linux-agents-vnet/provider.tf +++ b/test/fixture/linux-agents-vnet/provider.tf @@ -1,3 +1,12 @@ +terraform { + required_providers { + azurerm = { + source = "hashicorp/azurerm" + version = ">= 2.0" + } + } +} + provider "azurerm" { features {} } \ No newline at end of file diff --git a/test/fixture/linux-agents-vnet/variables.tf b/test/fixture/linux-agents-vnet/variables.tf index 87bfa7f..1d0152e 100644 --- a/test/fixture/linux-agents-vnet/variables.tf +++ b/test/fixture/linux-agents-vnet/variables.tf @@ -1,43 +1,43 @@ -variable azure_devops_org_name { +variable "azure_devops_org_name" { type = string description = "The name of the Azure DevOps organization in which the containerized agents will be deployed (e.g. https://dev.azure.com/YOUR_ORGANIZATION_NAME, must exist)" } -variable azure_devops_pool_name { +variable "azure_devops_pool_name" { type = string description = "The name of the Azure DevOps agent pool in which the containerized agents will be deployed (must exist)" } -variable azure_devops_personal_access_token { +variable "azure_devops_personal_access_token" { type = string description = "The personal access token to use to connect to Azure DevOps (see https://docs.microsoft.com/en-us/azure/devops/pipelines/agents/v2-windows?view=azure-devops#permissions)" } -variable location { +variable "location" { type = string description = "The Azure location to use" default = "westus" } -variable agent_docker_image { +variable "agent_docker_image" { type = string description = "The Docker image to use for the Linux agent" default = "jcorioland/aci-devops-agent" } -variable agent_docker_tag { +variable "agent_docker_tag" { type = string description = "The Docker tag to use for the Linux agent" default = "0.2-linux" } -variable agents_count { +variable "agents_count" { type = number description = "The number of agents to create" default = 2 } -variable random_suffix { +variable "random_suffix" { type = number description = "A random suffix for resources generated during the test" } \ No newline at end of file diff --git a/test/fixture/linux-agents/main.tf b/test/fixture/linux-agents/main.tf index 865c5e5..fb2c701 100644 --- a/test/fixture/linux-agents/main.tf +++ b/test/fixture/linux-agents/main.tf @@ -1,7 +1,7 @@ module "aci-devops-agent" { - source = "../../../" - enable_vnet_integration = false - create_resource_group = true + source = "../../../" + enable_vnet_integration = false + create_resource_group = true linux_agents_configuration = { agent_name_prefix = "linuxagent-${var.random_suffix}" count = var.agents_count diff --git a/test/fixture/linux-agents/provider.tf b/test/fixture/linux-agents/provider.tf index 615cb43..49f3ab5 100644 --- a/test/fixture/linux-agents/provider.tf +++ b/test/fixture/linux-agents/provider.tf @@ -1,3 +1,12 @@ +terraform { + required_providers { + azurerm = { + source = "hashicorp/azurerm" + version = ">= 2.0" + } + } +} + provider "azurerm" { features {} } \ No newline at end of file diff --git a/test/fixture/linux-agents/variables.tf b/test/fixture/linux-agents/variables.tf index a4ab247..462e34d 100644 --- a/test/fixture/linux-agents/variables.tf +++ b/test/fixture/linux-agents/variables.tf @@ -1,43 +1,43 @@ -variable azure_devops_org_name { +variable "azure_devops_org_name" { type = string description = "The name of the Azure DevOps organization in which the containerized agents will be deployed (e.g. https://dev.azure.com/YOUR_ORGANIZATION_NAME, must exist)" } -variable azure_devops_pool_name { +variable "azure_devops_pool_name" { type = string description = "The name of the Azure DevOps agent pool in which the containerized agents will be deployed (must exist)" } -variable azure_devops_personal_access_token { +variable "azure_devops_personal_access_token" { type = string description = "The personal access token to use to connect to Azure DevOps (see https://docs.microsoft.com/en-us/azure/devops/pipelines/agents/v2-windows?view=azure-devops#permissions)" } -variable location { +variable "location" { type = string description = "The Azure location to use" default = "westeurope" } -variable agent_docker_image { +variable "agent_docker_image" { type = string description = "The Docker image to use for the Linux agent" default = "jcorioland/aci-devops-agent" } -variable agent_docker_tag { +variable "agent_docker_tag" { type = string description = "The Docker tag to use for the Linux agent" default = "0.2-linux" } -variable agents_count { +variable "agents_count" { type = number description = "The number of agents to create" default = 2 } -variable random_suffix { +variable "random_suffix" { type = number description = "A random suffix for resources generated during the test" } \ No newline at end of file diff --git a/test/fixture/linux-and-windows-agents/main.tf b/test/fixture/linux-and-windows-agents/main.tf index d39fa52..ae2b270 100644 --- a/test/fixture/linux-and-windows-agents/main.tf +++ b/test/fixture/linux-and-windows-agents/main.tf @@ -1,7 +1,7 @@ module "aci-devops-agent" { - source = "../../../" - enable_vnet_integration = false - create_resource_group = true + source = "../../../" + enable_vnet_integration = false + create_resource_group = true linux_agents_configuration = { agent_name_prefix = "linux-agent-${var.random_suffix}" count = 2, diff --git a/test/fixture/linux-and-windows-agents/provider.tf b/test/fixture/linux-and-windows-agents/provider.tf index 615cb43..49f3ab5 100644 --- a/test/fixture/linux-and-windows-agents/provider.tf +++ b/test/fixture/linux-and-windows-agents/provider.tf @@ -1,3 +1,12 @@ +terraform { + required_providers { + azurerm = { + source = "hashicorp/azurerm" + version = ">= 2.0" + } + } +} + provider "azurerm" { features {} } \ No newline at end of file diff --git a/test/fixture/linux-and-windows-agents/variables.tf b/test/fixture/linux-and-windows-agents/variables.tf index 0551c60..4f7157a 100644 --- a/test/fixture/linux-and-windows-agents/variables.tf +++ b/test/fixture/linux-and-windows-agents/variables.tf @@ -1,62 +1,62 @@ -variable azure_devops_org_name { +variable "azure_devops_org_name" { type = string description = "The name of the Azure DevOps organization in which the containerized agents will be deployed (e.g. https://dev.azure.com/YOUR_ORGANIZATION_NAME, must exist)" } -variable azure_devops_personal_access_token { +variable "azure_devops_personal_access_token" { type = string description = "The personal access token to use to connect to Azure DevOps (see https://docs.microsoft.com/en-us/azure/devops/pipelines/agents/v2-windows?view=azure-devops#permissions)" } -variable linux_azure_devops_pool_name { +variable "linux_azure_devops_pool_name" { type = string description = "The name of the Azure DevOps agent pool in which the linux containerized agents will be deployed (must exist)" default = "linux-e2e-agents" } -variable windows_azure_devops_pool_name { +variable "windows_azure_devops_pool_name" { type = string description = "The name of the Azure DevOps agent pool in which the windows containerized agents will be deployed (must exist)" default = "windows-e2e-agents" } -variable location { +variable "location" { type = string description = "The Azure location to use" default = "westeurope" } -variable linux_agent_docker_image { +variable "linux_agent_docker_image" { type = string description = "The Docker image to use for the Linux agent" default = "jcorioland/aci-devops-agent" } -variable linux_agent_docker_tag { +variable "linux_agent_docker_tag" { type = string description = "The Docker tag to use for the Linux agent" default = "0.2-linux" } -variable windows_agent_docker_image { +variable "windows_agent_docker_image" { type = string description = "The Docker image to use for the Windows agent" default = "jcorioland/aci-devops-agent" } -variable windows_agent_docker_tag { +variable "windows_agent_docker_tag" { type = string description = "The Docker tag to use for the Windows agent" default = "0.2-win" } -variable agents_count { +variable "agents_count" { type = number description = "The number of agents to create" default = 2 } -variable random_suffix { +variable "random_suffix" { type = number description = "A random suffix for resources generated during the test" } \ No newline at end of file diff --git a/variables.tf b/variables.tf index f22c145..ce6aba6 100644 --- a/variables.tf +++ b/variables.tf @@ -1,54 +1,54 @@ -variable resource_group_name { +variable "resource_group_name" { type = string description = "The name of the resource group in which the containerized agents will be deployed" } -variable location { +variable "location" { type = string description = "The Azure location to use for deployment" } -variable create_resource_group { +variable "create_resource_group" { type = bool default = true description = "(Optional) A flag that indicates if the resource group in which the agents will be deployed must be created (true) or imported (false)." } -variable enable_vnet_integration { +variable "enable_vnet_integration" { type = bool default = false description = "(Optional) A flag that indicates if the containerized agents must be deployed into an existing virtual network" } -variable vnet_resource_group_name { +variable "vnet_resource_group_name" { type = string default = "" description = "(Optional) The name of the resource group that contains the virtual network in which the containerized agents will be deployed" } -variable vnet_name { +variable "vnet_name" { type = string default = "" description = "(Optional) The name of the virtual network in which the containerized agents will be deployed" } -variable subnet_name { +variable "subnet_name" { type = string default = "" description = "(Optional) The name of the subnet of the vnet in which the containerized agents will be deployed" } -variable azure_devops_org_name { +variable "azure_devops_org_name" { type = string description = "The name of the Azure DevOps organization in which the containerized agents will be deployed (e.g. https://dev.azure.com/YOUR_ORGANIZATION_NAME, must exist)" } -variable azure_devops_personal_access_token { +variable "azure_devops_personal_access_token" { type = string description = "The personal access token to use to connect to Azure DevOps (see https://docs.microsoft.com/en-us/azure/devops/pipelines/agents/v2-windows?view=azure-devops#permissions)" } -variable linux_agents_configuration { +variable "linux_agents_configuration" { type = object({ count = string, docker_image = string, @@ -70,7 +70,7 @@ variable linux_agents_configuration { } } -variable windows_agents_configuration { +variable "windows_agents_configuration" { type = object({ count = string, docker_image = string, @@ -92,7 +92,7 @@ variable windows_agents_configuration { } } -variable image_registry_credential { +variable "image_registry_credential" { type = object({ username = string, password = string,