Skip to content

Commit

Permalink
azurerm_private_dns_resolver_inbound_endpoint - mark `private_ip_ad…
Browse files Browse the repository at this point in the history
…dress` as `Optional` (#25035)

* azurerm_private_dns_resolver_inbound_endpoint - mark private_ip_address as Optional

* update code

* update code

* update code
  • Loading branch information
neil-yechenwei authored Mar 4, 2024
1 parent ecd7208 commit ec28e19
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ func (r PrivateDNSResolverInboundEndpointResource) Arguments() map[string]*plugi

"private_ip_address": {
Type: pluginsdk.TypeString,
Optional: true,
Computed: true,
},

Expand Down Expand Up @@ -133,7 +134,10 @@ func (r PrivateDNSResolverInboundEndpointResource) Create() sdk.ResourceFunc {
Tags: &model.Tags,
}

iPConfigurationsValue := expandIPConfigurationModel(model.IPConfigurations)
iPConfigurationsValue, err := expandIPConfigurationModel(model.IPConfigurations)
if err != nil {
return err
}

if iPConfigurationsValue != nil {
properties.Properties.IPConfigurations = *iPConfigurationsValue
Expand Down Expand Up @@ -176,7 +180,10 @@ func (r PrivateDNSResolverInboundEndpointResource) Update() sdk.ResourceFunc {
}

if metadata.ResourceData.HasChange("ip_configurations") {
iPConfigurationsValue := expandIPConfigurationModel(model.IPConfigurations)
iPConfigurationsValue, err := expandIPConfigurationModel(model.IPConfigurations)
if err != nil {
return err
}

if iPConfigurationsValue != nil {
properties.Properties.IPConfigurations = *iPConfigurationsValue
Expand Down Expand Up @@ -289,12 +296,20 @@ func dnsResolverInboundEndpointDeleteRefreshFunc(ctx context.Context, client *in
}
}

func expandIPConfigurationModel(inputList []IPConfigurationModel) *[]inboundendpoints.IPConfiguration {
func expandIPConfigurationModel(inputList []IPConfigurationModel) (*[]inboundendpoints.IPConfiguration, error) {
var outputList []inboundendpoints.IPConfiguration
for _, v := range inputList {
input := v
output := inboundendpoints.IPConfiguration{}

if input.PrivateIPAllocationMethod == inboundendpoints.IPAllocationMethodDynamic && input.PrivateIPAddress != "" {
return nil, fmt.Errorf("`private_ip_address` cannot be set when `private_ip_allocation_method` is `Dynamic`")
}

if input.PrivateIPAllocationMethod == inboundendpoints.IPAllocationMethodStatic && input.PrivateIPAddress == "" {
return nil, fmt.Errorf("`private_ip_address` must be set when `private_ip_allocation_method` is `Static`")
}

if input.PrivateIPAllocationMethod != "" {
output.PrivateIPAllocationMethod = &input.PrivateIPAllocationMethod
}
Expand All @@ -310,7 +325,7 @@ func expandIPConfigurationModel(inputList []IPConfigurationModel) *[]inboundendp
outputList = append(outputList, output)
}

return &outputList
return &outputList, nil
}

func flattenIPConfigurationModel(inputList *[]inboundendpoints.IPConfiguration) []IPConfigurationModel {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,20 @@ func TestAccDNSResolverInboundEndpoint_update(t *testing.T) {
})
}

func TestAccDNSResolverInboundEndpoint_static(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_private_dns_resolver_inbound_endpoint", "test")
r := DNSResolverInboundEndpointResource{}
data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.static(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

func (r DNSResolverInboundEndpointResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) {
id, err := inboundendpoints.ParseInboundEndpointID(state.ID)
if err != nil {
Expand Down Expand Up @@ -112,7 +126,7 @@ resource "azurerm_resource_group" "test" {
}
resource "azurerm_virtual_network" "test" {
name = "acctest-rg-%[2]d"
name = "acctest-vnet-%[2]d"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
address_space = ["10.0.0.0/16"]
Expand Down Expand Up @@ -226,3 +240,22 @@ resource "azurerm_private_dns_resolver_inbound_endpoint" "test" {
}
`, template, data.RandomInteger)
}

func (r DNSResolverInboundEndpointResource) static(data acceptance.TestData) string {
template := r.template(data)
return fmt.Sprintf(`
%s
resource "azurerm_private_dns_resolver_inbound_endpoint" "test" {
name = "acctest-drie-%d"
private_dns_resolver_id = azurerm_private_dns_resolver.test.id
location = azurerm_private_dns_resolver.test.location
ip_configurations {
subnet_id = azurerm_subnet.test.id
private_ip_allocation_method = "Static"
private_ip_address = "10.0.0.4"
}
}
`, template, data.RandomInteger)
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,23 +79,18 @@ The following arguments are supported:

An `ip_configurations` block supports the following:

* `private_ip_allocation_method` - (Optional) Private IP address allocation method. Allowed value is `Dynamic` and `Static`. Defaults to `Dynamic`.

* `subnet_id` - (Required) The subnet ID of the IP configuration.

* `private_ip_address` - (Optional) Private IP address of the IP configuration.

* `private_ip_allocation_method` - (Optional) Private IP address allocation method. Allowed value is `Dynamic` and `Static`. Defaults to `Dynamic`.

## Attributes Reference

In addition to the Arguments listed above - the following Attributes are exported:

* `id` - The ID of the Private DNS Resolver Inbound Endpoint.

---

An `ip_configurations` block exports the following:

* `private_ip_address` - Private IP address of the IP configuration.

## Timeouts

The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/docs/configuration/resources.html#timeouts) for certain actions:
Expand Down

0 comments on commit ec28e19

Please sign in to comment.