Skip to content

Commit f766e56

Browse files
committed
update
1 parent ea47182 commit f766e56

File tree

8 files changed

+203
-4
lines changed

8 files changed

+203
-4
lines changed

CHAP05/import-block/main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ provider "azurerm" {
1414

1515

1616
resource "azurerm_resource_group" "rg-app" {
17-
name = "RG-APP-IMPORT"
17+
name = "RG-APP-IMPORT2"
1818
location = "westeurope"
1919
}
2020

2121

2222
import {
23-
id = "/subscriptions/<your subscription id>/resourcegroups/RG-APP-IMPORT"
23+
id = "/subscriptions/8a7aace5-74aa-416f-b8e4-2c292b6304e5/resourcegroups/RG-APP-IMPORT2"
2424
to = azurerm_resource_group.rg-app
2525
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# __generated__ by Terraform
2+
# Please review these resources and move them into your main configuration files.
3+
4+
# __generated__ by Terraform from "/subscriptions/8a7aace5-74aa-416f-b8e4-2c292b6304e5/resourcegroups/RG-APP-IMPORT"
5+
resource "azurerm_resource_group" "rg-app" {
6+
location = "westeurope"
7+
name = "RG-APP-IMPORT"
8+
tags = {}
9+
timeouts {
10+
create = null
11+
delete = null
12+
read = null
13+
update = null
14+
}
15+
}

CHAP05/import-generated/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ provider "azurerm" {
1313
}
1414

1515
import {
16-
id = "/subscriptions/<your subscription id>/resourcegroups/RG-APP-IMPORT"
16+
id = "/subscriptions/8a7aace5-74aa-416f-b8e4-2c292b6304e5/resourcegroups/RG-APP-IMPORT"
1717
to = azurerm_resource_group.rg-app
1818
}

CHAP14/remoteexec/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ terraform {
55
version = "~> 3.35"
66
}
77
}
8-
cloud {
8+
cloud {
99
hostname = "app.terraform.io"
1010
organization = "demoBook"
1111

CHAP15/cycle/.terraform.lock.hcl

Lines changed: 41 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CHAP15/cycle/main.tf

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
terraform {
2+
required_version = "~> 1.1"
3+
required_providers {
4+
azurerm = {
5+
version = "~> 3.23"
6+
}
7+
}
8+
}
9+
10+
provider "azurerm" {
11+
features {}
12+
}
13+
14+
locals {
15+
vmname = "vmdemo-${random_string.str.result}"
16+
}
17+
18+
resource "random_string" "str" {
19+
length = 4
20+
special = false
21+
}
22+
23+
resource "azurerm_resource_group" "rg" {
24+
name = "RG-VM-${random_string.str.result}"
25+
location = "East US"
26+
}
27+
28+
resource "azurerm_public_ip" "ip" {
29+
name = "${local.vmname}-pip"
30+
resource_group_name = azurerm_resource_group.rg.name
31+
location = azurerm_resource_group.rg.location
32+
allocation_method = "Dynamic"
33+
}
34+
35+
data "azurerm_subnet" "subnet" {
36+
name = "Default1"
37+
resource_group_name = "RG_NETWORK"
38+
virtual_network_name = "VNET-DEMO"
39+
}
40+
41+
resource "azurerm_network_interface" "nic" {
42+
name = "${azurerm_linux_virtual_machine.vm.name}-nic"
43+
#name = "${local.vmname}-nic"
44+
resource_group_name = azurerm_resource_group.rg.name
45+
location = azurerm_resource_group.rg.location
46+
47+
ip_configuration {
48+
name = "internal"
49+
subnet_id = data.azurerm_subnet.subnet.id
50+
private_ip_address_allocation = "Dynamic"
51+
public_ip_address_id = azurerm_public_ip.ip.id
52+
}
53+
}
54+
55+
56+
resource "random_password" "password" {
57+
length = 16
58+
special = true
59+
override_special = "_%@"
60+
}
61+
62+
resource "azurerm_linux_virtual_machine" "vm" {
63+
name = "myvmdemo-${random_string.str.result}"
64+
network_interface_ids = [azurerm_network_interface.nic.id]
65+
resource_group_name = azurerm_resource_group.rg.name
66+
location = azurerm_resource_group.rg.location
67+
size = "Standard_F2"
68+
admin_username = "adminuser"
69+
admin_password = random_password.password.result
70+
disable_password_authentication = false
71+
72+
73+
source_image_reference {
74+
publisher = "Canonical"
75+
offer = "UbuntuServer"
76+
sku = "18.04-LTS"
77+
version = "latest"
78+
}
79+
80+
os_disk {
81+
storage_account_type = "Standard_LRS"
82+
caching = "ReadWrite"
83+
}
84+
85+
provisioner "remote-exec" {
86+
inline = [
87+
"sudo apt update",
88+
"sudo apt install nginx -y"
89+
]
90+
91+
connection {
92+
host = self.public_ip_address
93+
user = self.admin_username
94+
password = self.admin_password
95+
}
96+
}
97+
}

CHAP15/interpolation/.terraform.lock.hcl

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CHAP15/interpolation/main.tf

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
terraform {
2+
required_version = "~> 1.1"
3+
required_providers {
4+
azurerm = {
5+
version = "~> 3.23"
6+
}
7+
}
8+
}
9+
10+
provider "azurerm" {
11+
features {}
12+
}
13+
14+
15+
resource "azurerm_resource_group" "rg-app" {
16+
name = $var.resource_group_name}-test
17+
#name = "${var.resource_group_name}-test"
18+
location = "westeurope"
19+
}
20+
21+
22+
variable "resource_group_name" {
23+
default = "rg-demo-error"
24+
}

0 commit comments

Comments
 (0)