Terraform module to create Azure Virtual Network
- Module tested for Terraform 1.0.1.
- Azure provider version 2.90.0
main
branch: Provider versions not pinned to keep up with Terraform releasestags
releases: Tags are pinned with versions (usein your releases)
terrafrom init
terraform plan -var='teamid=tryme' -var='prjid=project1'
terraform apply -var='teamid=tryme' -var='prjid=project1'
terraform destroy -var='teamid=tryme' -var='prjid=project1'
Note: With this option please take care of remote state storage
Recommended method (stores remote state in storage using prjid
and teamid
to create directory structure):
- Create python 3.8+ virtual environment
python3 -m venv <venv name>
- Install package:
pip install tfremote --upgrade
- Set below environment variables:
export TF_AZURE_STORAGE_ACCOUNT=tfstatexxxxx # Output of remote_state.sh
export TF_AZURE_CONTAINER=tfstate # Output of remote_state.sh
export ARM_ACCESS_KEY=xxxxxxxxxx # Output of remote_state.sh
-
Updated
examples
directory to required values -
Run and verify the output before deploying:
tf -c=azure plan -var='teamid=foo' -var='prjid=bar'
- Run below to deploy:
tf -c=azure apply -var='teamid=foo' -var='prjid=bar'
- Run below to destroy:
tf -c=azure destroy -var='teamid=foo' -var='prjid=bar'
NOTE:
- Read more on tfremote
Terraform supports a number of different methods for authenticating to Azure:
- Authenticating to Azure using the Azure CLI
- Authenticating to Azure using Managed Service Identity
- Authenticating to Azure using a Service Principal and a Client Certificate
- Authenticating to Azure using a Service Principal and a Client Secret
module "vnet" {
source = "../../"
resource_group_name = "demo-rg"
location = "eastus2"
cidr_block = ["10.7.7.0/24"]
# ---------------------------------------------
# Note: Do not change teamid and prjid once set.
teamid = var.teamid
prjid = var.prjid
}
Please refer to examples directory link for references.
Name | Version |
---|---|
terraform | >= 1.0.1 |
azurerm | >= 2.90 |
Name | Version |
---|---|
azurerm | >= 2.90 |
No modules.
Name | Type |
---|---|
azurerm_virtual_network.network | resource |
Name | Description | Type | Default | Required |
---|---|---|---|---|
cidr_block | The address space that is used the virtual network. You can supply more than one address space | list(string) |
[ |
no |
deploy_virtual_network | feature flag to deploy this resource or not | bool |
true |
no |
location | The location/region where the virtual network is created. Changing this forces a new resource to be created. | string |
"westus2" |
no |
prjid | (Required) Name of the project/stack e.g: mystack, nifieks, demoaci. Should not be changed after running 'tf apply' | string |
n/a | yes |
resource_group_name | The name of the resource group in which to create the virtual network. | string |
n/a | yes |
teamid | (Required) Name of the team/group e.g. devops, dataengineering. Should not be changed after running 'tf apply' | string |
n/a | yes |
virtual_network_name | Virtual network name | string |
null |
no |