Skip to content

Commit

Permalink
Development and Documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
SunithaGudisagarIBM1 committed Oct 26, 2023
1 parent 166d3d8 commit 64a1fb1
Show file tree
Hide file tree
Showing 12 changed files with 334 additions and 1 deletion.
37 changes: 37 additions & 0 deletions ibm/service/vpc/data_source_ibm_is_security_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const (
isSgRuleDirection = "direction"
isSgRuleIPVersion = "ip_version"
isSgRuleRemote = "remote"
isSgRuleLocal = "local"
isSgRuleType = "type"
isSgRuleCode = "code"
isSgRulePortMax = "port_max"
Expand Down Expand Up @@ -81,6 +82,12 @@ func DataSourceIBMISSecurityGroup() *schema.Resource {
Description: "Security group id: an IP address, a CIDR block, or a single security group identifier",
},

isSgRuleLocal: {
Type: schema.TypeString,
Computed: true,
Description: "Security group local ip: an IP address, a CIDR block",
},

isSgRuleType: {
Type: schema.TypeInt,
Computed: true,
Expand Down Expand Up @@ -248,6 +255,16 @@ func securityGroupGet(d *schema.ResourceData, meta interface{}, name string) err
}
}
}
local, ok := rule.Local.(*vpcv1.SecurityGroupRuleLocal)
if ok {
if local != nil && reflect.ValueOf(local).IsNil() == false {
if local.Address != nil {
r[isSgRuleLocal] = local.Address
} else if local.CIDRBlock != nil {
r[isSgRuleLocal] = local.CIDRBlock
}
}
}
rules = append(rules, r)
}

Expand All @@ -273,6 +290,16 @@ func securityGroupGet(d *schema.ResourceData, meta interface{}, name string) err
}
}
}
local, ok := rule.Local.(*vpcv1.SecurityGroupRuleLocal)
if ok {
if local != nil && reflect.ValueOf(local).IsNil() == false {
if local.Address != nil {
r[isSgRuleLocal] = local.Address
} else if local.CIDRBlock != nil {
r[isSgRuleLocal] = local.CIDRBlock
}
}
}
rules = append(rules, r)
}

Expand Down Expand Up @@ -303,6 +330,16 @@ func securityGroupGet(d *schema.ResourceData, meta interface{}, name string) err
}
}
}
local, ok := rule.Local.(*vpcv1.SecurityGroupRuleLocal)
if ok {
if local != nil && reflect.ValueOf(local).IsNil() == false {
if local.Address != nil {
r[isSgRuleLocal] = local.Address
} else if local.CIDRBlock != nil {
r[isSgRuleLocal] = local.CIDRBlock
}
}
}
rules = append(rules, r)
}
}
Expand Down
67 changes: 67 additions & 0 deletions ibm/service/vpc/data_source_ibm_is_security_group_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,25 @@ func DataSourceIBMIsSecurityGroupRule() *schema.Resource {
},
},
},
"local": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Description: "The local IP address or range of local IP addresses to which this rule will allow inbound traffic (or from which, for outbound traffic). A CIDR block of 0.0.0.0/0 allows traffic to all local IP addresses (or from all local IP addresses, for outbound rules).",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"address": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The IP address.This property may add support for IPv6 addresses in the future. When processing a value in this property, verify that the address is in an expected format. If it is not, log an error. Optionally halt processing and surface the error, or bypass the resource on which the unexpected IP address format was encountered.",
},
"cidr_block": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The CIDR block. This property may add support for IPv6 CIDR blocks in the future. When processing a value in this property, verify that the CIDR block is in an expected format. If it is not, log an error. Optionally halt processing and surface the error, or bypass the resource on which the unexpected CIDR block format was encountered.",
},
},
},
},
"code": &schema.Schema{
Type: schema.TypeInt,
Computed: true,
Expand Down Expand Up @@ -173,6 +192,16 @@ func dataSourceIBMIsSecurityGroupRuleRead(context context.Context, d *schema.Res
return diag.FromErr(fmt.Errorf("Error setting remote %s", err))
}
}
if securityGroupRule.Local != nil {
securityGroupRuleLocal, err := dataSourceSecurityGroupRuleFlattenLocal(securityGroupRule.Local)
if err != nil {
return diag.FromErr(fmt.Errorf("Error flattening securityGroupRule.Local %s", err))
}
err = d.Set("local", securityGroupRuleLocal)
if err != nil {
return diag.FromErr(fmt.Errorf("Error setting local %s", err))
}
}

}
case "*vpcv1.SecurityGroupRuleSecurityGroupRuleProtocolIcmp":
Expand Down Expand Up @@ -202,6 +231,16 @@ func dataSourceIBMIsSecurityGroupRuleRead(context context.Context, d *schema.Res
return diag.FromErr(fmt.Errorf("Error setting remote %s", err))
}
}
if securityGroupRule.Local != nil {
securityGroupRuleLocal, err := dataSourceSecurityGroupRuleFlattenLocal(securityGroupRule.Local)
if err != nil {
return diag.FromErr(fmt.Errorf("Error flattening securityGroupRule.Local %s", err))
}
err = d.Set("local", securityGroupRuleLocal)
if err != nil {
return diag.FromErr(fmt.Errorf("Error setting local %s", err))
}
}

