Skip to content

Commit fd97463

Browse files
committed
support for creating oci_database_autonomous_database resource with the specified whitelisted_ips
1 parent bf4db56 commit fd97463

8 files changed

+61
-15
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
## 3.52.1 (Unreleased)
1+
## 3.53.0 (Unreleased)
2+
3+
### Added
4+
- Support for creating `oci_database_autonomous_database` resource with the specified `whitelisted_ips`
5+
26
## 3.52.0 (November 13, 2019)
37

48
### Added

examples/database/adb/autonomous_database.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ resource "oci_database_autonomous_database" "autonomous_database" {
2323
is_auto_scaling_enabled = "true"
2424
license_model = "${var.autonomous_database_license_model}"
2525
is_preview_version_with_service_terms_accepted = "false"
26+
whitelisted_ips = ["1.1.1.1/28"]
2627
}
2728

2829
data "oci_database_autonomous_databases" "autonomous_databases" {

oci/database_autonomous_database_resource.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,16 @@ func (s *DatabaseAutonomousDatabaseResourceCrud) populateTopLevelPolymorphicCrea
740740
if licenseModel, ok := s.D.GetOkExists("license_model"); ok {
741741
details.LicenseModel = oci_database.CreateAutonomousDatabaseBaseLicenseModelEnum(licenseModel.(string))
742742
}
743+
if whitelistedIps, ok := s.D.GetOkExists("whitelisted_ips"); ok {
744+
interfaces := whitelistedIps.([]interface{})
745+
tmp := make([]string, len(interfaces))
746+
for i := range interfaces {
747+
if interfaces[i] != nil {
748+
tmp[i] = interfaces[i].(string)
749+
}
750+
}
751+
details.WhitelistedIps = tmp
752+
}
743753
request.CreateAutonomousDatabaseDetails = details
744754
case strings.ToLower("NONE"):
745755
details := oci_database.CreateAutonomousDatabaseDetails{}
@@ -803,6 +813,16 @@ func (s *DatabaseAutonomousDatabaseResourceCrud) populateTopLevelPolymorphicCrea
803813
if licenseModel, ok := s.D.GetOkExists("license_model"); ok {
804814
details.LicenseModel = oci_database.CreateAutonomousDatabaseBaseLicenseModelEnum(licenseModel.(string))
805815
}
816+
if whitelistedIps, ok := s.D.GetOkExists("whitelisted_ips"); ok {
817+
interfaces := whitelistedIps.([]interface{})
818+
tmp := make([]string, len(interfaces))
819+
for i := range interfaces {
820+
if interfaces[i] != nil {
821+
tmp[i] = interfaces[i].(string)
822+
}
823+
}
824+
details.WhitelistedIps = tmp
825+
}
806826
request.CreateAutonomousDatabaseDetails = details
807827
default:
808828
return fmt.Errorf("unknown source '%v' was specified", source)

oci/database_autonomous_database_resource_test.go

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ var (
3131
})
3232

