forked from hashicorp/terraform
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
provider/azurerm: Add example of a VNET w/ Two Subnets (hashicorp#14115)
* merge master * added new constructs/naming for deploy scripts, etc. * suppress az login output * removed .tfvars and provider.tf; updated prev merge * reverted .travis.yml back to Hashicorp's * Reverting back to the Hashicorp travis file
- Loading branch information
1 parent
03c7cfb
commit 8e7f3cc
Showing
12 changed files
with
124 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,4 +8,4 @@ output "vm_fqdn" { | |
|
||
output "ssh_command" { | ||
value = "ssh ${var.admin_username}@${azurerm_public_ip.pip.fqdn}" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
terraform.tfstate* | ||
provider.tf | ||
out.tfplan |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Virtual Network with Two Subnets | ||
|
||
This template allows you to create a Virtual Network with two subnets. | ||
|
||
## main.tf | ||
The `main.tf` file contains the actual resources that will be deployed. It also contains the Azure Resource Group definition and any defined variables. | ||
|
||
## outputs.tf | ||
This data is outputted when `terraform apply` is called, and can be queried using the `terraform output` command. | ||
|
||
## provider.tf | ||
Azure requires that an application is added to Azure Active Directory to generate the `client_id`, `client_secret`, and `tenant_id` needed by Terraform (`subscription_id` can be recovered from your Azure account details). Please go [here](https://www.terraform.io/docs/providers/azurerm/) for full instructions on how to create this to populate your `provider.tf` file. | ||
|
||
## terraform.tfvars | ||
If a `terraform.tfvars` file is present in the current directory, Terraform automatically loads it to populate variables. We don't recommend saving usernames and password to version control, but you can create a local secret variables file and use `-var-file` to load it. | ||
|
||
## variables.tf | ||
The `variables.tf` file contains all of the input parameters that the user can specify when deploying this Terraform template. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#!/bin/bash | ||
|
||
set -o errexit -o nounset | ||
|
||
# generate a unique string for CI deployment | ||
# KEY=$(cat /dev/urandom | tr -cd 'a-z' | head -c 12) | ||
# PASSWORD=$KEY$(cat /dev/urandom | tr -cd 'A-Z' | head -c 2)$(cat /dev/urandom | tr -cd '0-9' | head -c 2) | ||
|
||
docker run --rm -it \ | ||
-e ARM_CLIENT_ID \ | ||
-e ARM_CLIENT_SECRET \ | ||
-e ARM_SUBSCRIPTION_ID \ | ||
-e ARM_TENANT_ID \ | ||
-v $(pwd):/data \ | ||
--workdir=/data \ | ||
--entrypoint "/bin/sh" \ | ||
hashicorp/terraform:light \ | ||
-c "/bin/terraform get; \ | ||
/bin/terraform validate; \ | ||
/bin/terraform plan -out=out.tfplan -var resource_group=$KEY; \ | ||
/bin/terraform apply out.tfplan; \ | ||
/bin/terraform show;" | ||
|
||
# check that resources exist via azure cli | ||
docker run --rm -it \ | ||
azuresdk/azure-cli-python \ | ||
sh -c "az login --service-principal -u $ARM_CLIENT_ID -p $ARM_CLIENT_SECRET --tenant $ARM_TENANT_ID > /dev/null; \ | ||
az network vnet subnet show -n subnet1 -g $KEY --vnet-name '$KEY'vnet; \ | ||
az network vnet subnet show -n subnet2 -g $KEY --vnet-name '$KEY'vnet;" | ||
|
||
# cleanup deployed azure resources via terraform | ||
docker run --rm -it \ | ||
-e ARM_CLIENT_ID \ | ||
-e ARM_CLIENT_SECRET \ | ||
-e ARM_SUBSCRIPTION_ID \ | ||
-e ARM_TENANT_ID \ | ||
-v $(pwd):/data \ | ||
--workdir=/data \ | ||
--entrypoint "/bin/sh" \ | ||
hashicorp/terraform:light \ | ||
-c "/bin/terraform destroy -force -var resource_group=$KEY;" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/bin/bash | ||
|
||
set -o errexit -o nounset | ||
|
||
if docker -v; then | ||
|
||
# generate a unique string for CI deployment | ||
export KEY=$(cat /dev/urandom | env LC_CTYPE=C tr -cd 'a-z' | head -c 12) | ||
export PASSWORD=$KEY$(cat /dev/urandom | env LC_CTYPE=C tr -cd 'A-Z' | head -c 2)$(cat /dev/urandom | env LC_CTYPE=C tr -cd '0-9' | head -c 2) | ||
|
||
/bin/sh ./deploy.ci.sh | ||
|
||
else | ||
echo "Docker is used to run terraform commands, please install before run: https://docs.docker.com/docker-for-mac/install/" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# provider "azurerm" { | ||
# subscription_id = "REPLACE-WITH-YOUR-SUBSCRIPTION-ID" | ||
# client_id = "REPLACE-WITH-YOUR-CLIENT-ID" | ||
# client_secret = "REPLACE-WITH-YOUR-CLIENT-SECRET" | ||
# tenant_id = "REPLACE-WITH-YOUR-TENANT-ID" | ||
# } | ||
|
||
resource "azurerm_resource_group" "rg" { | ||
name = "${var.resource_group}" | ||
location = "${var.location}" | ||
} | ||
|
||
resource "azurerm_virtual_network" "vnet" { | ||
name = "${var.resource_group}vnet" | ||
location = "${var.location}" | ||
address_space = ["10.0.0.0/16"] | ||
resource_group_name = "${azurerm_resource_group.rg.name}" | ||
} | ||
|
||
resource "azurerm_subnet" "subnet1" { | ||
name = "subnet1" | ||
virtual_network_name = "${azurerm_virtual_network.vnet.name}" | ||
resource_group_name = "${azurerm_resource_group.rg.name}" | ||
address_prefix = "10.0.0.0/24" | ||
} | ||
|
||
resource "azurerm_subnet" "subnet2" { | ||
name = "subnet2" | ||
virtual_network_name = "${azurerm_virtual_network.vnet.name}" | ||
resource_group_name = "${azurerm_resource_group.rg.name}" | ||
address_prefix = "10.0.1.0/24" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
variable "resource_group" { | ||
description = "The name of the resource group in which to create the virtual network." | ||
} | ||
|
||
variable "location" { | ||
description = "The location/region where the virtual network is created. Changing this forces a new resource to be created." | ||
default = "southcentralus" | ||
} |