if err = d.Set("code", flex.IntValue(securityGroupRule.Code)); err != nil {
return diag.FromErr(fmt.Errorf("Error setting code: %s", err))
Expand Down Expand Up @@ -237,6 +276,16 @@ func dataSourceIBMIsSecurityGroupRuleRead(context context.Context, d *schema.Res
return diag.FromErr(fmt.Errorf("Error setting remote %s", err))
}
}
if securityGroupRule.Local != nil {
securityGroupRuleLocal, err := dataSourceSecurityGroupRuleFlattenLocal(securityGroupRule.Local)
if err != nil {
return diag.FromErr(fmt.Errorf("Error flattening securityGroupRule.Local %s", err))
}
err = d.Set("local", securityGroupRuleLocal)
if err != nil {
return diag.FromErr(fmt.Errorf("Error setting local %s", err))
}
}
if err = d.Set("port_max", flex.IntValue(securityGroupRule.PortMax)); err != nil {
return diag.FromErr(fmt.Errorf("Error setting port_max: %s", err))
}
Expand Down Expand Up @@ -289,6 +338,24 @@ func dataSourceSecurityGroupRuleRemoteToMap(remoteItem *vpcv1.SecurityGroupRuleR
return remoteMap
}

func dataSourceSecurityGroupRuleFlattenLocal(m vpcv1.SecurityGroupRuleLocalIntf) ([]map[string]interface{}, error) {
var ruleList []map[string]interface{}
ruleMap := dataSourceSecurityGroupRuleLocalToMap(m.(*vpcv1.SecurityGroupRuleLocal))
ruleList = append(ruleList, ruleMap)
return ruleList, nil
}

func dataSourceSecurityGroupRuleLocalToMap(localItem *vpcv1.SecurityGroupRuleLocal) (localMap map[string]interface{}) {
localMap = map[string]interface{}{}
if localItem.Address != nil {
localMap["address"] = *localItem.Address
}
if localItem.CIDRBlock != nil {
localMap["cidr_block"] = *localItem.CIDRBlock
}
return localMap
}

