Skip to content

Commit

Permalink
feature(protocol-state-filtering): Support for protocol state filteri…
Browse files Browse the repository at this point in the history
…ng mode in VNI protocol (#5428)

doc update
  • Loading branch information
deepaksibm authored Jun 18, 2024
1 parent 78b48bb commit e3c9600
Show file tree
Hide file tree
Showing 32 changed files with 916 additions and 12 deletions.
16 changes: 16 additions & 0 deletions ibm/service/vpc/data_source_ibm_is_instance_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,11 @@ func DataSourceIBMISInstanceTemplate() *schema.Resource {
},
},
},
"protocol_state_filtering_mode": {
Type: schema.TypeString,
Computed: true,
Description: "The protocol state filtering mode used for this virtual network interface.",
},
"resource_group": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Expand Down Expand Up @@ -625,6 +630,11 @@ func DataSourceIBMISInstanceTemplate() *schema.Resource {
},
},
},
"protocol_state_filtering_mode": {
Type: schema.TypeString,
Computed: true,
Description: "The protocol state filtering mode used for this virtual network interface.",
},
"resource_group": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Expand Down Expand Up @@ -1798,6 +1808,9 @@ func dataSourceIBMIsInstanceTemplateInstanceNetworkAttachmentPrototypeVirtualNet
}
modelMap["primary_ip"] = []map[string]interface{}{primaryIPMap}
}
if model.ProtocolStateFilteringMode != nil {
modelMap["protocol_state_filtering_mode"] = model.ProtocolStateFilteringMode
}
if model.ResourceGroup != nil {
resourceGroupMap, err := dataSourceIBMIsInstanceTemplateResourceGroupIdentityToMap(model.ResourceGroup)
if err != nil {
Expand Down Expand Up @@ -1869,6 +1882,9 @@ func dataSourceIBMIsInstanceTemplateInstanceNetworkAttachmentPrototypeVirtualNet
}
modelMap["primary_ip"] = []map[string]interface{}{primaryIPMap}
}
if model.ProtocolStateFilteringMode != nil {
modelMap["protocol_state_filtering_mode"] = model.ProtocolStateFilteringMode
}
if model.ResourceGroup != nil {
resourceGroupMap, err := dataSourceIBMIsInstanceTemplateResourceGroupIdentityToMap(model.ResourceGroup)
if err != nil {
Expand Down
10 changes: 10 additions & 0 deletions ibm/service/vpc/data_source_ibm_is_instance_templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,11 @@ func DataSourceIBMISInstanceTemplates() *schema.Resource {
},
},
},
"protocol_state_filtering_mode": {
Type: schema.TypeString,
Computed: true,
Description: "The protocol state filtering mode used for this virtual network interface.",
},
"resource_group": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Expand Down Expand Up @@ -578,6 +583,11 @@ func DataSourceIBMISInstanceTemplates() *schema.Resource {
},
},
},
"protocol_state_filtering_mode": {
Type: schema.TypeString,
Computed: true,
Description: "The protocol state filtering mode used for this virtual network interface.",
},
"resource_group": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,11 @@ func DataSourceIBMIsVirtualNetworkInterface() *schema.Resource {
},
},
},
"protocol_state_filtering_mode": {
Type: schema.TypeString,
Computed: true,
Description: "The protocol state filtering mode used for this virtual network interface.",
},
"resource_group": {
Type: schema.TypeList,
Computed: true,
Expand Down Expand Up @@ -471,7 +476,9 @@ func dataSourceIBMIsVirtualNetworkInterfaceRead(context context.Context, d *sche
if err = d.Set("primary_ip", primaryIP); err != nil {
return diag.FromErr(fmt.Errorf("Error setting primary_ip %s", err))
}

if virtualNetworkInterface.ProtocolStateFilteringMode != nil {
d.Set("protocol_state_filtering_mode", virtualNetworkInterface.ProtocolStateFilteringMode)
}
resourceGroup := []map[string]interface{}{}
if virtualNetworkInterface.ResourceGroup != nil {
modelMap, err := dataSourceIBMIsVirtualNetworkInterfaceResourceGroupReferenceToMap(virtualNetworkInterface.ResourceGroup)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@ func DataSourceIBMIsVirtualNetworkInterfaces() *schema.Resource {
},
},
},
"protocol_state_filtering_mode": {
Type: schema.TypeString,
Computed: true,
Description: "The protocol state filtering mode used for this virtual network interface.",
},
"resource_group": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Expand Down Expand Up @@ -525,6 +530,9 @@ func dataSourceIBMIsVirtualNetworkInterfacesVirtualNetworkInterfaceToMap(model *
}
modelMap["primary_ip"] = []map[string]interface{}{primaryIPMap}
}
if model.ProtocolStateFilteringMode != nil {
modelMap["protocol_state_filtering_mode"] = *model.ProtocolStateFilteringMode
}
if model.ResourceGroup != nil {
resourceGroupMap, err := dataSourceIBMIsVirtualNetworkInterfaceResourceGroupReferenceToMap(model.ResourceGroup)
if err != nil {
Expand Down
36 changes: 36 additions & 0 deletions ibm/service/vpc/resource_ibm_is_bare_metal_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,13 @@ func ResourceIBMIsBareMetalServer() *schema.Resource {
ValidateFunc: validate.InvokeValidator("ibm_is_virtual_network_interface", "vni_name"),
Description: "The name for this virtual network interface. The name is unique across all virtual network interfaces in the VPC.",
},
"protocol_state_filtering_mode": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validate.InvokeValidator("ibm_is_virtual_network_interface", "protocol_state_filtering_mode"),
Description: "The protocol state filtering mode used for this virtual network interface.",
},
"primary_ip": &schema.Schema{
Type: schema.TypeList,
Optional: true,
Expand Down Expand Up @@ -959,6 +966,13 @@ func ResourceIBMIsBareMetalServer() *schema.Resource {
ValidateFunc: validate.InvokeValidator("ibm_is_virtual_network_interface", "vni_name"),
Description: "The name for this virtual network interface. The name is unique across all virtual network interfaces in the VPC.",
},
"protocol_state_filtering_mode": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validate.InvokeValidator("ibm_is_virtual_network_interface", "protocol_state_filtering_mode"),
Description: "The protocol state filtering mode used for this virtual network interface.",
},
"primary_ip": &schema.Schema{
Type: schema.TypeList,
Optional: true,
Expand Down Expand Up @@ -2387,6 +2401,10 @@ func bareMetalServerUpdate(context context.Context, d *schema.ResourceData, meta
allIpSpoofing := d.Get("primary_network_attachment.0.virtual_network_interface.0.allow_ip_spoofing").(bool)
virtualNetworkInterfacePatch.AllowIPSpoofing = &allIpSpoofing
}
if d.HasChange("primary_network_attachment.0.virtual_network_interface.0.protocol_state_filtering_mode") {
psfMode := d.Get("primary_network_attachment.0.virtual_network_interface.0.protocol_state_filtering_mode").(string)
virtualNetworkInterfacePatch.ProtocolStateFilteringMode = &psfMode
}
virtualNetworkInterfacePatchAsPatch, err := virtualNetworkInterfacePatch.AsPatch()
if err != nil {
return fmt.Errorf("[ERROR] Error encountered while apply as patch for virtualNetworkInterfacePatch of BareMetalServer(%s) vni (%s) %s", d.Id(), vniId, err)
Expand Down Expand Up @@ -4058,6 +4076,7 @@ func resourceIBMIsBareMetalServerBareMetalServerNetworkAttachmentReferenceToMap(
vniMap["auto_delete"] = vniDetails.AutoDelete
vniMap["enable_infrastructure_nat"] = vniDetails.EnableInfrastructureNat
vniMap["resource_group"] = vniDetails.ResourceGroup.ID
vniMap["protocol_state_filtering_mode"] = vniDetails.ProtocolStateFilteringMode
primaryipId := *vniDetails.PrimaryIP.ID
if !core.IsNil(vniDetails.Ips) {
ips := []map[string]interface{}{}
Expand Down Expand Up @@ -4200,6 +4219,9 @@ func resourceIBMIsBareMetalServerMapToVirtualNetworkInterfacePrototypeAttachment
if _, ok := d.GetOkExists(enablenat); ok && modelMap["enable_infrastructure_nat"] != nil {
model.EnableInfrastructureNat = core.BoolPtr(modelMap["enable_infrastructure_nat"].(bool))
}
if pStateFilteringInt, ok := modelMap["protocol_state_filtering_mode"]; ok {
model.ProtocolStateFilteringMode = core.StringPtr(pStateFilteringInt.(string))
}
if modelMap["ips"] != nil && modelMap["ips"].(*schema.Set).Len() > 0 {
ips := []vpcv1.VirtualNetworkInterfaceIPPrototypeIntf{}
for _, ipsItem := range modelMap["ips"].(*schema.Set).List() {
Expand Down Expand Up @@ -4458,6 +4480,9 @@ func compareAddedNacs(oldList, newList []interface{}, bareMetalServerId string)
}
virtualNetworkInterface.PrimaryIP = primaryIPModel
}
if newListItemVniMap["protocol_state_filtering_mode"] != nil && newListItemVniMap["protocol_state_filtering_mode"].(string) != "" {
virtualNetworkInterface.ProtocolStateFilteringMode = core.StringPtr(newListItemVniMap["protocol_state_filtering_mode"].(string))
}
if newListItemVniMap["resource_group"] != nil && newListItemVniMap["resource_group"].(string) != "" {

virtualNetworkInterface.ResourceGroup = &vpcv1.ResourceGroupIdentity{
Expand Down Expand Up @@ -4544,6 +4569,9 @@ func compareAddedNacs(oldList, newList []interface{}, bareMetalServerId string)
}
virtualNetworkInterface.PrimaryIP = primaryIPModel
}
if newListVniitemmMap["protocol_state_filtering_mode"] != nil && newListVniitemmMap["protocol_state_filtering_mode"].(string) != "" {
virtualNetworkInterface.ProtocolStateFilteringMode = core.StringPtr(newListVniitemmMap["protocol_state_filtering_mode"].(string))
}
if newListVniitemmMap["resource_group"] != nil && newListVniitemmMap["resource_group"].(string) != "" {

virtualNetworkInterface.ResourceGroup = &vpcv1.ResourceGroupIdentity{
Expand Down Expand Up @@ -4657,6 +4685,8 @@ func compareModifiedNacs(oldList, newList []interface{}, bareMetalServerId strin
s2vniMapIPS := s2VniMap["ips"]
s2vniMapName := s2VniMap["name"]
s2vniMapSG := s2VniMap["security_groups"]
s1vniPSFM := s1VniMap["protocol_state_filtering_mode"]
s2vniPSFM := s2VniMap["protocol_state_filtering_mode"]
vniUpdateOptions := &vpcv1.UpdateVirtualNetworkInterfaceOptions{
ID: &vniId,
}
Expand All @@ -4678,7 +4708,13 @@ func compareModifiedNacs(oldList, newList []interface{}, bareMetalServerId strin
vniPatch.Name = core.StringPtr(s2vniMapName.(string))
hasChanged = true
}
if s1vniPSFM != nil && s2vniPSFM != nil && s1vniPSFM.(string) != s2vniPSFM.(string) {
vniPatch.ProtocolStateFilteringMode = core.StringPtr(s2vniPSFM.(string))
hasChanged = true
}
if hasChanged {
virtualNetworkInterfacePatchAsPatch, err := vniPatch.AsPatch()
vniUpdateOptions.VirtualNetworkInterfacePatch = virtualNetworkInterfacePatchAsPatch
_, res, err := sess.UpdateVirtualNetworkInterface(vniUpdateOptions)
if err != nil {
return fmt.Errorf("%s/n%v", err, res)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,13 @@ func ResourceIBMIsBareMetalServerNetworkAttachment() *schema.Resource {
ValidateFunc: validate.InvokeValidator("ibm_is_virtual_network_interface", "vni_name"),
Description: "The name for this virtual network interface. The name is unique across all virtual network interfaces in the VPC.",
},
"protocol_state_filtering_mode": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validate.InvokeValidator("ibm_is_virtual_network_interface", "protocol_state_filtering_mode"),
Description: "The protocol state filtering mode used for this virtual network interface.",
},
"primary_ip": &schema.Schema{
Type: schema.TypeList,
Optional: true,
Expand Down Expand Up @@ -933,6 +940,10 @@ func resourceIBMIsBareMetalServerNetworkAttachmentUpdate(context context.Context
return diag.FromErr(fmt.Errorf("[ERROR] Error updating vni reserved ip(%s): %s\n%s", ripId, err, response))
}
}
if d.HasChange("virtual_network_interface.0.protocol_state_filtering_mode") {
psfMode := d.Get("virtual_network_interface.0.protocol_state_filtering_mode").(string)
virtualNetworkInterfacePatch.ProtocolStateFilteringMode = &psfMode
}
if d.HasChange("virtual_network_interface.0.security_groups") {
ovs, nvs := d.GetChange("virtual_network_interface.0.security_groups")
ov := ovs.(*schema.Set)
Expand Down Expand Up @@ -1081,6 +1092,9 @@ func resourceIBMIsBareMetalServerNetworkAttachmentMapToBareMetalServerNetworkAtt
if modelMap["name"] != nil && modelMap["name"].(string) != "" {
model.Name = core.StringPtr(modelMap["name"].(string))
}
if pStateFilteringInt, ok := modelMap["protocol_state_filtering_mode"]; ok {
model.ProtocolStateFilteringMode = core.StringPtr(pStateFilteringInt.(string))
}
if modelMap["primary_ip"] != nil && len(modelMap["primary_ip"].([]interface{})) > 0 {
PrimaryIPModel, err := resourceIBMIsBareMetalServerNetworkAttachmentMapToVirtualNetworkInterfacePrimaryIPPrototype(modelMap["primary_ip"].([]interface{})[0].(map[string]interface{}))
if err != nil {
Expand Down Expand Up @@ -1188,6 +1202,7 @@ func resourceIBMIsBareMetalServerNetworkAttachmentVirtualNetworkInterfaceReferen
modelMap["auto_delete"] = vniDetails.AutoDelete
modelMap["enable_infrastructure_nat"] = vniDetails.EnableInfrastructureNat
modelMap["resource_group"] = vniDetails.ResourceGroup.ID
modelMap["protocol_state_filtering_mode"] = vniDetails.ProtocolStateFilteringMode
primaryipId := *vniDetails.PrimaryIP.ID
if !core.IsNil(vniDetails.Ips) {
ips := []map[string]interface{}{}
Expand Down
Loading

0 comments on commit e3c9600

Please sign in to comment.