Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
myc2h6o committed Aug 3, 2023
1 parent 91147e0 commit 8618775
Show file tree
Hide file tree
Showing 19 changed files with 1,327 additions and 351 deletions.
2 changes: 1 addition & 1 deletion .github/labeler-issue-triage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ service/monitor:
- '### (|New or )Affected Resource\(s\)\/Data Source\(s\)((.|\n)*)azurerm_monitor_((.|\n)*)###'

service/mssql:
- '### (|New or )Affected Resource\(s\)\/Data Source\(s\)((.|\n)*)azurerm_(mssql_database\W+|mssql_database_extended_auditing_policy\W+|mssql_database_vulnerability_assessment_rule_baseline\W+|mssql_elasticpool\W+|mssql_failover_group\W+|mssql_firewall_rule\W+|mssql_job_agent\W+|mssql_job_credential\W+|mssql_outbound_firewall_rule\W+|mssql_server\W+|mssql_server_dns_alias\W+|mssql_server_extended_auditing_policy\W+|mssql_server_microsoft_support_auditing_policy\W+|mssql_server_security_alert_policy\W+|mssql_server_transparent_data_encryption\W+|mssql_server_vulnerability_assessment\W+|mssql_virtual_machine\W+|mssql_virtual_network_rule\W+)((.|\n)*)###'
- '### (|New or )Affected Resource\(s\)\/Data Source\(s\)((.|\n)*)azurerm_(mssql_database\W+|mssql_database_extended_auditing_policy\W+|mssql_database_vulnerability_assessment_rule_baseline\W+|mssql_elasticpool\W+|mssql_failover_group\W+|mssql_firewall_rule\W+|mssql_job_agent\W+|mssql_job_credential\W+|mssql_outbound_firewall_rule\W+|mssql_server\W+|mssql_server_dns_alias\W+|mssql_server_extended_auditing_policy\W+|mssql_server_microsoft_support_auditing_policy\W+|mssql_server_security_alert_policy\W+|mssql_server_transparent_data_encryption\W+|mssql_server_vulnerability_assessment\W+|mssql_virtual_machine\W+|mssql_virtual_machine_availability_group_listener\W+|mssql_virtual_machine_group\W+|mssql_virtual_network_rule\W+)((.|\n)*)###'

service/mssqlmanagedinstance:
- '### (|New or )Affected Resource\(s\)\/Data Source\(s\)((.|\n)*)azurerm_mssql_managed_((.|\n)*)###'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,43 +1,38 @@
package helper

import (
"bytes"
"fmt"
"strings"

"github.com/hashicorp/go-azure-sdk/resource-manager/sqlvirtualmachine/2022-02-01/availabilitygrouplisteners"
"github.com/hashicorp/go-azure-sdk/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachines"
"github.com/hashicorp/terraform-provider-azurerm/helpers/validate"
lbValidate "github.com/hashicorp/terraform-provider-azurerm/internal/services/loadbalancer/validate"
sqlValidate "github.com/hashicorp/terraform-provider-azurerm/internal/services/mssql/validate"
networkValidate "github.com/hashicorp/terraform-provider-azurerm/internal/services/network/validate"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/suppress"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation"
)

type LoadBalancerConfigurationMsSqlVirtualMachineAvailabilityGroupListener struct {
PrivateIpAddress []PrivateIpAddressMsSqlVirtualMachineAvailabilityGroupListener `tfschema:"private_ip_address"`
PublicIpAddressId string `tfschema:"public_ip_address_id"`
LoadBalancerId string `tfschema:"load_balancer_id"`
ProbePort int `tfschema:"probe_port"`
SqlVirtualMachineInstances []string `tfschema:"sql_virtual_machine_instances"`
PrivateIpAddress []PrivateIpAddressMsSqlVirtualMachineAvailabilityGroupListener `tfschema:"private_ip_address"`
LoadBalancerId string `tfschema:"load_balancer_id"`
ProbePort int `tfschema:"probe_port"`
SqlVirtualMachineIds []string `tfschema:"sql_virtual_machine_ids"`
}

