Silly98 commited on
Commit
3125437
·
verified ·
1 Parent(s): adaf4bf

Update chatgpt

Browse files
Files changed (1) hide show
  1. chatgpt +198 -2
chatgpt CHANGED
@@ -1,2 +1,198 @@
1
- az vm list-skus -l eastus --all --query "[?starts_with(name,'Standard_NC') || starts_with(name,'Standard_ND') || starts_with(name,'Standard_NV')].{SKU:name, GPUs:capabilities[?name=='GPUs']|[0].value, vCPUs:capabilities[?name=='vCPUs']|[0].value, RAM_GB:capabilities[?name=='MemoryGB']|[0].value}" -o table
2
- az vm list-sizes -l eastus -o table
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ variable "subscription_id" { type = string }
2
+ variable "location" { type = string default = "eastus" }
3
+
4
+ variable "prefix" { type = string default = "cad" }
5
+ variable "admin_username" { type = string default = "azureuser" }
6
+
7
+ variable "ssh_public_key" { type = string } # paste your .pub content
8
+ variable "allowed_ssh_cidr" { type = string } # your public IP like "x.x.x.x/32"
9
+
10
+ variable "vm_size" { type = string default = "Standard_NC4as_T4_v3" }
11
+ variable "os_disk_gb" { type = number default = 250 }
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+ terraform {
25
+ required_version = ">= 1.6.0"
26
+ required_providers {
27
+ azurerm = {
28
+ source = "hashicorp/azurerm"
29
+ version = "~> 4.0"
30
+ }
31
+ random = {
32
+ source = "hashicorp/random"
33
+ version = "~> 3.6"
34
+ }
35
+ }
36
+ }
37
+
38
+ provider "azurerm" {
39
+ features {}
40
+ subscription_id = var.subscription_id
41
+ }
42
+
43
+ resource "random_string" "suffix" {
44
+ length = 6
45
+ upper = false
46
+ special = false
47
+ }
48
+
49
+ locals {
50
+ sfx = random_string.suffix.result
51
+ rg_name = "rg-${var.prefix}-${local.sfx}"
52
+
53
+ # storage account must be 3-24 chars, lowercase + numbers only
54
+ st_name = lower(replace("${var.prefix}${local.sfx}st", "-", ""))
55
+
56
+ vnet = "vnet-${var.prefix}-${local.sfx}"
57
+ subnet = "subnet-${var.prefix}-${local.sfx}"
58
+ nsg = "nsg-${var.prefix}-${local.sfx}"
59
+ pip = "pip-${var.prefix}-${local.sfx}"
60
+ nic = "nic-${var.prefix}-${local.sfx}"
61
+ vm = "vm-${var.prefix}-${local.sfx}"
62
+ }
63
+
64
+ resource "azurerm_resource_group" "rg" {
65
+ name = local.rg_name
66
+ location = var.location
67
+ }
68
+
69
+ resource "azurerm_storage_account" "st" {
70
+ name = local.st_name
71
+ resource_group_name = azurerm_resource_group.rg.name
72
+ location = azurerm_resource_group.rg.location
73
+ account_tier = "Standard"
74
+ account_replication_type = "LRS"
75
+ allow_nested_items_to_be_public = false
76
+ }
77
+
78
+ resource "azurerm_virtual_network" "vnet" {
79
+ name = local.vnet
80
+ location = azurerm_resource_group.rg.location
81
+ resource_group_name = azurerm_resource_group.rg.name
82
+ address_space = ["10.10.0.0/16"]
83
+ }
84
+
85
+ resource "azurerm_subnet" "subnet" {
86
+ name = local.subnet
87
+ resource_group_name = azurerm_resource_group.rg.name
88
+ virtual_network_name = azurerm_virtual_network.vnet.name
89
+ address_prefixes = ["10.10.1.0/24"]
90
+ }
91
+
92
+ resource "azurerm_network_security_group" "nsg" {
93
+ name = local.nsg
94
+ location = azurerm_resource_group.rg.location
95
+ resource_group_name = azurerm_resource_group.rg.name
96
+
97
+ security_rule {
98
+ name = "allow-ssh"
99
+ priority = 100
100
+ direction = "Inbound"
101
+ access = "Allow"
102
+ protocol = "Tcp"
103
+ source_port_range = "*"
104
+ destination_port_range = "22"
105
+ source_address_prefix = var.allowed_ssh_cidr
106
+ destination_address_prefix = "*"
107
+ }
108
+ }
109
+
110
+ resource "azurerm_public_ip" "pip" {
111
+ name = local.pip
112
+ location = azurerm_resource_group.rg.location
113
+ resource_group_name = azurerm_resource_group.rg.name
114
+ allocation_method = "Static"
115
+ sku = "Standard"
116
+ }
117
+
118
+ resource "azurerm_network_interface" "nic" {
119
+ name = local.nic
120
+ location = azurerm_resource_group.rg.location
121
+ resource_group_name = azurerm_resource_group.rg.name
122
+
123
+ ip_configuration {
124
+ name = "ipconfig1"
125
+ subnet_id = azurerm_subnet.subnet.id
126
+ private_ip_address_allocation = "Dynamic"
127
+ public_ip_address_id = azurerm_public_ip.pip.id
128
+ }
129
+ }
130
+
131
+ resource "azurerm_network_interface_security_group_association" "nic_nsg" {
132
+ network_interface_id = azurerm_network_interface.nic.id
133
+ network_security_group_id = azurerm_network_security_group.nsg.id
134
+ }
135
+
136
+ resource "azurerm_linux_virtual_machine" "vm" {
137
+ name = local.vm
138
+ resource_group_name = azurerm_resource_group.rg.name
139
+ location = azurerm_resource_group.rg.location
140
+ size = var.vm_size
141
+ admin_username = var.admin_username
142
+ network_interface_ids = [azurerm_network_interface.nic.id]
143
+
144
+ admin_ssh_key {
145
+ username = var.admin_username
146
+ public_key = var.ssh_public_key
147
+ }
148
+
149
+ os_disk {
150
+ caching = "ReadWrite"
151
+ storage_account_type = "Premium_LRS"
152
+ disk_size_gb = var.os_disk_gb # 250 GB
153
+ }
154
+
155
+ source_image_reference {
156
+ publisher = "Canonical"
157
+ offer = "0001-com-ubuntu-server-jammy"
158
+ sku = "22_04-lts-gen2"
159
+ version = "latest"
160
+ }
161
+ }
162
+
163
+
164
+
165
+
166
+
167
+
168
+
169
+
170
+
171
+
172
+
173
+
174
+
175
+
176
+
177
+
178
+ subscription_id = "<YOUR_SUBSCRIPTION_ID>"
179
+ location = "eastus"
180
+
181
+ ssh_public_key = "ssh-ed25519 AAAA...paste_your_pub_key..."
182
+ allowed_ssh_cidr = "YOUR.PUBLIC.IP/32"
183
+
184
+ vm_size = "Standard_NC4as_T4_v3"
185
+ os_disk_gb = 250
186
+
187
+
188
+
189
+
190
+
191
+
192
+
193
+
194
+
195
+ output "resource_group" { value = azurerm_resource_group.rg.name }
196
+ output "storage_account" { value = azurerm_storage_account.st.name }
197
+ output "public_ip" { value = azurerm_public_ip.pip.ip_address }
198
+ output "vm_name" { value = azurerm_linux_virtual_machine.vm.name }