Skip to content

Commit 98596cd

Browse files
committed
add Support for ADB-S: Private Endpoint
1 parent c182243 commit 98596cd

File tree

4 files changed

+126
-64
lines changed

4 files changed

+126
-64
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
### Added
44
- Support `name` field to Identity Provider Group Summary response
5+
- Support for ADB-S: Private Endpoint
56

67
## 3.83.0 (July 01, 2020)
78

oci/database_autonomous_database_resource.go

Lines changed: 49 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ func DatabaseAutonomousDatabaseResource() *schema.Resource {
165165
Type: schema.TypeString,
166166
Optional: true,
167167
Computed: true,
168-
ForceNew: true,
169168
},
170169
"source": {
171170
Type: schema.TypeString,
@@ -190,7 +189,6 @@ func DatabaseAutonomousDatabaseResource() *schema.Resource {
190189
Type: schema.TypeString,
191190
Optional: true,
192191
Computed: true,
193-
ForceNew: true,
194192
},
195193
"timestamp": {
196194
Type: schema.TypeString,
@@ -504,34 +502,6 @@ func (s *DatabaseAutonomousDatabaseResourceCrud) Update() error {
504502
}
505503
}
506504

507-
if nsgIds, ok := s.D.GetOkExists("nsg_ids"); ok && s.D.HasChange("nsg_ids") {
508-
set := nsgIds.(*schema.Set)
509-
interfaces := set.List()
510-
tmp := make([]string, len(interfaces))
511-
for i := range interfaces {
512-
if interfaces[i] != nil {
513-
tmp[i] = interfaces[i].(string)
514-
}
515-
}
516-
if len(tmp) != 0 || s.D.HasChange("nsg_ids") {
517-
nsgUpdateRequest := oci_database.UpdateAutonomousDatabaseRequest{}
518-
519-
autonomousDatabaseId := s.D.Id()
520-
nsgUpdateRequest.AutonomousDatabaseId = &autonomousDatabaseId
521-
522-
nsgUpdateRequest.NsgIds = tmp
523-
524-
nsgUpdateRequest.RequestMetadata.RetryPolicy = getRetryPolicy(s.DisableNotFoundRetries, "database")
525-
526-
nsgUpdateResponse, err := s.Client.UpdateAutonomousDatabase(context.Background(), nsgUpdateRequest)
527-
if err != nil {
528-
return err
529-
}
530-
531-
s.Res = &nsgUpdateResponse.AutonomousDatabase
532-
}
533-
}
534-
535505
request := oci_database.UpdateAutonomousDatabaseRequest{}
536506

537507
if adminPassword, ok := s.D.GetOkExists("admin_password"); ok && s.D.HasChange("admin_password") {
@@ -590,6 +560,23 @@ func (s *DatabaseAutonomousDatabaseResourceCrud) Update() error {
590560
request.LicenseModel = oci_database.UpdateAutonomousDatabaseDetailsLicenseModelEnum(licenseModel.(string))
591561
}
592562

563+
if nsgIds, ok := s.D.GetOkExists("nsg_ids"); ok && s.D.HasChange("nsg_ids") {
564+
set := nsgIds.(*schema.Set)
565+
interfaces := set.List()
566+
tmp := make([]string, len(interfaces))
567+
for i := range interfaces {
568+
if interfaces[i] != nil {
569+
tmp[i] = interfaces[i].(string)
570+
}
571+
}
572+
if len(tmp) != 0 || s.D.HasChange("nsg_ids") {
573+
err := s.updateNsgIds(tmp)
574+
if err != nil {
575+
return err
576+
}
577+
}
578+
}
579+
593580
if whitelistedIps, ok := s.D.GetOkExists("whitelisted_ips"); ok && s.D.HasChange("whitelisted_ips") {
594581
set := whitelistedIps.(*schema.Set)
595582
interfaces := set.List()
@@ -1346,3 +1333,35 @@ func (s *DatabaseAutonomousDatabaseResourceCrud) updateDbVersion(dbVersion strin
13461333

13471334
return nil
13481335
}
1336+
1337+
func (s *DatabaseAutonomousDatabaseResourceCrud) updateNsgIds(nsgIds []string) error {
1338+
changeNsgIdsRequest := oci_database.UpdateAutonomousDatabaseRequest{}
1339+
changeNsgIdsRequest.NsgIds = nsgIds
1340+
1341+
if subnetId, ok := s.D.GetOkExists("subnet_id"); ok && s.D.HasChange("subnet_id") {
1342+
tmp := subnetId.(string)
1343+
changeNsgIdsRequest.SubnetId = &tmp
1344+
}
1345+
1346+
if privateEndpointLabel, ok := s.D.GetOkExists("private_endpoint_label"); ok && s.D.HasChange("private_endpoint_label") {
1347+
tmp := privateEndpointLabel.(string)
1348+
changeNsgIdsRequest.PrivateEndpointLabel = &tmp
1349+
}
1350+
tmp := s.D.Id()
1351+
changeNsgIdsRequest.AutonomousDatabaseId = &tmp
1352+
1353+
changeNsgIdsRequest.RequestMetadata.RetryPolicy = getRetryPolicy(s.DisableNotFoundRetries, "database")
1354+
1355+
response, err := s.Client.UpdateAutonomousDatabase(context.Background(), changeNsgIdsRequest)
1356+
if err != nil {
1357+
return err
1358+
}
1359+
1360+
workId := response.OpcWorkRequestId
1361+
_, err = WaitForWorkRequestWithErrorHandling(s.workRequestClient, workId, "database", oci_work_requests.WorkRequestResourceActionTypeUpdated, s.D.Timeout(schema.TimeoutUpdate), s.DisableNotFoundRetries)
1362+
if err != nil {
1363+
return err
1364+
}
1365+
s.Res = &response.AutonomousDatabase
1366+
return nil
1367+
}

oci/database_autonomous_database_resource_test.go

Lines changed: 74 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,38 +1141,7 @@ func TestResourceDatabaseAutonomousDatabaseResource_privateEndpoint(t *testing.T
11411141
},
11421142
),
11431143
},
1144-
// verify updates to updatable parameters without nsg update: Cannot update the Autonomous Database NSG IDs while another Autonomous Database update request is in progress
1145-
{
1146-
Config: config + compartmentIdVariableStr + AutonomousDatabasePrivateEndpointResourceDependencies +
1147-
generateResourceFromRepresentationMap("oci_database_autonomous_database", "test_autonomous_database", Optional, Update, autonomousDatabasePrivateEndpointRepresentation),
1148-
Check: resource.ComposeAggregateTestCheckFunc(
1149-
resource.TestCheckResourceAttr(resourceName, "admin_password", "BEstrO0ng_#12"),
1150-
resource.TestCheckResourceAttr(resourceName, "compartment_id", compartmentId),
1151-
resource.TestCheckResourceAttr(resourceName, "cpu_core_count", "1"),
1152-
resource.TestCheckResourceAttr(resourceName, "data_storage_size_in_tbs", "1"),
1153-
resource.TestCheckResourceAttr(resourceName, "db_name", adbName),
1154-
resource.TestCheckResourceAttr(resourceName, "db_workload", "OLTP"),
1155-
resource.TestCheckResourceAttr(resourceName, "defined_tags.%", "1"),
1156-
resource.TestCheckResourceAttr(resourceName, "display_name", "displayName2"),
1157-
resource.TestCheckResourceAttr(resourceName, "freeform_tags.%", "1"),
1158-
resource.TestCheckResourceAttr(resourceName, "is_auto_scaling_enabled", "false"),
1159-
resource.TestCheckResourceAttr(resourceName, "is_dedicated", "false"),
1160-
resource.TestCheckResourceAttr(resourceName, "is_preview_version_with_service_terms_accepted", "false"),
1161-
resource.TestCheckResourceAttr(resourceName, "license_model", "LICENSE_INCLUDED"),
1162-
resource.TestCheckResourceAttrSet(resourceName, "id"),
1163-
resource.TestCheckResourceAttr(resourceName, "nsg_ids.#", "2"),
1164-
resource.TestCheckResourceAttrSet(resourceName, "state"),
1165-
1166-
func(s *terraform.State) (err error) {
1167-
resId2, err = fromInstanceState(s, resourceName, "id")
1168-
if resId != resId2 {
1169-
return fmt.Errorf("Resource recreated when it was supposed to be updated.")
1170-
}
1171-
return err
1172-
},
1173-
),
1174-
},
1175-
// verify update to nsg
1144+
// verify updates to updatable parameters
11761145
{
11771146
Config: config + compartmentIdVariableStr + AutonomousDatabasePrivateEndpointResourceDependencies +
11781147
generateResourceFromRepresentationMap("oci_database_autonomous_database", "test_autonomous_database", Optional, Update, autonomousDatabasePrivateEndpointRepresentation),
@@ -1270,6 +1239,79 @@ func TestResourceDatabaseAutonomousDatabaseResource_privateEndpoint(t *testing.T
12701239
resource.TestCheckResourceAttrSet(singularDatasourceName, "time_created"),
12711240
),
12721241
},
1242+
// delete before next create
1243+
{
1244+
Config: config + compartmentIdVariableStr + AutonomousDatabasePrivateEndpointResourceDependencies,
1245+
},
1246+
// verify create with no private end point
1247+
{
1248+
Config: config + compartmentIdVariableStr + AutonomousDatabasePrivateEndpointResourceDependencies +
1249+
generateResourceFromRepresentationMap("oci_database_autonomous_database", "test_autonomous_database", Optional, Update,
1250+
representationCopyWithRemovedProperties(representationCopyWithNewProperties(autonomousDatabaseRepresentation, map[string]interface{}{
1251+
"db_version": Representation{repType: Optional, create: `19c`},
1252+
}), []string{"whitelisted_ips"})),
1253+
Check: resource.ComposeAggregateTestCheckFunc(
1254+
resource.TestCheckResourceAttr(resourceName, "admin_password", "BEstrO0ng_#12"),
1255+
resource.TestCheckResourceAttr(resourceName, "compartment_id", compartmentId),
1256+
resource.TestCheckResourceAttr(resourceName, "cpu_core_count", "1"),
1257+
resource.TestCheckResourceAttr(resourceName, "data_storage_size_in_tbs", "1"),
1258+
resource.TestCheckResourceAttr(resourceName, "db_name", adbName),
1259+
resource.TestCheckResourceAttr(resourceName, "db_workload", "OLTP"),
1260+
resource.TestCheckResourceAttr(resourceName, "defined_tags.%", "1"),
1261+
resource.TestCheckResourceAttr(resourceName, "display_name", "displayName2"),
1262+
resource.TestCheckResourceAttr(resourceName, "freeform_tags.%", "1"),
1263+
resource.TestCheckResourceAttrSet(resourceName, "id"),
1264+
resource.TestCheckResourceAttr(resourceName, "is_auto_scaling_enabled", "false"),
1265+
resource.TestCheckResourceAttr(resourceName, "is_dedicated", "false"),
1266+
resource.TestCheckResourceAttr(resourceName, "is_preview_version_with_service_terms_accepted", "false"),
1267+
resource.TestCheckResourceAttr(resourceName, "license_model", "LICENSE_INCLUDED"),
1268+
resource.TestCheckResourceAttr(resourceName, "nsg_ids.#", "0"),
1269+
resource.TestCheckResourceAttrSet(resourceName, "state"),
1270+
1271+
func(s *terraform.State) (err error) {
1272+
resId, err = fromInstanceState(s, resourceName, "id")
1273+
return err
1274+
},
1275+
),
1276+
},
1277+
// verify turn on PE
1278+
{
1279+
Config: config + compartmentIdVariableStr + AutonomousDatabasePrivateEndpointResourceDependencies +
1280+
generateResourceFromRepresentationMap("oci_database_autonomous_database", "test_autonomous_database", Optional, Update,
1281+
representationCopyWithRemovedProperties(representationCopyWithNewProperties(autonomousDatabaseRepresentation, map[string]interface{}{
1282+
"db_version": Representation{repType: Optional, create: `19c`},
1283+
"nsg_ids": Representation{repType: Optional, create: []string{`${oci_core_network_security_group.test_network_security_group.id}`}, update: []string{`${oci_core_network_security_group.test_network_security_group.id}`, `${oci_core_network_security_group.test_network_security_group2.id}`}},
1284+
"private_endpoint_label": Representation{repType: Optional, create: `xlx4fcli`},
1285+
"subnet_id": Representation{repType: Optional, create: `${oci_core_subnet.test_subnet.id}`},
1286+
}), []string{"whitelisted_ips"})), Check: resource.ComposeAggregateTestCheckFunc(
1287+
resource.TestCheckResourceAttr(resourceName, "admin_password", "BEstrO0ng_#12"),
1288+
resource.TestCheckResourceAttr(resourceName, "compartment_id", compartmentId),
1289+
resource.TestCheckResourceAttr(resourceName, "cpu_core_count", "1"),
1290+
resource.TestCheckResourceAttr(resourceName, "data_storage_size_in_tbs", "1"),
1291+
resource.TestCheckResourceAttr(resourceName, "db_name", adbName),
1292+
resource.TestCheckResourceAttr(resourceName, "db_workload", "OLTP"),
1293+
resource.TestCheckResourceAttr(resourceName, "defined_tags.%", "1"),
1294+
resource.TestCheckResourceAttr(resourceName, "display_name", "displayName2"),
1295+
resource.TestCheckResourceAttr(resourceName, "freeform_tags.%", "1"),
1296+
resource.TestCheckResourceAttrSet(resourceName, "id"),
1297+
resource.TestCheckResourceAttr(resourceName, "is_auto_scaling_enabled", "false"),
1298+
resource.TestCheckResourceAttr(resourceName, "is_dedicated", "false"),
1299+
resource.TestCheckResourceAttr(resourceName, "is_preview_version_with_service_terms_accepted", "false"),
1300+
resource.TestCheckResourceAttr(resourceName, "license_model", "LICENSE_INCLUDED"),
1301+
resource.TestCheckResourceAttr(resourceName, "private_endpoint_label", "xlx4fcli"),
1302+
resource.TestCheckResourceAttr(resourceName, "nsg_ids.#", "2"),
1303+
resource.TestCheckResourceAttrSet(resourceName, "state"),
1304+
resource.TestCheckResourceAttrSet(resourceName, "subnet_id"),
1305+
1306+
func(s *terraform.State) (err error) {
1307+
resId2, err = fromInstanceState(s, resourceName, "id")
1308+
if resId != resId2 {
1309+
return fmt.Errorf("Resource recreated when it was supposed to be updated.")
1310+
}
1311+
return err
1312+
},
1313+
),
1314+
},
12731315
},
12741316
})
12751317
}

