1
+ # Copyright (c) 2021 Oracle and/or its affiliates. All rights reserved.
2
+ # Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
3
+ #
4
+
5
+ # Gets a list of Availability Domains
6
+ data "oci_identity_availability_domains" "ADs" {
7
+ compartment_id = var. tenancy_ocid
8
+ }
9
+
10
+ # Randoms
11
+ resource "random_string" "deploy_id" {
12
+ length = 4
13
+ special = false
14
+ }
15
+
16
+ # Check for resource limits
17
+ # # Check available compute shape
18
+ data "oci_limits_services" "compute_services" {
19
+ compartment_id = var. tenancy_ocid
20
+
21
+ filter {
22
+ name = " name"
23
+ values = [" compute" ]
24
+ }
25
+ }
26
+ data "oci_limits_limit_definitions" "compute_limit_definitions" {
27
+ compartment_id = var. tenancy_ocid
28
+ service_name = data. oci_limits_services . compute_services . services . 0 . name
29
+
30
+ filter {
31
+ name = " description"
32
+ values = [var . instance_shape ]
33
+ }
34
+ }
35
+ data "oci_limits_resource_availability" "compute_resource_availability" {
36
+ compartment_id = var. tenancy_ocid
37
+ limit_name = data. oci_limits_limit_definitions . compute_limit_definitions . limit_definitions [0 ]. name
38
+ service_name = data. oci_limits_services . compute_services . services . 0 . name
39
+ availability_domain = data. oci_identity_availability_domains . ADs . availability_domains [count . index ]. name
40
+
41
+ count = length (data. oci_identity_availability_domains . ADs . availability_domains )
42
+ }
43
+ resource "random_shuffle" "compute_ad" {
44
+ input = local. compute_available_limit_ad_list
45
+ result_count = length (local. compute_available_limit_ad_list )
46
+ }
47
+ locals {
48
+ compute_available_limit_ad_list = [for limit in data . oci_limits_resource_availability . compute_resource_availability : limit . availability_domain if (limit. available - var. num_instances ) >= 0 ]
49
+ compute_available_limit_error = length (local. compute_available_limit_ad_list ) == 0 ? (
50
+ file (" ERROR: No limits available for the chosen compute shape and number of nodes" )) : 0
51
+ }
52
+
53
+ # Gets a list of supported images based on the shape, operating_system and operating_system_version provided
54
+ data "oci_core_images" "compute_images" {
55
+ compartment_id = var. compartment_ocid
56
+ operating_system = var. image_operating_system
57
+ operating_system_version = var. image_operating_system_version
58
+ shape = var. instance_shape
59
+ sort_by = " TIMECREATED"
60
+ sort_order = " DESC"
61
+ }
62
+
63
+ data "oci_identity_tenancy" "tenant_details" {
64
+ tenancy_id = var. tenancy_ocid
65
+
66
+ provider = oci. current_region
67
+ }
68
+
69
+ data "oci_identity_regions" "home_region" {
70
+ filter {
71
+ name = " key"
72
+ values = [data . oci_identity_tenancy . tenant_details . home_region_key ]
73
+ }
74
+
75
+ provider = oci. current_region
76
+ }
77
+
78
+ # Available Services
79
+ data "oci_core_services" "all_services" {
80
+ filter {
81
+ name = " name"
82
+ values = [" All .* Services In Oracle Services Network" ]
83
+ regex = true
84
+ }
85
+ }
86
+
87
+ locals {
88
+ common_tags = {
89
+ Reference = " Created by OCI QuickStart for DotNet sample"
90
+ }
91
+ }
92
+
93
+ # Cloud Init
94
+ data "template_cloudinit_config" "instances" {
95
+ gzip = true
96
+ base64_encode = true
97
+
98
+ part {
99
+ filename = " cloud-config.yaml"
100
+ content_type = " text/cloud-config"
101
+ content = data. template_file . cloud_init . rendered
102
+ }
103
+ }
104
+ data "template_file" "cloud_init" {
105
+ template = file (" ${ path . module } /scripts/cloud-config.template.yaml" )
106
+
107
+ vars = {
108
+ setup_preflight_sh_content = base64gzip (data. template_file . setup_preflight . rendered )
109
+ setup_template_sh_content = base64gzip (data. template_file . setup_template . rendered )
110
+ deploy_template_content = base64gzip (data. template_file . deploy_template . rendered )
111
+ }
112
+ }
113
+ data "template_file" "setup_preflight" {
114
+ template = file (" ${ path . module } /scripts/setup.preflight.sh" )
115
+ }
116
+ data "template_file" "setup_template" {
117
+ template = file (" ${ path . module } /scripts/setup.template.sh" )
118
+ }
119
+ data "template_file" "deploy_template" {
120
+ template = file (" ${ path . module } /scripts/deploy.template.sh" )
121
+
122
+ vars = {
123
+ dotnet_standard_type = var.dotnet_standard_type
124
+ dotnet_custom_text_for_standard_webapp = var.dotnet_custom_text_for_standard_webapp
125
+ dotnet_git_custom_webapp = var.dotnet_git_custom_webapp
126
+ }
127
+ }
0 commit comments