Skip to content

Commit 77f68d4

Browse files
Mathias GoncalvesjiaqchenO
authored andcommitted
Added - Support for MySQL HeatWave Service: Customer email notification
1 parent 8c7f1d7 commit 77f68d4

File tree

7 files changed

+196
-0
lines changed

7 files changed

+196
-0
lines changed

examples/mysql/main.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,11 @@ resource "oci_mysql_mysql_db_system" "test_mysql_db_system" {
125125
is_delete_protected = "false"
126126
}
127127

128+
#Optional
129+
customer_contacts {
130+
131+
}
132+
128133
#Optional
129134
data_storage {
130135
is_auto_expand_storage_enabled = "false"
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
// Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved.
2+
3+
package integrationtest
4+
5+
import (
6+
"fmt"
7+
"testing"
8+
9+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
10+
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
11+
12+
"github.com/oracle/terraform-provider-oci/httpreplay"
13+
"github.com/oracle/terraform-provider-oci/internal/acctest"
14+
"github.com/oracle/terraform-provider-oci/internal/utils"
15+
)
16+
17+
var (
18+
mysqlDbSystemRepresentationWithCustomerContacts = map[string]interface{}{
19+
"admin_password": acctest.Representation{RepType: acctest.Required, Create: `BEstrO0ng_#11`},
20+
"admin_username": acctest.Representation{RepType: acctest.Required, Create: `adminUser`},
21+
"availability_domain": acctest.Representation{RepType: acctest.Required, Create: `${data.oci_identity_availability_domains.test_availability_domains.availability_domains.0.name}`},
22+
"compartment_id": acctest.Representation{RepType: acctest.Required, Create: `${var.compartment_id}`},
23+
"configuration_id": acctest.Representation{RepType: acctest.Optional, Create: `${var.MysqlConfigurationOCID[var.region]}`},
24+
"shape_name": acctest.Representation{RepType: acctest.Required, Create: `MySQL.VM.Standard.E3.1.8GB`},
25+
"subnet_id": acctest.Representation{RepType: acctest.Required, Create: `${oci_core_subnet.test_subnet.id}`},
26+
"data_storage_size_in_gb": acctest.Representation{RepType: acctest.Required, Create: `50`},
27+
"customer_contacts": acctest.RepresentationGroup{RepType: acctest.Optional, Group: MysqlMysqlDbSystemCustomerContacts},
28+
}
29+
30+
MysqlMysqlDbSystemCustomerContacts = map[string]interface{}{
31+
"email": acctest.Representation{RepType: acctest.Required, Create: `[email protected]`, Update: `[email protected]`},
32+
}
33+
)
34+
35+
// issue-routing-tag: mysql/default
36+
func TestMysqlMysqlDbSystemResource_customerContacts(t *testing.T) {
37+
httpreplay.SetScenario("TestMysqlMysqlDbSystemResource_customerContacts")
38+
defer httpreplay.SaveScenario()
39+
40+
config := acctest.ProviderTestConfig()
41+
42+
compartmentId := utils.GetEnvSettingWithBlankDefault("compartment_ocid")
43+
compartmentIdVariableStr := fmt.Sprintf("variable \"compartment_id\" { default = \"%s\" }\n", compartmentId)
44+
45+
resourceName := "oci_mysql_mysql_db_system.test_mysql_db_system"
46+
47+
var resId, resId2 string
48+
49+
acctest.ResourceTest(t, nil, []resource.TestStep{
50+
// verify Create with optional fields
51+
{
52+
Config: config + compartmentIdVariableStr + MysqlMysqlDbSystemResourceDependencies +
53+
acctest.GenerateResourceFromRepresentationMap("oci_mysql_mysql_db_system", "test_mysql_db_system", acctest.Optional, acctest.Create, mysqlDbSystemRepresentationWithCustomerContacts),
54+
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
55+
resource.TestCheckResourceAttr(resourceName, "customer_contacts.#", "1"),
56+
resource.TestCheckResourceAttr(resourceName, "customer_contacts.0.email", "[email protected]"),
57+
58+
func(s *terraform.State) (err error) {
59+
resId, err = acctest.FromInstanceState(s, resourceName, "id")
60+
return err
61+
},
62+
),
63+
},
64+
65+
// verify it is possible to change the customer contacts
66+
{
67+
Config: config + compartmentIdVariableStr + MysqlMysqlDbSystemResourceDependencies +
68+
acctest.GenerateResourceFromRepresentationMap("oci_mysql_mysql_db_system", "test_mysql_db_system", acctest.Optional, acctest.Update, mysqlDbSystemRepresentationWithCustomerContacts),
69+
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
70+
resource.TestCheckResourceAttr(resourceName, "customer_contacts.#", "1"),
71+
resource.TestCheckResourceAttr(resourceName, "customer_contacts.0.email", "[email protected]"),
72+
73+
func(s *terraform.State) (err error) {
74+
resId2, err = acctest.FromInstanceState(s, resourceName, "id")
75+
if resId != resId2 {
76+
return fmt.Errorf("Resource recreated when it was supposed to be updated.")
77+
}
78+
return err
79+
},
80+
),
81+
},
82+
})
83+
}

