Scalr\Service\Aws\Ec2\V20140615\Ec2Api::deleteSecurityGroup PHP Method

deleteSecurityGroup() public method

Deletes a security group. This action applies to both EC2 security groups and VPC security groups. For information about VPC security groups and how they differ from EC2 security groups, see Security Groups in the Amazon Virtual Private Cloud User Guide. Note! If you attempt to delete a security group that contains instances, or attempt to delete a security group that is referenced by another security group, an error is returned. For example, if security group B has a rule that allows access from security group A, security group A cannot be deleted until the rule is removed. The fault returned is InvalidGroup.InUse for EC2 security groups, or DependencyViolation for VPC security groups.
public deleteSecurityGroup ( string $groupId = null, string $groupName = null ) : boolean
$groupId string optional The ID of the security group to remove.
$groupName string optional The name of security group to remove.
return boolean Returns true on success or throws an exception.
    public function deleteSecurityGroup($groupId = null, $groupName = null)
    {
        $result = false;
        $options = array();
        if ($groupName === null && $groupId === null || $groupName !== null && $groupId !== null) {
            throw new \InvalidArgumentException(sprintf('Either groupName or groupId is required for the %s. ' . 'Also you cannot specify both in the same call.', __METHOD__));
        }
        if ($groupId !== null) {
            $options['GroupId'] = (string) $groupId;
        } else {
            if ($groupName !== null) {
                $options['GroupName'] = (string) $groupName;
            }
        }
        $response = $this->client->call(ucfirst(__FUNCTION__), $options);
        if ($response->getError() === false) {
            $result = true;
            $entity = null;
            if (!empty($options['GroupId'])) {
                $entity = $this->ec2->getEntityManagerEnabled() ? $this->ec2->securityGroup->get($options['GroupId']) : null;
            } else {
                if (!empty($options['GroupName'])) {
                    //Undesirable workaround.
                    //You can have an EC2 security group with the same name as a VPC security group
                    //(each group has a unique security group ID separate from the name).
                    /*
                    $entity = $this
                        ->getEntityManager()->getRepository('Ec2:SecurityGroup')
                        ->findOneBy(array('groupName' => $options['GroupName']))
                    ;
                    */
                }
            }
            if (isset($entity)) {
                $this->getEntityManager()->detach($entity);
            }
        }
        return $result;
    }
Ec2Api