Skip to content

Commit

Permalink
add
Browse files Browse the repository at this point in the history
  • Loading branch information
mikaelkrief committed May 30, 2023
1 parent 0552510 commit 115eb6d
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 14 deletions.
22 changes: 22 additions & 0 deletions CHAP08/cost/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

86 changes: 86 additions & 0 deletions CHAP08/cost/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
terraform {
required_version = "~> 1.0"
required_providers {
azurerm = {
version = "~> 3.35"
}
}
}

provider "azurerm" {
features {}
}

resource "azurerm_resource_group" "rg" {
name = "rg-demo"
location = "West Europe"
}

resource "azurerm_virtual_network" "vnet" {
name = "vnet-demo"
address_space = ["10.0.0.0/16"]
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
}

resource "azurerm_subnet" "subnet" {
name = "subnet-demo"
resource_group_name = azurerm_resource_group.rg.name
virtual_network_name = azurerm_virtual_network.vnet.name
address_prefixes = ["10.0.2.0/24"]
}

resource "azurerm_network_interface" "nic" {
name = "nic-demo"
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name

ip_configuration {
name = "internal"
subnet_id = azurerm_subnet.subnet.id
private_ip_address_allocation = "Dynamic"
}
}

resource "azurerm_linux_virtual_machine" "vm" {
name = "vm-demo"
resource_group_name = azurerm_resource_group.rg.name
location = azurerm_resource_group.rg.location
size = "Standard_DS2_V2"
disable_password_authentication = false
admin_username = "adminuser"
admin_password = "P@ssw0rd123*"
network_interface_ids = [
azurerm_network_interface.nic.id,
]

os_disk {
caching = "ReadWrite"
storage_account_type = "Standard_LRS"
}

source_image_reference {
publisher = "Canonical"
offer = "UbuntuServer"
sku = "18.04-LTS"
version = "latest"
}
}

resource "azurerm_service_plan" "plan-app" {
name = "splan"
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name

os_type = "Linux"
sku_name = "B1"
}

resource "azurerm_linux_web_app" "app" {
name = "webappdemobook1001"
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
service_plan_id = azurerm_service_plan.plan-app.id

site_config {}
}
3 changes: 0 additions & 3 deletions CHAP08/terraformer/install.sh

This file was deleted.

19 changes: 19 additions & 0 deletions CHAP08/vm/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 8 additions & 11 deletions CHAP08/vm/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ provider "azurerm" {

resource "azurerm_resource_group" "rg" {
name = "RG-VM"
location = "West Europe"
location = "East US"
}

resource "azurerm_public_ip" "ip" {
Expand Down Expand Up @@ -43,14 +43,10 @@ resource "azurerm_network_interface" "nic" {
}


data "azurerm_key_vault" "keyvault" {
name = "keyvdemobook"
resource_group_name = "rg_keyvault"
}

data "azurerm_key_vault_secret" "vm-password" {
name = "vmdemoaccess"
key_vault_id = data.azurerm_key_vault.keyvault.id
resource "random_password" "password" {
length = 16
special = true
override_special = "_%@"
}

resource "azurerm_linux_virtual_machine" "vm" {
Expand All @@ -59,7 +55,7 @@ resource "azurerm_linux_virtual_machine" "vm" {
location = azurerm_resource_group.rg.location
size = "Standard_F2"
admin_username = "adminuser"
admin_password = data.azurerm_key_vault_secret.vm-password.value
admin_password = random_password.password.result
disable_password_authentication = false
network_interface_ids = [azurerm_network_interface.nic.id]

Expand All @@ -77,7 +73,8 @@ resource "azurerm_linux_virtual_machine" "vm" {

provisioner "remote-exec" {
inline = [
"apt update",
"sudo apt update",
"sudo apt install nginx -y"
]

connection {
Expand Down

0 comments on commit 115eb6d

Please sign in to comment.