반응형
1. Flavor 생성
resource "openstack_compute_flavor_v2" "C2M2D20" {
name = "C2M2D20"
ram = "2048"
vcpus = "2"
disk = "20"
is_public = "true"
}
2. Image 생성
resource "openstack_images_image_v2" "rhel7_6" {
name = "rhel7.6"
local_file_path = "/home/test/rhel7.qcow"
container_format = "bare"
disk_format = "qcow2"
visibility = "public"
properties = {
key = "value"
}
}
3. Network 및 Subnet 생성
resource "openstack_networking_network_v2" "public_net" {
name = "public_net"
admin_state_up = "true"
shared = "true"
external = "true"
mtu = "1500"
availability_zone_hints = ["OVS"]
port_security_enabled = "false"
segments {
physical_network = "physnet"
network_type = "flat"
}
}
resource "openstack_networking_subnet_v2" "public_subnet" {
name = "public_subnet"
network_id = "${openstack_networking_network_v2.public_net.id}"
cidr = "100.100.100.0/24"
ip_version = 4
}
4. keystone 인증
# Configure the OpenStack Provider
provider "openstack" {
tenant_name = "admin"
user_name = "admin"
password = "admin"
auth_url = "http://10.80.12.14:5000"
insecure = "true"
region = "regionOne"
}
5. variables 정의
# global variables
variable "Instance" {
default = {
image_id = "74dab4a8-852c-4096-afe5-fa7a0edf265b" # RHEL7_6
}
}
variable "network" {
default = {
id = "ab5d012c-b1d9-478c-8279-6acfff9a4c2c"
subnet_id = "8f03f155-30bb-4279-9558-dcba8a974c76"
}
}
6. VM 생성
resource "openstack_compute_instance_v2" "testvm2" {
name = "testvm2"
image_id = "${openstack_images_image_v2.rhel7_6.id}"
flavor_id = "${openstack_compute_flavor_v2.C2M2D20.id}"
availability_zone = "OVS"
network {
name = "public_net"
}
}
728x90
'IaC (Automation) > Terraform' 카테고리의 다른 글
Terraform Openstack VM생성 테스트 (0) | 2021.06.29 |
---|---|
CentOS7 Terraform install Guide (0) | 2021.06.29 |