website/docs/r/database_autonomous_database.html.markdown

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,12 @@ The following arguments are supported:
8080
* `license_model` - (Optional) (Updatable) The Oracle license model that applies to the Oracle Autonomous Database. Note that when provisioning an Autonomous Database on [dedicated Exadata infrastructure](https://docs.cloud.oracle.com/iaas/Content/Database/Concepts/adbddoverview.htm), this attribute must be null because the attribute is already set at the Autonomous Exadata Infrastructure level. When using [shared Exadata infrastructure](https://docs.cloud.oracle.com/iaas/Content/Database/Concepts/adboverview.htm#AEI), if a value is not specified, the system will supply the value of `BRING_YOUR_OWN_LICENSE`.
8181
* `nsg_ids` - (Optional) (Updatable) A list of the [OCIDs](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm) of the network security groups (NSGs) that this resource belongs to. Setting this to an empty array after the list is created removes the resource from all NSGs. For more information about NSGs, see [Security Rules](https://docs.cloud.oracle.com/iaas/Content/Network/Concepts/securityrules.htm). **NsgIds restrictions:**
8282
* Autonomous Databases with private access require at least 1 Network Security Group (NSG). The nsgIds array cannot be empty.
83-
* `private_endpoint_label` - (Optional) The private endpoint label for the resource.
83+
* `private_endpoint_label` - (Optional) (Updatable) The private endpoint label for the resource.
8484
* `source` - (Optional) The source of the database: Use `NONE` for creating a new Autonomous Database. Use `DATABASE` for creating a new Autonomous Database by cloning an existing Autonomous Database.
8585

8686
For Autonomous Databases on [shared Exadata infrastructure](https://docs.cloud.oracle.com/iaas/Content/Database/Concepts/adboverview.htm#AEI), the following cloning options are available: Use `BACKUP_FROM_ID` for creating a new Autonomous Database from a specified backup. Use `BACKUP_FROM_TIMESTAMP` for creating a point-in-time Autonomous Database clone using backups. For more information, see [Cloning an Autonomous Database](https://docs.cloud.oracle.com/iaas/Content/Database/Tasks/adbcloning.htm).
8787
* `source_id` - (Required when source=DATABASE) The [OCID](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm) of the source Autonomous Database that you will clone to create a new Autonomous Database.
88-
* `subnet_id` - (Optional) The [OCID](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm) of the subnet the resource is associated with.
88+
* `subnet_id` - (Optional) (Updatable) The [OCID](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm) of the subnet the resource is associated with.
8989

9090
**Subnet Restrictions:**
9191
* For bare metal DB systems and for single node virtual machine DB systems, do not use a subnet that overlaps with 192.168.16.16/28.

0 commit comments

Comments
 (0)