Tweaked TF code examples to ensure they work and flow

This commit is contained in:
Mark Gray 2019-10-19 13:06:31 -07:00
Родитель 2870a725c0
Коммит 69a6682831
16 изменённых файлов: 193 добавлений и 20 удалений

Просмотреть файл

@ -1,5 +1,4 @@
# Configure the Azure Provider
provider "azurerm" {
# whilst the `version` attribute is optional, we recommend pinning to a given version of the Provider
version = "=1.34.0"
version = "~>1.35.0"
}

Просмотреть файл

@ -1,3 +1,4 @@
# Configure Vnet and Subnet
resource "azurerm_virtual_network" "predayvnet" {
name = "tfignitepreday"
location = "East US 2"
@ -5,6 +6,7 @@ resource "azurerm_virtual_network" "predayvnet" {
address_space = ["10.0.0.0/16"]
subnet {
name = "subnet1"
name = "default"
address_prefix = "10.0.1.0/24"
}
}
}

Просмотреть файл

@ -1,12 +1,12 @@
#Configure Network Interface
resource "azurerm_network_interface" "example" {
#Configure Network Interface# Configure Network Interface
resource "azurerm_network_interface" "predaynic" {
name = "tfignitepredaynic"
location = "var.location"
resource_group_name = "var.my_resource_group"
location = var.location
resource_group_name = var.rg
ip_configuration {
name = "tfpredaynicconfig"
subnet_id = "azurerm_subnet.predayvnet.subnets[0]}"
subnet_id = azurerm_subnet.predaysubnet.id
private_ip_address_allocation = "Dynamic"
}
}

Просмотреть файл

@ -1,5 +1,4 @@
# Configure the Azure Provider
provider "azurerm" {
# whilst the `version` attribute is optional, we recommend pinning to a given version of the Provider
version = "=1.34.0"
version = "~>1.35.0"
}

Просмотреть файл

@ -0,0 +1,2 @@
rg = "" ## Enter the resource group pre-created in your lab
location = "" ## Enter the azure region for your resources

Просмотреть файл

@ -1,9 +1,9 @@
variable "my_resource_group" {
description = "Resource group to put resources into"
default = "<<<NAME OF YOUR RESOURCE GROUP>>>"
variable "rg" {
type = "string"
description = "Name of Lab resource group to provision resources to."
}
variable "location" {
type = "string"
description = "Azure region to put resources in"
default = "East US"
}

Просмотреть файл

@ -1,8 +1,10 @@
resource "azurerm_virtual_machine" "example" {
# Configure Virtual Machine
resource "azurerm_virtual_machine" "predayvm" {
name = "tfignitepredayvm"
location = "var.location"
resource_group_name = "var.my_resource_group"
location = var.location
resource_group_name = var.rg
vm_size = "Standard_DS1_v2"
network_interface_ids = [azurerm_network_interface.predaynic.id]
storage_image_reference {
publisher = "Canonical"
@ -10,15 +12,21 @@ resource "azurerm_virtual_machine" "example" {
sku = "16.04-LTS"
version = "latest"
}
storage_os_disk {
name = "myosdisk1"
caching = "ReadWrite"
create_option = "FromImage"
managed_disk_type = "Standard_LRS"
}
os_profile {
computer_name = "hostname"
admin_username = "testadmin"
admin_password = "Password1234!"
}
os_profile_linux_config {
disable_password_authentication = false
}
}

Просмотреть файл

@ -0,0 +1,15 @@
# Configure Vnet -- pull subnet out to its own resource to demonstrate references / dependencies
resource "azurerm_virtual_network" "predayvnet" {
name = "tfignitepreday"
location = var.location
resource_group_name = var.rg
address_space = ["10.0.0.0/16"]
}
# Configure Subnet
resource "azurerm_subnet" "predaysubnet" {
name = "default"
resource_group_name = var.rg
virtual_network_name = azurerm_virtual_network.predayvnet.name
address_prefix = "10.0.1.0/24"
}

Просмотреть файл

@ -0,0 +1,13 @@
#Configure Network Interface# Configure Network Interface
resource "azurerm_network_interface" "predaynic" {
name = "tfignitepredaynic"
location = var.location
resource_group_name = var.rg
ip_configuration {
name = "tfpredaynicconfig"
subnet_id = azurerm_subnet.predaysubnet.id
private_ip_address_allocation = "Dynamic"
}
tags = var.tags
}

Просмотреть файл

@ -0,0 +1,4 @@
# Configure the Azure Provider
provider "azurerm" {
version = "~>1.35.0"
}

Просмотреть файл

@ -0,0 +1,30 @@
rg = "" ## Enter the resource group pre-created in your lab
location = "" ## Enter the azure region for your resources
securityGroupRules = [
{
name = "DNS"
priority = 100
protocol = "*"
destinationPortRange = "53"
},
{
name = "HTTPS"
priority = 150
protocol = "tcp"
destinationPortRange = "443"
},
{
name = "WHOIS"
priority = 200
protocol = "tcp"
destinationPortRange = "43"
},
]
tags = {
event = "Ignite"
year = "2019"
session_id = "PRE04"
iac_tool = "terraform"
lab = "4"
}

Просмотреть файл

@ -0,0 +1,24 @@
variable "rg" {
type = "string"
description = "Name of Lab resource group to provision resources to."
}
variable "location" {
type = "string"
description = "Azure region to put resources in"
}
variable "securityGroupRules" {
type = list(object({
name = string
priority = number
protocol = string
destinationPortRange = string
}))
description = "List of security group rules"
}
variable "tags" {
type = map(string)
description = "tags to be used with all resources in the lab"
}

Просмотреть файл

@ -0,0 +1,34 @@
# Configure Virtual Machine
resource "azurerm_virtual_machine" "predayvm" {
name = "tfignitepredayvm"
location = var.location
resource_group_name = var.rg
vm_size = "Standard_DS1_v2"
network_interface_ids = [azurerm_network_interface.predaynic.id]
storage_image_reference {
publisher = "Canonical"
offer = "UbuntuServer"
sku = "16.04-LTS"
version = "latest"
}
storage_os_disk {
name = "myosdisk1"
caching = "ReadWrite"
create_option = "FromImage"
managed_disk_type = "Standard_LRS"
}
os_profile {
computer_name = "hostname"
admin_username = "testadmin"
admin_password = "Password1234!"
}
os_profile_linux_config {
disable_password_authentication = false
}
tags = var.tags
}

Просмотреть файл

@ -0,0 +1,43 @@
# Configure Vnet -- pull subnet out to its own resource to demonstrate references / dependencies
resource "azurerm_virtual_network" "predayvnet" {
name = "tfignitepreday"
location = var.location
resource_group_name = var.rg
address_space = ["10.0.0.0/16"]
tags = var.tags
}
# Configure Subnet
resource "azurerm_subnet" "predaysubnet" {
name = "default"
resource_group_name = var.rg
virtual_network_name = azurerm_virtual_network.predayvnet.name
address_prefix = "10.0.1.0/24"
}
resource "azurerm_network_security_group" "predaysg" {
name = "default-rules"
location = var.location
resource_group_name = var.rg
dynamic "security_rule" {
for_each = var.securityGroupRules
content {
name = lower(security_rule.value.name)
priority = security_rule.value.priority
direction = "Inbound"
access = "Allow"
protocol = title(security_rule.value.protocol)
source_port_range = "*"
destination_port_range = security_rule.value.destinationPortRange
source_address_prefix = "*"
destination_address_prefix = "VirtualNetwork"
}
}
}
resource "azurerm_subnet_network_security_group_association" "preday" {
subnet_id = azurerm_subnet.predaysubnet.id
network_security_group_id = azurerm_network_security_group.predaysg.id
}

Просмотреть файл

@ -1,5 +1,5 @@
# Configure Network Interface
resource "azurerm_network_interface" "tf_pre-day" {
resource "azurerm_network_interface" "predaynic" {
name = "tfignitepredaynic"
location = var.location
resource_group_name = var.rg

Просмотреть файл

@ -1,4 +1,4 @@
# Configure VNet and Subnet
# Configure VNet
resource "azurerm_virtual_network" "predayvnet" {
name = "tfignitepreday"
location = var.location