|
| 1 | +variable "tenancy_ocid" {} |
| 2 | +variable "user_ocid" {} |
| 3 | +variable "fingerprint" {} |
| 4 | +variable "private_key_path" {} |
| 5 | +variable "compartment_ocid" {} |
| 6 | +variable "region" {} |
| 7 | +variable "ssh_public_key" {} |
| 8 | + |
| 9 | +variable "SecondaryVnicCount" { |
| 10 | + default = 2 |
| 11 | +} |
| 12 | + |
| 13 | +# Choose an Availability Domain |
| 14 | +variable "AD" { |
| 15 | + default = "1" |
| 16 | +} |
| 17 | + |
| 18 | +variable "InstanceShape" { |
| 19 | + default = "VM.Standard1.8" |
| 20 | +} |
| 21 | + |
| 22 | +variable "InstanceOS" { |
| 23 | + default = "Oracle Linux" |
| 24 | +} |
| 25 | + |
| 26 | +variable "InstanceOSVersion" { |
| 27 | + default = "7.3" |
| 28 | +} |
| 29 | + |
| 30 | +provider "baremetal" { |
| 31 | + tenancy_ocid = "${var.tenancy_ocid}" |
| 32 | + user_ocid = "${var.user_ocid}" |
| 33 | + fingerprint = "${var.fingerprint}" |
| 34 | + private_key_path = "${var.private_key_path}" |
| 35 | + region = "${var.region}" |
| 36 | +} |
| 37 | + |
| 38 | +data "baremetal_identity_availability_domains" "ADs" { |
| 39 | + compartment_id = "${var.tenancy_ocid}" |
| 40 | +} |
| 41 | + |
| 42 | +resource "baremetal_core_virtual_network" "ExampleVCN" { |
| 43 | + cidr_block = "10.0.0.0/16" |
| 44 | + compartment_id = "${var.compartment_ocid}" |
| 45 | + display_name = "CompleteVCN" |
| 46 | + dns_label = "examplevcn" |
| 47 | +} |
| 48 | + |
| 49 | +resource "baremetal_core_subnet" "ExampleSubnet" { |
| 50 | + availability_domain = "${lookup(data.baremetal_identity_availability_domains.ADs.availability_domains[var.AD - 1],"name")}" |
| 51 | + cidr_block = "10.0.1.0/24" |
| 52 | + display_name = "ExampleSubnet" |
| 53 | + compartment_id = "${var.compartment_ocid}" |
| 54 | + vcn_id = "${baremetal_core_virtual_network.ExampleVCN.id}" |
| 55 | + route_table_id = "${baremetal_core_virtual_network.ExampleVCN.default_route_table_id}" |
| 56 | + security_list_ids = ["${baremetal_core_virtual_network.ExampleVCN.default_security_list_id}"] |
| 57 | + dhcp_options_id = "${baremetal_core_virtual_network.ExampleVCN.default_dhcp_options_id}" |
| 58 | + dns_label = "examplesubnet" |
| 59 | +} |
| 60 | + |
| 61 | +# Gets the OCID of the OS image to use |
| 62 | +data "baremetal_core_images" "OLImageOCID" { |
| 63 | + compartment_id = "${var.compartment_ocid}" |
| 64 | + operating_system = "${var.InstanceOS}" |
| 65 | + operating_system_version = "${var.InstanceOSVersion}" |
| 66 | +} |
| 67 | + |
| 68 | +resource "baremetal_core_instance" "ExampleInstance" { |
| 69 | + availability_domain = "${lookup(data.baremetal_identity_availability_domains.ADs.availability_domains[var.AD - 1],"name")}" |
| 70 | + compartment_id = "${var.compartment_ocid}" |
| 71 | + display_name = "ExampleInstance" |
| 72 | + image = "${lookup(data.baremetal_core_images.OLImageOCID.images[0], "id")}" |
| 73 | + shape = "${var.InstanceShape}" |
| 74 | + subnet_id = "${baremetal_core_subnet.ExampleSubnet.id}" |
| 75 | + create_vnic_details { |
| 76 | + subnet_id = "${baremetal_core_subnet.ExampleSubnet.id}" |
| 77 | + hostname_label = "exampleinstance" |
| 78 | + } |
| 79 | + metadata { |
| 80 | + ssh_authorized_keys = "${var.ssh_public_key}" |
| 81 | + } |
| 82 | + |
| 83 | + timeouts { |
| 84 | + create = "60m" |
| 85 | + } |
| 86 | +} |
| 87 | + |
| 88 | +resource "baremetal_core_vnic_attachment" "SecondaryVnicAttachment" { |
| 89 | + instance_id = "${baremetal_core_instance.ExampleInstance.id}" |
| 90 | + display_name = "SecondaryVnicAttachment_${count.index}" |
| 91 | + create_vnic_details { |
| 92 | + subnet_id = "${baremetal_core_subnet.ExampleSubnet.id}" |
| 93 | + display_name = "SecondaryVnic_${count.index}" |
| 94 | + assign_public_ip = true |
| 95 | + } |
| 96 | + count = "${var.SecondaryVnicCount}" |
| 97 | +} |
| 98 | + |
| 99 | +data "baremetal_core_vnic" "SecondaryVnic" { |
| 100 | + count = "${var.SecondaryVnicCount}" |
| 101 | + vnic_id = "${element(baremetal_core_vnic_attachment.SecondaryVnicAttachment.*.vnic_id, count.index)}" |
| 102 | +} |
| 103 | + |
| 104 | +output "PrimaryIPAddresses" { |
| 105 | + value = ["${baremetal_core_instance.ExampleInstance.public_ip}", |
| 106 | + "${baremetal_core_instance.ExampleInstance.private_ip}"] |
| 107 | +} |
| 108 | + |
| 109 | +output "SecondaryPublicIPAddresses" { |
| 110 | + value = ["${data.baremetal_core_vnic.SecondaryVnic.*.public_ip_address}"] |
| 111 | +} |
| 112 | + |
| 113 | +output "SecondaryPrivateIPAddresses" { |
| 114 | + value = ["${data.baremetal_core_vnic.SecondaryVnic.*.private_ip_address}"] |
| 115 | +} |
0 commit comments