Skip to content

Commit c379c2d

Browse files
committed
Remove instance variable from state if not found
Signed-off-by: Sune Keller <[email protected]>
1 parent 9128a4e commit c379c2d

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

gitlab/resource_gitlab_instance_variable.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package gitlab
22

33
import (
44
"log"
5+
"net/http"
56

67
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
78
gitlab "github.com/xanzy/go-gitlab"
@@ -84,8 +85,13 @@ func resourceGitlabInstanceVariableRead(d *schema.ResourceData, meta interface{}
8485

8586
log.Printf("[DEBUG] read gitlab instance level CI variable %s", key)
8687

87-
v, _, err := client.InstanceVariables.GetVariable(key)
88+
v, resp, err := client.InstanceVariables.GetVariable(key)
8889
if err != nil {
90+
if resp.StatusCode == http.StatusNotFound {
91+
log.Printf("[DEBUG] gitlab instance level CI variable for %s not found so removing from state", d.Id())
92+
d.SetId("")
93+
return nil
94+
}
8995
return err
9096
}
9197

0 commit comments

Comments
 (0)