|
1 | | -// Copyright (c) 2021, 2022, Oracle and/or its affiliates. |
2 | | - |
3 | | -############################# |
4 | | -## Data Block - Instance |
5 | | -## Create Instance and Boot Volume Backup Policy |
6 | | -############################# |
7 | | - |
8 | | -locals { |
9 | | - nsg_ids = var.nsg_ids != null ? flatten(tolist([for nsg in var.nsg_ids : (length(regexall("ocid1.networksecuritygroup.oc1*", nsg)) > 0 ? [nsg] : data.oci_core_network_security_groups.network_security_groups[nsg].network_security_groups[*].id)])) : null |
10 | | - |
11 | | - ADs = [ |
12 | | - for ad in data.oci_identity_availability_domains.ads.availability_domains : ad.name |
13 | | - ] |
14 | | - |
15 | | - shapes_config = { |
16 | | - for shape in data.oci_core_shapes.present_ad.shapes : shape.name => { |
17 | | - memory_in_gbs = shape.memory_in_gbs |
18 | | - ocpus = shape.ocpus |
19 | | - } |
20 | | - } |
21 | | - |
22 | | - platform_configs = { |
23 | | - for shape in data.oci_core_shapes.present_ad.shapes : shape.name => { |
24 | | - config_type = element(flatten(shape.platform_config_options[*].type),0) |
25 | | - } if shape.name == var.shape |
26 | | - } |
27 | | - |
28 | | - plugins_config = var.plugins_details != null ? var.plugins_details : {} |
29 | | - remote_execute_script = var.remote_execute == null ? "SCRIPT-NOT-SET" : var.remote_execute |
30 | | - cloud_init_script = var.cloud_init_script == null ? "SCRIPT-NOT-SET" : var.cloud_init_script |
31 | | -} |
32 | | - |
33 | | -data "oci_identity_availability_domains" "ads" { |
34 | | - compartment_id = var.compartment_id |
35 | | -} |
36 | | - |
37 | | -data "oci_core_shapes" "present_ad" { |
38 | | - compartment_id = var.compartment_id |
39 | | - availability_domain = var.availability_domain == "" || var.availability_domain == null ? element(local.ADs, 0) : var.availability_domain |
40 | | -} |
41 | | - |
42 | | -data "oci_core_vcns" "oci_vcns_instances" { |
43 | | - for_each = { for vcn in var.vcn_names : vcn => vcn } |
44 | | - compartment_id = var.network_compartment_id != null ? var.network_compartment_id : var.compartment_id |
45 | | - display_name = each.value |
46 | | -} |
47 | | -// |
48 | | -//data "oci_core_subnets" "oci_subnets_instances" { |
49 | | -// compartment_id = var.network_compartment_id != null ? var.network_compartment_id : var.compartment_id |
50 | | -// display_name = var.subnet_id |
51 | | -// vcn_id = data.oci_core_vcns.oci_vcns_instances[var.vcn_names[0]].virtual_networks.*.id[0] |
52 | | -//} |
53 | | - |
54 | | -data "oci_core_dedicated_vm_hosts" "existing_vm_host" { |
55 | | - count = var.dedicated_vm_host_name != null ? 1 : 0 |
56 | | - compartment_id = var.compartment_id |
57 | | - display_name = var.dedicated_vm_host_name |
58 | | - state = "ACTIVE" |
59 | | -} |
60 | | - |
61 | | -data "oci_core_network_security_groups" "network_security_groups" { |
62 | | - for_each = var.nsg_ids != null ? { for nsg in var.nsg_ids : nsg => nsg } : {} |
63 | | - compartment_id = var.network_compartment_id != null ? var.network_compartment_id : var.compartment_id |
64 | | - display_name = each.value |
65 | | - vcn_id = data.oci_core_vcns.oci_vcns_instances[var.vcn_names[0]].virtual_networks.*.id[0] |
66 | | -} |
67 | | - |
68 | | -#data "oci_core_boot_volumes" "all_boot_volumes" { |
69 | | -# depends_on = [oci_core_instance.instance] |
70 | | -# count = var.boot_tf_policy != null ? 1 : 0 |
71 | | -# #Required |
72 | | -# compartment_id = var.compartment_id |
73 | | -# availability_domain = var.availability_domain |
74 | | -# filter { |
75 | | -# name = "display_name" |
76 | | -# values = [join(" ", [var.display_name, "(Boot Volume)"])] |
77 | | -# } |
78 | | -# filter { |
79 | | -# name = "state" |
80 | | -# values = ["AVAILABLE"] |
81 | | -# } |
82 | | -#} |
83 | | - |
84 | | -data "oci_core_volume_backup_policies" "boot_vol_backup_policy" { |
85 | | - count = var.boot_tf_policy != null ? 1 : 0 |
86 | | - |
87 | | - filter { |
88 | | - name = "display_name" |
89 | | - values = [lower(var.boot_tf_policy)] |
90 | | - } |
91 | | -} |
92 | | - |
93 | | -data "oci_core_volume_backup_policies" "boot_vol_custom_policy" { |
94 | | - count = var.boot_tf_policy != null ? 1 : 0 |
95 | | - compartment_id = local.policy_tf_compartment_id |
96 | | - filter { |
97 | | - name = "display_name" |
98 | | - values = [var.boot_tf_policy] |
99 | | - } |
100 | | -} |
101 | | - |
102 | | -################################ |
103 | | -# Data Block - Instances |
104 | | -# Market Place Images |
105 | | -################################ |
106 | | - |
107 | | -data "oci_marketplace_listing_package_agreements" "listing_package_agreements" { |
108 | | - count = length(regexall("ocid1.image.oc1*", var.source_image_id)) > 0 || length(regexall("ocid1.bootvolume.oc1*", var.source_image_id)) > 0 || var.source_image_id == null ? 0 : 1 |
109 | | - #Required |
110 | | - listing_id = data.oci_marketplace_listing.listing.0.id |
111 | | - package_version = data.oci_marketplace_listing.listing.0.default_package_version |
112 | | - |
113 | | - #Optional |
114 | | - compartment_id = var.compartment_id |
115 | | -} |
116 | | - |
117 | | -data "oci_marketplace_listing_package" "listing_package" { |
118 | | - count = length(regexall("ocid1.image.oc1*", var.source_image_id)) > 0 || length(regexall("ocid1.bootvolume.oc1*", var.source_image_id)) > 0 || var.source_image_id == null ? 0 : 1 |
119 | | - #Required |
120 | | - listing_id = data.oci_marketplace_listing.listing.0.id |
121 | | - package_version = data.oci_marketplace_listing.listing.0.default_package_version |
122 | | - |
123 | | - #Optional |
124 | | - compartment_id = var.compartment_id |
125 | | -} |
126 | | - |
127 | | -data "oci_marketplace_listing_packages" "listing_packages" { |
128 | | - count = length(regexall("ocid1.image.oc1*", var.source_image_id)) > 0 || length(regexall("ocid1.bootvolume.oc1*", var.source_image_id)) > 0 || var.source_image_id == null ? 0 : 1 |
129 | | - #Required |
130 | | - listing_id = data.oci_marketplace_listing.listing.0.id |
131 | | - |
132 | | - #Optional |
133 | | - compartment_id = var.compartment_id |
134 | | -} |
135 | | - |
136 | | -data "oci_marketplace_listings" "listings" { |
137 | | - count = length(regexall("ocid1.image.oc1*", var.source_image_id)) > 0 || length(regexall("ocid1.bootvolume.oc1*", var.source_image_id)) > 0 || var.source_image_id == null ? 0 : 1 |
138 | | - name = [var.source_image_id] |
139 | | - #is_featured = true # Comment this line for GovCloud |
140 | | - compartment_id = var.compartment_id |
141 | | -} |
142 | | - |
143 | | -data "oci_marketplace_listing" "listing" { |
144 | | - count = length(regexall("ocid1.image.oc1*", var.source_image_id)) > 0 || length(regexall("ocid1.bootvolume.oc1*", var.source_image_id)) > 0 || var.source_image_id == null ? 0 : 1 |
145 | | - listing_id = data.oci_marketplace_listings.listings.0.listings[0].id |
146 | | - compartment_id = var.compartment_id |
147 | | -} |
148 | | - |
149 | | -data "oci_core_app_catalog_listing_resource_versions" "app_catalog_listing_resource_versions" { |
150 | | - count = length(regexall("ocid1.image.oc1*", var.source_image_id)) > 0 || length(regexall("ocid1.bootvolume.oc1*", var.source_image_id)) > 0 || var.source_image_id == null ? 0 : 1 |
151 | | - listing_id = data.oci_marketplace_listing_package.listing_package.0.app_catalog_listing_id |
152 | | -} |
153 | | - |
154 | | -data "oci_core_app_catalog_listing_resource_version" "catalog_listing" { |
155 | | - count = length(regexall("ocid1.image.oc1*", var.source_image_id)) > 0 || length(regexall("ocid1.bootvolume.oc1*", var.source_image_id)) > 0 || var.source_image_id == null ? 0 : 1 |
156 | | - listing_id = data.oci_marketplace_listing_package.listing_package.0.app_catalog_listing_id |
157 | | - resource_version = data.oci_marketplace_listing_package.listing_package.0.app_catalog_listing_resource_version |
158 | | -} |
159 | | - |
| 1 | +// Copyright (c) 2021, 2022, Oracle and/or its affiliates. |
| 2 | + |
| 3 | +############################# |
| 4 | +## Data Block - Instance |
| 5 | +## Create Instance and Boot Volume Backup Policy |
| 6 | +############################# |
| 7 | + |
| 8 | +locals { |
| 9 | + nsg_ids = var.nsg_ids != null ? flatten(tolist([for nsg in var.nsg_ids : (length(regexall("ocid1.networksecuritygroup.oc1*", nsg)) > 0 ? [nsg] : data.oci_core_network_security_groups.network_security_groups[nsg].network_security_groups[*].id)])) : null |
| 10 | + |
| 11 | + ADs = [ |
| 12 | + for ad in data.oci_identity_availability_domains.ads.availability_domains : ad.name |
| 13 | + ] |
| 14 | + |
| 15 | + shapes_config = { |
| 16 | + for shape in data.oci_core_shapes.present_ad.shapes : shape.name => { |
| 17 | + memory_in_gbs = shape.memory_in_gbs |
| 18 | + ocpus = shape.ocpus |
| 19 | + } |
| 20 | + } |
| 21 | + |
| 22 | + platform_configs = { |
| 23 | + for shape in data.oci_core_shapes.present_ad.shapes : shape.name => { |
| 24 | + config_type = length(shape.platform_config_options) > 0 ? element(flatten(shape.platform_config_options[*].type),0) : "" |
| 25 | + } if shape.name == var.shape |
| 26 | + } |
| 27 | + |
| 28 | + plugins_config = var.plugins_details != null ? var.plugins_details : {} |
| 29 | + remote_execute_script = var.remote_execute == null ? "SCRIPT-NOT-SET" : var.remote_execute |
| 30 | + cloud_init_script = var.cloud_init_script == null ? "SCRIPT-NOT-SET" : var.cloud_init_script |
| 31 | +} |
| 32 | + |
| 33 | +data "oci_identity_availability_domains" "ads" { |
| 34 | + compartment_id = var.compartment_id |
| 35 | +} |
| 36 | + |
| 37 | +data "oci_core_shapes" "present_ad" { |
| 38 | + compartment_id = var.compartment_id |
| 39 | + availability_domain = var.availability_domain == "" || var.availability_domain == null ? element(local.ADs, 0) : var.availability_domain |
| 40 | +} |
| 41 | + |
| 42 | +data "oci_core_vcns" "oci_vcns_instances" { |
| 43 | + for_each = { for vcn in var.vcn_names : vcn => vcn } |
| 44 | + compartment_id = var.network_compartment_id != null ? var.network_compartment_id : var.compartment_id |
| 45 | + display_name = each.value |
| 46 | +} |
| 47 | +// |
| 48 | +//data "oci_core_subnets" "oci_subnets_instances" { |
| 49 | +// compartment_id = var.network_compartment_id != null ? var.network_compartment_id : var.compartment_id |
| 50 | +// display_name = var.subnet_id |
| 51 | +// vcn_id = data.oci_core_vcns.oci_vcns_instances[var.vcn_names[0]].virtual_networks.*.id[0] |
| 52 | +//} |
| 53 | + |
| 54 | +data "oci_core_dedicated_vm_hosts" "existing_vm_host" { |
| 55 | + count = var.dedicated_vm_host_name != null ? 1 : 0 |
| 56 | + compartment_id = var.compartment_id |
| 57 | + display_name = var.dedicated_vm_host_name |
| 58 | + state = "ACTIVE" |
| 59 | +} |
| 60 | + |
| 61 | +data "oci_core_network_security_groups" "network_security_groups" { |
| 62 | + for_each = var.nsg_ids != null ? { for nsg in var.nsg_ids : nsg => nsg } : {} |
| 63 | + compartment_id = var.network_compartment_id != null ? var.network_compartment_id : var.compartment_id |
| 64 | + display_name = each.value |
| 65 | + vcn_id = data.oci_core_vcns.oci_vcns_instances[var.vcn_names[0]].virtual_networks.*.id[0] |
| 66 | +} |
| 67 | + |
| 68 | +#data "oci_core_boot_volumes" "all_boot_volumes" { |
| 69 | +# depends_on = [oci_core_instance.instance] |
| 70 | +# count = var.boot_tf_policy != null ? 1 : 0 |
| 71 | +# #Required |
| 72 | +# compartment_id = var.compartment_id |
| 73 | +# availability_domain = var.availability_domain |
| 74 | +# filter { |
| 75 | +# name = "display_name" |
| 76 | +# values = [join(" ", [var.display_name, "(Boot Volume)"])] |
| 77 | +# } |
| 78 | +# filter { |
| 79 | +# name = "state" |
| 80 | +# values = ["AVAILABLE"] |
| 81 | +# } |
| 82 | +#} |
| 83 | + |
| 84 | +data "oci_core_volume_backup_policies" "boot_vol_backup_policy" { |
| 85 | + count = var.boot_tf_policy != null ? 1 : 0 |
| 86 | + |
| 87 | + filter { |
| 88 | + name = "display_name" |
| 89 | + values = [lower(var.boot_tf_policy)] |
| 90 | + } |
| 91 | +} |
| 92 | + |
| 93 | +data "oci_core_volume_backup_policies" "boot_vol_custom_policy" { |
| 94 | + count = var.boot_tf_policy != null ? 1 : 0 |
| 95 | + compartment_id = local.policy_tf_compartment_id |
| 96 | + filter { |
| 97 | + name = "display_name" |
| 98 | + values = [var.boot_tf_policy] |
| 99 | + } |
| 100 | +} |
| 101 | + |
| 102 | +################################ |
| 103 | +# Data Block - Instances |
| 104 | +# Market Place Images |
| 105 | +################################ |
| 106 | + |
| 107 | +data "oci_marketplace_listing_package_agreements" "listing_package_agreements" { |
| 108 | + count = length(regexall("ocid1.image.oc1*", var.source_image_id)) > 0 || length(regexall("ocid1.bootvolume.oc1*", var.source_image_id)) > 0 || var.source_image_id == null ? 0 : 1 |
| 109 | + #Required |
| 110 | + listing_id = data.oci_marketplace_listing.listing.0.id |
| 111 | + package_version = data.oci_marketplace_listing.listing.0.default_package_version |
| 112 | + |
| 113 | + #Optional |
| 114 | + compartment_id = var.compartment_id |
| 115 | +} |
| 116 | + |
| 117 | +data "oci_marketplace_listing_package" "listing_package" { |
| 118 | + count = length(regexall("ocid1.image.oc1*", var.source_image_id)) > 0 || length(regexall("ocid1.bootvolume.oc1*", var.source_image_id)) > 0 || var.source_image_id == null ? 0 : 1 |
| 119 | + #Required |
| 120 | + listing_id = data.oci_marketplace_listing.listing.0.id |
| 121 | + package_version = data.oci_marketplace_listing.listing.0.default_package_version |
| 122 | + |
| 123 | + #Optional |
| 124 | + compartment_id = var.compartment_id |
| 125 | +} |
| 126 | + |
| 127 | +data "oci_marketplace_listing_packages" "listing_packages" { |
| 128 | + count = length(regexall("ocid1.image.oc1*", var.source_image_id)) > 0 || length(regexall("ocid1.bootvolume.oc1*", var.source_image_id)) > 0 || var.source_image_id == null ? 0 : 1 |
| 129 | + #Required |
| 130 | + listing_id = data.oci_marketplace_listing.listing.0.id |
| 131 | + |
| 132 | + #Optional |
| 133 | + compartment_id = var.compartment_id |
| 134 | +} |
| 135 | + |
| 136 | +data "oci_marketplace_listings" "listings" { |
| 137 | + count = length(regexall("ocid1.image.oc1*", var.source_image_id)) > 0 || length(regexall("ocid1.bootvolume.oc1*", var.source_image_id)) > 0 || var.source_image_id == null ? 0 : 1 |
| 138 | + name = [var.source_image_id] |
| 139 | + #is_featured = true # Comment this line for GovCloud |
| 140 | + compartment_id = var.compartment_id |
| 141 | +} |
| 142 | + |
| 143 | +data "oci_marketplace_listing" "listing" { |
| 144 | + count = length(regexall("ocid1.image.oc1*", var.source_image_id)) > 0 || length(regexall("ocid1.bootvolume.oc1*", var.source_image_id)) > 0 || var.source_image_id == null ? 0 : 1 |
| 145 | + listing_id = data.oci_marketplace_listings.listings.0.listings[0].id |
| 146 | + compartment_id = var.compartment_id |
| 147 | +} |
| 148 | + |
| 149 | +data "oci_core_app_catalog_listing_resource_versions" "app_catalog_listing_resource_versions" { |
| 150 | + count = length(regexall("ocid1.image.oc1*", var.source_image_id)) > 0 || length(regexall("ocid1.bootvolume.oc1*", var.source_image_id)) > 0 || var.source_image_id == null ? 0 : 1 |
| 151 | + listing_id = data.oci_marketplace_listing_package.listing_package.0.app_catalog_listing_id |
| 152 | +} |
| 153 | + |
| 154 | +data "oci_core_app_catalog_listing_resource_version" "catalog_listing" { |
| 155 | + count = length(regexall("ocid1.image.oc1*", var.source_image_id)) > 0 || length(regexall("ocid1.bootvolume.oc1*", var.source_image_id)) > 0 || var.source_image_id == null ? 0 : 1 |
| 156 | + listing_id = data.oci_marketplace_listing_package.listing_package.0.app_catalog_listing_id |
| 157 | + resource_version = data.oci_marketplace_listing_package.listing_package.0.app_catalog_listing_resource_version |
| 158 | +} |
| 159 | + |
0 commit comments