Skip to content

Commit d87fcf9

Browse files
Vinicius MonteiroMaxrovr
authored andcommitted
Added - Support for change hostname label to be updatable
1 parent 1ddc7e6 commit d87fcf9

File tree

3 files changed

+58
-2
lines changed

3 files changed

+58
-2
lines changed

internal/integrationtest/mysql_mysql_db_system_resource_test.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -901,3 +901,55 @@ func TestMysqlMysqlDbSystemResource_secureConnections(t *testing.T) {
901901
},
902902
})
903903
}
904+
905+
func TestMysqlMysqlDbSystemResource_hostnameLabel(t *testing.T) {
906+
httpreplay.SetScenario("TestMysqlMysqlDbSystemResource_hostnameLabel")
907+
defer httpreplay.SaveScenario()
908+
909+
config := acctest.ProviderTestConfig()
910+
911+
compartmentId := utils.GetEnvSettingWithBlankDefault("compartment_ocid")
912+
compartmentIdVariableStr := fmt.Sprintf("variable \"compartment_id\" { default = \"%s\" }\n", compartmentId)
913+
914+
resourceName := "oci_mysql_mysql_db_system.test_mysql_db_system"
915+
916+
var resId, resId2 string
917+
918+
updatedRepresentation := acctest.GetUpdatedRepresentationCopy("hostname_label", acctest.Representation{RepType: acctest.Optional, Create: `hostnameLabel`, Update: `hostnameLabel2`},
919+
acctest.RepresentationCopyWithNewProperties(MysqlMysqlDbSystemRepresentation, map[string]interface{}{
920+
"backup_policy": acctest.RepresentationGroup{RepType: acctest.Optional, Group: MysqlDbSystemBackupPolicyNotUpdateableRepresentation},
921+
}))
922+
923+
acctest.ResourceTest(t, nil, []resource.TestStep{
924+
// verify Create with hostname_label
925+
{
926+
Config: config + compartmentIdVariableStr + MysqlDbSystemSourceBackupResourceDependencies +
927+
acctest.GenerateResourceFromRepresentationMap("oci_mysql_mysql_db_system", "test_mysql_db_system", acctest.Optional, acctest.Create, updatedRepresentation),
928+
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
929+
resource.TestCheckResourceAttr(resourceName, "hostname_label", "hostnameLabel"),
930+
931+
func(s *terraform.State) (err error) {
932+
resId, err = acctest.FromInstanceState(s, resourceName, "id")
933+
return err
934+
},
935+
),
936+
},
937+
938+
// verify update to hostname_label
939+
{
940+
Config: config + compartmentIdVariableStr + MysqlDbSystemSourceBackupResourceDependencies +
941+
acctest.GenerateResourceFromRepresentationMap("oci_mysql_mysql_db_system", "test_mysql_db_system", acctest.Optional, acctest.Update, updatedRepresentation),
942+
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
943+
resource.TestCheckResourceAttr(resourceName, "hostname_label", "hostnameLabel2"),
944+
945+
func(s *terraform.State) (err error) {
946+
resId2, err = acctest.FromInstanceState(s, resourceName, "id")
947+
if resId != resId2 {
948+
return fmt.Errorf("Resource recreated when it was supposed to be updated.")
949+
}
950+
return err
951+
},
952+
),
953+
},
954+
})
955+
}

internal/service/mysql/mysql_mysql_db_system_resource.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,6 @@ func MysqlMysqlDbSystemResource() *schema.Resource {
270270
Type: schema.TypeString,
271271
Optional: true,
272272
Computed: true,
273-
ForceNew: true,
274273
},
275274
"ip_address": {
276275
Type: schema.TypeString,
@@ -1224,6 +1223,11 @@ func (s *MysqlMysqlDbSystemResourceCrud) Update() error {
12241223
request.FreeformTags = tfresource.ObjectMapToStringMap(freeformTags.(map[string]interface{}))
12251224
}
12261225

1226+
if hostnameLabel, ok := s.D.GetOkExists("hostname_label"); ok && s.D.HasChange("hostname_label") {
1227+
tmp := hostnameLabel.(string)
1228+
request.HostnameLabel = &tmp
1229+
}
1230+
12271231
if isHighlyAvailable, ok := s.D.GetOkExists("is_highly_available"); ok && s.D.HasChange("is_highly_available") {
12281232
tmp := isHighlyAvailable.(bool)
12291233
request.IsHighlyAvailable = &tmp

website/docs/r/mysql_mysql_db_system.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ The following arguments are supported:
150150

151151
For a standalone DB System, this defines the fault domain in which the DB System is placed.
152152
* `freeform_tags` - (Optional) (Updatable) Simple key-value pair applied without any predefined name, type or scope. Exists for cross-compatibility only. Example: `{"bar-key": "value"}`
153-
* `hostname_label` - (Optional) The hostname for the primary endpoint of the DB System. Used for DNS.
153+
* `hostname_label` - (Optional) (Updatable) The hostname for the primary endpoint of the DB System. Used for DNS.
154154

155155
The value is the hostname portion of the primary private IP's fully qualified domain name (FQDN) (for example, "dbsystem-1" in FQDN "dbsystem-1.subnet123.vcn1.oraclevcn.com").
156156

0 commit comments

Comments
 (0)