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

google_active_folder data lookup: make parent optional #7509

Closed
wants to merge 2 commits into from

Conversation

ngodec
Copy link

@ngodec ngodec commented Oct 13, 2020

Issue: when using a nested folder structure, it is proving challenging to use the existing data resource due to the need to know the parent ID.
Google folder lookup API finds folders perfectly fine without providing the parent:

"query": "lifecycleState=ACTIVE AND displayName=\"Engineering\""

{
  "folders": [
    {
      "name": "folders/<Redacted>",
      "parent": "organizations/<Redacted>",
      "displayName": "Engineering",
      "lifecycleState": "ACTIVE",
      "createTime": "2019-06-14T09:20:35.233Z"
    }
  ]
}

"query": "lifecycleState=ACTIVE AND displayName=\"Global Dev\""

Results returned just fine:
{
  "folders": [
    {
      "name": "folders/<Redacted>",
      "parent": "folders/<Redacted>",
      "displayName": "Global Dev",
      "lifecycleState": "ACTIVE",
      "createTime": "2020-06-16T11:41:45.998Z"
    }
  ]
}

@ghost ghost added the size/s label Oct 13, 2020
@ghost ghost requested a review from rileykarson October 13, 2020 14:04
Copy link
Collaborator

@rileykarson rileykarson left a comment

Choose a reason for hiding this comment

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

Generally looks good- we'll just want to update the website as well.

google/data_source_google_active_folder.go Outdated Show resolved Hide resolved
google/data_source_google_active_folder.go Show resolved Hide resolved
queryString := fmt.Sprintf("lifecycleState=ACTIVE AND parent=%s AND displayName=\"%s\"", parent, displayName)
// parent is optional
if parent, ok := d.GetOk("parent"); ok {
queryString := fmt.Sprintf("lifecycleState=ACTIVE AND parent=%s AND displayName=\"%s\"", parent.(string), displayName)
Copy link
Collaborator

Choose a reason for hiding this comment

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

You'll need to initialize the variable outside of this if block, and then set a value inside. As-is it isn't in scope when it gets used later.

Copy link
Author

Choose a reason for hiding this comment

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

Thank you! This is very helpful, I was wondering whether it was the case.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah- now, you'll want to change := to = on lines 43 and 45. As-is, you're shadowing the queryString variable above instead of assigning a value to it.

Copy link
Author

Choose a reason for hiding this comment

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

Hey, thank you - fixed that now. This should be good to go I think?

@ghost ghost added size/m and removed size/s labels Oct 15, 2020
Google folder lookup API finds folders perfectly fine without providing the folder parent:

```
"query": "lifecycleState=ACTIVE AND displayName=\"Engineering\""

{
  "folders": [
    {
      "name": "folders/<Redacted>",
      "parent": "organizations/<Redacted>",
      "displayName": "Engineering",
      "lifecycleState": "ACTIVE",
      "createTime": "2019-06-14T09:20:35.233Z"
    }
  ]
}

"query": "lifecycleState=ACTIVE AND displayName=\"Global Dev\""

Results returned just fine:
{
  "folders": [
    {
      "name": "folders/<Redacted>",
      "parent": "folders/<Redacted>",
      "displayName": "Global Dev",
      "lifecycleState": "ACTIVE",
      "createTime": "2020-06-16T11:41:45.998Z"
    }
  ]
}
```
@ngodec
Copy link
Author

ngodec commented Mar 23, 2021

Hey @rileykarson apologies, I just came to fixing this. Tests pass now

Copy link
Collaborator

@rileykarson rileykarson left a comment

Choose a reason for hiding this comment

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

I'll need to make a pull request against https://github.com/GoogleCloudPlatform/magic-modules cloning this PR and merge this at the same time as the one there.

modular-magician added a commit to modular-magician/terraform-provider-google that referenced this pull request Mar 29, 2023
Co-authored-by: Madhura Phadnis <[email protected]>
Signed-off-by: Modular Magician <[email protected]>
modular-magician added a commit that referenced this pull request Mar 29, 2023
Signed-off-by: Modular Magician <[email protected]>
Co-authored-by: Madhura Phadnis <[email protected]>
@rileykarson
Copy link
Collaborator

Closing PR as stale

Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants