Skip to content

Commit

Permalink
Merge pull request #1159 from hashicorp/IPL-4893-unable-to-connect-wo…
Browse files Browse the repository at this point in the history
…rkspace-to-agent-pool-via-resources-with-tfe-provider-0-48

Introduce tfe_workspace_settings (deprecates execution_mode, agent_pool_id)
  • Loading branch information
brandonc committed Dec 12, 2023
2 parents 596951c + 138bfe3 commit 9aeb9d0
Show file tree
Hide file tree
Showing 14 changed files with 934 additions and 441 deletions.
9 changes: 5 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@
<!-- Add CHANGELOG entry to this section for any PR awaiting the next release -->
<!-- Please also include if this is a Bug Fix, Enhancement, or Feature -->

BREAKING CHANGES:
* `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`).
DEPRECATIONS and BREAKING CHANGES:
* `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`.

BUG FIXES:
* `r/tfe_policy`: Fix the provider ignoring updates to the `query` field, by @skeggse [1108](https://github.com/hashicorp/terraform-provider-tfe/pull/1108)
* 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)
* 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)

FEATURES:
* `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)
* **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)'
* `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)'
* **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)'
* **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)
* **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)
* **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)
* **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)
Expand Down
78 changes: 39 additions & 39 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,45 +106,45 @@ func Provider() *schema.Provider {
},

ResourcesMap: map[string]*schema.Resource{
"tfe_admin_organization_settings": resourceTFEAdminOrganizationSettings(),
"tfe_agent_pool": resourceTFEAgentPool(),
"tfe_agent_pool_allowed_workspaces": resourceTFEAgentPoolAllowedWorkspaces(),
"tfe_agent_token": resourceTFEAgentToken(),
"tfe_notification_configuration": resourceTFENotificationConfiguration(),
"tfe_oauth_client": resourceTFEOAuthClient(),
"tfe_organization": resourceTFEOrganization(),
"tfe_organization_default_execution_mode": resourceTFEOrganizationDefaultExecutionMode(),
"tfe_organization_membership": resourceTFEOrganizationMembership(),
"tfe_organization_module_sharing": resourceTFEOrganizationModuleSharing(),
"tfe_organization_run_task": resourceTFEOrganizationRunTask(),
"tfe_organization_token": resourceTFEOrganizationToken(),
"tfe_policy": resourceTFEPolicy(),
"tfe_policy_set": resourceTFEPolicySet(),
"tfe_policy_set_parameter": resourceTFEPolicySetParameter(),
"tfe_project": resourceTFEProject(),
"tfe_project_policy_set": resourceTFEProjectPolicySet(),
"tfe_project_variable_set": resourceTFEProjectVariableSet(),
"tfe_registry_module": resourceTFERegistryModule(),
"tfe_no_code_module": resourceTFENoCodeModule(),
"tfe_run_trigger": resourceTFERunTrigger(),
"tfe_sentinel_policy": resourceTFESentinelPolicy(),
"tfe_ssh_key": resourceTFESSHKey(),
"tfe_team": resourceTFETeam(),
"tfe_team_access": resourceTFETeamAccess(),
"tfe_team_organization_member": resourceTFETeamOrganizationMember(),
"tfe_team_organization_members": resourceTFETeamOrganizationMembers(),
"tfe_team_project_access": resourceTFETeamProjectAccess(),
"tfe_team_member": resourceTFETeamMember(),
"tfe_team_members": resourceTFETeamMembers(),
"tfe_team_token": resourceTFETeamToken(),
"tfe_terraform_version": resourceTFETerraformVersion(),
"tfe_workspace": resourceTFEWorkspace(),
"tfe_workspace_run_task": resourceTFEWorkspaceRunTask(),
"tfe_variable_set": resourceTFEVariableSet(),
"tfe_workspace_policy_set": resourceTFEWorkspacePolicySet(),
"tfe_workspace_policy_set_exclusion": resourceTFEWorkspacePolicySetExclusion(),
"tfe_workspace_run": resourceTFEWorkspaceRun(),
"tfe_workspace_variable_set": resourceTFEWorkspaceVariableSet(),
"tfe_admin_organization_settings": resourceTFEAdminOrganizationSettings(),
"tfe_agent_pool": resourceTFEAgentPool(),
"tfe_agent_pool_allowed_workspaces": resourceTFEAgentPoolAllowedWorkspaces(),
"tfe_agent_token": resourceTFEAgentToken(),
"tfe_notification_configuration": resourceTFENotificationConfiguration(),
"tfe_oauth_client": resourceTFEOAuthClient(),
"tfe_organization": resourceTFEOrganization(),
"tfe_organization_default_settings": resourceTFEOrganizationDefaultSettings(),
"tfe_organization_membership": resourceTFEOrganizationMembership(),
"tfe_organization_module_sharing": resourceTFEOrganizationModuleSharing(),
"tfe_organization_run_task": resourceTFEOrganizationRunTask(),
"tfe_organization_token": resourceTFEOrganizationToken(),
"tfe_policy": resourceTFEPolicy(),
"tfe_policy_set": resourceTFEPolicySet(),
"tfe_policy_set_parameter": resourceTFEPolicySetParameter(),
"tfe_project": resourceTFEProject(),
"tfe_project_policy_set": resourceTFEProjectPolicySet(),
"tfe_project_variable_set": resourceTFEProjectVariableSet(),
"tfe_registry_module": resourceTFERegistryModule(),
"tfe_no_code_module": resourceTFENoCodeModule(),
"tfe_run_trigger": resourceTFERunTrigger(),
"tfe_sentinel_policy": resourceTFESentinelPolicy(),
"tfe_ssh_key": resourceTFESSHKey(),
"tfe_team": resourceTFETeam(),
"tfe_team_access": resourceTFETeamAccess(),
"tfe_team_organization_member": resourceTFETeamOrganizationMember(),
"tfe_team_organization_members": resourceTFETeamOrganizationMembers(),
"tfe_team_project_access": resourceTFETeamProjectAccess(),
"tfe_team_member": resourceTFETeamMember(),
"tfe_team_members": resourceTFETeamMembers(),
"tfe_team_token": resourceTFETeamToken(),
"tfe_terraform_version": resourceTFETerraformVersion(),
"tfe_workspace": resourceTFEWorkspace(),
"tfe_workspace_run_task": resourceTFEWorkspaceRunTask(),
"tfe_variable_set": resourceTFEVariableSet(),
"tfe_workspace_policy_set": resourceTFEWorkspacePolicySet(),
"tfe_workspace_policy_set_exclusion": resourceTFEWorkspacePolicySetExclusion(),
"tfe_workspace_run": resourceTFEWorkspaceRun(),
"tfe_workspace_variable_set": resourceTFEWorkspaceVariableSet(),
},
ConfigureContextFunc: configure(),
}
Expand Down
11 changes: 11 additions & 0 deletions internal/provider/provider_next.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ package provider

import (
"context"
"fmt"
"os"
"regexp"

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

// Can be used to construct ID regexp patterns
var base58Alphabet = "[1-9A-HJ-NP-Za-km-z]"

// IDPattern constructs a regexp pattern for Terraform Cloud with the given prefix
func IDPattern(prefix string) *regexp.Regexp {
return regexp.MustCompile(fmt.Sprintf("^%s-%s{16}$", prefix, base58Alphabet))
}

// FrameworkProviderConfig is a helper type for extracting the provider
// configuration from the provider block.
type FrameworkProviderConfig struct {
Expand Down Expand Up @@ -124,5 +134,6 @@ func (p *frameworkProvider) Resources(ctx context.Context) []func() resource.Res
NewRegistryGPGKeyResource,
NewResourceVariable,
NewSAMLSettingsResource,
NewResourceWorkspaceSettings,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
)

func resourceTFEOrganizationDefaultExecutionMode() *schema.Resource {
func resourceTFEOrganizationDefaultSettings() *schema.Resource {
return &schema.Resource{
Create: resourceTFEOrganizationDefaultExecutionModeCreate,
Read: resourceTFEOrganizationDefaultExecutionModeRead,
Delete: resourceTFEOrganizationDefaultExecutionModeDelete,
Create: resourceTFEOrganizationDefaultSettingsCreate,
Read: resourceTFEOrganizationDefaultSettingsRead,
Delete: resourceTFEOrganizationDefaultSettingsDelete,
Importer: &schema.ResourceImporter{
StateContext: resourceTFEOrganizationDefaultExecutionModeImporter,
StateContext: resourceTFEOrganizationDefaultSettingsImporter,
},

CustomizeDiff: customizeDiffIfProviderDefaultOrganizationChanged,
Expand Down Expand Up @@ -53,7 +53,7 @@ func resourceTFEOrganizationDefaultExecutionMode() *schema.Resource {
}
}

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

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

d.SetId(organization)

return resourceTFEOrganizationDefaultExecutionModeRead(d, meta)
return resourceTFEOrganizationDefaultSettingsRead(d, meta)
}

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

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

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

// Get the organization name.
Expand All @@ -141,7 +141,7 @@ func resourceTFEOrganizationDefaultExecutionModeDelete(d *schema.ResourceData, m
return nil
}

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

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

0 comments on commit 9aeb9d0

Please sign in to comment.