Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing ci #1581

Closed
wants to merge 4 commits into from
Closed
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
2 changes: 1 addition & 1 deletion .github/actions/test-provider-tfe/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ runs:
MOD_TFE: github.com/hashicorp/terraform-provider-tfe/internal/provider
MOD_VERSION: github.com/hashicorp/terraform-provider-tfe/version
run: |
gotestsum --junitfile summary.xml --format short-verbose -- $MOD_PROVIDER $MOD_TFE $MOD_VERSION -v -timeout=30m -run "${{ steps.test_split.outputs.run }}"
gotestsum --junitfile summary.xml --format short-verbose -- $MOD_PROVIDER $MOD_TFE $MOD_VERSION -v -timeout=60m -run "${{ steps.test_split.outputs.run }}"

- name: Upload test artifacts
uses: actions/upload-artifact@834a144ee995460fba8ed112a2fc961b36a5ec5a # v4.3.6
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/resource_tfe_workspace_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func (m validateSelfReference) PlanModifySet(_ context.Context, req planmodifier
}

// Check if the workspace ID is in the set
if slices.Contains(remoteStateConsumerIDs, workspaceID.ValueString()) {
if !workspaceID.IsUnknown() && slices.Contains(remoteStateConsumerIDs, workspaceID.ValueString()) {
resp.Diagnostics.AddError("Invalid remote_state_consumer_ids", "workspace_id cannot be in the set of remote_state_consumer_ids")
}
}
Expand Down
50 changes: 49 additions & 1 deletion internal/provider/resource_tfe_workspace_settings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,34 @@ func TestAccTFEWorkspaceSettings(t *testing.T) {
})
}

func TestAccTFEWorkspaceWithSettings(t *testing.T) {
tfeClient, err := getClientUsingEnv()
if err != nil {
t.Fatal(err)
}

org, cleanupOrg := createBusinessOrganization(t, tfeClient)
t.Cleanup(cleanupOrg)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV5ProviderFactories: testAccMuxedProviders,
Steps: []resource.TestStep{
// Start with local execution
{
Config: testAccTFEWorkspaceSettingsUnknownIDRemoteState(org.Name),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(
"tfe_workspace_settings.foobar", "id"),
resource.TestCheckResourceAttrSet(
"tfe_workspace_settings.foobar", "workspace_id",
),
),
},
},
})
}

func TestAccTFEWorkspaceSettingsRemoteState(t *testing.T) {
tfeClient, err := getClientUsingEnv()
if err != nil {
Expand Down Expand Up @@ -222,7 +250,7 @@ func testAccCheckTFEWorkspaceSettingsDestroy(s *terraform.State) error {
return testAccCheckTFEWorkspaceSettingsDestroyProvider(testAccProvider)(s)
}

func testAccCheckTFEWorkspaceSettingsDestroyProvider(p *schema.Provider) func(s *terraform.State) error {
func testAccCheckTFEWorkspaceSettingsDestroyProvider(_ *schema.Provider) func(s *terraform.State) error {
return func(s *terraform.State) error {
tfeClient, err := getClientUsingEnv()
if err != nil {
Expand Down Expand Up @@ -256,6 +284,26 @@ func testAccCheckTFEWorkspaceSettingsDestroyProvider(p *schema.Provider) func(s
}
}

func testAccTFEWorkspaceSettingsUnknownIDRemoteState(orgName string) string {
return fmt.Sprintf(`
resource "tfe_workspace" "foobar1" {
name = "foobar1"
organization = "%s"
}

resource "tfe_workspace" "foobar2" {
name = "foobar2"
organization = "%s"
}

resource "tfe_workspace_settings" "foobar" {
workspace_id = tfe_workspace.foobar1.id
global_remote_state = false
remote_state_consumer_ids = [tfe_workspace.foobar2.id]
}
`, orgName, orgName)
}

func testAccTFEWorkspaceSettingsRemoteState(workspaceID, workspaceID2 string) string {
return fmt.Sprintf(`
resource "tfe_workspace_settings" "foobar" {
Expand Down
10 changes: 6 additions & 4 deletions website/docs/r/workspace_run.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ There are a few main use cases this resource was designed for:

- **Workspaces that depend on other workspaces.** If a workspace will create infrastructure that other workspaces rely on (for example, a Kubernetes cluster to deploy resources into), those downstream workspaces can depend on an initial `apply` with `wait_for_run = true`, so they aren't created before their infrastructure dependencies.
- **A more reliable `queue_all_runs = true`.** The `queue_all_runs` argument on `tfe_workspace` requests an initial run, which can complete asynchronously outside of the Terraform run that creates the workspace. Unfortunately, it can't be used with workspaces that require variables to be set, because the `tfe_variable` resources themselves depend on the `tfe_workspace`. By managing an initial `apply` with `wait_for_run = false` that depends on your `tfe_variables`, you can accomplish the same goal without a circular dependency.
- **Safe workspace destruction.** To ensure a workspace's managed resources are destroyed before deleting it, manage a `destroy` with `wait_for_run = true`. When you destroy the whole configuration, Terraform will wait for the destroy run to complete before deleting the workspace. This pattern is compatible with the `tfe_workspace` resource's default safe deletion behavior.
- **Safe workspace destruction.** To ensure a workspace's managed resources are destroyed before deleting it, add a `destroy` block with `wait_for_run = true`. When you destroy the `tfe_workspace_run` resource, Terraform will wait for the destroy run to complete before deleting the workspace. This pattern is compatible with the `tfe_workspace` resource's default safe deletion behavior.

The `tfe_workspace_run` expects to own exactly one apply during a creation and/or one destroy during a destruction. This implies that even if previous successful applies exist in the workspace, a `tfe_workspace_run` resource that includes an `apply` block will queue a new apply when added to a config.

~> **NOTE:** Use caution when removing the `tfe_workspace_run` resource from your configuration, as destroying it with a `destroy` block present will create a destroy run which will destroy the workspace's underlying managed resources. To avoid this behavior, remove the `destroy` block first.

## Example Usage

Basic usage with multiple workspaces:
Expand Down Expand Up @@ -185,8 +187,8 @@ resource "tfe_workspace_run" "ws_run_parent" {
The following arguments are supported:

* `workspace_id` - (Required) ID of the workspace to execute the run.
* `apply` - (Optional) Settings for the workspace's apply run during creation.
* `destroy` - (Optional) Settings for the workspace's destroy run during destruction.
* `apply` - (Optional) Adding an apply block ensures an apply run is queued when the resource is created. The block controls settings for the workspace's apply run during creation.
* `destroy` - (Optional) Adding a destroy block ensures a destroy run is queued when the resource is destroyed. The block controls settings for the workspace's destroy run during destruction.

Both `apply` and `destroy` block supports:

Expand All @@ -204,4 +206,4 @@ Both `apply` and `destroy` block supports:

In addition to all arguments above, the following attributes are exported:

* `id` - The ID of the run created by this resource. Note, if the resource was created without an `apply{}` configuration block, then this ID will not refer to a real run in HCP Terraform.
* `id` - The ID of the run created by this resource. Note, if the resource was created without an `apply{}` configuration block, then this ID will not refer to a real run in HCP Terraform.
Loading