Skip to content

Commit 84a0acb

Browse files
feat: (storageinsights) added force_destroy to google_storage_insights_report_config resource (#15162) (#24462)
[upstream:e826043a2c6777853a15da984374558fd7b6bf8b] Signed-off-by: Modular Magician <magic-modules@google.com>
1 parent b506b69 commit 84a0acb

7 files changed

+31
-5
lines changed

.changelog/15162.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
storage: added `force_destroy` field to `google_storage_insights_report_config` resource
3+
```

google/services/storageinsights/resource_storage_insights_report_config.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,12 @@ must be in the same location.`,
230230
Computed: true,
231231
Description: `The UUID of the inventory report configuration.`,
232232
},
233+
"force_destroy": {
234+
Type: schema.TypeBool,
235+
Optional: true,
236+
Description: `If set, all the inventory report details associated with this report configuration are deleted.`,
237+
Default: false,
238+
},
233239
"project": {
234240
Type: schema.TypeString,
235241
Optional: true,
@@ -370,6 +376,12 @@ func resourceStorageInsightsReportConfigRead(d *schema.ResourceData, meta interf
370376
return transport_tpg.HandleNotFoundError(err, d, fmt.Sprintf("StorageInsightsReportConfig %q", d.Id()))
371377
}
372378

379+
// Explicitly set virtual fields to default values if unset
380+
if _, ok := d.GetOkExists("force_destroy"); !ok {
381+
if err := d.Set("force_destroy", false); err != nil {
382+
return fmt.Errorf("Error setting force_destroy: %s", err)
383+
}
384+
}
373385
if err := d.Set("project", project); err != nil {
374386
return fmt.Errorf("Error reading ReportConfig: %s", err)
375387
}
@@ -524,7 +536,7 @@ func resourceStorageInsightsReportConfigDelete(d *schema.ResourceData, meta inte
524536
}
525537
billingProject = project
526538

527-
url, err := tpgresource.ReplaceVars(d, config, "{{StorageInsightsBasePath}}projects/{{project}}/locations/{{location}}/reportConfigs/{{name}}")
539+
url, err := tpgresource.ReplaceVars(d, config, "{{StorageInsightsBasePath}}projects/{{project}}/locations/{{location}}/reportConfigs/{{name}}?force={{force_destroy}}")
528540
if err != nil {
529541
return err
530542
}
@@ -574,6 +586,11 @@ func resourceStorageInsightsReportConfigImport(d *schema.ResourceData, meta inte
574586
}
575587
d.SetId(id)
576588

589+
// Explicitly set virtual fields to default values on import
590+
if err := d.Set("force_destroy", false); err != nil {
591+
return nil, fmt.Errorf("Error setting force_destroy: %s", err)
592+
}
593+
577594
return []*schema.ResourceData{d}, nil
578595
}
579596

google/services/storageinsights/resource_storage_insights_report_config_generated_meta.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ fields:
99
- field: 'csv_options.header_required'
1010
- field: 'csv_options.record_separator'
1111
- field: 'display_name'
12+
- field: 'force_destroy'
13+
provider_only: true
1214
- field: 'frequency_options.end_date.day'
1315
- field: 'frequency_options.end_date.month'
1416
- field: 'frequency_options.end_date.year'

google/services/storageinsights/resource_storage_insights_report_config_generated_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func TestAccStorageInsightsReportConfig_storageInsightsReportConfigExample(t *te
4949
ResourceName: "google_storage_insights_report_config.config",
5050
ImportState: true,
5151
ImportStateVerify: true,
52-
ImportStateVerifyIgnore: []string{"location"},
52+
ImportStateVerifyIgnore: []string{"force_destroy", "location"},
5353
},
5454
},
5555
})

google/services/storageinsights/resource_storage_insights_report_config_sweeper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ func deleteResourceStorageInsightsReportConfig(config *transport_tpg.Config, d *
195195
return nil
196196
}
197197

198-
deleteTemplate := "https://storageinsights.googleapis.com/v1/projects/{{project}}/locations/{{location}}/reportConfigs/{{name}}"
198+
deleteTemplate := "https://storageinsights.googleapis.com/v1/projects/{{project}}/locations/{{location}}/reportConfigs/{{name}}?force={{force_destroy}}"
199199

200200
url, err := tpgresource.ReplaceVars(d, config, deleteTemplate)
201201
if err != nil {

google/services/storageinsights/resource_storage_insights_report_config_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func TestAccStorageInsightsReportConfig_update(t *testing.T) {
5353
ResourceName: "google_storage_insights_report_config.config",
5454
ImportState: true,
5555
ImportStateVerify: true,
56-
ImportStateVerifyIgnore: []string{"location"},
56+
ImportStateVerifyIgnore: []string{"location", "force_destroy"},
5757
},
5858
},
5959
})
@@ -86,7 +86,7 @@ func TestAccStorageInsightsReportConfig_parquet(t *testing.T) {
8686
ResourceName: "google_storage_insights_report_config.config",
8787
ImportState: true,
8888
ImportStateVerify: true,
89-
ImportStateVerifyIgnore: []string{"location"},
89+
ImportStateVerifyIgnore: []string{"location", "force_destroy"},
9090
},
9191
},
9292
})
@@ -183,6 +183,7 @@ resource "google_storage_insights_report_config" "config" {
183183
depends_on = [
184184
google_storage_bucket_iam_member.admin,
185185
]
186+
force_destroy = true
186187
}
187188
188189
resource "google_storage_bucket" "report_bucket" {
@@ -291,6 +292,7 @@ resource "google_storage_insights_report_config" "config" {
291292
depends_on = [
292293
google_storage_bucket_iam_member.admin,
293294
]
295+
force_destroy = true
294296
}
295297
296298
resource "google_storage_bucket" "report_bucket" {

website/docs/r/storage_insights_report_config.html.markdown

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ The following arguments are supported:
130130
* `project` - (Optional) The ID of the project in which the resource belongs.
131131
If it is not provided, the provider project is used.
132132

133+
* `force_destroy` - (Optional) If set, all the inventory report details associated with this report configuration are deleted.
134+
133135

134136

135137
<a name="nested_frequency_options"></a>The `frequency_options` block supports:

0 commit comments

Comments
 (0)