Skip to content

Commit e30b174

Browse files
Exact domain matching for organization data source (#3534) (#2085)
Signed-off-by: Modular Magician <[email protected]>
1 parent d16cbf8 commit e30b174

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

.changelog/3534.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
Fixed an issue where data source `google_organization` would ignore exact domain matches if multiple domains were found
3+
```

google-beta/data_source_google_organization.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,20 @@ func dataSourceOrganizationRead(d *schema.ResourceData, meta interface{}) error
7070
}
7171

7272
if len(resp.Organizations) > 1 {
73-
return fmt.Errorf("More than one matching organization found")
73+
// Attempt to find an exact domain match
74+
for _, org := range resp.Organizations {
75+
if org.DisplayName == v.(string) {
76+
organization = org
77+
break
78+
}
79+
}
80+
if organization == nil {
81+
return fmt.Errorf("Received multiple organizations in the response, but could not find an exact domain match.")
82+
}
83+
} else {
84+
organization = resp.Organizations[0]
7485
}
7586

76-
organization = resp.Organizations[0]
7787
} else if v, ok := d.GetOk("organization"); ok {
7888
var resp *cloudresourcemanager.Organization
7989
err := retryTimeDuration(func() (err error) {

0 commit comments

Comments
 (0)