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

Clean the state for jira if project doesn't exist #337

Merged
merged 1 commit into from
Sep 10, 2020
Merged
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
11 changes: 11 additions & 0 deletions gitlab/resource_gitlab_service_jira.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package gitlab
import (
"fmt"
"log"
"net/http"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
gitlab "github.com/xanzy/go-gitlab"
Expand Down Expand Up @@ -108,6 +109,16 @@ func resourceGitlabServiceJiraRead(d *schema.ResourceData, meta interface{}) err
client := meta.(*gitlab.Client)
project := d.Get("project").(string)

p, resp, err := client.Projects.GetProject(project, nil)
if err != nil {
if resp != nil && resp.StatusCode == http.StatusNotFound {
log.Printf("[DEBUG] Removing Gitlab Jira service %s because project %s not found", d.Id(), p.Name)
d.SetId("")
return nil
}
return err
}

log.Printf("[DEBUG] Read Gitlab Jira service %s", d.Id())

jiraService, _, err := client.Services.GetJiraService(project)
Expand Down