diff --git a/CHAP02/main.tf b/CHAP02/main.tf new file mode 100644 index 0000000..89e1645 --- /dev/null +++ b/CHAP02/main.tf @@ -0,0 +1,90 @@ +resource "azurerm_resource_group" "rg" { + name = "bookRg" + location = "West Europe" + + tags = { + environment = "Terraform Azure" + } +} + +resource "azurerm_virtual_network" "vnet" { + name = "book-vnet" + location = "West Europe" + address_space = ["10.0.0.0/16"] + resource_group_name = azurerm_resource_group.rg.name +} + +resource "azurerm_subnet" "subnet" { + name = "book-subnet" + virtual_network_name = azurerm_virtual_network.vnet.name + resource_group_name = azurerm_resource_group.rg.name + address_prefixes = ["10.0.10.0/24"] +} + +resource "azurerm_network_interface" "nic" { + name = "book-nic" + location = "West Europe" + resource_group_name = azurerm_resource_group.rg.name + + ip_configuration { + name = "bookipconfig" + subnet_id = azurerm_subnet.subnet.id + private_ip_address_allocation = "Dynamic" + public_ip_address_id = azurerm_public_ip.pip.id + } +} + +resource "azurerm_public_ip" "pip" { + name = "book-ip" + location = "West Europe" + resource_group_name = azurerm_resource_group.rg.name +# public_ip_address_allocation = "" + domain_name_label = "bookdevops" + allocation_method = "Dynamic" +} + +resource "azurerm_storage_account" "stor" { + name = "bookstor" + location = "West Europe" + resource_group_name = azurerm_resource_group.rg.name + account_tier = "Standard" + account_replication_type = "LRS" +} + +resource "azurerm_virtual_machine" "vm" { + name = "bookvm" + location = "West Europe" + resource_group_name = azurerm_resource_group.rg.name + vm_size = "Standard_DS1_v2" + network_interface_ids = [azurerm_network_interface.nic.id] + + storage_image_reference { + publisher = "Canonical" + offer = "UbuntuServer" + sku = "16.04-LTS" + version = "latest" + } + + storage_os_disk { + name = "book-osdisk" + managed_disk_type = "Standard_LRS" + caching = "ReadWrite" + create_option = "FromImage" + } + + os_profile { + computer_name = "VMBOOK" + admin_username = "admin" + admin_password = "book123*" + } + + os_profile_linux_config { + disable_password_authentication = false + } + + boot_diagnostics { + enabled = true + storage_uri = azurerm_storage_account.stor.primary_blob_endpoint + } +} + diff --git a/CHAP02/provider.tf b/CHAP02/provider.tf new file mode 100644 index 0000000..2b39ad2 --- /dev/null +++ b/CHAP02/provider.tf @@ -0,0 +1,3 @@ +provider "azurerm" { +features {} +} diff --git a/CHAP02/versions.tf b/CHAP02/versions.tf new file mode 100644 index 0000000..2b50674 --- /dev/null +++ b/CHAP02/versions.tf @@ -0,0 +1,8 @@ +terraform { + required_version = ">= 0.13" + required_providers { + azurerm = { + source = "hashicorp/azurerm" + } + } +} \ No newline at end of file