Skip to content

Commit 9aeb9d0

Browse files
authored
Merge pull request #1159 from hashicorp/IPL-4893-unable-to-connect-workspace-to-agent-pool-via-resources-with-tfe-provider-0-48
Introduce tfe_workspace_settings (deprecates execution_mode, agent_pool_id)
2 parents 596951c + 138bfe3 commit 9aeb9d0

14 files changed

+934
-441
lines changed

CHANGELOG.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@
22
<!-- Add CHANGELOG entry to this section for any PR awaiting the next release -->
33
<!-- Please also include if this is a Bug Fix, Enhancement, or Feature -->
44

5-
BREAKING CHANGES:
6-
* `r/tfe_workspace`: Default value of the `execution_mode` field now uses the organization's `default_execution_mode`. If no `default_execution_mode` has been set, the default `execution_mode` will be unchanged (i.e. `remote`).
5+
DEPRECATIONS and BREAKING CHANGES:
6+
* `r/tfe_workspace`: `execution_mode` and `agent_pool_id` attributes have been deprecated in favor of a new resource, `tfe_workspace_settings`. Note that these fields no longer compute defaults which is consistent with using a new resource to manage these same settings. What this means in practice is that if you unset `execution_mode` or `agent_pool_id` without also creating a `tfe_workspace_settings`, the setting will no longer revert to the default "remote" mode. To migrate, relocate the `execution_mode` and `agent_pool_id` arguments to `tfe_workspace_settings`.
77

