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

d/tfe_project: Ignore case when matching project name #958

Merged
merged 3 commits into from
Jul 17, 2023
Merged

Conversation

jbonhag
Copy link
Contributor

@jbonhag jbonhag commented Jul 17, 2023

Description

Fixes #882.

This PR performs case-insensitive matching when reading the list of projects from the Projects List API for the tfe_project data source.

There was a potential issue where a project would not be found in the API response when the name attribute didn't match the case of the existing project exactly. For example, given an organization with a project 'Hello There', this data source would fail to read a matching project, despite its presence in the API response:

data "tfe_project" "foo" {
  organization = "jbonhag"
  name         = "hello there"
}
...
╷
│ Error: could not find project jbonhag/hello there
│ 
│   with data.tfe_project.foo,
│   on main.tf line 10, in data "tfe_project" "foo":
│   10: data "tfe_project" "foo" {
│ 
╵

Request:

GET /api/v2/organizations/jbonhag/projects?filter%5Bnames%5D=hello+there

Response:

{
  "data": [
    {
      "id": "prj-cPt3Ax5iuwgaGxrp",
      "type": "projects",
      "attributes": {
        "name": "Hello There",
...

Because project names in TFC have to be unique without regard to case, it makes sense to match the project name case-insensitively.

Remember to:

Testing plan

  1. Create a project called Foo
  2. Create a tfe_project data source with lowercase name foo, e.g.:
data "tfe_project" "foo" {
  organization = "my-org"
  name = "foo"
}

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

  1. Run terraform apply
  2. Project should be found

External links

Include any links here that might be helpful for people reviewing your PR. If there are none, feel free to delete this section.

Output from acceptance tests

Please run applicable acceptance tests locally and include the output here. See testing.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 TestAccTFEProjectDataSource_caseInsensitive" make testacc
TF_ACC=1 TF_LOG_SDK_PROTO=OFF go test $(go list ./... |grep -v 'vendor') -v -run TestAccTFEProjectDataSource_caseInsensitive -timeout 15m
?   	github.com/hashicorp/terraform-provider-tfe	[no test files]
=== RUN   TestAccTFEProjectDataSource_caseInsensitive
--- PASS: TestAccTFEProjectDataSource_caseInsensitive (8.54s)
PASS
ok  	github.com/hashicorp/terraform-provider-tfe/tfe	9.045s
?   	github.com/hashicorp/terraform-provider-tfe/version	[no test files]

@jbonhag jbonhag requested a review from a team as a code owner July 17, 2023 13:40
@jbonhag jbonhag changed the title d/tfe_project: Match project name case-insensitive (fixes #882) d/tfe_project: Match project name case-insensitive Jul 17, 2023
@jbonhag jbonhag changed the title d/tfe_project: Match project name case-insensitive d/tfe_project: Ignore case when matching project name Jul 17, 2023
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.

👍

@jbonhag jbonhag merged commit 5695e84 into main Jul 17, 2023
8 checks passed
@jbonhag jbonhag deleted the jbonhag/882 branch July 17, 2023 15:40
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.

tfe_project data source not finding projects
2 participants