Skip to content

Commit 88d8588

Browse files
alexng-canuckrcohenma
authored andcommitted
Add preserve boot volume and source details options to Instance resource
Addresses github issues #457 and #488
1 parent c0cfa28 commit 88d8588

File tree

7 files changed

+505
-41
lines changed

7 files changed

+505
-41
lines changed

crud/helpers.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,11 @@ func FieldDeprecatedForAnother(deprecatedFieldName string, newFieldName string)
382382
return fmt.Sprintf("The '%s' field has been deprecated. Please use '%s' instead.", deprecatedFieldName, newFieldName)
383383
}
384384

385+
func FieldDeprecatedAndOverridenByAnother(deprecatedFieldName string, newFieldName string) string {
386+
return fmt.Sprintf("%s If both fields are specified, then '%s' will be used.",
387+
FieldDeprecatedForAnother(deprecatedFieldName, newFieldName), newFieldName)
388+
}
389+
385390
// GenerateDataSourceID generates an ID for the data source based on the current time stamp.
386391
func GenerateDataSourceID() string {
387392
// Important, if you don't have an ID, make one up for your datasource

docs/core/instances.md

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,22 @@
77
The following attributes are exported:
88

99
* `availability_domain` - The Availability Domain the instance is running in. Example: `Uocm:PHX-AD-1`
10+
* `boot_volume_id` - The OCID of the attached boot volume. If the `source_type` is `bootVolume`, this will be the same OCID as the `source_id`.
1011
* `compartment_id` - The OCID of the compartment that contains the instance.
1112
* `display_name` - A user-friendly name. Does not have to be unique, and it's changeable. Avoid entering confidential information. Example: `My bare metal instance`
1213
* `extended_metadata` - Additional metadata key/value pairs that you provide. They serve a similar purpose and functionality from fields in the 'metadata' object. They are distinguished from 'metadata' fields in that these can be nested JSON objects (whereas 'metadata' fields are string/string maps only). If you don't need nested metadata values, it is strongly advised to avoid using this object and use the Metadata object instead.
1314
* `id` - The OCID of the instance.
14-
* `image` - The OCID of the image used to boot the instance.
15+
* `image` - Deprecated. Use `sourceDetails` instead.
1516
* `ipxe_script` - When a bare metal or virtual machine instance boots, the iPXE firmware that runs on the instance is configured to run an iPXE script to continue the boot process. If you want more control over the boot process, you can provide your own custom iPXE script that will run when the instance boots; however, you should be aware that the same iPXE script will run every time an instance boots; not only after the initial LaunchInstance call. The default iPXE script connects to the instance's local boot volume over iSCSI and performs a network boot. If you use a custom iPXE script and want to network-boot from the instance's local boot volume over iSCSI the same way as the default iPXE script, you should use the following iSCSI IP address: 169.254.0.2, and boot volume IQN: iqn.2015-02.oracle.boot. For more information about the Bring Your Own Image feature of Oracle Cloud Infrastructure, see [Bring Your Own Image](https://docs.us-phoenix-1.oraclecloud.com/Content/Compute/References/bringyourownimage.htm). For more information about iPXE, see http://ipxe.org.
1617
* `metadata` - Custom metadata that you provide.
18+
* `preserve_boot_volume` - Specifies whether to delete or preserve the boot volume when terminating an instance. The default value is false. Note: This value only applies to destroy operations initiated by Terraform.
1719
* `private_ip` - The private IP address of instance VNIC. To set the private IP address, use the `private_ip` argument in create_vnic_details.
1820
* `public_ip` - The public IP address of instance VNIC (if enabled).
1921
* `region` - The region that contains the Availability Domain the instance is running in. Example: `phx`
20-
* `shape` - The shape of the instance. The shape determines the number of CPUs and the amount of memory allocated to the instance. You can enumerate all available shapes by calling [ListShapes](https://docs.us-phoenix-1.oraclecloud.com/api/#/en/iaas/20160918/Shape/ListShapes).
22+
* `shape` - The shape of the instance. The shape determines the number of CPUs and the amount of memory allocated to the instance. You can enumerate all available shapes by calling [ListShapes](https://docs.us-phoenix-1.oraclecloud.com/api/#/en/iaas/20160918/Shape/ListShapes).
23+
* `source_details` - Details for creating an instance
24+
* `source_id` - The OCID of an image or a boot volume to use, depending on the value of `source_type`.
25+
* `source_type` - The source type for the instance. Use `image` when specifying the image OCID. Use `bootVolume` when specifying the boot volume OCID.
2126
* `state` - The current state of the instance.
2227
* `time_created` - The date and time the instance was created, in the format defined by RFC3339. Example: `2016-08-25T21:10:29.600Z`
2328

@@ -69,10 +74,14 @@ The following arguments are supported:
6974
* `display_name` - (Optional) A user-friendly name. Does not have to be unique, and it's changeable. Avoid entering confidential information. Example: `My bare metal instance`
7075
* `extended_metadata` - (Optional) Additional metadata key/value pairs that you provide. They serve a similar purpose and functionality from fields in the 'metadata' object. They are distinguished from 'metadata' fields in that these can be nested JSON objects (whereas 'metadata' fields are string/string maps only). If you don't need nested metadata values, it is strongly advised to avoid using this object and use the Metadata object instead. Input in terraform is the same as metadata but allows nested metadata if you pass a valid JSON string as a value. See the example below.
7176
* `hostname_label` - (Optional) Deprecated. Instead Use `hostnameLabel` in [CreateVnicDetails](https://docs.us-phoenix-1.oraclecloud.com/api/#/en/iaas/20160918/CreateVnicDetails/). If you provide both, the values must match.
72-
* `image` - (Required) The OCID of the image used to boot the instance.
77+
* `image` - (Optional) Deprecated. Use `sourceDetails` with [InstanceSourceViaImageDetails](https://docs.us-phoenix-1.oraclecloud.com/api/#/en/iaas/latest/requests/InstanceSourceViaImageDetails) source type instead. If you specify values for both, the values must match.
7378
* `ipxe_script` - (Optional) This is an advanced option. When a bare metal or virtual machine instance boots, the iPXE firmware that runs on the instance is configured to run an iPXE script to continue the boot process. If you want more control over the boot process, you can provide your own custom iPXE script that will run when the instance boots; however, you should be aware that the same iPXE script will run every time an instance boots; not only after the initial LaunchInstance call. The default iPXE script connects to the instance's local boot volume over iSCSI and performs a network boot. If you use a custom iPXE script and want to network-boot from the instance's local boot volume over iSCSI the same way as the default iPXE script, you should use the following iSCSI IP address: 169.254.0.2, and boot volume IQN: iqn.2015-02.oracle.boot. For more information about the Bring Your Own Image feature of Oracle Cloud Infrastructure, see [Bring Your Own Image](https://docs.us-phoenix-1.oraclecloud.com/Content/Compute/References/bringyourownimage.htm). For more information about iPXE, see http://ipxe.org.
7479
* `metadata` - (Optional) Custom metadata key/value pairs that you provide, such as the SSH public key required to connect to the instance. A metadata service runs on every launched instance. The service is an HTTP endpoint listening on 169.254.169.254. You can use the service to: * Provide information to [Cloud-Init](https://cloudinit.readthedocs.org/en/latest/) to be used for various system initialization tasks. * Get information about the instance, including the custom metadata that you provide when you launch the instance. **Providing Cloud-Init Metadata** You can use the following metadata key names to provide information to Cloud-Init: **"ssh_authorized_keys"** - Provide one or more public SSH keys to be included in the `~/.ssh/authorized_keys` file for the default user on the instance. Use a newline character to separate multiple keys. The SSH keys must be in the format necessary for the `authorized_keys` file, as shown in the example below. **"user_data"** - Provide your own base64-encoded data to be used by Cloud-Init to run custom scripts or provide custom Cloud-Init configuration. For information about how to take advantage of user data, see the [Cloud-Init Documentation](http://cloudinit.readthedocs.org/en/latest/topics/format.html). On Windows instances, user_data isn't used. **Note:** Cloud-Init does not pull this data from the `http://169.254.169.254/opc/v1/instance/metadata/` path. When the instance launches and either of these keys are provided, the key values are formatted as OpenStack metadata and copied to the following locations, which are recognized by Cloud-Init: `http://169.254.169.254/openstack/latest/meta_data.json` - This JSON blob contains, among other things, the SSH keys that you provided for **"ssh_authorized_keys"**. `http://169.254.169.254/openstack/latest/user_data` - Contains the base64-decoded data that you provided for **"user_data"**. **Metadata Example** "metadata" : { "quake_bot_level" : "Severe", "ssh_authorized_keys" : "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQCZ06fccNTQfq+xubFlJ5ZR3kt+uzspdH9tXL+lAejSM1NXM+CFZev7MIxfEjas06y80ZBZ7DUTQO0GxJPeD8NCOb1VorF8M4xuLwrmzRtkoZzU16umt4y1W0Q4ifdp3IiiU0U8/WxczSXcUVZOLqkz5dc6oMHdMVpkimietWzGZ4LBBsH/LjEVY7E0V+a0sNchlVDIZcm7ErReBLcdTGDq0uLBiuChyl6RUkX1PNhusquTGwK7zc8OBXkRuubn5UKXhI3Ul9Nyk4XESkVWIGNKmw8mSpoJSjR8P9ZjRmcZVo8S+x4KVPMZKQEor== [email protected] ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAQEAzJSAtwEPoB3Jmr58IXrDGzLuDYkWAYg8AsLYlo6JZvKpjY1xednIcfEVQJm4T2DhVmdWhRrwQ8DmayVZvBkLt+zs2LdoAJEVimKwXcJFD/7wtH8Lnk17HiglbbbNXsemjDY0hea4JUE5CfvkIdZBITuMrfqSmA4n3VNoorXYdvtTMoGG8fxMub46RPtuxtqi9bG9Zqenordkg5FJt2mVNfQRqf83CWojcOkklUWq4CjyxaeLf5i9gv1fRoBo4QhiA8I6NCSppO8GnoV/6Ox6TNoh9BiifqGKC9VGYuC89RvUajRBTZSK2TK4DPfaT+2R+slPsFrwiT/oPEhhEK1S5Q== rsa-key-20160227", "user_data" : "SWYgeW91IGNhbiBzZWUgdGhpcywgdGhlbiBpdCB3b3JrZWQgbWF5YmUuCg==" } **Getting Metadata on the Instance** To get information about your instance, connect to the instance using SSH and issue any of the following GET requests: curl http://169.254.169.254/opc/v1/instance/ curl http://169.254.169.254/opc/v1/instance/metadata/ curl http://169.254.169.254/opc/v1/instance/metadata/<any-key-name> You'll get back a response that includes all the instance information; only the metadata information; or the metadata information for the specified key name, respectively.
75-
* `shape` - (Required) The shape of an instance. The shape determines the number of CPUs, amount of memory, and other resources allocated to the instance. You can enumerate all available shapes by calling [ListShapes](https://docs.us-phoenix-1.oraclecloud.com/api/#/en/iaas/20160918/Shape/ListShapes).
80+
* `preserve_boot_volume` - (Optional) Specifies whether to delete or preserve the boot volume when terminating an instance. The default value is false. Note: This value only applies to destroy operations initiated by Terraform.
81+
* `shape` - (Required) The shape of an instance. The shape determines the number of CPUs, amount of memory, and other resources allocated to the instance. You can enumerate all available shapes by calling [ListShapes](https://docs.us-phoenix-1.oraclecloud.com/api/#/en/iaas/20160918/Shape/ListShapes).
82+
* `source_details` - (Optional) Details for creating an instance
83+
* `source_id` - (Required) The OCID of an image or a boot volume to use, depending on the value of `source_type`.
84+
* `source_type` - (Required) The source type for the instance. Use `image` when specifying the image OCID. Use `bootVolume` when specifying the boot volume OCID.
7685
* `subnet_id` - (Optional) Deprecated. Instead use `subnetId` in [CreateVnicDetails](https://docs.us-phoenix-1.oraclecloud.com/api/#/en/iaas/20160918/CreateVnicDetails/). At least one of them is required; if you provide both, the values must match.
7786

7887

@@ -86,7 +95,9 @@ The following arguments support updates:
8695
* `create_vnic_details` - (Optional) Details for the primary VNIC, which is automatically created and attached when the instance is launched.
8796
* `display_name` - (Optional) A user-friendly name for the VNIC. Does not have to be unique. Avoid entering confidential information.
8897
* `hostname_label` - (Optional) The hostname for the VNIC's primary private IP. Used for DNS. The value is the hostname portion of the primary private IP's fully qualified domain name (FQDN) (for example, `bminstance-1` in FQDN `bminstance-1.subnet123.vcn1.oraclevcn.com`). Must be unique across all VNICs in the subnet and comply with [RFC 952](https://tools.ietf.org/html/rfc952) and [RFC 1123](https://tools.ietf.org/html/rfc1123). The value appears in the [Vnic](https://docs.us-phoenix-1.oraclecloud.com/api/#/en/iaas/20160918/Vnic/) object and also the [PrivateIp](https://docs.us-phoenix-1.oraclecloud.com/api/#/en/iaas/20160918/PrivateIp/) object returned by [ListPrivateIps](https://docs.us-phoenix-1.oraclecloud.com/api/#/en/iaas/20160918/PrivateIp/ListPrivateIps) and [GetPrivateIp](https://docs.us-phoenix-1.oraclecloud.com/api/#/en/iaas/20160918/PrivateIp/GetPrivateIp). For more information, see [DNS in Your Virtual Cloud Network](https://docs.us-phoenix-1.oraclecloud.com/Content/Network/Concepts/dns.htm). When launching an instance, use this `hostnameLabel` instead of the deprecated `hostnameLabel` in [LaunchInstanceDetails](https://docs.us-phoenix-1.oraclecloud.com/api/#/en/iaas/20160918/requests/LaunchInstanceDetails). If you provide both, the values must match. Example: `bminstance-1`
89-
* `skip_source_dest_check` - (Optional) Whether the source/destination check is disabled on the VNIC. Defaults to `false`, which means the check is performed. For information about why you would skip the source/destination check, see [Using a Private IP as a Route Target](https://docs.us-phoenix-1.oraclecloud.com/Content/Network/Tasks/managingroutetables.htm#privateip). Example: `true`
98+
* `skip_source_dest_check` - (Optional) Whether the source/destination check is disabled on the VNIC. Defaults to `false`, which means the check is performed. For information about why you would skip the source/destination check, see [Using a Private IP as a Route Target](https://docs.us-phoenix-1.oraclecloud.com/Content/Network/Tasks/managingroutetables.htm#privateip). Example: `true`
99+
* `preserve_boot_volume` - (Optional) Specifies whether to delete or preserve the boot volume when terminating an instance. The default value is false. Note: This value only applies to destroy operations initiated by Terraform.
100+
* When updating this value, please run `terraform apply` so that it takes effect before running `terraform destroy`
90101

91102
** IMPORTANT **
92103
Any change to a property that does not support update will force the destruction and recreation of the resource with the new property values
@@ -98,7 +109,6 @@ resource "oci_core_instance" "test_instance" {
98109
#Required
99110
availability_domain = "${var.instance_availability_domain}"
100111
compartment_id = "${var.compartment_id}"
101-
image = "${oci_core_image.test_image.id}"
102112
shape = "${var.instance_shape}"
103113
104114
#Optional
@@ -124,7 +134,11 @@ resource "oci_core_instance" "test_instance" {
124134
ssh_authorized_keys = "${var.ssh_public_key}"
125135
user_data = "${base64encode(file(var.custom_bootstrap_file_name))}"
126136
}
127-
subnet_id = "${oci_core_subnet.test_subnet.id}"
137+
source_details {
138+
source_type = "image"
139+
source_id = "${oci_core_image.test_image.id}"
140+
}
141+
preserve_boot_volume = false
128142
}
129143
```
130144

docs/examples/compute/instance/compute.tf

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ resource "oci_core_instance" "TFInstance" {
33
availability_domain = "${lookup(data.oci_identity_availability_domains.ADs.availability_domains[var.AD - 1],"name")}"
44
compartment_id = "${var.compartment_ocid}"
55
display_name = "TFInstance${count.index}"
6-
image = "${var.InstanceImageOCID[var.region]}"
76
shape = "${var.InstanceShape}"
87

98
create_vnic_details {
@@ -13,6 +12,16 @@ resource "oci_core_instance" "TFInstance" {
1312
hostname_label = "tfexampleinstance${count.index}"
1413
},
1514

15+
source_details {
16+
source_type = "image"
17+
source_id = "${var.InstanceImageOCID[var.region]}"
18+
}
19+
20+
# Apply the following flag only if you wish to preserve the attached boot volume upon destroying this instance
21+
# Setting this and destroying the instance will result in a boot volume that should be managed outside of this config.
22+
# When changing this value, make sure to run 'terraform apply' so that it takes effect before the resource is destroyed.
23+
#preserve_boot_volume = true
24+
1625
metadata {
1726
ssh_authorized_keys = "${var.ssh_public_key}"
1827
user_data = "${base64encode(file(var.BootStrapFile))}"

docs/examples/compute/instance/outputs.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,8 @@ value = ["${oci_core_instance.TFInstance.*.private_ip}"]
66
output "InstancePublicIPs" {
77
value = ["${oci_core_instance.TFInstance.*.public_ip}"]
88
}
9+
10+
# Output the boot volume IDs of the instance
11+
output "BootVolumeIDs" {
12+
value = ["${oci_core_instance.TFInstance.*.boot_volume_id}"]
13+
}

0 commit comments

Comments
 (0)