Skip to content

Commit

Permalink
Refactor: Remove ThreePointOhBeta from k service packages (#16688)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbfrahry authored May 6, 2022
1 parent 29e5835 commit 5ec191b
Show file tree
Hide file tree
Showing 21 changed files with 130 additions and 875 deletions.
22 changes: 8 additions & 14 deletions internal/services/legacy/virtual_machine_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"github.com/hashicorp/terraform-provider-azurerm/helpers/azure"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/features"
"github.com/hashicorp/terraform-provider-azurerm/internal/locks"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/compute/parse"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/compute/validate"
Expand Down Expand Up @@ -166,14 +165,13 @@ func resourceVirtualMachine() *pluginsdk.Resource {
},

"license_type": {
Type: pluginsdk.TypeString,
Optional: true,
Computed: true,
DiffSuppressFunc: suppress.CaseDifferenceV2Only,
Type: pluginsdk.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validation.StringInSlice([]string{
"Windows_Client",
"Windows_Server",
}, !features.ThreePointOhBeta()),
}, false),
},

"vm_size": {
Expand Down Expand Up @@ -239,8 +237,7 @@ func resourceVirtualMachine() *pluginsdk.Resource {
ValidateFunc: validation.StringInSlice([]string{
string(compute.OperatingSystemTypesLinux),
string(compute.OperatingSystemTypesWindows),
}, !features.ThreePointOhBeta()),
DiffSuppressFunc: suppress.CaseDifferenceV2Only,
}, false),
},

"name": {
Expand Down Expand Up @@ -275,8 +272,7 @@ func resourceVirtualMachine() *pluginsdk.Resource {
string(compute.StorageAccountTypesPremiumLRS),
string(compute.StorageAccountTypesStandardLRS),
string(compute.StorageAccountTypesStandardSSDLRS),
}, !features.ThreePointOhBeta()),
DiffSuppressFunc: suppress.CaseDifferenceV2Only,
}, false),
},

"image_uri": {
Expand Down Expand Up @@ -350,8 +346,7 @@ func resourceVirtualMachine() *pluginsdk.Resource {
string(compute.StorageAccountTypesStandardLRS),
string(compute.StorageAccountTypesStandardSSDLRS),
string(compute.StorageAccountTypesUltraSSDLRS),
}, !features.ThreePointOhBeta()),
DiffSuppressFunc: suppress.CaseDifferenceV2Only,
}, false),
},

"create_option": {
Expand Down Expand Up @@ -498,8 +493,7 @@ func resourceVirtualMachine() *pluginsdk.Resource {
ValidateFunc: validation.StringInSlice([]string{
"HTTP",
"HTTPS",
}, !features.ThreePointOhBeta()),
DiffSuppressFunc: suppress.CaseDifferenceV2Only,
}, false),
},
"certificate_url": {
Type: pluginsdk.TypeString,
Expand Down
22 changes: 8 additions & 14 deletions internal/services/legacy/virtual_machine_scale_set_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
"github.com/hashicorp/terraform-provider-azurerm/helpers/validate"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/features"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/compute/migration"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/compute/parse"
validate2 "github.com/hashicorp/terraform-provider-azurerm/internal/services/compute/validate"
Expand Down Expand Up @@ -133,14 +132,13 @@ func resourceVirtualMachineScaleSet() *pluginsdk.Resource {
},

"license_type": {
Type: pluginsdk.TypeString,
Optional: true,
Computed: true,
DiffSuppressFunc: suppress.CaseDifferenceV2Only,
Type: pluginsdk.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validation.StringInSlice([]string{
"Windows_Client",
"Windows_Server",
}, !features.ThreePointOhBeta()),
}, false),
},

"upgrade_policy_mode": {
Expand All @@ -150,8 +148,7 @@ func resourceVirtualMachineScaleSet() *pluginsdk.Resource {
string(compute.UpgradeModeAutomatic),
string(compute.UpgradeModeManual),
string(compute.UpgradeModeRolling),
}, !features.ThreePointOhBeta()),
DiffSuppressFunc: suppress.CaseDifferenceV2Only,
}, false),
},

