Skip to content

Commit ab33960

Browse files
committed
Changes for Terraform 2.0 and some clean-up
1 parent 08ef180 commit ab33960

8 files changed

+127
-106
lines changed

articles/terraform/terraform-cloud-shell.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
---
22
title: Tutorial - Configure Azure Cloud Shell for Terraform
3-
description: Use Terraform with Azure Cloud Shell to simplify authentication and template configuration.
3+
description: In this tutorial, you use Terraform with Azure Cloud Shell to simplify authentication and template configuration.
4+
keywords: azure devops terraform cloud shell
45
ms.topic: tutorial
5-
ms.date: 10/26/2019
6+
ms.date: 03/09/2020
67
---
78

89
# Tutorial: Configure Azure Cloud Shell for Terraform
@@ -26,6 +27,10 @@ Azure Terraform modules require credentials to access and modify Azure resources
2627
```hcl
2728
# Configure the Microsoft Azure Provider
2829
provider "azurerm" {
30+
# The "feature" block is required for AzureRM provider 2.x.
31+
# If you are using version 1.x, the "features" block is not allowed.
32+
version = "~>2.0"
33+
features {}
2934
}
3035
```
3136

@@ -41,4 +46,4 @@ The Azure CLI is available in Cloud Shell and is a great tool for testing config
4146
## Next steps
4247

4348
> [!div class="nextstepaction"]
44-
> [Create a small VM cluster using the Module Registry](terraform-create-vm-cluster-module.md)
49+
> [Create a small VM cluster using the Module Registry](terraform-create-vm-cluster-module.md)

articles/terraform/terraform-create-complete-vm.md

Lines changed: 61 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,21 @@
11
---
2-
title: Use Terraform to create a complete Linux VM in Azure
3-
description: Learn how to use Terraform to create and manage a complete Linux virtual machine environment in Azure
4-
services: virtual-machines-linux
5-
documentationcenter: virtual-machines
6-
author: tomarchermsft
7-
manager: gwallace
8-
editor: na
9-
tags: azure-resource-manager
10-
ms.assetid:
11-
ms.service: virtual-machines-linux
12-
ms.topic: article
13-
ms.tgt_pltfrm: vm-linux
14-
ms.workload: infrastructure
15-
ms.date: 09/20/2019
16-
ms.author: tarcher
2+
title: Quickstart - Use Terraform to create a complete Linux VM in Azure
3+
description: In this quickstart, you use Terraform to create and manage a complete Linux virtual machine environment in Azure
4+
keywords: azure devops terraform linux vm virtual machine
5+
ms.topic: quickstart
6+
ms.date: 03/09/2020
177
---
188

19-
# Create a complete Linux virtual machine infrastructure in Azure with Terraform
9+
# Quickstart: Create a complete Linux virtual machine infrastructure in Azure with Terraform
2010

21-
Terraform allows you to define and create complete infrastructure deployments in Azure. You build Terraform templates in a human-readable format that create and configure Azure resources in a consistent, reproducible manner. This article shows you how to create a complete Linux environment and supporting resources with Terraform. You can also learn how to [Install and configure Terraform](terraform-install-configure.md).
11+
Terraform allows you to define and create complete infrastructure deployments in Azure. You build Terraform templates in a human-readable format that create and configure Azure resources in a consistent, reproducible manner. This article shows you how to create a complete Linux environment and supporting resources with Terraform. You can also learn how to [install and configure Terraform](terraform-install-configure.md).
2212

