Skip to content

Commit 8cf18ed

Browse files
committed
Support for patching in ADB-D: Retrieving patch info from patchId
1 parent d0d8c8c commit 8cf18ed

16 files changed

+294
-11
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
## 3.92.0 (Unreleased)
2+
3+
### Added
4+
- Support for patching in ADB-D: datasource `oci_database_autonomous_container_patches` for autonomous container databases
5+
- Support for patching in ADB-D: Retrieving patch info from patchId
6+
27
## 3.91.0 (September 02, 2020)
38

49
### Added
@@ -7,7 +12,6 @@
712
- Support for VM DB System Cloning
813
- Support for DBAAS ADB Serverless Refreshable Clone
914
- Support for LBaaS Cipher Suite Configuration
10-
- Support for patching in ADB-D, datasource `oci_database_autonomous_container_patches` for autonomous container databases
1115

1216
### Fixed
1317
- Fix imports when oci_database_db_system is missing a primary db_home. Previous behavior resulted in unusable state file after

oci/database_autonomous_container_database_data_source.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ func (s *DatabaseAutonomousContainerDatabaseDataSourceCrud) SetData() error {
127127
s.D.Set("next_maintenance_run_id", *s.Res.NextMaintenanceRunId)
128128
}
129129

130+
if s.Res.PatchId != nil {
131+
s.D.Set("patch_id", *s.Res.PatchId)
132+
}
133+
130134
s.D.Set("patch_model", s.Res.PatchModel)
131135

132136
s.D.Set("service_level_agreement_type", s.Res.ServiceLevelAgreementType)

