Skip to content

Commit 7468da4

Browse files
Terraform Team AutomationNishtha Goel
authored andcommitted
Added - Support for Launch w/Multiple Attachments Support for VMs - Phase 1 for Goldman Sachs
1 parent be4c2a9 commit 7468da4

File tree

4 files changed

+799
-4
lines changed

4 files changed

+799
-4
lines changed
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
// Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
2+
// Licensed under the Mozilla Public License v2.0
3+
4+
variable "vm_multi_attach_instance_shape" {
5+
default = "VM.Standard2.1"
6+
}
7+
8+
resource "oci_core_volume" "test_block_volume_multi_attach" {
9+
availability_domain = data.oci_identity_availability_domain.ad.name
10+
compartment_id = var.compartment_ocid
11+
display_name = "test_attach_existing_volume_on_instance_launch_1"
12+
size_in_gbs = var.db_size
13+
}
14+
15+
resource "oci_core_instance" "test_vm_multi_attach_instance_launch" {
16+
availability_domain = data.oci_identity_availability_domain.ad.name
17+
compartment_id = var.compartment_ocid
18+
display_name = "test_vm_multi_attach_instance"
19+
shape = var.vm_multi_attach_instance_shape
20+
21+
create_vnic_details {
22+
subnet_id = oci_core_subnet.test_subnet.id
23+
display_name = "primary_vnic"
24+
assign_public_ip = true
25+
hostname_label = "tfexampleshinstance"
26+
}
27+
28+
source_details {
29+
source_type = "image"
30+
source_id = var.instance_image_ocid[var.region]
31+
# Apply this to set the size of the boot volume that is created for this instance.
32+
# Otherwise, the default boot volume size of the image is used.
33+
# This should only be specified when source_type is set to "image".
34+
#boot_volume_size_in_gbs = "60"
35+
kms_key_id = var.kms_key_ocid
36+
}
37+
38+
// Create and attach a volume
39+
launch_volume_attachments {
40+
type = "iscsi"
41+
display_name = "test_create_and_attach_volume_on_launch_1"
42+
launch_create_volume_details {
43+
volume_creation_type = "ATTRIBUTES"
44+
compartment_id = var.compartment_ocid
45+
display_name = "test_create_and_attach_volume_on_launch_1"
46+
size_in_gbs = var.db_size
47+
}
48+
}
49+
50+
// Create and attach a volume
51+
launch_volume_attachments {
52+
type = "iscsi"
53+
display_name = "test_create_and_attach_volume_on_launch_2"
54+
launch_create_volume_details {
55+
volume_creation_type = "ATTRIBUTES"
56+
compartment_id = var.compartment_ocid
57+
display_name = "test_create_and_attach_volume_on_launch_2"
58+
size_in_gbs = var.db_size
59+
}
60+
}
61+
62+
// Attach an existing volume
63+
launch_volume_attachments {
64+
type = "iscsi"
65+
display_name = "test_attach_existing_volume_on_launch"
66+
volume_id = oci_core_volume.test_block_volume_multi_attach.id
67+
}
68+
69+
# Apply the following flag only if you wish to preserve the attached boot volume upon destroying this instance
70+
# Setting this and destroying the instance will result in a boot volume that should be managed outside of this config.
71+
# When changing this value, make sure to run 'terraform apply' so that it takes effect before the resource is destroyed.
72+
#preserve_boot_volume = true
73+
74+
// Since preserve_data_volumes_created_at_launch is a required parameter for instances launched with volumes,
75+
// defaulting it to false.
76+
preserve_data_volumes_created_at_launch = false
77+
78+
metadata = {
79+
ssh_authorized_keys = var.ssh_public_key
80+
user_data = base64encode(file("./userdata/bootstrap"))
81+
}
82+
defined_tags = {
83+
"${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag2.name}" = "awesome-app-server"
84+
}
85+
86+
freeform_tags = {
87+
"freeformkey" = "freeformvalue"
88+
}
89+
timeouts {
90+
create = "60m"
91+
}
92+
}

0 commit comments

Comments
 (0)