Skip to content
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_network_interface - removes Computed from dns_server and renames enable_* to *_enabled #26293

Merged
merged 4 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions internal/services/network/network_interface_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ import (
"github.com/hashicorp/go-azure-sdk/resource-manager/network/2023-11-01/networkinterfaces"
"github.com/hashicorp/terraform-provider-azurerm/helpers/azure"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/features"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/timeouts"
)

func dataSourceNetworkInterface() *pluginsdk.Resource {
return &pluginsdk.Resource{
dataSource := &pluginsdk.Resource{
Read: dataSourceNetworkInterfaceRead,

Timeouts: &pluginsdk.ResourceTimeout{
Expand Down Expand Up @@ -149,14 +150,12 @@ func dataSourceNetworkInterface() *pluginsdk.Resource {
Set: pluginsdk.HashString,
},

// TODO 4.0: change this from enable_* to *_enabled
"enable_accelerated_networking": {
"accelerated_networking_enabled": {
Type: pluginsdk.TypeBool,
Computed: true,
},

// TODO 4.0: change this from enable_* to *_enabled
"enable_ip_forwarding": {
"ip_forwarding_enabled": {
Type: pluginsdk.TypeBool,
Computed: true,
},
Expand All @@ -177,6 +176,18 @@ func dataSourceNetworkInterface() *pluginsdk.Resource {
"tags": commonschema.TagsDataSource(),
},
}

if !features.FourPointOhBeta() {
dataSource.Schema["enable_ip_forwarding"] = &pluginsdk.Schema{
Type: pluginsdk.TypeBool,
Computed: true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to add a Deprecated messages to this attribute?

}
dataSource.Schema["enable_accelerated_networking"] = &pluginsdk.Schema{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And do we want to add a Deprecated messages to this attribute?

Type: pluginsdk.TypeBool,
Computed: true,
}
}
return dataSource
}

func dataSourceNetworkInterfaceRead(d *pluginsdk.ResourceData, meta interface{}) error {
Expand Down Expand Up @@ -267,8 +278,12 @@ func dataSourceNetworkInterfaceRead(d *pluginsdk.ResourceData, meta interface{})

d.Set("applied_dns_servers", appliedDNSServers)
d.Set("dns_servers", dnsServers)
d.Set("enable_ip_forwarding", props.EnableIPForwarding)
d.Set("enable_accelerated_networking", props.EnableAcceleratedNetworking)
if !features.FourPointOh() {
d.Set("enable_ip_forwarding", props.EnableIPForwarding)
d.Set("enable_accelerated_networking", props.EnableAcceleratedNetworking)
}
d.Set("ip_forwarding_enabled", props.EnableIPForwarding)
d.Set("accelerated_networking_enabled", props.EnableAcceleratedNetworking)
}

return tags.FlattenAndSet(d, model.Tags)
Expand Down
145 changes: 87 additions & 58 deletions internal/services/network/network_interface_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,22 @@ import (
"github.com/hashicorp/go-azure-helpers/resourcemanager/location"
"github.com/hashicorp/go-azure-helpers/resourcemanager/tags"
"github.com/hashicorp/go-azure-sdk/resource-manager/network/2023-11-01/networkinterfaces"
"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"
lbvalidate "github.com/hashicorp/terraform-provider-azurerm/internal/services/loadbalancer/validate"
"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"
"github.com/hashicorp/terraform-provider-azurerm/internal/timeouts"
"github.com/hashicorp/terraform-provider-azurerm/utils"
)

var networkInterfaceResourceName = "azurerm_network_interface"

func resourceNetworkInterface() *pluginsdk.Resource {
return &pluginsdk.Resource{
resource := &pluginsdk.Resource{
Create: resourceNetworkInterfaceCreate,
Read: resourceNetworkInterfaceRead,
Update: resourceNetworkInterfaceUpdate,
Expand Down Expand Up @@ -143,7 +142,7 @@ func resourceNetworkInterface() *pluginsdk.Resource {
"dns_servers": {
Type: pluginsdk.TypeList,
Optional: true,
Computed: true,
Computed: !features.FourPointOhBeta(),
Elem: &pluginsdk.Schema{
Type: pluginsdk.TypeString,
ValidateFunc: validation.StringIsNotEmpty,
Expand All @@ -152,18 +151,28 @@ func resourceNetworkInterface() *pluginsdk.Resource {

"edge_zone": commonschema.EdgeZoneOptionalForceNew(),

// TODO 4.0: change this from enable_* to *_enabled
"enable_accelerated_networking": {
"accelerated_networking_enabled": {
Type: pluginsdk.TypeBool,
Optional: true,
Default: false,
Computed: !features.FourPointOhBeta(),
ConflictsWith: func() []string {
if !features.FourPointOhBeta() {
return []string{"enable_accelerated_networking"}
}
return []string{}
}(),
},

// TODO 4.0: change this from enable_* to *_enabled
"enable_ip_forwarding": {
"ip_forwarding_enabled": {
Type: pluginsdk.TypeBool,
Optional: true,
Default: false,
Computed: !features.FourPointOhBeta(),
ConflictsWith: func() []string {
if !features.FourPointOhBeta() {
return []string{"enable_ip_forwarding"}
}
return []string{}
}(),
},

"internal_dns_name_label": {
Expand Down Expand Up @@ -213,6 +222,24 @@ func resourceNetworkInterface() *pluginsdk.Resource {
},
},
}

if !features.FourPointOhBeta() {
resource.Schema["enable_accelerated_networking"] = &pluginsdk.Schema{
Type: pluginsdk.TypeBool,
Optional: true,
Computed: true,
ConflictsWith: []string{"accelerated_networking_enabled"},
Deprecated: "The property `enable_accelerated_networking` has been superseded by `accelerated_networking_enabled` and will be removed in v4.0 of the AzureRM Provider.",
}
resource.Schema["enable_ip_forwarding"] = &pluginsdk.Schema{
Type: pluginsdk.TypeBool,
Optional: true,
Computed: true,
ConflictsWith: []string{"ip_forwarding_enabled"},
Deprecated: "The property `enable_ip_forwarding` has been superseded by `ip_forwarding_enabled` and will be removed in v4.0 of the AzureRM Provider.",
}
}
return resource
}

func resourceNetworkInterfaceCreate(d *pluginsdk.ResourceData, meta interface{}) error {
Expand All @@ -233,10 +260,18 @@ func resourceNetworkInterfaceCreate(d *pluginsdk.ResourceData, meta interface{})
return tf.ImportAsExistsError("azurerm_network_interface", id.ID())
}

location := azure.NormalizeLocation(d.Get("location").(string))
enableIpForwarding := d.Get("enable_ip_forwarding").(bool)
enableAcceleratedNetworking := d.Get("enable_accelerated_networking").(bool)
t := d.Get("tags").(map[string]interface{})
var enableIpForwarding, enableAcceleratedNetworking bool

enableIpForwarding = d.Get("ip_forwarding_enabled").(bool)
enableAcceleratedNetworking = d.Get("accelerated_networking_enabled").(bool)

if v, ok := d.GetOk("enable_ip_forwarding"); ok && !features.FourPointOhBeta() {
enableIpForwarding = v.(bool)
}

if v, ok := d.GetOk("enable_accelerated_networking"); ok && !features.FourPointOhBeta() {
enableAcceleratedNetworking = v.(bool)
}

properties := networkinterfaces.NetworkInterfacePropertiesFormat{
EnableIPForwarding: &enableIpForwarding,
Expand Down Expand Up @@ -266,7 +301,7 @@ func resourceNetworkInterfaceCreate(d *pluginsdk.ResourceData, meta interface{})
}

if hasNameLabel {
dnsSettings.InternalDnsNameLabel = utils.String(nameLabel.(string))
dnsSettings.InternalDnsNameLabel = pointer.To(nameLabel.(string))
}

properties.DnsSettings = &dnsSettings
Expand All @@ -292,9 +327,9 @@ func resourceNetworkInterfaceCreate(d *pluginsdk.ResourceData, meta interface{})
iface := networkinterfaces.NetworkInterface{
Name: pointer.To(id.NetworkInterfaceName),
ExtendedLocation: expandEdgeZoneModel(d.Get("edge_zone").(string)),
Location: utils.String(location),
Location: pointer.To(location.Normalize(d.Get("location").(string))),
Properties: &properties,
Tags: tags.Expand(t),
Tags: tags.Expand(d.Get("tags").(map[string]interface{})),
}

err = client.CreateOrUpdateThenPoll(ctx, id, iface)
Expand Down Expand Up @@ -336,52 +371,49 @@ func resourceNetworkInterfaceUpdate(d *pluginsdk.ResourceData, meta interface{})
// then pull out things we need to lock on
info := parseFieldsFromNetworkInterface(*existing.Model.Properties)

location := azure.NormalizeLocation(d.Get("location").(string))
update := networkinterfaces.NetworkInterface{
Name: utils.String(id.NetworkInterfaceName),
ExtendedLocation: expandEdgeZoneModel(d.Get("edge_zone").(string)),
Location: utils.String(location),
Properties: &networkinterfaces.NetworkInterfacePropertiesFormat{
EnableAcceleratedNetworking: utils.Bool(d.Get("enable_accelerated_networking").(bool)),
DnsSettings: &networkinterfaces.NetworkInterfaceDnsSettings{},
},
}
payload := existing.Model

if d.HasChange("auxiliary_mode") {
if auxiliaryMode, hasAuxiliaryMode := d.GetOk("auxiliary_mode"); hasAuxiliaryMode {
update.Properties.AuxiliaryMode = pointer.To(networkinterfaces.NetworkInterfaceAuxiliaryMode(auxiliaryMode.(string)))
if auxiliaryMode := d.Get("auxiliary_mode").(string); auxiliaryMode != "" {
payload.Properties.AuxiliaryMode = pointer.To(networkinterfaces.NetworkInterfaceAuxiliaryMode(auxiliaryMode))
} else {
payload.Properties.AuxiliaryMode = nil
}
} else {
update.Properties.AuxiliaryMode = existing.Model.Properties.AuxiliaryMode
}

if d.HasChange("auxiliary_sku") {
if auxiliarySku, hasAuxiliarySku := d.GetOk("auxiliary_sku"); hasAuxiliarySku {
update.Properties.AuxiliarySku = pointer.To(networkinterfaces.NetworkInterfaceAuxiliarySku(auxiliarySku.(string)))
if auxiliarySku := d.Get("auxiliary_sku").(string); auxiliarySku != "" {
payload.Properties.AuxiliarySku = pointer.To(networkinterfaces.NetworkInterfaceAuxiliarySku(auxiliarySku))
} else {
payload.Properties.AuxiliarySku = nil
}
} else {
update.Properties.AuxiliarySku = existing.Model.Properties.AuxiliarySku
}

if d.HasChange("dns_servers") {
dnsServersRaw := d.Get("dns_servers").([]interface{})
dnsServers := expandNetworkInterfaceDnsServers(dnsServersRaw)

update.Properties.DnsSettings.DnsServers = &dnsServers
} else {
update.Properties.DnsSettings.DnsServers = existing.Model.Properties.DnsSettings.DnsServers
payload.Properties.DnsSettings.DnsServers = &dnsServers
}

if d.HasChange("enable_ip_forwarding") {
update.Properties.EnableIPForwarding = utils.Bool(d.Get("enable_ip_forwarding").(bool))
} else {
update.Properties.EnableIPForwarding = existing.Model.Properties.EnableIPForwarding
if d.HasChange("accelerated_networking_enabled") {
payload.Properties.EnableAcceleratedNetworking = pointer.To(d.Get("accelerated_networking_enabled").(bool))
}

if !features.FourPointOhBeta() && d.HasChange("enable_accelerated_networking") {
payload.Properties.EnableAcceleratedNetworking = pointer.To(d.Get("enable_accelerated_networking").(bool))
}

if d.HasChange("ip_forwarding_enabled") {
payload.Properties.EnableIPForwarding = pointer.To(d.Get("ip_forwarding_enabled").(bool))
}

if !features.FourPointOhBeta() && d.HasChange("enable_ip_forwarding") {
payload.Properties.EnableIPForwarding = pointer.To(d.Get("enable_ip_forwarding").(bool))
}

if d.HasChange("internal_dns_name_label") {
update.Properties.DnsSettings.InternalDnsNameLabel = utils.String(d.Get("internal_dns_name_label").(string))
} else {
update.Properties.DnsSettings.InternalDnsNameLabel = existing.Model.Properties.DnsSettings.InternalDnsNameLabel
payload.Properties.DnsSettings.InternalDnsNameLabel = pointer.To(d.Get("internal_dns_name_label").(string))
}

if d.HasChange("ip_configuration") {
Expand All @@ -401,22 +433,15 @@ func resourceNetworkInterfaceUpdate(d *pluginsdk.ResourceData, meta interface{})
// then map the fields managed in other resources back
ipConfigs = mapFieldsToNetworkInterface(ipConfigs, info)

update.Properties.IPConfigurations = ipConfigs
} else {
update.Properties.IPConfigurations = existing.Model.Properties.IPConfigurations
payload.Properties.IPConfigurations = ipConfigs
}

if d.HasChange("tags") {
tagsRaw := d.Get("tags").(map[string]interface{})
update.Tags = tags.Expand(tagsRaw)
} else {
update.Tags = existing.Model.Tags
payload.Tags = tags.Expand(tagsRaw)
}

// this can be managed in another resource, so just port it over
update.Properties.NetworkSecurityGroup = existing.Model.Properties.NetworkSecurityGroup

err = client.CreateOrUpdateThenPoll(ctx, *id, update)
err = client.CreateOrUpdateThenPoll(ctx, *id, *payload)
if err != nil {
return fmt.Errorf("updating %s: %+v", *id, err)
}
Expand Down Expand Up @@ -513,8 +538,12 @@ func resourceNetworkInterfaceRead(d *pluginsdk.ResourceData, meta interface{}) e
}

d.Set("auxiliary_sku", auxiliarySku)
d.Set("enable_ip_forwarding", props.EnableIPForwarding)
d.Set("enable_accelerated_networking", props.EnableAcceleratedNetworking)
d.Set("ip_forwarding_enabled", props.EnableIPForwarding)
d.Set("accelerated_networking_enabled", props.EnableAcceleratedNetworking)
if !features.FourPointOhBeta() {
d.Set("enable_ip_forwarding", props.EnableIPForwarding)
d.Set("enable_accelerated_networking", props.EnableAcceleratedNetworking)
}
d.Set("internal_dns_name_label", internalDnsNameLabel)
d.Set("internal_domain_name_suffix", internalDomainNameSuffix)
d.Set("mac_address", props.MacAddress)
Expand Down Expand Up @@ -623,7 +652,7 @@ func expandNetworkInterfaceIPConfigurations(input []interface{}) (*[]networkinte
}

if v, ok := data["primary"]; ok {
properties.Primary = utils.Bool(v.(bool))
properties.Primary = pointer.To(v.(bool))
}

if v := data["gateway_load_balancer_frontend_ip_configuration_id"].(string); v != "" {
Expand Down
Loading
Loading