Skip to content

Commit

Permalink
add logs when drift detected
Browse files Browse the repository at this point in the history
  • Loading branch information
samuel-br committed Mar 9, 2022
1 parent 8f87942 commit c2ec119
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions env0/resource_cloud_credentials_project_assignment.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package env0

import (
"context"
"log"

"github.com/env0/terraform-provider-env0/client"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
Expand Down Expand Up @@ -60,6 +61,7 @@ func resourceCloudCredentialsProjectAssignmentRead(ctx context.Context, d *schem
}
}
if !found && !d.IsNewResource() {
log.Printf("[WARN] Drift Detected: Terraform will remove %s from state", d.Id())
d.SetId("")
return nil
}
Expand Down
2 changes: 2 additions & 0 deletions env0/resource_team_project_assignment.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package env0
import (
"context"
"fmt"
"log"

. "github.com/env0/terraform-provider-env0/client"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
Expand Down Expand Up @@ -71,6 +72,7 @@ func resourceTeamProjectAssignmentRead(ctx context.Context, d *schema.ResourceDa
}
}
if !found && !d.IsNewResource() {
log.Printf("[WARN] Drift Detected: Terraform will remove %s from state", d.Id())
d.SetId("")
}
return nil
Expand Down
3 changes: 2 additions & 1 deletion env0/resource_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,8 @@ func resourceTemplateRead(ctx context.Context, d *schema.ResourceData, meta inte
return diag.Errorf("could not get template: %v", err)
}

if template.IsDeleted {
if template.IsDeleted && !d.IsNewResource() {
log.Printf("[WARN] Drift Detected: Terraform will remove %s from state", d.Id())
d.SetId("")
return nil
}
Expand Down
4 changes: 4 additions & 0 deletions env0/resource_template_project_assignment.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package env0

import (
"context"
"log"

"github.com/env0/terraform-provider-env0/client"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
Expand Down Expand Up @@ -64,6 +66,7 @@ func resourceTemplateProjectAssignmentRead(ctx context.Context, d *schema.Resour
}

if template.IsDeleted {
log.Printf("[WARN] Drift Detected: Terraform will remove %s from state", d.Id())
d.SetId("")
return nil
}
Expand All @@ -76,6 +79,7 @@ func resourceTemplateProjectAssignmentRead(ctx context.Context, d *schema.Resour
}
}
if !isProjectIdInTemplate {
log.Printf("[WARN] Drift Detected: Terraform will remove %s from state", d.Id())
d.SetId("")
return nil
}
Expand Down

0 comments on commit c2ec119

Please sign in to comment.