internal/service/mysql/mysql_mysql_db_system_data_source.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ func (s *MysqlMysqlDbSystemDataSourceCrud) SetData() error {
9898
s.D.Set("current_placement", nil)
9999
}
100100

101+
customerContacts := []interface{}{}
102+
for _, item := range s.Res.CustomerContacts {
103+
customerContacts = append(customerContacts, CustomerContactToMap(item))
104+
}
105+
s.D.Set("customer_contacts", customerContacts)
106+
101107
if s.Res.DataStorage != nil {
102108
s.D.Set("data_storage", []interface{}{DataStorageToMap(s.Res.DataStorage)})
103109
} else {

internal/service/mysql/mysql_mysql_db_system_resource.go

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,24 @@ func MysqlMysqlDbSystemResource() *schema.Resource {
180180
},
181181
},
182182
},
183+
"customer_contacts": {
184+
Type: schema.TypeList,
185+
Optional: true,
186+
Computed: true,
187+
Elem: &schema.Resource{
188+
Schema: map[string]*schema.Schema{
189+
// Required
190+
"email": {
191+
Type: schema.TypeString,
192+
Required: true,
193+
},
194+
195+
// Optional
196+
197+
// Computed
198+
},
199+
},
200+
},
183201
"data_storage_size_in_gb": {
184202
Type: schema.TypeInt,
185203
Optional: true,
@@ -937,6 +955,27 @@ func (s *MysqlMysqlDbSystemResourceCrud) Create() error {
937955
}
938956
}
939957

958+
if customerContacts, ok := s.D.GetOkExists("customer_contacts"); ok {
959+
interfaces := customerContacts.([]interface{})
960+
tmp := make([]oci_mysql.CustomerContact, len(interfaces))
961+
for i := range interfaces {
962+
stateDataIndex := i
963+
fieldKeyFormat := fmt.Sprintf("%s.%d.%%s", "customer_contacts", stateDataIndex)
964+
converted, err := s.mapToCustomerContact(fieldKeyFormat)
965+
if err != nil {
966+
return err
967+
}
968+
tmp[i] = converted
969+
}
970+
// customer_contacts should only be set if:
971+
// 1) some customer contacts are provided (not `nil`)
972+
// and
973+
// 2) the customer contacts have changed
974+
if tmp != nil && s.D.HasChange("customer_contacts") {
975+
request.CustomerContacts = tmp
976+
}
977+
}
978+
940979
if dataStorageSizeInGB, ok := s.D.GetOkExists("data_storage_size_in_gb"); ok {
941980
tmp := dataStorageSizeInGB.(int)
942981
request.DataStorageSizeInGBs = &tmp
@@ -1122,6 +1161,27 @@ func (s *MysqlMysqlDbSystemResourceCrud) Update() error {
11221161
}
11231162
}
11241163