"health_probe_id": {
Expand Down Expand Up @@ -224,8 +221,7 @@ func resourceVirtualMachineScaleSet() *pluginsdk.Resource {
ValidateFunc: validation.StringInSlice([]string{
string(compute.VirtualMachinePriorityTypesLow),
string(compute.VirtualMachinePriorityTypesRegular),
}, !features.ThreePointOhBeta()),
DiffSuppressFunc: suppress.CaseDifferenceV2Only,
}, false),
},

"eviction_policy": {
Expand Down Expand Up @@ -591,8 +587,7 @@ func resourceVirtualMachineScaleSet() *pluginsdk.Resource {
string(compute.StorageAccountTypesPremiumLRS),
string(compute.StorageAccountTypesStandardLRS),
string(compute.StorageAccountTypesStandardSSDLRS),
}, !features.ThreePointOhBeta()),
DiffSuppressFunc: suppress.CaseDifferenceV2Only,
}, false),
},

"caching": {
Expand Down Expand Up @@ -651,8 +646,7 @@ func resourceVirtualMachineScaleSet() *pluginsdk.Resource {
string(compute.StorageAccountTypesPremiumLRS),
string(compute.StorageAccountTypesStandardLRS),
string(compute.StorageAccountTypesStandardSSDLRS),
}, !features.ThreePointOhBeta()),
DiffSuppressFunc: suppress.CaseDifferenceV2Only,
}, false),
},
},
},
Expand Down
191 changes: 68 additions & 123 deletions internal/services/loadbalancer/backend_address_pool_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,11 @@ import (
"time"

"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2021-05-01/network"
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/features"
"github.com/hashicorp/terraform-provider-azurerm/internal/locks"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/loadbalancer/parse"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/loadbalancer/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/validation"
"github.com/hashicorp/terraform-provider-azurerm/internal/timeouts"
Expand Down Expand Up @@ -46,123 +43,88 @@ func resourceArmLoadBalancerBackendAddressPool() *pluginsdk.Resource {
Delete: pluginsdk.DefaultTimeout(30 * time.Minute),
},

Schema: func() map[string]*pluginsdk.Schema {
s := map[string]*pluginsdk.Schema{
"name": {
Type: pluginsdk.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringIsNotEmpty,
},

"loadbalancer_id": {
Type: pluginsdk.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validate.LoadBalancerID,
},

"tunnel_interface": {
Type: pluginsdk.TypeList,
Optional: true,
MinItems: 1,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"identifier": {
Type: pluginsdk.TypeInt,
Required: true,
},
Schema: map[string]*pluginsdk.Schema{
"name": {
Type: pluginsdk.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringIsNotEmpty,
},

"loadbalancer_id": {
Type: pluginsdk.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validate.LoadBalancerID,
},

"tunnel_interface": {
Type: pluginsdk.TypeList,
Optional: true,
MinItems: 1,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"identifier": {
Type: pluginsdk.TypeInt,
Required: true,
},

"type": {
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{
string(network.GatewayLoadBalancerTunnelInterfaceTypeNone),
string(network.GatewayLoadBalancerTunnelInterfaceTypeInternal),
string(network.GatewayLoadBalancerTunnelInterfaceTypeExternal),
},
false,
),
"type": {
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{
string(network.GatewayLoadBalancerTunnelInterfaceTypeNone),
string(network.GatewayLoadBalancerTunnelInterfaceTypeInternal),
string(network.GatewayLoadBalancerTunnelInterfaceTypeExternal),
},
false,
),
},

"protocol": {
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{
string(network.GatewayLoadBalancerTunnelProtocolNone),
string(network.GatewayLoadBalancerTunnelProtocolNative),
string(network.GatewayLoadBalancerTunnelProtocolVXLAN),
},
false,
),
"protocol": {
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{
string(network.GatewayLoadBalancerTunnelProtocolNone),
string(network.GatewayLoadBalancerTunnelProtocolNative),
string(network.GatewayLoadBalancerTunnelProtocolVXLAN),
},
false,
),
},

"port": {
Type: pluginsdk.TypeInt,
Required: true,
},
"port": {
Type: pluginsdk.TypeInt,
Required: true,
},
},
},
},

"backend_ip_configurations": {
Type: pluginsdk.TypeList,
Computed: true,
Elem: &pluginsdk.Schema{
Type: pluginsdk.TypeString,
},
"backend_ip_configurations": {
Type: pluginsdk.TypeList,
Computed: true,
Elem: &pluginsdk.Schema{
Type: pluginsdk.TypeString,
},
},

"load_balancing_rules": {
Type: pluginsdk.TypeList,
Computed: true,
Elem: &pluginsdk.Schema{
Type: pluginsdk.TypeString,
},
"load_balancing_rules": {
Type: pluginsdk.TypeList,
Computed: true,
Elem: &pluginsdk.Schema{
Type: pluginsdk.TypeString,
},
},

"outbound_rules": {
Type: pluginsdk.TypeList,
Computed: true,
Elem: &pluginsdk.Schema{
Type: pluginsdk.TypeString,
},
"outbound_rules": {
Type: pluginsdk.TypeList,
Computed: true,
Elem: &pluginsdk.Schema{
Type: pluginsdk.TypeString,
},
}

if !features.ThreePointOhBeta() {
s["resource_group_name"] = commonschema.ResourceGroupNameDeprecatedComputed()
s["backend_address"] = &pluginsdk.Schema{
Type: pluginsdk.TypeSet,
Optional: true,
Deprecated: "This field is non-functional and will be removed in version 3.0 of the Azure Provider - use the separate `azurerm_lb_backend_address_pool_address` resource instead.",
MinItems: 1,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"name": {
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: validation.StringIsNotEmpty,
},

"virtual_network_id": {
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: networkValidate.VirtualNetworkID,
},

"ip_address": {
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: validation.IsIPAddress,
},
},
},
}
}

return s
}(),
},
},
}
}

