From 691a82956c57c7939fecbdda6c2318a692aff6da Mon Sep 17 00:00:00 2001 From: yupwei68 Date: Wed, 10 Jun 2020 10:05:19 +0800 Subject: [PATCH 1/6] update --- .../services/mysql/mysql_server_resource.go | 31 +++++++++++-------- .../mysql/tests/mysql_server_resource_test.go | 3 +- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/azurerm/internal/services/mysql/mysql_server_resource.go b/azurerm/internal/services/mysql/mysql_server_resource.go index 7cc3d8364401..3d2a5ca569a9 100644 --- a/azurerm/internal/services/mysql/mysql_server_resource.go +++ b/azurerm/internal/services/mysql/mysql_server_resource.go @@ -169,23 +169,24 @@ func resourceArmMySqlServer() *schema.Resource { }, "ssl_enforcement": { - Type: schema.TypeString, - Optional: true, - Computed: true, - Deprecated: "this has been moved to the boolean attribute `ssl_enforcement_enabled` and will be removed in version 3.0 of the provider.", - ExactlyOneOf: []string{"ssl_enforcement", "ssl_enforcement_enabled"}, + Type: schema.TypeString, + Optional: true, + Computed: true, + Deprecated: "this has been moved to the boolean attribute `ssl_enforcement_enabled` and will be removed in version 3.0 of the provider.", + //ExactlyOneOf: []string{"ssl_enforcement", "ssl_enforcement_enabled"}, ValidateFunc: validation.StringInSlice([]string{ string(mysql.SslEnforcementEnumDisabled), string(mysql.SslEnforcementEnumEnabled), }, true), DiffSuppressFunc: suppress.CaseDifference, + ConflictsWith: []string{"ssl_enforcement_enabled"}, }, "ssl_enforcement_enabled": { - Type: schema.TypeBool, - Optional: true, // required in 3.0 - Computed: true, // remove computed in 3.0 - ExactlyOneOf: []string{"ssl_enforcement", "ssl_enforcement_enabled"}, + Type: schema.TypeBool, + Optional: true, // required in 3.0 + Computed: true, // remove computed in 3.0 + ConflictsWith: []string{"ssl_enforcement"}, }, "ssl_minimal_tls_version_enforced": { @@ -478,11 +479,15 @@ func resourceArmMySqlServerUpdate(d *schema.ResourceData, meta interface{}) erro } ssl := mysql.SslEnforcementEnumEnabled - if v := d.Get("ssl_enforcement"); strings.EqualFold(v.(string), string(mysql.SslEnforcementEnumDisabled)) { - ssl = mysql.SslEnforcementEnumDisabled + if d.HasChange("ssl_enforcement") { + if v, ok := d.GetOk("ssl_enforcement"); ok && strings.EqualFold(v.(string), string(mysql.SslEnforcementEnumDisabled)) { + ssl = mysql.SslEnforcementEnumDisabled + } } - if v := d.Get("ssl_enforcement_enabled").(bool); !v { - ssl = mysql.SslEnforcementEnumDisabled + if d.HasChange("ssl_enforcement_enabled") { + if v, ok := d.GetOkExists("ssl_enforcement_enabled"); ok && !v.(bool) { + ssl = mysql.SslEnforcementEnumDisabled + } } storageProfile := expandMySQLStorageProfile(d) diff --git a/azurerm/internal/services/mysql/tests/mysql_server_resource_test.go b/azurerm/internal/services/mysql/tests/mysql_server_resource_test.go index 645cd296f6a7..54fd145da266 100644 --- a/azurerm/internal/services/mysql/tests/mysql_server_resource_test.go +++ b/azurerm/internal/services/mysql/tests/mysql_server_resource_test.go @@ -464,7 +464,7 @@ resource "azurerm_mysql_server" "test" { backup_retention_days = 7 create_mode = "Default" geo_redundant_backup_enabled = false - ssl_enforcement_enabled = true + ssl_enforcement_enabled = false storage_mb = 51200 version = "%s" } @@ -594,6 +594,7 @@ resource "azurerm_mysql_server" "replica" { create_mode = "Replica" creation_source_server_id = azurerm_mysql_server.test.id ssl_enforcement_enabled = true + storage_mb = 51200 } `, testAccAzureRMMySQLServer_basic(data, version), data.RandomInteger, version) } From 49d9533126ca3a94629e9e08b92ef7830e1d5bd4 Mon Sep 17 00:00:00 2001 From: yupwei68 Date: Fri, 12 Jun 2020 11:06:06 +0800 Subject: [PATCH 2/6] ri --- .../internal/services/mssql/client/client.go | 1 + .../services/mysql/mysql_server_resource.go | 19 +++++++++---------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/azurerm/internal/services/mssql/client/client.go b/azurerm/internal/services/mssql/client/client.go index 9c3f834b3823..76f75ca72eae 100644 --- a/azurerm/internal/services/mssql/client/client.go +++ b/azurerm/internal/services/mssql/client/client.go @@ -19,6 +19,7 @@ type Client struct { ServerSecurityAlertPoliciesClient *sql.ServerSecurityAlertPoliciesClient ServerVulnerabilityAssessmentsClient *sql.ServerVulnerabilityAssessmentsClient VirtualMachinesClient *sqlvirtualmachine.SQLVirtualMachinesClient + *sql.FirewallRulesClient } func NewClient(o *common.ClientOptions) *Client { diff --git a/azurerm/internal/services/mysql/mysql_server_resource.go b/azurerm/internal/services/mysql/mysql_server_resource.go index 3d2a5ca569a9..875c2a21f4d3 100644 --- a/azurerm/internal/services/mysql/mysql_server_resource.go +++ b/azurerm/internal/services/mysql/mysql_server_resource.go @@ -169,24 +169,23 @@ func resourceArmMySqlServer() *schema.Resource { }, "ssl_enforcement": { - Type: schema.TypeString, - Optional: true, - Computed: true, - Deprecated: "this has been moved to the boolean attribute `ssl_enforcement_enabled` and will be removed in version 3.0 of the provider.", - //ExactlyOneOf: []string{"ssl_enforcement", "ssl_enforcement_enabled"}, + Type: schema.TypeString, + Optional: true, + Computed: true, + Deprecated: "this has been moved to the boolean attribute `ssl_enforcement_enabled` and will be removed in version 3.0 of the provider.", + ExactlyOneOf: []string{"ssl_enforcement", "ssl_enforcement_enabled"}, ValidateFunc: validation.StringInSlice([]string{ string(mysql.SslEnforcementEnumDisabled), string(mysql.SslEnforcementEnumEnabled), }, true), DiffSuppressFunc: suppress.CaseDifference, - ConflictsWith: []string{"ssl_enforcement_enabled"}, }, "ssl_enforcement_enabled": { - Type: schema.TypeBool, - Optional: true, // required in 3.0 - Computed: true, // remove computed in 3.0 - ConflictsWith: []string{"ssl_enforcement"}, + Type: schema.TypeBool, + Optional: true, // required in 3.0 + Computed: true, // remove computed in 3.0 + ExactlyOneOf: []string{"ssl_enforcement", "ssl_enforcement_enabled"}, }, "ssl_minimal_tls_version_enforced": { From 230d67393bc548e5f6cf19834271c22ce33836d8 Mon Sep 17 00:00:00 2001 From: yupwei68 Date: Fri, 12 Jun 2020 11:27:38 +0800 Subject: [PATCH 3/6] clear code --- azurerm/internal/services/mssql/client/client.go | 1 - 1 file changed, 1 deletion(-) diff --git a/azurerm/internal/services/mssql/client/client.go b/azurerm/internal/services/mssql/client/client.go index 76f75ca72eae..9c3f834b3823 100644 --- a/azurerm/internal/services/mssql/client/client.go +++ b/azurerm/internal/services/mssql/client/client.go @@ -19,7 +19,6 @@ type Client struct { ServerSecurityAlertPoliciesClient *sql.ServerSecurityAlertPoliciesClient ServerVulnerabilityAssessmentsClient *sql.ServerVulnerabilityAssessmentsClient VirtualMachinesClient *sqlvirtualmachine.SQLVirtualMachinesClient - *sql.FirewallRulesClient } func NewClient(o *common.ClientOptions) *Client { From c5f7efa2949b00a8cf988cc2458bf86789c33269 Mon Sep 17 00:00:00 2001 From: yupwei68 Date: Fri, 10 Jul 2020 11:25:49 +0800 Subject: [PATCH 4/6] update --- .../services/mysql/mysql_server_resource.go | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/azurerm/internal/services/mysql/mysql_server_resource.go b/azurerm/internal/services/mysql/mysql_server_resource.go index 533979fe67d6..05e53ac8bbbd 100644 --- a/azurerm/internal/services/mysql/mysql_server_resource.go +++ b/azurerm/internal/services/mysql/mysql_server_resource.go @@ -184,7 +184,6 @@ func resourceArmMySqlServer() *schema.Resource { "ssl_enforcement_enabled": { Type: schema.TypeBool, Optional: true, // required in 3.0 - Computed: true, // remove computed in 3.0 ExactlyOneOf: []string{"ssl_enforcement", "ssl_enforcement_enabled"}, }, @@ -409,10 +408,7 @@ func resourceArmMySqlServerCreate(d *schema.ResourceData, meta interface{}) erro } ssl := mysql.SslEnforcementEnumEnabled - if v, ok := d.GetOk("ssl_enforcement"); ok && strings.EqualFold(v.(string), string(mysql.SslEnforcementEnumDisabled)) { - ssl = mysql.SslEnforcementEnumDisabled - } - if v, ok := d.GetOkExists("ssl_enforcement_enabled"); ok && !v.(bool) { + if v := d.Get("ssl_enforcement_enabled"); !v.(bool) { ssl = mysql.SslEnforcementEnumDisabled } @@ -560,15 +556,8 @@ func resourceArmMySqlServerUpdate(d *schema.ResourceData, meta interface{}) erro } ssl := mysql.SslEnforcementEnumEnabled - if d.HasChange("ssl_enforcement") { - if v, ok := d.GetOk("ssl_enforcement"); ok && strings.EqualFold(v.(string), string(mysql.SslEnforcementEnumDisabled)) { - ssl = mysql.SslEnforcementEnumDisabled - } - } - if d.HasChange("ssl_enforcement_enabled") { - if v, ok := d.GetOkExists("ssl_enforcement_enabled"); ok && !v.(bool) { - ssl = mysql.SslEnforcementEnumDisabled - } + if v := d.Get("ssl_enforcement_enabled").(bool); !v { + ssl = mysql.SslEnforcementEnumDisabled } storageProfile := expandMySQLStorageProfile(d) From 917fcc324905404bc86619786cd47fda7bc0f48a Mon Sep 17 00:00:00 2001 From: yupwei68 Date: Fri, 10 Jul 2020 15:05:04 +0800 Subject: [PATCH 5/6] update --- .../services/mysql/mysql_server_resource.go | 1 + .../mysql/tests/mysql_server_resource_test.go | 28 +++++++++---------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/azurerm/internal/services/mysql/mysql_server_resource.go b/azurerm/internal/services/mysql/mysql_server_resource.go index 05e53ac8bbbd..b52b6cef5c2b 100644 --- a/azurerm/internal/services/mysql/mysql_server_resource.go +++ b/azurerm/internal/services/mysql/mysql_server_resource.go @@ -567,6 +567,7 @@ func resourceArmMySqlServerUpdate(d *schema.ResourceData, meta interface{}) erro AdministratorLoginPassword: utils.String(d.Get("administrator_login_password").(string)), PublicNetworkAccess: publicAccess, SslEnforcement: ssl, + MinimalTLSVersion: mysql.MinimalTLSVersionEnum(d.Get("ssl_minimal_tls_version_enforced").(string)), StorageProfile: storageProfile, Version: mysql.ServerVersion(d.Get("version").(string)), }, diff --git a/azurerm/internal/services/mysql/tests/mysql_server_resource_test.go b/azurerm/internal/services/mysql/tests/mysql_server_resource_test.go index ff9407cb04ab..1bed3fbe3528 100644 --- a/azurerm/internal/services/mysql/tests/mysql_server_resource_test.go +++ b/azurerm/internal/services/mysql/tests/mysql_server_resource_test.go @@ -505,19 +505,20 @@ resource "azurerm_storage_account" "test" { } resource "azurerm_mysql_server" "test" { - name = "acctestmysqlsvr-%[1]d" - location = azurerm_resource_group.test.location - resource_group_name = azurerm_resource_group.test.name - sku_name = "GP_Gen5_2" - administrator_login = "acctestun" - administrator_login_password = "H@Sh1CoR3!updated" - auto_grow_enabled = true - backup_retention_days = 7 - create_mode = "Default" - geo_redundant_backup_enabled = false - ssl_enforcement_enabled = true - storage_mb = 51200 - version = "%[3]s" + name = "acctestmysqlsvr-%[1]d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + sku_name = "GP_Gen5_2" + administrator_login = "acctestun" + administrator_login_password = "H@Sh1CoR3!updated" + auto_grow_enabled = true + backup_retention_days = 7 + create_mode = "Default" + geo_redundant_backup_enabled = false + ssl_enforcement_enabled = true + ssl_minimal_tls_version_enforced = "TLS1_1" + storage_mb = 51200 + version = "%[3]s" threat_detection_policy { enabled = true disabled_alerts = ["Sql_Injection"] @@ -655,7 +656,6 @@ resource "azurerm_mysql_server" "replica" { create_mode = "Replica" creation_source_server_id = azurerm_mysql_server.test.id ssl_enforcement_enabled = true - storage_mb = 51200 } `, testAccAzureRMMySQLServer_basic(data, version), data.RandomInteger, version) } From bca369e5b4569f474a7540988087ef5fc2f23ada Mon Sep 17 00:00:00 2001 From: yupwei68 Date: Fri, 10 Jul 2020 17:19:04 +0800 Subject: [PATCH 6/6] update tests --- .../mysql/tests/mysql_server_resource_test.go | 109 +++++++++--------- 1 file changed, 57 insertions(+), 52 deletions(-) diff --git a/azurerm/internal/services/mysql/tests/mysql_server_resource_test.go b/azurerm/internal/services/mysql/tests/mysql_server_resource_test.go index 1bed3fbe3528..27c8b3566960 100644 --- a/azurerm/internal/services/mysql/tests/mysql_server_resource_test.go +++ b/azurerm/internal/services/mysql/tests/mysql_server_resource_test.go @@ -406,15 +406,16 @@ resource "azurerm_resource_group" "test" { } resource "azurerm_mysql_server" "test" { - name = "acctestmysqlsvr-%d" - location = azurerm_resource_group.test.location - resource_group_name = azurerm_resource_group.test.name - sku_name = "GP_Gen5_2" - administrator_login = "acctestun" - administrator_login_password = "H@Sh1CoR3!" - ssl_enforcement_enabled = true - storage_mb = 51200 - version = "%s" + name = "acctestmysqlsvr-%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + sku_name = "GP_Gen5_2" + administrator_login = "acctestun" + administrator_login_password = "H@Sh1CoR3!" + ssl_enforcement_enabled = true + ssl_minimal_tls_version_enforced = "TLS1_1" + storage_mb = 51200 + version = "%s" } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, version) } @@ -441,10 +442,11 @@ resource "azurerm_mysql_server" "test" { storage_mb = 51200 } - administrator_login = "acctestun" - administrator_login_password = "H@Sh1CoR3!" - version = "%s" - ssl_enforcement_enabled = true + administrator_login = "acctestun" + administrator_login_password = "H@Sh1CoR3!" + version = "%s" + ssl_enforcement_enabled = true + ssl_minimal_tls_version_enforced = "TLS1_1" } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, version) } @@ -461,19 +463,20 @@ resource "azurerm_resource_group" "test" { } resource "azurerm_mysql_server" "test" { - name = "acctestmysqlsvr-%[1]d" - location = azurerm_resource_group.test.location - resource_group_name = azurerm_resource_group.test.name - sku_name = "GP_Gen5_2" - administrator_login = "acctestun" - administrator_login_password = "H@Sh1CoR3!" - auto_grow_enabled = true - backup_retention_days = 7 - create_mode = "Default" - geo_redundant_backup_enabled = false - ssl_enforcement_enabled = false - storage_mb = 51200 - version = "%[3]s" + name = "acctestmysqlsvr-%[1]d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + sku_name = "GP_Gen5_2" + administrator_login = "acctestun" + administrator_login_password = "H@Sh1CoR3!" + auto_grow_enabled = true + backup_retention_days = 7 + create_mode = "Default" + geo_redundant_backup_enabled = false + ssl_enforcement_enabled = true + ssl_minimal_tls_version_enforced = "TLS1_2" + storage_mb = 51200 + version = "%[3]s" threat_detection_policy { enabled = true disabled_alerts = ["Sql_Injection", "Data_Exfiltration"] @@ -505,20 +508,19 @@ resource "azurerm_storage_account" "test" { } resource "azurerm_mysql_server" "test" { - name = "acctestmysqlsvr-%[1]d" - location = azurerm_resource_group.test.location - resource_group_name = azurerm_resource_group.test.name - sku_name = "GP_Gen5_2" - administrator_login = "acctestun" - administrator_login_password = "H@Sh1CoR3!updated" - auto_grow_enabled = true - backup_retention_days = 7 - create_mode = "Default" - geo_redundant_backup_enabled = false - ssl_enforcement_enabled = true - ssl_minimal_tls_version_enforced = "TLS1_1" - storage_mb = 51200 - version = "%[3]s" + name = "acctestmysqlsvr-%[1]d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + sku_name = "GP_Gen5_2" + administrator_login = "acctestun" + administrator_login_password = "H@Sh1CoR3!updated" + auto_grow_enabled = true + backup_retention_days = 7 + create_mode = "Default" + geo_redundant_backup_enabled = false + ssl_enforcement_enabled = false + storage_mb = 51200 + version = "%[3]s" threat_detection_policy { enabled = true disabled_alerts = ["Sql_Injection"] @@ -557,10 +559,11 @@ resource "azurerm_mysql_server" "test" { auto_grow = "Enabled" } - administrator_login = "acctestun" - administrator_login_password = "H@Sh1CoR3!" - version = "%s" - ssl_enforcement_enabled = true + administrator_login = "acctestun" + administrator_login_password = "H@Sh1CoR3!" + version = "%s" + ssl_enforcement_enabled = true + ssl_minimal_tls_version_enforced = "TLS1_2" } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, version) } @@ -653,9 +656,10 @@ resource "azurerm_mysql_server" "replica" { version = "%s" storage_mb = 51200 - create_mode = "Replica" - creation_source_server_id = azurerm_mysql_server.test.id - ssl_enforcement_enabled = true + create_mode = "Replica" + creation_source_server_id = azurerm_mysql_server.test.id + ssl_enforcement_enabled = true + ssl_minimal_tls_version_enforced = "TLS1_1" } `, testAccAzureRMMySQLServer_basic(data, version), data.RandomInteger, version) } @@ -671,11 +675,12 @@ resource "azurerm_mysql_server" "restore" { sku_name = "GP_Gen5_2" version = "%s" - create_mode = "PointInTimeRestore" - creation_source_server_id = azurerm_mysql_server.test.id - restore_point_in_time = "%s" - ssl_enforcement_enabled = true - storage_mb = 51200 + create_mode = "PointInTimeRestore" + creation_source_server_id = azurerm_mysql_server.test.id + restore_point_in_time = "%s" + ssl_enforcement_enabled = true + ssl_minimal_tls_version_enforced = "TLS1_1" + storage_mb = 51200 } `, testAccAzureRMMySQLServer_basic(data, version), data.RandomInteger, version, restoreTime) }