Skip to content

Commit 41553c2

Browse files
committed
convert public access attrib to arg
1 parent df7190c commit 41553c2

File tree

3 files changed

+35
-10
lines changed

3 files changed

+35
-10
lines changed

internal/services/mysql/mysql_flexible_server_configuration_resource_test.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -275,13 +275,14 @@ resource "azurerm_resource_group" "test" {
275275
}
276276
277277
resource "azurerm_mysql_flexible_server" "test" {
278-
name = "acctest-fs-%d"
279-
resource_group_name = azurerm_resource_group.test.name
280-
location = azurerm_resource_group.test.location
281-
administrator_login = "adminTerraform"
282-
administrator_password = "QAZwsx123"
283-
sku_name = "B_Standard_B1s"
284-
zone = "1"
278+
name = "acctest-fs-%d"
279+
resource_group_name = azurerm_resource_group.test.name
280+
location = azurerm_resource_group.test.location
281+
administrator_login = "adminTerraform"
282+
administrator_password = "QAZwsx123"
283+
public_network_access_enabled = false
284+
sku_name = "B_Standard_B1s"
285+
zone = "1"
285286
}
286287
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger)
287288
}

internal/services/mysql/mysql_flexible_server_resource.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,8 @@ func resourceMysqlFlexibleServer() *pluginsdk.Resource {
298298

299299
"public_network_access_enabled": {
300300
Type: pluginsdk.TypeBool,
301-
Computed: true,
301+
Default: true,
302+
Optional: true,
302303
},
303304

304305
"replica_capacity": {
@@ -412,6 +413,16 @@ func resourceMysqlFlexibleServerCreate(d *pluginsdk.ResourceData, meta interface
412413
parameters.Properties.SourceServerResourceId = utils.String(v.(string))
413414
}
414415

416+
if v, ok := d.GetOk("public_network_access_enabled"); ok {
417+
var publicNetworkAccess servers.EnableStatusEnum
418+
if v.(bool) {
419+
publicNetworkAccess = servers.EnableStatusEnumEnabled
420+
} else {
421+
publicNetworkAccess = servers.EnableStatusEnumDisabled
422+
}
423+
parameters.Properties.Network.PublicNetworkAccess = pointer.To(publicNetworkAccess)
424+
}
425+
415426
pointInTimeUTC := d.Get("point_in_time_restore_time_in_utc").(string)
416427
if pointInTimeUTC != "" {
417428
v, err := time.Parse(time.RFC3339, pointInTimeUTC)
@@ -706,6 +717,19 @@ func resourceMysqlFlexibleServerUpdate(d *pluginsdk.ResourceData, meta interface
706717
parameters.Tags = tags.Expand(d.Get("tags").(map[string]interface{}))
707718
}
708719

720+
if d.HasChange("public_network_access_enabled") {
721+
var publicNetworkAccess servers.EnableStatusEnum
722+
if d.Get("public_network_access_enabled").(bool) {
723+
publicNetworkAccess = servers.EnableStatusEnumEnabled
724+
} else {
725+
publicNetworkAccess = servers.EnableStatusEnumDisabled
726+
}
727+
if parameters.Properties.Network == nil {
728+
parameters.Properties.Network = &servers.Network{}
729+
}
730+
parameters.Properties.Network.PublicNetworkAccess = pointer.To(publicNetworkAccess)
731+
}
732+
709733
if err := client.UpdateThenPoll(ctx, *id, parameters); err != nil {
710734
return fmt.Errorf("updating %s: %+v", *id, err)
711735
}

website/docs/r/mysql_flexible_server.html.markdown

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ The following arguments are supported:
115115

116116
~> **NOTE:** The `private_dns_zone_id` is required when setting a `delegated_subnet_id`. The `azurerm_private_dns_zone` should end with suffix `.mysql.database.azure.com`.
117117

118+
* `public_network_access_enabled` - (Optional) Is the public network access enabled? Defaults to `true`.
119+
118120
* `replication_role` - (Optional) The replication role. Possible value is `None`.
119121

120122
~> **NOTE:** The `replication_role` cannot be set while creating and only can be updated from `Replica` to `None`.
@@ -205,8 +207,6 @@ In addition to the Arguments listed above - the following Attributes are exporte
205207

206208
* `fqdn` - The fully qualified domain name of the MySQL Flexible Server.
207209

208-
* `public_network_access_enabled` - Is the public network access enabled?
209-
210210
* `replica_capacity` - The maximum number of replicas that a primary MySQL Flexible Server can have.
211211

212212
## Timeouts

0 commit comments

Comments
 (0)