Skip to content

Commit

Permalink
bug: Drift Detection and recreation for deleted resources
Browse files Browse the repository at this point in the history
  • Loading branch information
yossig-aquasec committed Feb 1, 2023
1 parent a23ff32 commit 4184e47
Show file tree
Hide file tree
Showing 22 changed files with 31 additions and 22 deletions.
2 changes: 1 addition & 1 deletion aquasec/resource_acknowledge.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ func resourceAcknowledgeRead(d *schema.ResourceData, m interface{}) error {
currentAcknowledges, err := ac.AcknowledgeRead()

if err != nil {
if strings.Contains(fmt.Sprintf("%s", err), "404 Not Found") {
if strings.Contains(fmt.Sprintf("%s", err), "404") {
d.SetId("")
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion aquasec/resource_application_scope.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ func resourceApplicationScopeRead(d *schema.ResourceData, m interface{}) error {

iap, err := ac.GetApplicationScope(d.Id())
if err != nil {
if strings.Contains(fmt.Sprintf("%s", err), "404 Not Found") {
if strings.Contains(fmt.Sprintf("%s", err), "404") {
d.SetId("")
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion aquasec/resource_aqua_labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func resourceAquaLabelRead(d *schema.ResourceData, m interface{}) error {
r, err := c.GetAquaLabel(d.Id())

if err != nil {
if strings.Contains(fmt.Sprintf("%s", err), "404 Not Found") {
if strings.Contains(fmt.Sprintf("%s", err), "404") {
d.SetId("")
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion aquasec/resource_container_runtime_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ func resourceContainerRuntimePolicyRead(ctx context.Context, d *schema.ResourceD
crp, err := c.GetRuntimePolicy(d.Id())

if err != nil {
if strings.Contains(fmt.Sprintf("%s", err), "404 Not Found") {
if strings.Contains(fmt.Sprintf("%s", err), "404") {
d.SetId("")
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion aquasec/resource_enforcer_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ func resourceEnforcerGroupRead(d *schema.ResourceData, m interface{}) error {
r, err := ac.GetEnforcerGroup(name)

if err != nil {
if strings.Contains(fmt.Sprintf("%s", err), "404 Not Found") {
if strings.Contains(fmt.Sprintf("%s", err), "404") {
d.SetId("")
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion aquasec/resource_firewall_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func resourceFirewallPolicyRead(ctx context.Context, d *schema.ResourceData, m i
firewallPolicy, err := c.GetFirewallPolicy(d.Id())

if err != nil {
if strings.Contains(fmt.Sprintf("%s", err), "404 Not Found") {
if strings.Contains(fmt.Sprintf("%s", err), "404") {
d.SetId("")
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion aquasec/resource_function_assurance_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ func resourceFunctionAssurancePolicyRead(d *schema.ResourceData, m interface{})
iap, err := ac.GetAssurancePolicy(d.Id(), assurance_type)

if err != nil {
if strings.Contains(fmt.Sprintf("%s", err), "404 Not Found") {
if strings.Contains(fmt.Sprintf("%s", err), "404") {
d.SetId("")
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion aquasec/resource_function_runtime_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func resourceFunctionRuntimePolicyRead(ctx context.Context, d *schema.ResourceDa
crp, err := c.GetRuntimePolicy(d.Id())

if err != nil {
if strings.Contains(fmt.Sprintf("%s", err), "404 Not Found") {
if strings.Contains(fmt.Sprintf("%s", err), "404") {
d.SetId("")
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion aquasec/resource_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func resourceGroupRead(d *schema.ResourceData, m interface{}) error {
r, err := ac.GetGroup(id)

if err != nil {
if strings.Contains(fmt.Sprintf("%s", err), "404 Not Found") {
if strings.Contains(fmt.Sprintf("%s", err), "404") {
d.SetId("")
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion aquasec/resource_host_assurance_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ func resourceHostAssurancePolicyRead(d *schema.ResourceData, m interface{}) erro
iap, err := ac.GetAssurancePolicy(d.Id(), assurance_type)

if err != nil {
if strings.Contains(fmt.Sprintf("%s", err), "404 Not Found") {
if strings.Contains(fmt.Sprintf("%s", err), "404") {
d.SetId("")
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion aquasec/resource_host_runtime_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ func resourceHostRuntimePolicyRead(ctx context.Context, d *schema.ResourceData,
crp, err := c.GetRuntimePolicy(d.Id())

if err != nil {
if strings.Contains(fmt.Sprintf("%s", err), "404 Not Found") {
if strings.Contains(fmt.Sprintf("%s", err), "404") {
d.SetId("")
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions aquasec/resource_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ func resourceImageRead(ctx context.Context, d *schema.ResourceData, m interface{
newImage, err := c.GetImage(id)

if err != nil {
if strings.Contains(fmt.Sprintf("%s", err), "404 Not Found") {
if strings.Contains(fmt.Sprintf("%s", err), "404") {
d.SetId("")
return nil
}
Expand All @@ -730,7 +730,7 @@ func resourceImageRead(ctx context.Context, d *schema.ResourceData, m interface{
vulnerabilities, err := c.GetVulnerabilities(newImage)

if err != nil {
if strings.Contains(fmt.Sprintf("%s", err), "404 Not Found") {
if strings.Contains(fmt.Sprintf("%s", err), "404") {
d.SetId("")
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion aquasec/resource_image_assurance_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ func resourceImageAssurancePolicyRead(d *schema.ResourceData, m interface{}) err
iap, err := ac.GetAssurancePolicy(d.Id(), assurance_type)

if err != nil {
if strings.Contains(fmt.Sprintf("%s", err), "404 Not Found") {
if strings.Contains(fmt.Sprintf("%s", err), "404") {
d.SetId("")
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion aquasec/resource_kubernetes_assurance_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ func resourceKubernetesAssurancePolicyRead(d *schema.ResourceData, m interface{}
iap, err := ac.GetAssurancePolicy(d.Id(), assurance_type)

if err != nil {
if strings.Contains(fmt.Sprintf("%s", err), "404 Not Found") {
if strings.Contains(fmt.Sprintf("%s", err), "404") {
d.SetId("")
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion aquasec/resource_notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func resourceNotificationRead(d *schema.ResourceData, m interface{}) error {

r, err := ac.SlackNotificationRead()
if err != nil {
if strings.Contains(fmt.Sprintf("%s", err), "404 Not Found") {
if strings.Contains(fmt.Sprintf("%s", err), "404") {
d.SetId("")
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion aquasec/resource_permission_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func resourcePermissionSetRead(d *schema.ResourceData, m interface{}) error {
iap, err := ac.GetPermissionsSet(d.Id())

if err != nil {
if strings.Contains(fmt.Sprintf("%s", err), "404 Not Found") {
if strings.Contains(fmt.Sprintf("%s", err), "404") {
d.SetId("")
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion aquasec/resource_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func resourceRegistryRead(d *schema.ResourceData, m interface{}) error {

r, err := ac.GetRegistry(d.Id())
if err != nil {
if strings.Contains(fmt.Sprintf("%s", err), "404 Not Found") {
if strings.Contains(fmt.Sprintf("%s", err), "404") {
d.SetId("")
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion aquasec/resource_role.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func resourceRoleRead(d *schema.ResourceData, m interface{}) error {
r, err := ac.GetRole(d.Id())

if err != nil {
if strings.Contains(fmt.Sprintf("%s", err), "404 Not Found") {
if strings.Contains(fmt.Sprintf("%s", err), "404") {
d.SetId("")
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion aquasec/resource_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ func resourceServiceRead(ctx context.Context, d *schema.ResourceData, m interfac
service, err := c.GetService(d.Id())

if err != nil {
if strings.Contains(fmt.Sprintf("%s", err), "404 Not Found") {
if strings.Contains(fmt.Sprintf("%s", err), "404") {
d.SetId("")
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion aquasec/resource_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func resourceUserRead(d *schema.ResourceData, m interface{}) error {

r, err := ac.GetUser(d.Id())
if err != nil {
if strings.Contains(fmt.Sprintf("%s", err), "404 Not Found") {
if strings.Contains(fmt.Sprintf("%s", err), "404") {
d.SetId("")
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion aquasec/resource_user_saas.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ func resourceUserSaasRead(d *schema.ResourceData, m interface{}) error {
ac := m.(*client.Client)
r, err := ac.GetUser(d.Id())
if err != nil {
if strings.Contains(fmt.Sprintf("%s", err), "404 Not Found") {
if strings.Contains(fmt.Sprintf("%s", err), "404") {
d.SetId("")
return nil
}
Expand Down
9 changes: 9 additions & 0 deletions aquasec/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/aquasecurity/terraform-provider-aquasec/client"
"github.com/aquasecurity/terraform-provider-aquasec/consts"
os "os"
"strings"
)

func convertStringArr(ifaceArr []interface{}) []string {
Expand Down Expand Up @@ -186,3 +187,11 @@ func isSaasEnv() bool {
return false
}
}

func isResourceExist(response string) bool {
if strings.Contains(response, "404") {
return false
} else {
return true
}
}

0 comments on commit 4184e47

Please sign in to comment.