Expand Down Expand Up @@ -222,12 +184,6 @@ func resourceArmLoadBalancerBackendAddressPoolCreateUpdate(d *pluginsdk.Resource
return fmt.Errorf("nil or empty `sku` for Load Balancer %q for Backend Address Pool %q was not found", loadBalancerId, id)
}

// Sanity checks
if !features.ThreePointOhBeta() && len(d.Get("backend_address").(*pluginsdk.Set).List()) != 0 && sku.Name != network.LoadBalancerSkuNameStandard {
return fmt.Errorf("only the Standard (sku) Load Balancer allows IP based Backend Address Pool configuration,"+
"whilst %q is of sku %s", id, sku.Name)
}

if len(d.Get("tunnel_interface").([]interface{})) != 0 && sku.Name != network.LoadBalancerSkuNameGateway {
return fmt.Errorf("only the Gateway (sku) Load Balancer allows IP based Backend Address Pool configuration,"+
"whilst %q is of sku %s", id, sku.Name)
Expand Down Expand Up @@ -313,18 +269,7 @@ func resourceArmLoadBalancerBackendAddressPoolRead(d *pluginsdk.ResourceData, me
d.Set("name", id.BackendAddressPoolName)
d.Set("loadbalancer_id", lbId.ID())

if !features.ThreePointOhBeta() {
d.Set("resource_group_name", id.ResourceGroup)
}

if props := resp.BackendAddressPoolPropertiesFormat; props != nil {
if !features.ThreePointOhBeta() {
// @tombuildsstuff: this is a Set so won't be referenced, let's just nil this out for now
if err := d.Set("backend_address", []interface{}{}); err != nil {
return fmt.Errorf("setting `backend_address`: %v", err)
}
}

if err := d.Set("tunnel_interface", flattenGatewayLoadBalancerTunnelInterfaces(props.TunnelInterfaces)); err != nil {
return fmt.Errorf("setting `tunnel_interface`: %v", err)
}
Expand Down
Loading

0 comments on commit 5ec191b

Please sign in to comment.