Skip to content

Commit

Permalink
Merge pull request #18 from nifcloud/fix/security-group-rule-flatten
Browse files Browse the repository at this point in the history
resource/nifcloud_security_group_rule: Fix bug of flatten
  • Loading branch information
tunakyonn authored Dec 14, 2020
2 parents bed2cb5 + dd23514 commit 5f8c9bd
Showing 1 changed file with 29 additions and 12 deletions.
41 changes: 29 additions & 12 deletions nifcloud/resources/securitygrouprule/flattener.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func flatten(d *schema.ResourceData, res *computing.DescribeSecurityGroupsRespon
r := expandAuthorizeSecurityGroupIngressInputList(d)[0].IpPermissions[0]
for i := range res.SecurityGroupInfo[0].IpPermissions {
p := &res.SecurityGroupInfo[0].IpPermissions[i]

if p.ToPort != nil && r.ToPort != nil && nifcloud.Int64Value(p.ToPort) != nifcloud.Int64Value(r.ToPort) {
continue
}
Expand All @@ -35,21 +36,37 @@ func flatten(d *schema.ResourceData, res *computing.DescribeSecurityGroupsRespon
continue
}

if len(p.IpRanges) > 0 &&
len(r.ListOfRequestIpRanges) > 0 &&
p.IpRanges[0].CidrIp != nil &&
r.ListOfRequestIpRanges[0].CidrIp != nil &&
nifcloud.StringValue(p.IpRanges[0].CidrIp) != nifcloud.StringValue(r.ListOfRequestIpRanges[0].CidrIp) {
if nifcloud.StringValue(p.InOut) != string(r.InOut) {
continue
}
if len(p.Groups) > 0 &&
len(r.ListOfRequestGroups) > 0 &&
p.Groups[0].GroupName != nil &&
r.ListOfRequestGroups[0].GroupName != nil &&
nifcloud.StringValue(p.Groups[0].GroupName) != nifcloud.StringValue(r.ListOfRequestGroups[0].GroupName) {
continue

findCidrIP := false
if len(r.ListOfRequestIpRanges) > 0 {
for _, ip := range p.IpRanges {
if nifcloud.StringValue(ip.CidrIp) == nifcloud.StringValue(r.ListOfRequestIpRanges[0].CidrIp) {
findCidrIP = true
break
}
}
}
if findCidrIP {
rule = p
break
}

findGroup := false
if len(r.ListOfRequestGroups) > 0 {
for _, gn := range p.Groups {
if nifcloud.StringValue(gn.GroupName) == nifcloud.StringValue(r.ListOfRequestGroups[0].GroupName) {
findGroup = true
break
}
}
}
if findGroup {
rule = p
break
}
rule = p
}

if rule == nil {
Expand Down

0 comments on commit 5f8c9bd

Please sign in to comment.