This Terraform module deploys a Virtual Network in Azure with a subnet or a set of subnets passed in as input parameters.
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.
module "vnet" {
source = "Azure/vnet/azurerm"
resource_group_name = "myapp"
location = "westus"
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"
}
}
variable "resource_group_name" { }
module "vnet" {
source = "Azure/vnet/azurerm"
resource_group_name = "${var.resource_group_name}"
location = "westus"
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"
}
}
resource "azurerm_subnet" "subnet" {
name = "subnet1"
address_prefix = "10.0.1.0/24"
resource_group_name = "${var.resource_group_name}"
virtual_network_name = "acctvnet"
network_security_group_id = "${azurerm_network_security_group.ssh.id}"
}
resource "azurerm_network_security_group" "ssh" {
depends_on = ["module.vnet"]
name = "ssh"
location = "westus"
resource_group_name = "${var.resource_group_name}"
security_rule {
name = "test123"
priority = 100
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "22"
source_address_prefix = "*"
destination_address_prefix = "*"
}
}
We provide 2 ways to build, run, and test module on local dev box:
We provide simple script to quickly set up module development environment:
$ curl -sSL https://raw.githubusercontent.com/Azure/terramodtest/master/tool/env_setup.sh | sudo bash
Then simply run it in local shell:
$ bundle install
$ rake build
$ rake e2e
We provide a Dockerfile to build a new image based FROM
the microsoft/terraform-test
Docker hub image which adds additional tools / packages specific for this module (see Custom Image section). Alternatively use only the microsoft/terraform-test
Docker hub image by using these instructions.
This builds the custom image:
$ docker build --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 azure-network .
This runs the build and unit tests:
$ docker run --rm azure-network /bin/bash -c "bundle install && rake build"
This runs the end to end tests:
$ docker run -v ~/.ssh:/root/.ssh/ --rm azure-network /bin/bash -c "bundle install && rake e2e"
Originally created by Eugene Chuvyrov