forked from GoogleCloudPlatform/magic-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enabling management of Default Start Flow + Default Welcome Intent + …
…Default Negative Intent, without terraform import Fixes hashicorp/terraform-provider-google#16308
- Loading branch information
1 parent
6c5551f
commit ed9503c
Showing
6 changed files
with
100 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
mmv1/templates/terraform/pre_create/dialogflowcx_set_location_skip_default_obj.go.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
|
||
// extract location from the parent | ||
location := "" | ||
|
||
if parts := regexp.MustCompile(`locations\/([^\/]*)\/`).FindStringSubmatch(d.Get("parent").(string)); parts != nil { | ||
location = parts[1] | ||
} else { | ||
return fmt.Errorf( | ||
"Saw %s when the parent is expected to contains location %s", | ||
d.Get("parent"), | ||
"projects/{{project}}/locations/{{location}}/...", | ||
) | ||
} | ||
|
||
url = strings.Replace(url,"-dialogflow",fmt.Sprintf("%s-dialogflow",location),1) | ||
|
||
// if it's a default object Dialogflow creates for you, "Update" instead of "Create" | ||
isDefaultStartFlow, _ := d.Get("is_default_start_flow").(bool) | ||
isDefaultWelcomeIntent, _ := d.Get("is_default_welcome_intent").(bool) | ||
isDefaultNegativeIntent, _ := d.Get("is_default_negative_intent").(bool) | ||
if isDefaultStartFlow || isDefaultWelcomeIntent || isDefaultNegativeIntent { | ||
// hardcode the default object ID: | ||
var defaultObjName string | ||
if isDefaultStartFlow || isDefaultWelcomeIntent { | ||
defaultObjName = "00000000-0000-0000-0000-000000000000" | ||
} | ||
if isDefaultNegativeIntent { | ||
defaultObjName = "00000000-0000-0000-0000-000000000001" | ||
} | ||
|
||
// Store the ID | ||
d.Set("name", defaultObjName) | ||
id, err := tpgresource.ReplaceVars(d, config, "<%= id_format(object) -%>") | ||
if err != nil { | ||
return fmt.Errorf("Error constructing id: %s", err) | ||
} | ||
d.SetId(id) | ||
|
||
// and defer to the Update method: | ||
return resource<%= resource_name -%>Update(d, meta) | ||
} |
25 changes: 25 additions & 0 deletions
25
mmv1/templates/terraform/pre_delete/dialogflowcx_set_location_skip_default_obj.go.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
// extract location from the parent | ||
location := "" | ||
|
||
if parts := regexp.MustCompile(`locations\/([^\/]*)\/`).FindStringSubmatch(d.Get("parent").(string)); parts != nil { | ||
location = parts[1] | ||
} else { | ||
return fmt.Errorf( | ||
"Saw %s when the parent is expected to contains location %s", | ||
d.Get("parent"), | ||
"projects/{{project}}/locations/{{location}}/...", | ||
) | ||
} | ||
|
||
url = strings.Replace(url,"-dialogflow",fmt.Sprintf("%s-dialogflow",location),1) | ||
|
||
// if it's a default object Dialogflow creates for you, skip deletion | ||
isDefaultStartFlow, _ := d.Get("is_default_start_flow").(bool) | ||
isDefaultWelcomeIntent, _ := d.Get("is_default_welcome_intent").(bool) | ||
isDefaultNegativeIntent, _ := d.Get("is_default_negative_intent").(bool) | ||
if isDefaultStartFlow || isDefaultWelcomeIntent || isDefaultNegativeIntent { | ||
// we can't delete these resources so do nothing | ||
log.Printf("[DEBUG] Not deleting default <%= resource_name -%>") | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters