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

Add projects support #704

Merged
merged 8 commits into from Dec 6, 2022
Merged

Add projects support #704

merged 8 commits into from Dec 6, 2022

Conversation

mwudka
Copy link
Contributor

@mwudka mwudka commented Nov 24, 2022

Description

IMPORTANT: Before merging, upgrade to a go-tfe release that includes hashicorp/go-tfe#564.

Add support for projects (currently in beta). Introduces a new tfe_project resource, which allows creating projects. Also introduces a new project_id attribute on workspaces, to allow creating workspaces within specific projects.

Testing plan

  1. Ensure all tests pass
  2. Manual testing with configs that create and move projects. Acceptance tests have examples, but generally the configs look something like:
resource "tfe_organization" "org" {
  name  = "projects-testing2"
  email = "admin@company.com"
}

resource "tfe_project" "proj" {
  organization = tfe_organization.org.id
  name = "myprojectio"
}

resource "tfe_workspace" "workspace" {
  organization = tfe_organization.org.id
  name = "creatify2"
  # project_id = tfe_project.proj.id
}

output "project_id" {
  value = tfe_project.proj.id  
}

output "workspace_project" {
  value = tfe_workspace.workspace.project_id
}

Docs preview

image

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
TF_ACC=1 TF_LOG_SDK_PROTO=OFF 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 (8.26s)
=== RUN   TestAccTFEWorkspaceIDsDataSource_wildcard
--- PASS: TestAccTFEWorkspaceIDsDataSource_wildcard (8.17s)
=== RUN   TestAccTFEWorkspaceIDsDataSource_tags
--- PASS: TestAccTFEWorkspaceIDsDataSource_tags (8.64s)
=== RUN   TestAccTFEWorkspaceIDsDataSource_searchByTagAndName
--- PASS: TestAccTFEWorkspaceIDsDataSource_searchByTagAndName (8.50s)
=== RUN   TestAccTFEWorkspaceIDsDataSource_empty
--- PASS: TestAccTFEWorkspaceIDsDataSource_empty (2.70s)
=== RUN   TestAccTFEWorkspaceIDsDataSource_namesEmpty
--- PASS: TestAccTFEWorkspaceIDsDataSource_namesEmpty (8.46s)
=== RUN   TestAccTFEWorkspaceIDsDataSource_excludeTags
--- PASS: TestAccTFEWorkspaceIDsDataSource_excludeTags (7.75s)
=== RUN   TestAccTFEWorkspaceIDsDataSource_sameTagInTagNamesAndExcludeTags
--- PASS: TestAccTFEWorkspaceIDsDataSource_sameTagInTagNamesAndExcludeTags (8.75s)
=== RUN   TestAccTFEWorkspaceRunTaskDataSource_basic
    testing.go:175: Skipping tests for Run Tasks. Set 'RUN_TASKS_URL' to enabled this tests.
--- SKIP: TestAccTFEWorkspaceRunTaskDataSource_basic (0.00s)
=== RUN   TestAccTFEWorkspaceDataSource_remoteStateConsumers
--- PASS: TestAccTFEWorkspaceDataSource_remoteStateConsumers (9.27s)
=== RUN   TestAccTFEWorkspaceDataSource_basic
--- PASS: TestAccTFEWorkspaceDataSource_basic (7.97s)
=== RUN   TestAccTFEWorkspaceDataSourceWithTriggerPatterns
--- PASS: TestAccTFEWorkspaceDataSourceWithTriggerPatterns (7.05s)
=== RUN   TestAccTFEWorkspaceDataSource_readProjectIDDefault
--- PASS: TestAccTFEWorkspaceDataSource_readProjectIDDefault (7.64s)
=== RUN   TestAccTFEWorkspaceDataSource_readProjectIDNonDefault
--- PASS: TestAccTFEWorkspaceDataSource_readProjectIDNonDefault (7.55s)
=== RUN   TestAccTFEWorkspacePolicySet_basic
--- PASS: TestAccTFEWorkspacePolicySet_basic (8.19s)
=== RUN   TestAccTFEWorkspacePolicySet_incorrectImportSyntax
--- PASS: TestAccTFEWorkspacePolicySet_incorrectImportSyntax (7.55s)
=== RUN   TestAccTFEWorkspaceRunTask_create
    testing.go:175: Skipping tests for Run Tasks. Set 'RUN_TASKS_URL' to enabled this tests.
--- SKIP: TestAccTFEWorkspaceRunTask_create (0.00s)
=== RUN   TestAccTFEWorkspaceRunTask_beta_create
    testing.go:175: Skipping tests for Run Tasks. Set 'RUN_TASKS_URL' to enabled this tests.
