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

r/network_security_rule: removing the locks by default in 3.0 #15719

Merged
merged 1 commit into from
Mar 14, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 0 additions & 3 deletions internal/features/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ func Default() UserFeatures {
LogAnalyticsWorkspace: LogAnalyticsWorkspaceFeatures{
PermanentlyDeleteOnDestroy: false,
},
Network: NetworkFeatures{
RelaxedLocking: false,
},
ResourceGroup: ResourceGroupFeatures{
PreventDeletionIfContainsResources: false,
},
Expand Down
5 changes: 0 additions & 5 deletions internal/features/user_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ type UserFeatures struct {
VirtualMachine VirtualMachineFeatures
VirtualMachineScaleSet VirtualMachineScaleSetFeatures
KeyVault KeyVaultFeatures
Network NetworkFeatures
TemplateDeployment TemplateDeploymentFeatures
LogAnalyticsWorkspace LogAnalyticsWorkspaceFeatures
ResourceGroup ResourceGroupFeatures
Expand Down Expand Up @@ -39,10 +38,6 @@ type KeyVaultFeatures struct {
RecoverSoftDeletedSecrets bool
}

type NetworkFeatures struct {
RelaxedLocking bool
}

type TemplateDeploymentFeatures struct {
DeleteNestedItemsDuringDeletion bool
}
Expand Down
10 changes: 0 additions & 10 deletions internal/provider/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,16 +317,6 @@ func expandFeatures(input []interface{}) features.UserFeatures {
}
}

if raw, ok := val["network"]; ok {
items := raw.([]interface{})
if len(items) > 0 {
networkRaw := items[0].(map[string]interface{})
if v, ok := networkRaw["relaxed_locking"]; ok {
featuresMap.Network.RelaxedLocking = v.(bool)
}
}
}

if raw, ok := val["template_deployment"]; ok {
items := raw.([]interface{})
if len(items) > 0 {
Expand Down
74 changes: 0 additions & 74 deletions internal/provider/features_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ func TestExpandFeatures(t *testing.T) {
LogAnalyticsWorkspace: features.LogAnalyticsWorkspaceFeatures{
PermanentlyDeleteOnDestroy: false,
},
Network: features.NetworkFeatures{
RelaxedLocking: false,
},
TemplateDeployment: features.TemplateDeploymentFeatures{
DeleteNestedItemsDuringDeletion: true,
},
Expand Down Expand Up @@ -140,9 +137,6 @@ func TestExpandFeatures(t *testing.T) {
LogAnalyticsWorkspace: features.LogAnalyticsWorkspaceFeatures{
PermanentlyDeleteOnDestroy: true,
},
Network: features.NetworkFeatures{
RelaxedLocking: true,
},
ResourceGroup: features.ResourceGroupFeatures{
PreventDeletionIfContainsResources: true,
},
Expand Down Expand Up @@ -243,9 +237,6 @@ func TestExpandFeatures(t *testing.T) {
LogAnalyticsWorkspace: features.LogAnalyticsWorkspaceFeatures{
PermanentlyDeleteOnDestroy: false,
},
Network: features.NetworkFeatures{
RelaxedLocking: false,
},
ResourceGroup: features.ResourceGroupFeatures{
PreventDeletionIfContainsResources: false,
},
Expand Down Expand Up @@ -505,71 +496,6 @@ func TestExpandFeaturesKeyVault(t *testing.T) {
}
}

func TestExpandFeaturesNetwork(t *testing.T) {
testData := []struct {
Name string
Input []interface{}
EnvVars map[string]interface{}
Expected features.UserFeatures
}{
{
Name: "Empty Block",
Input: []interface{}{
map[string]interface{}{
"network": []interface{}{},
},
},
Expected: features.UserFeatures{
Network: features.NetworkFeatures{
RelaxedLocking: false,
},
},
},
{
Name: "Relaxed Locking Enabled",
Input: []interface{}{
map[string]interface{}{
"network": []interface{}{
map[string]interface{}{
"relaxed_locking": true,
},
},
},
},
Expected: features.UserFeatures{
Network: features.NetworkFeatures{
RelaxedLocking: true,
},
},
},
{
Name: "Relaxed Locking Disabled",
Input: []interface{}{
map[string]interface{}{
"network": []interface{}{
map[string]interface{}{
"relaxed_locking": false,
},
},
},
},
Expected: features.UserFeatures{
Network: features.NetworkFeatures{
RelaxedLocking: false,
},
},
},
}

for _, testCase := range testData {
t.Logf("[DEBUG] Test Case: %q", testCase.Name)
result := expandFeatures(testCase.Input)
if !reflect.DeepEqual(result.Network, testCase.Expected.Network) {
t.Fatalf("Expected %+v but got %+v", result.Network, testCase.Expected.Network)
}
}
}

func TestExpandFeaturesTemplateDeployment(t *testing.T) {
testData := []struct {
Name string
Expand Down
11 changes: 0 additions & 11 deletions internal/services/network/network_security_rule_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"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/network/parse"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/suppress"
Expand Down Expand Up @@ -204,11 +203,6 @@ func resourceNetworkSecurityRuleCreateUpdate(d *pluginsdk.ResourceData, meta int
direction := d.Get("direction").(string)
protocol := d.Get("protocol").(string)

if !meta.(*clients.Client).Features.Network.RelaxedLocking {
locks.ByName(id.NetworkSecurityGroupName, networkSecurityGroupResourceName)
defer locks.UnlockByName(id.NetworkSecurityGroupName, networkSecurityGroupResourceName)
}

rule := network.SecurityRule{
Name: &id.Name,
SecurityRulePropertiesFormat: &network.SecurityRulePropertiesFormat{
Expand Down Expand Up @@ -364,11 +358,6 @@ func resourceNetworkSecurityRuleDelete(d *pluginsdk.ResourceData, meta interface
return err
}

if !meta.(*clients.Client).Features.Network.RelaxedLocking {
locks.ByName(id.NetworkSecurityGroupName, networkSecurityGroupResourceName)
defer locks.UnlockByName(id.NetworkSecurityGroupName, networkSecurityGroupResourceName)
}

future, err := client.Delete(ctx, id.ResourceGroup, id.NetworkSecurityGroupName, id.Name)
if err != nil {
return fmt.Errorf("Deleting %s: %+v", *id, err)
Expand Down