Skip to content

Commit 9538d7a

Browse files
committed
[TF-27883] Add agent execution mode and pool to test config
Introduces 'agent_execution_mode' and 'agent_pool_id' fields to the registry module test_config schema, supporting both agent and remote execution modes. Adds validation to prevent agent_pool_id from being set when execution mode is 'remote', updates create, update, and read logic, and provides comprehensive acceptance tests for new behaviors. Also updates dependencies to latest versions.
1 parent adc5c69 commit 9538d7a

File tree

4 files changed

+379
-4
lines changed

4 files changed

+379
-4
lines changed

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ require (
1212
github.com/hashicorp/errwrap v1.1.0 // indirect
1313
github.com/hashicorp/go-hclog v1.6.3 // indirect
1414
github.com/hashicorp/go-multierror v1.1.1 // indirect
15-
github.com/hashicorp/go-retryablehttp v0.7.7 // indirect
15+
github.com/hashicorp/go-retryablehttp v0.7.8 // indirect
1616
github.com/hashicorp/go-slug v0.16.7
17-
github.com/hashicorp/go-tfe v1.90.0
17+
github.com/hashicorp/go-tfe v1.91.2-0.20250906002750-cfc48fdc08e8
1818
github.com/hashicorp/go-version v1.7.0
1919
github.com/hashicorp/hcl v1.0.0
2020
github.com/hashicorp/hcl/v2 v2.23.0 // indirect
@@ -32,7 +32,7 @@ require (
3232
golang.org/x/oauth2 v0.29.0 // indirect
3333
golang.org/x/sys v0.35.0 // indirect
3434
golang.org/x/text v0.28.0 // indirect
35-
golang.org/x/time v0.11.0 // indirect
35+
golang.org/x/time v0.12.0 // indirect
3636
google.golang.org/protobuf v1.36.6 // indirect
3737
)
3838

go.sum

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,14 @@ github.com/hashicorp/go-plugin v1.6.3 h1:xgHB+ZUSYeuJi96WtxEjzi23uh7YQpznjGh0U0U
7070
github.com/hashicorp/go-plugin v1.6.3/go.mod h1:MRobyh+Wc/nYy1V4KAXUiYfzxoYhs7V1mlH1Z7iY2h0=
7171
github.com/hashicorp/go-retryablehttp v0.7.7 h1:C8hUCYzor8PIfXHa4UrZkU4VvK8o9ISHxT2Q8+VepXU=
7272
github.com/hashicorp/go-retryablehttp v0.7.7/go.mod h1:pkQpWZeYWskR+D1tR2O5OcBFOxfA7DoAO6xtkuQnHTk=
73+
github.com/hashicorp/go-retryablehttp v0.7.8 h1:ylXZWnqa7Lhqpk0L1P1LzDtGcCR0rPVUrx/c8Unxc48=
74+
github.com/hashicorp/go-retryablehttp v0.7.8/go.mod h1:rjiScheydd+CxvumBsIrFKlx3iS0jrZ7LvzFGFmuKbw=
7375
github.com/hashicorp/go-slug v0.16.7 h1:sBW8y1sX+JKOZKu9a+DQZuWDVaX+U9KFnk6+VDQvKcw=
7476
github.com/hashicorp/go-slug v0.16.7/go.mod h1:X5fm++dL59cDOX8j48CqHr4KARTQau7isGh0ZVxJB5I=
7577
github.com/hashicorp/go-tfe v1.90.0 h1:NHJB8i19QXJEsEqTlRenZ3mWsS11OivkPgokMpg1fSs=
7678
github.com/hashicorp/go-tfe v1.90.0/go.mod h1:6dUFMBKh0jkxlRsrw7bYD2mby0efdwE4dtlAuTogIzA=
79+
github.com/hashicorp/go-tfe v1.91.2-0.20250906002750-cfc48fdc08e8 h1:j9qc+RVQKhL5NZWCyCi8e+ESyXi1tmJSxUofe4K78xw=
80+
github.com/hashicorp/go-tfe v1.91.2-0.20250906002750-cfc48fdc08e8/go.mod h1:GQL5wq6HOP2kiLrwKAhB+m38IN552Jz6lNhZfGQ64hw=
7781
github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
7882
github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/Co8=
7983
github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
@@ -231,6 +235,8 @@ golang.org/x/text v0.28.0 h1:rhazDwis8INMIwQ4tpjLDzUhx6RlXqZNPEM0huQojng=
231235
golang.org/x/text v0.28.0/go.mod h1:U8nCwOR8jO/marOQ0QbDiOngZVEBB7MAiitBuMjXiNU=
232236
golang.org/x/time v0.11.0 h1:/bpjEDfN9tkoN/ryeYHnv5hcMlc8ncjMcM4XBk5NWV0=
233237
golang.org/x/time v0.11.0/go.mod h1:CDIdPxbZBQxdj6cxyCIdrNogrJKMJ7pr37NYpMcMDSg=
238+
golang.org/x/time v0.12.0 h1:ScB/8o8olJvc+CQPWrK3fPZNfh7qgwCrY0zJmoEQLSE=
239+
golang.org/x/time v0.12.0/go.mod h1:CDIdPxbZBQxdj6cxyCIdrNogrJKMJ7pr37NYpMcMDSg=
234240
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
235241
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
236242
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=

internal/provider/resource_tfe_registry_module.go

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ func resourceTFERegistryModule() *schema.Resource {
3333
},
3434

3535
CustomizeDiff: func(c context.Context, d *schema.ResourceDiff, meta interface{}) error {
36-
return validateVcsRepo(d)
36+
if err := validateVcsRepo(d); err != nil {
37+
return err
38+
}
39+
return validateTestConfig(d)
3740
},
3841
Schema: map[string]*schema.Schema{
3942
"organization": {
@@ -136,6 +139,19 @@ func resourceTFERegistryModule() *schema.Resource {
136139
Type: schema.TypeBool,
137140
Optional: true,
138141
},
142+
"agent_execution_mode": {
143+
Type: schema.TypeString,
144+
Optional: true,
145+
Computed: true,
146+
ValidateFunc: validation.StringInSlice(
147+
[]string{"agent", "remote"},
148+
false,
149+
),
150+
},
151+
"agent_pool_id": {
152+
Type: schema.TypeString,
153+
Optional: true,
154+
},
139155
},
140156
},
141157
},
@@ -197,6 +213,16 @@ func resourceTFERegistryModuleCreateWithVCS(v interface{}, meta interface{}, d *
197213
options.TestConfig = &tfe.RegistryModuleTestConfigOptions{
198214
TestsEnabled: tfe.Bool(testsEnabled),
199215
}
216+
217+
if agentExecutionMode, ok := testConfig["agent_execution_mode"].(string); ok && agentExecutionMode != "" {
218+
mode := tfe.AgentExecutionMode(agentExecutionMode)
219+
options.TestConfig.AgentExecutionMode = &mode
220+
}
221+
222+
// Handle agent pool ID - only set if explicitly provided and not empty
223+
if agentPoolID, ok := testConfig["agent_pool_id"].(string); ok && agentPoolID != "" {
224+
options.TestConfig.AgentPoolID = tfe.String(agentPoolID)
225+
}
200226
}
201227