--- SKIP: TestAccTFEWorkspaceRunTask_beta_create (0.00s)
=== RUN   TestAccTFEWorkspaceRunTask_import
    testing.go:175: Skipping tests for Run Tasks. Set 'RUN_TASKS_URL' to enabled this tests.
--- SKIP: TestAccTFEWorkspaceRunTask_import (0.00s)
=== RUN   TestAccTFEWorkspace_basic
--- PASS: TestAccTFEWorkspace_basic (7.06s)
=== RUN   TestAccTFEWorkspace_basicReadProjectId
--- PASS: TestAccTFEWorkspace_basicReadProjectId (6.98s)
=== RUN   TestAccTFEWorkspace_customProject
--- PASS: TestAccTFEWorkspace_customProject (7.23s)
=== RUN   TestAccTFEWorkspace_panic
--- PASS: TestAccTFEWorkspace_panic (6.71s)
=== RUN   TestAccTFEWorkspace_monorepo
--- PASS: TestAccTFEWorkspace_monorepo (6.97s)
=== RUN   TestAccTFEWorkspace_renamed
--- PASS: TestAccTFEWorkspace_renamed (8.83s)
=== RUN   TestAccTFEWorkspace_update
--- PASS: TestAccTFEWorkspace_update (9.83s)
=== RUN   TestAccTFEWorkspace_updateWorkingDirectory
--- PASS: TestAccTFEWorkspace_updateWorkingDirectory (12.55s)
=== RUN   TestAccTFEWorkspace_updateProject
--- PASS: TestAccTFEWorkspace_updateProject (10.45s)
=== RUN   TestAccTFEWorkspace_updateFileTriggers
--- PASS: TestAccTFEWorkspace_updateFileTriggers (9.72s)
=== RUN   TestAccTFEWorkspace_updateTriggerPrefixes
--- PASS: TestAccTFEWorkspace_updateTriggerPrefixes (9.63s)
=== RUN   TestAccTFEWorkspace_overwriteTriggerPatternsWithPrefixes
--- PASS: TestAccTFEWorkspace_overwriteTriggerPatternsWithPrefixes (12.45s)
=== RUN   TestAccTFEWorkspace_permutation_test_suite
=== RUN   TestAccTFEWorkspace_permutation_test_suite/file_triggers_enabled_is_false
=== RUN   TestAccTFEWorkspace_permutation_test_suite/file_triggers_enabled_is_false/and_trigger_prefixes_are_set_and_empty
=== RUN   TestAccTFEWorkspace_permutation_test_suite/file_triggers_enabled_is_false/and_trigger_prefixes_are_populated
=== RUN   TestAccTFEWorkspace_permutation_test_suite/file_triggers_enabled_is_false/and_trigger_patterns_are_set_and_empty
=== RUN   TestAccTFEWorkspace_permutation_test_suite/file_triggers_enabled_is_false/and_trigger_patterns_are_populated
=== RUN   TestAccTFEWorkspace_permutation_test_suite/file_triggers_enabled_is_true
=== RUN   TestAccTFEWorkspace_permutation_test_suite/file_triggers_enabled_is_true/and_trigger_prefixes_are_set_and_empty
=== RUN   TestAccTFEWorkspace_permutation_test_suite/file_triggers_enabled_is_true/and_trigger_prefixes_are_populated
=== RUN   TestAccTFEWorkspace_permutation_test_suite/file_triggers_enabled_is_true/and_trigger_patterns_are_set_and_empty
=== RUN   TestAccTFEWorkspace_permutation_test_suite/file_triggers_enabled_is_true/and_trigger_patterns_are_populated
=== RUN   TestAccTFEWorkspace_permutation_test_suite/file_triggers_enabled_is_true/and_both_trigger_prefixes_and_patterns_are_populated
=== RUN   TestAccTFEWorkspace_permutation_test_suite/file_triggers_enabled_is_true/and_both_trigger_prefixes_and_patterns_are_empty
=== RUN   TestAccTFEWorkspace_permutation_test_suite/file_triggers_enabled_is_true/change_trigger_prefixes_to_trigger_patterns_and_vice-versa
--- PASS: TestAccTFEWorkspace_permutation_test_suite (113.57s)
    --- PASS: TestAccTFEWorkspace_permutation_test_suite/file_triggers_enabled_is_false (37.66s)
        --- PASS: TestAccTFEWorkspace_permutation_test_suite/file_triggers_enabled_is_false/and_trigger_prefixes_are_set_and_empty (9.99s)
        --- PASS: TestAccTFEWorkspace_permutation_test_suite/file_triggers_enabled_is_false/and_trigger_prefixes_are_populated (9.77s)
        --- PASS: TestAccTFEWorkspace_permutation_test_suite/file_triggers_enabled_is_false/and_trigger_patterns_are_set_and_empty (9.54s)
        --- PASS: TestAccTFEWorkspace_permutation_test_suite/file_triggers_enabled_is_false/and_trigger_patterns_are_populated (8.36s)
    --- PASS: TestAccTFEWorkspace_permutation_test_suite/file_triggers_enabled_is_true (75.91s)
        --- PASS: TestAccTFEWorkspace_permutation_test_suite/file_triggers_enabled_is_true/and_trigger_prefixes_are_set_and_empty (10.10s)
        --- PASS: TestAccTFEWorkspace_permutation_test_suite/file_triggers_enabled_is_true/and_trigger_prefixes_are_populated (9.85s)
        --- PASS: TestAccTFEWorkspace_permutation_test_suite/file_triggers_enabled_is_true/and_trigger_patterns_are_set_and_empty (17.70s)
        --- PASS: TestAccTFEWorkspace_permutation_test_suite/file_triggers_enabled_is_true/and_trigger_patterns_are_populated (10.74s)
        --- PASS: TestAccTFEWorkspace_permutation_test_suite/file_triggers_enabled_is_true/and_both_trigger_prefixes_and_patterns_are_populated (2.77s)
        --- PASS: TestAccTFEWorkspace_permutation_test_suite/file_triggers_enabled_is_true/and_both_trigger_prefixes_and_patterns_are_empty (2.85s)
        --- PASS: TestAccTFEWorkspace_permutation_test_suite/file_triggers_enabled_is_true/change_trigger_prefixes_to_trigger_patterns_and_vice-versa (21.91s)
=== RUN   TestAccTFEWorkspace_updateTriggerPatterns
--- PASS: TestAccTFEWorkspace_updateTriggerPatterns (15.49s)
=== RUN   TestAccTFEWorkspace_patternsAndPrefixesConflicting
--- PASS: TestAccTFEWorkspace_patternsAndPrefixesConflicting (2.75s)
=== RUN   TestAccTFEWorkspace_changeTags
--- PASS: TestAccTFEWorkspace_changeTags (28.44s)
=== RUN   TestAccTFEWorkspace_updateSpeculative
--- PASS: TestAccTFEWorkspace_updateSpeculative (9.77s)
=== RUN   TestAccTFEWorkspace_structuredRunOutputDisabled
--- PASS: TestAccTFEWorkspace_structuredRunOutputDisabled (10.53s)
=== RUN   TestAccTFEWorkspace_updateVCSRepo
    provider_test.go:293: Please set GITHUB_WORKSPACE_IDENTIFIER to run this test
--- SKIP: TestAccTFEWorkspace_updateVCSRepo (0.21s)
=== RUN   TestAccTFEWorkspace_updateVCSRepoTagsRegex
    provider_test.go:293: Please set GITHUB_WORKSPACE_IDENTIFIER to run this test
--- SKIP: TestAccTFEWorkspace_updateVCSRepoTagsRegex (0.21s)
=== RUN   TestAccTFEWorkspace_updateVCSRepoChangeTagRegexToTriggerPattern
    provider_test.go:293: Please set GITHUB_WORKSPACE_IDENTIFIER to run this test
--- SKIP: TestAccTFEWorkspace_updateVCSRepoChangeTagRegexToTriggerPattern (0.50s)
=== RUN   TestAccTFEWorkspace_updateRemoveVCSRepoWithTagsRegex
    provider_test.go:293: Please set GITHUB_WORKSPACE_IDENTIFIER to run this test
--- SKIP: TestAccTFEWorkspace_updateRemoveVCSRepoWithTagsRegex (0.36s)
=== RUN   TestAccTFEWorkspace_sshKey
--- PASS: TestAccTFEWorkspace_sshKey (13.71s)
=== RUN   TestAccTFEWorkspace_import
--- PASS: TestAccTFEWorkspace_import (8.29s)
=== RUN   TestAccTFEWorkspace_importVCSBranch
    provider_test.go:293: Please set GITHUB_WORKSPACE_IDENTIFIER to run this test