3333
autonomousDatabaseDedicatedRepresentation = representationCopyWithNewProperties(
34-
representationCopyWithRemovedProperties(getUpdatedRepresentationCopy("db_name", Representation{repType: Required, create: adbDedicatedName}, autonomousDatabaseRepresentation), []string{"license_model"}),
34+
representationCopyWithRemovedProperties(getUpdatedRepresentationCopy("db_name", Representation{repType: Required, create: adbDedicatedName}, autonomousDatabaseRepresentation), []string{"license_model", "whitelisted_ips"}),
3535
map[string]interface{}{
3636
"autonomous_container_database_id": Representation{repType: Optional, create: `${oci_database_autonomous_container_database.test_autonomous_container_database.id}`},
3737
"is_dedicated": Representation{repType: Optional, create: `true`},
@@ -423,7 +423,10 @@ func TestResourceDatabaseAutonomousDatabaseResource_preview(t *testing.T) {
423423
// verify autoscaling
424424
{
425425
Config: config + compartmentIdVariableStr + AutonomousDatabaseResourceDependencies +
426-
generateResourceFromRepresentationMap("oci_database_autonomous_database", "test_autonomous_database", Optional, Update, representationCopyWithNewProperties(autonomousDatabasePreviewRepresentation, map[string]interface{}{"is_auto_scaling_enabled": Representation{repType: Optional, update: `true`}})),
426+
generateResourceFromRepresentationMap("oci_database_autonomous_database", "test_autonomous_database", Optional, Update,
427+
representationCopyWithNewProperties(autonomousDatabasePreviewRepresentation, map[string]interface{}{
428+
"whitelisted_ips": Representation{repType: Optional, create: []string{"1.1.1.1/28", "1.1.1.29"}},
429+
"is_auto_scaling_enabled": Representation{repType: Optional, update: `true`}})),
427430
Check: resource.ComposeAggregateTestCheckFunc(
428431
resource.TestCheckResourceAttr(resourceName, "admin_password", "BEstrO0ng_#12"),
429432
resource.TestCheckResourceAttr(resourceName, "compartment_id", compartmentId),
@@ -456,7 +459,10 @@ func TestResourceDatabaseAutonomousDatabaseResource_preview(t *testing.T) {
456459
Config: config +
457460
generateDataSourceFromRepresentationMap("oci_database_autonomous_databases", "test_autonomous_databases", Optional, Update, autonomousDatabaseDataSourceRepresentation) +
458461
compartmentIdVariableStr + AutonomousDatabaseResourceDependencies +
459-
generateResourceFromRepresentationMap("oci_database_autonomous_database", "test_autonomous_database", Optional, Update, autonomousDatabasePreviewRepresentation),
462+
generateResourceFromRepresentationMap("oci_database_autonomous_database", "test_autonomous_database", Optional, Update,
463+
representationCopyWithNewProperties(autonomousDatabasePreviewRepresentation, map[string]interface{}{
464+
"whitelisted_ips": Representation{repType: Optional, create: []string{"1.1.1.1/28", "1.1.1.29"}},
465+
})),
460466
Check: resource.ComposeAggregateTestCheckFunc(
461467
resource.TestCheckResourceAttr(datasourceName, "compartment_id", compartmentId),
462468
resource.TestCheckResourceAttr(datasourceName, "db_workload", "OLTP"),
@@ -487,7 +493,11 @@ func TestResourceDatabaseAutonomousDatabaseResource_preview(t *testing.T) {
487493
{
488494
Config: config +
489495
generateDataSourceFromRepresentationMap("oci_database_autonomous_database", "test_autonomous_database", Required, Create, autonomousDatabaseSingularDataSourceRepresentation) +
490-
compartmentIdVariableStr + AutonomousDatabaseResourceConfig,
496+
compartmentIdVariableStr + AutonomousDatabaseResourceDependencies +
497+
generateResourceFromRepresentationMap("oci_database_autonomous_database", "test_autonomous_database", Optional, Update,
498+
representationCopyWithNewProperties(autonomousDatabasePreviewRepresentation, map[string]interface{}{
499+
"whitelisted_ips": Representation{repType: Optional, create: []string{"1.1.1.1/28", "1.1.1.29"}},
500+
})),
491501
Check: resource.ComposeAggregateTestCheckFunc(
492502
resource.TestCheckResourceAttrSet(singularDatasourceName, "autonomous_database_id"),
493503

@@ -514,7 +524,11 @@ func TestResourceDatabaseAutonomousDatabaseResource_preview(t *testing.T) {
514524
},
515525
// remove singular datasource from previous step so that it doesn't conflict with import tests
516526
{
517-
Config: config + compartmentIdVariableStr + AutonomousDatabaseResourceConfig,
527+
Config: config + compartmentIdVariableStr + AutonomousDatabaseResourceDependencies +
528+
generateResourceFromRepresentationMap("oci_database_autonomous_database", "test_autonomous_database", Optional, Update,
529+
representationCopyWithNewProperties(autonomousDatabasePreviewRepresentation, map[string]interface{}{
530+
"whitelisted_ips": Representation{repType: Optional, create: []string{"1.1.1.1/28", "1.1.1.29"}},
531+
})),
518532
},
519533
// verify resource import
520534
{

oci/database_autonomous_database_test.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,12 @@ var (
5555
"is_auto_scaling_enabled": Representation{repType: Optional, create: `false`},
5656
"is_dedicated": Representation{repType: Optional, create: `false`},
5757
"is_preview_version_with_service_terms_accepted": Representation{repType: Optional, create: `false`},
58-
"license_model": Representation{repType: Optional, create: `LICENSE_INCLUDED`},
58+
"license_model": Representation{repType: Optional, create: `LICENSE_INCLUDED`},
59+
"whitelisted_ips": Representation{repType: Optional, create: []string{`1.1.1.1/28`}},
5960
}
6061

62+
autonomousDatabaseCopyWithUpdatedIPsRepresentation = getUpdatedRepresentationCopy("whitelisted_ips", Representation{repType: Optional, create: []string{"1.1.1.1/28", "1.1.1.29"}, update: []string{}}, autonomousDatabaseRepresentation)
63+
6164
autonomousDatabaseRepresentationForClone = representationCopyWithNewProperties(
6265
getUpdatedRepresentationCopy("db_name", Representation{repType: Required, create: adbCloneName}, autonomousDatabaseRepresentation),
6366
map[string]interface{}{
@@ -140,6 +143,7 @@ func TestDatabaseAutonomousDatabaseResource_basic(t *testing.T) {
140143
resource.TestCheckResourceAttr(resourceName, "is_preview_version_with_service_terms_accepted", "false"),
141144
resource.TestCheckResourceAttr(resourceName, "license_model", "LICENSE_INCLUDED"),
142145
resource.TestCheckResourceAttrSet(resourceName, "state"),
146+
resource.TestCheckResourceAttr(resourceName, "whitelisted_ips.#", "1"),
143147

144148
func(s *terraform.State) (err error) {
145149
resId, err = fromInstanceState(s, resourceName, "id")
@@ -172,6 +176,7 @@ func TestDatabaseAutonomousDatabaseResource_basic(t *testing.T) {
172176
resource.TestCheckResourceAttr(resourceName, "is_preview_version_with_service_terms_accepted", "false"),
173177
resource.TestCheckResourceAttr(resourceName, "license_model", "LICENSE_INCLUDED"),
174178
resource.TestCheckResourceAttrSet(resourceName, "state"),
179+
resource.TestCheckResourceAttr(resourceName, "whitelisted_ips.#", "1"),
175180

176181
func(s *terraform.State) (err error) {
177182
resId2, err = fromInstanceState(s, resourceName, "id")
@@ -218,7 +223,8 @@ func TestDatabaseAutonomousDatabaseResource_basic(t *testing.T) {
218223
// verify updates to whitelisted_ips
219224
{
220225
Config: config + compartmentIdVariableStr + AutonomousDatabaseResourceDependencies +
221-
generateResourceFromRepresentationMap("oci_database_autonomous_database", "test_autonomous_database", Optional, Update, representationCopyWithNewProperties(autonomousDatabaseRepresentation, map[string]interface{}{"whitelisted_ips": Representation{repType: Optional, create: []string{"1.1.1.1/28", "1.1.1.29"}}})),
226+
generateResourceFromRepresentationMap("oci_database_autonomous_database", "test_autonomous_database", Optional, Update,
227+
getUpdatedRepresentationCopy("whitelisted_ips", Representation{repType: Optional, create: []string{"1.1.1.1/28", "1.1.1.29"}}, autonomousDatabaseRepresentation)),
222228
Check: resource.ComposeAggregateTestCheckFunc(
223229
resource.TestCheckResourceAttr(resourceName, "admin_password", "BEstrO0ng_#12"),
224230
resource.TestCheckResourceAttr(resourceName, "compartment_id", compartmentId),
@@ -248,7 +254,7 @@ func TestDatabaseAutonomousDatabaseResource_basic(t *testing.T) {
248254
// verify remove whitelisted_ips
249255
{
250256
Config: config + compartmentIdVariableStr + AutonomousDatabaseResourceDependencies +
251-
generateResourceFromRepresentationMap("oci_database_autonomous_database", "test_autonomous_database", Optional, Update, autonomousDatabaseRepresentation),
257+
generateResourceFromRepresentationMap("oci_database_autonomous_database", "test_autonomous_database", Optional, Update, autonomousDatabaseCopyWithUpdatedIPsRepresentation),
252258
Check: resource.ComposeAggregateTestCheckFunc(
253259
resource.TestCheckResourceAttr(resourceName, "admin_password", "BEstrO0ng_#12"),
254260
resource.TestCheckResourceAttr(resourceName, "compartment_id", compartmentId),
@@ -278,7 +284,7 @@ func TestDatabaseAutonomousDatabaseResource_basic(t *testing.T) {
278284
// verify autoscaling
279285
{
280286
Config: config + compartmentIdVariableStr + AutonomousDatabaseResourceDependencies +
281-
generateResourceFromRepresentationMap("oci_database_autonomous_database", "test_autonomous_database", Optional, Update, representationCopyWithNewProperties(autonomousDatabaseRepresentation, map[string]interface{}{"is_auto_scaling_enabled": Representation{repType: Optional, update: `true`}})),
287+
generateResourceFromRepresentationMap("oci_database_autonomous_database", "test_autonomous_database", Optional, Update, representationCopyWithNewProperties(autonomousDatabaseCopyWithUpdatedIPsRepresentation, map[string]interface{}{"is_auto_scaling_enabled": Representation{repType: Optional, update: `true`}})),
282288
Check: resource.ComposeAggregateTestCheckFunc(
283289
resource.TestCheckResourceAttr(resourceName, "admin_password", "BEstrO0ng_#12"),
284290
resource.TestCheckResourceAttr(resourceName, "compartment_id", compartmentId),
@@ -311,7 +317,7 @@ func TestDatabaseAutonomousDatabaseResource_basic(t *testing.T) {
311317
Config: config +
312318
generateDataSourceFromRepresentationMap("oci_database_autonomous_databases", "test_autonomous_databases", Optional, Update, autonomousDatabaseDataSourceRepresentation) +
313319
compartmentIdVariableStr + AutonomousDatabaseResourceDependencies +
314-
generateResourceFromRepresentationMap("oci_database_autonomous_database", "test_autonomous_database", Optional, Update, autonomousDatabaseRepresentation),
320+
generateResourceFromRepresentationMap("oci_database_autonomous_database", "test_autonomous_database", Optional, Update, autonomousDatabaseCopyWithUpdatedIPsRepresentation),
315321
Check: resource.ComposeAggregateTestCheckFunc(
316322
resource.TestCheckResourceAttr(datasourceName, "compartment_id", compartmentId),
317323
resource.TestCheckResourceAttr(datasourceName, "db_workload", "OLTP"),

website/docs/d/database_autonomous_database.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,5 +68,5 @@ The following attributes are exported:
6868
* `time_deletion_of_free_autonomous_database` - The date and time the Always Free database will be automatically deleted because of inactivity. If the database is in the STOPPED state and without activity until this time, it will be deleted.
6969
* `time_reclamation_of_free_autonomous_database` - The date and time the Always Free database will be stopped because of inactivity. If this time is reached without any database activity, the database will automatically be put into the STOPPED state.
7070
* `used_data_storage_size_in_tbs` - The amount of storage that has been used, in terabytes.
71-
* `whitelisted_ips` - The client IP access control list (ACL). This feature is available for [serverless deployments](https://docs.cloud.oracle.com/iaas/Content/Database/Concepts/adboverview.htm#AEI) only. Only clients connecting from an IP address included in the ACL may access the Autonomous Database instance. This is an array of CIDR (Classless Inter-Domain Routing) notations for a subnet.
71+
* `whitelisted_ips` - The client IP access control list (ACL). This feature is available for [serverless deployments](https://docs.cloud.oracle.com/iaas/Content/Database/Concepts/adboverview.htm#AEI) only. Only clients connecting from an IP address included in the ACL may access the Autonomous Database instance. This is an array of CIDR (Classless Inter-Domain Routing) notations for a subnet or VCN OCID. To add the whitelist VCN specific subnet or IP, use a semicoln ';' as a deliminator to add the VCN specific subnets or IPs. Example: `["1.1.1.1","1.1.1.0/24","ocid1.vcn.oc1.sea.aaaaaaaard2hfx2nn3e5xeo6j6o62jga44xjizkw","ocid1.vcn.oc1.sea.aaaaaaaard2hfx2nn3e5xeo6j6o62jga44xjizkw;1.1.1.1","ocid1.vcn.oc1.sea.aaaaaaaard2hfx2nn3e5xeo6j6o62jga44xjizkw;1.1.0.0/16"]`
7272

website/docs/d/database_autonomous_databases.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,5 +86,5 @@ The following attributes are exported:
8686
* `time_deletion_of_free_autonomous_database` - The date and time the Always Free database will be automatically deleted because of inactivity. If the database is in the STOPPED state and without activity until this time, it will be deleted.
8787
* `time_reclamation_of_free_autonomous_database` - The date and time the Always Free database will be stopped because of inactivity. If this time is reached without any database activity, the database will automatically be put into the STOPPED state.
8888
* `used_data_storage_size_in_tbs` - The amount of storage that has been used, in terabytes.
89-
* `whitelisted_ips` - The client IP access control list (ACL). This feature is available for [serverless deployments](https://docs.cloud.oracle.com/iaas/Content/Database/Concepts/adboverview.htm#AEI) only. Only clients connecting from an IP address included in the ACL may access the Autonomous Database instance. This is an array of CIDR (Classless Inter-Domain Routing) notations for a subnet.
89+
* `whitelisted_ips` - The client IP access control list (ACL). This feature is available for [serverless deployments](https://docs.cloud.oracle.com/iaas/Content/Database/Concepts/adboverview.htm#AEI) only. Only clients connecting from an IP address included in the ACL may access the Autonomous Database instance. This is an array of CIDR (Classless Inter-Domain Routing) notations for a subnet or VCN OCID. To add the whitelist VCN specific subnet or IP, use a semicoln ';' as a deliminator to add the VCN specific subnets or IPs. Example: `["1.1.1.1","1.1.1.0/24","ocid1.vcn.oc1.sea.aaaaaaaard2hfx2nn3e5xeo6j6o62jga44xjizkw","ocid1.vcn.oc1.sea.aaaaaaaard2hfx2nn3e5xeo6j6o62jga44xjizkw;1.1.1.1","ocid1.vcn.oc1.sea.aaaaaaaard2hfx2nn3e5xeo6j6o62jga44xjizkw;1.1.0.0/16"]`
9090

0 commit comments

Comments
 (0)