func dataSourceSecurityGroupRuleRemoteDeletedToMap(deletedItem *vpcv1.SecurityGroupReferenceDeleted) (resultMap map[string]interface{}) {
resultMap = map[string]interface{}{}

Expand Down
40 changes: 40 additions & 0 deletions ibm/service/vpc/data_source_ibm_is_security_group_rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,25 @@ func DataSourceIBMIsSecurityGroupRules() *schema.Resource {
},
},
},
"local": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Description: "The local IP address or range of local IP addresses to which this rule will allow inbound traffic (or from which, for outbound traffic). A CIDR block of 0.0.0.0/0 allows traffic to all local IP addresses (or from all local IP addresses, for outbound rules).",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"address": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The IP address.This property may add support for IPv6 addresses in the future. When processing a value in this property, verify that the address is in an expected format. If it is not, log an error. Optionally halt processing and surface the error, or bypass the resource on which the unexpected IP address format was encountered.",
},
"cidr_block": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The CIDR block. This property may add support for IPv6 CIDR blocks in the future. When processing a value in this property, verify that the CIDR block is in an expected format. If it is not, log an error. Optionally halt processing and surface the error, or bypass the resource on which the unexpected CIDR block format was encountered.",
},
},
},
},
"code": &schema.Schema{
Type: schema.TypeInt,
Computed: true,
Expand Down Expand Up @@ -168,6 +187,13 @@ func dataSourceIBMIsSecurityGroupRulesRead(d *schema.ResourceData, meta interfac
remoteList = append(remoteList, remoteMap)
l["remote"] = remoteList
}
// nested map for local.
if rulex.Local != nil {
localList := []map[string]interface{}{}
localMap := dataSourceSecurityGroupRuleLocalToMap(rulex.Local.(*vpcv1.SecurityGroupRuleLocal))
localList = append(localList, localMap)
l["local"] = localList
}

}
case "*vpcv1.SecurityGroupRuleSecurityGroupRuleProtocolIcmp":
Expand All @@ -187,6 +213,13 @@ func dataSourceIBMIsSecurityGroupRulesRead(d *schema.ResourceData, meta interfac
remoteList = append(remoteList, remoteMap)
l["remote"] = remoteList
}
// nested map for local.
if rulex.Local != nil {
localList := []map[string]interface{}{}
localMap := dataSourceSecurityGroupRuleLocalToMap(rulex.Local.(*vpcv1.SecurityGroupRuleLocal))
localList = append(localList, localMap)
l["local"] = localList
}
}
case "*vpcv1.SecurityGroupRuleSecurityGroupRuleProtocolTcpudp":
{
Expand All @@ -205,6 +238,13 @@ func dataSourceIBMIsSecurityGroupRulesRead(d *schema.ResourceData, meta interfac
remoteList = append(remoteList, remoteMap)
l["remote"] = remoteList
}
// nested map for local.
if rulex.Local != nil {
localList := []map[string]interface{}{}
localMap := dataSourceSecurityGroupRuleLocalToMap(rulex.Local.(*vpcv1.SecurityGroupRuleLocal))
localList = append(localList, localMap)
l["local"] = localList
}
}
}
rulesInfo = append(rulesInfo, l)
Expand Down
50 changes: 50 additions & 0 deletions ibm/service/vpc/data_source_ibm_is_security_groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,25 @@ func DataSourceIBMIsSecurityGroups() *schema.Resource {
Computed: true,
Description: "The protocol to enforce.",
},
"local": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Description: "The local IP address or range of local IP addresses to which this rule will allow inbound traffic (or from which, for outbound traffic). A CIDR block of 0.0.0.0/0 allows traffic to all local IP addresses (or from all local IP addresses, for outbound rules).",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"address": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The IP address.This property may add support for IPv6 addresses in the future. When processing a value in this property, verify that the address is in an expected format. If it is not, log an error. Optionally halt processing and surface the error, or bypass the resource on which the unexpected IP address format was encountered.",
},
"cidr_block": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The CIDR block. This property may add support for IPv6 CIDR blocks in the future. When processing a value in this property, verify that the CIDR block is in an expected format. If it is not, log an error. Optionally halt processing and surface the error, or bypass the resource on which the unexpected CIDR block format was encountered.",
},
},
},
},
"remote": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Expand Down Expand Up @@ -476,6 +495,12 @@ func dataSourceSecurityGroupCollectionSecurityGroupsRulesToMap(rulesItem vpcv1.S
remoteList = append(remoteList, remoteMap)
resultMap["remote"] = remoteList
}
if securityGroupRule.Local != nil {
localList := []map[string]interface{}{}
localMap := dataSourceSecurityGroupsLocalToMap(*securityGroupRule.Local.(*vpcv1.SecurityGroupRuleLocal))
localList = append(localList, localMap)
resultMap["local"] = localList
}
}
case "*vpcv1.SecurityGroupRuleSecurityGroupRuleProtocolIcmp":
{
Expand Down Expand Up @@ -511,6 +536,12 @@ func dataSourceSecurityGroupCollectionSecurityGroupsRulesToMap(rulesItem vpcv1.S
remoteList = append(remoteList, remoteMap)
resultMap["remote"] = remoteList
}
if securityGroupRule.Local != nil {
localList := []map[string]interface{}{}
localMap := dataSourceSecurityGroupsLocalToMap(*securityGroupRule.Local.(*vpcv1.SecurityGroupRuleLocal))
localList = append(localList, localMap)
resultMap["local"] = localList
}
}
case "*vpcv1.SecurityGroupRuleSecurityGroupRuleProtocolTcpudp":
{
Expand Down Expand Up @@ -546,6 +577,12 @@ func dataSourceSecurityGroupCollectionSecurityGroupsRulesToMap(rulesItem vpcv1.S
remoteList = append(remoteList, remoteMap)
resultMap["remote"] = remoteList
}
if securityGroupRule.Local != nil {
localList := []map[string]interface{}{}
localMap := dataSourceSecurityGroupsLocalToMap(*securityGroupRule.Local.(*vpcv1.SecurityGroupRuleLocal))
localList = append(localList, localMap)
resultMap["local"] = localList
}
}
}

