Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: Drift Detection and recreation for deleted resources #233

Merged
merged 1 commit into from
Feb 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
8 changes: 4 additions & 4 deletions aquasec/resource_image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func newTestImage() client.Image {
}

func TestResourceAquasecImageCreate(t *testing.T) {
t.Parallel()
//t.Parallel()
image := newTestImage()
rootRef := imageResourceRef("test")
resource.Test(t, resource.TestCase{
Expand Down Expand Up @@ -61,7 +61,7 @@ func TestResourceAquasecImageCreate(t *testing.T) {
}

func TestResourceAquasecImageAllow(t *testing.T) {
t.Parallel()
//t.Parallel()
image := newTestImage()
rootRef := imageResourceRef("test")
resource.Test(t, resource.TestCase{
Expand Down Expand Up @@ -92,7 +92,7 @@ func TestResourceAquasecImageAllow(t *testing.T) {
}

func TestResourceAquasecImageBlock(t *testing.T) {
t.Parallel()
//t.Parallel()
image := newTestImage()
rootRef := imageResourceRef("test")
resource.Test(t, resource.TestCase{
Expand Down Expand Up @@ -123,7 +123,7 @@ func TestResourceAquasecImageBlock(t *testing.T) {
}

func TestResourceAquasecImageAllowAndBlock(t *testing.T) {
t.Parallel()
//t.Parallel()
image := newTestImage()
rootRef := imageResourceRef("test")
resource.Test(t, resource.TestCase{
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
}
}