-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
azurerm_lb_backend_address_pool_address
- support for the backend_address_ip_configuration_id
property
#17770
Changes from 14 commits
7d8c0d4
293384a
811d57e
f2904dd
55bd76d
3e74c53
8cb7c87
ab739d3
3bf9b97
8015123
4f4b08d
6a9ed63
14c4d19
e9aa960
c2bf2d2
bcde78f
5024e3f
68556d2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -6,6 +6,7 @@ import ( | |||||
"time" | ||||||
|
||||||
"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2021-08-01/network" | ||||||
"github.com/hashicorp/terraform-provider-azurerm/helpers/azure" | ||||||
"github.com/hashicorp/terraform-provider-azurerm/internal/locks" | ||||||
"github.com/hashicorp/terraform-provider-azurerm/internal/sdk" | ||||||
"github.com/hashicorp/terraform-provider-azurerm/internal/services/loadbalancer/parse" | ||||||
|
@@ -24,11 +25,12 @@ var ( | |||||
type BackendAddressPoolAddressResource struct{} | ||||||
|
||||||
type BackendAddressPoolAddressModel struct { | ||||||
Name string `tfschema:"name"` | ||||||
BackendAddressPoolId string `tfschema:"backend_address_pool_id"` | ||||||
VirtualNetworkId string `tfschema:"virtual_network_id"` | ||||||
IPAddress string `tfschema:"ip_address"` | ||||||
PortMapping []inboundNATRulePortMapping `tfschema:"inbound_nat_rule_port_mapping"` | ||||||
Name string `tfschema:"name"` | ||||||
BackendAddressPoolId string `tfschema:"backend_address_pool_id"` | ||||||
VirtualNetworkId string `tfschema:"virtual_network_id"` | ||||||
IPAddress string `tfschema:"ip_address"` | ||||||
FrontendIPConfiguration string `tfschema:"backend_address_ip_config_id"` | ||||||
PortMapping []inboundNATRulePortMapping `tfschema:"inbound_nat_rule_port_mapping"` | ||||||
} | ||||||
|
||||||
type inboundNATRulePortMapping struct { | ||||||
|
@@ -78,15 +80,21 @@ func (r BackendAddressPoolAddressResource) Arguments() map[string]*pluginsdk.Sch | |||||
|
||||||
"virtual_network_id": { | ||||||
Type: pluginsdk.TypeString, | ||||||
Required: true, | ||||||
Optional: true, | ||||||
ValidateFunc: networkValidate.VirtualNetworkID, | ||||||
}, | ||||||
|
||||||
"ip_address": { | ||||||
Type: pluginsdk.TypeString, | ||||||
Required: true, | ||||||
Optional: true, | ||||||
ValidateFunc: validation.IsIPAddress, | ||||||
}, | ||||||
|
||||||
"backend_address_ip_config_id": { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shouldn't this be
Suggested change
to match the resource? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you set both of these or should they conflict? |
||||||
Type: pluginsdk.TypeString, | ||||||
Optional: true, | ||||||
ValidateFunc: azure.ValidateResourceID, | ||||||
}, | ||||||
} | ||||||
} | ||||||
|
||||||
|
@@ -135,6 +143,9 @@ func (r BackendAddressPoolAddressResource) Create() sdk.ResourceFunc { | |||||
if isBasicSku { | ||||||
return fmt.Errorf("Backend Addresses are not supported on Basic SKU Load Balancers") | ||||||
} | ||||||
if lb.Sku != nil && lb.Sku.Tier != network.LoadBalancerSkuTierGlobal && model.FrontendIPConfiguration != "" { | ||||||
return fmt.Errorf("Regional Backend Address Pool Addresses can only be set under the Global SKU tier") | ||||||
} | ||||||
|
||||||
id := parse.NewBackendAddressPoolAddressID(subscriptionId, poolId.ResourceGroup, poolId.LoadBalancerName, poolId.BackendAddressPoolName, model.Name) | ||||||
pool, err := client.Get(ctx, poolId.ResourceGroup, poolId.LoadBalancerName, poolId.BackendAddressPoolName) | ||||||
|
@@ -161,15 +172,26 @@ func (r BackendAddressPoolAddressResource) Create() sdk.ResourceFunc { | |||||
} | ||||||
} | ||||||
|
||||||
addresses = append(addresses, network.LoadBalancerBackendAddress{ | ||||||
LoadBalancerBackendAddressPropertiesFormat: &network.LoadBalancerBackendAddressPropertiesFormat{ | ||||||
IPAddress: utils.String(model.IPAddress), | ||||||
VirtualNetwork: &network.SubResource{ | ||||||
ID: utils.String(model.VirtualNetworkId), | ||||||
if lb.Sku.Tier == network.LoadBalancerSkuTierGlobal { | ||||||
addresses = append(addresses, network.LoadBalancerBackendAddress{ | ||||||
Name: utils.String(id.AddressName), | ||||||
LoadBalancerBackendAddressPropertiesFormat: &network.LoadBalancerBackendAddressPropertiesFormat{ | ||||||
LoadBalancerFrontendIPConfiguration: &network.SubResource{ | ||||||
ID: utils.String(model.FrontendIPConfiguration), | ||||||
}, | ||||||
}, | ||||||
}, | ||||||
Name: utils.String(id.AddressName), | ||||||
}) | ||||||
}) | ||||||
} else { | ||||||
addresses = append(addresses, network.LoadBalancerBackendAddress{ | ||||||
LoadBalancerBackendAddressPropertiesFormat: &network.LoadBalancerBackendAddressPropertiesFormat{ | ||||||
IPAddress: utils.String(model.IPAddress), | ||||||
VirtualNetwork: &network.SubResource{ | ||||||
ID: utils.String(model.VirtualNetworkId), | ||||||
}, | ||||||
}, | ||||||
Name: utils.String(id.AddressName), | ||||||
}) | ||||||
} | ||||||
pool.BackendAddressPoolPropertiesFormat.LoadBalancerBackendAddresses = &addresses | ||||||
|
||||||
metadata.Logger.Infof("adding %s..", id) | ||||||
|
@@ -192,6 +214,7 @@ func (r BackendAddressPoolAddressResource) Read() sdk.ResourceFunc { | |||||
return sdk.ResourceFunc{ | ||||||
Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { | ||||||
client := metadata.Client.LoadBalancers.LoadBalancerBackendAddressPoolsClient | ||||||
lbClient := metadata.Client.LoadBalancers.LoadBalancersClient | ||||||
id, err := parse.BackendAddressPoolAddressID(metadata.ResourceData.Id()) | ||||||
if err != nil { | ||||||
return err | ||||||
|
@@ -205,6 +228,11 @@ func (r BackendAddressPoolAddressResource) Read() sdk.ResourceFunc { | |||||
return fmt.Errorf("retrieving %s: `properties` was nil", *id) | ||||||
} | ||||||
|
||||||
lb, err := lbClient.Get(ctx, id.ResourceGroup, id.LoadBalancerName, "") | ||||||
if err != nil { | ||||||
return fmt.Errorf("retrieving Load Balancer %q (Resource Group %q): %+v", id.LoadBalancerName, id.ResourceGroup, err) | ||||||
} | ||||||
|
||||||
var backendAddress *network.LoadBalancerBackendAddress | ||||||
if pool.BackendAddressPoolPropertiesFormat.LoadBalancerBackendAddresses != nil { | ||||||
for _, address := range *pool.BackendAddressPoolPropertiesFormat.LoadBalancerBackendAddresses { | ||||||
|
@@ -229,12 +257,18 @@ func (r BackendAddressPoolAddressResource) Read() sdk.ResourceFunc { | |||||
} | ||||||
|
||||||
if props := backendAddress.LoadBalancerBackendAddressPropertiesFormat; props != nil { | ||||||
if props.IPAddress != nil { | ||||||
model.IPAddress = *props.IPAddress | ||||||
} | ||||||
if lb.Sku.Tier == network.LoadBalancerSkuTierGlobal { | ||||||
if props.LoadBalancerFrontendIPConfiguration != nil && props.LoadBalancerFrontendIPConfiguration.ID != nil { | ||||||
model.FrontendIPConfiguration = *props.LoadBalancerFrontendIPConfiguration.ID | ||||||
} | ||||||
} else { | ||||||
if props.IPAddress != nil { | ||||||
model.IPAddress = *props.IPAddress | ||||||
} | ||||||
|
||||||
if props.VirtualNetwork != nil && props.VirtualNetwork.ID != nil { | ||||||
model.VirtualNetworkId = *props.VirtualNetwork.ID | ||||||
if props.VirtualNetwork != nil && props.VirtualNetwork.ID != nil { | ||||||
model.VirtualNetworkId = *props.VirtualNetwork.ID | ||||||
} | ||||||
} | ||||||
} | ||||||
|
||||||
|
@@ -359,6 +393,11 @@ func (r BackendAddressPoolAddressResource) Update() sdk.ResourceFunc { | |||||
return fmt.Errorf("retrieving %s: `properties` was nil", *id) | ||||||
} | ||||||
|
||||||
lb, err := lbClient.Get(ctx, id.ResourceGroup, id.LoadBalancerName, "") | ||||||
if err != nil { | ||||||
return fmt.Errorf("retrieving Load Balancer %q (Resource Group %q): %+v", id.LoadBalancerName, id.ResourceGroup, err) | ||||||
} | ||||||
|
||||||
addresses := make([]network.LoadBalancerBackendAddress, 0) | ||||||
if pool.BackendAddressPoolPropertiesFormat.LoadBalancerBackendAddresses != nil { | ||||||
addresses = *pool.BackendAddressPoolPropertiesFormat.LoadBalancerBackendAddresses | ||||||
|
@@ -378,22 +417,34 @@ func (r BackendAddressPoolAddressResource) Update() sdk.ResourceFunc { | |||||
return fmt.Errorf("%s was not found", *id) | ||||||
} | ||||||
|
||||||
addresses[index] = network.LoadBalancerBackendAddress{ | ||||||
LoadBalancerBackendAddressPropertiesFormat: &network.LoadBalancerBackendAddressPropertiesFormat{ | ||||||
IPAddress: utils.String(model.IPAddress), | ||||||
VirtualNetwork: &network.SubResource{ | ||||||
ID: utils.String(model.VirtualNetworkId), | ||||||
if lb.Sku.Tier == network.LoadBalancerSkuTierGlobal { | ||||||
addresses[index] = network.LoadBalancerBackendAddress{ | ||||||
Name: utils.String(model.Name), | ||||||
LoadBalancerBackendAddressPropertiesFormat: &network.LoadBalancerBackendAddressPropertiesFormat{ | ||||||
LoadBalancerFrontendIPConfiguration: &network.SubResource{ | ||||||
ID: utils.String(model.FrontendIPConfiguration), | ||||||
}, | ||||||
}, | ||||||
}, | ||||||
Name: utils.String(id.AddressName), | ||||||
} | ||||||
} else { | ||||||
addresses[index] = network.LoadBalancerBackendAddress{ | ||||||
LoadBalancerBackendAddressPropertiesFormat: &network.LoadBalancerBackendAddressPropertiesFormat{ | ||||||
IPAddress: utils.String(model.IPAddress), | ||||||
VirtualNetwork: &network.SubResource{ | ||||||
ID: utils.String(model.VirtualNetworkId), | ||||||
}, | ||||||
}, | ||||||
Name: utils.String(id.AddressName), | ||||||
} | ||||||
} | ||||||
pool.BackendAddressPoolPropertiesFormat.LoadBalancerBackendAddresses = &addresses | ||||||
|
||||||
timeout, _ := ctx.Deadline() | ||||||
lbStatus := &pluginsdk.StateChangeConf{ | ||||||
Pending: []string{string(network.ProvisioningStateUpdating)}, | ||||||
Target: []string{string(network.ProvisioningStateSucceeded)}, | ||||||
MinTimeout: 5 * time.Minute, | ||||||
Delay: 30 * time.Second, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could you explain why there is this delay ona. comment? |
||||||
PollInterval: 10 * time.Second, | ||||||
Refresh: loadbalacnerProvisioningStatusRefreshFunc(ctx, lbClient, *id), | ||||||
ContinuousTargetOccurence: 10, | ||||||
Timeout: time.Until(timeout), | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are these required with each other? if so we sould use a RequiredWith here?