Skip to content

Commit 9990b80

Browse files
authored
Merge pull request #1569 from hashicorp/TF-23444-terraform-provider-tfe-gh-issue-1568-tfe-workspace-settings-remote-state-consumer-ids-fails-for-not-yet-created-workspaces
Don't ensure workspace ID is in collection when it is unknown
2 parents 96ffe18 + 0869231 commit 9990b80

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
lines changed

internal/provider/resource_tfe_workspace_settings.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ func (m validateSelfReference) PlanModifySet(_ context.Context, req planmodifier
179179
}
180180

181181
// Check if the workspace ID is in the set
182-
if slices.Contains(remoteStateConsumerIDs, workspaceID.ValueString()) {
182+
if !workspaceID.IsUnknown() && slices.Contains(remoteStateConsumerIDs, workspaceID.ValueString()) {
183183
resp.Diagnostics.AddError("Invalid remote_state_consumer_ids", "workspace_id cannot be in the set of remote_state_consumer_ids")
184184
}
185185
}

internal/provider/resource_tfe_workspace_settings_test.go

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,34 @@ func TestAccTFEWorkspaceSettings(t *testing.T) {
9595
})
9696
}
9797

98+
func TestAccTFEWorkspaceWithSettings(t *testing.T) {
99+
tfeClient, err := getClientUsingEnv()
100+
if err != nil {
101+
t.Fatal(err)
102+
}
103+
104+
org, cleanupOrg := createBusinessOrganization(t, tfeClient)
105+
t.Cleanup(cleanupOrg)
106+
107+
resource.Test(t, resource.TestCase{
108+
PreCheck: func() { testAccPreCheck(t) },
109+
ProtoV5ProviderFactories: testAccMuxedProviders,
110+
Steps: []resource.TestStep{
111+
// Start with local execution
112+
{
113+
Config: testAccTFEWorkspaceSettingsUnknownIDRemoteState(org.Name),
114+
Check: resource.ComposeTestCheckFunc(
115+
resource.TestCheckResourceAttrSet(
116+
"tfe_workspace_settings.foobar", "id"),
117+
resource.TestCheckResourceAttrSet(
118+
"tfe_workspace_settings.foobar", "workspace_id",
119+
),
120+
),
121+
},
122+
},
123+
})
124+
}
125+
98126
func TestAccTFEWorkspaceSettingsRemoteState(t *testing.T) {
99127
tfeClient, err := getClientUsingEnv()
100128
if err != nil {
@@ -222,7 +250,7 @@ func testAccCheckTFEWorkspaceSettingsDestroy(s *terraform.State) error {
222250
return testAccCheckTFEWorkspaceSettingsDestroyProvider(testAccProvider)(s)
223251
}
224252

225-
func testAccCheckTFEWorkspaceSettingsDestroyProvider(p *schema.Provider) func(s *terraform.State) error {
253+
func testAccCheckTFEWorkspaceSettingsDestroyProvider(_ *schema.Provider) func(s *terraform.State) error {
226254
return func(s *terraform.State) error {
227255
tfeClient, err := getClientUsingEnv()
228256
if err != nil {
@@ -256,6 +284,26 @@ func testAccCheckTFEWorkspaceSettingsDestroyProvider(p *schema.Provider) func(s
256284
}
257285
}
258286

287+
func testAccTFEWorkspaceSettingsUnknownIDRemoteState(orgName string) string {
288+
return fmt.Sprintf(`
289+
resource "tfe_workspace" "foobar1" {
290+
name = "foobar1"
291+
organization = "%s"
292+
}
293+
294+
resource "tfe_workspace" "foobar2" {
295+
name = "foobar2"
296+
organization = "%s"
297+
}
298+
299+
resource "tfe_workspace_settings" "foobar" {
300+
workspace_id = tfe_workspace.foobar1.id
301+
global_remote_state = false
302+
remote_state_consumer_ids = [tfe_workspace.foobar2.id]
303+
}
304+
`, orgName, orgName)
305+
}
306+
259307
func testAccTFEWorkspaceSettingsRemoteState(workspaceID, workspaceID2 string) string {
260308
return fmt.Sprintf(`
261309
resource "tfe_workspace_settings" "foobar" {

0 commit comments

Comments
 (0)