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

Feat: add "parent_project_path" or "hierarchy_by_name" to data "env0_… #952

Merged
merged 5 commits into from
Sep 11, 2024

Conversation

TomerHeber
Copy link
Collaborator

@TomerHeber TomerHeber commented Sep 6, 2024

…project"

Issue & Steps to Reproduce / Feature Request

resolves #948

Solution

  1. Updated the project schema and added the new value.
  2. Add required code to search based on path.
  3. Added acceptance tests.
  4. Added harness tests.

@TomerHeber TomerHeber changed the title WIP: Feat: add "parent_project_path" or "hierarchy_by_name" to data "env0_… Feat: add "parent_project_path" or "hierarchy_by_name" to data "env0_… Sep 8, 2024
Type: schema.TypeString,
Description: "a path of ancestors projects divided by the prefix '|'. Can be used as a filter when there are multiple subprojects with the same name under different parent projects. For example: 'App|Dev|us-east-1' will search for a project with the hierarchy 'App -> Dev -> us-east-1' ('us-east-1' being the parent)",
Optional: true,
ConflictsWith: []string{"parent_project_name"},

Choose a reason for hiding this comment

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

does it not also conflict with the parent_project_id?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

you're correct...
I think I did not do that because the parent_project_id is also a computed field, and I was worried it will cause issues.
But looks like the SDK knows how to handle that use-case, so I'll push the change. (Sometimes the Terraform SDK is buggy).

// right most element is the project itself, remove it.
parentIds = parentIds[:len(parentIds)-1]

matches, err := pathMatches(path, parentIds, meta)

Choose a reason for hiding this comment

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

mmmm that feels a bit complicated, couldn't we have filtered the projects by their hierarchy seeing if hierarchy.contains(searchedPath) ?
Or am I missing something?

Choose a reason for hiding this comment

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

oh oh nvm I am wrong since those are IDs not names so it won't work that way 👌

@@ -162,14 +182,64 @@ func getProjectByName(name string, parentId string, parentName string, meta inte
return projectsByName[0], nil
}

func pathMatches(path, parentIds []string, meta interface{}) (bool, error) {
if len(path) != len(parentIds) {

Choose a reason for hiding this comment

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

so if we have a1|a2|a3|searchedProject
and we put a1|a2 as the path we would not find it, is that intended?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I tend to agree. We could support prefixes as well.
I don't know if that's what @away168 had in mind... but why not...

modifying to:

	if len(path) > len(parentIds) {
		return false, nil
	}

Copy link

@ItamarMalka ItamarMalka left a comment

Choose a reason for hiding this comment

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

Looks good, just ping me when you answered the questions I left 👍

@TomerHeber
Copy link
Collaborator Author

Looks good, just ping me when you answered the questions I left 👍

@ItamarMalka thank you.
I have updated the PR. For the prefix match, I've added a couple of new tests.
All changes are in 40dcdef

Copy link

@ItamarMalka ItamarMalka left a comment

Choose a reason for hiding this comment

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

LGTM 🚀 👍
@away168 let us know if there is anything else that you think is needed here 🙏

@github-actions github-actions bot added ready to merge PR approved - can be merged once the PR owner is ready and removed pending final review labels Sep 11, 2024
@TomerHeber TomerHeber merged commit f886bd3 into main Sep 11, 2024
4 of 5 checks passed
@TomerHeber TomerHeber deleted the feat-parent-path-#948 branch September 11, 2024 13:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature integration-tests provider ready to merge PR approved - can be merged once the PR owner is ready
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add "parent_project_path" or "hierarchy_by_name" to data "env0_project"
2 participants