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 project data source #829

Merged
merged 6 commits into from
Apr 14, 2023
Merged

Add project data source #829

merged 6 commits into from
Apr 14, 2023

Conversation

hs26gill
Copy link
Contributor

@hs26gill hs26gill commented Mar 23, 2023

Description

This PR adds a new data_source_project resource. This'll allow the users to get project id and all the associated workspaces ids.

Testing plan

  1. Create a terraform file as shown below
resource "tfe_organization" "test" {
  name  = "my organization"
  email = "[email protected]"
}

resource "tfe_project" "foobar" {
  name         = "my project"
  organization = tfe_organization.test.id
}

resource "tfe_workspace" "foobar" {
  name         = "workspace-foo"
  organization = tfe_organization.test.id
  project_id  = tfe_project.foobar.id
}

resource "tfe_workspace" "foobar2" {
  name         = "workspace-foo2"
  organization = tfe_organization.test.id
  project_id  = tfe_project.foobar.id
}

data "tfe_project" "foobar" {
  name         = tfe_project.foobar.name
  organization = tfe_organization.test.name
}

output "project_id" {
  value = data.tfe_project.foobar.id
}


output "workspace_ids" {
  value = data.tfe_project.foobar.workspace_ids
}
  1. terraform apply
  2. Check that the project id and the two workspaces ids are returned under the terraform outputs. For example:
project_id = "prj-q1R8xZxokQuQjwpq"
workspace_ids = toset([
  "ws-R5Ch51cRLbrY59bE",
  "ws-SkTq9Pni89KWYbop",
])

External links

Related Go-TFE PRs

Output from acceptance tests

$ TESTARGS="-run TestAccTFEProjectDataSource_basic" make testacc

Ran tests locally with below output

=== RUN   TestAccTFEProjectDataSource_basic
--- PASS: TestAccTFEProjectDataSource_basic (13.06s)
PASS

Process finished with the exit code 0

@hs26gill hs26gill self-assigned this Mar 23, 2023
@hs26gill hs26gill force-pushed the TF-3371-add-project-data-source branch from 7ce6540 to 4e35ea9 Compare April 11, 2023 15:18
@hs26gill hs26gill marked this pull request as ready for review April 11, 2023 15:35
@hs26gill hs26gill requested a review from a team as a code owner April 11, 2023 15:35
@hs26gill hs26gill force-pushed the TF-3371-add-project-data-source branch 4 times, most recently from cf71050 to 8c3562b Compare April 12, 2023 14:37
@hs26gill hs26gill changed the title add project data source and tests Add project data source Apr 12, 2023
tfe/data_source_project.go Outdated Show resolved Hide resolved
website/docs/d/project.html.markdown Show resolved Hide resolved
tfe/data_source_project.go Outdated Show resolved Hide resolved
tfe/data_source_project.go Outdated Show resolved Hide resolved
@hs26gill hs26gill force-pushed the TF-3371-add-project-data-source branch from 832d9ca to 8934101 Compare April 13, 2023 21:00
tfe/data_source_project.go Outdated Show resolved Hide resolved
@hs26gill hs26gill force-pushed the TF-3371-add-project-data-source branch from 8934101 to 369a6b2 Compare April 13, 2023 21:50
@hs26gill hs26gill force-pushed the TF-3371-add-project-data-source branch from 369a6b2 to a8e39a4 Compare April 13, 2023 21:50
@hs26gill hs26gill merged commit d6f0047 into main Apr 14, 2023
@hs26gill hs26gill deleted the TF-3371-add-project-data-source branch April 14, 2023 13:53
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