Skip to content

Commit bb25269

Browse files
authored
Multicloud Terraform examples for Oracle Database@Azure (#357)
* exainfra create on Azure * list operations on Exa Infra * exainfra patch * list db servers * Create vm cluster * List VMC * vnet create and list * Dbshapes list * exa e2e * adbs deploy * ADBS List * ADBS e2e * exa Db node start and stop
1 parent f333087 commit bb25269

13 files changed

+629
-0
lines changed

Multicloud/Azure/Exa_mgmt_e2e.tf

Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
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+
}

Multicloud/Azure/adbs_deploy.tf

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
resource "azapi_resource" "autonomousDbDeploy" {
2+
type = "Oracle.Database/autonomousDatabases@2023-09-01-preview"
3+
parent_id = azapi_resource.resource_group.id
4+
name = "Adbs${local.resource_group_name}"
5+
schema_validation_enabled = false
6+
timeouts {
7+
create = "1h30m"
8+
update = "2h"
9+
delete = "20m"
10+
}
11+
body = jsonencode({
12+
"location" : local.location,
13+
"tags" : {
14+
"createdby" : local.user
15+
},
16+
"properties" : {
17+
"subnetId" : data.azurerm_subnet.listSubnet.id
18+
"dataBaseType": "Regular",
19+
"displayName": "example_autonomous_databasedb1",
20+
"computeModel": "ECPU",
21+
"computeCount": 2,
22+
"dataStorageSizeInGbs": 32,
23+
"dbWorkload": "OLTP",
24+
"adminPassword": "Password",
25+
"dbVersion": "19c",
26+
"characterSet": "AL32UTF8",
27+
"ncharacterSet": "AL16UTF16",
28+
"vnetId": azurerm_virtual_network.virtual_network.id,
29+
}
30+
})
31+
response_export_values = ["properties.ocid"]
32+
}

Multicloud/Azure/adbs_e2e.tf

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
terraform {
2+
required_providers {
3+
azapi = {
4+
source = "Azure/azapi"
5+
}
6+
azurerm = {
7+
source = "hashicorp/azurerm"
8+
}
9+
}
10+
}
11+
12+
provider "azapi" {
13+
skip_provider_registration = false
14+
}
15+
16+
provider "azurerm" {
17+
skip_provider_registration = true
18+
features {}
19+
}
20+
21+
locals {
22+
resource_group_name = "adbsdemotest"
23+
user = "myuser"
24+
location = "eastus"
25+
}
26+
27+
resource "azapi_resource" "resource_group" {
28+
type = "Microsoft.Resources/resourceGroups@2023-07-01"
29+
name = local.resource_group_name
30+
location = local.location
31+
}
32+
33+
resource "azurerm_virtual_network" "virtual_network" {
34+
name = "${local.resource_group_name}_vnet"
35+
address_space = ["10.0.0.0/16"]
36+
location = local.location
37+
resource_group_name = local.resource_group_name
38+
}
39+
40+
resource "azurerm_subnet" "virtual_network_subnet" {
41+
name = "${local.resource_group_name}_subnet"
42+
resource_group_name = local.resource_group_name
43+
virtual_network_name = azurerm_virtual_network.virtual_network.name
44+
address_prefixes = ["10.0.1.0/24"]
45+
46+
delegation {
47+
name = "delegation"
48+
49+
service_delegation {
50+
name = "Oracle.Database/networkAttachments"
51+
}
52+
}
53+
}
54+
55+
data "azurerm_subnet" "listSubnet" {
56+
name = "${local.resource_group_name}_subnet"
57+
virtual_network_name = "${local.resource_group_name}_vnet"
58+
resource_group_name = local.resource_group_name
59+
depends_on = [azurerm_subnet.virtual_network_subnet]
60+
}
61+
62+
resource "tls_private_key" "generated_ssh_key" {
63+
algorithm = "RSA"
64+
rsa_bits = 4096
65+
}
66+
67+
resource "azapi_resource" "ssh_public_key" {
68+
type = "Microsoft.Compute/sshPublicKeys@2023-09-01"
69+
name = "${local.resource_group_name}_key"
70+
location = local.location
71+
parent_id = azapi_resource.resource_group.id
72+
body = jsonencode({
73+
properties = {
74+
publicKey = tls_private_key.generated_ssh_key.public_key_openssh
75+
}
76+
})
77+
}
78+
79+
resource "azapi_resource" "autonomousDbDeploy" {
80+
type = "Oracle.Database/autonomousDatabases@2023-09-01-preview"
81+
parent_id = azapi_resource.resource_group.id
82+
name = "Adbs${local.resource_group_name}"
83+
schema_validation_enabled = false
84+
depends_on = [azapi_resource.ssh_public_key]
85+
timeouts {
86+
create = "1h30m"
87+
update = "2h"
88+
delete = "20m"
89+
}
90+
body = jsonencode({
91+
"location" : local.location,
92+
"tags" : {
93+
"createdby" : local.user
94+
},
95+
"properties" : {
96+
"subnetId" : data.azurerm_subnet.listSubnet.id
97+
"dataBaseType": "Regular",
98+
"displayName": "example_autonomous_databasedb1",
99+
"computeModel": "ECPU",
100+
"computeCount": 2,
101+
"dataStorageSizeInGbs": 32,
102+
"dbWorkload": "OLTP",
103+
"adminPassword": "TestPass#2024#",
104+
"dbVersion": "19c",
105+
"characterSet": "AL32UTF8",
106+
"ncharacterSet": "AL16UTF16",
107+
"vnetId": azurerm_virtual_network.virtual_network.id,
108+
}
109+
})
110+
response_export_values = ["properties.ocid"]
111+
}

