Skip to content

Commit

Permalink
Terraform 0.13 support (#30)
Browse files Browse the repository at this point in the history
* update

* update

* update

* update

* update

* update

* update
  • Loading branch information
yupwei68 authored Sep 7, 2020
1 parent b093046 commit 65c31ec
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion 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.12.20"
ARG BUILD_TERRAFORM_VERSION="0.13.0"
FROM mcr.microsoft.com/terraform-test:${BUILD_TERRAFORM_VERSION}

ARG MODULE_NAME="terraform-azurerm-vnet"
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
36 changes: 34 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand All @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
7 changes: 7 additions & 0 deletions test/fixture/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -42,6 +47,8 @@ module "vnet" {
environment = "dev"
costcenter = "it"
}

depends_on = [azurerm_resource_group.test]
}


Expand Down
11 changes: 11 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -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" {
Expand All @@ -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)
Expand Down

0 comments on commit 65c31ec

Please sign in to comment.