diff --git a/.travis.yml b/.travis.yml index 1189dae..996ad9b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,7 +13,7 @@ services: - docker env: - - TERRAFORM_VERSION=0.12.20 IMAGE_NAME=azure-vnet-module + - TERRAFORM_VERSION=0.13.0 IMAGE_NAME=azure-vnet-module jobs: include: diff --git a/Dockerfile b/Dockerfile index abfa645..c521071 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ # Pull the base image with given version. -ARG BUILD_TERRAFORM_VERSION="0.12.20" +ARG BUILD_TERRAFORM_VERSION="0.13.0" FROM mcr.microsoft.com/terraform-test:${BUILD_TERRAFORM_VERSION} ARG MODULE_NAME="terraform-azurerm-vnet" diff --git a/Gemfile b/Gemfile index a8ddcb6..a5a775a 100644 --- a/Gemfile +++ b/Gemfile @@ -2,6 +2,6 @@ source 'https://rubygems.org/' group :test do git 'https://github.com/Azure/terramodtest.git' do - gem 'terramodtest', tag: '0.5.0' + gem 'terramodtest', tag: '0.7.0' end end diff --git a/README.md b/README.md index e8e5bff..5928216 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ This Terraform module deploys a Virtual Network in Azure with a subnet or a set The module does not create nor expose a security group. This would need to be defined separately as additional security rules on subnets in the deployed network. -## Usage +## Usage in Terraform 0.13 ```hcl provider "azurerm" { @@ -27,12 +27,44 @@ module "vnet" { subnet_prefixes = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"] subnet_names = ["subnet1", "subnet2", "subnet3"] + subnet_service_endpoints = { + subnet2 = ["Microsoft.Storage", "Microsoft.Sql"], + subnet3 = ["Microsoft.AzureActiveDirectory"] + } + tags = { environment = "dev" costcenter = "it" } + + depends_on = [azurerm_resource_group.example] +} +``` + +## Usage in Terraform 0.12 + +```hcl +provider "azurerm" { + features {} } +resource "azurerm_resource_group" "example" { + name = "my-resources" + location = "West Europe" +} + +module "vnet" { + source = "Azure/vnet/azurerm" + resource_group_name = azurerm_resource_group.example.name + address_space = ["10.0.0.0/16"] + subnet_prefixes = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"] + subnet_names = ["subnet1", "subnet2", "subnet3"] + + tags = { + environment = "dev" + costcenter = "it" + } +} ``` ## Example adding a network security rule for SSH @@ -108,7 +140,7 @@ module "vnet" { subnet_names = ["subnet1", "subnet2", "subnet3"] route_table_ids = { - subnet1 = azurerm_route_table.example.id + subnet1 = azurerm_route_table.example.id subnet2 = azurerm_route_table.example.id subnet3 = azurerm_roiute_table.example.id } diff --git a/main.tf b/main.tf index ce0daf1..f1fdec6 100644 --- a/main.tf +++ b/main.tf @@ -18,6 +18,7 @@ resource "azurerm_subnet" "subnet" { resource_group_name = data.azurerm_resource_group.vnet.name virtual_network_name = azurerm_virtual_network.vnet.name address_prefixes = [var.subnet_prefixes[count.index]] + service_endpoints = lookup(var.subnet_service_endpoints, var.subnet_names[count.index], null) } data "azurerm_subnet" "import" { diff --git a/test/fixture/main.tf b/test/fixture/main.tf index 2259735..a8d61f3 100644 --- a/test/fixture/main.tf +++ b/test/fixture/main.tf @@ -34,6 +34,11 @@ module "vnet" { subnet1 = azurerm_network_security_group.nsg1.id } + subnet_service_endpoints = { + subnet2 = ["Microsoft.Storage", "Microsoft.Sql"], + subnet3 = ["Microsoft.AzureActiveDirectory"] + } + route_tables_ids = { subnet1 = azurerm_route_table.rt1.id } @@ -42,6 +47,8 @@ module "vnet" { environment = "dev" costcenter = "it" } + + depends_on = [azurerm_resource_group.test] } diff --git a/variables.tf b/variables.tf index 37ff884..156a176 100644 --- a/variables.tf +++ b/variables.tf @@ -1,10 +1,12 @@ variable "vnet_name" { description = "Name of the vnet to create" + type = string default = "acctvnet" } variable "resource_group_name" { description = "Name of the resource group to be imported." + type = string } variable "address_space" { @@ -16,19 +18,28 @@ variable "address_space" { # If no values specified, this defaults to Azure DNS variable "dns_servers" { description = "The DNS servers to be used with vNet." + type = list(string) default = [] } variable "subnet_prefixes" { description = "The address prefix to use for the subnet." + type = list(string) default = ["10.0.1.0/24"] } variable "subnet_names" { description = "A list of public subnets inside the vNet." + type = list(string) default = ["subnet1", "subnet2", "subnet3"] } +variable "subnet_service_endpoints" { + description = "A map of subnet name to service endpoints to add to the subnet." + type = map(any) + default = {} +} + variable "nsg_ids" { description = "A map of subnet name to Network Security Group IDs" type = map(string)