-
Notifications
You must be signed in to change notification settings - Fork 15
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
Conversation
env0/data_project.go
Outdated
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"}, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 👌
env0/data_project.go
Outdated
@@ -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) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
}
There was a problem hiding this 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 👍
@ItamarMalka thank you. |
There was a problem hiding this 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 🙏
…project"
Issue & Steps to Reproduce / Feature Request
resolves #948
Solution