Skip to content

Commit

Permalink
Allow NotificationChannel import process to set project from the URI …
Browse files Browse the repository at this point in the history
…(#9022) (#6327)

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Sep 21, 2023
1 parent 7644a30 commit 2661abb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .changelog/9022.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
monitoring: fixed bug where importing `google_monitoring_notification_channel` failed when no default project was supplied in provider configuration or through environment variables
```
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"fmt"
"log"
"reflect"
"strings"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff"
Expand Down Expand Up @@ -540,10 +541,21 @@ func resourceMonitoringNotificationChannelImport(d *schema.ResourceData, meta in
config := meta.(*transport_tpg.Config)

// current import_formats can't import fields with forward slashes in their value
if err := tpgresource.ParseImportId([]string{"(?P<project>[^ ]+) (?P<name>[^ ]+)", "(?P<name>[^ ]+)"}, d, config); err != nil {
if err := tpgresource.ParseImportId([]string{"(?P<name>.+)"}, d, config); err != nil {
return nil, err
}

stringParts := strings.Split(d.Get("name").(string), "/")
if len(stringParts) < 2 {
return nil, fmt.Errorf(
"Could not split project from name: %s",
d.Get("name"),
)
}

if err := d.Set("project", stringParts[1]); err != nil {
return nil, fmt.Errorf("Error setting project: %s", err)
}
return []*schema.ResourceData{d}, nil
}

Expand Down

0 comments on commit 2661abb

Please sign in to comment.