 
 (defn- build-sg
   [opts]
-  (delete-sg (get opts :GroupName))
+  (delete-sg (:GroupName opts))
   (if-let [sg-id (create opts)]
-    (do
-      (configure-network sg-id opts)
-      (log/info "Succesfully created and configured a security group with the config " opts))
+    (try+
+     (do
+       (configure-network sg-id opts)
+       (log/info "Succesfully created and configured a security group with the config " opts))
+     (catch map? error
+       (delete-sg (:GroupName opts))
+       (throw+ error)))
     (log/error "Security group already exists for the config " opts)))
 
 (defn- filter-params

  (let [egress (check-default-egress opts)]
    (when-not (empty? egress)
      (network-action sg-id egress :AuthorizeSecurityGroupEgress)
      (network-action sg-id {:IpRanges "0.0.0.0/0" :IpProtocol "-1"} :RevokeSecurityGroupEgress))))

(defn- network-config
  [params]

  (let [opts (-> opts
                 (assoc :Ingress (flatten (:Ingress opts)))
                 (assoc :Egress (flatten (:Egress opts))))
        response (process :DescribeSecurityGroups (filter-params opts))]
    (if-let [sg-id (xml1-> response :securityGroupInfo :item :groupId text) ]
      (compare-sg sg-id response opts)