Expand Down Expand Up @@ -703,3 +740,16 @@ func dataSourceSecurityGroupsRemoteToMap(remoteItem vpcv1.SecurityGroupRuleRemot
}
return remoteMap
}

func dataSourceSecurityGroupsLocalToMap(localItem vpcv1.SecurityGroupRuleLocal) (localMap map[string]interface{}) {
localMap = map[string]interface{}{}

if localItem.Address != nil {
localMap["address"] = *localItem.Address
}

if localItem.CIDRBlock != nil {
localMap["cidr_block"] = *localItem.CIDRBlock
}
return localMap
}
36 changes: 36 additions & 0 deletions ibm/service/vpc/resource_ibm_is_security_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,16 @@ func resourceIBMISSecurityGroupRead(d *schema.ResourceData, meta interface{}) er
}
}
}
local, ok := rule.Local.(*vpcv1.SecurityGroupRuleLocal)
if ok {
if local != nil && reflect.ValueOf(local).IsNil() == false {
if local.Address != nil {
r[isSecurityGroupRuleLocal] = local.Address
} else if local.CIDRBlock != nil {
r[isSecurityGroupRuleLocal] = local.CIDRBlock
}
}
}
rules = append(rules, r)
}
case "*vpcv1.SecurityGroupRuleSecurityGroupRuleProtocolAll":
Expand All @@ -312,6 +322,16 @@ func resourceIBMISSecurityGroupRead(d *schema.ResourceData, meta interface{}) er
}
}
}
local, ok := rule.Local.(*vpcv1.SecurityGroupRuleLocal)
if ok {
if local != nil && reflect.ValueOf(local).IsNil() == false {
if local.Address != nil {
r[isSecurityGroupRuleLocal] = local.Address
} else if local.CIDRBlock != nil {
r[isSecurityGroupRuleLocal] = local.CIDRBlock
}
}
}
rules = append(rules, r)
}
case "*vpcv1.SecurityGroupRuleSecurityGroupRuleProtocolTcpudp":
Expand Down Expand Up @@ -341,6 +361,16 @@ func resourceIBMISSecurityGroupRead(d *schema.ResourceData, meta interface{}) er
}
}
}
local, ok := rule.Local.(*vpcv1.SecurityGroupRuleLocal)
if ok {
if local != nil && reflect.ValueOf(local).IsNil() == false {
if local.Address != nil {
r[isSecurityGroupRuleLocal] = local.Address
} else if local.CIDRBlock != nil {
r[isSecurityGroupRuleLocal] = local.CIDRBlock
}
}
}
rules = append(rules, r)
}
}
Expand Down Expand Up @@ -548,6 +578,12 @@ func makeIBMISSecurityRuleSchema() map[string]*schema.Schema {
Description: "Security group id: an IP address, a CIDR block, or a single security group identifier",
},

isSecurityGroupRuleLocal: {
Type: schema.TypeString,
Computed: true,
Description: "Security group local ip: an IP address, a CIDR block",
},

isSecurityGroupRuleType: {
Type: schema.TypeInt,
Computed: true,
Expand Down
Loading

0 comments on commit 64a1fb1

Please sign in to comment.