:: Azure에서 VM 생성
:: resrouce 그룹은 resourcegroup.tf 에서 생성한 resource 사용
:: 부트 진단설정을 위한 storage account 생성
# unique storage account name 생성
#resource "random_id" "random_id" {
# keepers = {
# resource_group = azurerm_resource_group.dkkim.name
# }
# byte_length = 8
#}
#resource group 1 : DKKIM
resource "azurerm_resource_group" "DKKIM" {
name = "DKKIM"
location = "korea central"
tags = {
environment = "management:dkkim"
}
}
#VM 부트 진단에 사용할 storage account 생성
# (https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/storage_account)
resource "azurerm_storage_account" "dkkim-storage-account"{
name = "vmbootdiagnostic156"
location = azurerm_resource_group.DKKIM.location
resource_group_name = azurerm_resource_group.DKKIM.name
account_tier = "Standard" #tier list = Standard, Premium
account_replication_type = "LRS" #type list = LRS, GRS, RAGRS, ZRS, GZRS, RAGZRS
tags = {
environment = "management:dkkim"
}
}
#vm에 연결할 public ip 정의
resource "azurerm_public_ip" "dkkimvm-public-ip" {
name = "dkkimvm-pip"
location = azurerm_resource_group.DKKIM.location
resource_group_name = azurerm_resource_group.DKKIM.name
allocation_method = "Static" #Static, Dynamic
sku = "Basic"
tags = {
environment = "management:dkkim"
}
}
#vm에 연결할 nic 정의
resource "azurerm_network_interface" "dkkim-nic1" {
name = "dkkimvm-nic"
location = azurerm_resource_group.DKKIM.location
resource_group_name = azurerm_resource_group.DKKIM.name
ip_configuration {
name = "dkkimvm-nic1"
subnet_id = azurerm_subnet.dkkim-vnet-subnet.id
private_ip_address_allocation = "Dynamic"
public_ip_address_id = azurerm_public_ip.dkkimvm-public-ip.id
}
tags = {
environment = "management:dkkim"
}
}
#VM 정의
resource "azurerm_linux_virtual_machine" "dkkimvm" {
name = "dkkimvm"
resource_group_name = azurerm_resource_group.DKKIM.name
location = azurerm_resource_group.DKKIM.location
size = "Standard_F2"
admin_username = "dkkim"
admin_password = "Flyyunha12!@"
disable_password_authentication = false
# linux 의 경우 sshkey 생성 필요 없을시 false 옵션을 줘야 admin_password 사용 가능
network_interface_ids = [ azurerm_network_interface.dkkim-nic1.id ]
source_image_reference {
publisher = "Canonical"
offer = "UbuntuServer"
sku = "18.04-LTS"
version = "latest"
}
os_disk {
caching = "ReadWrite"
storage_account_type = "StandardSSD_LRS"
disk_size_gb = "60"
}
#https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/linux_virtual_machine#storage_account_type
boot_diagnostics {
storage_account_uri = azurerm_storage_account.dkkim-storage-account.primary_blob_endpoint
}
tags = {
environment = "management:dkkim"
}
}
'Work > Terraform for Azure' 카테고리의 다른 글
Terraform Public_ip.tf (0) | 2024.01.04 |
---|---|
Terraform vnet.tf (0) | 2024.01.03 |
Terraform resourcegroup.tf (0) | 2024.01.03 |
Terraform main.tf (1) | 2024.01.03 |
Linux 환경(CentOS)에서 Terraform 환경 설정 for Azure (0) | 2024.01.02 |