202228
log.Printf("[DEBUG] Create registry module from repository %s", *options.VCSRepo.Identifier)
@@ -338,6 +364,21 @@ func resourceTFERegistryModuleUpdate(d *schema.ResourceData, meta interface{}) e
338364
if testsEnabled, ok := testConfig["tests_enabled"].(bool); ok {
339365
options.TestConfig.TestsEnabled = tfe.Bool(testsEnabled)
340366
}
367+
368+
if agentExecutionMode, ok := testConfig["agent_execution_mode"].(string); ok && agentExecutionMode != "" {
369+
mode := tfe.AgentExecutionMode(agentExecutionMode)
370+
options.TestConfig.AgentExecutionMode = &mode
371+
}
372+
373+
if agentPoolID, ok := testConfig["agent_pool_id"].(string); ok {
374+
if agentPoolID != "" {
375+
options.TestConfig.AgentPoolID = tfe.String(agentPoolID)
376+
} else if d.HasChange("test_config.0.agent_pool_id") {
377+
options.TestConfig.AgentPoolID = tfe.String("")
378+
}
379+
} else if d.HasChange("test_config.0.agent_pool_id") {
380+
options.TestConfig.AgentPoolID = tfe.String("")
381+
}
341382
}
342383

343384
err = retry.Retry(time.Duration(5)*time.Minute, func() *retry.RetryError {
@@ -413,6 +454,13 @@ func resourceTFERegistryModuleRead(d *schema.ResourceData, meta interface{}) err
413454
"tests_enabled": registryModule.TestConfig.TestsEnabled,
414455
}
415456

457+
if registryModule.TestConfig.AgentExecutionMode != nil && *registryModule.TestConfig.AgentExecutionMode != "" {
458+
testConfigValues["agent_execution_mode"] = string(*registryModule.TestConfig.AgentExecutionMode)
459+
}
460+
461+
if registryModule.TestConfig.AgentPoolID != nil && *registryModule.TestConfig.AgentPoolID != "" {
462+
testConfigValues["agent_pool_id"] = *registryModule.TestConfig.AgentPoolID
463+
}
416464
testConfig = append(testConfig, testConfigValues)
417465
}
418466

@@ -509,3 +557,29 @@ func validateVcsRepo(d *schema.ResourceDiff) error {
509557

510558
return nil
511559
}
560+
561+
func validateTestConfig(d *schema.ResourceDiff) error {
562+
testConfig, ok := d.GetRawConfig().AsValueMap()["test_config"]
563+
if !ok || testConfig.LengthInt() == 0 {
564+
return nil
565+
}
566+
567+
testConfigValue := testConfig.AsValueSlice()[0]
568+
agentExecutionModeValue := testConfigValue.GetAttr("agent_execution_mode")
569+
agentPoolIDValue := testConfigValue.GetAttr("agent_pool_id")
570+
571+
if agentExecutionModeValue.IsNull() && agentPoolIDValue.IsNull() {
572+
return nil
573+
}
574+
575+
if !agentExecutionModeValue.IsNull() && !agentPoolIDValue.IsNull() {
576+
executionMode := agentExecutionModeValue.AsString()
577+
agentPoolID := agentPoolIDValue.AsString()
578+
579+
if executionMode == "remote" && agentPoolID != "" {
580+
return fmt.Errorf("agent_pool_id cannot be set when agent_execution_mode is 'remote'")
581+
}
582+
}
583+
584+
return nil
585+
}

0 commit comments

Comments
 (0)