88
BUG FIXES:
99
* `r/tfe_policy`: Fix the provider ignoring updates to the `query` field, by @skeggse [1108](https://github.com/hashicorp/terraform-provider-tfe/pull/1108)
1010
* Fix the undetected change when modifying the `organization` default in the provider configuration by @brandonc [1152](https://github.com/hashicorp/terraform-provider-tfe/issue/1152)
11+
* New resource `r/tfe_workspace_settings`: Can be used to break any circular dependency between `tfe_workspace` and `tfe_agent_pool_allowed_workspaces` by managing the `agent_pool_id` for a Workspace by @brandonc [1159](https://github.com/hashicorp/terraform-provider-tfe/pull/1159)
1112

1213
FEATURES:
1314
* `d/tfe_registry_module`: Add `vcs_repo.tags` and `vcs_repo.branch` attributes to allow configuration of `publishing_mechanism`. Add `test_config` to support running tests on `branch`-based registry modules, by @hashimoon [1096](https://github.com/hashicorp/terraform-provider-tfe/pull/1096)
14-
* **New Resource**: `r/tfe_organization_default_execution_mode` is a new resource to set the `default_execution_mode` and `default_agent_pool_id` for an organization, by @SwiftEngineer [1137](https://github.com/hashicorp/terraform-provider-tfe/pull/1137)'
15-
* `r/tfe_workspace`: Now uses the organization's `default_execution_mode` and `default_agent_pool_id` as the default `execution_mode`, by @SwiftEngineer [1137](https://github.com/hashicorp/terraform-provider-tfe/pull/1137)'
15+
* **New Resource**: `r/tfe_organization_default_settings` is a new resource to set the `default_execution_mode` and `default_agent_pool_id` for an organization, by @SwiftEngineer [1137](https://github.com/hashicorp/terraform-provider-tfe/pull/1137)'
16+
* **New Resource**: `r/tfe_workspace_settings` Uses the `tfe_organization_default_settings` `default_execution_mode` and `default_agent_pool_id` as the default `execution_mode` by @brandonc and @laurenolivia [1159](https://github.com/hashicorp/terraform-provider-tfe/pull/1159)
1617
* **New Resource**: `r/tfe_registry_gpg_key` is a new resource for managing private registry GPG keys, by @tmatilai [1160](https://github.com/hashicorp/terraform-provider-tfe/pull/1160)
1718
* **New Data Source**: `d/tfe_registry_gpg_key` is a new data source to retrieve a private registry GPG key, by @tmatilai [1160](https://github.com/hashicorp/terraform-provider-tfe/pull/1160)
1819
* **New Data Source**: `d/tfe_registry_gpg_keys` is a new data source to retrieve all private registry GPG keys of an organization, by @tmatilai [1160](https://github.com/hashicorp/terraform-provider-tfe/pull/1160)

internal/provider/provider.go

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -106,45 +106,45 @@ func Provider() *schema.Provider {
106106
},
107107

108108
ResourcesMap: map[string]*schema.Resource{
109-
"tfe_admin_organization_settings": resourceTFEAdminOrganizationSettings(),
110-
"tfe_agent_pool": resourceTFEAgentPool(),
111-
"tfe_agent_pool_allowed_workspaces": resourceTFEAgentPoolAllowedWorkspaces(),
112-
"tfe_agent_token": resourceTFEAgentToken(),
113-
"tfe_notification_configuration": resourceTFENotificationConfiguration(),
114-
"tfe_oauth_client": resourceTFEOAuthClient(),
115-
"tfe_organization": resourceTFEOrganization(),
116-
"tfe_organization_default_execution_mode": resourceTFEOrganizationDefaultExecutionMode(),
117-
"tfe_organization_membership": resourceTFEOrganizationMembership(),
118-
"tfe_organization_module_sharing": resourceTFEOrganizationModuleSharing(),
119-
"tfe_organization_run_task": resourceTFEOrganizationRunTask(),
120-
"tfe_organization_token": resourceTFEOrganizationToken(),
121-
"tfe_policy": resourceTFEPolicy(),
122-
"tfe_policy_set": resourceTFEPolicySet(),
123-
"tfe_policy_set_parameter": resourceTFEPolicySetParameter(),
124-
"tfe_project": resourceTFEProject(),
125-
"tfe_project_policy_set": resourceTFEProjectPolicySet(),
126-
"tfe_project_variable_set": resourceTFEProjectVariableSet(),
127-
"tfe_registry_module": resourceTFERegistryModule(),
128-
"tfe_no_code_module": resourceTFENoCodeModule(),
129-
"tfe_run_trigger": resourceTFERunTrigger(),
130-
"tfe_sentinel_policy": resourceTFESentinelPolicy(),
131-
"tfe_ssh_key": resourceTFESSHKey(),
132-
"tfe_team": resourceTFETeam(),
133-
"tfe_team_access": resourceTFETeamAccess(),
134-
"tfe_team_organization_member": resourceTFETeamOrganizationMember(),
135-
"tfe_team_organization_members": resourceTFETeamOrganizationMembers(),
136-
"tfe_team_project_access": resourceTFETeamProjectAccess(),
137-
"tfe_team_member": resourceTFETeamMember(),
138-
"tfe_team_members": resourceTFETeamMembers(),
139-
"tfe_team_token": resourceTFETeamToken(),
140-
"tfe_terraform_version": resourceTFETerraformVersion(),
141-
"tfe_workspace": resourceTFEWorkspace(),
142-
"tfe_workspace_run_task": resourceTFEWorkspaceRunTask(),
143-
"tfe_variable_set": resourceTFEVariableSet(),
144-
"tfe_workspace_policy_set": resourceTFEWorkspacePolicySet(),
145-
"tfe_workspace_policy_set_exclusion": resourceTFEWorkspacePolicySetExclusion(),
146-
"tfe_workspace_run": resourceTFEWorkspaceRun(),
147-
"tfe_workspace_variable_set": resourceTFEWorkspaceVariableSet(),
109+
"tfe_admin_organization_settings": resourceTFEAdminOrganizationSettings(),
110+
"tfe_agent_pool": resourceTFEAgentPool(),
111+
"tfe_agent_pool_allowed_workspaces": resourceTFEAgentPoolAllowedWorkspaces(),
112+
"tfe_agent_token": resourceTFEAgentToken(),
113+
"tfe_notification_configuration": resourceTFENotificationConfiguration(),
114+
"tfe_oauth_client": resourceTFEOAuthClient(),
115+
"tfe_organization": resourceTFEOrganization(),
116+
"tfe_organization_default_settings": resourceTFEOrganizationDefaultSettings(),
117+
"tfe_organization_membership": resourceTFEOrganizationMembership(),
118+
"tfe_organization_module_sharing": resourceTFEOrganizationModuleSharing(),
119+
"tfe_organization_run_task": resourceTFEOrganizationRunTask(),
120+
"tfe_organization_token": resourceTFEOrganizationToken(),
121+
"tfe_policy": resourceTFEPolicy(),
122+
"tfe_policy_set": resourceTFEPolicySet(),
123+
"tfe_policy_set_parameter": resourceTFEPolicySetParameter(),
124+
"tfe_project": resourceTFEProject(),
125+
"tfe_project_policy_set": resourceTFEProjectPolicySet(),
126+
"tfe_project_variable_set": resourceTFEProjectVariableSet(),
127+
"tfe_registry_module": resourceTFERegistryModule(),
128+
"tfe_no_code_module": resourceTFENoCodeModule(),
129+
"tfe_run_trigger": resourceTFERunTrigger(),
130+
"tfe_sentinel_policy": resourceTFESentinelPolicy(),
131+
"tfe_ssh_key": resourceTFESSHKey(),
132+
"tfe_team": resourceTFETeam(),
133+
"tfe_team_access": resourceTFETeamAccess(),
134+
"tfe_team_organization_member": resourceTFETeamOrganizationMember(),
135+
"tfe_team_organization_members": resourceTFETeamOrganizationMembers(),
136+
"tfe_team_project_access": resourceTFETeamProjectAccess(),
137+
"tfe_team_member": resourceTFETeamMember(),
138+
"tfe_team_members": resourceTFETeamMembers(),
139+
"tfe_team_token": resourceTFETeamToken(),
140+
"tfe_terraform_version": resourceTFETerraformVersion(),
141+
"tfe_workspace": resourceTFEWorkspace(),
142+
"tfe_workspace_run_task": resourceTFEWorkspaceRunTask(),
143+
"tfe_variable_set": resourceTFEVariableSet(),
144+
"tfe_workspace_policy_set": resourceTFEWorkspacePolicySet(),
145+
"tfe_workspace_policy_set_exclusion": resourceTFEWorkspacePolicySetExclusion(),
146+
"tfe_workspace_run": resourceTFEWorkspaceRun(),
147+
"tfe_workspace_variable_set": resourceTFEWorkspaceVariableSet(),
148148
},
149149
ConfigureContextFunc: configure(),
150150
}

internal/provider/provider_next.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ package provider
55

66
import (
77
"context"
8+
"fmt"
89
"os"
10+
"regexp"
911

1012
"github.com/hashicorp/terraform-plugin-framework/datasource"
1113
"github.com/hashicorp/terraform-plugin-framework/provider"
@@ -23,6 +25,14 @@ type frameworkProvider struct{}
2325
// Compile-time interface check
2426
var _ provider.Provider = &frameworkProvider{}
2527

28+
// Can be used to construct ID regexp patterns
29+
var base58Alphabet = "[1-9A-HJ-NP-Za-km-z]"
30+
31+
// IDPattern constructs a regexp pattern for Terraform Cloud with the given prefix
32+
func IDPattern(prefix string) *regexp.Regexp {
33+
return regexp.MustCompile(fmt.Sprintf("^%s-%s{16}$", prefix, base58Alphabet))
34+
}
35+
2636
// FrameworkProviderConfig is a helper type for extracting the provider
2737
// configuration from the provider block.
2838
type FrameworkProviderConfig struct {
@@ -124,5 +134,6 @@ func (p *frameworkProvider) Resources(ctx context.Context) []func() resource.Res
124134
NewRegistryGPGKeyResource,
125135
NewResourceVariable,
126136
NewSAMLSettingsResource,
137+
NewResourceWorkspaceSettings,
127138
}
128139
}

internal/provider/resource_tfe_organization_default_execution_mode.go renamed to internal/provider/resource_tfe_organization_default_settings.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ import (
1111
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
1212
)
1313

14-
func resourceTFEOrganizationDefaultExecutionMode() *schema.Resource {
14+
func resourceTFEOrganizationDefaultSettings() *schema.Resource {
1515
return &schema.Resource{
16-
Create: resourceTFEOrganizationDefaultExecutionModeCreate,
17-
Read: resourceTFEOrganizationDefaultExecutionModeRead,
18-
Delete: resourceTFEOrganizationDefaultExecutionModeDelete,
16+
Create: resourceTFEOrganizationDefaultSettingsCreate,
17+
Read: resourceTFEOrganizationDefaultSettingsRead,
18+
Delete: resourceTFEOrganizationDefaultSettingsDelete,
1919
Importer: &schema.ResourceImporter{
20-
StateContext: resourceTFEOrganizationDefaultExecutionModeImporter,
20+
StateContext: resourceTFEOrganizationDefaultSettingsImporter,
2121
},
2222

2323
CustomizeDiff: customizeDiffIfProviderDefaultOrganizationChanged,
@@ -53,7 +53,7 @@ func resourceTFEOrganizationDefaultExecutionMode() *schema.Resource {
5353
}
5454
}
5555

56-
func resourceTFEOrganizationDefaultExecutionModeCreate(d *schema.ResourceData, meta interface{}) error {
56+
func resourceTFEOrganizationDefaultSettingsCreate(d *schema.ResourceData, meta interface{}) error {
5757
config := meta.(ConfiguredClient)
5858

5959
// Get the organization name.
@@ -88,10 +88,10 @@ func resourceTFEOrganizationDefaultExecutionModeCreate(d *schema.ResourceData, m
8888

8989
d.SetId(organization)
9090

91-
return resourceTFEOrganizationDefaultExecutionModeRead(d, meta)
91+
return resourceTFEOrganizationDefaultSettingsRead(d, meta)
9292
}
9393

94-
func resourceTFEOrganizationDefaultExecutionModeRead(d *schema.ResourceData, meta interface{}) error {
94+
func resourceTFEOrganizationDefaultSettingsRead(d *schema.ResourceData, meta interface{}) error {
9595
config := meta.(ConfiguredClient)
9696

9797
log.Printf("[DEBUG] Read the organization: %s", d.Id())
@@ -119,7 +119,7 @@ func resourceTFEOrganizationDefaultExecutionModeRead(d *schema.ResourceData, met
119119
return nil
120120
}
121121

122-
func resourceTFEOrganizationDefaultExecutionModeDelete(d *schema.ResourceData, meta interface{}) error {
122+
func resourceTFEOrganizationDefaultSettingsDelete(d *schema.ResourceData, meta interface{}) error {
123123
config := meta.(ConfiguredClient)
124124

125125
// Get the organization name.
@@ -141,7 +141,7 @@ func resourceTFEOrganizationDefaultExecutionModeDelete(d *schema.ResourceData, m
141141
return nil
142142
}
143143

144-
func resourceTFEOrganizationDefaultExecutionModeImporter(ctx context.Context, d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
144+
func resourceTFEOrganizationDefaultSettingsImporter(ctx context.Context, d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
145145
config := meta.(ConfiguredClient)
146146

147147
log.Printf("[DEBUG] Read the organization: %s", d.Id())

0 commit comments

Comments
 (0)