|
1 | 1 | // Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved. |
2 | 2 |
|
3 | | -resource "oci_core_boot_volume" "TFBootVolumeFromSourceBootVolume" { |
4 | | - availability_domain = "${oci_core_instance.TFInstance.availability_domain}" |
5 | | - compartment_id = "${oci_core_instance.TFInstance.compartment_id}" |
| 3 | +# This example creates a new boot volume from an existing instance |
| 4 | + |
| 5 | +# This demo connects to the running instance so you will need to supply public/private keys to create an ssh connection. |
| 6 | +# NOTE: do not try to use your api keys, see [this doc](https://docs.us-phoenix-1.oraclecloud.com/Content/Compute/Tasks/managingkeypairs.htm) |
| 7 | +# for more info on configuring keys. |
| 8 | + |
| 9 | +variable "tenancy_ocid" {} |
| 10 | +variable "user_ocid" {} |
| 11 | +variable "fingerprint" {} |
| 12 | +variable "private_key_path" {} |
| 13 | +variable "region" {} |
| 14 | +variable "compartment_ocid" {} |
| 15 | +variable "ssh_public_key" {} |
| 16 | +variable "ssh_private_key" {} |
| 17 | + |
| 18 | +variable "instance_image_ocid" { |
| 19 | + type = "map" |
| 20 | + |
| 21 | + default = { |
| 22 | + # See https://docs.us-phoenix-1.oraclecloud.com/images/ |
| 23 | + # Oracle-provided image "Oracle-Linux-7.5-2018.10.16-0" |
| 24 | + us-phoenix-1 = "ocid1.image.oc1.phx.aaaaaaaaoqj42sokaoh42l76wsyhn3k2beuntrh5maj3gmgmzeyr55zzrwwa" |
| 25 | + |
| 26 | + us-ashburn-1 = "ocid1.image.oc1.iad.aaaaaaaageeenzyuxgia726xur4ztaoxbxyjlxogdhreu3ngfj2gji3bayda" |
| 27 | + eu-frankfurt-1 = "ocid1.image.oc1.eu-frankfurt-1.aaaaaaaaitzn6tdyjer7jl34h2ujz74jwy5nkbukbh55ekp6oyzwrtfa4zma" |
| 28 | + uk-london-1 = "ocid1.image.oc1.uk-london-1.aaaaaaaa32voyikkkzfxyo4xbdmadc2dmvorfxxgdhpnk6dw64fa3l4jh7wa" |
| 29 | + } |
| 30 | +} |
| 31 | + |
| 32 | +provider "oci" { |
| 33 | + tenancy_ocid = "${var.tenancy_ocid}" |
| 34 | + user_ocid = "${var.user_ocid}" |
| 35 | + fingerprint = "${var.fingerprint}" |
| 36 | + private_key_path = "${var.private_key_path}" |
| 37 | + region = "${var.region}" |
| 38 | +} |
| 39 | + |
| 40 | +resource "oci_core_boot_volume" "test_boot_volume_from_source_boot_volume" { |
| 41 | + availability_domain = "${oci_core_instance.test_instance.availability_domain}" |
| 42 | + compartment_id = "${oci_core_instance.test_instance.compartment_id}" |
6 | 43 |
|
7 | 44 | source_details { |
8 | 45 | #Required |
9 | | - id = "${oci_core_instance.TFInstance.boot_volume_id}" |
| 46 | + id = "${oci_core_instance.test_instance.boot_volume_id}" |
10 | 47 | type = "bootVolume" |
11 | 48 | } |
12 | 49 | } |
13 | 50 |
|
14 | | -resource "oci_core_boot_volume_backup" "TFBootVolumeBackupFromSourceBootVolume" { |
| 51 | +resource "oci_core_boot_volume_backup" "test_boot_volume_backup_from_source_boot_volume" { |
15 | 52 | #Required |
16 | | - boot_volume_id = "${oci_core_boot_volume.TFBootVolumeFromSourceBootVolume.id}" |
| 53 | + boot_volume_id = "${oci_core_boot_volume.test_boot_volume_from_source_boot_volume.id}" |
17 | 54 | } |
18 | 55 |
|
19 | | -resource "oci_core_boot_volume" "TFBootVolumeFromSourceBootVolumeBackup" { |
20 | | - availability_domain = "${oci_core_instance.TFInstance.availability_domain}" |
21 | | - compartment_id = "${oci_core_instance.TFInstance.compartment_id}" |
| 56 | +resource "oci_core_boot_volume" "test_boot_volume_from_source_boot_volume_backup" { |
| 57 | + availability_domain = "${oci_core_instance.test_instance.availability_domain}" |
| 58 | + compartment_id = "${oci_core_instance.test_instance.compartment_id}" |
22 | 59 |
|
23 | 60 | source_details { |
24 | 61 | #Required |
25 | | - id = "${oci_core_boot_volume_backup.TFBootVolumeBackupFromSourceBootVolume.id}" |
| 62 | + id = "${oci_core_boot_volume_backup.test_boot_volume_backup_from_source_boot_volume.id}" |
26 | 63 | type = "bootVolumeBackup" |
27 | 64 | } |
28 | 65 | } |
29 | 66 |
|
30 | | -data "oci_core_boot_volume_backups" "TFBootVolumeBackupFromSourceBootVolumeDatasource" { |
31 | | - compartment_id = "${oci_core_instance.TFInstance.compartment_id}" |
| 67 | +resource "oci_core_instance" "test_instance" { |
| 68 | + availability_domain = "${data.oci_identity_availability_domain.ad.name}" |
| 69 | + compartment_id = "${var.compartment_ocid}" |
| 70 | + display_name = "TestInstance" |
| 71 | + shape = "VM.Standard2.1" |
| 72 | + |
| 73 | + create_vnic_details { |
| 74 | + subnet_id = "${oci_core_subnet.test_subnet.id}" |
| 75 | + display_name = "Primaryvnic" |
| 76 | + assign_public_ip = true |
| 77 | + hostname_label = "testinstance" |
| 78 | + } |
| 79 | + |
| 80 | + source_details { |
| 81 | + source_type = "image" |
| 82 | + source_id = "${var.instance_image_ocid[var.region]}" |
| 83 | + } |
| 84 | + |
| 85 | + metadata = { |
| 86 | + ssh_authorized_keys = "${var.ssh_public_key}" |
| 87 | + } |
| 88 | + |
| 89 | + timeouts { |
| 90 | + create = "60m" |
| 91 | + } |
| 92 | +} |
| 93 | + |
| 94 | +resource "oci_core_vcn" "test_vcn" { |
| 95 | + cidr_block = "10.1.0.0/16" |
| 96 | + compartment_id = "${var.compartment_ocid}" |
| 97 | + display_name = "TestVcn" |
| 98 | + dns_label = "testvcn" |
| 99 | +} |
| 100 | + |
| 101 | +resource "oci_core_subnet" "test_subnet" { |
| 102 | + availability_domain = "${data.oci_identity_availability_domain.ad.name}" |
| 103 | + cidr_block = "10.1.20.0/24" |
| 104 | + display_name = "TestSubnet" |
| 105 | + dns_label = "testsubnet" |
| 106 | + security_list_ids = ["${oci_core_vcn.test_vcn.default_security_list_id}"] |
| 107 | + compartment_id = "${var.compartment_ocid}" |
| 108 | + vcn_id = "${oci_core_vcn.test_vcn.id}" |
| 109 | + route_table_id = "${oci_core_vcn.test_vcn.default_route_table_id}" |
| 110 | + dhcp_options_id = "${oci_core_vcn.test_vcn.default_dhcp_options_id}" |
| 111 | +} |
| 112 | + |
| 113 | +data "oci_identity_availability_domain" "ad" { |
| 114 | + compartment_id = "${var.tenancy_ocid}" |
| 115 | + ad_number = 1 |
| 116 | +} |
| 117 | + |
| 118 | +data "oci_core_boot_volume_backups" "test_boot_volume_backup_from_source_boot_volume_datasource" { |
| 119 | + compartment_id = "${oci_core_instance.test_instance.compartment_id}" |
32 | 120 |
|
33 | 121 | filter { |
34 | 122 | name = "id" |
35 | | - values = ["${oci_core_boot_volume_backup.TFBootVolumeBackupFromSourceBootVolume.id}"] |
| 123 | + values = ["${oci_core_boot_volume_backup.test_boot_volume_backup_from_source_boot_volume.id}"] |
36 | 124 | } |
37 | 125 | } |
38 | 126 |
|
39 | | -data "oci_core_boot_volumes" "TFBootVolumeFromSourceBootVolumeDatasource" { |
| 127 | +data "oci_core_boot_volumes" "test_boot_volume_from_source_boot_volume_datasource" { |
40 | 128 | #Required |
41 | | - availability_domain = "${oci_core_boot_volume.TFBootVolumeFromSourceBootVolume.availability_domain}" |
42 | | - compartment_id = "${oci_core_boot_volume.TFBootVolumeFromSourceBootVolume.compartment_id}" |
| 129 | + availability_domain = "${oci_core_boot_volume.test_boot_volume_from_source_boot_volume.availability_domain}" |
| 130 | + compartment_id = "${oci_core_boot_volume.test_boot_volume_from_source_boot_volume.compartment_id}" |
43 | 131 |
|
44 | 132 | filter { |
45 | 133 | name = "id" |
46 | | - values = ["${oci_core_boot_volume.TFBootVolumeFromSourceBootVolume.id}"] |
| 134 | + values = ["${oci_core_boot_volume.test_boot_volume_from_source_boot_volume.id}"] |
47 | 135 | } |
48 | 136 | } |
49 | 137 |
|
50 | | -data "oci_core_boot_volumes" "TFBootVolumeFromSourceBootVolumeBackupDatasource" { |
| 138 | +data "oci_core_boot_volumes" "test_boot_volume_from_source_boot_volume_backup_datasource" { |
51 | 139 | #Required |
52 | | - availability_domain = "${oci_core_boot_volume.TFBootVolumeFromSourceBootVolumeBackup.availability_domain}" |
53 | | - compartment_id = "${oci_core_boot_volume.TFBootVolumeFromSourceBootVolumeBackup.compartment_id}" |
| 140 | + availability_domain = "${oci_core_boot_volume.test_boot_volume_from_source_boot_volume_backup.availability_domain}" |
| 141 | + compartment_id = "${oci_core_boot_volume.test_boot_volume_from_source_boot_volume_backup.compartment_id}" |
54 | 142 |
|
55 | 143 | filter { |
56 | 144 | name = "id" |
57 | | - values = ["${oci_core_boot_volume.TFBootVolumeFromSourceBootVolumeBackup.id}"] |
| 145 | + values = ["${oci_core_boot_volume.test_boot_volume_from_source_boot_volume_backup.id}"] |
| 146 | + } |
| 147 | +} |
| 148 | + |
| 149 | +output "boot_volume_from_instance_outputs" { |
| 150 | + value = { |
| 151 | + boot_volume_from_instance = "${oci_core_instance.test_instance.boot_volume_id}" |
| 152 | + boot_volume_from_source_boot_volume_id = "${oci_core_boot_volume.test_boot_volume_from_source_boot_volume.id}" |
| 153 | + boot_volume_backup_from_source_boot_volume_id = "${oci_core_boot_volume_backup.test_boot_volume_backup_from_source_boot_volume.id}" |
| 154 | + boot_volume_from_source_boot_volume_backup_id = "${oci_core_boot_volume.test_boot_volume_from_source_boot_volume_backup.id}" |
| 155 | + boot_volume_from_source_boot_volume_datasource = "${data.oci_core_boot_volumes.test_boot_volume_from_source_boot_volume_datasource.boot_volumes}" |
| 156 | + boot_volume_backup_from_source_boot_volume_datasource = "${data.oci_core_boot_volume_backups.test_boot_volume_backup_from_source_boot_volume_datasource.boot_volume_backups}" |
| 157 | + boot_volume_from_source_boot_volume_backup_datasource = "${data.oci_core_boot_volumes.test_boot_volume_from_source_boot_volume_backup_datasource.boot_volumes}" |
58 | 158 | } |
59 | 159 | } |
0 commit comments