2313
> [!NOTE]
2414
> For Terraform specific support, please reach out to Terraform directly using one of their community channels:
2515
>
26-
> The [Terraform section](https://discuss.hashicorp.com/c/terraform-core) of the community portal contains questions, use cases, and useful patterns.
16+
> * The [Terraform section](https://discuss.hashicorp.com/c/terraform-core) of the community portal contains questions, use cases, and useful patterns.
2717
>
28-
> For provider-related questions please visit the [Terraform Providers](https://discuss.hashicorp.com/c/terraform-providers) section of the community portal.
18+
> * For provider-related questions please visit the [Terraform Providers](https://discuss.hashicorp.com/c/terraform-providers) section of the community portal.
2919
3020

3121
## Create Azure connection and resource group
@@ -39,6 +29,11 @@ The `provider` section tells Terraform to use an Azure provider. To get values f
3929
4030
```hcl
4131
provider "azurerm" {
32+
# The "feature" block is required for AzureRM provider 2.x.
33+
# If you are using version 1.x, the "features" block is not allowed.
34+
version = "~>2.0"
35+
features {}
36+
4237
subscription_id = "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
4338
client_id = "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
4439
client_secret = "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
@@ -142,7 +137,6 @@ resource "azurerm_network_interface" "myterraformnic" {
142137
name = "myNIC"
143138
location = "eastus"
144139
resource_group_name = azurerm_resource_group.myterraformgroup.name
145-
network_security_group_id = azurerm_network_security_group.myterraformnsg.id
146140
147141
ip_configuration {
148142
name = "myNicConfiguration"
@@ -155,6 +149,12 @@ resource "azurerm_network_interface" "myterraformnic" {
155149
environment = "Terraform Demo"
156150
}
157151
}
152+
153+
# Connect the security group to the network interface
154+
resource "azurerm_network_interface_security_group_association" "example" {
155+
network_interface_id = azurerm_network_interface.myterraformnic.id
156+
network_security_group_id = azurerm_network_security_group.myterraformnsg.id
157+
}
158158
```
159159

160160

@@ -196,18 +196,17 @@ The final step is to create a VM and use all the resources created. The followin
196196
SSH key data is provided in the *ssh_keys* section. Provide a valid public SSH key in the *key_data* field.
197197

198198
```hcl
199-
resource "azurerm_virtual_machine" "myterraformvm" {
199+
resource "azurerm_linux_virtual_machine" "myterraformvm" {
200200
name = "myVM"
201201
location = "eastus"
202202
resource_group_name = azurerm_resource_group.myterraformgroup.name
203203
network_interface_ids = [azurerm_network_interface.myterraformnic.id]
204-
vm_size = "Standard_DS1_v2"
204+
size = "Standard_DS1_v2"
205205
206-
storage_os_disk {
206+
os_disk {
207207
name = "myOsDisk"
208208
caching = "ReadWrite"
209-
create_option = "FromImage"
210-
managed_disk_type = "Premium_LRS"
209+
storage_account_type = "Premium_LRS"
211210
}
212211
213212
storage_image_reference {
@@ -217,22 +216,17 @@ resource "azurerm_virtual_machine" "myterraformvm" {
217216
version = "latest"
218217
}
219218
220-
os_profile {
221-
computer_name = "myvm"
222-
admin_username = "azureuser"
223-
}
224-
225-
os_profile_linux_config {
226-
disable_password_authentication = true
227-
ssh_keys {
228-
path = "/home/azureuser/.ssh/authorized_keys"
229-
key_data = "ssh-rsa AAAAB3Nz{snip}hwhqT9h"
230-
}
219+
computer_name = "myvm"
220+
admin_username = "azureuser"
221+
disable_password_authentication = true
222+
223+
admin_ssh_key {
224+
username = "azureuser"
225+
public_key = file("/home/azureuser/.ssh/authorized_keys")
231226
}
232227
233228
boot_diagnostics {
234-
enabled = "true"
235-
storage_uri = azurerm_storage_account.mystorageaccount.primary_blob_endpoint
229+
storage_account_uri = azurerm_storage_account.mystorageaccount.primary_blob_endpoint
236230
}
237231
238232
tags = {
@@ -248,13 +242,18 @@ To bring all these sections together and see Terraform in action, create a file
248242
```hcl
249243
# Configure the Microsoft Azure Provider
250244
provider "azurerm" {
245+
# The "feature" block is required for AzureRM provider 2.x.
246+
# If you are using version 1.x, the "features" block is not allowed.
247+
version = "~>2.0"
248+
features {}
249+
251250
subscription_id = "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
252251
client_id = "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
253252
client_secret = "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
254253
tenant_id = "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
255254
}
256255
257-
# Create a resource group if it doesnt exist
256+
# Create a resource group if it doesn't exist
258257
resource "azurerm_resource_group" "myterraformgroup" {
259258
name = "myResourceGroup"
260259
location = "eastus"
@@ -324,7 +323,6 @@ resource "azurerm_network_interface" "myterraformnic" {
324323
name = "myNIC"
325324
location = "eastus"
326325
resource_group_name = azurerm_resource_group.myterraformgroup.name
327-
network_security_group_id = azurerm_network_security_group.myterraformnsg.id
328326
329327
ip_configuration {
330328
name = "myNicConfiguration"
@@ -338,6 +336,12 @@ resource "azurerm_network_interface" "myterraformnic" {
338336
}
339337
}
340338
339+
# Connect the security group to the network interface
340+
resource "azurerm_network_interface_security_group_association" "example" {
341+
network_interface_id = azurerm_network_interface.myterraformnic.id
342+
network_security_group_id = azurerm_network_security_group.myterraformnsg.id
343+
}
344+
341345
# Generate random text for a unique storage account name
342346
resource "random_id" "randomId" {
343347
keepers = {
@@ -362,43 +366,37 @@ resource "azurerm_storage_account" "mystorageaccount" {
362366
}
363367
364368
# Create virtual machine
365-
resource "azurerm_virtual_machine" "myterraformvm" {
369+
resource "azurerm_linux_virtual_machine" "myterraformvm" {
366370
name = "myVM"
367371
location = "eastus"
368372
resource_group_name = azurerm_resource_group.myterraformgroup.name
369373
network_interface_ids = [azurerm_network_interface.myterraformnic.id]
370-
vm_size = "Standard_DS1_v2"
374+
size = "Standard_DS1_v2"
371375
372-
storage_os_disk {
376+
os_disk {
373377
name = "myOsDisk"
374378
caching = "ReadWrite"
375-
create_option = "FromImage"
376-
managed_disk_type = "Premium_LRS"
379+
storage_account_type = "Premium_LRS"
377380
}
378381
379-
storage_image_reference {
382+
source_image_reference {
380383
publisher = "Canonical"
381384
offer = "UbuntuServer"
382385
sku = "16.04.0-LTS"
383386
version = "latest"
384387
}
385388
386-
os_profile {
387-
computer_name = "myvm"
388-
admin_username = "azureuser"
389-
}
390-
391-
os_profile_linux_config {
392-
disable_password_authentication = true
393-
ssh_keys {
394-
path = "/home/azureuser/.ssh/authorized_keys"
395-
key_data = "ssh-rsa AAAAB3Nz{snip}hwhqT9h"
396-
}
389+
computer_name = "myvm"
390+
admin_username = "azureuser"
391+
disable_password_authentication = true
392+
393+
admin_ssh_key {
394+
username = "azureuser"
395+
public_key = file("/home/azureuser/.ssh/authorized_keys")
397396
}
398397
399398
boot_diagnostics {
400-
enabled = "true"
401-
storage_uri = azurerm_storage_account.mystorageaccount.primary_blob_endpoint
399+
storage_account_uri = azurerm_storage_account.mystorageaccount.primary_blob_endpoint
402400
}
403401
404402
tags = {
@@ -431,8 +429,8 @@ persisted to local or remote state storage.
431429

432430
...
433431

434-
Note: You didnt specify an -out parameter to save this plan, so when
435-
apply is called, Terraform cant guarantee this is what will execute.
432+
Note: You didn't specify an "-out" parameter to save this plan, so when
433+
"apply" is called, Terraform can't guarantee this is what will execute.
436434
+ azurerm_resource_group.myterraform
437435
<snip>
438436
+ azurerm_virtual_network.myterraformnetwork
@@ -469,4 +467,5 @@ ssh azureuser@<publicIps>
469467
```
470468

471469
## Next steps
472-
You have created basic infrastructure in Azure by using Terraform. For more complex scenarios, including examples that use load balancers and virtual machine scale sets, see numerous [Terraform examples for Azure](https://github.com/hashicorp/terraform/tree/master/examples). For an up-to-date list of supported Azure providers, see the [Terraform documentation](https://www.terraform.io/docs/providers/azurerm/index.html).
470+
> [!div class="nextstepaction"]
471+
> [Learn more about using Terraform in Azure](/azure/terraform)

articles/terraform/terraform-create-k8s-cluster-with-aks-applicationgateway-ingress.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
---
22
title: Tutorial - Create an Application Gateway ingress controller in Azure Kubernetes Service
3-
description: Tutorial illustrating how to create a Kubernetes Cluster with Azure Kubernetes Service with Application Gateway as ingress controller
3+
description: In this tutorial, you create a Kubernetes Cluster with Azure Kubernetes Service with Application Gateway as ingress controller
4+
keywords: azure devops terraform application gateway ingress aks kubernetes
45
ms.topic: tutorial
5-
ms.date: 11/13/2019
6+
ms.date: 03/09/2020
67
---
78

89
# Tutorial: Create an Application Gateway ingress controller in Azure Kubernetes Service
@@ -72,7 +73,10 @@ Create the Terraform configuration file that declares the Azure provider.
7273

7374
```hcl
7475
provider "azurerm" {
75-
version = "~>1.18"
76+
# The "feature" block is required for AzureRM provider 2.x.
77+
# If you are using version 1.x, the "features" block is not allowed.
78+
version = "~>2.0"
79+
features {}
7680
}
7781
7882
terraform {
@@ -437,11 +441,10 @@ Create Terraform configuration file that creates all the resources.
437441
}
438442
}
439443
440-
agent_pool_profile {
444+
default_node_pool {
441445
name = "agentpool"
442-
count = var.aks_agent_count
446+
node_count = var.aks_agent_count
443447
vm_size = var.aks_agent_vm_size
444-
os_type = "Linux"
445448
os_disk_size_gb = var.aks_agent_os_disk_size
446449
vnet_subnet_id = data.azurerm_subnet.kubesubnet.id
447450
}
@@ -767,4 +770,4 @@ az group delete -n <resource-group>
767770
## Next steps
768771
769772
> [!div class="nextstepaction"]
770-
> [Application Gateway Ingress Controller](https://azure.github.io/application-gateway-kubernetes-ingress/)
773+
> [Application Gateway Ingress Controller](https://azure.github.io/application-gateway-kubernetes-ingress/)

articles/terraform/terraform-create-k8s-cluster-with-tf-and-aks.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
---
22
title: Tutorial - Create a Kubernetes cluster with Azure Kubernetes Service (AKS) using Terraform
3-
description: Tutorial illustrating how to create a Kubernetes Cluster with Azure Kubernetes Service and Terraform
3+
description: In this tutorial, you create a Kubernetes Cluster with Azure Kubernetes Service and Terraform
4+
keywords: azure devops terraform aks kubernetes
45
ms.topic: tutorial
5-
ms.date: 11/07/2019
6+
ms.date: 03/09/2020
67
---
78

89
# Tutorial: Create a Kubernetes cluster with Azure Kubernetes Service using Terraform
@@ -66,7 +67,10 @@ Create the Terraform configuration file that declares the Azure provider.
6667

6768
```hcl
6869
provider "azurerm" {
69-
version = "~>1.5"
70+
# The "feature" block is required for AzureRM provider 2.x.
71+
# If you are using version 1.x, the "features" block is not allowed.
72+
version = "~>2.0"
73+
features {}
7074
}
7175
7276
terraform {
@@ -389,4 +393,4 @@ see [Monitor Azure Kubernetes Service health](/azure/azure-monitor/insights/cont
389393
## Next steps
390394

391395
> [!div class="nextstepaction"]
392-
> [Learn more about using Terraform in Azure](/azure/terraform)
396+
> [Learn more about using Terraform in Azure](/azure/terraform)

articles/terraform/terraform-create-vm-cluster-module.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
---
22
title: Tutorial - Create an Azure VM cluster with Terraform using the Module Registry
3-
description: Learn how to use Terraform modules to create a Windows virtual machine cluster in Azure
3+
description: In this tutorial, you use Terraform modules to create a Windows virtual machine cluster in Azure
4+
keywords: azure devops terraform vm virtual machine cluster module registry
45
ms.topic: tutorial
5-
ms.date: 10/26/2019
6+
ms.date: 03/09/2020
67
---
78

89
# Tutorial: Create an Azure VM cluster with Terraform using the Module Registry
@@ -31,6 +32,8 @@ variable client_id {}
3132
variable client_secret {}
3233
3334
provider "azurerm" {
35+
version = "~>1.40"
36+
3437
subscription_id = "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
3538
tenant_id = "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
3639
client_id = "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
@@ -95,4 +98,4 @@ Run `terraform apply` to provision the VMs on Azure.
9598
## Next steps
9699

97100
> [!div class="nextstepaction"]
98-
> [Browse the list of Azure Terraform modules](https://registry.terraform.io/modules/Azure)
101+
> [Browse the list of Azure Terraform modules](https://registry.terraform.io/modules/Azure)

0 commit comments

Comments
 (0)