--- SKIP: TestAccTFEWorkspace_importVCSBranch (0.21s)
=== RUN   TestAccTFEWorkspace_importProject
--- PASS: TestAccTFEWorkspace_importProject (8.18s)
=== RUN   TestAccTFEWorkspace_operationsAndExecutionModeInteroperability
--- PASS: TestAccTFEWorkspace_operationsAndExecutionModeInteroperability (18.37s)
=== RUN   TestAccTFEWorkspace_unsetExecutionMode
--- PASS: TestAccTFEWorkspace_unsetExecutionMode (10.24s)
=== RUN   TestAccTFEWorkspace_globalRemoteState
--- PASS: TestAccTFEWorkspace_globalRemoteState (10.87s)
=== RUN   TestAccTFEWorkspace_alterRemoteStateConsumers
--- PASS: TestAccTFEWorkspace_alterRemoteStateConsumers (21.23s)
=== RUN   TestAccTFEWorkspace_createWithRemoteStateConsumers
--- PASS: TestAccTFEWorkspace_createWithRemoteStateConsumers (8.50s)
=== RUN   TestAccTFEWorkspace_paginatedRemoteStateConsumers
--- PASS: TestAccTFEWorkspace_paginatedRemoteStateConsumers (36.12s)
=== RUN   TestAccTFEWorkspace_delete_forceDeleteSettingDisabled
--- PASS: TestAccTFEWorkspace_delete_forceDeleteSettingDisabled (11.09s)
=== RUN   TestAccTFEWorkspace_delete_forceDeleteSettingEnabled
--- PASS: TestAccTFEWorkspace_delete_forceDeleteSettingEnabled (9.36s)
=== RUN   TestAccTFEWorkspace_basicAssessmentsEnabled
--- PASS: TestAccTFEWorkspace_basicAssessmentsEnabled (10.16s)
=== RUN   TestAccTFEWorkspaceVariableSet_basic
--- PASS: TestAccTFEWorkspaceVariableSet_basic (9.19s)
PASS
ok  	github.com/hashicorp/terraform-provider-tfe/tfe	582.408s
?   	github.com/hashicorp/terraform-provider-tfe/version	[no test files]
mwudka-C02Z77BPLVDQ:terraform-provider-tfe mwudka$
...

@mwudka mwudka self-assigned this Nov 24, 2022
@mwudka mwudka changed the title Mwudka/projects Add projects support Nov 24, 2022
@mwudka mwudka force-pushed the mwudka/projects branch 3 times, most recently from fdaf4b6 to 1034717 Compare November 29, 2022 21:31
@mwudka mwudka marked this pull request as ready for review November 29, 2022 22:55
@mwudka mwudka requested a review from a team as a code owner November 29, 2022 22:55
tfe/resource_tfe_project.go Outdated Show resolved Hide resolved
@@ -0,0 +1,109 @@
package tfe

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like the markdown docs, project.html.markdown is missing, is there a plan to add that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, I just pushed it and added a preview to the PR description.

CHANGELOG.md Outdated Show resolved Hide resolved
Copy link
Contributor

@Uk1288 Uk1288 left a comment

Choose a reason for hiding this comment

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

Looking good! Thank you for doing the text clean up along side.

One small comment, the commits history can be squashed to keep the history minimal.

Copy link
Collaborator

@brandonc brandonc left a comment

Choose a reason for hiding this comment

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

Having the project_id in the workspace creates an interesting co-dependency when destroying project resources. You have to apply two plans:

  1. change all tfe_workspace.project_id to some other project
  2. remove the project to destroy it

One potential way to resolve this is to have a relationship resource tfe_workspace_project which, upon destruction, changes to the org default or something. That would usually get destroyed before the project. I don't think it's necessary and may be even more cumbersome than the project_id field.

This is great! I didn't find anything

tfe/resource_tfe_policy_set_parameter.go Show resolved Hide resolved
tfe/resource_tfe_project.go Show resolved Hide resolved
tfe/resource_tfe_project.go Show resolved Hide resolved
Copy link
Collaborator

@brandonc brandonc left a comment

Choose a reason for hiding this comment

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

One tiny thing I found was that the default_project_id is set as optional, but configurations ought not set it because it's always computed.

"Computed" alone means that it's not allowed in the configuration at all, which is what we probably want here. If a user sets this to something arbitrary, you get Error: Provider produced inconsistent final plan after the API computes it.

tfe/resource_tfe_organization.go Outdated Show resolved Hide resolved
@mwudka mwudka force-pushed the mwudka/projects branch 2 times, most recently from 7a10a0f to d6c9e63 Compare December 1, 2022 19:40
@mwudka mwudka deleted the mwudka/projects branch December 6, 2022 01:55
@MichaelGerhart
Copy link

@mwudka is there any intention to add the ability to manage project access for teams to this before it goes GA?

We are a paid TF Cloud customer that is using the projects private beta, and something that seems to be missing from this resource is the ability to manage access to the project.

Should I open a new issue for that functionality or go through the beta process to request it?

@brandonc
Copy link
Collaborator

brandonc commented Jan 5, 2023

I've created a feature request in this repo to reinforce that project support is incomplete without a team access resource. Support for project/team access was just merged into our go SDK today so I assume that a provider resource is forthcoming.

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.

None yet

4 participants