oci/database_autonomous_container_database_resource.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,10 @@ func DatabaseAutonomousContainerDatabaseResource() *schema.Resource {
325325
Type: schema.TypeString,
326326
Computed: true,
327327
},
328+
"patch_id": {
329+
Type: schema.TypeString,
330+
Computed: true,
331+
},
328332
"state": {
329333
Type: schema.TypeString,
330334
Computed: true,
@@ -662,6 +666,10 @@ func (s *DatabaseAutonomousContainerDatabaseResourceCrud) SetData() error {
662666
s.D.Set("next_maintenance_run_id", *s.Res.NextMaintenanceRunId)
663667
}
664668

669+
if s.Res.PatchId != nil {
670+
s.D.Set("patch_id", *s.Res.PatchId)
671+
}
672+
665673
s.D.Set("patch_model", s.Res.PatchModel)
666674

667675
s.D.Set("service_level_agreement_type", s.Res.ServiceLevelAgreementType)

oci/database_autonomous_container_database_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ func TestDatabaseAutonomousContainerDatabaseResource_basic(t *testing.T) {
270270
resource.TestCheckResourceAttr(datasourceName, "autonomous_container_databases.0.freeform_tags.%", "1"),
271271
resource.TestCheckResourceAttrSet(datasourceName, "autonomous_container_databases.0.id"),
272272
resource.TestCheckResourceAttr(datasourceName, "autonomous_container_databases.0.maintenance_window.#", "1"),
273+
resource.TestCheckResourceAttrSet(datasourceName, "autonomous_container_databases.0.patch_id"),
273274
resource.TestCheckResourceAttr(datasourceName, "autonomous_container_databases.0.maintenance_window.0.days_of_week.#", "1"),
274275
resource.TestCheckResourceAttr(datasourceName, "autonomous_container_databases.0.maintenance_window.0.days_of_week.0.name", "TUESDAY"),
275276
resource.TestCheckResourceAttr(datasourceName, "autonomous_container_databases.0.maintenance_window.0.hours_of_day.#", "1"),
@@ -301,6 +302,7 @@ func TestDatabaseAutonomousContainerDatabaseResource_basic(t *testing.T) {
301302
resource.TestCheckResourceAttr(singularDatasourceName, "freeform_tags.%", "1"),
302303
resource.TestCheckResourceAttrSet(singularDatasourceName, "id"),
303304
resource.TestCheckResourceAttr(singularDatasourceName, "maintenance_window.#", "1"),
305+
resource.TestCheckResourceAttrSet(singularDatasourceName, "patch_id"),
304306
resource.TestCheckResourceAttr(singularDatasourceName, "maintenance_window.0.days_of_week.#", "1"),
305307
resource.TestCheckResourceAttr(singularDatasourceName, "maintenance_window.0.days_of_week.0.name", "TUESDAY"),
306308
resource.TestCheckResourceAttr(singularDatasourceName, "maintenance_window.0.hours_of_day.#", "1"),

oci/database_autonomous_container_databases_data_source.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,10 @@ func (s *DatabaseAutonomousContainerDatabasesDataSourceCrud) SetData() error {
206206
autonomousContainerDatabase["next_maintenance_run_id"] = *r.NextMaintenanceRunId
207207
}
208208

209+
if r.PatchId != nil {
210+
autonomousContainerDatabase["patch_id"] = *r.PatchId
211+
}
212+
209213
autonomousContainerDatabase["patch_model"] = r.PatchModel
210214

211215
autonomousContainerDatabase["service_level_agreement_type"] = r.ServiceLevelAgreementType
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
// Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
2+
// Licensed under the Mozilla Public License v2.0
3+
4+
package oci
5+
6+
import (
7+
"context"
8+
9+
"github.com/hashicorp/terraform/helper/schema"
10+
oci_database "github.com/oracle/oci-go-sdk/database"
11+
)
12+
13+
func init() {
14+
RegisterDatasource("oci_database_autonomous_patch", DatabaseAutonomousPatchDataSource())
15+
}
16+
17+
func DatabaseAutonomousPatchDataSource() *schema.Resource {
18+
return &schema.Resource{
19+
Read: readSingularDatabaseAutonomousPatch,
20+
Schema: map[string]*schema.Schema{
21+
"autonomous_patch_id": {
22+
Type: schema.TypeString,
23+
Required: true,
24+
},
25+
// Computed
26+
"description": {
27+
Type: schema.TypeString,
28+
Computed: true,
29+
},
30+
"lifecycle_details": {
31+
Type: schema.TypeString,
32+
Computed: true,
33+
},
34+
"patch_model": {
35+
Type: schema.TypeString,
36+
Computed: true,
37+
},
38+
"quarter": {
39+
Type: schema.TypeString,
40+
Computed: true,
41+
},
42+
"state": {
43+
Type: schema.TypeString,
44+
Computed: true,
45+
},
46+
"time_released": {
47+
Type: schema.TypeString,
48+
Computed: true,
49+
},
50+
"type": {
51+
Type: schema.TypeString,
52+
Computed: true,
53+
},
54+
"version": {
55+
Type: schema.TypeString,
56+
Computed: true,
57+
},
58+
"year": {
59+
Type: schema.TypeString,
60+
Computed: true,
61+
},
62+
},
63+
}
64+
}
65+
66+
func readSingularDatabaseAutonomousPatch(d *schema.ResourceData, m interface{}) error {
67+
sync := &DatabaseAutonomousPatchDataSourceCrud{}
68+
sync.D = d
69+
sync.Client = m.(*OracleClients).databaseClient()
70+
71+
return ReadResource(sync)
72+
}
73+
74+
type DatabaseAutonomousPatchDataSourceCrud struct {
75+
D *schema.ResourceData
76+
Client *oci_database.DatabaseClient
77+
Res *oci_database.GetAutonomousPatchResponse
78+
}
79+
80+
func (s *DatabaseAutonomousPatchDataSourceCrud) VoidState() {
81+
s.D.SetId("")
82+
}
83+
84+
func (s *DatabaseAutonomousPatchDataSourceCrud) Get() error {
85+
request := oci_database.GetAutonomousPatchRequest{}
86+
87+
if autonomousPatchId, ok := s.D.GetOkExists("autonomous_patch_id"); ok {
88+
tmp := autonomousPatchId.(string)
89+
request.AutonomousPatchId = &tmp
90+
}
91+
92+
request.RequestMetadata.RetryPolicy = getRetryPolicy(false, "database")
93+
94+
response, err := s.Client.GetAutonomousPatch(context.Background(), request)
95+
if err != nil {
96+
return err
97+
}
98+
99+
s.Res = &response
100+
return nil
101+
}
102+
103+
func (s *DatabaseAutonomousPatchDataSourceCrud) SetData() error {
104+
if s.Res == nil {
105+
return nil
106+
}
107+
108+
s.D.SetId(*s.Res.Id)
109+
110+
if s.Res.Description != nil {
111+
s.D.Set("description", *s.Res.Description)
112+
}
113+
114+
if s.Res.LifecycleDetails != nil {
115+
s.D.Set("lifecycle_details", *s.Res.LifecycleDetails)
116+
}
117+
118+
s.D.Set("patch_model", s.Res.PatchModel)
119+
120+
if s.Res.Quarter != nil {
121+
s.D.Set("quarter", *s.Res.Quarter)
122+
}
123+
124+
s.D.Set("state", s.Res.LifecycleState)
125+
126+
if s.Res.TimeReleased != nil {
127+
s.D.Set("time_released", s.Res.TimeReleased.String())
128+
}
129+
130+
if s.Res.Type != nil {
131+
s.D.Set("type", *s.Res.Type)
132+
}
133+
134+
if s.Res.Version != nil {
135+
s.D.Set("version", *s.Res.Version)
136+
}
137+
138+
if s.Res.Year != nil {
139+
s.D.Set("year", *s.Res.Year)
140+
}
141+
142+
return nil
143+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
2+
// Licensed under the Mozilla Public License v2.0
3+
4+
package oci
5+
6+
import (
7+
"fmt"
8+
"testing"
9+
10+
"github.com/hashicorp/terraform/helper/resource"
11+
"github.com/hashicorp/terraform/terraform"
12+
13+
"github.com/terraform-providers/terraform-provider-oci/httpreplay"
14+
)
15+
16+
var (
17+
autonomousPatchSingularDataSourceRepresentation = map[string]interface{}{
18+
"autonomous_patch_id": Representation{repType: Required, create: "LATEST"},
19+
}
20+
21+
AutonomousPatchResourceConfig = ""
22+
)
23+
24+
func TestDatabaseAutonomousPatchResource_basic(t *testing.T) {
25+
t.Skip("Skip this test till the MR resource test is skipped since the patch id is reliably fetched from MR resource")
26+
httpreplay.SetScenario("TestDatabaseAutonomousPatchResource_basic")
27+
defer httpreplay.SaveScenario()
28+
29+
provider := testAccProvider
30+
config := testProviderConfig()
31+
32+
compartmentId := getEnvSettingWithBlankDefault("compartment_ocid")
33+
compartmentIdVariableStr := fmt.Sprintf("variable \"compartment_id\" { default = \"%s\" }\n", compartmentId)
34+
35+
singularDatasourceName := "data.oci_database_autonomous_patch.test_autonomous_patch"
36+
37+
resource.Test(t, resource.TestCase{
38+
PreCheck: func() { testAccPreCheck(t) },
39+
Providers: map[string]terraform.ResourceProvider{
40+
"oci": provider,
41+
},
42+
Steps: []resource.TestStep{
43+
// verify singular datasource
44+
{
45+
Config: config +
46+
generateDataSourceFromRepresentationMap("oci_database_autonomous_patch", "test_autonomous_patch", Required, Create, autonomousPatchSingularDataSourceRepresentation) +
47+
compartmentIdVariableStr,
48+
Check: resource.ComposeAggregateTestCheckFunc(
49+
resource.TestCheckResourceAttrSet(singularDatasourceName, "autonomous_patch_id"),
50+
51+
resource.TestCheckResourceAttrSet(singularDatasourceName, "description"),
52+
resource.TestCheckResourceAttrSet(singularDatasourceName, "id"),
53+
resource.TestCheckResourceAttrSet(singularDatasourceName, "patch_model"),
54+
resource.TestCheckResourceAttrSet(singularDatasourceName, "quarter"),
55+
resource.TestCheckResourceAttrSet(singularDatasourceName, "state"),
56+
resource.TestCheckResourceAttrSet(singularDatasourceName, "time_released"),
57+
resource.TestCheckResourceAttrSet(singularDatasourceName, "type"),
58+
resource.TestCheckResourceAttrSet(singularDatasourceName, "version"),
59+
resource.TestCheckResourceAttrSet(singularDatasourceName, "year"),
60+
),
61+
},
62+
},
63+
})
64+
}

website/docs/d/database_autonomous_container_database.html.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ The following attributes are exported:
6464
* `preference` - The maintenance window scheduling preference.
6565
* `weeks_of_month` - Weeks during the month when maintenance should be performed. Weeks start on the 1st, 8th, 15th, and 22nd days of the month, and have a duration of 7 days. Weeks start and end based on calendar dates, not days of the week. For example, to allow maintenance during the 2nd week of the month (from the 8th day to the 14th day of the month), use the value 2. Maintenance cannot be scheduled for the fifth week of months that contain more than 28 days. Note that this parameter works in conjunction with the daysOfWeek and hoursOfDay parameters to allow you to specify specific days of the week and hours that maintenance will be performed.
6666
* `next_maintenance_run_id` - The [OCID](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm) of the next maintenance run.
67+
* `patch_id` - The [OCID](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm) of the last patch applied on the system.
6768
* `patch_model` - Database patch model preference.
6869
* `service_level_agreement_type` - The service level agreement type of the container database. The default is STANDARD.
6970
* `state` - The current state of the Autonomous Container Database.

website/docs/d/database_autonomous_container_databases.html.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ The following attributes are exported:
8585
* `preference` - The maintenance window scheduling preference.
8686
* `weeks_of_month` - Weeks during the month when maintenance should be performed. Weeks start on the 1st, 8th, 15th, and 22nd days of the month, and have a duration of 7 days. Weeks start and end based on calendar dates, not days of the week. For example, to allow maintenance during the 2nd week of the month (from the 8th day to the 14th day of the month), use the value 2. Maintenance cannot be scheduled for the fifth week of months that contain more than 28 days. Note that this parameter works in conjunction with the daysOfWeek and hoursOfDay parameters to allow you to specify specific days of the week and hours that maintenance will be performed.
8787
* `next_maintenance_run_id` - The [OCID](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm) of the next maintenance run.
88+
* `patch_id` - The [OCID](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm) of the last patch applied on the system.
8889
* `patch_model` - Database patch model preference.
8990
* `service_level_agreement_type` - The service level agreement type of the container database. The default is STANDARD.
9091
* `state` - The current state of the Autonomous Container Database.

website/docs/d/database_autonomous_database.html.markdown

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ The following attributes are exported:
6161
* `freeform_tags` - Free-form tags for this resource. Each tag is a simple key-value pair with no predefined name, type, or namespace. For more information, see [Resource Tags](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/resourcetags.htm). Example: `{"Department": "Finance"}`
6262
* `id` - The [OCID](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm) of the Autonomous Database.
6363
* `infrastructure_type` - The infrastructure type this resource belongs to.
64-
* `is_auto_scaling_enabled` - Indicates if auto scaling is enabled for the Autonomous Database CPU core count. Note that auto scaling is available for databases on [shared Exadata infrastructure](https://docs.cloud.oracle.com/iaas/Content/Database/Concepts/adboverview.htm#AEI) only.
64+
* `is_auto_scaling_enabled` - Indicates if auto scaling is enabled for the Autonomous Database CPU core count.
6565
* `is_data_guard_enabled` - Indicates whether the Autonomous Database has Data Guard enabled.
6666
* `is_dedicated` - True if the database uses [dedicated Exadata infrastructure](https://docs.cloud.oracle.com/iaas/Content/Database/Concepts/adbddoverview.htm).
6767
* `is_free_tier` - Indicates if this is an Always Free resource. The default value is false. Note that Always Free Autonomous Databases have 1 CPU and 20GB of memory. For Always Free databases, memory and CPU cannot be scaled.
@@ -106,5 +106,5 @@ The following attributes are exported:
106106
* `used_data_storage_size_in_tbs` - The amount of storage that has been used, in terabytes.
107107
* `whitelisted_ips` - The client IP access control list (ACL). This feature is available for databases on [shared Exadata infrastructure](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.
108108

109-
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"]`
109+
To add the whitelist VCN specific subnet or IP, use a semicoln ';' as a deliminator to add the VCN specific subnets or IPs. For update operation, if you wish to delete all the existing whitelisted IP’s, use an array with a single empty string entry. 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"]`
110110

0 commit comments

Comments
 (0)