Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Learn Terraform with Azure

This is the companion code from the HashiCorp Learn tutorials for [getting started with Terraform on Azure](https://learn.hashicorp.com/collections/terraform/azure-get-started).
126 changes: 125 additions & 1 deletion test/main.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,128 @@
# Configure the Microsoft Azure Provider.
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = ">= 2.26"
}
}

required_version = ">= 0.14.9"
}

provider "azurerm" {
# Configuration options
features {}
}

# Create a resource group
resource "azurerm_resource_group" "rg" {
name = "${var.prefix}TFRG"
location = var.location
tags = var.tags
}

# Create virtual network
resource "azurerm_virtual_network" "vnet" {
name = "${var.prefix}TFVnet"
address_space = ["10.0.0.0/16"]
location = var.location
resource_group_name = azurerm_resource_group.rg.name
tags = var.tags
}

# Create subnet
resource "azurerm_subnet" "subnet" {
name = "${var.prefix}TFSubnet"
resource_group_name = azurerm_resource_group.rg.name
virtual_network_name = azurerm_virtual_network.vnet.name
address_prefixes = ["10.0.1.0/24"]
}

# Create public IP
resource "azurerm_public_ip" "publicip" {
name = "${var.prefix}TFPublicIP"
location = var.location
resource_group_name = azurerm_resource_group.rg.name
allocation_method = "Dynamic"
tags = var.tags
}

# Create Network Security Group and rule
resource "azurerm_network_security_group" "nsg" {
name = "${var.prefix}TFNSG"
location = var.location
resource_group_name = azurerm_resource_group.rg.name
tags = var.tags

security_rule {
name = "SSH"
priority = 1001
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "22"
source_address_prefix = "*"
destination_address_prefix = "*"
}
}

# Create network interface
resource "azurerm_network_interface" "nic" {
name = "${var.prefix}NIC"
location = var.location
resource_group_name = azurerm_resource_group.rg.name
tags = var.tags

ip_configuration {
name = "${var.prefix}NICConfg"
subnet_id = azurerm_subnet.subnet.id
private_ip_address_allocation = "dynamic"
public_ip_address_id = azurerm_public_ip.publicip.id
}
}

# Create a Linux virtual machine
resource "azurerm_virtual_machine" "vm" {
name = "${var.prefix}TFVM"
location = var.location
resource_group_name = azurerm_resource_group.rg.name
network_interface_ids = [azurerm_network_interface.nic.id]
vm_size = "Standard_DS1_v2"
tags = var.tags

storage_os_disk {
name = "${var.prefix}OsDisk"
caching = "ReadWrite"
create_option = "FromImage"
managed_disk_type = "Premium_LRS"
}

storage_image_reference {
publisher = "Canonical"
offer = "UbuntuServer"
sku = lookup(var.sku, var.location)
version = "latest"
}

os_profile {
computer_name = "${var.prefix}TFVM"
admin_username = var.admin_username
admin_password = var.admin_password
}

os_profile_linux_config {
disable_password_authentication = false
}

}

data "azurerm_public_ip" "ip" {
name = azurerm_public_ip.publicip.name
resource_group_name = azurerm_virtual_machine.vm.resource_group_name
depends_on = ["azurerm_virtual_machine.vm"]
}

output "os_sku" {
value = lookup(var.sku, var.location)
}
11 changes: 0 additions & 11 deletions test/outputs.tf

This file was deleted.

2 changes: 2 additions & 0 deletions test/terraform.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
location = "westus2"
prefix = "tf"
35 changes: 26 additions & 9 deletions test/variables.tf
Original file line number Diff line number Diff line change
@@ -1,15 +1,32 @@
variable "region" {
description = "AWS region"
default = "us-west-1"
variable "location" {}

variable "admin_username" {
type = string
description = "Administrator user name for virtual machine"
}

variable "instance_type" {
description = "Type of EC2 instance to provision"
default = "t2.micro"
variable "admin_password" {
type = string
description = "Password must meet Azure complexity requirements"
}

variable "instance_name" {
description = "EC2 instance name"
default = "Provisioned by Terraform"
variable "prefix" {
type = string
default = "my"
}

variable "tags" {
type = map

default = {
Environment = "Terraform GS"
Dept = "Engineering"
}
}

variable "sku" {
default = {
westus2 = "16.04-LTS"
eastus = "18.04-LTS"
}
}
12 changes: 0 additions & 12 deletions test/versions.tf

This file was deleted.