Skip to content
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## Unreleased

ENHANCEMENTS:
* `r/tfe_registry_module`: Add support for `agent_execution_mode` and `agent_pool_id` attributes in `test_config` block to enable running registry module tests on custom agent pools. By @hashimoon [#1832](https://github.com/hashicorp/terraform-provider-tfe/pull/1832)
* `r/tfe_oauth_client`: The `oauth_token` attribute no longer triggers resource replacement unless combined with other replacement-triggering attributes. Use `terraform apply -replace` to force replacement. By @lilincmu [#1825](https://github.com/hashicorp/terraform-provider-tfe/pull/1825)

## v0.68.3
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ require (
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-hclog v1.6.3 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-retryablehttp v0.7.7 // indirect
github.com/hashicorp/go-retryablehttp v0.7.8 // indirect
github.com/hashicorp/go-slug v0.16.7
github.com/hashicorp/go-tfe v1.90.0
github.com/hashicorp/go-tfe v1.91.2-0.20250906002750-cfc48fdc08e8
github.com/hashicorp/go-version v1.7.0
github.com/hashicorp/hcl v1.0.0
github.com/hashicorp/hcl/v2 v2.23.0 // indirect
Expand All @@ -32,7 +32,7 @@ require (
golang.org/x/oauth2 v0.29.0 // indirect
golang.org/x/sys v0.35.0 // indirect
golang.org/x/text v0.28.0 // indirect
golang.org/x/time v0.11.0 // indirect
golang.org/x/time v0.12.0 // indirect
google.golang.org/protobuf v1.36.6 // indirect
)

Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,14 @@ github.com/hashicorp/go-plugin v1.6.3 h1:xgHB+ZUSYeuJi96WtxEjzi23uh7YQpznjGh0U0U
github.com/hashicorp/go-plugin v1.6.3/go.mod h1:MRobyh+Wc/nYy1V4KAXUiYfzxoYhs7V1mlH1Z7iY2h0=
github.com/hashicorp/go-retryablehttp v0.7.7 h1:C8hUCYzor8PIfXHa4UrZkU4VvK8o9ISHxT2Q8+VepXU=
github.com/hashicorp/go-retryablehttp v0.7.7/go.mod h1:pkQpWZeYWskR+D1tR2O5OcBFOxfA7DoAO6xtkuQnHTk=
github.com/hashicorp/go-retryablehttp v0.7.8 h1:ylXZWnqa7Lhqpk0L1P1LzDtGcCR0rPVUrx/c8Unxc48=
github.com/hashicorp/go-retryablehttp v0.7.8/go.mod h1:rjiScheydd+CxvumBsIrFKlx3iS0jrZ7LvzFGFmuKbw=
github.com/hashicorp/go-slug v0.16.7 h1:sBW8y1sX+JKOZKu9a+DQZuWDVaX+U9KFnk6+VDQvKcw=
github.com/hashicorp/go-slug v0.16.7/go.mod h1:X5fm++dL59cDOX8j48CqHr4KARTQau7isGh0ZVxJB5I=
github.com/hashicorp/go-tfe v1.90.0 h1:NHJB8i19QXJEsEqTlRenZ3mWsS11OivkPgokMpg1fSs=
github.com/hashicorp/go-tfe v1.90.0/go.mod h1:6dUFMBKh0jkxlRsrw7bYD2mby0efdwE4dtlAuTogIzA=
github.com/hashicorp/go-tfe v1.91.2-0.20250906002750-cfc48fdc08e8 h1:j9qc+RVQKhL5NZWCyCi8e+ESyXi1tmJSxUofe4K78xw=
github.com/hashicorp/go-tfe v1.91.2-0.20250906002750-cfc48fdc08e8/go.mod h1:GQL5wq6HOP2kiLrwKAhB+m38IN552Jz6lNhZfGQ64hw=
github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/Co8=
github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
Expand Down Expand Up @@ -231,6 +235,8 @@ golang.org/x/text v0.28.0 h1:rhazDwis8INMIwQ4tpjLDzUhx6RlXqZNPEM0huQojng=
golang.org/x/text v0.28.0/go.mod h1:U8nCwOR8jO/marOQ0QbDiOngZVEBB7MAiitBuMjXiNU=
golang.org/x/time v0.11.0 h1:/bpjEDfN9tkoN/ryeYHnv5hcMlc8ncjMcM4XBk5NWV0=
golang.org/x/time v0.11.0/go.mod h1:CDIdPxbZBQxdj6cxyCIdrNogrJKMJ7pr37NYpMcMDSg=
golang.org/x/time v0.12.0 h1:ScB/8o8olJvc+CQPWrK3fPZNfh7qgwCrY0zJmoEQLSE=
golang.org/x/time v0.12.0/go.mod h1:CDIdPxbZBQxdj6cxyCIdrNogrJKMJ7pr37NYpMcMDSg=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
Expand Down
85 changes: 84 additions & 1 deletion internal/provider/resource_tfe_registry_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ func resourceTFERegistryModule() *schema.Resource {
},

CustomizeDiff: func(c context.Context, d *schema.ResourceDiff, meta interface{}) error {
return validateVcsRepo(d)
if err := validateVcsRepo(d); err != nil {
return err
}
return validateTestConfig(d)
},
Schema: map[string]*schema.Schema{
"organization": {
Expand Down Expand Up @@ -136,6 +139,19 @@ func resourceTFERegistryModule() *schema.Resource {
Type: schema.TypeBool,
Optional: true,
},
"agent_execution_mode": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validation.StringInSlice(
[]string{"agent", "remote"},
false,
),
},
"agent_pool_id": {
Type: schema.TypeString,
Optional: true,
},
},
},
},
Expand Down Expand Up @@ -197,6 +213,16 @@ func resourceTFERegistryModuleCreateWithVCS(v interface{}, meta interface{}, d *
options.TestConfig = &tfe.RegistryModuleTestConfigOptions{
TestsEnabled: tfe.Bool(testsEnabled),
}

if agentExecutionMode, ok := testConfig["agent_execution_mode"].(string); ok && agentExecutionMode != "" {
mode := tfe.AgentExecutionMode(agentExecutionMode)
options.TestConfig.AgentExecutionMode = &mode
}

// Handle agent pool ID - only set if explicitly provided and not empty
if agentPoolID, ok := testConfig["agent_pool_id"].(string); ok && agentPoolID != "" {
options.TestConfig.AgentPoolID = tfe.String(agentPoolID)
}
}

log.Printf("[DEBUG] Create registry module from repository %s", *options.VCSRepo.Identifier)
Expand Down Expand Up @@ -338,6 +364,13 @@ func resourceTFERegistryModuleUpdate(d *schema.ResourceData, meta interface{}) e
if testsEnabled, ok := testConfig["tests_enabled"].(bool); ok {
options.TestConfig.TestsEnabled = tfe.Bool(testsEnabled)
}

if agentExecutionMode, ok := testConfig["agent_execution_mode"].(string); ok && agentExecutionMode != "" {
mode := tfe.AgentExecutionMode(agentExecutionMode)
options.TestConfig.AgentExecutionMode = &mode
}

handleAgentPoolID(testConfig, d, options.TestConfig)
}

