// Revoke all ingress/egress rules that a Security Group has
Revoke all ingress/egress rules that a Security Group has
// Revoke all ingress / egress rules that a Security Group has
func forceRevokeSecurityGroupRules(conn *ec2.EC2, d *schema.ResourceData) error {
	sgRaw, _, err := SGStateRefreshFunc(conn, d.Id())()
	if err != nil {
		return err
	}
	if sgRaw == nil {
		return nil
	}
	group := sgRaw.(*ec2.SecurityGroup)
	if len(group.IpPermissions) > 0 {
		req := &ec2.RevokeSecurityGroupIngressInput{
			GroupId:       group.GroupId,
			IpPermissions: group.IpPermissions,
		}
		if group.VpcId == nil || *group.VpcId == "" {
			req.GroupId = nil
			req.GroupName = group.GroupName
		}
		_, err = conn.RevokeSecurityGroupIngress(req)
		if err != nil {
			return fmt.Errorf(
				"Error revoking security group %s rules: %s",
				*group.GroupId, err)
		}
	}
	if len(group.IpPermissionsEgress) > 0 {
		req := &ec2.RevokeSecurityGroupEgressInput{
			GroupId:       group.GroupId,
			IpPermissions: group.IpPermissionsEgress,
		}
		_, err = conn.RevokeSecurityGroupEgress(req)
		if err != nil {
			return fmt.Errorf(
				"Error revoking security group %s rules: %s",
				*group.GroupId, err)
		}
	}
	return nil
}
func forceRevokeSecurityGroupRules ( conn * ec2 . EC2 , d * schema . ResourceData ) error { sgRaw , _ , err := SGStateRefreshFunc ( conn , d . Id ( ) ) ( ) if err != nil { return err } if sgRaw == nil { return nil } group := sgRaw . ( * ec2 . SecurityGroup ) if len ( group . IpPermissions ) > 0 { req := & ec2 . RevokeSecurityGroupIngressInput { GroupId : group . GroupId , IpPermissions : group . IpPermissions , } if group . VpcId == nil || * group . VpcId == " " { req . GroupId = nil req . GroupName = group . GroupName } _ , err = conn . RevokeSecurityGroupIngress ( req ) if err != nil { return fmt . Errorf ( " " , * group . GroupId , err ) } } if len ( group . IpPermissionsEgress ) > 0 { req := & ec2 . RevokeSecurityGroupEgressInput { GroupId : group . GroupId , IpPermissions : group . IpPermissionsEgress , } _ , err = conn . RevokeSecurityGroupEgress ( req ) if err != nil { return fmt . Errorf ( " " , * group . GroupId , err ) } } return nil }
Revoke all ingress/egress rules that a Security Group has
Revoke all ingress / egress rules that a Security Group has