Skip to content

Commit becf2ce

Browse files
authored
Merge pull request #1158 from olhado/send_project_name_on_update
Fix a case where a change to a project in terraform can never apply w…
2 parents 746420e + d8987d2 commit becf2ce

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

internal/provider/resource_gitlab_project.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -1230,7 +1230,13 @@ func resourceGitlabProjectRead(ctx context.Context, d *schema.ResourceData, meta
12301230
func resourceGitlabProjectUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
12311231
client := meta.(*gitlab.Client)
12321232

1233-
options := &gitlab.EditProjectOptions{}
1233+
// Always send the name field, to satisfy the requirement of having one
1234+
// of the project attributes listed below in the update call
1235+
// https://gitlab.com/gitlab-org/gitlab-foss/-/blob/master/lib/api/helpers/projects_helpers.rb#L120-188
1236+
options := &gitlab.EditProjectOptions{
1237+
Name: gitlab.String(d.Get("name").(string)),
1238+
}
1239+
12341240
transferOptions := &gitlab.TransferProjectOptions{}
12351241

12361242
if d.HasChange("name") {

internal/provider/resource_gitlab_project_test.go

+43
Original file line numberDiff line numberDiff line change
@@ -1139,6 +1139,49 @@ func TestAccGitlabProject_templateMutualExclusiveNameAndID(t *testing.T) {
11391139
})
11401140
}
11411141

1142+
// Gitlab update project API call requires one from a subset of project fields to be set (See #1157)
1143+
// If only a non-blessed field is changed, this test checks that the provider ensures the code won't return an error.
1144+
func TestAccGitlabProject_UpdateAnalyticsAccessLevel(t *testing.T) {
1145+
rInt := acctest.RandInt()
1146+
1147+
resource.Test(t, resource.TestCase{
1148+
ProviderFactories: providerFactories,
1149+
CheckDestroy: testAccCheckGitlabProjectDestroy,
1150+
Steps: []resource.TestStep{
1151+
// Create minimal test project
1152+
{
1153+
Config: fmt.Sprintf(`
1154+
resource "gitlab_project" "this" {
1155+
name = "foo-%d"
1156+
visibility_level = "public"
1157+
analytics_access_level = "private"
1158+
}`, rInt),
1159+
},
1160+
// Verify Import
1161+
{
1162+
ResourceName: "gitlab_project.this",
1163+
ImportState: true,
1164+
ImportStateVerify: true,
1165+
},
1166+
// Update `analytics_access_level`
1167+
{
1168+
Config: fmt.Sprintf(`
1169+
resource "gitlab_project" "this" {
1170+
name = "foo-%d"
1171+
visibility_level = "public"
1172+
analytics_access_level = "disabled"
1173+
}`, rInt),
1174+
},
1175+
// Verify Import
1176+
{
1177+
ResourceName: "gitlab_project.this",
1178+
ImportState: true,
1179+
ImportStateVerify: true,
1180+
},
1181+
},
1182+
})
1183+
}
1184+
11421185
func TestAccGitlabProject_containerExpirationPolicy(t *testing.T) {
11431186
var received gitlab.Project
11441187
rInt := acctest.RandInt()

0 commit comments

Comments
 (0)