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

Workspace Source Name and URL #527

Merged
merged 14 commits into from
Feb 7, 2023

Conversation

lucymhdavies
Copy link
Contributor

@lucymhdavies lucymhdavies commented Jun 21, 2022

Description

Addresses #392

Testing plan

Example code:

resource "tfe_workspace" "test" {
  name         = "test-source"
  organization = "lmhd"
  source_name  = "TFE Provider"
  source_url   = "https://github.com/hashicorp/terraform-provider-tfe/issues/392"
}

(See #392 for further tests)

External links

  • API documentation
    • As these are listed as beta parameters, I can understand if we wish to hold off on adding support to the provider for now. On the other hand, they are already supported by the Go TFE SDK.

Output from acceptance tests

Please run applicable acceptance tests locally and include the output here. See TESTS.md to learn how to run acceptance tests.

If you are an external contributor, your contribution(s) will first be reviewed before running them against the project's CI pipeline.

$ TESTARGS="-run TestAccTFEWorkspace" make testacc
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test $(go list ./... |grep -v 'vendor') -v -run TestAccTFEWorkspace -timeout 15m
?   	github.com/hashicorp/terraform-provider-tfe	[no test files]
=== RUN   TestAccTFEWorkspaceIDsDataSource_basic
--- PASS: TestAccTFEWorkspaceIDsDataSource_basic (23.16s)
=== RUN   TestAccTFEWorkspaceIDsDataSource_wildcard
--- PASS: TestAccTFEWorkspaceIDsDataSource_wildcard (19.90s)
=== RUN   TestAccTFEWorkspaceIDsDataSource_tags
--- PASS: TestAccTFEWorkspaceIDsDataSource_tags (19.18s)
=== RUN   TestAccTFEWorkspaceIDsDataSource_searchByTagAndName
--- PASS: TestAccTFEWorkspaceIDsDataSource_searchByTagAndName (20.73s)
=== RUN   TestAccTFEWorkspaceIDsDataSource_empty
--- PASS: TestAccTFEWorkspaceIDsDataSource_empty (3.45s)
=== RUN   TestAccTFEWorkspaceIDsDataSource_namesEmpty
--- PASS: TestAccTFEWorkspaceIDsDataSource_namesEmpty (26.51s)
=== RUN   TestAccTFEWorkspaceRunTaskDataSource_basic
    testing.go:65: Skipping tests for Run Tasks. Set 'RUN_TASKS_URL' to enabled this tests.
--- SKIP: TestAccTFEWorkspaceRunTaskDataSource_basic (0.00s)
=== RUN   TestAccTFEWorkspaceDataSource_remoteStateConsumers
--- PASS: TestAccTFEWorkspaceDataSource_remoteStateConsumers (25.28s)
=== RUN   TestAccTFEWorkspaceDataSource_basic
--- PASS: TestAccTFEWorkspaceDataSource_basic (20.84s)
=== RUN   TestAccTFEWorkspaceRunTask_create
    testing.go:65: Skipping tests for Run Tasks. Set 'RUN_TASKS_URL' to enabled this tests.
--- SKIP: TestAccTFEWorkspaceRunTask_create (0.00s)
=== RUN   TestAccTFEWorkspaceRunTask_import
    testing.go:65: Skipping tests for Run Tasks. Set 'RUN_TASKS_URL' to enabled this tests.
--- SKIP: TestAccTFEWorkspaceRunTask_import (0.00s)
=== RUN   TestAccTFEWorkspace_basic
--- PASS: TestAccTFEWorkspace_basic (21.79s)
=== RUN   TestAccTFEWorkspace_panic
--- PASS: TestAccTFEWorkspace_panic (18.79s)
=== RUN   TestAccTFEWorkspace_monorepo
--- PASS: TestAccTFEWorkspace_monorepo (16.36s)
=== RUN   TestAccTFEWorkspace_renamed
--- PASS: TestAccTFEWorkspace_renamed (29.48s)
=== RUN   TestAccTFEWorkspace_update
--- PASS: TestAccTFEWorkspace_update (25.68s)
=== RUN   TestAccTFEWorkspace_updateWorkingDirectory
--- PASS: TestAccTFEWorkspace_updateWorkingDirectory (32.28s)
=== RUN   TestAccTFEWorkspace_updateFileTriggers
--- PASS: TestAccTFEWorkspace_updateFileTriggers (19.76s)
=== RUN   TestAccTFEWorkspace_updateTriggerPrefixes
--- PASS: TestAccTFEWorkspace_updateTriggerPrefixes (26.69s)
=== RUN   TestAccTFEWorkspace_changeTags
--- PASS: TestAccTFEWorkspace_changeTags (73.04s)
=== RUN   TestAccTFEWorkspace_updateSpeculative
--- PASS: TestAccTFEWorkspace_updateSpeculative (19.19s)
=== RUN   TestAccTFEWorkspace_structuredRunOutputDisabled
--- PASS: TestAccTFEWorkspace_structuredRunOutputDisabled (18.97s)
=== RUN   TestAccTFEWorkspace_updateVCSRepo
    resource_tfe_workspace_test.go:556: Please set GITHUB_TOKEN to run this test
--- SKIP: TestAccTFEWorkspace_updateVCSRepo (0.55s)
=== RUN   TestAccTFEWorkspace_sshKey
--- PASS: TestAccTFEWorkspace_sshKey (28.93s)
=== RUN   TestAccTFEWorkspace_import
--- PASS: TestAccTFEWorkspace_import (14.71s)
=== RUN   TestAccTFEWorkspace_importVCSBranch
    resource_tfe_workspace_test.go:706: Please set GITHUB_TOKEN to run this test
--- SKIP: TestAccTFEWorkspace_importVCSBranch (0.47s)
=== RUN   TestAccTFEWorkspace_operationsAndExecutionModeInteroperability
    resource_tfe_workspace_test.go:750: Step 5/5 error: Error running apply: exit status 1

        Error: Error creating agent pool agent-pool-test for organization tst-terraform-3886321602341347244: resource not found

          with tfe_agent_pool.foobar,
          on terraform_plugin_test.tf line 7, in resource "tfe_agent_pool" "foobar":
           7: resource "tfe_agent_pool" "foobar" {

--- FAIL: TestAccTFEWorkspace_operationsAndExecutionModeInteroperability (35.04s)
=== RUN   TestAccTFEWorkspace_globalRemoteState
--- PASS: TestAccTFEWorkspace_globalRemoteState (17.85s)
=== RUN   TestAccTFEWorkspace_alterRemoteStateConsumers
    resource_tfe_workspace_test.go:865: Step 1/5 error: Check failed: Check 2/2 error: tfe_workspace.foobar: Attribute 'global_remote_state' expected "true", got "false"
--- FAIL: TestAccTFEWorkspace_alterRemoteStateConsumers (7.50s)
=== RUN   TestAccTFEWorkspace_createWithRemoteStateConsumers
--- PASS: TestAccTFEWorkspace_createWithRemoteStateConsumers (10.43s)
=== RUN   TestAccTFEWorkspace_paginatedRemoteStateConsumers
--- PASS: TestAccTFEWorkspace_paginatedRemoteStateConsumers (73.65s)
FAIL
FAIL	github.com/hashicorp/terraform-provider-tfe/tfe	652.987s
?   	github.com/hashicorp/terraform-provider-tfe/version	[no test files]
FAIL
make: *** [testacc] Error 1
...

i.e. there was a failure... but not in resources I've modified

Addresses hashicorp#392

The TFE SDK does actually contain `SourceName` and `SourceURL` fields already:
https://github.com/hashicorp/go-tfe/blob/main/workspace.go#L129-L130

This is currently untested
`tfe.WorkspaceUpdateOptions` does not contain these fields, which makes
sense, as those fields can only be set upon workspace creation.

Will need to test to see what happens when a workspace is updated to add
these fields.
Additionally, if SourceURL is set, but SourceName is not, set Name to
URL
@lucymhdavies
Copy link
Contributor Author

Ah, it's failing on:

=== RUN   TestAccTFEWorkspace_operationsAndExecutionModeInteroperability
    resource_tfe_workspace_test.go:750: Step 5/5 error: Error running apply: exit status 1

        Error: Error creating agent pool agent-pool-test for organization tst-terraform-5037466040717225428: resource not found

          with tfe_agent_pool.foobar,
          on terraform_plugin_test.tf line 7, in resource "tfe_agent_pool" "foobar":
           7: resource "tfe_agent_pool" "foobar" {

--- FAIL: TestAccTFEWorkspace_operationsAndExecutionModeInteroperability (39.92s)

because agent pools are a paid feature.

With SKIP_PAID=1...

$ SKIP_PAID=1 TESTARGS="-run TestAccTFEWorkspace" make testacc
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test $(go list ./... |grep -v 'vendor') -v -run TestAccTFEWorkspace -timeout 15m
?   	github.com/hashicorp/terraform-provider-tfe	[no test files]
=== RUN   TestAccTFEWorkspaceIDsDataSource_basic
--- PASS: TestAccTFEWorkspaceIDsDataSource_basic (15.13s)
=== RUN   TestAccTFEWorkspaceIDsDataSource_wildcard
--- PASS: TestAccTFEWorkspaceIDsDataSource_wildcard (14.87s)
=== RUN   TestAccTFEWorkspaceIDsDataSource_tags
--- PASS: TestAccTFEWorkspaceIDsDataSource_tags (13.99s)
=== RUN   TestAccTFEWorkspaceIDsDataSource_searchByTagAndName
--- PASS: TestAccTFEWorkspaceIDsDataSource_searchByTagAndName (19.23s)
=== RUN   TestAccTFEWorkspaceIDsDataSource_empty
--- PASS: TestAccTFEWorkspaceIDsDataSource_empty (2.19s)
=== RUN   TestAccTFEWorkspaceIDsDataSource_namesEmpty
--- PASS: TestAccTFEWorkspaceIDsDataSource_namesEmpty (15.63s)
=== RUN   TestAccTFEWorkspaceRunTaskDataSource_basic
    testing.go:65: Skipping tests for Run Tasks. Set 'RUN_TASKS_URL' to enabled this tests.
--- SKIP: TestAccTFEWorkspaceRunTaskDataSource_basic (0.00s)
=== RUN   TestAccTFEWorkspaceDataSource_remoteStateConsumers
--- PASS: TestAccTFEWorkspaceDataSource_remoteStateConsumers (17.62s)
=== RUN   TestAccTFEWorkspaceDataSource_basic
--- PASS: TestAccTFEWorkspaceDataSource_basic (15.41s)
=== RUN   TestAccTFEWorkspaceRunTask_create
    testing.go:65: Skipping tests for Run Tasks. Set 'RUN_TASKS_URL' to enabled this tests.
--- SKIP: TestAccTFEWorkspaceRunTask_create (0.00s)
=== RUN   TestAccTFEWorkspaceRunTask_import
    testing.go:65: Skipping tests for Run Tasks. Set 'RUN_TASKS_URL' to enabled this tests.
--- SKIP: TestAccTFEWorkspaceRunTask_import (0.00s)
=== RUN   TestAccTFEWorkspace_basic
--- PASS: TestAccTFEWorkspace_basic (13.50s)
=== RUN   TestAccTFEWorkspace_panic
--- PASS: TestAccTFEWorkspace_panic (14.22s)
=== RUN   TestAccTFEWorkspace_monorepo
--- PASS: TestAccTFEWorkspace_monorepo (14.98s)
=== RUN   TestAccTFEWorkspace_renamed
--- PASS: TestAccTFEWorkspace_renamed (17.30s)
=== RUN   TestAccTFEWorkspace_update
--- PASS: TestAccTFEWorkspace_update (26.76s)
=== RUN   TestAccTFEWorkspace_updateWorkingDirectory
--- PASS: TestAccTFEWorkspace_updateWorkingDirectory (30.21s)
=== RUN   TestAccTFEWorkspace_updateFileTriggers
--- PASS: TestAccTFEWorkspace_updateFileTriggers (16.43s)
=== RUN   TestAccTFEWorkspace_updateTriggerPrefixes
--- PASS: TestAccTFEWorkspace_updateTriggerPrefixes (22.41s)
=== RUN   TestAccTFEWorkspace_changeTags
--- PASS: TestAccTFEWorkspace_changeTags (80.46s)
=== RUN   TestAccTFEWorkspace_updateSpeculative
--- PASS: TestAccTFEWorkspace_updateSpeculative (21.07s)
=== RUN   TestAccTFEWorkspace_structuredRunOutputDisabled
--- PASS: TestAccTFEWorkspace_structuredRunOutputDisabled (17.76s)
=== RUN   TestAccTFEWorkspace_updateVCSRepo
    resource_tfe_workspace_test.go:556: Please set GITHUB_TOKEN to run this test
--- SKIP: TestAccTFEWorkspace_updateVCSRepo (0.54s)
=== RUN   TestAccTFEWorkspace_sshKey
--- PASS: TestAccTFEWorkspace_sshKey (37.78s)
=== RUN   TestAccTFEWorkspace_import
--- PASS: TestAccTFEWorkspace_import (15.48s)
=== RUN   TestAccTFEWorkspace_importVCSBranch
    resource_tfe_workspace_test.go:706: Please set GITHUB_TOKEN to run this test
--- SKIP: TestAccTFEWorkspace_importVCSBranch (0.58s)
=== RUN   TestAccTFEWorkspace_operationsAndExecutionModeInteroperability
    testing.go:47: Skipping test that requires a paid feature. Remove 'SKIP_PAID=1' if you want to run this test
--- SKIP: TestAccTFEWorkspace_operationsAndExecutionModeInteroperability (0.00s)
=== RUN   TestAccTFEWorkspace_globalRemoteState
--- PASS: TestAccTFEWorkspace_globalRemoteState (26.38s)
=== RUN   TestAccTFEWorkspace_alterRemoteStateConsumers
    resource_tfe_workspace_test.go:865: Step 1/5 error: Check failed: Check 2/2 error: tfe_workspace.foobar: Attribute 'global_remote_state' expected "true", got "false"
--- FAIL: TestAccTFEWorkspace_alterRemoteStateConsumers (11.77s)
=== RUN   TestAccTFEWorkspace_createWithRemoteStateConsumers
--- PASS: TestAccTFEWorkspace_createWithRemoteStateConsumers (14.98s)
=== RUN   TestAccTFEWorkspace_paginatedRemoteStateConsumers
--- PASS: TestAccTFEWorkspace_paginatedRemoteStateConsumers (87.79s)
FAIL
FAIL	github.com/hashicorp/terraform-provider-tfe/tfe	584.851s
?   	github.com/hashicorp/terraform-provider-tfe/version	[no test files]
FAIL
make: *** [testacc] Error 1

so not sure if that's a flakey test, or something else up

@lucymhdavies
Copy link
Contributor Author

Added some tests specific to this feature:

$ SKIP_PAID=1 TESTARGS="-run TestAccTFEWorkspace_createWithSource" make testacc
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test $(go list ./... |grep -v 'vendor') -v -run TestAccTFEWorkspace_createWithSource -timeout 15m
?   	github.com/hashicorp/terraform-provider-tfe	[no test files]
=== RUN   TestAccTFEWorkspace_createWithSourceURL
    resource_tfe_workspace_test.go:944: Step 1/1 error: After applying this test step, the plan was not empty.
        stdout:


        Terraform used the selected providers to generate the following execution
        plan. Resource actions are indicated with the following symbols:
        -/+ destroy and then create replacement

        Terraform will perform the following actions:

          # tfe_workspace.foobar must be replaced
        -/+ resource "tfe_workspace" "foobar" {
              ~ execution_mode                = "remote" -> (known after apply)
              ~ global_remote_state           = false -> (known after apply)
              ~ id                            = "ws-z194mW93qgPQJdpa" -> (known after apply)
                name                          = "workspace-test"
              ~ operations                    = true -> (known after apply)
              ~ remote_state_consumer_ids     = [] -> (known after apply)
              - source_name                   = "https://example.com" -> null # forces replacement
              ~ terraform_version             = "1.2.4" -> (known after apply)
              ~ trigger_prefixes              = [] -> (known after apply)
                # (10 unchanged attributes hidden)
            }

        Plan: 1 to add, 0 to change, 1 to destroy.
--- FAIL: TestAccTFEWorkspace_createWithSourceURL (19.37s)
=== RUN   TestAccTFEWorkspace_createWithSourceURLAndName
--- PASS: TestAccTFEWorkspace_createWithSourceURLAndName (24.55s)

And it looks like there's actually a problem with my own functionality too, specifically how it handles the case where source_name is not set. Leave that with me, and I'll fix that.

(I might be trying to overcomplicate it actually; perhaps it's better not to try to be clever, and instead require that if either of source_name or source_url is set, then the other should be too 🤔)

@lucymhdavies
Copy link
Contributor Author

$ TESTARGS="-run TestAccTFEWorkspace_createWithSource" make testacc
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test $(go list ./... |grep -v 'vendor') -v -run TestAccTFEWorkspace_createWithSource -timeout 15m
?   	github.com/hashicorp/terraform-provider-tfe	[no test files]
=== RUN   TestAccTFEWorkspace_createWithSourceURL
--- PASS: TestAccTFEWorkspace_createWithSourceURL (1.39s)
=== RUN   TestAccTFEWorkspace_createWithSourceName
--- PASS: TestAccTFEWorkspace_createWithSourceName (1.07s)
=== RUN   TestAccTFEWorkspace_createWithSourceURLAndName
--- PASS: TestAccTFEWorkspace_createWithSourceURLAndName (14.75s)
PASS
ok  	github.com/hashicorp/terraform-provider-tfe/tfe	17.803s
?   	github.com/hashicorp/terraform-provider-tfe/version	[no test files]

Copy link
Contributor

@sudomateo sudomateo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good overall. Might want to have someone that writes providers frequently review it just in case I missed something. I left a few wording suggestions and some general comments. Nice work!

website/docs/d/workspace.html.markdown Outdated Show resolved Hide resolved
website/docs/r/workspace.html.markdown Outdated Show resolved Hide resolved
tfe/resource_tfe_workspace_test.go Outdated Show resolved Hide resolved
tfe/resource_tfe_workspace_test.go Outdated Show resolved Hide resolved
@lucymhdavies
Copy link
Contributor Author

Good catches! This is what happens when I finish off a PR while half-asleep on a train and procrastinating from the work I'm actually supposed to be doing 🤣

I'll get those added.

lucymhdavies and others added 4 commits June 30, 2022 22:07
Co-authored-by: Matthew Sanabria <24284972+sudomateo@users.noreply.github.com>
Co-authored-by: Matthew Sanabria <24284972+sudomateo@users.noreply.github.com>
@lucymhdavies
Copy link
Contributor Author

Changelog updated to fix conflicts

Copy link
Contributor

@annawinkler annawinkler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💖 Thank you for submitting this PR! We'll wait to merge this until the attributes are in GA.

@annawinkler
Copy link
Contributor

Added the label DO NOT MERGE so it's clear to folks that we're not ready to merge this PR. Once the 2 attributes are GA then we can merge this PR.

@lucymhdavies
Copy link
Contributor Author

lucymhdavies commented Jul 7, 2022

That’s fair. I suspected we might want to do that, just in case we change how they work. 🙂

Do we have any timeline on when we expect those to be GA?
(Feel free to slack the answer if that information is not public yet)

@annawinkler
Copy link
Contributor

I'm finding out if we can merge this PR. Stay tuned! 📻

@lucymhdavies
Copy link
Contributor Author

Oh nice! We'd need to resolve the conflict of course, but if this is likely to get merged that'd be awesome :)

@lucymhdavies lucymhdavies requested a review from a team as a code owner February 2, 2023 16:23
@lucymhdavies
Copy link
Contributor Author

lucymhdavies commented Feb 2, 2023

Conflicts should be resolved. I'm gonna do a quick once-over in the diff to make sure it didn't break anything, then it should be all ready to go.

Edit: Some auto-checks failed, due to changes in the code since I originally raised the PR. Getting those resolved, and then I'll let you know when it's ready.

Edit 2: Well... it's still failing, but as far as I can tell that's not due to anything in my change.

It has had a new field added since I initially raised the PR
@annawinkler
Copy link
Contributor

Small update: we're sorting out a build/CI issue.

Copy link
Contributor

@annawinkler annawinkler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@lucymhdavies
Copy link
Contributor Author

#783 for the version of this with working CI

@annawinkler annawinkler merged commit b11f822 into hashicorp:main Feb 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants