|
| 1 | +terraform { |
| 2 | + required_providers { |
| 3 | + azapi = { |
| 4 | + source = "Azure/azapi" |
| 5 | + } |
| 6 | + oci = { |
| 7 | + source = "oracle/oci" |
| 8 | + } |
| 9 | + } |
| 10 | +} |
| 11 | + |
| 12 | +provider "azapi" { |
| 13 | + skip_provider_registration = false |
| 14 | +} |
| 15 | + |
| 16 | +provider "oci" { |
| 17 | + user_ocid = <user_ocid> |
| 18 | + fingerprint = <user_fingerprint> |
| 19 | + tenancy_ocid = <oci_tenancy_ocid> |
| 20 | + region = "us-ashburn-1" |
| 21 | + private_key_path = <Path to API Key> |
| 22 | +} |
| 23 | + |
| 24 | +locals { |
| 25 | + resource_group_name = "TestResourceGroup" |
| 26 | + user = "Username" |
| 27 | + location = "eastus" |
| 28 | +} |
| 29 | + |
| 30 | +resource "azapi_resource" "resource_group" { |
| 31 | + type = "Microsoft.Resources/resourceGroups@2023-07-01" |
| 32 | + name = local.resource_group_name |
| 33 | + location = local.location |
| 34 | +} |
| 35 | + |
| 36 | +resource "azapi_resource" "virtual_network" { |
| 37 | + type = "Microsoft.Network/virtualNetworks@2023-04-01" |
| 38 | + name = "${local.resource_group_name}_vnet" |
| 39 | + location = local.location |
| 40 | + parent_id = azapi_resource.resource_group.id |
| 41 | + body = jsonencode({ |
| 42 | + properties = { |
| 43 | + addressSpace = { |
| 44 | + addressPrefixes = [ |
| 45 | + "10.0.0.0/16" |
| 46 | + ] |
| 47 | + } |
| 48 | + subnets = [ |
| 49 | + { |
| 50 | + name = "delegated" |
| 51 | + properties = { |
| 52 | + addressPrefix = "10.0.1.0/24" |
| 53 | + delegations = [ |
| 54 | + { |
| 55 | + name = "Oracle.Database.networkAttachments" |
| 56 | + properties = { |
| 57 | + serviceName = "Oracle.Database/networkAttachments" |
| 58 | + } |
| 59 | + } |
| 60 | + ] |
| 61 | + } |
| 62 | + } |
| 63 | + ] |
| 64 | + } |
| 65 | + }) |
| 66 | +} |
| 67 | + |
| 68 | +data "azapi_resource_list" "listVirtualNetwork" { |
| 69 | + type = "Microsoft.Network/virtualNetworks/subnets@2023-09-01" |
| 70 | + parent_id = azapi_resource.virtual_network.id |
| 71 | + depends_on = [azapi_resource.virtual_network] |
| 72 | + response_export_values = ["*"] |
| 73 | +} |
| 74 | + |
| 75 | +resource "tls_private_key" "generated_ssh_key" { |
| 76 | + algorithm = "RSA" |
| 77 | + rsa_bits = 4096 |
| 78 | +} |
| 79 | + |
| 80 | +resource "azapi_resource" "ssh_public_key" { |
| 81 | + type = "Microsoft.Compute/sshPublicKeys@2023-09-01" |
| 82 | + name = "${local.resource_group_name}_key" |
| 83 | + location = local.location |
| 84 | + parent_id = azapi_resource.resource_group.id |
| 85 | + body = jsonencode({ |
| 86 | + properties = { |
| 87 | + publicKey = "${tls_private_key.generated_ssh_key.public_key_openssh}" |
| 88 | + } |
| 89 | + }) |
| 90 | +} |
| 91 | + |
| 92 | +// OperationId: CloudExadataInfrastructures_CreateOrUpdate, CloudExadataInfrastructures_Get, CloudExadataInfrastructures_Delete |
| 93 | +// PUT /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Oracle.Database/cloudExadataInfrastructures/{cloudexadatainfrastructurename} |
| 94 | +resource "azapi_resource" "cloudExadataInfrastructure" { |
| 95 | + type = "Oracle.Database/cloudExadataInfrastructures@2023-09-01-preview" |
| 96 | + parent_id = azapi_resource.resource_group.id |
| 97 | + name = "OFake_terraform_deploy_infra_${local.resource_group_name}" |
| 98 | + timeouts { |
| 99 | + create = "1h30m" |
| 100 | + delete = "20m" |
| 101 | + } |
| 102 | + body = jsonencode({ |
| 103 | + "location" : "${local.location}", |
| 104 | + "zones" : [ |
| 105 | + "2" |
| 106 | + ], |
| 107 | + "tags" : { |
| 108 | + "createdby" : "${local.user}" |
| 109 | + }, |
| 110 | + "properties" : { |
| 111 | + "computeCount" : 2, |
| 112 | + "displayName" : "OFake_terraform_deploy_infra_${local.resource_group_name}", |
| 113 | + "maintenanceWindow" : { |
| 114 | + "leadTimeInWeeks" : 0, |
| 115 | + "preference" : "NoPreference", |
| 116 | + "patchingMode" : "Rolling" |
| 117 | + }, |
| 118 | + "shape" : "Exadata.X9M", |
| 119 | + "storageCount" : 3 |
| 120 | + } |
| 121 | + |
| 122 | + }) |
| 123 | + schema_validation_enabled = false |
| 124 | +} |
| 125 | + |
| 126 | +// OperationId: DbServers_ListByCloudExadataInfrastructure |
| 127 | +// GET /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Oracle.Database/cloudExadataInfrastructures/{cloudexadatainfrastructurename}/dbServers |
| 128 | +data "azapi_resource_list" "listDbServersByCloudExadataInfrastructure" { |
| 129 | + type = "Oracle.Database/cloudExadataInfrastructures/dbServers@2023-09-01-preview" |
| 130 | + parent_id = azapi_resource.cloudExadataInfrastructure.id |
| 131 | + depends_on = [azapi_resource.cloudExadataInfrastructure] |
| 132 | + response_export_values = ["*"] |
| 133 | +} |
| 134 | + |
| 135 | +// OperationId: CloudVmClusters_CreateOrUpdate, CloudVmClusters_Get, CloudVmClusters_Delete |
| 136 | +// PUT /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Oracle.Database/cloudVmClusters/{cloudvmclustername} |
| 137 | +resource "azapi_resource" "cloudVmCluster" { |
| 138 | + type = "Oracle.Database/cloudVmClusters@2023-09-01-preview" |
| 139 | + parent_id = azapi_resource.resource_group.id |
| 140 | + name = "OFake_terraform_deploy_cluster_${local.resource_group_name}" |
| 141 | + schema_validation_enabled = false |
| 142 | + depends_on = [azapi_resource.cloudExadataInfrastructure] |
| 143 | + timeouts { |
| 144 | + create = "1h30m" |
| 145 | + delete = "20m" |
| 146 | + } |
| 147 | + body = jsonencode({ |
| 148 | + "location" : "${local.location}", |
| 149 | + "tags" : { |
| 150 | + "createdby" : "${local.user}" |
| 151 | + }, |
| 152 | + "properties" : { |
| 153 | + "subnetId" : "${jsondecode(data.azapi_resource_list.listVirtualNetwork.output).value[0].id}" |
| 154 | + "cloudExadataInfrastructureId" : "${azapi_resource.cloudExadataInfrastructure.id}" |
| 155 | + "cpuCoreCount" : 4 |
| 156 | + "dataCollectionOptions" : { |
| 157 | + "isDiagnosticsEventsEnabled" : true, |
| 158 | + "isHealthMonitoringEnabled" : true, |
| 159 | + "isIncidentLogsEnabled" : true |
| 160 | + }, |
| 161 | + "dataStoragePercentage" : 80, |
| 162 | + "dataStorageSizeInTbs" : 2, |
| 163 | + "dbNodeStorageSizeInGbs" : 120, |
| 164 | + "dbServers" : [ |
| 165 | + "${jsondecode(data.azapi_resource_list.listDbServersByCloudExadataInfrastructure.output).value[0].properties.ocid}", |
| 166 | + "${jsondecode(data.azapi_resource_list.listDbServersByCloudExadataInfrastructure.output).value[1].properties.ocid}" |
| 167 | + ] |
| 168 | + "displayName" : "OFake_terraform_deploy_cluster_${local.resource_group_name}", |
| 169 | + "giVersion" : "19.0.0.0", |
| 170 | + "hostname" : "${local.user}", |
| 171 | + "isLocalBackupEnabled" : false, |
| 172 | + "isSparseDiskgroupEnabled" : false, |
| 173 | + "licenseModel" : "LicenseIncluded", |
| 174 | + "memorySizeInGbs" : 60, |
| 175 | + "sshPublicKeys" : ["${tls_private_key.generated_ssh_key.public_key_openssh}"], |
| 176 | + "timeZone" : "UTC", |
| 177 | + "vnetId" : "${azapi_resource.virtual_network.id}", |
| 178 | + "provisioningState" : "Succeeded" |
| 179 | + } |
| 180 | + }) |
| 181 | + response_export_values = ["properties.ocid"] |
| 182 | +} |
| 183 | + |
| 184 | +resource "oci_database_db_home" "exa_db_home" { |
| 185 | + source = "VM_CLUSTER_NEW" |
| 186 | + vm_cluster_id = jsondecode(azapi_resource.cloudVmCluster.output).properties.ocid |
| 187 | + db_version = "19.20.0.0" |
| 188 | + display_name = "TFDBHOME" |
| 189 | + |
| 190 | + database { |
| 191 | + db_name = "TFCDB" |
| 192 | + pdb_name = "TFPDB" |
| 193 | + admin_password = "TestPass#2024#" |
| 194 | + db_workload = "OLTP" |
| 195 | + } |
| 196 | + depends_on = [azapi_resource.cloudVmCluster] |
| 197 | +} |
0 commit comments