Tweaked TF code examples to ensure they work and flow
This commit is contained in:
Родитель
2870a725c0
Коммит
69a6682831
|
@ -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
|
||||
|
|
Загрузка…
Ссылка в новой задаче