func LoadBalancerConfigurationSchemaMsSqlVirtualMachineAvailabilityGroupListener() *pluginsdk.Schema {
return &pluginsdk.Schema{
Type: pluginsdk.TypeList,
Required: true,
ForceNew: true,
MaxItems: 1,
Type: pluginsdk.TypeList,
Optional: true,
ExactlyOneOf: []string{"load_balancer_configuration", "multi_subnet_ip_configuration"},
ForceNew: true,
MaxItems: 1,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"private_ip_address": PrivateIpAddressSchemaMsSqlVirtualMachineAvailabilityGroupListener(),

"public_ip_address_id": {
Type: pluginsdk.TypeString,
Optional: true,
ForceNew: true,
ConflictsWith: []string{"load_balancer_configuration.0.private_ip_address"},
ValidateFunc: networkValidate.PublicIpAddressID,
},

"load_balancer_id": {
Type: pluginsdk.TypeString,
Required: true,
Expand All @@ -47,12 +42,12 @@ func LoadBalancerConfigurationSchemaMsSqlVirtualMachineAvailabilityGroupListener

"probe_port": {
Type: pluginsdk.TypeInt,
Optional: true,
Required: true,
ForceNew: true,
ValidateFunc: validate.PortNumber,
},

"sql_virtual_machine_instances": {
"sql_virtual_machine_ids": {
Type: pluginsdk.TypeSet,
Required: true,
ForceNew: true,
Expand All @@ -66,30 +61,55 @@ func LoadBalancerConfigurationSchemaMsSqlVirtualMachineAvailabilityGroupListener
}
}

type MultiSubnetIpConfigurationMsSqlVirtualMachineAvailabilityGroupListener struct {
PrivateIpAddress []PrivateIpAddressMsSqlVirtualMachineAvailabilityGroupListener `tfschema:"private_ip_address"`
SqlVirtualMachineId string `tfschema:"sql_virtual_machine_id"`
}

func MultiSubnetIpConfigurationSchemaMsSqlVirtualMachineAvailabilityGroupListener() *pluginsdk.Schema {
return &pluginsdk.Schema{
Type: pluginsdk.TypeSet,
Optional: true,
ExactlyOneOf: []string{"load_balancer_configuration", "multi_subnet_ip_configuration"},
ForceNew: true,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"private_ip_address": PrivateIpAddressSchemaMsSqlVirtualMachineAvailabilityGroupListener(),

"sql_virtual_machine_id": {
Type: pluginsdk.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: sqlvirtualmachines.ValidateSqlVirtualMachineID,
},
},
},
}
}

type PrivateIpAddressMsSqlVirtualMachineAvailabilityGroupListener struct {
IpAddress string `tfschema:"ip_address"`
SubnetId string `tfschema:"subnet_id"`
}

func PrivateIpAddressSchemaMsSqlVirtualMachineAvailabilityGroupListener() *pluginsdk.Schema {
return &pluginsdk.Schema{
Type: pluginsdk.TypeList,
Optional: true,
ForceNew: true,
MinItems: 1,
ConflictsWith: []string{"load_balancer_configuration.0.public_ip_address_id"},
Type: pluginsdk.TypeList,
Required: true,
ForceNew: true,
MaxItems: 1,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"ip_address": {
Type: pluginsdk.TypeString,
Optional: true,
Required: true,
ForceNew: true,
ValidateFunc: validation.IsIPAddress,
},

"subnet_id": {
Type: pluginsdk.TypeString,
Optional: true,
Required: true,
ForceNew: true,
ValidateFunc: networkValidate.SubnetID,
},
Expand All @@ -99,56 +119,70 @@ func PrivateIpAddressSchemaMsSqlVirtualMachineAvailabilityGroupListener() *plugi
}

type ReplicaMsSqlVirtualMachineAvailabilityGroupListener struct {
SqlVirtualMachineInstanceId string `tfschema:"sql_virtual_machine_instance_id"`
Role string `tfschema:"role"`
Commit string `tfschema:"commit"`
Failover string `tfschema:"failover"`
ReadableSecondary string `tfschema:"readable_secondary"`
SqlVirtualMachineId string `tfschema:"sql_virtual_machine_id"`
Role string `tfschema:"role"`
Commit string `tfschema:"commit"`
Failover string `tfschema:"failover"`
ReadableSecondary string `tfschema:"readable_secondary"`
}

func ReplicaSchemaMsSqlVirtualMachineAvailabilityGroupListener() *pluginsdk.Schema {
return &pluginsdk.Schema{
Type: pluginsdk.TypeSet,
Optional: true,
Required: true,
ForceNew: true,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"sql_virtual_machine_instance_id": {
Type: pluginsdk.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: sqlValidate.SqlVirtualMachineID,
DiffSuppressFunc: suppress.CaseDifference,
"sql_virtual_machine_id": {
Type: pluginsdk.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: sqlValidate.SqlVirtualMachineID,
},

"role": {
Type: pluginsdk.TypeString,
Optional: true,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{string(availabilitygrouplisteners.RolePrimary), string(availabilitygrouplisteners.RoleSecondary)}, false),
},

"commit": {
Type: pluginsdk.TypeString,
Optional: true,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{string(availabilitygrouplisteners.CommitSynchronousCommit), string(availabilitygrouplisteners.CommitAsynchronousCommit)}, false),
},

"failover": {
Type: pluginsdk.TypeString,
Optional: true,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{string(availabilitygrouplisteners.FailoverManual), string(availabilitygrouplisteners.FailoverAutomatic)}, false),
},

"readable_secondary": {
Type: pluginsdk.TypeString,
Optional: true,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{string(availabilitygrouplisteners.ReadableSecondaryNo), string(availabilitygrouplisteners.ReadableSecondaryReadOnly), string(availabilitygrouplisteners.ReadableSecondaryAll)}, false),
},
},
},
Set: ReplicaSchemaMsSqlVirtualMachineAvailabilityGroupListenerHash,
}
}

