-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
Reverting the change to make Nested security rules from List to Set. … #893
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
package azurerm | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
|
||
"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2017-09-01/network" | ||
"github.com/hashicorp/terraform/helper/hashcode" | ||
"github.com/hashicorp/terraform/helper/schema" | ||
"github.com/hashicorp/terraform/helper/validation" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" | ||
|
@@ -33,7 +35,7 @@ func resourceArmNetworkSecurityGroup() *schema.Resource { | |
"resource_group_name": resourceGroupNameSchema(), | ||
|
||
"security_rule": { | ||
Type: schema.TypeList, | ||
Type: schema.TypeSet, | ||
Optional: true, | ||
Computed: true, | ||
Elem: &schema.Resource{ | ||
|
@@ -103,6 +105,7 @@ func resourceArmNetworkSecurityGroup() *schema.Resource { | |
}, | ||
}, | ||
}, | ||
Set: resourceArmNetworkSecurityGroupRuleHash, | ||
}, | ||
|
||
"tags": tagsSchema(), | ||
|
@@ -216,8 +219,23 @@ func resourceArmNetworkSecurityGroupDelete(d *schema.ResourceData, meta interfac | |
return err | ||
} | ||
|
||
func flattenNetworkSecurityRules(rules *[]network.SecurityRule) []interface{} { | ||
result := make([]interface{}, 0) | ||
func resourceArmNetworkSecurityGroupRuleHash(v interface{}) int { | ||
var buf bytes.Buffer | ||
m := v.(map[string]interface{}) | ||
buf.WriteString(fmt.Sprintf("%s-", m["protocol"].(string))) | ||
buf.WriteString(fmt.Sprintf("%s-", m["source_port_range"].(string))) | ||
buf.WriteString(fmt.Sprintf("%s-", m["destination_port_range"].(string))) | ||
buf.WriteString(fmt.Sprintf("%s-", m["source_address_prefix"].(string))) | ||
buf.WriteString(fmt.Sprintf("%s-", m["destination_address_prefix"].(string))) | ||
buf.WriteString(fmt.Sprintf("%s-", m["access"].(string))) | ||
buf.WriteString(fmt.Sprintf("%d-", m["priority"].(int))) | ||
buf.WriteString(fmt.Sprintf("%s-", m["direction"].(string))) | ||
|
||
return hashcode.String(buf.String()) | ||
} | ||
|
||
func flattenNetworkSecurityRules(rules *[]network.SecurityRule) []map[string]interface{} { | ||
result := make([]map[string]interface{}, 0, len(*rules)) | ||
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. there's a crash here is
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. Fixed it. |
||
|
||
if rules != nil { | ||
for _, rule := range *rules { | ||
|
@@ -255,8 +273,8 @@ func flattenNetworkSecurityRules(rules *[]network.SecurityRule) []interface{} { | |
} | ||
|
||
func expandAzureRmSecurityRules(d *schema.ResourceData) ([]network.SecurityRule, error) { | ||
sgRules := d.Get("security_rule").([]interface{}) | ||
rules := make([]network.SecurityRule, 0) | ||
sgRules := d.Get("security_rule").(*schema.Set).List() | ||
rules := make([]network.SecurityRule, 0, len(sgRules)) | ||
|
||
for _, sgRaw := range sgRules { | ||
data := sgRaw.(map[string]interface{}) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
since all items are contained within the Set's hash function, we actually don't need to specify this function at all - so can we remove this method? the default set hash function will include all values in the set
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.
Agreed. removed this function.