Skip to content

Commit

Permalink
fix(sg-rule): added a check to check if remote sg id exists in is_sec…
Browse files Browse the repository at this point in the history
…urity_group_rule
  • Loading branch information
ujjwal-ibm authored and hkantare committed Feb 1, 2022
1 parent 3fa9947 commit e8290dd
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions ibm/service/vpc/resource_ibm_is_security_group_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,18 @@ func parseIBMISSecurityGroupRuleDictionary(d *schema.ResourceData, tag string, s
} else if parsed.remoteSecGrpID != "" {
remoteTemplate.ID = &parsed.remoteSecGrpID
remoteTemplateUpdate.ID = &parsed.remoteSecGrpID

// check if remote is actually a SG identifier
getSecurityGroupOptions := &vpcv1.GetSecurityGroupOptions{
ID: &parsed.remoteSecGrpID,
}
sg, res, err := sess.GetSecurityGroup(getSecurityGroupOptions)
if err != nil || sg == nil {
if res != nil && res.StatusCode == 404 {
return nil, nil, nil, err
}
return nil, nil, nil, fmt.Errorf("Error getting Security Group in remote (%s): %s\n%s", parsed.remoteSecGrpID, err, res)
}
}
sgTemplate.Remote = remoteTemplate
securityGroupRulePatchModel.Remote = remoteTemplateUpdate
Expand Down

0 comments on commit e8290dd

Please sign in to comment.