err = retry.Retry(time.Duration(5)*time.Minute, func() *retry.RetryError {
Expand Down Expand Up @@ -413,6 +446,13 @@ func resourceTFERegistryModuleRead(d *schema.ResourceData, meta interface{}) err
"tests_enabled": registryModule.TestConfig.TestsEnabled,
}

if registryModule.TestConfig.AgentExecutionMode != nil && *registryModule.TestConfig.AgentExecutionMode != "" {
testConfigValues["agent_execution_mode"] = *registryModule.TestConfig.AgentExecutionMode
}

if registryModule.TestConfig.AgentPoolID != nil && *registryModule.TestConfig.AgentPoolID != "" {
testConfigValues["agent_pool_id"] = *registryModule.TestConfig.AgentPoolID
}
testConfig = append(testConfig, testConfigValues)
}

Expand Down Expand Up @@ -509,3 +549,46 @@ func validateVcsRepo(d *schema.ResourceDiff) error {

return nil
}

func validateTestConfig(d *schema.ResourceDiff) error {
testConfig, ok := d.GetRawConfig().AsValueMap()["test_config"]
if !ok || testConfig.LengthInt() == 0 {
return nil
}

testConfigValue := testConfig.AsValueSlice()[0]
agentExecutionModeValue := testConfigValue.GetAttr("agent_execution_mode")
agentPoolIDValue := testConfigValue.GetAttr("agent_pool_id")

if agentExecutionModeValue.IsNull() && agentPoolIDValue.IsNull() {
return nil
}

// Skip validation if values are unknown (during plan phase)
if !agentExecutionModeValue.IsKnown() || !agentPoolIDValue.IsKnown() {
return nil
}

if !agentExecutionModeValue.IsNull() && !agentPoolIDValue.IsNull() {
executionMode := agentExecutionModeValue.AsString()
agentPoolID := agentPoolIDValue.AsString()

if executionMode == "remote" && agentPoolID != "" {
return fmt.Errorf("agent_pool_id cannot be set when agent_execution_mode is 'remote'")
}
}

return nil
}

func handleAgentPoolID(testConfig map[string]interface{}, d *schema.ResourceData, options *tfe.RegistryModuleTestConfigOptions) {
if agentPoolID, ok := testConfig["agent_pool_id"].(string); ok {
if agentPoolID != "" {
options.AgentPoolID = tfe.String(agentPoolID)
} else if d.HasChange("test_config.0.agent_pool_id") {
options.AgentPoolID = tfe.String("")
}
} else if d.HasChange("test_config.0.agent_pool_id") {
options.AgentPoolID = tfe.String("")
}
}
Loading
Loading