Skip to content

Commit

Permalink
azurerm_mssql_server - support public_network_access_enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
katbyte committed Apr 29, 2020
1 parent 9104e81 commit 2dc96b1
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 211 deletions.
29 changes: 21 additions & 8 deletions azurerm/internal/services/mssql/resource_arm_mssql_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ func resourceArmMsSqlServer() *schema.Resource {
},
},

"public_network_access_enabled": {
Type: schema.TypeBool,
Optional: true,
Default: true,
},

"extended_auditing_policy": helper.ExtendedAuditingSchema(),

"fully_qualified_domain_name": {
Expand Down Expand Up @@ -148,26 +154,32 @@ func resourceArmMsSqlServerCreateUpdate(d *schema.ResourceData, meta interface{}
}
}

parameters := sql.Server{
props := sql.Server{
Location: utils.String(location),
Tags: metadata,
ServerProperties: &sql.ServerProperties{
Version: utils.String(version),
AdministratorLogin: utils.String(adminUsername),
PublicNetworkAccess: sql.ServerPublicNetworkAccessEnabled,
},
}

if _, ok := d.GetOk("identity"); ok {
sqlServerIdentity := expandAzureRmSqlServerIdentity(d)
parameters.Identity = sqlServerIdentity
props.Identity = sqlServerIdentity
}

if v := d.Get("public_network_access_enabled"); !v.(bool) {
props.ServerProperties.PublicNetworkAccess = sql.ServerPublicNetworkAccessDisabled
}


if d.HasChange("administrator_login_password") {
adminPassword := d.Get("administrator_login_password").(string)
parameters.ServerProperties.AdministratorLoginPassword = utils.String(adminPassword)
props.ServerProperties.AdministratorLoginPassword = utils.String(adminPassword)
}

future, err := client.CreateOrUpdate(ctx, resGroup, name, parameters)
future, err := client.CreateOrUpdate(ctx, resGroup, name, props)
if err != nil {
return fmt.Errorf("Error issuing create/update request for SQL Server %q (Resource Group %q): %+v", name, resGroup, err)
}
Expand Down Expand Up @@ -242,10 +254,11 @@ func resourceArmMsSqlServerRead(d *schema.ResourceData, meta interface{}) error
return fmt.Errorf("Error setting `identity`: %+v", err)
}

if serverProperties := resp.ServerProperties; serverProperties != nil {
d.Set("version", serverProperties.Version)
d.Set("administrator_login", serverProperties.AdministratorLogin)
d.Set("fully_qualified_domain_name", serverProperties.FullyQualifiedDomainName)
if props := resp.ServerProperties; props != nil {
d.Set("version", props.Version)
d.Set("administrator_login", props.AdministratorLogin)
d.Set("fully_qualified_domain_name", props.FullyQualifiedDomainName)
d.Set("public_network_access_enabled", props.PublicNetworkAccess == sql.ServerPublicNetworkAccessEnabled)
}

connection, err := connectionClient.Get(ctx, resGroup, name)
Expand Down
Loading

0 comments on commit 2dc96b1

Please sign in to comment.