Skip to content

Commit 4054ebe

Browse files
Update Instance.yaml delete_url for Looker (#11950) (#8453)
[upstream:b7d5a7d1eeeda16a04126c1dd4f37e10a0c537b8] Signed-off-by: Modular Magician <[email protected]>
1 parent 2ba385b commit 4054ebe

File tree

4 files changed

+94
-0
lines changed

4 files changed

+94
-0
lines changed

.changelog/11950.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
looker: added `deletion_policy` to `google_looker_instance` to allow force-destroying instances with nested resources by setting `deletion_policy = FORCE`
3+
```

google-beta/services/looker/resource_looker_instance.go

+24
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,15 @@ accurate to nanoseconds.`,
496496
Description: `The time the instance was updated in RFC3339 UTC "Zulu" format,
497497
accurate to nanoseconds.`,
498498
},
499+
"deletion_policy": {
500+
Type: schema.TypeString,
501+
Optional: true,
502+
Description: `Policy to determine if the cluster should be deleted forcefully.
503+
If setting deletion_policy = "FORCE", the Looker instance will be deleted regardless
504+
of its nested resources. If set to "DEFAULT", Looker instances that still have
505+
nested resources will return an error. Possible values: DEFAULT, FORCE`,
506+
Default: "DEFAULT",
507+
},
499508
"project": {
500509
Type: schema.TypeString,
501510
Optional: true,
@@ -712,6 +721,12 @@ func resourceLookerInstanceRead(d *schema.ResourceData, meta interface{}) error
712721
return transport_tpg.HandleNotFoundError(err, d, fmt.Sprintf("LookerInstance %q", d.Id()))
713722
}
714723

724+
// Explicitly set virtual fields to default values if unset
725+
if _, ok := d.GetOkExists("deletion_policy"); !ok {
726+
if err := d.Set("deletion_policy", "DEFAULT"); err != nil {
727+
return fmt.Errorf("Error setting deletion_policy: %s", err)
728+
}
729+
}
715730
if err := d.Set("project", project); err != nil {
716731
return fmt.Errorf("Error reading Instance: %s", err)
717732
}
@@ -1021,6 +1036,10 @@ func resourceLookerInstanceDelete(d *schema.ResourceData, meta interface{}) erro
10211036
}
10221037

10231038
headers := make(http.Header)
1039+
// Forcefully delete the Looker instance
1040+
if deletionPolicy := d.Get("deletion_policy"); deletionPolicy == "FORCE" {
1041+
url = url + "?force=True"
1042+
}
10241043

10251044
log.Printf("[DEBUG] Deleting Instance %q", d.Id())
10261045
res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{
@@ -1068,6 +1087,11 @@ func resourceLookerInstanceImport(d *schema.ResourceData, meta interface{}) ([]*
10681087
}
10691088
d.SetId(id)
10701089

1090+
// Explicitly set virtual fields to default values on import
1091+
if err := d.Set("deletion_policy", "DEFAULT"); err != nil {
1092+
return nil, fmt.Errorf("Error setting deletion_policy: %s", err)
1093+
}
1094+
10711095
return []*schema.ResourceData{d}, nil
10721096
}
10731097

google-beta/services/looker/resource_looker_instance_generated_test.go

+41
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ resource "google_looker_instance" "looker-instance" {
6565
client_id = "tf-test-my-client-id%{random_suffix}"
6666
client_secret = "tf-test-my-client-secret%{random_suffix}"
6767
}
68+
deletion_policy = "DEFAULT"
6869
}
6970
`, context)
7071
}
@@ -368,6 +369,46 @@ resource "google_looker_instance" "looker-instance" {
368369
`, context)
369370
}
370371

372+
func TestAccLookerInstance_lookerInstanceForceDeleteExample(t *testing.T) {
373+
t.Parallel()
374+
375+
context := map[string]interface{}{
376+
"random_suffix": acctest.RandString(t, 10),
377+
}
378+
379+
acctest.VcrTest(t, resource.TestCase{
380+
PreCheck: func() { acctest.AccTestPreCheck(t) },
381+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
382+
CheckDestroy: testAccCheckLookerInstanceDestroyProducer(t),
383+
Steps: []resource.TestStep{
384+
{
385+
Config: testAccLookerInstance_lookerInstanceForceDeleteExample(context),
386+
},
387+
{
388+
ResourceName: "google_looker_instance.looker-instance",
389+
ImportState: true,
390+
ImportStateVerify: true,
391+
ImportStateVerifyIgnore: []string{"deletion_policy", "name", "oauth_config", "region"},
392+
},
393+
},
394+
})
395+
}
396+
397+
func testAccLookerInstance_lookerInstanceForceDeleteExample(context map[string]interface{}) string {
398+
return acctest.Nprintf(`
399+
resource "google_looker_instance" "looker-instance" {
400+
name = "tf-test-my-instance%{random_suffix}"
401+
platform_edition = "LOOKER_CORE_STANDARD_ANNUAL"
402+
region = "us-central1"
403+
oauth_config {
404+
client_id = "tf-test-my-client-id%{random_suffix}"
405+
client_secret = "tf-test-my-client-secret%{random_suffix}"
406+
}
407+
deletion_policy = "FORCE"
408+
}
409+
`, context)
410+
}
411+
371412
func testAccCheckLookerInstanceDestroyProducer(t *testing.T) func(s *terraform.State) error {
372413
return func(s *terraform.State) error {
373414
for name, rs := range s.RootModule().Resources {

website/docs/r/looker_instance.html.markdown

+26
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ resource "google_looker_instance" "looker-instance" {
4646
client_id = "my-client-id"
4747
client_secret = "my-client-secret"
4848
}
49+
deletion_policy = "DEFAULT"
4950
}
5051
```
5152
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
@@ -250,6 +251,26 @@ resource "google_looker_instance" "looker-instance" {
250251
}
251252
}
252253
```
254+
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
255+
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.jpy.wang%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_image=gcr.io%2Fcloudshell-images%2Fcloudshell%3Alatest&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md&cloudshell_working_dir=looker_instance_force_delete&open_in_editor=main.tf" target="_blank">
256+
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
257+
</a>
258+
</div>
259+
## Example Usage - Looker Instance Force Delete
260+
261+
262+
```hcl
263+
resource "google_looker_instance" "looker-instance" {
264+
name = "my-instance"
265+
platform_edition = "LOOKER_CORE_STANDARD_ANNUAL"
266+
region = "us-central1"
267+
oauth_config {
268+
client_id = "my-client-id"
269+
client_secret = "my-client-secret"
270+
}
271+
deletion_policy = "FORCE"
272+
}
273+
```
253274

254275
## Argument Reference
255276

@@ -360,6 +381,11 @@ The following arguments are supported:
360381
* `project` - (Optional) The ID of the project in which the resource belongs.
361382
If it is not provided, the provider project is used.
362383

384+
* `deletion_policy` - (Optional) Policy to determine if the cluster should be deleted forcefully.
385+
If setting deletion_policy = "FORCE", the Looker instance will be deleted regardless
386+
of its nested resources. If set to "DEFAULT", Looker instances that still have
387+
nested resources will return an error. Possible values: DEFAULT, FORCE
388+
363389

364390
<a name="nested_admin_settings"></a>The `admin_settings` block supports:
365391

0 commit comments

Comments
 (0)