1164+
if customerContacts, ok := s.D.GetOkExists("customer_contacts"); ok {
1165+
interfaces := customerContacts.([]interface{})
1166+
tmp := make([]oci_mysql.CustomerContact, len(interfaces))
1167+
for i := range interfaces {
1168+
stateDataIndex := i
1169+
fieldKeyFormat := fmt.Sprintf("%s.%d.%%s", "customer_contacts", stateDataIndex)
1170+
converted, err := s.mapToCustomerContact(fieldKeyFormat)
1171+
if err != nil {
1172+
return err
1173+
}
1174+
tmp[i] = converted
1175+
}
1176+
// customer_contacts should only be set if:
1177+
// 1) some customer contacts are provided (not `nil`)
1178+
// and
1179+
// 2) the customer contacts have changed
1180+
if tmp != nil && s.D.HasChange("customer_contacts") {
1181+
request.CustomerContacts = tmp
1182+
}
1183+
}
1184+
11251185
if dataStorageSizeInGB, ok := s.D.GetOkExists("data_storage_size_in_gb"); ok && s.D.HasChange("data_storage_size_in_gb") {
11261186
tmp := dataStorageSizeInGB.(int)
11271187
request.DataStorageSizeInGBs = &tmp
@@ -1257,6 +1317,12 @@ func (s *MysqlMysqlDbSystemResourceCrud) SetData() error {
12571317
s.D.Set("data_storage", nil)
12581318
}
12591319

1320+
customerContacts := []interface{}{}
1321+
for _, item := range s.Res.CustomerContacts {
1322+
customerContacts = append(customerContacts, CustomerContactToMap(item))
1323+
}
1324+
s.D.Set("customer_contacts", customerContacts)
1325+
12601326
if s.Res.DataStorageSizeInGBs != nil {
12611327
s.D.Set("data_storage_size_in_gb", *s.Res.DataStorageSizeInGBs)
12621328
}
@@ -1909,6 +1975,27 @@ func DataStorageToMap(obj *oci_mysql.DataStorage) map[string]interface{} {
19091975
return result
19101976
}
19111977

1978+
func (s *MysqlMysqlDbSystemResourceCrud) mapToCustomerContact(fieldKeyFormat string) (oci_mysql.CustomerContact, error) {
1979+
result := oci_mysql.CustomerContact{}
1980+
1981+
if email, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "email")); ok {
1982+
tmp := email.(string)
1983+
result.Email = &tmp
1984+
}
1985+
1986+
return result, nil
1987+
}
1988+
1989+
func CustomerContactToMap(obj oci_mysql.CustomerContact) map[string]interface{} {
1990+
result := map[string]interface{}{}
1991+
1992+
if obj.Email != nil {
1993+
result["email"] = string(*obj.Email)
1994+
}
1995+
1996+
return result
1997+
}
1998+
19121999
func DbSystemPlacementToMap(obj *oci_mysql.DbSystemPlacement) map[string]interface{} {
19132000
result := map[string]interface{}{}
19142001

website/docs/d/mysql_mysql_db_system.html.markdown

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ The following attributes are exported:
120120

121121
It is not possible to decrease data storage size. You cannot set the maximum data storage size to less than either current DB System dataStorageSizeInGBs or allocatedStorageSizeInGBs.
122122
* `data_storage_size_in_gb` - DEPRECATED: User specified size of the data volume. May be less than current allocatedStorageSizeInGBs. Replaced by dataStorage.dataStorageSizeInGBs.
123+
* `customer_contacts` - The list of customer email addresses that receive information from Oracle about the specified Oracle Cloud Infrastructure DB System resource. Oracle uses these email addresses to send notifications about planned and unplanned software maintenance updates, information about system hardware, and other information needed by administrators. Up to 10 email addresses can be added to the customer contacts for a DB System.
124+
* `email` - The email address used by Oracle to send notifications regarding the DB System.
125+
* `data_storage_size_in_gb` - Initial size of the data volume in GiBs that will be created and attached.
123126
* `database_management` - Whether to enable monitoring via the Database Management service.
124127
* `defined_tags` - Defined tags for this resource. Each key is predefined and scoped to a namespace. Example: `{"foo-namespace.bar-key": "value"}`
125128
* `deletion_policy` - The Deletion policy for the DB System.

website/docs/d/mysql_mysql_db_systems.html.markdown

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@ The following attributes are exported:
144144

145145
It is not possible to decrease data storage size. You cannot set the maximum data storage size to less than either current DB System dataStorageSizeInGBs or allocatedStorageSizeInGBs.
146146
* `data_storage_size_in_gb` - DEPRECATED: User specified size of the data volume. May be less than current allocatedStorageSizeInGBs. Replaced by dataStorage.dataStorageSizeInGBs.
147+
* `customer_contacts` - The list of customer email addresses that receive information from Oracle about the specified Oracle Cloud Infrastructure DB System resource. Oracle uses these email addresses to send notifications about planned and unplanned software maintenance updates, information about system hardware, and other information needed by administrators. Up to 10 email addresses can be added to the customer contacts for a DB System.
148+
* `email` - The email address used by Oracle to send notifications regarding the DB System.
149+
* `data_storage_size_in_gb` - Initial size of the data volume in GiBs that will be created and attached.
147150
* `database_management` - Whether to enable monitoring via the Database Management service.
148151
* `defined_tags` - Defined tags for this resource. Each key is predefined and scoped to a namespace. Example: `{"foo-namespace.bar-key": "value"}`
149152
* `deletion_policy` - The Deletion policy for the DB System.

website/docs/r/mysql_mysql_db_system.html.markdown

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ resource "oci_mysql_mysql_db_system" "test_mysql_db_system" {
4141
}
4242
configuration_id = oci_audit_configuration.test_configuration.id
4343
crash_recovery = var.mysql_db_system_crash_recovery
44+
customer_contacts {
45+
#Required
46+
email = var.mysql_db_system_customer_contacts_email
47+
}
4448
data_storage {
4549
4650
#Optional
@@ -129,6 +133,8 @@ The following arguments are supported:
129133
DB Systems with an initial storage size of 400 GB or less can be expanded up to 32 TB. DB Systems with an initial storage size between 401-800 GB can be expanded up to 64 TB. DB Systems with an initial storage size between 801-1200 GB can be expanded up to 96 TB. DB Systems with an initial storage size of 1201 GB or more can be expanded up to 128 TB.
130134

131135
It is not possible to decrease data storage size. You cannot set the maximum data storage size to less than either current DB System dataStorageSizeInGBs or allocatedStorageSizeInGBs.
136+
* `customer_contacts` - (Optional) (Updatable) The list of customer email addresses that receive information from Oracle about the specified Oracle Cloud Infrastructure DB System resource. Oracle uses these email addresses to send notifications about planned and unplanned software maintenance updates, information about system hardware, and other information needed by administrators. Up to 10 email addresses can be added to the customer contacts for a DB System.
137+
* `email` - (Required) (Updatable) The email address used by Oracle to send notifications regarding the DB System.
132138
* `data_storage_size_in_gb` - (Optional) (Updatable) Initial size of the data volume in GBs that will be created and attached. Keep in mind that this only specifies the size of the database data volume, the log volume for the database will be scaled appropriately with its shape. It is required if you are creating a new database. It cannot be set if you are creating a database from a backup.
133139
* `database_management` - (Optional) (Updatable) Whether to enable monitoring via the Database Management service.
134140
* `defined_tags` - (Optional) (Updatable) Usage of predefined tag keys. These predefined keys are scoped to namespaces. Example: `{"foo-namespace.bar-key": "value"}`
@@ -276,6 +282,9 @@ The following attributes are exported:
276282

277283
It is not possible to decrease data storage size. You cannot set the maximum data storage size to less than either current DB System dataStorageSizeInGBs or allocatedStorageSizeInGBs.
278284
* `data_storage_size_in_gb` - DEPRECATED: User specified size of the data volume. May be less than current allocatedStorageSizeInGBs. Replaced by dataStorage.dataStorageSizeInGBs.
285+
* `customer_contacts` - The list of customer email addresses that receive information from Oracle about the specified Oracle Cloud Infrastructure DB System resource. Oracle uses these email addresses to send notifications about planned and unplanned software maintenance updates, information about system hardware, and other information needed by administrators. Up to 10 email addresses can be added to the customer contacts for a DB System.
286+
* `email` - The email address used by Oracle to send notifications regarding the DB System.
287+
* `data_storage_size_in_gb` - Initial size of the data volume in GiBs that will be created and attached.
279288
* `database_management` - Whether to enable monitoring via the Database Management service.
280289
* `defined_tags` - Defined tags for this resource. Each key is predefined and scoped to a namespace. Example: `{"foo-namespace.bar-key": "value"}`
281290
* `deletion_policy` - The Deletion policy for the DB System.

0 commit comments

Comments
 (0)