func ReplicaSchemaMsSqlVirtualMachineAvailabilityGroupListenerHash(v interface{}) int {
var buf bytes.Buffer

if m, ok := v.(map[string]interface{}); ok {
buf.WriteString(fmt.Sprintf("%s-", strings.ToLower(m["sql_virtual_machine_id"].(string))))
buf.WriteString(fmt.Sprintf("%s-", m["role"].(string)))
buf.WriteString(fmt.Sprintf("%s-", m["commit"].(string)))
buf.WriteString(fmt.Sprintf("%s-", m["failover"].(string)))
buf.WriteString(fmt.Sprintf("%s-", m["readable_secondary"].(string)))
}

return pluginsdk.HashString(buf.String())
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ type WsfcDomainProfile struct {
ClusterBootstrapAccountName string `tfschema:"cluster_bootstrap_account_name"`
ClusterOperatorAccountName string `tfschema:"cluster_operator_account_name"`
SqlServiceAccountName string `tfschema:"sql_service_account_name"`
FileShareWitnessPath string `tfschema:"file_share_witness_path"`
StorageAccountUrl string `tfschema:"storage_account_url"`
StorageAccountPrimaryKey string `tfschema:"storage_account_primary_key"`
ClusterSubnetType string `tfschema:"cluster_subnet_type"`
Expand All @@ -25,6 +24,16 @@ func WsfcDomainProfileSchemaMsSqlVirtualMachineAvailabilityGroup() *pluginsdk.Sc
MaxItems: 1,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"cluster_subnet_type": {
Type: pluginsdk.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{
string(sqlvirtualmachinegroups.ClusterSubnetTypeMultiSubnet),
string(sqlvirtualmachinegroups.ClusterSubnetTypeSingleSubnet),
}, false),
},

"fqdn": {
Type: pluginsdk.TypeString,
Required: true,
Expand Down Expand Up @@ -60,13 +69,6 @@ func WsfcDomainProfileSchemaMsSqlVirtualMachineAvailabilityGroup() *pluginsdk.Sc
ValidateFunc: validation.StringIsNotEmpty,
},

"file_share_witness_path": {
Type: pluginsdk.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: validation.StringIsNotEmpty,
},

"storage_account_url": {
Type: pluginsdk.TypeString,
Optional: true,
Expand All @@ -80,15 +82,6 @@ func WsfcDomainProfileSchemaMsSqlVirtualMachineAvailabilityGroup() *pluginsdk.Sc
Sensitive: true,
ValidateFunc: validation.StringIsNotEmpty,
},

"cluster_subnet_type": {
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{
string(sqlvirtualmachinegroups.ClusterSubnetTypeMultiSubnet),
string(sqlvirtualmachinegroups.ClusterSubnetTypeSingleSubnet),
}, false),
},
},
},
}
Expand Down
Loading

0 comments on commit 8618775

Please sign in to comment.