Multicloud/Azure/adbs_list.tf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// OperationId: AutonomousDatabases_ListBySubscription
2+
// GET /subscriptions/{subscriptionId}/providers/Oracle.Database/autonomousDatabases
3+
data "azapi_resource_list" "listAutonomousDatabasesBySubscription" {
4+
type = "Oracle.Database/autonomousDatabases@2023-09-01-preview"
5+
parent_id = data.azapi_resource.subscription.id
6+
depends_on = [azapi_resource.autonomousDatabase]
7+
}
8+
9+
// OperationId: AutonomousDatabases_ListByResourceGroup
10+
// GET /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Oracle.Database/autonomousDatabases
11+
data "azapi_resource_list" "listAutonomousDatabasesByResourceGroup" {
12+
type = "Oracle.Database/autonomousDatabases@2023-09-01-preview"
13+
parent_id = azapi_resource.resourceGroup.id
14+
depends_on = [azapi_resource.autonomousDatabase]
15+
}

Multicloud/Azure/dbshapes_list.tf

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// List an Oracle Exadata Database Shape
2+
3+
data "azapi_resource_id" "location" {
4+
type = "Oracle.Database/locations@2023-12-12"
5+
parent_id = data.azapi_resource.subscription.id
6+
name = "eastus"
7+
}
8+
9+
// OperationId: DbSystemShapes_Get
10+
// GET /subscriptions/{subscriptionId}/providers/Oracle.Database/locations/{location}/dbSystemShapes/{dbsystemshapename}
11+
data "azapi_resource" "dbSystemShape" {
12+
type = "Oracle.Database/locations/dbSystemShapes@2023-09-01-preview"
13+
parent_id = data.azapi_resource_id.location.id
14+
name = var.resource_name
15+
}
16+
17+
// List Oracle Exadata Database Shapes by Location
18+
19+
// OperationId: DbSystemShapes_ListByLocation
20+
// GET /subscriptions/{subscriptionId}/providers/Oracle.Database/locations/{location}/dbSystemShapes
21+
data "azapi_resource_list" "listDbSystemShapesByLocation" {
22+
type = "Oracle.Database/locations/dbSystemShapes@2023-09-01-preview"
23+
parent_id = data.azapi_resource_id.location.id
24+
}

0 commit comments

Comments
 (0)