diff --git a/.changelog/17380.txt b/.changelog/17380.txt new file mode 100644 index 00000000000..5f85f6d731d --- /dev/null +++ b/.changelog/17380.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +provider: support for a `deletion_policy` field has been added to almost all resources in the provider. Details on its usage can be found within individual resource documentation if supported. +``` \ No newline at end of file diff --git a/google-beta/acctest/test_utils.go b/google-beta/acctest/test_utils.go index 7f2ec88dfab..dd1a2f9daca 100644 --- a/google-beta/acctest/test_utils.go +++ b/google-beta/acctest/test_utils.go @@ -79,7 +79,7 @@ func CheckDataSourceStateMatchesResourceStateWithIgnores(dataSourceName, resourc continue } - if strings.HasPrefix(k, "labels.") || strings.HasPrefix(k, "terraform_labels.") || strings.HasPrefix(k, "effective_labels.") { + if strings.HasPrefix(k, "labels.") || strings.HasPrefix(k, "terraform_labels.") || strings.HasPrefix(k, "effective_labels.") || strings.HasPrefix(k, "deletion_policy") { continue } if k == "%" { diff --git a/google-beta/acctest/vcr_utils.go b/google-beta/acctest/vcr_utils.go index c9bf5b03e45..64b0858459b 100644 --- a/google-beta/acctest/vcr_utils.go +++ b/google-beta/acctest/vcr_utils.go @@ -192,6 +192,11 @@ func VcrTest(t *testing.T, c resource.TestCase) { re := regexp.MustCompile(`create_duration = "\d+[sm]"`) s.Config = re.ReplaceAllString(s.Config, `create_duration = "1s"`) } + // deletion_policy is a universal virtual attribute for managing the behavior of resources when a delete is attempted + // in Terraform. Because it is a virtual attribute, it needs to be excluded from these ImportStateVerifys. + if s.ImportStateVerify && !slices.Contains(s.ImportStateVerifyIgnore, "deletion_policy") { + s.ImportStateVerifyIgnore = append(s.ImportStateVerifyIgnore, "deletion_policy") + } steps = append(steps, s) } c.Steps = steps diff --git a/google-beta/fwmodels/provider_model.go b/google-beta/fwmodels/provider_model.go index c2053302703..99d98195595 100644 --- a/google-beta/fwmodels/provider_model.go +++ b/google-beta/fwmodels/provider_model.go @@ -47,6 +47,7 @@ type ProviderModel struct { RequestTimeout types.String `tfsdk:"request_timeout"` RequestReason types.String `tfsdk:"request_reason"` PollInterval types.String `tfsdk:"poll_interval"` + DeletionPolicy types.String `tfsdk:"deletion_policy"` UniverseDomain types.String `tfsdk:"universe_domain"` DefaultLabels types.Map `tfsdk:"default_labels"` AddTerraformAttributionLabel types.Bool `tfsdk:"add_terraform_attribution_label"` diff --git a/google-beta/fwprovider/framework_provider.go b/google-beta/fwprovider/framework_provider.go index 91dc71e9881..f14f0a331c5 100644 --- a/google-beta/fwprovider/framework_provider.go +++ b/google-beta/fwprovider/framework_provider.go @@ -166,6 +166,9 @@ func (p *FrameworkProvider) Schema(_ context.Context, _ provider.SchemaRequest, fwvalidators.NonNegativeDurationValidator(), }, }, + "deletion_policy": schema.StringAttribute{ + Optional: true, + }, "request_reason": schema.StringAttribute{ Optional: true, }, diff --git a/google-beta/provider/provider.go b/google-beta/provider/provider.go index e07c0b27aba..ab33918945a 100644 --- a/google-beta/provider/provider.go +++ b/google-beta/provider/provider.go @@ -160,6 +160,11 @@ func Provider() *schema.Provider { Optional: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + }, + "request_reason": { Type: schema.TypeString, Optional: true, @@ -297,6 +302,10 @@ func ProviderConfigure(ctx context.Context, d *schema.ResourceData, p *schema.Pr } } + if v, ok := d.GetOk("deletion_policy"); ok { + config.DeletionPolicy = v.(string) + } + if v, ok := d.GetOk("request_reason"); ok { config.RequestReason = v.(string) } diff --git a/google-beta/services/accessapproval/resource_folder_access_approval_settings.go b/google-beta/services/accessapproval/resource_folder_access_approval_settings.go index 479ff26a600..f04d71cc2a9 100644 --- a/google-beta/services/accessapproval/resource_folder_access_approval_settings.go +++ b/google-beta/services/accessapproval/resource_folder_access_approval_settings.go @@ -213,6 +213,19 @@ as key versions are inherited top-down.`, Computed: true, Description: `The resource name of the settings. Format is "folders/{folder_id}/accessApprovalSettings"`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -396,6 +409,20 @@ func resourceAccessApprovalFolderSettingsRead(d *schema.ResourceData, meta inter log.Printf("[DEBUG] Finished reading AccessApprovalFolderSettings %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceAccessApprovalFolderSettingsFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -417,6 +444,19 @@ func resourceAccessApprovalFolderSettingsRead(d *schema.ResourceData, meta inter } func resourceAccessApprovalFolderSettingsUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceAccessApprovalFolderSettings().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceAccessApprovalFolderSettingsRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -516,6 +556,13 @@ func resourceAccessApprovalFolderSettingsUpdate(d *schema.ResourceData, meta int } func resourceAccessApprovalFolderSettingsDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy AccessApprovalFolderSettings without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing FolderSettings %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/accessapproval/resource_folder_access_approval_settings_generated_meta.yaml b/google-beta/services/accessapproval/resource_folder_access_approval_settings_generated_meta.yaml index 16414ec005a..12c5f9b7f90 100644 --- a/google-beta/services/accessapproval/resource_folder_access_approval_settings_generated_meta.yaml +++ b/google-beta/services/accessapproval/resource_folder_access_approval_settings_generated_meta.yaml @@ -19,3 +19,5 @@ fields: - api_field: invalidKeyVersion - api_field: name - api_field: notificationEmails + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/accessapproval/resource_organization_access_approval_settings.go b/google-beta/services/accessapproval/resource_organization_access_approval_settings.go index 4a7e87beb32..1aa104230d1 100644 --- a/google-beta/services/accessapproval/resource_organization_access_approval_settings.go +++ b/google-beta/services/accessapproval/resource_organization_access_approval_settings.go @@ -187,6 +187,19 @@ correct permissions on it, etc.).`, Computed: true, Description: `The resource name of the settings. Format is "organizations/{organization_id}/accessApprovalSettings"`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -357,6 +370,20 @@ func resourceAccessApprovalOrganizationSettingsRead(d *schema.ResourceData, meta log.Printf("[DEBUG] Finished reading AccessApprovalOrganizationSettings %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceAccessApprovalOrganizationSettingsFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -378,6 +405,19 @@ func resourceAccessApprovalOrganizationSettingsRead(d *schema.ResourceData, meta } func resourceAccessApprovalOrganizationSettingsUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceAccessApprovalOrganizationSettings().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceAccessApprovalOrganizationSettingsRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -477,6 +517,13 @@ func resourceAccessApprovalOrganizationSettingsUpdate(d *schema.ResourceData, me } func resourceAccessApprovalOrganizationSettingsDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy AccessApprovalOrganizationSettings without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing OrganizationSettings %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/accessapproval/resource_organization_access_approval_settings_generated_meta.yaml b/google-beta/services/accessapproval/resource_organization_access_approval_settings_generated_meta.yaml index 2dbd3f19e10..3da7fed4c50 100644 --- a/google-beta/services/accessapproval/resource_organization_access_approval_settings_generated_meta.yaml +++ b/google-beta/services/accessapproval/resource_organization_access_approval_settings_generated_meta.yaml @@ -19,3 +19,5 @@ fields: - api_field: notificationEmails - field: organization_id provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/accessapproval/resource_project_access_approval_settings.go b/google-beta/services/accessapproval/resource_project_access_approval_settings.go index ecb8a43f639..e6605e8e0c0 100644 --- a/google-beta/services/accessapproval/resource_project_access_approval_settings.go +++ b/google-beta/services/accessapproval/resource_project_access_approval_settings.go @@ -195,6 +195,19 @@ as key versions are inherited top-down.`, Computed: true, Description: `The resource name of the settings. Format is "projects/{project_id}/accessApprovalSettings"`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -375,6 +388,20 @@ func resourceAccessApprovalProjectSettingsRead(d *schema.ResourceData, meta inte log.Printf("[DEBUG] Finished reading AccessApprovalProjectSettings %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceAccessApprovalProjectSettingsFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -396,6 +423,19 @@ func resourceAccessApprovalProjectSettingsRead(d *schema.ResourceData, meta inte } func resourceAccessApprovalProjectSettingsUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceAccessApprovalProjectSettings().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceAccessApprovalProjectSettingsRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -505,6 +545,13 @@ func resourceAccessApprovalProjectSettingsUpdate(d *schema.ResourceData, meta in } func resourceAccessApprovalProjectSettingsDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy AccessApprovalProjectSettings without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing ProjectSettings %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/accessapproval/resource_project_access_approval_settings_generated_meta.yaml b/google-beta/services/accessapproval/resource_project_access_approval_settings_generated_meta.yaml index f72d30415cf..7b6dbe6c3f7 100644 --- a/google-beta/services/accessapproval/resource_project_access_approval_settings_generated_meta.yaml +++ b/google-beta/services/accessapproval/resource_project_access_approval_settings_generated_meta.yaml @@ -20,3 +20,5 @@ fields: - api_field: project - field: project_id provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/accesscontextmanager/resource_access_context_manager_access_level.go b/google-beta/services/accesscontextmanager/resource_access_context_manager_access_level.go index 155b9e0728f..b7cd5514ad5 100644 --- a/google-beta/services/accesscontextmanager/resource_access_context_manager_access_level.go +++ b/google-beta/services/accesscontextmanager/resource_access_context_manager_access_level.go @@ -399,6 +399,19 @@ custom access levels - https://cloud.google.com/access-context-manager/docs/cust Optional: true, Description: `Description of the AccessLevel and its use. Does not affect behavior.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -556,6 +569,20 @@ func resourceAccessContextManagerAccessLevelRead(d *schema.ResourceData, meta in log.Printf("[DEBUG] Finished reading AccessContextManagerAccessLevel %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceAccessContextManagerAccessLevelFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -577,6 +604,19 @@ func resourceAccessContextManagerAccessLevelRead(d *schema.ResourceData, meta in } func resourceAccessContextManagerAccessLevelUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceAccessContextManagerAccessLevel().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceAccessContextManagerAccessLevelRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -701,6 +741,13 @@ func resourceAccessContextManagerAccessLevelUpdate(d *schema.ResourceData, meta } func resourceAccessContextManagerAccessLevelDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy AccessContextManagerAccessLevel without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing AccessLevel %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/accesscontextmanager/resource_access_context_manager_access_level_condition.go b/google-beta/services/accesscontextmanager/resource_access_context_manager_access_level_condition.go index f2012f6a1f7..f8d6efee4b3 100644 --- a/google-beta/services/accesscontextmanager/resource_access_context_manager_access_level_condition.go +++ b/google-beta/services/accesscontextmanager/resource_access_context_manager_access_level_condition.go @@ -100,6 +100,7 @@ func ResourceAccessContextManagerAccessLevelCondition() *schema.Resource { return &schema.Resource{ Create: resourceAccessContextManagerAccessLevelConditionCreate, Read: resourceAccessContextManagerAccessLevelConditionRead, + Update: resourceAccessContextManagerAccessLevelConditionUpdate, Delete: resourceAccessContextManagerAccessLevelConditionDelete, Timeouts: &schema.ResourceTimeout{ @@ -317,6 +318,19 @@ Format: accessPolicies/{policy_id}/accessLevels/{short_name}`, Computed: true, Description: `The name of the Access Policy this resource belongs to.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -540,6 +554,20 @@ func resourceAccessContextManagerAccessLevelConditionRead(d *schema.ResourceData return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceAccessContextManagerAccessLevelConditionFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -560,7 +588,19 @@ func resourceAccessContextManagerAccessLevelConditionRead(d *schema.ResourceData return nil } +func resourceAccessContextManagerAccessLevelConditionUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceAccessContextManagerAccessLevelConditionRead(d, meta) +} + func resourceAccessContextManagerAccessLevelConditionDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy AccessContextManagerAccessLevelCondition without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing AccessLevelCondition %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/accesscontextmanager/resource_access_context_manager_access_level_condition_generated_meta.yaml b/google-beta/services/accesscontextmanager/resource_access_context_manager_access_level_condition_generated_meta.yaml index e6f36a4156d..0a940719b19 100644 --- a/google-beta/services/accesscontextmanager/resource_access_context_manager_access_level_condition_generated_meta.yaml +++ b/google-beta/services/accesscontextmanager/resource_access_context_manager_access_level_condition_generated_meta.yaml @@ -39,3 +39,5 @@ fields: field: vpc_network_sources.vpc_subnetwork.network - api_field: basic.conditions.vpcNetworkSources.vpcSubnetwork.vpcIpSubnetworks field: vpc_network_sources.vpc_subnetwork.vpc_ip_subnetworks + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/accesscontextmanager/resource_access_context_manager_access_level_generated_meta.yaml b/google-beta/services/accesscontextmanager/resource_access_context_manager_access_level_generated_meta.yaml index 0da0bf94533..32f876f87f2 100644 --- a/google-beta/services/accesscontextmanager/resource_access_context_manager_access_level_generated_meta.yaml +++ b/google-beta/services/accesscontextmanager/resource_access_context_manager_access_level_generated_meta.yaml @@ -32,3 +32,5 @@ fields: - api_field: name - api_field: parent - api_field: title + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/accesscontextmanager/resource_access_context_manager_access_levels.go b/google-beta/services/accesscontextmanager/resource_access_context_manager_access_levels.go index 9f10620c99a..3825dd4f41d 100644 --- a/google-beta/services/accesscontextmanager/resource_access_context_manager_access_levels.go +++ b/google-beta/services/accesscontextmanager/resource_access_context_manager_access_levels.go @@ -143,6 +143,19 @@ Format: accessPolicies/{policy_id}`, Elem: accesscontextmanagerAccessLevelsAccessLevelsSchema(), // Default schema.HashSchema is used. }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -528,6 +541,20 @@ func resourceAccessContextManagerAccessLevelsRead(d *schema.ResourceData, meta i log.Printf("[DEBUG] Finished reading AccessContextManagerAccessLevels %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceAccessContextManagerAccessLevelsFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -549,6 +576,19 @@ func resourceAccessContextManagerAccessLevelsRead(d *schema.ResourceData, meta i } func resourceAccessContextManagerAccessLevelsUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceAccessContextManagerAccessLevels().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceAccessContextManagerAccessLevelsRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -624,6 +664,13 @@ func resourceAccessContextManagerAccessLevelsUpdate(d *schema.ResourceData, meta } func resourceAccessContextManagerAccessLevelsDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy AccessContextManagerAccessLevels without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing AccessLevels %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/accesscontextmanager/resource_access_context_manager_access_levels_generated_meta.yaml b/google-beta/services/accesscontextmanager/resource_access_context_manager_access_levels_generated_meta.yaml index 6b040d75e8c..cde6043e40c 100644 --- a/google-beta/services/accesscontextmanager/resource_access_context_manager_access_levels_generated_meta.yaml +++ b/google-beta/services/accesscontextmanager/resource_access_context_manager_access_levels_generated_meta.yaml @@ -32,3 +32,5 @@ fields: - api_field: accessLevels.title - field: parent provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/accesscontextmanager/resource_access_context_manager_access_policy.go b/google-beta/services/accesscontextmanager/resource_access_context_manager_access_policy.go index 7561fa87ba3..a2a8296de8c 100644 --- a/google-beta/services/accesscontextmanager/resource_access_context_manager_access_policy.go +++ b/google-beta/services/accesscontextmanager/resource_access_context_manager_access_policy.go @@ -167,6 +167,19 @@ Format: 'folders/{{folder_id}}' or 'projects/{{project_number}}'`, Computed: true, Description: `Time the AccessPolicy was updated in UTC.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -315,6 +328,20 @@ func resourceAccessContextManagerAccessPolicyRead(d *schema.ResourceData, meta i log.Printf("[DEBUG] Finished reading AccessContextManagerAccessPolicy %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceAccessContextManagerAccessPolicyFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -336,6 +363,19 @@ func resourceAccessContextManagerAccessPolicyRead(d *schema.ResourceData, meta i } func resourceAccessContextManagerAccessPolicyUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceAccessContextManagerAccessPolicy().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceAccessContextManagerAccessPolicyRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -425,6 +465,13 @@ func resourceAccessContextManagerAccessPolicyUpdate(d *schema.ResourceData, meta } func resourceAccessContextManagerAccessPolicyDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy AccessContextManagerAccessPolicy without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing AccessPolicy %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/accesscontextmanager/resource_access_context_manager_access_policy_generated_meta.yaml b/google-beta/services/accesscontextmanager/resource_access_context_manager_access_policy_generated_meta.yaml index d1c06975ff1..4f59e7f4266 100644 --- a/google-beta/services/accesscontextmanager/resource_access_context_manager_access_policy_generated_meta.yaml +++ b/google-beta/services/accesscontextmanager/resource_access_context_manager_access_policy_generated_meta.yaml @@ -15,3 +15,5 @@ fields: - api_field: scopes - api_field: title - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/accesscontextmanager/resource_access_context_manager_authorized_orgs_desc.go b/google-beta/services/accesscontextmanager/resource_access_context_manager_authorized_orgs_desc.go index a1e9116ccca..2fa76454f6c 100644 --- a/google-beta/services/accesscontextmanager/resource_access_context_manager_authorized_orgs_desc.go +++ b/google-beta/services/accesscontextmanager/resource_access_context_manager_authorized_orgs_desc.go @@ -204,6 +204,19 @@ Example: 'organizations/123456'`, Computed: true, Description: `Time the AuthorizedOrgsDesc was updated in UTC.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -366,6 +379,20 @@ func resourceAccessContextManagerAuthorizedOrgsDescRead(d *schema.ResourceData, log.Printf("[DEBUG] Finished reading AccessContextManagerAuthorizedOrgsDesc %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceAccessContextManagerAuthorizedOrgsDescFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -387,6 +414,19 @@ func resourceAccessContextManagerAuthorizedOrgsDescRead(d *schema.ResourceData, } func resourceAccessContextManagerAuthorizedOrgsDescUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceAccessContextManagerAuthorizedOrgsDesc().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceAccessContextManagerAuthorizedOrgsDescRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -478,6 +518,13 @@ func resourceAccessContextManagerAuthorizedOrgsDescUpdate(d *schema.ResourceData } func resourceAccessContextManagerAuthorizedOrgsDescDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy AccessContextManagerAuthorizedOrgsDesc without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing AuthorizedOrgsDesc %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/accesscontextmanager/resource_access_context_manager_authorized_orgs_desc_generated_meta.yaml b/google-beta/services/accesscontextmanager/resource_access_context_manager_authorized_orgs_desc_generated_meta.yaml index 365e7a70b99..ac6f7e5e7f0 100644 --- a/google-beta/services/accesscontextmanager/resource_access_context_manager_authorized_orgs_desc_generated_meta.yaml +++ b/google-beta/services/accesscontextmanager/resource_access_context_manager_authorized_orgs_desc_generated_meta.yaml @@ -15,3 +15,5 @@ fields: - api_field: orgs - api_field: parent - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/accesscontextmanager/resource_access_context_manager_egress_policy.go b/google-beta/services/accesscontextmanager/resource_access_context_manager_egress_policy.go index 258ba178015..d17114f88eb 100644 --- a/google-beta/services/accesscontextmanager/resource_access_context_manager_egress_policy.go +++ b/google-beta/services/accesscontextmanager/resource_access_context_manager_egress_policy.go @@ -100,6 +100,7 @@ func ResourceAccessContextManagerEgressPolicy() *schema.Resource { return &schema.Resource{ Create: resourceAccessContextManagerEgressPolicyCreate, Read: resourceAccessContextManagerEgressPolicyRead, + Update: resourceAccessContextManagerEgressPolicyUpdate, Delete: resourceAccessContextManagerEgressPolicyDelete, Importer: &schema.ResourceImporter{ @@ -149,6 +150,19 @@ func ResourceAccessContextManagerEgressPolicy() *schema.Resource { Computed: true, Description: `The name of the Access Policy this resource belongs to.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -302,6 +316,20 @@ func resourceAccessContextManagerEgressPolicyRead(d *schema.ResourceData, meta i return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceAccessContextManagerEgressPolicyFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -328,7 +356,19 @@ func resourceAccessContextManagerEgressPolicyRead(d *schema.ResourceData, meta i return nil } +func resourceAccessContextManagerEgressPolicyUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceAccessContextManagerEgressPolicyRead(d, meta) +} + func resourceAccessContextManagerEgressPolicyDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy AccessContextManagerEgressPolicy without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing EgressPolicy %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/accesscontextmanager/resource_access_context_manager_egress_policy_generated_meta.yaml b/google-beta/services/accesscontextmanager/resource_access_context_manager_egress_policy_generated_meta.yaml index d967eb69d15..4a9053a8e98 100644 --- a/google-beta/services/accesscontextmanager/resource_access_context_manager_egress_policy_generated_meta.yaml +++ b/google-beta/services/accesscontextmanager/resource_access_context_manager_egress_policy_generated_meta.yaml @@ -13,3 +13,5 @@ fields: provider_only: true - api_field: status.resources.resource field: resource + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/accesscontextmanager/resource_access_context_manager_gcp_user_access_binding.go b/google-beta/services/accesscontextmanager/resource_access_context_manager_gcp_user_access_binding.go index c358f49cc35..28fbbc24fe2 100644 --- a/google-beta/services/accesscontextmanager/resource_access_context_manager_gcp_user_access_binding.go +++ b/google-beta/services/accesscontextmanager/resource_access_context_manager_gcp_user_access_binding.go @@ -315,6 +315,19 @@ func ResourceAccessContextManagerGcpUserAccessBinding() *schema.Resource { Computed: true, Description: `Immutable. Assigned by the server during creation. The last segment has an arbitrary length and has only URI unreserved characters (as defined by RFC 3986 Section 2.3). Should not be specified by the client during creation. Example: "organizations/256/gcpUserAccessBindings/b3-BhcX_Ud5N"`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -462,6 +475,20 @@ func resourceAccessContextManagerGcpUserAccessBindingRead(d *schema.ResourceData log.Printf("[DEBUG] Finished reading AccessContextManagerGcpUserAccessBinding %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceAccessContextManagerGcpUserAccessBindingFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -483,6 +510,19 @@ func resourceAccessContextManagerGcpUserAccessBindingRead(d *schema.ResourceData } func resourceAccessContextManagerGcpUserAccessBindingUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceAccessContextManagerGcpUserAccessBinding().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceAccessContextManagerGcpUserAccessBindingRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -585,6 +625,13 @@ func resourceAccessContextManagerGcpUserAccessBindingUpdate(d *schema.ResourceDa } func resourceAccessContextManagerGcpUserAccessBindingDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy AccessContextManagerGcpUserAccessBinding without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing GcpUserAccessBinding %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/accesscontextmanager/resource_access_context_manager_gcp_user_access_binding_generated_meta.yaml b/google-beta/services/accesscontextmanager/resource_access_context_manager_gcp_user_access_binding_generated_meta.yaml index 53d86f661c5..f92560bd865 100644 --- a/google-beta/services/accesscontextmanager/resource_access_context_manager_gcp_user_access_binding_generated_meta.yaml +++ b/google-beta/services/accesscontextmanager/resource_access_context_manager_gcp_user_access_binding_generated_meta.yaml @@ -26,3 +26,5 @@ fields: - api_field: sessionSettings.sessionLengthEnabled - api_field: sessionSettings.sessionReauthMethod - api_field: sessionSettings.useOidcMaxAge + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/accesscontextmanager/resource_access_context_manager_ingress_policy.go b/google-beta/services/accesscontextmanager/resource_access_context_manager_ingress_policy.go index b8ee43ee202..8f7678cafbb 100644 --- a/google-beta/services/accesscontextmanager/resource_access_context_manager_ingress_policy.go +++ b/google-beta/services/accesscontextmanager/resource_access_context_manager_ingress_policy.go @@ -100,6 +100,7 @@ func ResourceAccessContextManagerIngressPolicy() *schema.Resource { return &schema.Resource{ Create: resourceAccessContextManagerIngressPolicyCreate, Read: resourceAccessContextManagerIngressPolicyRead, + Update: resourceAccessContextManagerIngressPolicyUpdate, Delete: resourceAccessContextManagerIngressPolicyDelete, Importer: &schema.ResourceImporter{ @@ -149,6 +150,19 @@ func ResourceAccessContextManagerIngressPolicy() *schema.Resource { Computed: true, Description: `The name of the Access Policy this resource belongs to.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -302,6 +316,20 @@ func resourceAccessContextManagerIngressPolicyRead(d *schema.ResourceData, meta return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceAccessContextManagerIngressPolicyFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -328,7 +356,19 @@ func resourceAccessContextManagerIngressPolicyRead(d *schema.ResourceData, meta return nil } +func resourceAccessContextManagerIngressPolicyUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceAccessContextManagerIngressPolicyRead(d, meta) +} + func resourceAccessContextManagerIngressPolicyDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy AccessContextManagerIngressPolicy without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing IngressPolicy %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/accesscontextmanager/resource_access_context_manager_ingress_policy_generated_meta.yaml b/google-beta/services/accesscontextmanager/resource_access_context_manager_ingress_policy_generated_meta.yaml index ada397b4481..59c56e6572a 100644 --- a/google-beta/services/accesscontextmanager/resource_access_context_manager_ingress_policy_generated_meta.yaml +++ b/google-beta/services/accesscontextmanager/resource_access_context_manager_ingress_policy_generated_meta.yaml @@ -13,3 +13,5 @@ fields: provider_only: true - api_field: status.resources.resource field: resource + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/accesscontextmanager/resource_access_context_manager_service_perimeter.go b/google-beta/services/accesscontextmanager/resource_access_context_manager_service_perimeter.go index 3df42059070..8e5c03e35c7 100644 --- a/google-beta/services/accesscontextmanager/resource_access_context_manager_service_perimeter.go +++ b/google-beta/services/accesscontextmanager/resource_access_context_manager_service_perimeter.go @@ -1133,6 +1133,19 @@ bet set to True if any of the fields in the spec are set to non-default values.` Computed: true, Description: `Time the AccessPolicy was updated in UTC.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -1302,6 +1315,20 @@ func resourceAccessContextManagerServicePerimeterRead(d *schema.ResourceData, me log.Printf("[DEBUG] Finished reading AccessContextManagerServicePerimeter %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceAccessContextManagerServicePerimeterFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -1323,6 +1350,19 @@ func resourceAccessContextManagerServicePerimeterRead(d *schema.ResourceData, me } func resourceAccessContextManagerServicePerimeterUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceAccessContextManagerServicePerimeter().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceAccessContextManagerServicePerimeterRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1457,6 +1497,13 @@ func resourceAccessContextManagerServicePerimeterUpdate(d *schema.ResourceData, } func resourceAccessContextManagerServicePerimeterDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy AccessContextManagerServicePerimeter without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing ServicePerimeter %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/accesscontextmanager/resource_access_context_manager_service_perimeter_dry_run_egress_policy.go b/google-beta/services/accesscontextmanager/resource_access_context_manager_service_perimeter_dry_run_egress_policy.go index ba4a9293e0a..e711d39e00c 100644 --- a/google-beta/services/accesscontextmanager/resource_access_context_manager_service_perimeter_dry_run_egress_policy.go +++ b/google-beta/services/accesscontextmanager/resource_access_context_manager_service_perimeter_dry_run_egress_policy.go @@ -212,6 +212,7 @@ func ResourceAccessContextManagerServicePerimeterDryRunEgressPolicy() *schema.Re return &schema.Resource{ Create: resourceAccessContextManagerServicePerimeterDryRunEgressPolicyCreate, Read: resourceAccessContextManagerServicePerimeterDryRunEgressPolicyRead, + Update: resourceAccessContextManagerServicePerimeterDryRunEgressPolicyUpdate, Delete: resourceAccessContextManagerServicePerimeterDryRunEgressPolicyDelete, Timeouts: &schema.ResourceTimeout{ @@ -422,6 +423,19 @@ are allowed to perform.`, Computed: true, Description: `The perimeter etag is internally used to prevent overwriting the list of policies on PATCH calls. It is retrieved from the same GET perimeter API call that's used to get the current list of policies. The policy defined in this resource is added or removed from that list, and then this etag is sent with the PATCH call along with the updated policies.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -602,6 +616,20 @@ func resourceAccessContextManagerServicePerimeterDryRunEgressPolicyRead(d *schem return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceAccessContextManagerServicePerimeterDryRunEgressPolicyFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -622,7 +650,19 @@ func resourceAccessContextManagerServicePerimeterDryRunEgressPolicyRead(d *schem return nil } +func resourceAccessContextManagerServicePerimeterDryRunEgressPolicyUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceAccessContextManagerServicePerimeterDryRunEgressPolicyRead(d, meta) +} + func resourceAccessContextManagerServicePerimeterDryRunEgressPolicyDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy AccessContextManagerServicePerimeterDryRunEgressPolicy without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing ServicePerimeterDryRunEgressPolicy %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/accesscontextmanager/resource_access_context_manager_service_perimeter_dry_run_egress_policy_generated_meta.yaml b/google-beta/services/accesscontextmanager/resource_access_context_manager_service_perimeter_dry_run_egress_policy_generated_meta.yaml index 89a61408ad5..68198856480 100644 --- a/google-beta/services/accesscontextmanager/resource_access_context_manager_service_perimeter_dry_run_egress_policy_generated_meta.yaml +++ b/google-beta/services/accesscontextmanager/resource_access_context_manager_service_perimeter_dry_run_egress_policy_generated_meta.yaml @@ -37,3 +37,5 @@ fields: provider_only: true - api_field: spec.egressPolicies.title field: title + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/accesscontextmanager/resource_access_context_manager_service_perimeter_dry_run_ingress_policy.go b/google-beta/services/accesscontextmanager/resource_access_context_manager_service_perimeter_dry_run_ingress_policy.go index 6d8c8e71d5e..c8e68689c69 100644 --- a/google-beta/services/accesscontextmanager/resource_access_context_manager_service_perimeter_dry_run_ingress_policy.go +++ b/google-beta/services/accesscontextmanager/resource_access_context_manager_service_perimeter_dry_run_ingress_policy.go @@ -212,6 +212,7 @@ func ResourceAccessContextManagerServicePerimeterDryRunIngressPolicy() *schema.R return &schema.Resource{ Create: resourceAccessContextManagerServicePerimeterDryRunIngressPolicyCreate, Read: resourceAccessContextManagerServicePerimeterDryRunIngressPolicyRead, + Update: resourceAccessContextManagerServicePerimeterDryRunIngressPolicyUpdate, Delete: resourceAccessContextManagerServicePerimeterDryRunIngressPolicyDelete, Timeouts: &schema.ResourceTimeout{ @@ -415,6 +416,19 @@ are allowed to perform.`, Computed: true, Description: `The perimeter etag is internally used to prevent overwriting the list of policies on PATCH calls. It is retrieved from the same GET perimeter API call that's used to get the current list of policies. The policy defined in this resource is added or removed from that list, and then this etag is sent with the PATCH call along with the updated policies.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -595,6 +609,20 @@ func resourceAccessContextManagerServicePerimeterDryRunIngressPolicyRead(d *sche return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceAccessContextManagerServicePerimeterDryRunIngressPolicyFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -615,7 +643,19 @@ func resourceAccessContextManagerServicePerimeterDryRunIngressPolicyRead(d *sche return nil } +func resourceAccessContextManagerServicePerimeterDryRunIngressPolicyUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceAccessContextManagerServicePerimeterDryRunIngressPolicyRead(d, meta) +} + func resourceAccessContextManagerServicePerimeterDryRunIngressPolicyDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy AccessContextManagerServicePerimeterDryRunIngressPolicy without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing ServicePerimeterDryRunIngressPolicy %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/accesscontextmanager/resource_access_context_manager_service_perimeter_dry_run_ingress_policy_generated_meta.yaml b/google-beta/services/accesscontextmanager/resource_access_context_manager_service_perimeter_dry_run_ingress_policy_generated_meta.yaml index 203bc1ee726..33fcae72e0c 100644 --- a/google-beta/services/accesscontextmanager/resource_access_context_manager_service_perimeter_dry_run_ingress_policy_generated_meta.yaml +++ b/google-beta/services/accesscontextmanager/resource_access_context_manager_service_perimeter_dry_run_ingress_policy_generated_meta.yaml @@ -33,3 +33,5 @@ fields: provider_only: true - api_field: spec.ingressPolicies.title field: title + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/accesscontextmanager/resource_access_context_manager_service_perimeter_dry_run_resource.go b/google-beta/services/accesscontextmanager/resource_access_context_manager_service_perimeter_dry_run_resource.go index 32c4596574d..4f314d536b7 100644 --- a/google-beta/services/accesscontextmanager/resource_access_context_manager_service_perimeter_dry_run_resource.go +++ b/google-beta/services/accesscontextmanager/resource_access_context_manager_service_perimeter_dry_run_resource.go @@ -100,6 +100,7 @@ func ResourceAccessContextManagerServicePerimeterDryRunResource() *schema.Resour return &schema.Resource{ Create: resourceAccessContextManagerServicePerimeterDryRunResourceCreate, Read: resourceAccessContextManagerServicePerimeterDryRunResourceRead, + Update: resourceAccessContextManagerServicePerimeterDryRunResourceUpdate, Delete: resourceAccessContextManagerServicePerimeterDryRunResourceDelete, Importer: &schema.ResourceImporter{ @@ -156,6 +157,19 @@ Format: projects/{project_number}`, Computed: true, Description: `The perimeter etag is internally used to prevent overwriting the list of perimeter resources on PATCH calls. It is retrieved from the same GET perimeter API call that's used to get the current list of resources. The resource to add or remove is merged into that list and then this etag is sent with the PATCH call along with the updated resource list.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -329,6 +343,20 @@ func resourceAccessContextManagerServicePerimeterDryRunResourceRead(d *schema.Re return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceAccessContextManagerServicePerimeterDryRunResourceFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -355,7 +383,19 @@ func resourceAccessContextManagerServicePerimeterDryRunResourceRead(d *schema.Re return nil } +func resourceAccessContextManagerServicePerimeterDryRunResourceUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceAccessContextManagerServicePerimeterDryRunResourceRead(d, meta) +} + func resourceAccessContextManagerServicePerimeterDryRunResourceDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy AccessContextManagerServicePerimeterDryRunResource without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing ServicePerimeterDryRunResource %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/accesscontextmanager/resource_access_context_manager_service_perimeter_dry_run_resource_generated_meta.yaml b/google-beta/services/accesscontextmanager/resource_access_context_manager_service_perimeter_dry_run_resource_generated_meta.yaml index c2f5318a6d9..970f2dfb697 100644 --- a/google-beta/services/accesscontextmanager/resource_access_context_manager_service_perimeter_dry_run_resource_generated_meta.yaml +++ b/google-beta/services/accesscontextmanager/resource_access_context_manager_service_perimeter_dry_run_resource_generated_meta.yaml @@ -15,3 +15,5 @@ fields: provider_only: true - api_field: spec.resources.resource field: resource + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/accesscontextmanager/resource_access_context_manager_service_perimeter_egress_policy.go b/google-beta/services/accesscontextmanager/resource_access_context_manager_service_perimeter_egress_policy.go index 8d0b14e4470..c096544a7cd 100644 --- a/google-beta/services/accesscontextmanager/resource_access_context_manager_service_perimeter_egress_policy.go +++ b/google-beta/services/accesscontextmanager/resource_access_context_manager_service_perimeter_egress_policy.go @@ -212,6 +212,7 @@ func ResourceAccessContextManagerServicePerimeterEgressPolicy() *schema.Resource return &schema.Resource{ Create: resourceAccessContextManagerServicePerimeterEgressPolicyCreate, Read: resourceAccessContextManagerServicePerimeterEgressPolicyRead, + Update: resourceAccessContextManagerServicePerimeterEgressPolicyUpdate, Delete: resourceAccessContextManagerServicePerimeterEgressPolicyDelete, Timeouts: &schema.ResourceTimeout{ @@ -422,6 +423,19 @@ are allowed to perform.`, Computed: true, Description: `The perimeter etag is internally used to prevent overwriting the list of policies on PATCH calls. It is retrieved from the same GET perimeter API call that's used to get the current list of policies. The policy defined in this resource is added or removed from that list, and then this etag is sent with the PATCH call along with the updated policies.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -600,6 +614,20 @@ func resourceAccessContextManagerServicePerimeterEgressPolicyRead(d *schema.Reso return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceAccessContextManagerServicePerimeterEgressPolicyFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -620,7 +648,19 @@ func resourceAccessContextManagerServicePerimeterEgressPolicyRead(d *schema.Reso return nil } +func resourceAccessContextManagerServicePerimeterEgressPolicyUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceAccessContextManagerServicePerimeterEgressPolicyRead(d, meta) +} + func resourceAccessContextManagerServicePerimeterEgressPolicyDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy AccessContextManagerServicePerimeterEgressPolicy without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing ServicePerimeterEgressPolicy %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/accesscontextmanager/resource_access_context_manager_service_perimeter_egress_policy_generated_meta.yaml b/google-beta/services/accesscontextmanager/resource_access_context_manager_service_perimeter_egress_policy_generated_meta.yaml index ecd1eb341bc..79e852c5b70 100644 --- a/google-beta/services/accesscontextmanager/resource_access_context_manager_service_perimeter_egress_policy_generated_meta.yaml +++ b/google-beta/services/accesscontextmanager/resource_access_context_manager_service_perimeter_egress_policy_generated_meta.yaml @@ -37,3 +37,5 @@ fields: provider_only: true - api_field: status.egressPolicies.title field: title + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/accesscontextmanager/resource_access_context_manager_service_perimeter_generated_meta.yaml b/google-beta/services/accesscontextmanager/resource_access_context_manager_service_perimeter_generated_meta.yaml index 50465e67f21..237b4a6c9db 100644 --- a/google-beta/services/accesscontextmanager/resource_access_context_manager_service_perimeter_generated_meta.yaml +++ b/google-beta/services/accesscontextmanager/resource_access_context_manager_service_perimeter_generated_meta.yaml @@ -69,3 +69,5 @@ fields: - api_field: title - api_field: updateTime - api_field: useExplicitDryRunSpec + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/accesscontextmanager/resource_access_context_manager_service_perimeter_ingress_policy.go b/google-beta/services/accesscontextmanager/resource_access_context_manager_service_perimeter_ingress_policy.go index f33dd4ad0a5..c5ce6dd22e2 100644 --- a/google-beta/services/accesscontextmanager/resource_access_context_manager_service_perimeter_ingress_policy.go +++ b/google-beta/services/accesscontextmanager/resource_access_context_manager_service_perimeter_ingress_policy.go @@ -212,6 +212,7 @@ func ResourceAccessContextManagerServicePerimeterIngressPolicy() *schema.Resourc return &schema.Resource{ Create: resourceAccessContextManagerServicePerimeterIngressPolicyCreate, Read: resourceAccessContextManagerServicePerimeterIngressPolicyRead, + Update: resourceAccessContextManagerServicePerimeterIngressPolicyUpdate, Delete: resourceAccessContextManagerServicePerimeterIngressPolicyDelete, Timeouts: &schema.ResourceTimeout{ @@ -418,6 +419,19 @@ are allowed to perform.`, Computed: true, Description: `The perimeter etag is internally used to prevent overwriting the list of policies on PATCH calls. It is retrieved from the same GET perimeter API call that's used to get the current list of policies. The policy defined in this resource is added or removed from that list, and then this etag is sent with the PATCH call along with the updated policies.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -596,6 +610,20 @@ func resourceAccessContextManagerServicePerimeterIngressPolicyRead(d *schema.Res return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceAccessContextManagerServicePerimeterIngressPolicyFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -616,7 +644,19 @@ func resourceAccessContextManagerServicePerimeterIngressPolicyRead(d *schema.Res return nil } +func resourceAccessContextManagerServicePerimeterIngressPolicyUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceAccessContextManagerServicePerimeterIngressPolicyRead(d, meta) +} + func resourceAccessContextManagerServicePerimeterIngressPolicyDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy AccessContextManagerServicePerimeterIngressPolicy without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing ServicePerimeterIngressPolicy %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/accesscontextmanager/resource_access_context_manager_service_perimeter_ingress_policy_generated_meta.yaml b/google-beta/services/accesscontextmanager/resource_access_context_manager_service_perimeter_ingress_policy_generated_meta.yaml index 93b35a4779d..e87020f0e80 100644 --- a/google-beta/services/accesscontextmanager/resource_access_context_manager_service_perimeter_ingress_policy_generated_meta.yaml +++ b/google-beta/services/accesscontextmanager/resource_access_context_manager_service_perimeter_ingress_policy_generated_meta.yaml @@ -33,3 +33,5 @@ fields: provider_only: true - api_field: status.ingressPolicies.title field: title + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/accesscontextmanager/resource_access_context_manager_service_perimeter_resource.go b/google-beta/services/accesscontextmanager/resource_access_context_manager_service_perimeter_resource.go index b43269b5a0e..595cbb9473c 100644 --- a/google-beta/services/accesscontextmanager/resource_access_context_manager_service_perimeter_resource.go +++ b/google-beta/services/accesscontextmanager/resource_access_context_manager_service_perimeter_resource.go @@ -100,6 +100,7 @@ func ResourceAccessContextManagerServicePerimeterResource() *schema.Resource { return &schema.Resource{ Create: resourceAccessContextManagerServicePerimeterResourceCreate, Read: resourceAccessContextManagerServicePerimeterResourceRead, + Update: resourceAccessContextManagerServicePerimeterResourceUpdate, Delete: resourceAccessContextManagerServicePerimeterResourceDelete, Importer: &schema.ResourceImporter{ @@ -156,6 +157,19 @@ Format: projects/{project_number}`, Computed: true, Description: `The perimeter etag is internally used to prevent overwriting the list of perimeter resources on PATCH calls. It is retrieved from the same GET perimeter API call that's used to get the current list of resources. The resource to add or remove is merged into that list and then this etag is sent with the PATCH call along with the updated resource list.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -327,6 +341,20 @@ func resourceAccessContextManagerServicePerimeterResourceRead(d *schema.Resource return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceAccessContextManagerServicePerimeterResourceFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -353,7 +381,19 @@ func resourceAccessContextManagerServicePerimeterResourceRead(d *schema.Resource return nil } +func resourceAccessContextManagerServicePerimeterResourceUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceAccessContextManagerServicePerimeterResourceRead(d, meta) +} + func resourceAccessContextManagerServicePerimeterResourceDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy AccessContextManagerServicePerimeterResource without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing ServicePerimeterResource %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/accesscontextmanager/resource_access_context_manager_service_perimeter_resource_generated_meta.yaml b/google-beta/services/accesscontextmanager/resource_access_context_manager_service_perimeter_resource_generated_meta.yaml index 35fd6354bc6..99aa7b392be 100644 --- a/google-beta/services/accesscontextmanager/resource_access_context_manager_service_perimeter_resource_generated_meta.yaml +++ b/google-beta/services/accesscontextmanager/resource_access_context_manager_service_perimeter_resource_generated_meta.yaml @@ -15,3 +15,5 @@ fields: provider_only: true - api_field: status.resources.resource field: resource + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/accesscontextmanager/resource_access_context_manager_service_perimeters.go b/google-beta/services/accesscontextmanager/resource_access_context_manager_service_perimeters.go index 90adc7a6357..101abe8245c 100644 --- a/google-beta/services/accesscontextmanager/resource_access_context_manager_service_perimeters.go +++ b/google-beta/services/accesscontextmanager/resource_access_context_manager_service_perimeters.go @@ -871,6 +871,19 @@ bet set to True if any of the fields in the spec are set to non-default values.` }, }, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -1152,6 +1165,20 @@ func resourceAccessContextManagerServicePerimetersRead(d *schema.ResourceData, m log.Printf("[DEBUG] Finished reading AccessContextManagerServicePerimeters %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceAccessContextManagerServicePerimetersFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -1173,6 +1200,19 @@ func resourceAccessContextManagerServicePerimetersRead(d *schema.ResourceData, m } func resourceAccessContextManagerServicePerimetersUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceAccessContextManagerServicePerimeters().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceAccessContextManagerServicePerimetersRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1254,6 +1294,13 @@ func resourceAccessContextManagerServicePerimetersUpdate(d *schema.ResourceData, } func resourceAccessContextManagerServicePerimetersDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy AccessContextManagerServicePerimeters without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing ServicePerimeters %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/accesscontextmanager/resource_access_context_manager_service_perimeters_generated_meta.yaml b/google-beta/services/accesscontextmanager/resource_access_context_manager_service_perimeters_generated_meta.yaml index 7ee1a2ee46b..1bc03f6c03e 100644 --- a/google-beta/services/accesscontextmanager/resource_access_context_manager_service_perimeters_generated_meta.yaml +++ b/google-beta/services/accesscontextmanager/resource_access_context_manager_service_perimeters_generated_meta.yaml @@ -69,3 +69,5 @@ fields: - api_field: servicePerimeters.title - api_field: servicePerimeters.updateTime - api_field: servicePerimeters.useExplicitDryRunSpec + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/activedirectory/resource_active_directory_domain.go b/google-beta/services/activedirectory/resource_active_directory_domain.go index f943b153cc5..ac345c3540d 100644 --- a/google-beta/services/activedirectory/resource_active_directory_domain.go +++ b/google-beta/services/activedirectory/resource_active_directory_domain.go @@ -116,6 +116,7 @@ func ResourceActiveDirectoryDomain() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -230,6 +231,18 @@ When the field is set to false, deleting the domain is allowed.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -408,6 +421,18 @@ func resourceActiveDirectoryDomainRead(d *schema.ResourceData, meta interface{}) return fmt.Errorf("Error setting deletion_protection: %s", err) } } + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Domain: %s", err) } @@ -439,6 +464,19 @@ func resourceActiveDirectoryDomainRead(d *schema.ResourceData, meta interface{}) } func resourceActiveDirectoryDomainUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceActiveDirectoryDomain().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceActiveDirectoryDomainRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -553,6 +591,13 @@ func resourceActiveDirectoryDomainUpdate(d *schema.ResourceData, meta interface{ } func resourceActiveDirectoryDomainDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ActiveDirectoryDomain without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Domain %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/activedirectory/resource_active_directory_domain_generated_meta.yaml b/google-beta/services/activedirectory/resource_active_directory_domain_generated_meta.yaml index a83fff7ab1b..b4fbf23fc1c 100644 --- a/google-beta/services/activedirectory/resource_active_directory_domain_generated_meta.yaml +++ b/google-beta/services/activedirectory/resource_active_directory_domain_generated_meta.yaml @@ -22,3 +22,5 @@ fields: - api_field: reservedIpRange - field: terraform_labels provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/activedirectory/resource_active_directory_domain_trust.go b/google-beta/services/activedirectory/resource_active_directory_domain_trust.go index 00192a61063..0a02e55f330 100644 --- a/google-beta/services/activedirectory/resource_active_directory_domain_trust.go +++ b/google-beta/services/activedirectory/resource_active_directory_domain_trust.go @@ -115,6 +115,7 @@ func ResourceActiveDirectoryDomainTrust() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -195,6 +196,18 @@ of https://cloud.google.com/managed-microsoft-ad/reference/rest/v1/projects.loca Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -391,6 +404,19 @@ func resourceActiveDirectoryDomainTrustRead(d *schema.ResourceData, meta interfa return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading DomainTrust: %s", err) } @@ -428,6 +454,19 @@ func resourceActiveDirectoryDomainTrustRead(d *schema.ResourceData, meta interfa } func resourceActiveDirectoryDomainTrustUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceActiveDirectoryDomainTrust().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceActiveDirectoryDomainTrustRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -547,6 +586,13 @@ func resourceActiveDirectoryDomainTrustUpdate(d *schema.ResourceData, meta inter } func resourceActiveDirectoryDomainTrustDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ActiveDirectoryDomainTrust without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing DomainTrust %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/activedirectory/resource_active_directory_domain_trust_generated_meta.yaml b/google-beta/services/activedirectory/resource_active_directory_domain_trust_generated_meta.yaml index 7839feb57b7..835af71f6a6 100644 --- a/google-beta/services/activedirectory/resource_active_directory_domain_trust_generated_meta.yaml +++ b/google-beta/services/activedirectory/resource_active_directory_domain_trust_generated_meta.yaml @@ -21,3 +21,5 @@ fields: field: trust_handshake_secret - api_field: trusts.trustType field: trust_type + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/activedirectory/resource_active_directory_peering.go b/google-beta/services/activedirectory/resource_active_directory_peering.go index 20e8f50351e..0076b8e91f0 100644 --- a/google-beta/services/activedirectory/resource_active_directory_peering.go +++ b/google-beta/services/activedirectory/resource_active_directory_peering.go @@ -112,6 +112,7 @@ func ResourceActiveDirectoryPeering() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -195,6 +196,18 @@ Please refer to the field 'effective_labels' for all of the labels present on th Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -359,6 +372,19 @@ func resourceActiveDirectoryPeeringRead(d *schema.ResourceData, meta interface{} log.Printf("[DEBUG] Finished reading ActiveDirectoryPeering %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Peering: %s", err) } @@ -390,6 +416,19 @@ func resourceActiveDirectoryPeeringRead(d *schema.ResourceData, meta interface{} } func resourceActiveDirectoryPeeringUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceActiveDirectoryPeering().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceActiveDirectoryPeeringRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -475,6 +514,13 @@ func resourceActiveDirectoryPeeringUpdate(d *schema.ResourceData, meta interface } func resourceActiveDirectoryPeeringDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ActiveDirectoryPeering without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Peering %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/activedirectory/resource_active_directory_peering_generated_meta.yaml b/google-beta/services/activedirectory/resource_active_directory_peering_generated_meta.yaml index 0cdeb64304b..7e04831f6ce 100644 --- a/google-beta/services/activedirectory/resource_active_directory_peering_generated_meta.yaml +++ b/google-beta/services/activedirectory/resource_active_directory_peering_generated_meta.yaml @@ -20,3 +20,5 @@ fields: - api_field: statusMessage - field: terraform_labels provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/alloydb/resource_alloydb_backup.go b/google-beta/services/alloydb/resource_alloydb_backup.go index 5bd54353189..d7e7256b160 100644 --- a/google-beta/services/alloydb/resource_alloydb_backup.go +++ b/google-beta/services/alloydb/resource_alloydb_backup.go @@ -117,6 +117,7 @@ func ResourceAlloydbBackup() *schema.Resource { tpgresource.SetLabelsDiff, tpgresource.SetAnnotationsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -343,6 +344,18 @@ Examples: "2014-10-02T15:01:23Z" and "2014-10-02T15:01:23.045123456Z".`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -521,6 +534,19 @@ func resourceAlloydbBackupRead(d *schema.ResourceData, meta interface{}) error { log.Printf("[DEBUG] Finished reading AlloydbBackup %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Backup: %s", err) } @@ -558,6 +584,19 @@ func resourceAlloydbBackupRead(d *schema.ResourceData, meta interface{}) error { } func resourceAlloydbBackupUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceAlloydbBackup().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceAlloydbBackupRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -711,6 +750,13 @@ func resourceAlloydbBackupUpdate(d *schema.ResourceData, meta interface{}) error } func resourceAlloydbBackupDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy AlloydbBackup without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Backup %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/alloydb/resource_alloydb_backup_generated_meta.yaml b/google-beta/services/alloydb/resource_alloydb_backup_generated_meta.yaml index 8a8e8be8474..a7058a7b2ca 100644 --- a/google-beta/services/alloydb/resource_alloydb_backup_generated_meta.yaml +++ b/google-beta/services/alloydb/resource_alloydb_backup_generated_meta.yaml @@ -39,3 +39,5 @@ fields: - api_field: type - api_field: uid - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/alloydb/resource_alloydb_cluster.go b/google-beta/services/alloydb/resource_alloydb_cluster.go index 46cd2823b15..4fbdeb0ee35 100644 --- a/google-beta/services/alloydb/resource_alloydb_cluster.go +++ b/google-beta/services/alloydb/resource_alloydb_cluster.go @@ -117,6 +117,7 @@ func ResourceAlloydbCluster() *schema.Resource { tpgresource.SetLabelsDiff, tpgresource.SetAnnotationsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DEFAULT"), ), Identity: &schema.ResourceIdentity{ @@ -850,15 +851,6 @@ This can happen due to user-triggered updates or system actions like failover or Computed: true, Description: `The system-generated UID of the resource.`, }, - "deletion_policy": { - Type: schema.TypeString, - Optional: true, - Description: `Policy to determine if the cluster should be deleted forcefully. -Deleting a cluster forcefully, deletes the cluster and all its associated instances within the cluster. -Deleting a Secondary cluster with a secondary instance REQUIRES setting deletion_policy = "FORCE" otherwise an error is returned. This is needed as there is no support to delete just the secondary instance, and the only way to delete secondary instance is to delete the associated secondary cluster forcefully which also deletes the secondary instance. -Possible values: DEFAULT, FORCE`, - Default: "DEFAULT", - }, "deletion_protection": { Type: schema.TypeBool, Optional: true, @@ -882,6 +874,12 @@ Default value: "true"`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `This field uses a custom implementation please refer to documentation under /hashicorp/terraform-provider-google-beta/website/docs/r/alloydb_cluster.html.markdown for specifics`, + }, }, UseJSONNumber: true, } @@ -1221,11 +1219,6 @@ func resourceAlloydbClusterRead(d *schema.ResourceData, meta interface{}) error log.Printf("[DEBUG] Finished reading AlloydbCluster %q: %#v", d.Id(), res) // Explicitly set virtual fields to default values if unset - if _, ok := d.GetOkExists("deletion_policy"); !ok { - if err := d.Set("deletion_policy", "DEFAULT"); err != nil { - return fmt.Errorf("Error setting deletion_policy: %s", err) - } - } if _, ok := d.GetOkExists("deletion_protection"); !ok { if err := d.Set("deletion_protection", true); err != nil { return fmt.Errorf("Error setting deletion_protection: %s", err) @@ -1236,6 +1229,18 @@ func resourceAlloydbClusterRead(d *schema.ResourceData, meta interface{}) error return fmt.Errorf("Error setting skip_await_major_version_upgrade: %s", err) } } + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DEFAULT"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Cluster: %s", err) } @@ -1273,6 +1278,19 @@ func resourceAlloydbClusterRead(d *schema.ResourceData, meta interface{}) error } func resourceAlloydbClusterUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceAlloydbCluster().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceAlloydbClusterRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1650,6 +1668,13 @@ func resourceAlloydbClusterUpdate(d *schema.ResourceData, meta interface{}) erro } func resourceAlloydbClusterDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy AlloydbCluster without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Cluster %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1738,9 +1763,6 @@ func resourceAlloydbClusterImport(d *schema.ResourceData, meta interface{}) ([]* d.SetId(id) // Explicitly set virtual fields to default values on import - if err := d.Set("deletion_policy", "DEFAULT"); err != nil { - return nil, fmt.Errorf("Error setting deletion_policy: %s", err) - } if err := d.Set("deletion_protection", true); err != nil { return nil, fmt.Errorf("Error setting deletion_protection: %s", err) } diff --git a/google-beta/services/alloydb/resource_alloydb_cluster_generated_meta.yaml b/google-beta/services/alloydb/resource_alloydb_cluster_generated_meta.yaml index 13bcb26c332..bd16e28e60f 100644 --- a/google-beta/services/alloydb/resource_alloydb_cluster_generated_meta.yaml +++ b/google-beta/services/alloydb/resource_alloydb_cluster_generated_meta.yaml @@ -35,8 +35,6 @@ fields: - api_field: continuousBackupInfo.schedule - api_field: databaseVersion - api_field: dataplexConfig.enabled - - field: deletion_policy - provider_only: true - field: deletion_protection provider_only: true - api_field: displayName @@ -89,3 +87,5 @@ fields: - api_field: trialMetadata.startTime - api_field: trialMetadata.upgradeTime - api_field: uid + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/alloydb/resource_alloydb_instance.go b/google-beta/services/alloydb/resource_alloydb_instance.go index 40b503188b4..ab7f1aec82f 100644 --- a/google-beta/services/alloydb/resource_alloydb_instance.go +++ b/google-beta/services/alloydb/resource_alloydb_instance.go @@ -116,6 +116,7 @@ func ResourceAlloydbInstance() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.SetAnnotationsDiff, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Schema: map[string]*schema.Schema{ @@ -627,6 +628,19 @@ endpoint for an end-user application.`, Computed: true, Description: `Time the Instance was updated in UTC.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -827,6 +841,20 @@ func resourceAlloydbInstanceRead(d *schema.ResourceData, meta interface{}) error log.Printf("[DEBUG] Finished reading AlloydbInstance %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceAlloydbInstanceFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -836,6 +864,18 @@ func resourceAlloydbInstanceRead(d *schema.ResourceData, meta interface{}) error } func resourceAlloydbInstanceUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceAlloydbInstance().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceAlloydbInstanceRead(d, meta) + } var project string config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) @@ -1049,6 +1089,13 @@ func resourceAlloydbInstanceUpdate(d *schema.ResourceData, meta interface{}) err } func resourceAlloydbInstanceDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy AlloydbInstance without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Instance %q from Terraform state without deletion", d.Id()) + return nil + } var project string config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) diff --git a/google-beta/services/alloydb/resource_alloydb_instance_generated_meta.yaml b/google-beta/services/alloydb/resource_alloydb_instance_generated_meta.yaml index b329d953c83..3bddb95ef62 100644 --- a/google-beta/services/alloydb/resource_alloydb_instance_generated_meta.yaml +++ b/google-beta/services/alloydb/resource_alloydb_instance_generated_meta.yaml @@ -69,3 +69,5 @@ fields: provider_only: true - api_field: uid - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/alloydb/resource_alloydb_user.go b/google-beta/services/alloydb/resource_alloydb_user.go index 225033b722b..ff593657bd7 100644 --- a/google-beta/services/alloydb/resource_alloydb_user.go +++ b/google-beta/services/alloydb/resource_alloydb_user.go @@ -169,6 +169,19 @@ func ResourceAlloydbUser() *schema.Resource { Computed: true, Description: `Name of the resource in the form of projects/{project}/locations/{location}/clusters/{cluster}/users/{user}.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -281,6 +294,20 @@ func resourceAlloydbUserRead(d *schema.ResourceData, meta interface{}) error { log.Printf("[DEBUG] Finished reading AlloydbUser %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceAlloydbUserFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -290,6 +317,19 @@ func resourceAlloydbUserRead(d *schema.ResourceData, meta interface{}) error { } func resourceAlloydbUserUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceAlloydbUser().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceAlloydbUserRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -392,6 +432,13 @@ func resourceAlloydbUserUpdate(d *schema.ResourceData, meta interface{}) error { } func resourceAlloydbUserDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy AlloydbUser without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing User %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/alloydb/resource_alloydb_user_generated_meta.yaml b/google-beta/services/alloydb/resource_alloydb_user_generated_meta.yaml index 5fc5a5291f0..aed3da67c47 100644 --- a/google-beta/services/alloydb/resource_alloydb_user_generated_meta.yaml +++ b/google-beta/services/alloydb/resource_alloydb_user_generated_meta.yaml @@ -19,3 +19,5 @@ fields: - field: user_id provider_only: true - api_field: userType + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/apigateway/resource_api_gateway_api.go b/google-beta/services/apigateway/resource_api_gateway_api.go index 4a6b6666abd..eefde2ce193 100644 --- a/google-beta/services/apigateway/resource_api_gateway_api.go +++ b/google-beta/services/apigateway/resource_api_gateway_api.go @@ -116,6 +116,7 @@ func ResourceApiGatewayApi() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -197,6 +198,18 @@ If not specified, a new Service will automatically be created in the same projec Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -341,6 +354,19 @@ func resourceApiGatewayApiRead(d *schema.ResourceData, meta interface{}) error { log.Printf("[DEBUG] Finished reading ApiGatewayApi %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Api: %s", err) } @@ -372,6 +398,19 @@ func resourceApiGatewayApiRead(d *schema.ResourceData, meta interface{}) error { } func resourceApiGatewayApiUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceApiGatewayApi().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceApiGatewayApiRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -475,6 +514,13 @@ func resourceApiGatewayApiUpdate(d *schema.ResourceData, meta interface{}) error } func resourceApiGatewayApiDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ApiGatewayApi without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Api %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/apigateway/resource_api_gateway_api_config.go b/google-beta/services/apigateway/resource_api_gateway_api_config.go index b4f5b5d9a03..e75810f5375 100644 --- a/google-beta/services/apigateway/resource_api_gateway_api_config.go +++ b/google-beta/services/apigateway/resource_api_gateway_api_config.go @@ -116,6 +116,7 @@ func ResourceApiGatewayApiConfig() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -353,6 +354,18 @@ If multiple files are specified, the files are merged with the following rules: Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -525,6 +538,19 @@ func resourceApiGatewayApiConfigRead(d *schema.ResourceData, meta interface{}) e log.Printf("[DEBUG] Finished reading ApiGatewayApiConfig %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading ApiConfig: %s", err) } @@ -562,6 +588,19 @@ func resourceApiGatewayApiConfigRead(d *schema.ResourceData, meta interface{}) e } func resourceApiGatewayApiConfigUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceApiGatewayApiConfig().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceApiGatewayApiConfigRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -705,6 +744,13 @@ func resourceApiGatewayApiConfigUpdate(d *schema.ResourceData, meta interface{}) } func resourceApiGatewayApiConfigDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ApiGatewayApiConfig without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing ApiConfig %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/apigateway/resource_api_gateway_api_config_generated_meta.yaml b/google-beta/services/apigateway/resource_api_gateway_api_config_generated_meta.yaml index 0e50706e856..2a90bc76ba4 100644 --- a/google-beta/services/apigateway/resource_api_gateway_api_config_generated_meta.yaml +++ b/google-beta/services/apigateway/resource_api_gateway_api_config_generated_meta.yaml @@ -28,3 +28,5 @@ fields: - api_field: serviceConfigId - field: terraform_labels provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/apigateway/resource_api_gateway_api_generated_meta.yaml b/google-beta/services/apigateway/resource_api_gateway_api_generated_meta.yaml index 29b78b19ffd..440b246de08 100644 --- a/google-beta/services/apigateway/resource_api_gateway_api_generated_meta.yaml +++ b/google-beta/services/apigateway/resource_api_gateway_api_generated_meta.yaml @@ -18,3 +18,5 @@ fields: - api_field: name - field: terraform_labels provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/apigateway/resource_api_gateway_gateway.go b/google-beta/services/apigateway/resource_api_gateway_gateway.go index dd621ca16f8..bc74b9534fb 100644 --- a/google-beta/services/apigateway/resource_api_gateway_gateway.go +++ b/google-beta/services/apigateway/resource_api_gateway_gateway.go @@ -116,6 +116,7 @@ func ResourceApiGatewayGateway() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -208,6 +209,18 @@ Please refer to the field 'effective_labels' for all of the labels present on th Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -357,6 +370,19 @@ func resourceApiGatewayGatewayRead(d *schema.ResourceData, meta interface{}) err log.Printf("[DEBUG] Finished reading ApiGatewayGateway %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Gateway: %s", err) } @@ -394,6 +420,19 @@ func resourceApiGatewayGatewayRead(d *schema.ResourceData, meta interface{}) err } func resourceApiGatewayGatewayUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceApiGatewayGateway().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceApiGatewayGatewayRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -512,6 +551,13 @@ func resourceApiGatewayGatewayUpdate(d *schema.ResourceData, meta interface{}) e } func resourceApiGatewayGatewayDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ApiGatewayGateway without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Gateway %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/apigateway/resource_api_gateway_gateway_generated_meta.yaml b/google-beta/services/apigateway/resource_api_gateway_gateway_generated_meta.yaml index bf42731f118..d6f42c64b7c 100644 --- a/google-beta/services/apigateway/resource_api_gateway_gateway_generated_meta.yaml +++ b/google-beta/services/apigateway/resource_api_gateway_gateway_generated_meta.yaml @@ -20,3 +20,5 @@ fields: provider_only: true - field: terraform_labels provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/apigee/resource_apigee_addons_config.go b/google-beta/services/apigee/resource_apigee_addons_config.go index fb826b8d30d..2dac7982910 100644 --- a/google-beta/services/apigee/resource_apigee_addons_config.go +++ b/google-beta/services/apigee/resource_apigee_addons_config.go @@ -230,6 +230,19 @@ func ResourceApigeeAddonsConfig() *schema.Resource { }, }, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -345,6 +358,20 @@ func resourceApigeeAddonsConfigRead(d *schema.ResourceData, meta interface{}) er log.Printf("[DEBUG] Finished reading ApigeeAddonsConfig %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceApigeeAddonsConfigFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -366,6 +393,19 @@ func resourceApigeeAddonsConfigRead(d *schema.ResourceData, meta interface{}) er } func resourceApigeeAddonsConfigUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceApigeeAddonsConfig().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceApigeeAddonsConfigRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -434,6 +474,13 @@ func resourceApigeeAddonsConfigUpdate(d *schema.ResourceData, meta interface{}) } func resourceApigeeAddonsConfigDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ApigeeAddonsConfig without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing AddonsConfig %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/apigee/resource_apigee_addons_config_generated_meta.yaml b/google-beta/services/apigee/resource_apigee_addons_config_generated_meta.yaml index eab36f647a5..3f82e81a958 100644 --- a/google-beta/services/apigee/resource_apigee_addons_config_generated_meta.yaml +++ b/google-beta/services/apigee/resource_apigee_addons_config_generated_meta.yaml @@ -16,3 +16,5 @@ fields: - api_field: addonsConfig.monetizationConfig.enabled - field: org provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/apigee/resource_apigee_api.go b/google-beta/services/apigee/resource_apigee_api.go index 938c77a90e4..aba8a1a517d 100644 --- a/google-beta/services/apigee/resource_apigee_api.go +++ b/google-beta/services/apigee/resource_apigee_api.go @@ -50,6 +50,7 @@ func ResourceApigeeApi() *schema.Resource { }, CustomizeDiff: customdiff.All( + tpgresource.DefaultProviderDeletionPolicy("DELETE"), /* If any of the config_bundle, detect_md5hash or md5hash is changed, then an update is expected, so we tell Terraform core to expect update on meta_data, @@ -149,6 +150,9 @@ func ResourceApigeeApi() *schema.Resource { return true }, }, + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end }, UseJSONNumber: true, } @@ -222,6 +226,11 @@ func resourceApigeeApiCreate(d *schema.ResourceData, meta interface{}) error { } func resourceApigeeApiUpdate(d *schema.ResourceData, meta interface{}) error { + + if tpgresource.DeletionPolicyPreUpdate(d, ResourceApigeeApi) { + return ResourceApigeeApi().Read(d, meta) + } + //For how API proxy api is implemented, just treat an update as create, when the name is same, it will create a new revision return resourceApigeeApiCreate(d, meta) } @@ -278,6 +287,11 @@ func resourceApigeeApiRead(d *schema.ResourceData, meta interface{}) error { d.Set("md5hash", "UNKNOWN") d.Set("detect_md5hash", "UNKNOWN") } + + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + return nil } @@ -300,6 +314,13 @@ func getApigeeApiLastModifiedAt(d *schema.ResourceData) string { } func resourceApigeeApiDelete(d *schema.ResourceData, meta interface{}) error { + + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { + return nil + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/apigee/resource_apigee_api_deployment.go b/google-beta/services/apigee/resource_apigee_api_deployment.go index c41d31a4808..c125ece7553 100644 --- a/google-beta/services/apigee/resource_apigee_api_deployment.go +++ b/google-beta/services/apigee/resource_apigee_api_deployment.go @@ -100,6 +100,7 @@ func ResourceApigeeApiDeployment() *schema.Resource { return &schema.Resource{ Create: resourceApigeeApiDeploymentCreate, Read: resourceApigeeApiDeploymentRead, + Update: resourceApigeeApiDeploymentUpdate, Delete: resourceApigeeApiDeploymentDelete, Importer: &schema.ResourceImporter{ @@ -168,6 +169,19 @@ func ResourceApigeeApiDeployment() *schema.Resource { Computed: true, Description: `The ID of the API deployment in the format 'organizations/{{org_id}}/environments/{{environment}}/apis/{{proxy_id}}/revisions/{{revision}}/deployments'.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -282,6 +296,20 @@ func resourceApigeeApiDeploymentRead(d *schema.ResourceData, meta interface{}) e log.Printf("[DEBUG] Finished reading ApigeeApiDeployment %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceApigeeApiDeploymentFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -320,7 +348,19 @@ func resourceApigeeApiDeploymentRead(d *schema.ResourceData, meta interface{}) e return nil } +func resourceApigeeApiDeploymentUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceApigeeApiDeploymentRead(d, meta) +} + func resourceApigeeApiDeploymentDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ApigeeApiDeployment without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing ApiDeployment %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/apigee/resource_apigee_api_deployment_generated_meta.yaml b/google-beta/services/apigee/resource_apigee_api_deployment_generated_meta.yaml index fd954a83c64..ce1c25a7bd7 100644 --- a/google-beta/services/apigee/resource_apigee_api_deployment_generated_meta.yaml +++ b/google-beta/services/apigee/resource_apigee_api_deployment_generated_meta.yaml @@ -16,3 +16,5 @@ fields: provider_only: true - field: revision provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/apigee/resource_apigee_api_meta.yaml b/google-beta/services/apigee/resource_apigee_api_meta.yaml index 41c17a12abb..a3c434303e9 100644 --- a/google-beta/services/apigee/resource_apigee_api_meta.yaml +++ b/google-beta/services/apigee/resource_apigee_api_meta.yaml @@ -16,3 +16,5 @@ fields: - api_field: 'name' - field: 'org_id' - api_field: 'revision' + - field: 'deletion_policy' + provider_only: true diff --git a/google-beta/services/apigee/resource_apigee_api_product.go b/google-beta/services/apigee/resource_apigee_api_product.go index 8e4d80a8491..034c16861ae 100644 --- a/google-beta/services/apigee/resource_apigee_api_product.go +++ b/google-beta/services/apigee/resource_apigee_api_product.go @@ -312,6 +312,19 @@ For example, a quota of 50, for a quotaInterval of 12 and a quotaTimeUnit of hou Computed: true, Description: `Response only. Modified time of this environment as milliseconds since epoch.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -791,6 +804,20 @@ func resourceApigeeApiProductRead(d *schema.ResourceData, meta interface{}) erro log.Printf("[DEBUG] Finished reading ApigeeApiProduct %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceApigeeApiProductFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -818,6 +845,19 @@ func resourceApigeeApiProductRead(d *schema.ResourceData, meta interface{}) erro } func resourceApigeeApiProductUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceApigeeApiProduct().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceApigeeApiProductRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -979,6 +1019,13 @@ func resourceApigeeApiProductUpdate(d *schema.ResourceData, meta interface{}) er } func resourceApigeeApiProductDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ApigeeApiProduct without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing ApiProduct %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/apigee/resource_apigee_api_product_generated_meta.yaml b/google-beta/services/apigee/resource_apigee_api_product_generated_meta.yaml index c24723d5e50..547fed03bad 100644 --- a/google-beta/services/apigee/resource_apigee_api_product_generated_meta.yaml +++ b/google-beta/services/apigee/resource_apigee_api_product_generated_meta.yaml @@ -52,3 +52,5 @@ fields: - api_field: quotaTimeUnit - api_field: scopes - api_field: space + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/apigee/resource_apigee_app_group.go b/google-beta/services/apigee/resource_apigee_app_group.go index 51b0b36e15d..c6c52c7197b 100644 --- a/google-beta/services/apigee/resource_apigee_app_group.go +++ b/google-beta/services/apigee/resource_apigee_app_group.go @@ -206,6 +206,19 @@ in the format 'organizations/{{org_name}}'.`, Computed: true, Description: `App group name displayed in the UI`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -346,6 +359,20 @@ func resourceApigeeAppGroupRead(d *schema.ResourceData, meta interface{}) error log.Printf("[DEBUG] Finished reading ApigeeAppGroup %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceApigeeAppGroupFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -373,6 +400,19 @@ func resourceApigeeAppGroupRead(d *schema.ResourceData, meta interface{}) error } func resourceApigeeAppGroupUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceApigeeAppGroup().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceApigeeAppGroupRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -468,6 +508,13 @@ func resourceApigeeAppGroupUpdate(d *schema.ResourceData, meta interface{}) erro } func resourceApigeeAppGroupDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ApigeeAppGroup without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing AppGroup %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/apigee/resource_apigee_app_group_generated_meta.yaml b/google-beta/services/apigee/resource_apigee_app_group_generated_meta.yaml index ad60951bccc..141a56ed8fd 100644 --- a/google-beta/services/apigee/resource_apigee_app_group_generated_meta.yaml +++ b/google-beta/services/apigee/resource_apigee_app_group_generated_meta.yaml @@ -20,3 +20,5 @@ fields: provider_only: true - api_field: organization - api_field: status + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/apigee/resource_apigee_control_plane_access.go b/google-beta/services/apigee/resource_apigee_control_plane_access.go index b70df39ffaa..8e7371fd319 100644 --- a/google-beta/services/apigee/resource_apigee_control_plane_access.go +++ b/google-beta/services/apigee/resource_apigee_control_plane_access.go @@ -303,6 +303,7 @@ func resourceApigeeControlPlaneAccessRead(d *schema.ResourceData, meta interface } func resourceApigeeControlPlaneAccessUpdate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/apigee/resource_apigee_developer.go b/google-beta/services/apigee/resource_apigee_developer.go index 2ab1f494b2f..812aac7e7b5 100644 --- a/google-beta/services/apigee/resource_apigee_developer.go +++ b/google-beta/services/apigee/resource_apigee_developer.go @@ -200,6 +200,19 @@ in the format 'organizations/{{org_name}}'.`, Computed: true, Description: `Status of the developer. Valid values are active and inactive.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -334,6 +347,20 @@ func resourceApigeeDeveloperRead(d *schema.ResourceData, meta interface{}) error log.Printf("[DEBUG] Finished reading ApigeeDeveloper %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceApigeeDeveloperFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -361,6 +388,19 @@ func resourceApigeeDeveloperRead(d *schema.ResourceData, meta interface{}) error } func resourceApigeeDeveloperUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceApigeeDeveloper().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceApigeeDeveloperRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -450,6 +490,13 @@ func resourceApigeeDeveloperUpdate(d *schema.ResourceData, meta interface{}) err } func resourceApigeeDeveloperDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ApigeeDeveloper without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Developer %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/apigee/resource_apigee_developer_app.go b/google-beta/services/apigee/resource_apigee_developer_app.go index 079b4544646..a891d5f0ce9 100644 --- a/google-beta/services/apigee/resource_apigee_developer_app.go +++ b/google-beta/services/apigee/resource_apigee_developer_app.go @@ -330,6 +330,19 @@ you associate with the app.`, Computed: true, Description: `Time at which the developer was last modified in milliseconds since epoch.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -499,6 +512,20 @@ func resourceApigeeDeveloperAppRead(d *schema.ResourceData, meta interface{}) er return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceApigeeDeveloperAppFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -532,6 +559,19 @@ func resourceApigeeDeveloperAppRead(d *schema.ResourceData, meta interface{}) er } func resourceApigeeDeveloperAppUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceApigeeDeveloperApp().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceApigeeDeveloperAppRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -644,6 +684,13 @@ func resourceApigeeDeveloperAppUpdate(d *schema.ResourceData, meta interface{}) } func resourceApigeeDeveloperAppDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ApigeeDeveloperApp without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing DeveloperApp %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/apigee/resource_apigee_developer_app_generated_meta.yaml b/google-beta/services/apigee/resource_apigee_developer_app_generated_meta.yaml index 89310ab3226..ef06dedfec3 100644 --- a/google-beta/services/apigee/resource_apigee_developer_app_generated_meta.yaml +++ b/google-beta/services/apigee/resource_apigee_developer_app_generated_meta.yaml @@ -34,3 +34,5 @@ fields: provider_only: true - api_field: scopes - api_field: status + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/apigee/resource_apigee_developer_generated_meta.yaml b/google-beta/services/apigee/resource_apigee_developer_generated_meta.yaml index ab644cff8a8..bfaa16feb68 100644 --- a/google-beta/services/apigee/resource_apigee_developer_generated_meta.yaml +++ b/google-beta/services/apigee/resource_apigee_developer_generated_meta.yaml @@ -19,3 +19,5 @@ fields: - api_field: organizatioName - api_field: status - api_field: userName + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/apigee/resource_apigee_dns_zone.go b/google-beta/services/apigee/resource_apigee_dns_zone.go index 9a81d038856..e37e6c30079 100644 --- a/google-beta/services/apigee/resource_apigee_dns_zone.go +++ b/google-beta/services/apigee/resource_apigee_dns_zone.go @@ -100,6 +100,7 @@ func ResourceApigeeDnsZone() *schema.Resource { return &schema.Resource{ Create: resourceApigeeDnsZoneCreate, Read: resourceApigeeDnsZoneRead, + Update: resourceApigeeDnsZoneUpdate, Delete: resourceApigeeDnsZoneDelete, Importer: &schema.ResourceImporter{ @@ -166,6 +167,19 @@ in the format 'organizations/{{org_name}}'.`, Description: `Name of the Dns Zone in the following format: organizations/{organization}/dnsZones/{dnsZone}.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -282,6 +296,20 @@ func resourceApigeeDnsZoneRead(d *schema.ResourceData, meta interface{}) error { log.Printf("[DEBUG] Finished reading ApigeeDnsZone %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceApigeeDnsZoneFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -290,7 +318,19 @@ func resourceApigeeDnsZoneRead(d *schema.ResourceData, meta interface{}) error { return nil } +func resourceApigeeDnsZoneUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceApigeeDnsZoneRead(d, meta) +} + func resourceApigeeDnsZoneDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ApigeeDnsZone without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing DnsZone %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/apigee/resource_apigee_dns_zone_generated_meta.yaml b/google-beta/services/apigee/resource_apigee_dns_zone_generated_meta.yaml index 761721604a1..fb402351d62 100644 --- a/google-beta/services/apigee/resource_apigee_dns_zone_generated_meta.yaml +++ b/google-beta/services/apigee/resource_apigee_dns_zone_generated_meta.yaml @@ -16,3 +16,5 @@ fields: provider_only: true - api_field: peeringConfig.targetNetworkId - api_field: peeringConfig.targetProjectId + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/apigee/resource_apigee_endpoint_attachment.go b/google-beta/services/apigee/resource_apigee_endpoint_attachment.go index 757349ffc93..377d82434cc 100644 --- a/google-beta/services/apigee/resource_apigee_endpoint_attachment.go +++ b/google-beta/services/apigee/resource_apigee_endpoint_attachment.go @@ -100,6 +100,7 @@ func ResourceApigeeEndpointAttachment() *schema.Resource { return &schema.Resource{ Create: resourceApigeeEndpointAttachmentCreate, Read: resourceApigeeEndpointAttachmentRead, + Update: resourceApigeeEndpointAttachmentUpdate, Delete: resourceApigeeEndpointAttachmentDelete, Importer: &schema.ResourceImporter{ @@ -172,6 +173,19 @@ in the format 'organizations/{{org_name}}'.`, Description: `Name of the Endpoint Attachment in the following format: organizations/{organization}/endpointAttachments/{endpointAttachment}.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -298,6 +312,20 @@ func resourceApigeeEndpointAttachmentRead(d *schema.ResourceData, meta interface log.Printf("[DEBUG] Finished reading ApigeeEndpointAttachment %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceApigeeEndpointAttachmentFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -324,7 +352,19 @@ func resourceApigeeEndpointAttachmentRead(d *schema.ResourceData, meta interface return nil } +func resourceApigeeEndpointAttachmentUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceApigeeEndpointAttachmentRead(d, meta) +} + func resourceApigeeEndpointAttachmentDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ApigeeEndpointAttachment without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing EndpointAttachment %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/apigee/resource_apigee_endpoint_attachment_generated_meta.yaml b/google-beta/services/apigee/resource_apigee_endpoint_attachment_generated_meta.yaml index a7f1fa225c4..e6690ebdc35 100644 --- a/google-beta/services/apigee/resource_apigee_endpoint_attachment_generated_meta.yaml +++ b/google-beta/services/apigee/resource_apigee_endpoint_attachment_generated_meta.yaml @@ -16,3 +16,5 @@ fields: - field: org_id provider_only: true - api_field: serviceAttachment + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/apigee/resource_apigee_env_keystore.go b/google-beta/services/apigee/resource_apigee_env_keystore.go index 4b075450bac..cf693525124 100644 --- a/google-beta/services/apigee/resource_apigee_env_keystore.go +++ b/google-beta/services/apigee/resource_apigee_env_keystore.go @@ -100,6 +100,7 @@ func ResourceApigeeEnvKeystore() *schema.Resource { return &schema.Resource{ Create: resourceApigeeEnvKeystoreCreate, Read: resourceApigeeEnvKeystoreRead, + Update: resourceApigeeEnvKeystoreUpdate, Delete: resourceApigeeEnvKeystoreDelete, Importer: &schema.ResourceImporter{ @@ -152,6 +153,19 @@ in the format 'organizations/{{org_name}}/environments/{{env_name}}'.`, Type: schema.TypeString, }, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -262,6 +276,20 @@ func resourceApigeeEnvKeystoreRead(d *schema.ResourceData, meta interface{}) err log.Printf("[DEBUG] Finished reading ApigeeEnvKeystore %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceApigeeEnvKeystoreFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -288,7 +316,19 @@ func resourceApigeeEnvKeystoreRead(d *schema.ResourceData, meta interface{}) err return nil } +func resourceApigeeEnvKeystoreUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceApigeeEnvKeystoreRead(d, meta) +} + func resourceApigeeEnvKeystoreDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ApigeeEnvKeystore without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing EnvKeystore %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/apigee/resource_apigee_env_keystore_generated_meta.yaml b/google-beta/services/apigee/resource_apigee_env_keystore_generated_meta.yaml index ed961141c57..bf323ba4ce3 100644 --- a/google-beta/services/apigee/resource_apigee_env_keystore_generated_meta.yaml +++ b/google-beta/services/apigee/resource_apigee_env_keystore_generated_meta.yaml @@ -11,3 +11,5 @@ fields: - field: env_id provider_only: true - api_field: name + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/apigee/resource_apigee_env_references.go b/google-beta/services/apigee/resource_apigee_env_references.go index c8715d9212a..b994ee9c389 100644 --- a/google-beta/services/apigee/resource_apigee_env_references.go +++ b/google-beta/services/apigee/resource_apigee_env_references.go @@ -163,6 +163,19 @@ in the format 'organizations/{{org_name}}/environments/{{env_name}}'.`, ForceNew: true, Description: `Optional. A human-readable description of this reference.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -291,6 +304,20 @@ func resourceApigeeEnvReferencesRead(d *schema.ResourceData, meta interface{}) e log.Printf("[DEBUG] Finished reading ApigeeEnvReferences %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceApigeeEnvReferencesFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -318,6 +345,19 @@ func resourceApigeeEnvReferencesRead(d *schema.ResourceData, meta interface{}) e } func resourceApigeeEnvReferencesUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceApigeeEnvReferences().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceApigeeEnvReferencesRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -401,6 +441,13 @@ func resourceApigeeEnvReferencesUpdate(d *schema.ResourceData, meta interface{}) } func resourceApigeeEnvReferencesDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ApigeeEnvReferences without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing EnvReferences %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/apigee/resource_apigee_env_references_generated_meta.yaml b/google-beta/services/apigee/resource_apigee_env_references_generated_meta.yaml index 2cb7c85ddcf..5b77eca0797 100644 --- a/google-beta/services/apigee/resource_apigee_env_references_generated_meta.yaml +++ b/google-beta/services/apigee/resource_apigee_env_references_generated_meta.yaml @@ -13,3 +13,5 @@ fields: - api_field: name - api_field: refers - api_field: resourceType + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/apigee/resource_apigee_envgroup.go b/google-beta/services/apigee/resource_apigee_envgroup.go index 57eefea29b1..07c4a5af972 100644 --- a/google-beta/services/apigee/resource_apigee_envgroup.go +++ b/google-beta/services/apigee/resource_apigee_envgroup.go @@ -154,6 +154,19 @@ in the format 'organizations/{{org_name}}'.`, Type: schema.TypeString, }, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -280,6 +293,20 @@ func resourceApigeeEnvgroupRead(d *schema.ResourceData, meta interface{}) error log.Printf("[DEBUG] Finished reading ApigeeEnvgroup %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceApigeeEnvgroupFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -307,6 +334,19 @@ func resourceApigeeEnvgroupRead(d *schema.ResourceData, meta interface{}) error } func resourceApigeeEnvgroupUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceApigeeEnvgroup().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceApigeeEnvgroupRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -394,6 +434,13 @@ func resourceApigeeEnvgroupUpdate(d *schema.ResourceData, meta interface{}) erro } func resourceApigeeEnvgroupDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ApigeeEnvgroup without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Envgroup %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/apigee/resource_apigee_envgroup_attachment.go b/google-beta/services/apigee/resource_apigee_envgroup_attachment.go index e338515e75a..ae0e516c497 100644 --- a/google-beta/services/apigee/resource_apigee_envgroup_attachment.go +++ b/google-beta/services/apigee/resource_apigee_envgroup_attachment.go @@ -100,6 +100,7 @@ func ResourceApigeeEnvgroupAttachment() *schema.Resource { return &schema.Resource{ Create: resourceApigeeEnvgroupAttachmentCreate, Read: resourceApigeeEnvgroupAttachmentRead, + Update: resourceApigeeEnvgroupAttachmentUpdate, Delete: resourceApigeeEnvgroupAttachmentDelete, Importer: &schema.ResourceImporter{ @@ -149,6 +150,19 @@ in the format 'organizations/{{org_name}}/envgroups/{{envgroup_name}}'.`, Computed: true, Description: `The name of the newly created attachment (output parameter).`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -283,6 +297,20 @@ func resourceApigeeEnvgroupAttachmentRead(d *schema.ResourceData, meta interface log.Printf("[DEBUG] Finished reading ApigeeEnvgroupAttachment %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceApigeeEnvgroupAttachmentFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -309,7 +337,19 @@ func resourceApigeeEnvgroupAttachmentRead(d *schema.ResourceData, meta interface return nil } +func resourceApigeeEnvgroupAttachmentUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceApigeeEnvgroupAttachmentRead(d, meta) +} + func resourceApigeeEnvgroupAttachmentDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ApigeeEnvgroupAttachment without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing EnvgroupAttachment %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/apigee/resource_apigee_envgroup_attachment_generated_meta.yaml b/google-beta/services/apigee/resource_apigee_envgroup_attachment_generated_meta.yaml index ee0e07e7243..1c3c3109d7f 100644 --- a/google-beta/services/apigee/resource_apigee_envgroup_attachment_generated_meta.yaml +++ b/google-beta/services/apigee/resource_apigee_envgroup_attachment_generated_meta.yaml @@ -11,3 +11,5 @@ fields: provider_only: true - api_field: environment - api_field: name + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/apigee/resource_apigee_envgroup_generated_meta.yaml b/google-beta/services/apigee/resource_apigee_envgroup_generated_meta.yaml index 8c686d1d0bd..871494ddccc 100644 --- a/google-beta/services/apigee/resource_apigee_envgroup_generated_meta.yaml +++ b/google-beta/services/apigee/resource_apigee_envgroup_generated_meta.yaml @@ -11,3 +11,5 @@ fields: - api_field: name - field: org_id provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/apigee/resource_apigee_environment.go b/google-beta/services/apigee/resource_apigee_environment.go index 89975d191a8..75ddf55316d 100644 --- a/google-beta/services/apigee/resource_apigee_environment.go +++ b/google-beta/services/apigee/resource_apigee_environment.go @@ -285,6 +285,19 @@ limited by capability and capacity. Refer to Apigee's public documentation to understand about each of these types in details. An Apigee org can support heterogeneous Environments. Possible values: ["ENVIRONMENT_TYPE_UNSPECIFIED", "BASE", "INTERMEDIATE", "COMPREHENSIVE"]`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -459,6 +472,20 @@ func resourceApigeeEnvironmentRead(d *schema.ResourceData, meta interface{}) err log.Printf("[DEBUG] Finished reading ApigeeEnvironment %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceApigeeEnvironmentFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -486,6 +513,19 @@ func resourceApigeeEnvironmentRead(d *schema.ResourceData, meta interface{}) err } func resourceApigeeEnvironmentUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceApigeeEnvironment().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceApigeeEnvironmentRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -605,6 +645,13 @@ func resourceApigeeEnvironmentUpdate(d *schema.ResourceData, meta interface{}) e } func resourceApigeeEnvironmentDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ApigeeEnvironment without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Environment %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/apigee/resource_apigee_environment_addons_config.go b/google-beta/services/apigee/resource_apigee_environment_addons_config.go index dac10dafbb9..0c5d224a2ae 100644 --- a/google-beta/services/apigee/resource_apigee_environment_addons_config.go +++ b/google-beta/services/apigee/resource_apigee_environment_addons_config.go @@ -289,6 +289,7 @@ func resourceApigeeEnvironmentAddonsConfigRead(d *schema.ResourceData, meta inte } func resourceApigeeEnvironmentAddonsConfigUpdate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/apigee/resource_apigee_environment_api_revision_deployment.go b/google-beta/services/apigee/resource_apigee_environment_api_revision_deployment.go index 7de8b27301d..9cfa8e9a4d4 100644 --- a/google-beta/services/apigee/resource_apigee_environment_api_revision_deployment.go +++ b/google-beta/services/apigee/resource_apigee_environment_api_revision_deployment.go @@ -100,6 +100,7 @@ func ResourceApigeeEnvironmentApiRevisionDeployment() *schema.Resource { return &schema.Resource{ Create: resourceApigeeEnvironmentApiRevisionDeploymentCreate, Read: resourceApigeeEnvironmentApiRevisionDeploymentRead, + Update: resourceApigeeEnvironmentApiRevisionDeploymentUpdate, Delete: resourceApigeeEnvironmentApiRevisionDeploymentDelete, Importer: &schema.ResourceImporter{ @@ -201,6 +202,19 @@ func ResourceApigeeEnvironmentApiRevisionDeployment() *schema.Resource { Computed: true, Description: `Deployment state reported by Apigee.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -316,6 +330,20 @@ func resourceApigeeEnvironmentApiRevisionDeploymentRead(d *schema.ResourceData, log.Printf("[DEBUG] Finished reading ApigeeEnvironmentApiRevisionDeployment %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceApigeeEnvironmentApiRevisionDeploymentFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -354,7 +382,19 @@ func resourceApigeeEnvironmentApiRevisionDeploymentRead(d *schema.ResourceData, return nil } +func resourceApigeeEnvironmentApiRevisionDeploymentUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceApigeeEnvironmentApiRevisionDeploymentRead(d, meta) +} + func resourceApigeeEnvironmentApiRevisionDeploymentDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ApigeeEnvironmentApiRevisionDeployment without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing EnvironmentApiRevisionDeployment %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/apigee/resource_apigee_environment_api_revision_deployment_generated_meta.yaml b/google-beta/services/apigee/resource_apigee_environment_api_revision_deployment_generated_meta.yaml index 0317e8e2bf9..b3b5862e30e 100644 --- a/google-beta/services/apigee/resource_apigee_environment_api_revision_deployment_generated_meta.yaml +++ b/google-beta/services/apigee/resource_apigee_environment_api_revision_deployment_generated_meta.yaml @@ -25,3 +25,5 @@ fields: - field: service_account provider_only: true - api_field: state + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/apigee/resource_apigee_environment_generated_meta.yaml b/google-beta/services/apigee/resource_apigee_environment_generated_meta.yaml index 84028f415a9..fc573211af7 100644 --- a/google-beta/services/apigee/resource_apigee_environment_generated_meta.yaml +++ b/google-beta/services/apigee/resource_apigee_environment_generated_meta.yaml @@ -23,3 +23,5 @@ fields: - api_field: properties.property.name - api_field: properties.property.value - api_field: type + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/apigee/resource_apigee_environment_keyvaluemaps.go b/google-beta/services/apigee/resource_apigee_environment_keyvaluemaps.go index 17505fd3750..daaa6e3fca1 100644 --- a/google-beta/services/apigee/resource_apigee_environment_keyvaluemaps.go +++ b/google-beta/services/apigee/resource_apigee_environment_keyvaluemaps.go @@ -100,6 +100,7 @@ func ResourceApigeeEnvironmentKeyvaluemaps() *schema.Resource { return &schema.Resource{ Create: resourceApigeeEnvironmentKeyvaluemapsCreate, Read: resourceApigeeEnvironmentKeyvaluemapsRead, + Update: resourceApigeeEnvironmentKeyvaluemapsUpdate, Delete: resourceApigeeEnvironmentKeyvaluemapsDelete, Importer: &schema.ResourceImporter{ @@ -144,6 +145,19 @@ in the format 'organizations/{{org_name}}/environments/{{env_name}}'.`, ForceNew: true, Description: `Required. ID of the key value map.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -248,6 +262,20 @@ func resourceApigeeEnvironmentKeyvaluemapsRead(d *schema.ResourceData, meta inte return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceApigeeEnvironmentKeyvaluemapsFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -274,7 +302,19 @@ func resourceApigeeEnvironmentKeyvaluemapsRead(d *schema.ResourceData, meta inte return nil } +func resourceApigeeEnvironmentKeyvaluemapsUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceApigeeEnvironmentKeyvaluemapsRead(d, meta) +} + func resourceApigeeEnvironmentKeyvaluemapsDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ApigeeEnvironmentKeyvaluemaps without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing EnvironmentKeyvaluemaps %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/apigee/resource_apigee_environment_keyvaluemaps_entries.go b/google-beta/services/apigee/resource_apigee_environment_keyvaluemaps_entries.go index aef6432c9ff..921d0ae7c1b 100644 --- a/google-beta/services/apigee/resource_apigee_environment_keyvaluemaps_entries.go +++ b/google-beta/services/apigee/resource_apigee_environment_keyvaluemaps_entries.go @@ -100,6 +100,7 @@ func ResourceApigeeEnvironmentKeyvaluemapsEntries() *schema.Resource { return &schema.Resource{ Create: resourceApigeeEnvironmentKeyvaluemapsEntriesCreate, Read: resourceApigeeEnvironmentKeyvaluemapsEntriesRead, + Update: resourceApigeeEnvironmentKeyvaluemapsEntriesUpdate, Delete: resourceApigeeEnvironmentKeyvaluemapsEntriesDelete, Importer: &schema.ResourceImporter{ @@ -150,6 +151,19 @@ in the format 'organizations/{{org_name}}/environments/{{env_name}}/keyvaluemaps ForceNew: true, Description: `Required. Data or payload that is being retrieved and associated with the unique key.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -266,6 +280,20 @@ func resourceApigeeEnvironmentKeyvaluemapsEntriesRead(d *schema.ResourceData, me log.Printf("[DEBUG] Finished reading ApigeeEnvironmentKeyvaluemapsEntries %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceApigeeEnvironmentKeyvaluemapsEntriesFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -292,7 +320,19 @@ func resourceApigeeEnvironmentKeyvaluemapsEntriesRead(d *schema.ResourceData, me return nil } +func resourceApigeeEnvironmentKeyvaluemapsEntriesUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceApigeeEnvironmentKeyvaluemapsEntriesRead(d, meta) +} + func resourceApigeeEnvironmentKeyvaluemapsEntriesDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ApigeeEnvironmentKeyvaluemapsEntries without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing EnvironmentKeyvaluemapsEntries %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/apigee/resource_apigee_environment_keyvaluemaps_entries_generated_meta.yaml b/google-beta/services/apigee/resource_apigee_environment_keyvaluemaps_entries_generated_meta.yaml index 9d82d6b2b47..1be894eb015 100644 --- a/google-beta/services/apigee/resource_apigee_environment_keyvaluemaps_entries_generated_meta.yaml +++ b/google-beta/services/apigee/resource_apigee_environment_keyvaluemaps_entries_generated_meta.yaml @@ -11,3 +11,5 @@ fields: provider_only: true - api_field: name - api_field: value + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/apigee/resource_apigee_environment_keyvaluemaps_generated_meta.yaml b/google-beta/services/apigee/resource_apigee_environment_keyvaluemaps_generated_meta.yaml index 98ee045d98e..f37bd9501f1 100644 --- a/google-beta/services/apigee/resource_apigee_environment_keyvaluemaps_generated_meta.yaml +++ b/google-beta/services/apigee/resource_apigee_environment_keyvaluemaps_generated_meta.yaml @@ -10,3 +10,5 @@ fields: - field: env_id provider_only: true - api_field: name + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/apigee/resource_apigee_flowhook.go b/google-beta/services/apigee/resource_apigee_flowhook.go index 7214c071c0d..4462e68b0cb 100644 --- a/google-beta/services/apigee/resource_apigee_flowhook.go +++ b/google-beta/services/apigee/resource_apigee_flowhook.go @@ -22,6 +22,7 @@ import ( "reflect" "time" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-google-beta/google-beta/registry" "github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource" @@ -32,6 +33,7 @@ func ResourceApigeeFlowhook() *schema.Resource { return &schema.Resource{ Create: resourceApigeeFlowhookCreate, Read: resourceApigeeFlowhookRead, + Update: resourceApigeeFlowhookUpdate, Delete: resourceApigeeFlowhookDelete, Importer: &schema.ResourceImporter{ @@ -43,6 +45,10 @@ func ResourceApigeeFlowhook() *schema.Resource { Delete: schema.DefaultTimeout(20 * time.Minute), }, + CustomizeDiff: customdiff.All( + tpgresource.DefaultProviderDeletionPolicy("DELETE"), + ), + Schema: map[string]*schema.Schema{ "description": { Type: schema.TypeString, @@ -81,6 +87,9 @@ func ResourceApigeeFlowhook() *schema.Resource { Default: true, Description: `Flag that specifies whether execution should continue if the flow hook throws an exception. Set to true to continue execution. Set to false to stop execution if the flow hook throws an exception. Defaults to true.`, }, + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end }, UseJSONNumber: true, } @@ -195,10 +204,29 @@ func resourceApigeeFlowhookRead(d *schema.ResourceData, meta interface{}) error return fmt.Errorf("Error reading Flowhook: %s", err) } + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + return nil } +// UDP update start +func resourceApigeeFlowhookUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceApigeeFlowhookRead(d, meta) +} + +//UDP update end + func resourceApigeeFlowhookDelete(d *schema.ResourceData, meta interface{}) error { + + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { + return nil + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/apigee/resource_apigee_flowhook_meta.yaml b/google-beta/services/apigee/resource_apigee_flowhook_meta.yaml index 56a4cb9b9de..b72de311f3a 100644 --- a/google-beta/services/apigee/resource_apigee_flowhook_meta.yaml +++ b/google-beta/services/apigee/resource_apigee_flowhook_meta.yaml @@ -12,3 +12,5 @@ fields: - api_field: 'flowHookPoint' - field: 'org_id' - field: 'sharedflow' + - field: 'deletion_policy' + provider_only: true diff --git a/google-beta/services/apigee/resource_apigee_instance.go b/google-beta/services/apigee/resource_apigee_instance.go index 4d5ddd68caf..7e4454e274c 100644 --- a/google-beta/services/apigee/resource_apigee_instance.go +++ b/google-beta/services/apigee/resource_apigee_instance.go @@ -273,6 +273,19 @@ see [CidrRange](https://cloud.google.com/apigee/docs/reference/apis/apigee/rest/ the format: projects/*/regions/*/serviceAttachments/* Apigee customers can privately forward traffic to this service attachment using the PSC endpoints.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -450,6 +463,20 @@ func resourceApigeeInstanceRead(d *schema.ResourceData, meta interface{}) error log.Printf("[DEBUG] Finished reading ApigeeInstance %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceApigeeInstanceFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -477,6 +504,19 @@ func resourceApigeeInstanceRead(d *schema.ResourceData, meta interface{}) error } func resourceApigeeInstanceUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceApigeeInstance().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceApigeeInstanceRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -572,6 +612,13 @@ func resourceApigeeInstanceUpdate(d *schema.ResourceData, meta interface{}) erro } func resourceApigeeInstanceDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ApigeeInstance without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Instance %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/apigee/resource_apigee_instance_attachment.go b/google-beta/services/apigee/resource_apigee_instance_attachment.go index 2ea713b6ac1..e8908961c91 100644 --- a/google-beta/services/apigee/resource_apigee_instance_attachment.go +++ b/google-beta/services/apigee/resource_apigee_instance_attachment.go @@ -100,6 +100,7 @@ func ResourceApigeeInstanceAttachment() *schema.Resource { return &schema.Resource{ Create: resourceApigeeInstanceAttachmentCreate, Read: resourceApigeeInstanceAttachmentRead, + Update: resourceApigeeInstanceAttachmentUpdate, Delete: resourceApigeeInstanceAttachmentDelete, Importer: &schema.ResourceImporter{ @@ -149,6 +150,19 @@ in the format 'organizations/{{org_name}}/instances/{{instance_name}}'.`, Computed: true, Description: `The name of the newly created attachment (output parameter).`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -290,6 +304,20 @@ func resourceApigeeInstanceAttachmentRead(d *schema.ResourceData, meta interface log.Printf("[DEBUG] Finished reading ApigeeInstanceAttachment %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceApigeeInstanceAttachmentFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -316,7 +344,19 @@ func resourceApigeeInstanceAttachmentRead(d *schema.ResourceData, meta interface return nil } +func resourceApigeeInstanceAttachmentUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceApigeeInstanceAttachmentRead(d, meta) +} + func resourceApigeeInstanceAttachmentDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ApigeeInstanceAttachment without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing InstanceAttachment %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/apigee/resource_apigee_instance_attachment_generated_meta.yaml b/google-beta/services/apigee/resource_apigee_instance_attachment_generated_meta.yaml index f0429e41b93..4f3a367ea81 100644 --- a/google-beta/services/apigee/resource_apigee_instance_attachment_generated_meta.yaml +++ b/google-beta/services/apigee/resource_apigee_instance_attachment_generated_meta.yaml @@ -11,3 +11,5 @@ fields: - field: instance_id provider_only: true - api_field: name + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/apigee/resource_apigee_instance_generated_meta.yaml b/google-beta/services/apigee/resource_apigee_instance_generated_meta.yaml index 4bd173be83f..81aedb22c52 100644 --- a/google-beta/services/apigee/resource_apigee_instance_generated_meta.yaml +++ b/google-beta/services/apigee/resource_apigee_instance_generated_meta.yaml @@ -22,3 +22,5 @@ fields: - api_field: peeringCidrRange - api_field: port - api_field: serviceAttachment + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/apigee/resource_apigee_keystores_aliases_pkcs12.go b/google-beta/services/apigee/resource_apigee_keystores_aliases_pkcs12.go index 6320aa957ca..1a21fed7f13 100644 --- a/google-beta/services/apigee/resource_apigee_keystores_aliases_pkcs12.go +++ b/google-beta/services/apigee/resource_apigee_keystores_aliases_pkcs12.go @@ -26,6 +26,7 @@ import ( "reflect" "time" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-google-beta/google-beta/registry" "github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource" @@ -36,6 +37,7 @@ func ResourceApigeeKeystoresAliasesPkcs12() *schema.Resource { return &schema.Resource{ Create: ResourceApigeeKeystoresAliasesPkcs12Create, Read: ResourceApigeeKeystoresAliasesPkcs12Read, + Update: ResourceApigeeKeystoresAliasesPkcs12Update, Delete: ResourceApigeeKeystoresAliasesPkcs12Delete, Importer: &schema.ResourceImporter{ @@ -47,6 +49,10 @@ func ResourceApigeeKeystoresAliasesPkcs12() *schema.Resource { Delete: schema.DefaultTimeout(20 * time.Minute), }, + CustomizeDiff: customdiff.All( + tpgresource.DefaultProviderDeletionPolicy("DELETE"), + ), + Schema: map[string]*schema.Schema{ "alias": { Type: schema.TypeString, @@ -172,6 +178,9 @@ Flag is set to Yes if the certificate is valid, No if expired, or Not yet if not Computed: true, Description: `Optional.Type of Alias`, }, + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end }, UseJSONNumber: true, } @@ -271,10 +280,29 @@ func ResourceApigeeKeystoresAliasesPkcs12Read(d *schema.ResourceData, meta inter return fmt.Errorf("Error reading KeystoreAliasesPkcs: %s", err) } + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + return nil } +// UDP update start +func ResourceApigeeKeystoresAliasesPkcs12Update(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return ResourceApigeeKeystoresAliasesPkcs12Read(d, meta) +} + +//UDP update end + func ResourceApigeeKeystoresAliasesPkcs12Delete(d *schema.ResourceData, meta interface{}) error { + + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { + return nil + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/apigee/resource_apigee_keystores_aliases_pkcs12_meta.yaml b/google-beta/services/apigee/resource_apigee_keystores_aliases_pkcs12_meta.yaml index 7b293a84896..bee4ad4f9ee 100644 --- a/google-beta/services/apigee/resource_apigee_keystores_aliases_pkcs12_meta.yaml +++ b/google-beta/services/apigee/resource_apigee_keystores_aliases_pkcs12_meta.yaml @@ -25,3 +25,5 @@ fields: - field: 'org_id' - field: 'password' - api_field: 'type' + - field: 'deletion_policy' + provider_only: true diff --git a/google-beta/services/apigee/resource_apigee_keystores_aliases_self_signed_cert.go b/google-beta/services/apigee/resource_apigee_keystores_aliases_self_signed_cert.go index 04cc49dd90a..d2bad3e659f 100644 --- a/google-beta/services/apigee/resource_apigee_keystores_aliases_self_signed_cert.go +++ b/google-beta/services/apigee/resource_apigee_keystores_aliases_self_signed_cert.go @@ -100,6 +100,7 @@ func ResourceApigeeKeystoresAliasesSelfSignedCert() *schema.Resource { return &schema.Resource{ Create: resourceApigeeKeystoresAliasesSelfSignedCertCreate, Read: resourceApigeeKeystoresAliasesSelfSignedCertRead, + Update: resourceApigeeKeystoresAliasesSelfSignedCertUpdate, Delete: resourceApigeeKeystoresAliasesSelfSignedCertDelete, Importer: &schema.ResourceImporter{ @@ -335,6 +336,19 @@ Flag is set to Yes if the certificate is valid, No if expired, or Not yet if not Computed: true, Description: `Optional.Type of Alias`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -485,6 +499,20 @@ func resourceApigeeKeystoresAliasesSelfSignedCertRead(d *schema.ResourceData, me log.Printf("[DEBUG] Finished reading ApigeeKeystoresAliasesSelfSignedCert %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceApigeeKeystoresAliasesSelfSignedCertFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -523,7 +551,19 @@ func resourceApigeeKeystoresAliasesSelfSignedCertRead(d *schema.ResourceData, me return nil } +func resourceApigeeKeystoresAliasesSelfSignedCertUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceApigeeKeystoresAliasesSelfSignedCertRead(d, meta) +} + func resourceApigeeKeystoresAliasesSelfSignedCertDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ApigeeKeystoresAliasesSelfSignedCert without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing KeystoresAliasesSelfSignedCert %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/apigee/resource_apigee_keystores_aliases_self_signed_cert_generated_meta.yaml b/google-beta/services/apigee/resource_apigee_keystores_aliases_self_signed_cert_generated_meta.yaml index d1d905ddf99..9d4602046b2 100644 --- a/google-beta/services/apigee/resource_apigee_keystores_aliases_self_signed_cert_generated_meta.yaml +++ b/google-beta/services/apigee/resource_apigee_keystores_aliases_self_signed_cert_generated_meta.yaml @@ -37,3 +37,5 @@ fields: - api_field: subject.state - api_field: subjectAlternativeDnsNames.subjectAlternativeName - api_field: type + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/apigee/resource_apigee_nat_address.go b/google-beta/services/apigee/resource_apigee_nat_address.go index ff9933f46ed..3c363b9988c 100644 --- a/google-beta/services/apigee/resource_apigee_nat_address.go +++ b/google-beta/services/apigee/resource_apigee_nat_address.go @@ -183,6 +183,19 @@ in the format 'organizations/{{org_name}}/instances/{{instance_name}}'.`, Computed: true, Description: `State of the NAT IP address.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -337,6 +350,20 @@ func resourceApigeeNatAddressRead(d *schema.ResourceData, meta interface{}) erro return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceApigeeNatAddressFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -364,6 +391,19 @@ func resourceApigeeNatAddressRead(d *schema.ResourceData, meta interface{}) erro } func resourceApigeeNatAddressUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceApigeeNatAddress().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceApigeeNatAddressRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -402,6 +442,13 @@ func resourceApigeeNatAddressUpdate(d *schema.ResourceData, meta interface{}) er } func resourceApigeeNatAddressDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ApigeeNatAddress without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing NatAddress %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/apigee/resource_apigee_nat_address_generated_meta.yaml b/google-beta/services/apigee/resource_apigee_nat_address_generated_meta.yaml index 1d1868ce6f5..50e0a46c998 100644 --- a/google-beta/services/apigee/resource_apigee_nat_address_generated_meta.yaml +++ b/google-beta/services/apigee/resource_apigee_nat_address_generated_meta.yaml @@ -13,3 +13,5 @@ fields: - api_field: ipAddress - api_field: name - api_field: state + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/apigee/resource_apigee_organization.go b/google-beta/services/apigee/resource_apigee_organization.go index c0c1dff7f52..210d93b37ef 100644 --- a/google-beta/services/apigee/resource_apigee_organization.go +++ b/google-beta/services/apigee/resource_apigee_organization.go @@ -274,6 +274,19 @@ Valid only when 'RuntimeType' is CLOUD. A base64-encoded string.`, Description: `Output only. Subscription type of the Apigee organization. Valid values include trial (free, limited, and for evaluation purposes only) or paid (full subscription has been purchased).`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -474,6 +487,20 @@ func resourceApigeeOrganizationRead(d *schema.ResourceData, meta interface{}) er log.Printf("[DEBUG] Finished reading ApigeeOrganization %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceApigeeOrganizationFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -495,6 +522,19 @@ func resourceApigeeOrganizationRead(d *schema.ResourceData, meta interface{}) er } func resourceApigeeOrganizationUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceApigeeOrganization().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceApigeeOrganizationRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -626,6 +666,13 @@ func resourceApigeeOrganizationUpdate(d *schema.ResourceData, meta interface{}) } func resourceApigeeOrganizationDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ApigeeOrganization without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Organization %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/apigee/resource_apigee_organization_generated_meta.yaml b/google-beta/services/apigee/resource_apigee_organization_generated_meta.yaml index 05277cad850..399a63256af 100644 --- a/google-beta/services/apigee/resource_apigee_organization_generated_meta.yaml +++ b/google-beta/services/apigee/resource_apigee_organization_generated_meta.yaml @@ -28,3 +28,5 @@ fields: - api_field: runtimeDatabaseEncryptionKeyName - api_field: runtimeType - api_field: subscriptionType + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/apigee/resource_apigee_security_action.go b/google-beta/services/apigee/resource_apigee_security_action.go index 8869141afea..ba58a971cda 100644 --- a/google-beta/services/apigee/resource_apigee_security_action.go +++ b/google-beta/services/apigee/resource_apigee_security_action.go @@ -100,6 +100,7 @@ func ResourceApigeeSecurityAction() *schema.Resource { return &schema.Resource{ Create: resourceApigeeSecurityActionCreate, Read: resourceApigeeSecurityActionRead, + Update: resourceApigeeSecurityActionUpdate, Delete: resourceApigeeSecurityActionDelete, Importer: &schema.ResourceImporter{ @@ -391,6 +392,19 @@ Offsets other than "Z" are also accepted. Examples: "2014-10-02T15:01:23Z", "201 Uses RFC 3339, where generated output will always be Z-normalized and uses 0, 3, 6 or 9 fractional digits. Offsets other than "Z" are also accepted. Examples: "2014-10-02T15:01:23Z", "2014-10-02T15:01:23.045123456Z" or "2014-10-02T15:01:23+05:30".`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -554,6 +568,20 @@ func resourceApigeeSecurityActionRead(d *schema.ResourceData, meta interface{}) log.Printf("[DEBUG] Finished reading ApigeeSecurityAction %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceApigeeSecurityActionFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -586,7 +614,19 @@ func resourceApigeeSecurityActionRead(d *schema.ResourceData, meta interface{}) return nil } +func resourceApigeeSecurityActionUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceApigeeSecurityActionRead(d, meta) +} + func resourceApigeeSecurityActionDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ApigeeSecurityAction without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing SecurityAction %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/apigee/resource_apigee_security_action_generated_meta.yaml b/google-beta/services/apigee/resource_apigee_security_action_generated_meta.yaml index e9b5e3370fa..773f22c53d7 100644 --- a/google-beta/services/apigee/resource_apigee_security_action_generated_meta.yaml +++ b/google-beta/services/apigee/resource_apigee_security_action_generated_meta.yaml @@ -35,3 +35,5 @@ fields: - api_field: state - api_field: ttl - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/apigee/resource_apigee_security_feedback.go b/google-beta/services/apigee/resource_apigee_security_feedback.go index ef98a156650..3af53ee840f 100644 --- a/google-beta/services/apigee/resource_apigee_security_feedback.go +++ b/google-beta/services/apigee/resource_apigee_security_feedback.go @@ -188,6 +188,19 @@ in the format 'organizations/{{org_name}}/securityFeedback/{{feedback_id}}'.`, Computed: true, Description: `The time when this specific feedback id was updated.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -306,6 +319,20 @@ func resourceApigeeSecurityFeedbackRead(d *schema.ResourceData, meta interface{} log.Printf("[DEBUG] Finished reading ApigeeSecurityFeedback %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceApigeeSecurityFeedbackFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -315,6 +342,19 @@ func resourceApigeeSecurityFeedbackRead(d *schema.ResourceData, meta interface{} } func resourceApigeeSecurityFeedbackUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceApigeeSecurityFeedback().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceApigeeSecurityFeedbackRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -389,6 +429,13 @@ func resourceApigeeSecurityFeedbackUpdate(d *schema.ResourceData, meta interface } func resourceApigeeSecurityFeedbackDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ApigeeSecurityFeedback without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing SecurityFeedback %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/apigee/resource_apigee_security_feedback_generated_meta.yaml b/google-beta/services/apigee/resource_apigee_security_feedback_generated_meta.yaml index bada62bba17..30ca4b364c7 100644 --- a/google-beta/services/apigee/resource_apigee_security_feedback_generated_meta.yaml +++ b/google-beta/services/apigee/resource_apigee_security_feedback_generated_meta.yaml @@ -20,3 +20,5 @@ fields: provider_only: true - api_field: reason - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/apigee/resource_apigee_security_monitoring_condition.go b/google-beta/services/apigee/resource_apigee_security_monitoring_condition.go index 24a90b103c3..6c2282cf955 100644 --- a/google-beta/services/apigee/resource_apigee_security_monitoring_condition.go +++ b/google-beta/services/apigee/resource_apigee_security_monitoring_condition.go @@ -173,6 +173,19 @@ in the format 'organizations/{{org_name}}/securityMonitoringConditions/{{conditi Computed: true, Description: `The timestamp at which this profile was most recently updated.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -279,6 +292,20 @@ func resourceApigeeSecurityMonitoringConditionRead(d *schema.ResourceData, meta log.Printf("[DEBUG] Finished reading ApigeeSecurityMonitoringCondition %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceApigeeSecurityMonitoringConditionFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -288,6 +315,19 @@ func resourceApigeeSecurityMonitoringConditionRead(d *schema.ResourceData, meta } func resourceApigeeSecurityMonitoringConditionUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceApigeeSecurityMonitoringCondition().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceApigeeSecurityMonitoringConditionRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -350,6 +390,13 @@ func resourceApigeeSecurityMonitoringConditionUpdate(d *schema.ResourceData, met } func resourceApigeeSecurityMonitoringConditionDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ApigeeSecurityMonitoringCondition without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing SecurityMonitoringCondition %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/apigee/resource_apigee_security_monitoring_condition_generated_meta.yaml b/google-beta/services/apigee/resource_apigee_security_monitoring_condition_generated_meta.yaml index e2ce4aad324..d5a21a1b3a6 100644 --- a/google-beta/services/apigee/resource_apigee_security_monitoring_condition_generated_meta.yaml +++ b/google-beta/services/apigee/resource_apigee_security_monitoring_condition_generated_meta.yaml @@ -19,3 +19,5 @@ fields: - api_field: totalDeployedResources - api_field: totalMonitoredResources - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/apigee/resource_apigee_security_profile_v2.go b/google-beta/services/apigee/resource_apigee_security_profile_v2.go index 60c850cbdec..d98442e5fc0 100644 --- a/google-beta/services/apigee/resource_apigee_security_profile_v2.go +++ b/google-beta/services/apigee/resource_apigee_security_profile_v2.go @@ -167,6 +167,19 @@ in the format 'organizations/{{org_name}}/securityProfilesV2/{{profile_id}}'.`, Computed: true, Description: `The timestamp at which this profile was most recently updated.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -267,6 +280,20 @@ func resourceApigeeSecurityProfileV2Read(d *schema.ResourceData, meta interface{ log.Printf("[DEBUG] Finished reading ApigeeSecurityProfileV2 %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceApigeeSecurityProfileV2Flatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -276,6 +303,19 @@ func resourceApigeeSecurityProfileV2Read(d *schema.ResourceData, meta interface{ } func resourceApigeeSecurityProfileV2Update(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceApigeeSecurityProfileV2().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceApigeeSecurityProfileV2Read(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -351,6 +391,13 @@ func resourceApigeeSecurityProfileV2Update(d *schema.ResourceData, meta interfac } func resourceApigeeSecurityProfileV2Delete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ApigeeSecurityProfileV2 without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing SecurityProfileV2 %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/apigee/resource_apigee_security_profile_v2_generated_meta.yaml b/google-beta/services/apigee/resource_apigee_security_profile_v2_generated_meta.yaml index 57a076a122e..e668c83ff7b 100644 --- a/google-beta/services/apigee/resource_apigee_security_profile_v2_generated_meta.yaml +++ b/google-beta/services/apigee/resource_apigee_security_profile_v2_generated_meta.yaml @@ -19,3 +19,5 @@ fields: - field: profile_id provider_only: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/apigee/resource_apigee_sharedflow.go b/google-beta/services/apigee/resource_apigee_sharedflow.go index de82d833fdf..cf07aef1f29 100644 --- a/google-beta/services/apigee/resource_apigee_sharedflow.go +++ b/google-beta/services/apigee/resource_apigee_sharedflow.go @@ -50,6 +50,7 @@ func ResourceApigeeSharedFlow() *schema.Resource { }, CustomizeDiff: customdiff.All( + tpgresource.DefaultProviderDeletionPolicy("DELETE"), /* If any of the config_bundle, detect_md5hash or md5hash is changed, then an update is expected, so we tell Terraform core to expect update on meta_data, @@ -150,6 +151,9 @@ func ResourceApigeeSharedFlow() *schema.Resource { return true }, }, + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end }, UseJSONNumber: true, } @@ -221,6 +225,11 @@ func resourceApigeeSharedFlowCreate(d *schema.ResourceData, meta interface{}) er } func resourceApigeeSharedFlowUpdate(d *schema.ResourceData, meta interface{}) error { + + if tpgresource.DeletionPolicyPreUpdate(d, ResourceApigeeSharedFlow) { + return ResourceApigeeSharedFlow().Read(d, meta) + } + //For how sharedflow api is implemented, just treat an update as create, when the name is same, it will create a new revision return resourceApigeeSharedFlowCreate(d, meta) } @@ -277,6 +286,11 @@ func resourceApigeeSharedFlowRead(d *schema.ResourceData, meta interface{}) erro d.Set("md5hash", "UNKNOWN") d.Set("detect_md5hash", "UNKNOWN") } + + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + return nil } @@ -300,6 +314,13 @@ func getApigeeSharedFlowLastModifiedAt(d *schema.ResourceData) string { func resourceApigeeSharedFlowDelete(d *schema.ResourceData, meta interface{}) error { log.Printf("[DEBUG] resourceApigeeSharedFlowDelete") + + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { + return nil + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/apigee/resource_apigee_sharedflow_deployment.go b/google-beta/services/apigee/resource_apigee_sharedflow_deployment.go index bd2b42ce861..47fb214827b 100644 --- a/google-beta/services/apigee/resource_apigee_sharedflow_deployment.go +++ b/google-beta/services/apigee/resource_apigee_sharedflow_deployment.go @@ -21,6 +21,7 @@ import ( "log" "time" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-google-beta/google-beta/registry" "github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource" @@ -44,6 +45,10 @@ func ResourceApigeeSharedFlowDeployment() *schema.Resource { Delete: schema.DefaultTimeout(20 * time.Minute), }, + CustomizeDiff: customdiff.All( + tpgresource.DefaultProviderDeletionPolicy("DELETE"), + ), + Schema: map[string]*schema.Schema{ "environment": { Type: schema.TypeString, @@ -74,6 +79,9 @@ func ResourceApigeeSharedFlowDeployment() *schema.Resource { ForceNew: true, Description: `Id of the Sharedflow to be deployed.`, }, + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end }, UseJSONNumber: true, } @@ -156,6 +164,10 @@ func resourceApigeeSharedflowDeploymentRead(d *schema.ResourceData, meta interfa } log.Printf("[DEBUG] ApigeeSharedflowDeployment deployStartTime %s", res["deployStartTime"]) + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + return nil } @@ -166,6 +178,10 @@ func resourceApigeeSharedflowDeploymentUpdate(d *schema.ResourceData, meta inter return err } + if tpgresource.DeletionPolicyPreUpdate(d, ResourceApigeeSharedFlowDeployment) { + return ResourceApigeeSharedFlowDeployment().Read(d, meta) + } + url, err := tpgresource.ReplaceVars(d, config, transport_tpg.BaseUrl(Product, config)+"organizations/{{org_id}}/environments/{{environment}}/sharedflows/{{sharedflow_id}}/revisions/{{revision}}/deployments?override=true&serviceAccount={{service_account}}") if err != nil { return err @@ -204,6 +220,13 @@ func resourceApigeeSharedflowDeploymentUpdate(d *schema.ResourceData, meta inter } func resourceApigeeSharedflowDeploymentDelete(d *schema.ResourceData, meta interface{}) error { + + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { + return nil + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/apigee/resource_apigee_sharedflow_deployment_meta.yaml b/google-beta/services/apigee/resource_apigee_sharedflow_deployment_meta.yaml index 7b84ac919a8..6a6afd14f03 100644 --- a/google-beta/services/apigee/resource_apigee_sharedflow_deployment_meta.yaml +++ b/google-beta/services/apigee/resource_apigee_sharedflow_deployment_meta.yaml @@ -11,3 +11,5 @@ fields: - api_field: 'revision' - field: 'service_account' - field: 'sharedflow_id' + - field: 'deletion_policy' + provider_only: true diff --git a/google-beta/services/apigee/resource_apigee_sharedflow_meta.yaml b/google-beta/services/apigee/resource_apigee_sharedflow_meta.yaml index 5487bfd6e52..7c1fc9d6964 100644 --- a/google-beta/services/apigee/resource_apigee_sharedflow_meta.yaml +++ b/google-beta/services/apigee/resource_apigee_sharedflow_meta.yaml @@ -16,3 +16,5 @@ fields: - api_field: 'name' - field: 'org_id' - api_field: 'revision' + - field: 'deletion_policy' + provider_only: true diff --git a/google-beta/services/apigee/resource_apigee_space.go b/google-beta/services/apigee/resource_apigee_space.go index 0e23950762e..8b086d94f2d 100644 --- a/google-beta/services/apigee/resource_apigee_space.go +++ b/google-beta/services/apigee/resource_apigee_space.go @@ -146,6 +146,19 @@ func ResourceApigeeSpace() *schema.Resource { Computed: true, Description: `Last modified timestamp of the space.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -240,6 +253,20 @@ func resourceApigeeSpaceRead(d *schema.ResourceData, meta interface{}) error { log.Printf("[DEBUG] Finished reading ApigeeSpace %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceApigeeSpaceFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -249,6 +276,19 @@ func resourceApigeeSpaceRead(d *schema.ResourceData, meta interface{}) error { } func resourceApigeeSpaceUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceApigeeSpace().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceApigeeSpaceRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -314,6 +354,13 @@ func resourceApigeeSpaceUpdate(d *schema.ResourceData, meta interface{}) error { } func resourceApigeeSpaceDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ApigeeSpace without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Space %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/apigee/resource_apigee_space_generated_meta.yaml b/google-beta/services/apigee/resource_apigee_space_generated_meta.yaml index b5d15f1d070..ffbf5900c9d 100644 --- a/google-beta/services/apigee/resource_apigee_space_generated_meta.yaml +++ b/google-beta/services/apigee/resource_apigee_space_generated_meta.yaml @@ -15,3 +15,5 @@ fields: - field: space_id provider_only: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/apigee/resource_apigee_sync_authorization.go b/google-beta/services/apigee/resource_apigee_sync_authorization.go index 88d5d53c288..b379b52fed6 100644 --- a/google-beta/services/apigee/resource_apigee_sync_authorization.go +++ b/google-beta/services/apigee/resource_apigee_sync_authorization.go @@ -287,6 +287,7 @@ func resourceApigeeSyncAuthorizationRead(d *schema.ResourceData, meta interface{ } func resourceApigeeSyncAuthorizationUpdate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/apigee/resource_apigee_target_server.go b/google-beta/services/apigee/resource_apigee_target_server.go index 25fe6f04673..80cb4b802bd 100644 --- a/google-beta/services/apigee/resource_apigee_target_server.go +++ b/google-beta/services/apigee/resource_apigee_target_server.go @@ -256,6 +256,19 @@ in the format 'organizations/{{org_name}}/environments/{{env_name}}'.`, }, }, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -402,6 +415,20 @@ func resourceApigeeTargetServerRead(d *schema.ResourceData, meta interface{}) er log.Printf("[DEBUG] Finished reading ApigeeTargetServer %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceApigeeTargetServerFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -429,6 +456,19 @@ func resourceApigeeTargetServerRead(d *schema.ResourceData, meta interface{}) er } func resourceApigeeTargetServerUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceApigeeTargetServer().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceApigeeTargetServerRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -530,6 +570,13 @@ func resourceApigeeTargetServerUpdate(d *schema.ResourceData, meta interface{}) } func resourceApigeeTargetServerDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ApigeeTargetServer without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing TargetServer %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/apigee/resource_apigee_target_server_generated_meta.yaml b/google-beta/services/apigee/resource_apigee_target_server_generated_meta.yaml index 06c2dc5eab5..03c23082108 100644 --- a/google-beta/services/apigee/resource_apigee_target_server_generated_meta.yaml +++ b/google-beta/services/apigee/resource_apigee_target_server_generated_meta.yaml @@ -26,3 +26,5 @@ fields: - api_field: sSLInfo.keyStore - api_field: sSLInfo.protocols - api_field: sSLInfo.trustStore + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/apihub/resource_apihub_api_hub_instance.go b/google-beta/services/apihub/resource_apihub_api_hub_instance.go index a013a21fc96..4121f0d36d6 100644 --- a/google-beta/services/apihub/resource_apihub_api_hub_instance.go +++ b/google-beta/services/apihub/resource_apihub_api_hub_instance.go @@ -478,7 +478,7 @@ func resourceApihubApiHubInstanceRead(d *schema.ResourceData, meta interface{}) } func resourceApihubApiHubInstanceUpdate(d *schema.ResourceData, meta interface{}) error { - // Only the root field "labels", "terraform_labels", and virtual fields are mutable + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable return resourceApihubApiHubInstanceRead(d, meta) } diff --git a/google-beta/services/apihub/resource_apihub_curation.go b/google-beta/services/apihub/resource_apihub_curation.go index ded6578c432..abb5d01b734 100644 --- a/google-beta/services/apihub/resource_apihub_curation.go +++ b/google-beta/services/apihub/resource_apihub_curation.go @@ -115,6 +115,7 @@ func ResourceApihubCuration() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -290,6 +291,18 @@ Format is Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -429,6 +442,19 @@ func resourceApihubCurationRead(d *schema.ResourceData, meta interface{}) error log.Printf("[DEBUG] Finished reading ApihubCuration %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Curation: %s", err) } @@ -466,6 +492,19 @@ func resourceApihubCurationRead(d *schema.ResourceData, meta interface{}) error } func resourceApihubCurationUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceApihubCuration().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceApihubCurationRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -567,6 +606,13 @@ func resourceApihubCurationUpdate(d *schema.ResourceData, meta interface{}) erro } func resourceApihubCurationDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ApihubCuration without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Curation %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/apihub/resource_apihub_curation_generated_meta.yaml b/google-beta/services/apihub/resource_apihub_curation_generated_meta.yaml index 0b7387eb7d6..cb6ee93ceba 100644 --- a/google-beta/services/apihub/resource_apihub_curation_generated_meta.yaml +++ b/google-beta/services/apihub/resource_apihub_curation_generated_meta.yaml @@ -24,3 +24,5 @@ fields: - api_field: pluginInstanceActions.actionId - api_field: pluginInstanceActions.pluginInstance - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/apihub/resource_apihub_plugin.go b/google-beta/services/apihub/resource_apihub_plugin.go index 1b5cad07ec8..4619f8e31d0 100644 --- a/google-beta/services/apihub/resource_apihub_plugin.go +++ b/google-beta/services/apihub/resource_apihub_plugin.go @@ -100,6 +100,7 @@ func ResourceApihubPlugin() *schema.Resource { return &schema.Resource{ Create: resourceApihubPluginCreate, Read: resourceApihubPluginRead, + Update: resourceApihubPluginUpdate, Delete: resourceApihubPluginDelete, Importer: &schema.ResourceImporter{ @@ -113,6 +114,7 @@ func ResourceApihubPlugin() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -466,6 +468,18 @@ DISABLED`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -629,6 +643,19 @@ func resourceApihubPluginRead(d *schema.ResourceData, meta interface{}) error { log.Printf("[DEBUG] Finished reading ApihubPlugin %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Plugin: %s", err) } @@ -665,7 +692,19 @@ func resourceApihubPluginRead(d *schema.ResourceData, meta interface{}) error { return nil } +func resourceApihubPluginUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceApihubPluginRead(d, meta) +} + func resourceApihubPluginDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ApihubPlugin without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Plugin %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/apihub/resource_apihub_plugin_generated_meta.yaml b/google-beta/services/apihub/resource_apihub_plugin_generated_meta.yaml index 463f32c0e84..6dfd93d75b7 100644 --- a/google-beta/services/apihub/resource_apihub_plugin_generated_meta.yaml +++ b/google-beta/services/apihub/resource_apihub_plugin_generated_meta.yaml @@ -39,3 +39,5 @@ fields: provider_only: true - api_field: state - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/apihub/resource_apihub_plugin_instance.go b/google-beta/services/apihub/resource_apihub_plugin_instance.go index 9d22529e597..2c842654792 100644 --- a/google-beta/services/apihub/resource_apihub_plugin_instance.go +++ b/google-beta/services/apihub/resource_apihub_plugin_instance.go @@ -115,6 +115,7 @@ func ResourceApihubPluginInstance() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -532,6 +533,18 @@ DELETING`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -692,6 +705,19 @@ func resourceApihubPluginInstanceRead(d *schema.ResourceData, meta interface{}) log.Printf("[DEBUG] Finished reading ApihubPluginInstance %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading PluginInstance: %s", err) } @@ -735,6 +761,19 @@ func resourceApihubPluginInstanceRead(d *schema.ResourceData, meta interface{}) } func resourceApihubPluginInstanceUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceApihubPluginInstance().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceApihubPluginInstanceRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -828,6 +867,13 @@ func resourceApihubPluginInstanceUpdate(d *schema.ResourceData, meta interface{} } func resourceApihubPluginInstanceDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ApihubPluginInstance without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing PluginInstance %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/apihub/resource_apihub_plugin_instance_generated_meta.yaml b/google-beta/services/apihub/resource_apihub_plugin_instance_generated_meta.yaml index 8444249568f..67c53dba1b1 100644 --- a/google-beta/services/apihub/resource_apihub_plugin_instance_generated_meta.yaml +++ b/google-beta/services/apihub/resource_apihub_plugin_instance_generated_meta.yaml @@ -41,3 +41,5 @@ fields: provider_only: true - api_field: state - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/apikeys/resource_apikeys_key.go b/google-beta/services/apikeys/resource_apikeys_key.go index be4af72a0af..1905394d3fb 100644 --- a/google-beta/services/apikeys/resource_apikeys_key.go +++ b/google-beta/services/apikeys/resource_apikeys_key.go @@ -49,6 +49,7 @@ func ResourceApikeysKey() *schema.Resource { }, CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Schema: map[string]*schema.Schema{ @@ -102,6 +103,10 @@ func ResourceApikeysKey() *schema.Resource { Computed: true, Description: "Output only. Unique id in UUID4 format.", }, + + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end }, } } @@ -351,9 +356,18 @@ func resourceApikeysKeyRead(d *schema.ResourceData, meta interface{}) error { return fmt.Errorf("error setting uid in state: %s", err) } + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + return nil } func resourceApikeysKeyUpdate(d *schema.ResourceData, meta interface{}) error { + + if tpgresource.DeletionPolicyPreUpdate(d, ResourceApikeysKey) { + return ResourceApikeysKey().Read(d, meta) + } + config := meta.(*transport_tpg.Config) project, err := tpgresource.GetProject(d, config) if err != nil { @@ -401,6 +415,13 @@ func resourceApikeysKeyUpdate(d *schema.ResourceData, meta interface{}) error { } func resourceApikeysKeyDelete(d *schema.ResourceData, meta interface{}) error { + + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { + return nil + } + config := meta.(*transport_tpg.Config) project, err := tpgresource.GetProject(d, config) if err != nil { diff --git a/google-beta/services/apikeys/resource_apikeys_key_meta.yaml b/google-beta/services/apikeys/resource_apikeys_key_meta.yaml index aa8ab119509..38ebc78a221 100644 --- a/google-beta/services/apikeys/resource_apikeys_key_meta.yaml +++ b/google-beta/services/apikeys/resource_apikeys_key_meta.yaml @@ -19,3 +19,5 @@ fields: - api_field: 'restrictions.serverKeyRestrictions.allowedIps' - api_field: 'uid' - api_field: 'serviceAccountEmail' + - field: 'deletion_policy' + provider_only: true diff --git a/google-beta/services/appengine/resource_app_engine_application_url_dispatch_rules.go b/google-beta/services/appengine/resource_app_engine_application_url_dispatch_rules.go index f12278615b0..00d9b82cdc6 100644 --- a/google-beta/services/appengine/resource_app_engine_application_url_dispatch_rules.go +++ b/google-beta/services/appengine/resource_app_engine_application_url_dispatch_rules.go @@ -115,6 +115,7 @@ func ResourceAppEngineApplicationUrlDispatchRules() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -167,6 +168,18 @@ Defaults to matching all domains: "*".`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -303,6 +316,19 @@ func resourceAppEngineApplicationUrlDispatchRulesRead(d *schema.ResourceData, me log.Printf("[DEBUG] Finished reading AppEngineApplicationUrlDispatchRules %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading ApplicationUrlDispatchRules: %s", err) } @@ -328,6 +354,19 @@ func resourceAppEngineApplicationUrlDispatchRulesRead(d *schema.ResourceData, me } func resourceAppEngineApplicationUrlDispatchRulesUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceAppEngineApplicationUrlDispatchRules().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceAppEngineApplicationUrlDispatchRulesRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -410,6 +449,13 @@ func resourceAppEngineApplicationUrlDispatchRulesUpdate(d *schema.ResourceData, } func resourceAppEngineApplicationUrlDispatchRulesDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy AppEngineApplicationUrlDispatchRules without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing ApplicationUrlDispatchRules %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/appengine/resource_app_engine_application_url_dispatch_rules_generated_meta.yaml b/google-beta/services/appengine/resource_app_engine_application_url_dispatch_rules_generated_meta.yaml index 4dc64d4cdf1..ba3f29b969f 100644 --- a/google-beta/services/appengine/resource_app_engine_application_url_dispatch_rules_generated_meta.yaml +++ b/google-beta/services/appengine/resource_app_engine_application_url_dispatch_rules_generated_meta.yaml @@ -10,3 +10,5 @@ fields: - api_field: dispatchRules.domain - api_field: dispatchRules.path - api_field: dispatchRules.service + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/appengine/resource_app_engine_domain_mapping.go b/google-beta/services/appengine/resource_app_engine_domain_mapping.go index 8db7e1c9887..d2ec29f683d 100644 --- a/google-beta/services/appengine/resource_app_engine_domain_mapping.go +++ b/google-beta/services/appengine/resource_app_engine_domain_mapping.go @@ -115,6 +115,7 @@ func ResourceAppEngineDomainMapping() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -226,6 +227,18 @@ configuration in order to serve the application via this domain mapping.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -383,6 +396,19 @@ func resourceAppEngineDomainMappingRead(d *schema.ResourceData, meta interface{} return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading DomainMapping: %s", err) } @@ -414,6 +440,19 @@ func resourceAppEngineDomainMappingRead(d *schema.ResourceData, meta interface{} } func resourceAppEngineDomainMappingUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceAppEngineDomainMapping().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceAppEngineDomainMappingRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -515,6 +554,13 @@ func resourceAppEngineDomainMappingUpdate(d *schema.ResourceData, meta interface } func resourceAppEngineDomainMappingDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy AppEngineDomainMapping without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing DomainMapping %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/appengine/resource_app_engine_domain_mapping_generated_meta.yaml b/google-beta/services/appengine/resource_app_engine_domain_mapping_generated_meta.yaml index fde730706d6..df2ee204783 100644 --- a/google-beta/services/appengine/resource_app_engine_domain_mapping_generated_meta.yaml +++ b/google-beta/services/appengine/resource_app_engine_domain_mapping_generated_meta.yaml @@ -18,3 +18,5 @@ fields: - api_field: sslSettings.certificateId - api_field: sslSettings.pendingManagedCertificateId - api_field: sslSettings.sslManagementType + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/appengine/resource_app_engine_firewall_rule.go b/google-beta/services/appengine/resource_app_engine_firewall_rule.go index d06a2211e96..2cb0ecb73ae 100644 --- a/google-beta/services/appengine/resource_app_engine_firewall_rule.go +++ b/google-beta/services/appengine/resource_app_engine_firewall_rule.go @@ -115,6 +115,7 @@ func ResourceAppEngineFirewallRule() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -169,6 +170,18 @@ this rule can be modified by the user.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -363,6 +376,19 @@ func resourceAppEngineFirewallRuleRead(d *schema.ResourceData, meta interface{}) log.Printf("[DEBUG] Finished reading AppEngineFirewallRule %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading FirewallRule: %s", err) } @@ -394,6 +420,19 @@ func resourceAppEngineFirewallRuleRead(d *schema.ResourceData, meta interface{}) } func resourceAppEngineFirewallRuleUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceAppEngineFirewallRule().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceAppEngineFirewallRuleRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -518,6 +557,13 @@ func resourceAppEngineFirewallRuleUpdate(d *schema.ResourceData, meta interface{ } func resourceAppEngineFirewallRuleDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy AppEngineFirewallRule without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing FirewallRule %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/appengine/resource_app_engine_firewall_rule_generated_meta.yaml b/google-beta/services/appengine/resource_app_engine_firewall_rule_generated_meta.yaml index aa0cafd940b..fc277c42f64 100644 --- a/google-beta/services/appengine/resource_app_engine_firewall_rule_generated_meta.yaml +++ b/google-beta/services/appengine/resource_app_engine_firewall_rule_generated_meta.yaml @@ -11,3 +11,5 @@ fields: - api_field: description - api_field: priority - api_field: sourceRange + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/appengine/resource_app_engine_flexible_app_version.go b/google-beta/services/appengine/resource_app_engine_flexible_app_version.go index efdff3c055c..a7c693278dd 100644 --- a/google-beta/services/appengine/resource_app_engine_flexible_app_version.go +++ b/google-beta/services/appengine/resource_app_engine_flexible_app_version.go @@ -115,6 +115,7 @@ func ResourceAppEngineFlexibleAppVersion() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -986,6 +987,18 @@ Reserved names,"default", "latest", and any name with the prefix "ah-".`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -1298,6 +1311,18 @@ func resourceAppEngineFlexibleAppVersionRead(d *schema.ResourceData, meta interf return fmt.Errorf("Error setting delete_service_on_destroy: %s", err) } } + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading FlexibleAppVersion: %s", err) } @@ -1335,6 +1360,19 @@ func resourceAppEngineFlexibleAppVersionRead(d *schema.ResourceData, meta interf } func resourceAppEngineFlexibleAppVersionUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceAppEngineFlexibleAppVersion().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceAppEngineFlexibleAppVersionRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1582,6 +1620,13 @@ func resourceAppEngineFlexibleAppVersionUpdate(d *schema.ResourceData, meta inte } func resourceAppEngineFlexibleAppVersionDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy AppEngineFlexibleAppVersion without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing FlexibleAppVersion %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/appengine/resource_app_engine_flexible_app_version_generated_meta.yaml b/google-beta/services/appengine/resource_app_engine_flexible_app_version_generated_meta.yaml index 388ecd410ad..8173308d48e 100644 --- a/google-beta/services/appengine/resource_app_engine_flexible_app_version_generated_meta.yaml +++ b/google-beta/services/appengine/resource_app_engine_flexible_app_version_generated_meta.yaml @@ -113,3 +113,5 @@ fields: - api_field: id field: version_id - api_field: vpcAccessConnector.name + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/appengine/resource_app_engine_service_network_settings.go b/google-beta/services/appengine/resource_app_engine_service_network_settings.go index 5c9b7440625..b4a923b591b 100644 --- a/google-beta/services/appengine/resource_app_engine_service_network_settings.go +++ b/google-beta/services/appengine/resource_app_engine_service_network_settings.go @@ -341,6 +341,7 @@ func resourceAppEngineServiceNetworkSettingsRead(d *schema.ResourceData, meta in } func resourceAppEngineServiceNetworkSettingsUpdate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/appengine/resource_app_engine_service_split_traffic.go b/google-beta/services/appengine/resource_app_engine_service_split_traffic.go index 227b6730d27..b46161aa541 100644 --- a/google-beta/services/appengine/resource_app_engine_service_split_traffic.go +++ b/google-beta/services/appengine/resource_app_engine_service_split_traffic.go @@ -351,6 +351,7 @@ func resourceAppEngineServiceSplitTrafficRead(d *schema.ResourceData, meta inter } func resourceAppEngineServiceSplitTrafficUpdate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/appengine/resource_app_engine_standard_app_version.go b/google-beta/services/appengine/resource_app_engine_standard_app_version.go index 2449c643172..62a9db9a7e1 100644 --- a/google-beta/services/appengine/resource_app_engine_standard_app_version.go +++ b/google-beta/services/appengine/resource_app_engine_standard_app_version.go @@ -115,6 +115,7 @@ func ResourceAppEngineStandardAppVersion() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -562,6 +563,18 @@ Substitute '' with 'python', 'java', 'php', 'ruby', 'go' or 'nodejs'.` Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -815,6 +828,18 @@ func resourceAppEngineStandardAppVersionRead(d *schema.ResourceData, meta interf return fmt.Errorf("Error setting delete_service_on_destroy: %s", err) } } + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading StandardAppVersion: %s", err) } @@ -852,6 +877,19 @@ func resourceAppEngineStandardAppVersionRead(d *schema.ResourceData, meta interf } func resourceAppEngineStandardAppVersionUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceAppEngineStandardAppVersion().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceAppEngineStandardAppVersionRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1040,6 +1078,13 @@ func resourceAppEngineStandardAppVersionUpdate(d *schema.ResourceData, meta inte } func resourceAppEngineStandardAppVersionDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy AppEngineStandardAppVersion without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing StandardAppVersion %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/appengine/resource_app_engine_standard_app_version_generated_meta.yaml b/google-beta/services/appengine/resource_app_engine_standard_app_version_generated_meta.yaml index d29fd566fc0..c5657937fec 100644 --- a/google-beta/services/appengine/resource_app_engine_standard_app_version_generated_meta.yaml +++ b/google-beta/services/appengine/resource_app_engine_standard_app_version_generated_meta.yaml @@ -62,3 +62,5 @@ fields: field: version_id - api_field: vpcAccessConnector.egressSetting - api_field: vpcAccessConnector.name + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/apphub/resource_apphub_application.go b/google-beta/services/apphub/resource_apphub_application.go index 8a56df6dd09..1dd36915826 100644 --- a/google-beta/services/apphub/resource_apphub_application.go +++ b/google-beta/services/apphub/resource_apphub_application.go @@ -134,6 +134,7 @@ func ResourceApphubApplication() *schema.Resource { CustomizeDiff: customdiff.All( apphubApplicationCustomizeDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -337,6 +338,18 @@ DELETING`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -492,6 +505,19 @@ func resourceApphubApplicationRead(d *schema.ResourceData, meta interface{}) err log.Printf("[DEBUG] Finished reading ApphubApplication %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Application: %s", err) } @@ -529,6 +555,19 @@ func resourceApphubApplicationRead(d *schema.ResourceData, meta interface{}) err } func resourceApphubApplicationUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceApphubApplication().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceApphubApplicationRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -657,6 +696,13 @@ func resourceApphubApplicationUpdate(d *schema.ResourceData, meta interface{}) e } func resourceApphubApplicationDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ApphubApplication without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Application %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/apphub/resource_apphub_application_generated_meta.yaml b/google-beta/services/apphub/resource_apphub_application_generated_meta.yaml index adb1aee4918..8aecefb1fcf 100644 --- a/google-beta/services/apphub/resource_apphub_application_generated_meta.yaml +++ b/google-beta/services/apphub/resource_apphub_application_generated_meta.yaml @@ -28,3 +28,5 @@ fields: - api_field: state - api_field: uid - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/apphub/resource_apphub_boundary.go b/google-beta/services/apphub/resource_apphub_boundary.go index 678e59ba4a1..0401b6b9510 100644 --- a/google-beta/services/apphub/resource_apphub_boundary.go +++ b/google-beta/services/apphub/resource_apphub_boundary.go @@ -340,6 +340,7 @@ func resourceApphubBoundaryRead(d *schema.ResourceData, meta interface{}) error } func resourceApphubBoundaryUpdate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/apphub/resource_apphub_service.go b/google-beta/services/apphub/resource_apphub_service.go index b8a12fd90c9..4537d3dd62a 100644 --- a/google-beta/services/apphub/resource_apphub_service.go +++ b/google-beta/services/apphub/resource_apphub_service.go @@ -115,6 +115,7 @@ func ResourceApphubService() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -426,6 +427,18 @@ format.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -586,6 +599,19 @@ func resourceApphubServiceRead(d *schema.ResourceData, meta interface{}) error { log.Printf("[DEBUG] Finished reading ApphubService %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Service: %s", err) } @@ -629,6 +655,19 @@ func resourceApphubServiceRead(d *schema.ResourceData, meta interface{}) error { } func resourceApphubServiceUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceApphubService().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceApphubServiceRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -752,6 +791,13 @@ func resourceApphubServiceUpdate(d *schema.ResourceData, meta interface{}) error } func resourceApphubServiceDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ApphubService without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Service %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/apphub/resource_apphub_service_generated_meta.yaml b/google-beta/services/apphub/resource_apphub_service_generated_meta.yaml index b4316f6a9fa..8e9c5e7dfaa 100644 --- a/google-beta/services/apphub/resource_apphub_service_generated_meta.yaml +++ b/google-beta/services/apphub/resource_apphub_service_generated_meta.yaml @@ -42,3 +42,5 @@ fields: - api_field: state - api_field: uid - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/apphub/resource_apphub_service_project_attachment.go b/google-beta/services/apphub/resource_apphub_service_project_attachment.go index 29675db9b17..96c35ec3337 100644 --- a/google-beta/services/apphub/resource_apphub_service_project_attachment.go +++ b/google-beta/services/apphub/resource_apphub_service_project_attachment.go @@ -105,6 +105,7 @@ func ResourceApphubServiceProjectAttachment() *schema.Resource { return &schema.Resource{ Create: resourceApphubServiceProjectAttachmentCreate, Read: resourceApphubServiceProjectAttachmentRead, + Update: resourceApphubServiceProjectAttachmentUpdate, Delete: resourceApphubServiceProjectAttachmentDelete, Importer: &schema.ResourceImporter{ @@ -118,6 +119,7 @@ func ResourceApphubServiceProjectAttachment() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -181,6 +183,18 @@ are accepted. As output, this field will contain project number."`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -313,6 +327,19 @@ func resourceApphubServiceProjectAttachmentRead(d *schema.ResourceData, meta int log.Printf("[DEBUG] Finished reading ApphubServiceProjectAttachment %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading ServiceProjectAttachment: %s", err) } @@ -343,7 +370,19 @@ func resourceApphubServiceProjectAttachmentRead(d *schema.ResourceData, meta int return nil } +func resourceApphubServiceProjectAttachmentUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceApphubServiceProjectAttachmentRead(d, meta) +} + func resourceApphubServiceProjectAttachmentDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ApphubServiceProjectAttachment without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing ServiceProjectAttachment %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/apphub/resource_apphub_service_project_attachment_generated_meta.yaml b/google-beta/services/apphub/resource_apphub_service_project_attachment_generated_meta.yaml index 720303fd92a..f26ff3f4564 100644 --- a/google-beta/services/apphub/resource_apphub_service_project_attachment_generated_meta.yaml +++ b/google-beta/services/apphub/resource_apphub_service_project_attachment_generated_meta.yaml @@ -15,3 +15,5 @@ fields: provider_only: true - api_field: state - api_field: uid + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/apphub/resource_apphub_workload.go b/google-beta/services/apphub/resource_apphub_workload.go index 89029c0deca..64cbbdbd080 100644 --- a/google-beta/services/apphub/resource_apphub_workload.go +++ b/google-beta/services/apphub/resource_apphub_workload.go @@ -115,6 +115,7 @@ func ResourceApphubWorkload() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -409,6 +410,18 @@ func ResourceApphubWorkload() *schema.Resource { Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -569,6 +582,19 @@ func resourceApphubWorkloadRead(d *schema.ResourceData, meta interface{}) error log.Printf("[DEBUG] Finished reading ApphubWorkload %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Workload: %s", err) } @@ -612,6 +638,19 @@ func resourceApphubWorkloadRead(d *schema.ResourceData, meta interface{}) error } func resourceApphubWorkloadUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceApphubWorkload().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceApphubWorkloadRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -735,6 +774,13 @@ func resourceApphubWorkloadUpdate(d *schema.ResourceData, meta interface{}) erro } func resourceApphubWorkloadDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ApphubWorkload without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Workload %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/apphub/resource_apphub_workload_generated_meta.yaml b/google-beta/services/apphub/resource_apphub_workload_generated_meta.yaml index 6ba262ef7a8..f10414b804e 100644 --- a/google-beta/services/apphub/resource_apphub_workload_generated_meta.yaml +++ b/google-beta/services/apphub/resource_apphub_workload_generated_meta.yaml @@ -41,3 +41,5 @@ fields: - api_field: workloadProperties.location - api_field: workloadProperties.zone - api_field: workloadReference.uri + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/artifactregistry/resource_artifact_registry_repository.go b/google-beta/services/artifactregistry/resource_artifact_registry_repository.go index 22361b2f595..223de9b9291 100644 --- a/google-beta/services/artifactregistry/resource_artifact_registry_repository.go +++ b/google-beta/services/artifactregistry/resource_artifact_registry_repository.go @@ -273,6 +273,7 @@ func ResourceArtifactRegistryRepository() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -923,6 +924,18 @@ Repository. Upstream policies cannot be set on a standard repository.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -1139,6 +1152,19 @@ func resourceArtifactRegistryRepositoryRead(d *schema.ResourceData, meta interfa log.Printf("[DEBUG] Finished reading ArtifactRegistryRepository %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Repository: %s", err) } @@ -1176,6 +1202,19 @@ func resourceArtifactRegistryRepositoryRead(d *schema.ResourceData, meta interfa } func resourceArtifactRegistryRepositoryUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceArtifactRegistryRepository().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceArtifactRegistryRepositoryRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1345,6 +1384,13 @@ func resourceArtifactRegistryRepositoryUpdate(d *schema.ResourceData, meta inter } func resourceArtifactRegistryRepositoryDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ArtifactRegistryRepository without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Repository %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/artifactregistry/resource_artifact_registry_repository_generated_meta.yaml b/google-beta/services/artifactregistry/resource_artifact_registry_repository_generated_meta.yaml index 44176c32234..de6329c326f 100644 --- a/google-beta/services/artifactregistry/resource_artifact_registry_repository_generated_meta.yaml +++ b/google-beta/services/artifactregistry/resource_artifact_registry_repository_generated_meta.yaml @@ -71,3 +71,5 @@ fields: - api_field: vulnerabilityScanningConfig.enablementConfig - api_field: vulnerabilityScanningConfig.enablementState - api_field: vulnerabilityScanningConfig.enablementStateReason + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/artifactregistry/resource_artifact_registry_rule.go b/google-beta/services/artifactregistry/resource_artifact_registry_rule.go index 96c6bf97ed3..51e42434062 100644 --- a/google-beta/services/artifactregistry/resource_artifact_registry_rule.go +++ b/google-beta/services/artifactregistry/resource_artifact_registry_rule.go @@ -115,6 +115,7 @@ func ResourceArtifactRegistryRule() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -233,6 +234,18 @@ packages inside the repository.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -389,6 +402,19 @@ func resourceArtifactRegistryRuleRead(d *schema.ResourceData, meta interface{}) log.Printf("[DEBUG] Finished reading ArtifactRegistryRule %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Rule: %s", err) } @@ -432,6 +458,19 @@ func resourceArtifactRegistryRuleRead(d *schema.ResourceData, meta interface{}) } func resourceArtifactRegistryRuleUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceArtifactRegistryRule().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceArtifactRegistryRuleRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -561,6 +600,13 @@ func resourceArtifactRegistryRuleUpdate(d *schema.ResourceData, meta interface{} } func resourceArtifactRegistryRuleDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ArtifactRegistryRule without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Rule %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/artifactregistry/resource_artifact_registry_rule_generated_meta.yaml b/google-beta/services/artifactregistry/resource_artifact_registry_rule_generated_meta.yaml index 1b97b3add37..e1e453944e0 100644 --- a/google-beta/services/artifactregistry/resource_artifact_registry_rule_generated_meta.yaml +++ b/google-beta/services/artifactregistry/resource_artifact_registry_rule_generated_meta.yaml @@ -21,3 +21,5 @@ fields: provider_only: true - field: rule_id provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/artifactregistry/resource_artifact_registry_vpcsc_config.go b/google-beta/services/artifactregistry/resource_artifact_registry_vpcsc_config.go index 7f039e2bf98..e179aab57c4 100644 --- a/google-beta/services/artifactregistry/resource_artifact_registry_vpcsc_config.go +++ b/google-beta/services/artifactregistry/resource_artifact_registry_vpcsc_config.go @@ -341,6 +341,7 @@ func resourceArtifactRegistryVPCSCConfigRead(d *schema.ResourceData, meta interf } func resourceArtifactRegistryVPCSCConfigUpdate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/assuredworkloads/resource_assured_workloads_workload.go b/google-beta/services/assuredworkloads/resource_assured_workloads_workload.go index 9e4093a032c..8a79f402303 100644 --- a/google-beta/services/assuredworkloads/resource_assured_workloads_workload.go +++ b/google-beta/services/assuredworkloads/resource_assured_workloads_workload.go @@ -48,6 +48,7 @@ func ResourceAssuredWorkloadsWorkload() *schema.Resource { }, CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Schema: map[string]*schema.Schema{ @@ -230,6 +231,9 @@ func ResourceAssuredWorkloadsWorkload() *schema.Resource { Computed: true, Description: "The combination of labels configured directly on the resource and default labels configured on the provider.", }, + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end }, } } @@ -591,9 +595,18 @@ func resourceAssuredWorkloadsWorkloadRead(d *schema.ResourceData, meta interface return fmt.Errorf("error setting terraform_labels in state: %s", err) } + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + return nil } func resourceAssuredWorkloadsWorkloadUpdate(d *schema.ResourceData, meta interface{}) error { + + if tpgresource.DeletionPolicyPreUpdate(d, ResourceAssuredWorkloadsWorkload) { + return ResourceAssuredWorkloadsWorkload().Read(d, meta) + } + config := meta.(*transport_tpg.Config) obj := &Workload{ @@ -668,6 +681,13 @@ func resourceAssuredWorkloadsWorkloadUpdate(d *schema.ResourceData, meta interfa } func resourceAssuredWorkloadsWorkloadDelete(d *schema.ResourceData, meta interface{}) error { + + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { + return nil + } + config := meta.(*transport_tpg.Config) obj := &Workload{ diff --git a/google-beta/services/assuredworkloads/resource_assured_workloads_workload_meta.yaml b/google-beta/services/assuredworkloads/resource_assured_workloads_workload_meta.yaml index 200c1c44080..6660e21e35e 100644 --- a/google-beta/services/assuredworkloads/resource_assured_workloads_workload_meta.yaml +++ b/google-beta/services/assuredworkloads/resource_assured_workloads_workload_meta.yaml @@ -45,3 +45,5 @@ fields: provider_only: true - api_field: 'violationNotificationsEnabled' - api_field: 'workloadOptions.kajEnrollmentType' + - field: 'deletion_policy' + provider_only: true diff --git a/google-beta/services/backupdr/resource_backup_dr_backup_plan.go b/google-beta/services/backupdr/resource_backup_dr_backup_plan.go index 8b7a2362ec5..6935985fe2c 100644 --- a/google-beta/services/backupdr/resource_backup_dr_backup_plan.go +++ b/google-beta/services/backupdr/resource_backup_dr_backup_plan.go @@ -115,6 +115,7 @@ func ResourceBackupDRBackupPlan() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -351,6 +352,18 @@ create crash-consistent backups.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -524,6 +537,19 @@ func resourceBackupDRBackupPlanRead(d *schema.ResourceData, meta interface{}) er log.Printf("[DEBUG] Finished reading BackupDRBackupPlan %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading BackupPlan: %s", err) } @@ -561,6 +587,19 @@ func resourceBackupDRBackupPlanRead(d *schema.ResourceData, meta interface{}) er } func resourceBackupDRBackupPlanUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceBackupDRBackupPlan().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceBackupDRBackupPlanRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -699,6 +738,13 @@ func resourceBackupDRBackupPlanUpdate(d *schema.ResourceData, meta interface{}) } func resourceBackupDRBackupPlanDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy BackupDRBackupPlan without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing BackupPlan %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/backupdr/resource_backup_dr_backup_plan_association.go b/google-beta/services/backupdr/resource_backup_dr_backup_plan_association.go index 7e717d1ac75..56ed05ad970 100644 --- a/google-beta/services/backupdr/resource_backup_dr_backup_plan_association.go +++ b/google-beta/services/backupdr/resource_backup_dr_backup_plan_association.go @@ -115,6 +115,7 @@ func ResourceBackupDRBackupPlanAssociation() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -241,6 +242,18 @@ Examples include, "compute.googleapis.com/Instance", "compute.googleapis.com/Dis Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -390,6 +403,19 @@ func resourceBackupDRBackupPlanAssociationRead(d *schema.ResourceData, meta inte log.Printf("[DEBUG] Finished reading BackupDRBackupPlanAssociation %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading BackupPlanAssociation: %s", err) } @@ -427,6 +453,19 @@ func resourceBackupDRBackupPlanAssociationRead(d *schema.ResourceData, meta inte } func resourceBackupDRBackupPlanAssociationUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceBackupDRBackupPlanAssociation().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceBackupDRBackupPlanAssociationRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -545,6 +584,13 @@ func resourceBackupDRBackupPlanAssociationUpdate(d *schema.ResourceData, meta in } func resourceBackupDRBackupPlanAssociationDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy BackupDRBackupPlanAssociation without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing BackupPlanAssociation %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/backupdr/resource_backup_dr_backup_plan_association_generated_meta.yaml b/google-beta/services/backupdr/resource_backup_dr_backup_plan_association_generated_meta.yaml index f9c13730bd8..8aa03f15bba 100644 --- a/google-beta/services/backupdr/resource_backup_dr_backup_plan_association_generated_meta.yaml +++ b/google-beta/services/backupdr/resource_backup_dr_backup_plan_association_generated_meta.yaml @@ -23,3 +23,5 @@ fields: - api_field: rulesConfigInfo.lastSuccessfulBackupConsistencyTime - api_field: rulesConfigInfo.ruleId - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/backupdr/resource_backup_dr_backup_plan_generated_meta.yaml b/google-beta/services/backupdr/resource_backup_dr_backup_plan_generated_meta.yaml index 2131f176cf9..3ceb09c4983 100644 --- a/google-beta/services/backupdr/resource_backup_dr_backup_plan_generated_meta.yaml +++ b/google-beta/services/backupdr/resource_backup_dr_backup_plan_generated_meta.yaml @@ -34,3 +34,5 @@ fields: - api_field: resourceType - api_field: supportedResourceTypes - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/backupdr/resource_backup_dr_backup_vault.go b/google-beta/services/backupdr/resource_backup_dr_backup_vault.go index 4a22cb6bac7..ffbade150ce 100644 --- a/google-beta/services/backupdr/resource_backup_dr_backup_vault.go +++ b/google-beta/services/backupdr/resource_backup_dr_backup_vault.go @@ -117,6 +117,7 @@ func ResourceBackupDRBackupVault() *schema.Resource { tpgresource.SetLabelsDiff, tpgresource.SetAnnotationsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -339,6 +340,18 @@ Please refer to the field 'effective_labels' for all of the labels present on th Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -518,6 +531,19 @@ func resourceBackupDRBackupVaultRead(d *schema.ResourceData, meta interface{}) e log.Printf("[DEBUG] Finished reading BackupDRBackupVault %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading BackupVault: %s", err) } @@ -555,6 +581,19 @@ func resourceBackupDRBackupVaultRead(d *schema.ResourceData, meta interface{}) e } func resourceBackupDRBackupVaultUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceBackupDRBackupVault().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceBackupDRBackupVaultRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -713,6 +752,13 @@ func resourceBackupDRBackupVaultUpdate(d *schema.ResourceData, meta interface{}) } func resourceBackupDRBackupVaultDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy BackupDRBackupVault without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing BackupVault %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/backupdr/resource_backup_dr_backup_vault_generated_meta.yaml b/google-beta/services/backupdr/resource_backup_dr_backup_vault_generated_meta.yaml index fb45a675f2d..08eb7a86e55 100644 --- a/google-beta/services/backupdr/resource_backup_dr_backup_vault_generated_meta.yaml +++ b/google-beta/services/backupdr/resource_backup_dr_backup_vault_generated_meta.yaml @@ -45,3 +45,5 @@ fields: - api_field: totalStoredBytes - api_field: uid - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/backupdr/resource_backup_dr_management_server.go b/google-beta/services/backupdr/resource_backup_dr_management_server.go index 333ed98b02b..c8624645724 100644 --- a/google-beta/services/backupdr/resource_backup_dr_management_server.go +++ b/google-beta/services/backupdr/resource_backup_dr_management_server.go @@ -100,6 +100,7 @@ func ResourceBackupDRManagementServer() *schema.Resource { return &schema.Resource{ Create: resourceBackupDRManagementServerCreate, Read: resourceBackupDRManagementServerRead, + Update: resourceBackupDRManagementServerUpdate, Delete: resourceBackupDRManagementServerDelete, Importer: &schema.ResourceImporter{ @@ -113,6 +114,7 @@ func ResourceBackupDRManagementServer() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -213,6 +215,18 @@ func ResourceBackupDRManagementServer() *schema.Resource { Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -356,6 +370,19 @@ func resourceBackupDRManagementServerRead(d *schema.ResourceData, meta interface log.Printf("[DEBUG] Finished reading BackupDRManagementServer %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading ManagementServer: %s", err) } @@ -392,7 +419,19 @@ func resourceBackupDRManagementServerRead(d *schema.ResourceData, meta interface return nil } +func resourceBackupDRManagementServerUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceBackupDRManagementServerRead(d, meta) +} + func resourceBackupDRManagementServerDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy BackupDRManagementServer without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing ManagementServer %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/backupdr/resource_backup_dr_management_server_generated_meta.yaml b/google-beta/services/backupdr/resource_backup_dr_management_server_generated_meta.yaml index ab7448056ad..6718e61439c 100644 --- a/google-beta/services/backupdr/resource_backup_dr_management_server_generated_meta.yaml +++ b/google-beta/services/backupdr/resource_backup_dr_management_server_generated_meta.yaml @@ -17,3 +17,5 @@ fields: - api_field: networks.peeringMode - api_field: oauth2ClientId - api_field: type + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/backupdr/resource_backup_dr_restore_workload.go b/google-beta/services/backupdr/resource_backup_dr_restore_workload.go index 6eef7264a7a..a4c0be71114 100644 --- a/google-beta/services/backupdr/resource_backup_dr_restore_workload.go +++ b/google-beta/services/backupdr/resource_backup_dr_restore_workload.go @@ -100,6 +100,7 @@ func ResourceBackupDRRestoreWorkload() *schema.Resource { return &schema.Resource{ Create: resourceBackupDRRestoreWorkloadCreate, Read: resourceBackupDRRestoreWorkloadRead, + Update: resourceBackupDRRestoreWorkloadUpdate, Delete: resourceBackupDRRestoreWorkloadDelete, Importer: &schema.ResourceImporter{ @@ -1403,6 +1404,19 @@ the request if it has already been completed.`, }, }, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -2421,7 +2435,19 @@ func resourceBackupDRRestoreWorkloadRead(d *schema.ResourceData, meta interface{ return nil } +func resourceBackupDRRestoreWorkloadUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceBackupDRRestoreWorkloadRead(d, meta) +} + func resourceBackupDRRestoreWorkloadDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy BackupDRRestoreWorkload without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing RestoreWorkload %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/backupdr/resource_backup_dr_restore_workload_generated_meta.yaml b/google-beta/services/backupdr/resource_backup_dr_restore_workload_generated_meta.yaml index 1dfd64aa697..5a8c5971606 100644 --- a/google-beta/services/backupdr/resource_backup_dr_restore_workload_generated_meta.yaml +++ b/google-beta/services/backupdr/resource_backup_dr_restore_workload_generated_meta.yaml @@ -155,3 +155,5 @@ fields: - api_field: targetResource.gcpResource.gcpResourcename - api_field: targetResource.gcpResource.location - api_field: targetResource.gcpResource.type + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/beyondcorp/resource_beyondcorp_app_connection.go b/google-beta/services/beyondcorp/resource_beyondcorp_app_connection.go index 459b15cbb88..ee3efe4486e 100644 --- a/google-beta/services/beyondcorp/resource_beyondcorp_app_connection.go +++ b/google-beta/services/beyondcorp/resource_beyondcorp_app_connection.go @@ -116,6 +116,7 @@ func ResourceBeyondcorpAppConnection() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -257,6 +258,18 @@ for a list of possible values.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -424,6 +437,19 @@ func resourceBeyondcorpAppConnectionRead(d *schema.ResourceData, meta interface{ log.Printf("[DEBUG] Finished reading BeyondcorpAppConnection %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading AppConnection: %s", err) } @@ -461,6 +487,19 @@ func resourceBeyondcorpAppConnectionRead(d *schema.ResourceData, meta interface{ } func resourceBeyondcorpAppConnectionUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceBeyondcorpAppConnection().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceBeyondcorpAppConnectionRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -599,6 +638,13 @@ func resourceBeyondcorpAppConnectionUpdate(d *schema.ResourceData, meta interfac } func resourceBeyondcorpAppConnectionDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy BeyondcorpAppConnection without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing AppConnection %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/beyondcorp/resource_beyondcorp_app_connection_generated_meta.yaml b/google-beta/services/beyondcorp/resource_beyondcorp_app_connection_generated_meta.yaml index 6ac9910e104..c07ada489f6 100644 --- a/google-beta/services/beyondcorp/resource_beyondcorp_app_connection_generated_meta.yaml +++ b/google-beta/services/beyondcorp/resource_beyondcorp_app_connection_generated_meta.yaml @@ -25,3 +25,5 @@ fields: - field: terraform_labels provider_only: true - api_field: type + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/beyondcorp/resource_beyondcorp_app_connector.go b/google-beta/services/beyondcorp/resource_beyondcorp_app_connector.go index 540271a2b5d..53c782bd39a 100644 --- a/google-beta/services/beyondcorp/resource_beyondcorp_app_connector.go +++ b/google-beta/services/beyondcorp/resource_beyondcorp_app_connector.go @@ -116,6 +116,7 @@ func ResourceBeyondcorpAppConnector() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -218,6 +219,18 @@ Please refer to the field 'effective_labels' for all of the labels present on th Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -367,6 +380,19 @@ func resourceBeyondcorpAppConnectorRead(d *schema.ResourceData, meta interface{} log.Printf("[DEBUG] Finished reading BeyondcorpAppConnector %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading AppConnector: %s", err) } @@ -404,6 +430,19 @@ func resourceBeyondcorpAppConnectorRead(d *schema.ResourceData, meta interface{} } func resourceBeyondcorpAppConnectorUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceBeyondcorpAppConnector().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceBeyondcorpAppConnectorRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -522,6 +561,13 @@ func resourceBeyondcorpAppConnectorUpdate(d *schema.ResourceData, meta interface } func resourceBeyondcorpAppConnectorDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy BeyondcorpAppConnector without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing AppConnector %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/beyondcorp/resource_beyondcorp_app_connector_generated_meta.yaml b/google-beta/services/beyondcorp/resource_beyondcorp_app_connector_generated_meta.yaml index e7b4893202f..787259b47e7 100644 --- a/google-beta/services/beyondcorp/resource_beyondcorp_app_connector_generated_meta.yaml +++ b/google-beta/services/beyondcorp/resource_beyondcorp_app_connector_generated_meta.yaml @@ -19,3 +19,5 @@ fields: - api_field: state - field: terraform_labels provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/beyondcorp/resource_beyondcorp_app_gateway.go b/google-beta/services/beyondcorp/resource_beyondcorp_app_gateway.go index 81d1ee4a02a..3dce55d64b6 100644 --- a/google-beta/services/beyondcorp/resource_beyondcorp_app_gateway.go +++ b/google-beta/services/beyondcorp/resource_beyondcorp_app_gateway.go @@ -125,6 +125,7 @@ func ResourceBeyondcorpAppGateway() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -244,6 +245,18 @@ Please refer to the field 'effective_labels' for all of the labels present on th Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -399,6 +412,19 @@ func resourceBeyondcorpAppGatewayRead(d *schema.ResourceData, meta interface{}) log.Printf("[DEBUG] Finished reading BeyondcorpAppGateway %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading AppGateway: %s", err) } @@ -436,11 +462,18 @@ func resourceBeyondcorpAppGatewayRead(d *schema.ResourceData, meta interface{}) } func resourceBeyondcorpAppGatewayUpdate(d *schema.ResourceData, meta interface{}) error { - // Only the root field "labels", "terraform_labels", and virtual fields are mutable + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable return resourceBeyondcorpAppGatewayRead(d, meta) } func resourceBeyondcorpAppGatewayDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy BeyondcorpAppGateway without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing AppGateway %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/beyondcorp/resource_beyondcorp_app_gateway_generated_meta.yaml b/google-beta/services/beyondcorp/resource_beyondcorp_app_gateway_generated_meta.yaml index a08a24f186d..9cbf203fb7d 100644 --- a/google-beta/services/beyondcorp/resource_beyondcorp_app_gateway_generated_meta.yaml +++ b/google-beta/services/beyondcorp/resource_beyondcorp_app_gateway_generated_meta.yaml @@ -23,3 +23,5 @@ fields: provider_only: true - api_field: type - api_field: uri + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/beyondcorp/resource_beyondcorp_security_gateway.go b/google-beta/services/beyondcorp/resource_beyondcorp_security_gateway.go index 96485abf42b..5e69ca7f745 100644 --- a/google-beta/services/beyondcorp/resource_beyondcorp_security_gateway.go +++ b/google-beta/services/beyondcorp/resource_beyondcorp_security_gateway.go @@ -128,6 +128,7 @@ func ResourceBeyondcorpSecurityGateway() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -407,6 +408,18 @@ ERROR`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -568,6 +581,19 @@ func resourceBeyondcorpSecurityGatewayRead(d *schema.ResourceData, meta interfac log.Printf("[DEBUG] Finished reading BeyondcorpSecurityGateway %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading SecurityGateway: %s", err) } @@ -605,6 +631,19 @@ func resourceBeyondcorpSecurityGatewayRead(d *schema.ResourceData, meta interfac } func resourceBeyondcorpSecurityGatewayUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceBeyondcorpSecurityGateway().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceBeyondcorpSecurityGatewayRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -743,6 +782,13 @@ func resourceBeyondcorpSecurityGatewayUpdate(d *schema.ResourceData, meta interf } func resourceBeyondcorpSecurityGatewayDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy BeyondcorpSecurityGateway without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing SecurityGateway %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/beyondcorp/resource_beyondcorp_security_gateway_application.go b/google-beta/services/beyondcorp/resource_beyondcorp_security_gateway_application.go index e400584e274..f8adf4a82ed 100644 --- a/google-beta/services/beyondcorp/resource_beyondcorp_security_gateway_application.go +++ b/google-beta/services/beyondcorp/resource_beyondcorp_security_gateway_application.go @@ -115,6 +115,7 @@ func ResourceBeyondcorpSecurityGatewayApplication() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -397,6 +398,18 @@ The names should conform to RFC 9110: Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -552,6 +565,19 @@ func resourceBeyondcorpSecurityGatewayApplicationRead(d *schema.ResourceData, me log.Printf("[DEBUG] Finished reading BeyondcorpSecurityGatewayApplication %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading SecurityGatewayApplication: %s", err) } @@ -589,6 +615,19 @@ func resourceBeyondcorpSecurityGatewayApplicationRead(d *schema.ResourceData, me } func resourceBeyondcorpSecurityGatewayApplicationUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceBeyondcorpSecurityGatewayApplication().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceBeyondcorpSecurityGatewayApplicationRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -717,6 +756,13 @@ func resourceBeyondcorpSecurityGatewayApplicationUpdate(d *schema.ResourceData, } func resourceBeyondcorpSecurityGatewayApplicationDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy BeyondcorpSecurityGatewayApplication without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing SecurityGatewayApplication %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/beyondcorp/resource_beyondcorp_security_gateway_application_generated_meta.yaml b/google-beta/services/beyondcorp/resource_beyondcorp_security_gateway_application_generated_meta.yaml index b3064ad3ea0..dbf6218940e 100644 --- a/google-beta/services/beyondcorp/resource_beyondcorp_security_gateway_application_generated_meta.yaml +++ b/google-beta/services/beyondcorp/resource_beyondcorp_security_gateway_application_generated_meta.yaml @@ -31,3 +31,5 @@ fields: - api_field: upstreams.proxyProtocol.contextualHeaders.userInfo.outputType - api_field: upstreams.proxyProtocol.gatewayIdentity - api_field: upstreams.proxyProtocol.metadataHeaders + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/beyondcorp/resource_beyondcorp_security_gateway_generated_meta.yaml b/google-beta/services/beyondcorp/resource_beyondcorp_security_gateway_generated_meta.yaml index eca7444960a..f5f91b030d3 100644 --- a/google-beta/services/beyondcorp/resource_beyondcorp_security_gateway_generated_meta.yaml +++ b/google-beta/services/beyondcorp/resource_beyondcorp_security_gateway_generated_meta.yaml @@ -33,3 +33,5 @@ fields: - api_field: serviceDiscovery.apiGateway.resourceOverride.path - api_field: state - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/biglake/resource_biglake_catalog.go b/google-beta/services/biglake/resource_biglake_catalog.go index 1509256bf1c..a901cdaa7dc 100644 --- a/google-beta/services/biglake/resource_biglake_catalog.go +++ b/google-beta/services/biglake/resource_biglake_catalog.go @@ -100,6 +100,7 @@ func ResourceBiglakeCatalog() *schema.Resource { return &schema.Resource{ Create: resourceBiglakeCatalogCreate, Read: resourceBiglakeCatalogRead, + Update: resourceBiglakeCatalogUpdate, Delete: resourceBiglakeCatalogDelete, Importer: &schema.ResourceImporter{ @@ -113,6 +114,7 @@ func ResourceBiglakeCatalog() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -187,6 +189,18 @@ fractional digits.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -308,6 +322,19 @@ func resourceBiglakeCatalogRead(d *schema.ResourceData, meta interface{}) error log.Printf("[DEBUG] Finished reading BiglakeCatalog %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Catalog: %s", err) } @@ -344,7 +371,19 @@ func resourceBiglakeCatalogRead(d *schema.ResourceData, meta interface{}) error return nil } +func resourceBiglakeCatalogUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceBiglakeCatalogRead(d, meta) +} + func resourceBiglakeCatalogDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy BiglakeCatalog without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Catalog %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/biglake/resource_biglake_catalog_generated_meta.yaml b/google-beta/services/biglake/resource_biglake_catalog_generated_meta.yaml index 57809297d15..4bad2a73fa0 100644 --- a/google-beta/services/biglake/resource_biglake_catalog_generated_meta.yaml +++ b/google-beta/services/biglake/resource_biglake_catalog_generated_meta.yaml @@ -15,3 +15,5 @@ fields: - field: name provider_only: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/biglake/resource_biglake_database.go b/google-beta/services/biglake/resource_biglake_database.go index d7453be2587..945c654877c 100644 --- a/google-beta/services/biglake/resource_biglake_database.go +++ b/google-beta/services/biglake/resource_biglake_database.go @@ -205,6 +205,19 @@ RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine fractional digits. Examples: "2014-10-02T15:01:23Z" and "2014-10-02T15:01:23.045123456Z".`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -321,6 +334,20 @@ func resourceBiglakeDatabaseRead(d *schema.ResourceData, meta interface{}) error log.Printf("[DEBUG] Finished reading BiglakeDatabase %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceBiglakeDatabaseFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -348,6 +375,19 @@ func resourceBiglakeDatabaseRead(d *schema.ResourceData, meta interface{}) error } func resourceBiglakeDatabaseUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceBiglakeDatabase().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceBiglakeDatabaseRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -438,6 +478,13 @@ func resourceBiglakeDatabaseUpdate(d *schema.ResourceData, meta interface{}) err } func resourceBiglakeDatabaseDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy BiglakeDatabase without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Database %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/biglake/resource_biglake_database_generated_meta.yaml b/google-beta/services/biglake/resource_biglake_database_generated_meta.yaml index 394ccc9d6db..e1aafe3c820 100644 --- a/google-beta/services/biglake/resource_biglake_database_generated_meta.yaml +++ b/google-beta/services/biglake/resource_biglake_database_generated_meta.yaml @@ -18,3 +18,5 @@ fields: provider_only: true - api_field: type - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/biglake/resource_biglake_table.go b/google-beta/services/biglake/resource_biglake_table.go index 907871f7dbf..163f8a2ef77 100644 --- a/google-beta/services/biglake/resource_biglake_table.go +++ b/google-beta/services/biglake/resource_biglake_table.go @@ -240,6 +240,19 @@ RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine fractional digits. Examples: "2014-10-02T15:01:23Z" and "2014-10-02T15:01:23.045123456Z".`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -356,6 +369,20 @@ func resourceBiglakeTableRead(d *schema.ResourceData, meta interface{}) error { log.Printf("[DEBUG] Finished reading BiglakeTable %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceBiglakeTableFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -383,6 +410,19 @@ func resourceBiglakeTableRead(d *schema.ResourceData, meta interface{}) error { } func resourceBiglakeTableUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceBiglakeTable().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceBiglakeTableRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -473,6 +513,13 @@ func resourceBiglakeTableUpdate(d *schema.ResourceData, meta interface{}) error } func resourceBiglakeTableDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy BiglakeTable without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Table %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/biglake/resource_biglake_table_generated_meta.yaml b/google-beta/services/biglake/resource_biglake_table_generated_meta.yaml index e1f3a490db4..abdc58b8807 100644 --- a/google-beta/services/biglake/resource_biglake_table_generated_meta.yaml +++ b/google-beta/services/biglake/resource_biglake_table_generated_meta.yaml @@ -22,3 +22,5 @@ fields: provider_only: true - api_field: type - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/biglakeiceberg/resource_biglake_iceberg_catalog.go b/google-beta/services/biglakeiceberg/resource_biglake_iceberg_catalog.go index 920a65273fa..2cdcfadc15a 100644 --- a/google-beta/services/biglakeiceberg/resource_biglake_iceberg_catalog.go +++ b/google-beta/services/biglakeiceberg/resource_biglake_iceberg_catalog.go @@ -115,6 +115,7 @@ func ResourceBiglakeIcebergIcebergCatalog() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -221,6 +222,18 @@ catalog's location.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -357,6 +370,19 @@ func resourceBiglakeIcebergIcebergCatalogRead(d *schema.ResourceData, meta inter log.Printf("[DEBUG] Finished reading BiglakeIcebergIcebergCatalog %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading IcebergCatalog: %s", err) } @@ -388,6 +414,19 @@ func resourceBiglakeIcebergIcebergCatalogRead(d *schema.ResourceData, meta inter } func resourceBiglakeIcebergIcebergCatalogUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceBiglakeIcebergIcebergCatalog().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceBiglakeIcebergIcebergCatalogRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -462,6 +501,13 @@ func resourceBiglakeIcebergIcebergCatalogUpdate(d *schema.ResourceData, meta int } func resourceBiglakeIcebergIcebergCatalogDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy BiglakeIcebergIcebergCatalog without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing IcebergCatalog %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/biglakeiceberg/resource_biglake_iceberg_catalog_generated_meta.yaml b/google-beta/services/biglakeiceberg/resource_biglake_iceberg_catalog_generated_meta.yaml index bf93fe03c34..4a2ca3effe7 100644 --- a/google-beta/services/biglakeiceberg/resource_biglake_iceberg_catalog_generated_meta.yaml +++ b/google-beta/services/biglakeiceberg/resource_biglake_iceberg_catalog_generated_meta.yaml @@ -20,3 +20,5 @@ fields: - api_field: replicas.state - api_field: storage-regions - api_field: update-time + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/biglakeiceberg/resource_biglake_iceberg_namespace.go b/google-beta/services/biglakeiceberg/resource_biglake_iceberg_namespace.go index ee124ebc183..2371ffc21c6 100644 --- a/google-beta/services/biglakeiceberg/resource_biglake_iceberg_namespace.go +++ b/google-beta/services/biglakeiceberg/resource_biglake_iceberg_namespace.go @@ -128,6 +128,7 @@ func ResourceBiglakeIcebergIcebergNamespace() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -180,6 +181,18 @@ func ResourceBiglakeIcebergIcebergNamespace() *schema.Resource { Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -321,6 +334,19 @@ func resourceBiglakeIcebergIcebergNamespaceRead(d *schema.ResourceData, meta int log.Printf("[DEBUG] Finished reading BiglakeIcebergIcebergNamespace %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading IcebergNamespace: %s", err) } @@ -358,6 +384,19 @@ func resourceBiglakeIcebergIcebergNamespaceRead(d *schema.ResourceData, meta int } func resourceBiglakeIcebergIcebergNamespaceUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceBiglakeIcebergIcebergNamespace().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceBiglakeIcebergIcebergNamespaceRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -448,6 +487,13 @@ func resourceBiglakeIcebergIcebergNamespaceUpdate(d *schema.ResourceData, meta i } func resourceBiglakeIcebergIcebergNamespaceDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy BiglakeIcebergIcebergNamespace without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing IcebergNamespace %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/biglakeiceberg/resource_biglake_iceberg_namespace_generated_meta.yaml b/google-beta/services/biglakeiceberg/resource_biglake_iceberg_namespace_generated_meta.yaml index c95c9da02a8..de5865c3941 100644 --- a/google-beta/services/biglakeiceberg/resource_biglake_iceberg_namespace_generated_meta.yaml +++ b/google-beta/services/biglakeiceberg/resource_biglake_iceberg_namespace_generated_meta.yaml @@ -12,3 +12,5 @@ fields: - api_field: namespace field: namespace_id - api_field: properties + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/biglakeiceberg/resource_biglake_iceberg_table.go b/google-beta/services/biglakeiceberg/resource_biglake_iceberg_table.go index 86d5185cca8..bc4aabf74c7 100644 --- a/google-beta/services/biglakeiceberg/resource_biglake_iceberg_table.go +++ b/google-beta/services/biglakeiceberg/resource_biglake_iceberg_table.go @@ -131,6 +131,7 @@ func ResourceBiglakeIcebergIcebergTable() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -309,6 +310,18 @@ func ResourceBiglakeIcebergIcebergTable() *schema.Resource { Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -564,6 +577,19 @@ func resourceBiglakeIcebergIcebergTableRead(d *schema.ResourceData, meta interfa } } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading IcebergTable: %s", err) } @@ -607,6 +633,19 @@ func resourceBiglakeIcebergIcebergTableRead(d *schema.ResourceData, meta interfa } func resourceBiglakeIcebergIcebergTableUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceBiglakeIcebergIcebergTable().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceBiglakeIcebergIcebergTableRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -720,6 +759,13 @@ func resourceBiglakeIcebergIcebergTableUpdate(d *schema.ResourceData, meta inter } func resourceBiglakeIcebergIcebergTableDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy BiglakeIcebergIcebergTable without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing IcebergTable %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/biglakeiceberg/resource_biglake_iceberg_table_generated_meta.yaml b/google-beta/services/biglakeiceberg/resource_biglake_iceberg_table_generated_meta.yaml index 04a263089ef..68e1b3bd1cd 100644 --- a/google-beta/services/biglakeiceberg/resource_biglake_iceberg_table_generated_meta.yaml +++ b/google-beta/services/biglakeiceberg/resource_biglake_iceberg_table_generated_meta.yaml @@ -27,3 +27,5 @@ fields: - api_field: schema.identifier-field-ids - api_field: schema.schema-id - api_field: schema.type + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/bigquery/resource_bigquery_dataset.go b/google-beta/services/bigquery/resource_bigquery_dataset.go index defb30b5ad7..3580f72b422 100644 --- a/google-beta/services/bigquery/resource_bigquery_dataset.go +++ b/google-beta/services/bigquery/resource_bigquery_dataset.go @@ -204,6 +204,7 @@ func ResourceBigQueryDataset() *schema.Resource { customCollationDiff, tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Schema: map[string]*schema.Schema{ @@ -458,6 +459,18 @@ destroying the resource will fail if tables are present.`, Type: schema.TypeString, Computed: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -844,6 +857,18 @@ func resourceBigQueryDatasetRead(d *schema.ResourceData, meta interface{}) error return fmt.Errorf("Error setting delete_contents_on_destroy: %s", err) } } + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Dataset: %s", err) } @@ -857,6 +882,19 @@ func resourceBigQueryDatasetRead(d *schema.ResourceData, meta interface{}) error } func resourceBigQueryDatasetUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceBigQueryDataset().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceBigQueryDatasetRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1003,6 +1041,13 @@ func resourceBigQueryDatasetUpdate(d *schema.ResourceData, meta interface{}) err } func resourceBigQueryDatasetDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy BigQueryDataset without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Dataset %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/bigquery/resource_bigquery_dataset_access.go b/google-beta/services/bigquery/resource_bigquery_dataset_access.go index 27353795cc4..e3347531b33 100644 --- a/google-beta/services/bigquery/resource_bigquery_dataset_access.go +++ b/google-beta/services/bigquery/resource_bigquery_dataset_access.go @@ -223,6 +223,7 @@ func ResourceBigQueryDatasetAccess() *schema.Resource { return &schema.Resource{ Create: resourceBigQueryDatasetAccessCreate, Read: resourceBigQueryDatasetAccessRead, + Update: resourceBigQueryDatasetAccessUpdate, Delete: resourceBigQueryDatasetAccessDelete, Timeouts: &schema.ResourceTimeout{ @@ -232,6 +233,7 @@ func ResourceBigQueryDatasetAccess() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -489,6 +491,18 @@ is 1,024 characters.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -725,6 +739,19 @@ func resourceBigQueryDatasetAccessRead(d *schema.ResourceData, meta interface{}) return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading DatasetAccess: %s", err) } @@ -755,7 +782,19 @@ func resourceBigQueryDatasetAccessRead(d *schema.ResourceData, meta interface{}) return nil } +func resourceBigQueryDatasetAccessUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceBigQueryDatasetAccessRead(d, meta) +} + func resourceBigQueryDatasetAccessDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy BigQueryDatasetAccess without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing DatasetAccess %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/bigquery/resource_bigquery_dataset_access_generated_meta.yaml b/google-beta/services/bigquery/resource_bigquery_dataset_access_generated_meta.yaml index 14488014f96..ceddea13bc0 100644 --- a/google-beta/services/bigquery/resource_bigquery_dataset_access_generated_meta.yaml +++ b/google-beta/services/bigquery/resource_bigquery_dataset_access_generated_meta.yaml @@ -47,3 +47,5 @@ fields: field: view.project_id - api_field: access.view.tableId field: view.table_id + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/bigquery/resource_bigquery_dataset_generated_meta.yaml b/google-beta/services/bigquery/resource_bigquery_dataset_generated_meta.yaml index eb728770782..062cd728692 100644 --- a/google-beta/services/bigquery/resource_bigquery_dataset_generated_meta.yaml +++ b/google-beta/services/bigquery/resource_bigquery_dataset_generated_meta.yaml @@ -54,3 +54,5 @@ fields: - field: terraform_labels provider_only: true - api_field: selfLink + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/bigquery/resource_bigquery_job.go b/google-beta/services/bigquery/resource_bigquery_job.go index 616c080f0dd..5838f75e9bc 100644 --- a/google-beta/services/bigquery/resource_bigquery_job.go +++ b/google-beta/services/bigquery/resource_bigquery_job.go @@ -1286,7 +1286,7 @@ func resourceBigQueryJobRead(d *schema.ResourceData, meta interface{}) error { } func resourceBigQueryJobUpdate(d *schema.ResourceData, meta interface{}) error { - // Only the root field "labels", "terraform_labels", and virtual fields are mutable + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable return resourceBigQueryJobRead(d, meta) } diff --git a/google-beta/services/bigquery/resource_bigquery_routine.go b/google-beta/services/bigquery/resource_bigquery_routine.go index 810b48c20fb..d41b4e0b6b3 100644 --- a/google-beta/services/bigquery/resource_bigquery_routine.go +++ b/google-beta/services/bigquery/resource_bigquery_routine.go @@ -115,6 +115,7 @@ func ResourceBigQueryRoutine() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Schema: map[string]*schema.Schema{ @@ -463,6 +464,18 @@ epoch.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -659,6 +672,19 @@ func resourceBigQueryRoutineRead(d *schema.ResourceData, meta interface{}) error log.Printf("[DEBUG] Finished reading BigQueryRoutine %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Routine: %s", err) } @@ -672,6 +698,19 @@ func resourceBigQueryRoutineRead(d *schema.ResourceData, meta interface{}) error } func resourceBigQueryRoutineUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceBigQueryRoutine().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceBigQueryRoutineRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -818,6 +857,13 @@ func resourceBigQueryRoutineUpdate(d *schema.ResourceData, meta interface{}) err } func resourceBigQueryRoutineDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy BigQueryRoutine without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Routine %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/bigquery/resource_bigquery_routine_generated_meta.yaml b/google-beta/services/bigquery/resource_bigquery_routine_generated_meta.yaml index f79e300f04e..feaac4a3e75 100644 --- a/google-beta/services/bigquery/resource_bigquery_routine_generated_meta.yaml +++ b/google-beta/services/bigquery/resource_bigquery_routine_generated_meta.yaml @@ -51,3 +51,5 @@ fields: - api_field: sparkOptions.properties - api_field: sparkOptions.pyFileUris - api_field: sparkOptions.runtimeVersion + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/bigquery/resource_bigquery_row_access_policy.go b/google-beta/services/bigquery/resource_bigquery_row_access_policy.go index d5c40c44ddc..cbd7c13ce49 100644 --- a/google-beta/services/bigquery/resource_bigquery_row_access_policy.go +++ b/google-beta/services/bigquery/resource_bigquery_row_access_policy.go @@ -115,6 +115,7 @@ func ResourceBigQueryRowAccessPolicy() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Schema: map[string]*schema.Schema{ @@ -200,6 +201,18 @@ since the epoch.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -318,6 +331,19 @@ func resourceBigQueryRowAccessPolicyRead(d *schema.ResourceData, meta interface{ log.Printf("[DEBUG] Finished reading BigQueryRowAccessPolicy %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading RowAccessPolicy: %s", err) } @@ -331,6 +357,19 @@ func resourceBigQueryRowAccessPolicyRead(d *schema.ResourceData, meta interface{ } func resourceBigQueryRowAccessPolicyUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceBigQueryRowAccessPolicy().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceBigQueryRowAccessPolicyRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -399,6 +438,13 @@ func resourceBigQueryRowAccessPolicyUpdate(d *schema.ResourceData, meta interfac } func resourceBigQueryRowAccessPolicyDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy BigQueryRowAccessPolicy without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing RowAccessPolicy %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/bigquery/resource_bigquery_row_access_policy_generated_meta.yaml b/google-beta/services/bigquery/resource_bigquery_row_access_policy_generated_meta.yaml index 1124623d130..b74f6800d04 100644 --- a/google-beta/services/bigquery/resource_bigquery_row_access_policy_generated_meta.yaml +++ b/google-beta/services/bigquery/resource_bigquery_row_access_policy_generated_meta.yaml @@ -17,3 +17,5 @@ fields: field: policy_id - api_field: rowAccessPolicyReference.tableId field: table_id + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/bigquery/resource_bigquery_table.go b/google-beta/services/bigquery/resource_bigquery_table.go index c676765d5af..aa8b1718826 100644 --- a/google-beta/services/bigquery/resource_bigquery_table.go +++ b/google-beta/services/bigquery/resource_bigquery_table.go @@ -702,6 +702,7 @@ func ResourceBigQueryTable() *schema.Resource { State: resourceBigQueryTableImport, }, CustomizeDiff: customdiff.All( + tpgresource.DefaultProviderDeletionPolicy("DELETE"), tpgresource.DefaultProviderProject, resourceBigQueryTableSchemaCustomizeDiff, tpgresource.SetLabelsDiff, @@ -1853,6 +1854,9 @@ func ResourceBigQueryTable() *schema.Resource { }, }, }, + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end }, UseJSONNumber: true, } @@ -2399,6 +2403,10 @@ func resourceBigQueryTableRead(d *schema.ResourceData, meta interface{}) error { } } + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + return nil } @@ -2429,7 +2437,7 @@ func addAutoGenSchemaFields(d *schema.ResourceData, table *bigquery.Table) error func resourceBigQueryTableUpdate(d *schema.ResourceData, meta interface{}) error { // If only client-side fields were modified, short-circuit the Update function to avoid sending an update API request. - clientSideFields := map[string]bool{"deletion_protection": true, "ignore_schema_changes": true, "ignore_auto_generated_schema": true, "table_metadata_view": true} + clientSideFields := map[string]bool{"deletion_protection": true, "ignore_schema_changes": true, "ignore_auto_generated_schema": true, "table_metadata_view": true, "deletion_policy": true} clientSideOnly := true for field := range ResourceBigQueryTable().Schema { if d.HasChange(field) && !clientSideFields[field] { @@ -2569,6 +2577,13 @@ func resourceBigQueryTableColumnDrop(config *transport_tpg.Config, userAgent str } func resourceBigQueryTableDelete(d *schema.ResourceData, meta interface{}) error { + + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { + return nil + } + if d.Get("deletion_protection").(bool) { return fmt.Errorf("cannot destroy table %v without setting deletion_protection=false and running `terraform apply`", d.Id()) } diff --git a/google-beta/services/bigquery/resource_bigquery_table_meta.yaml b/google-beta/services/bigquery/resource_bigquery_table_meta.yaml index bdc43097c58..ccc6aedb5d6 100644 --- a/google-beta/services/bigquery/resource_bigquery_table_meta.yaml +++ b/google-beta/services/bigquery/resource_bigquery_table_meta.yaml @@ -136,3 +136,5 @@ fields: - api_field: 'type' - api_field: 'view.query' - api_field: 'view.useLegacySql' + - field: 'deletion_policy' + provider_only: true diff --git a/google-beta/services/bigqueryanalyticshub/resource_bigquery_analytics_hub_data_exchange.go b/google-beta/services/bigqueryanalyticshub/resource_bigquery_analytics_hub_data_exchange.go index 83ac94a3376..a2a4a0e9ca9 100644 --- a/google-beta/services/bigqueryanalyticshub/resource_bigquery_analytics_hub_data_exchange.go +++ b/google-beta/services/bigqueryanalyticshub/resource_bigquery_analytics_hub_data_exchange.go @@ -115,6 +115,7 @@ func ResourceBigqueryAnalyticsHubDataExchange() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -242,6 +243,18 @@ This field is required for data clean room exchanges.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -411,6 +424,19 @@ func resourceBigqueryAnalyticsHubDataExchangeRead(d *schema.ResourceData, meta i log.Printf("[DEBUG] Finished reading BigqueryAnalyticsHubDataExchange %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading DataExchange: %s", err) } @@ -448,6 +474,19 @@ func resourceBigqueryAnalyticsHubDataExchangeRead(d *schema.ResourceData, meta i } func resourceBigqueryAnalyticsHubDataExchangeUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceBigqueryAnalyticsHubDataExchange().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceBigqueryAnalyticsHubDataExchangeRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -599,6 +638,13 @@ func resourceBigqueryAnalyticsHubDataExchangeUpdate(d *schema.ResourceData, meta } func resourceBigqueryAnalyticsHubDataExchangeDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy BigqueryAnalyticsHubDataExchange without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing DataExchange %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/bigqueryanalyticshub/resource_bigquery_analytics_hub_data_exchange_generated_meta.yaml b/google-beta/services/bigqueryanalyticshub/resource_bigquery_analytics_hub_data_exchange_generated_meta.yaml index f8c10a48566..f436b8ef675 100644 --- a/google-beta/services/bigqueryanalyticshub/resource_bigquery_analytics_hub_data_exchange_generated_meta.yaml +++ b/google-beta/services/bigqueryanalyticshub/resource_bigquery_analytics_hub_data_exchange_generated_meta.yaml @@ -22,3 +22,5 @@ fields: - api_field: primaryContact - api_field: sharingEnvironmentConfig.dcrExchangeConfig - api_field: sharingEnvironmentConfig.defaultExchangeConfig + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/bigqueryanalyticshub/resource_bigquery_analytics_hub_data_exchange_subscription.go b/google-beta/services/bigqueryanalyticshub/resource_bigquery_analytics_hub_data_exchange_subscription.go index 4e9691f7da7..796dc30cb0c 100644 --- a/google-beta/services/bigqueryanalyticshub/resource_bigquery_analytics_hub_data_exchange_subscription.go +++ b/google-beta/services/bigqueryanalyticshub/resource_bigquery_analytics_hub_data_exchange_subscription.go @@ -115,6 +115,7 @@ func ResourceBigqueryAnalyticsHubDataExchangeSubscription() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -356,6 +357,18 @@ For Data Exchange subscriptions, this map may contain multiple entries if the Da Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -569,6 +582,18 @@ func resourceBigqueryAnalyticsHubDataExchangeSubscriptionRead(d *schema.Resource return fmt.Errorf("Error setting refresh_policy: %s", err) } } + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading DataExchangeSubscription: %s", err) } @@ -606,6 +631,19 @@ func resourceBigqueryAnalyticsHubDataExchangeSubscriptionRead(d *schema.Resource } func resourceBigqueryAnalyticsHubDataExchangeSubscriptionUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceBigqueryAnalyticsHubDataExchangeSubscription().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceBigqueryAnalyticsHubDataExchangeSubscriptionRead(d, meta) + } + config := meta.(*transport_tpg.Config) //If a mutable field is added later in the subscription resource, an update API endpoint will be created //and this custom_update will have to be changed and will call a Update API as well as done by mutable resources. @@ -650,6 +688,13 @@ func resourceBigqueryAnalyticsHubDataExchangeSubscriptionUpdate(d *schema.Resour } func resourceBigqueryAnalyticsHubDataExchangeSubscriptionDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy BigqueryAnalyticsHubDataExchangeSubscription without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing DataExchangeSubscription %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/bigqueryanalyticshub/resource_bigquery_analytics_hub_data_exchange_subscription_generated_meta.yaml b/google-beta/services/bigqueryanalyticshub/resource_bigquery_analytics_hub_data_exchange_subscription_generated_meta.yaml index 6d6df99d5cc..29f2f4b98bc 100644 --- a/google-beta/services/bigqueryanalyticshub/resource_bigquery_analytics_hub_data_exchange_subscription_generated_meta.yaml +++ b/google-beta/services/bigqueryanalyticshub/resource_bigquery_analytics_hub_data_exchange_subscription_generated_meta.yaml @@ -44,3 +44,5 @@ fields: - api_field: state - api_field: subscriberContact - api_field: subscriptionId + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/bigqueryanalyticshub/resource_bigquery_analytics_hub_listing.go b/google-beta/services/bigqueryanalyticshub/resource_bigquery_analytics_hub_listing.go index c5d339d301c..c209a1c9b09 100644 --- a/google-beta/services/bigqueryanalyticshub/resource_bigquery_analytics_hub_listing.go +++ b/google-beta/services/bigqueryanalyticshub/resource_bigquery_analytics_hub_listing.go @@ -115,6 +115,7 @@ func ResourceBigqueryAnalyticsHubListing() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -443,6 +444,18 @@ Possible values: COMMERCIAL_STATE_UNSPECIFIED, ONBOARDING, ACTIVE`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -660,6 +673,18 @@ func resourceBigqueryAnalyticsHubListingRead(d *schema.ResourceData, meta interf log.Printf("[DEBUG] Finished reading BigqueryAnalyticsHubListing %q: %#v", d.Id(), res) // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Listing: %s", err) } @@ -703,6 +728,19 @@ func resourceBigqueryAnalyticsHubListingRead(d *schema.ResourceData, meta interf } func resourceBigqueryAnalyticsHubListingUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceBigqueryAnalyticsHubListing().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceBigqueryAnalyticsHubListingRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -968,6 +1006,13 @@ func resourceBigqueryAnalyticsHubListingUpdate(d *schema.ResourceData, meta inte } func resourceBigqueryAnalyticsHubListingDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy BigqueryAnalyticsHubListing without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Listing %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/bigqueryanalyticshub/resource_bigquery_analytics_hub_listing_generated_meta.yaml b/google-beta/services/bigqueryanalyticshub/resource_bigquery_analytics_hub_listing_generated_meta.yaml index 965d2aad422..f834f728b50 100644 --- a/google-beta/services/bigqueryanalyticshub/resource_bigquery_analytics_hub_listing_generated_meta.yaml +++ b/google-beta/services/bigqueryanalyticshub/resource_bigquery_analytics_hub_listing_generated_meta.yaml @@ -45,3 +45,5 @@ fields: - api_field: restrictedExportConfig.restrictDirectTableAccess - api_field: restrictedExportConfig.restrictQueryResult - api_field: state + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/bigqueryanalyticshub/resource_bigquery_analytics_hub_listing_subscription.go b/google-beta/services/bigqueryanalyticshub/resource_bigquery_analytics_hub_listing_subscription.go index 58731b65048..fd7d81ef939 100644 --- a/google-beta/services/bigqueryanalyticshub/resource_bigquery_analytics_hub_listing_subscription.go +++ b/google-beta/services/bigqueryanalyticshub/resource_bigquery_analytics_hub_listing_subscription.go @@ -106,6 +106,7 @@ func ResourceBigqueryAnalyticsHubListingSubscription() *schema.Resource { return &schema.Resource{ Create: resourceBigqueryAnalyticsHubListingSubscriptionCreate, Read: resourceBigqueryAnalyticsHubListingSubscriptionRead, + Update: resourceBigqueryAnalyticsHubListingSubscriptionUpdate, Delete: resourceBigqueryAnalyticsHubListingSubscriptionDelete, Importer: &schema.ResourceImporter{ @@ -119,6 +120,7 @@ func ResourceBigqueryAnalyticsHubListingSubscription() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -359,6 +361,18 @@ e.g. projects/123/locations/US/dataExchanges/456/listings/789 -> projects/123/da Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -531,6 +545,19 @@ func resourceBigqueryAnalyticsHubListingSubscriptionRead(d *schema.ResourceData, return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading ListingSubscription: %s", err) } @@ -567,7 +594,19 @@ func resourceBigqueryAnalyticsHubListingSubscriptionRead(d *schema.ResourceData, return nil } +func resourceBigqueryAnalyticsHubListingSubscriptionUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceBigqueryAnalyticsHubListingSubscriptionRead(d, meta) +} + func resourceBigqueryAnalyticsHubListingSubscriptionDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy BigqueryAnalyticsHubListingSubscription without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing ListingSubscription %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/bigqueryanalyticshub/resource_bigquery_analytics_hub_listing_subscription_generated_meta.yaml b/google-beta/services/bigqueryanalyticshub/resource_bigquery_analytics_hub_listing_subscription_generated_meta.yaml index 2ff273a82fd..04ff84c7c41 100644 --- a/google-beta/services/bigqueryanalyticshub/resource_bigquery_analytics_hub_listing_subscription_generated_meta.yaml +++ b/google-beta/services/bigqueryanalyticshub/resource_bigquery_analytics_hub_listing_subscription_generated_meta.yaml @@ -39,3 +39,5 @@ fields: - api_field: state - api_field: subscriberContact - api_field: subscriptionId + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/bigqueryconnection/resource_bigquery_connection.go b/google-beta/services/bigqueryconnection/resource_bigquery_connection.go index fb96dc80518..9f952caa4ad 100644 --- a/google-beta/services/bigqueryconnection/resource_bigquery_connection.go +++ b/google-beta/services/bigqueryconnection/resource_bigquery_connection.go @@ -115,6 +115,7 @@ func ResourceBigqueryConnectionConnection() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -565,6 +566,18 @@ Azure allowed regions are azure-eastus2`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -763,6 +776,19 @@ func resourceBigqueryConnectionConnectionRead(d *schema.ResourceData, meta inter log.Printf("[DEBUG] Finished reading BigqueryConnectionConnection %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Connection: %s", err) } @@ -800,6 +826,19 @@ func resourceBigqueryConnectionConnectionRead(d *schema.ResourceData, meta inter } func resourceBigqueryConnectionConnectionUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceBigqueryConnectionConnection().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceBigqueryConnectionConnectionRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -987,6 +1026,13 @@ func resourceBigqueryConnectionConnectionUpdate(d *schema.ResourceData, meta int } func resourceBigqueryConnectionConnectionDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy BigqueryConnectionConnection without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Connection %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/bigqueryconnection/resource_bigquery_connection_generated_meta.yaml b/google-beta/services/bigqueryconnection/resource_bigquery_connection_generated_meta.yaml index 7871a93d364..4efacb6e827 100644 --- a/google-beta/services/bigqueryconnection/resource_bigquery_connection_generated_meta.yaml +++ b/google-beta/services/bigqueryconnection/resource_bigquery_connection_generated_meta.yaml @@ -49,3 +49,5 @@ fields: - api_field: spark.metastoreServiceConfig.metastoreService - api_field: spark.serviceAccountId - api_field: spark.sparkHistoryServerConfig.dataprocCluster + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/bigquerydatapolicy/resource_bigquery_datapolicy_data_policy.go b/google-beta/services/bigquerydatapolicy/resource_bigquery_datapolicy_data_policy.go index 495a004b478..9a2778b28fb 100644 --- a/google-beta/services/bigquerydatapolicy/resource_bigquery_datapolicy_data_policy.go +++ b/google-beta/services/bigquerydatapolicy/resource_bigquery_datapolicy_data_policy.go @@ -115,6 +115,7 @@ func ResourceBigqueryDatapolicyDataPolicy() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -200,6 +201,18 @@ func ResourceBigqueryDatapolicyDataPolicy() *schema.Resource { Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -345,6 +358,19 @@ func resourceBigqueryDatapolicyDataPolicyRead(d *schema.ResourceData, meta inter log.Printf("[DEBUG] Finished reading BigqueryDatapolicyDataPolicy %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading DataPolicy: %s", err) } @@ -382,6 +408,19 @@ func resourceBigqueryDatapolicyDataPolicyRead(d *schema.ResourceData, meta inter } func resourceBigqueryDatapolicyDataPolicyUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceBigqueryDatapolicyDataPolicy().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceBigqueryDatapolicyDataPolicyRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -493,6 +532,13 @@ func resourceBigqueryDatapolicyDataPolicyUpdate(d *schema.ResourceData, meta int } func resourceBigqueryDatapolicyDataPolicyDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy BigqueryDatapolicyDataPolicy without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing DataPolicy %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/bigquerydatapolicy/resource_bigquery_datapolicy_data_policy_generated_meta.yaml b/google-beta/services/bigquerydatapolicy/resource_bigquery_datapolicy_data_policy_generated_meta.yaml index 25d43873590..868e1e24c41 100644 --- a/google-beta/services/bigquerydatapolicy/resource_bigquery_datapolicy_data_policy_generated_meta.yaml +++ b/google-beta/services/bigquerydatapolicy/resource_bigquery_datapolicy_data_policy_generated_meta.yaml @@ -15,3 +15,5 @@ fields: provider_only: true - api_field: name - api_field: policyTag + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/bigquerydatapolicyv2/resource_bigquery_datapolicyv2_data_policy.go b/google-beta/services/bigquerydatapolicyv2/resource_bigquery_datapolicyv2_data_policy.go index ff4ca62265e..1577420f69a 100644 --- a/google-beta/services/bigquerydatapolicyv2/resource_bigquery_datapolicyv2_data_policy.go +++ b/google-beta/services/bigquerydatapolicyv2/resource_bigquery_datapolicyv2_data_policy.go @@ -115,6 +115,7 @@ func ResourceBigqueryDatapolicyv2DataPolicy() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -248,6 +249,18 @@ V2`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -404,6 +417,19 @@ func resourceBigqueryDatapolicyv2DataPolicyRead(d *schema.ResourceData, meta int log.Printf("[DEBUG] Finished reading BigqueryDatapolicyv2DataPolicy %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading DataPolicy: %s", err) } @@ -441,6 +467,19 @@ func resourceBigqueryDatapolicyv2DataPolicyRead(d *schema.ResourceData, meta int } func resourceBigqueryDatapolicyv2DataPolicyUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceBigqueryDatapolicyv2DataPolicy().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceBigqueryDatapolicyv2DataPolicyRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -577,6 +616,13 @@ func resourceBigqueryDatapolicyv2DataPolicyUpdate(d *schema.ResourceData, meta i } func resourceBigqueryDatapolicyv2DataPolicyDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy BigqueryDatapolicyv2DataPolicy without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing DataPolicy %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/bigquerydatapolicyv2/resource_bigquery_datapolicyv2_data_policy_generated_meta.yaml b/google-beta/services/bigquerydatapolicyv2/resource_bigquery_datapolicyv2_data_policy_generated_meta.yaml index de4c149861a..3dc7aa51180 100644 --- a/google-beta/services/bigquerydatapolicyv2/resource_bigquery_datapolicyv2_data_policy_generated_meta.yaml +++ b/google-beta/services/bigquerydatapolicyv2/resource_bigquery_datapolicyv2_data_policy_generated_meta.yaml @@ -18,3 +18,5 @@ fields: - api_field: name - api_field: policyTag - api_field: version + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/bigquerydatatransfer/resource_bigquery_data_transfer_config.go b/google-beta/services/bigquerydatatransfer/resource_bigquery_data_transfer_config.go index 5bd6be748f5..b5fa8045a1b 100644 --- a/google-beta/services/bigquerydatatransfer/resource_bigquery_data_transfer_config.go +++ b/google-beta/services/bigquerydatatransfer/resource_bigquery_data_transfer_config.go @@ -192,6 +192,7 @@ func ResourceBigqueryDataTransferConfig() *schema.Resource { sensitiveParamCustomizeDiff, paramsCustomizeDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -412,6 +413,18 @@ The name is ignored when creating a transfer config.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -619,6 +632,19 @@ func resourceBigqueryDataTransferConfigRead(d *schema.ResourceData, meta interfa return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Config: %s", err) } @@ -650,6 +676,19 @@ func resourceBigqueryDataTransferConfigRead(d *schema.ResourceData, meta interfa } func resourceBigqueryDataTransferConfigUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceBigqueryDataTransferConfig().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceBigqueryDataTransferConfigRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -830,6 +869,13 @@ func resourceBigqueryDataTransferConfigUpdate(d *schema.ResourceData, meta inter } func resourceBigqueryDataTransferConfigDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy BigqueryDataTransferConfig without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Config %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/bigquerydatatransfer/resource_bigquery_data_transfer_config_generated_meta.yaml b/google-beta/services/bigquerydatatransfer/resource_bigquery_data_transfer_config_generated_meta.yaml index 84ea392650b..c63e640ce64 100644 --- a/google-beta/services/bigquerydatatransfer/resource_bigquery_data_transfer_config_generated_meta.yaml +++ b/google-beta/services/bigquerydatatransfer/resource_bigquery_data_transfer_config_generated_meta.yaml @@ -31,3 +31,5 @@ fields: provider_only: true - field: service_account_name provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/bigqueryreservation/resource_bigquery_bi_reservation.go b/google-beta/services/bigqueryreservation/resource_bigquery_bi_reservation.go index 9ad7adb6374..e6b73df8c9a 100644 --- a/google-beta/services/bigqueryreservation/resource_bigquery_bi_reservation.go +++ b/google-beta/services/bigqueryreservation/resource_bigquery_bi_reservation.go @@ -115,6 +115,7 @@ func ResourceBigqueryReservationBiReservation() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -190,6 +191,18 @@ A timestamp in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to n Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -333,6 +346,19 @@ func resourceBigqueryReservationBiReservationRead(d *schema.ResourceData, meta i log.Printf("[DEBUG] Finished reading BigqueryReservationBiReservation %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading BiReservation: %s", err) } @@ -364,6 +390,19 @@ func resourceBigqueryReservationBiReservationRead(d *schema.ResourceData, meta i } func resourceBigqueryReservationBiReservationUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceBigqueryReservationBiReservation().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceBigqueryReservationBiReservationRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -460,6 +499,13 @@ func resourceBigqueryReservationBiReservationUpdate(d *schema.ResourceData, meta } func resourceBigqueryReservationBiReservationDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy BigqueryReservationBiReservation without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing BiReservation %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/bigqueryreservation/resource_bigquery_bi_reservation_generated_meta.yaml b/google-beta/services/bigqueryreservation/resource_bigquery_bi_reservation_generated_meta.yaml index 457fe234336..0a0a4fe4e6f 100644 --- a/google-beta/services/bigqueryreservation/resource_bigquery_bi_reservation_generated_meta.yaml +++ b/google-beta/services/bigqueryreservation/resource_bigquery_bi_reservation_generated_meta.yaml @@ -15,3 +15,5 @@ fields: - api_field: preferredTables.tableId - api_field: size - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/bigqueryreservation/resource_bigquery_capacity_commitment.go b/google-beta/services/bigqueryreservation/resource_bigquery_capacity_commitment.go index 49e7d444609..d01c0bc5097 100644 --- a/google-beta/services/bigqueryreservation/resource_bigquery_capacity_commitment.go +++ b/google-beta/services/bigqueryreservation/resource_bigquery_capacity_commitment.go @@ -122,6 +122,7 @@ func ResourceBigqueryReservationCapacityCommitment() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -221,6 +222,18 @@ Examples: US, EU, asia-northeast1. The default value is US.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -372,6 +385,19 @@ func resourceBigqueryReservationCapacityCommitmentRead(d *schema.ResourceData, m log.Printf("[DEBUG] Finished reading BigqueryReservationCapacityCommitment %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading CapacityCommitment: %s", err) } @@ -409,6 +435,19 @@ func resourceBigqueryReservationCapacityCommitmentRead(d *schema.ResourceData, m } func resourceBigqueryReservationCapacityCommitmentUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceBigqueryReservationCapacityCommitment().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceBigqueryReservationCapacityCommitmentRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -510,6 +549,13 @@ func resourceBigqueryReservationCapacityCommitmentUpdate(d *schema.ResourceData, } func resourceBigqueryReservationCapacityCommitmentDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy BigqueryReservationCapacityCommitment without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing CapacityCommitment %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/bigqueryreservation/resource_bigquery_capacity_commitment_generated_meta.yaml b/google-beta/services/bigqueryreservation/resource_bigquery_capacity_commitment_generated_meta.yaml index d827ab267ab..02447bcd02b 100644 --- a/google-beta/services/bigqueryreservation/resource_bigquery_capacity_commitment_generated_meta.yaml +++ b/google-beta/services/bigqueryreservation/resource_bigquery_capacity_commitment_generated_meta.yaml @@ -21,3 +21,5 @@ fields: - api_field: renewalPlan - api_field: slotCount - api_field: state + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/bigqueryreservation/resource_bigquery_reservation.go b/google-beta/services/bigqueryreservation/resource_bigquery_reservation.go index 162ca97f43d..cfe1d5acef1 100644 --- a/google-beta/services/bigqueryreservation/resource_bigquery_reservation.go +++ b/google-beta/services/bigqueryreservation/resource_bigquery_reservation.go @@ -115,6 +115,7 @@ func ResourceBigqueryReservationReservation() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -371,6 +372,18 @@ replicated to the secondary.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -546,6 +559,19 @@ func resourceBigqueryReservationReservationRead(d *schema.ResourceData, meta int log.Printf("[DEBUG] Finished reading BigqueryReservationReservation %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Reservation: %s", err) } @@ -583,6 +609,19 @@ func resourceBigqueryReservationReservationRead(d *schema.ResourceData, meta int } func resourceBigqueryReservationReservationUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceBigqueryReservationReservation().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceBigqueryReservationReservationRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -744,6 +783,13 @@ func resourceBigqueryReservationReservationUpdate(d *schema.ResourceData, meta i } func resourceBigqueryReservationReservationDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy BigqueryReservationReservation without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Reservation %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/bigqueryreservation/resource_bigquery_reservation_assignment.go b/google-beta/services/bigqueryreservation/resource_bigquery_reservation_assignment.go index 5d1d589dc30..8f7c493fc94 100644 --- a/google-beta/services/bigqueryreservation/resource_bigquery_reservation_assignment.go +++ b/google-beta/services/bigqueryreservation/resource_bigquery_reservation_assignment.go @@ -100,6 +100,7 @@ func ResourceBigqueryReservationReservationAssignment() *schema.Resource { return &schema.Resource{ Create: resourceBigqueryReservationReservationAssignmentCreate, Read: resourceBigqueryReservationReservationAssignmentRead, + Update: resourceBigqueryReservationReservationAssignmentUpdate, Delete: resourceBigqueryReservationReservationAssignmentDelete, Importer: &schema.ResourceImporter{ @@ -113,6 +114,7 @@ func ResourceBigqueryReservationReservationAssignment() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -187,6 +189,18 @@ Possible values: STATE_UNSPECIFIED, PENDING, ACTIVE`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -363,6 +377,19 @@ func resourceBigqueryReservationReservationAssignmentRead(d *schema.ResourceData return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading ReservationAssignment: %s", err) } @@ -405,7 +432,19 @@ func resourceBigqueryReservationReservationAssignmentRead(d *schema.ResourceData return nil } +func resourceBigqueryReservationReservationAssignmentUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceBigqueryReservationReservationAssignmentRead(d, meta) +} + func resourceBigqueryReservationReservationAssignmentDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy BigqueryReservationReservationAssignment without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing ReservationAssignment %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/bigqueryreservation/resource_bigquery_reservation_assignment_generated_meta.yaml b/google-beta/services/bigqueryreservation/resource_bigquery_reservation_assignment_generated_meta.yaml index 7bf964dff15..a30081032b0 100644 --- a/google-beta/services/bigqueryreservation/resource_bigquery_reservation_assignment_generated_meta.yaml +++ b/google-beta/services/bigqueryreservation/resource_bigquery_reservation_assignment_generated_meta.yaml @@ -15,3 +15,5 @@ fields: - field: reservation provider_only: true - api_field: state + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/bigqueryreservation/resource_bigquery_reservation_generated_meta.yaml b/google-beta/services/bigqueryreservation/resource_bigquery_reservation_generated_meta.yaml index f1cfbbee860..2703e775d0d 100644 --- a/google-beta/services/bigqueryreservation/resource_bigquery_reservation_generated_meta.yaml +++ b/google-beta/services/bigqueryreservation/resource_bigquery_reservation_generated_meta.yaml @@ -27,3 +27,5 @@ fields: - api_field: scalingMode - api_field: secondaryLocation - api_field: slotCapacity + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/bigqueryreservation/resource_bigquery_reservation_group.go b/google-beta/services/bigqueryreservation/resource_bigquery_reservation_group.go index 864f28930b7..9be9b6c3077 100644 --- a/google-beta/services/bigqueryreservation/resource_bigquery_reservation_group.go +++ b/google-beta/services/bigqueryreservation/resource_bigquery_reservation_group.go @@ -100,6 +100,7 @@ func ResourceBigqueryReservationReservationGroup() *schema.Resource { return &schema.Resource{ Create: resourceBigqueryReservationReservationGroupCreate, Read: resourceBigqueryReservationReservationGroupRead, + Update: resourceBigqueryReservationReservationGroupUpdate, Delete: resourceBigqueryReservationReservationGroupDelete, Importer: &schema.ResourceImporter{ @@ -113,6 +114,7 @@ func ResourceBigqueryReservationReservationGroup() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -160,6 +162,18 @@ Examples: US, EU, asia-northeast1. The default value is US.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -287,6 +301,19 @@ func resourceBigqueryReservationReservationGroupRead(d *schema.ResourceData, met log.Printf("[DEBUG] Finished reading BigqueryReservationReservationGroup %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading ReservationGroup: %s", err) } @@ -323,7 +350,19 @@ func resourceBigqueryReservationReservationGroupRead(d *schema.ResourceData, met return nil } +func resourceBigqueryReservationReservationGroupUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceBigqueryReservationReservationGroupRead(d, meta) +} + func resourceBigqueryReservationReservationGroupDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy BigqueryReservationReservationGroup without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing ReservationGroup %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/bigqueryreservation/resource_bigquery_reservation_group_generated_meta.yaml b/google-beta/services/bigqueryreservation/resource_bigquery_reservation_group_generated_meta.yaml index 6bfdaffd4a6..07da6ad4b06 100644 --- a/google-beta/services/bigqueryreservation/resource_bigquery_reservation_group_generated_meta.yaml +++ b/google-beta/services/bigqueryreservation/resource_bigquery_reservation_group_generated_meta.yaml @@ -10,3 +10,5 @@ fields: - field: location provider_only: true - api_field: name + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/bigtable/resource_bigtable_app_profile.go b/google-beta/services/bigtable/resource_bigtable_app_profile.go index 880a25437f0..9417741f6a8 100644 --- a/google-beta/services/bigtable/resource_bigtable_app_profile.go +++ b/google-beta/services/bigtable/resource_bigtable_app_profile.go @@ -117,6 +117,7 @@ func ResourceBigtableAppProfile() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -258,6 +259,18 @@ It is unsafe to send these requests to the same table/row/column in multiple clu Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -414,6 +427,19 @@ func resourceBigtableAppProfileRead(d *schema.ResourceData, meta interface{}) er log.Printf("[DEBUG] Finished reading BigtableAppProfile %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading AppProfile: %s", err) } @@ -451,6 +477,19 @@ func resourceBigtableAppProfileRead(d *schema.ResourceData, meta interface{}) er } func resourceBigtableAppProfileUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceBigtableAppProfile().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceBigtableAppProfileRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -623,6 +662,13 @@ func resourceBigtableAppProfileUpdate(d *schema.ResourceData, meta interface{}) } func resourceBigtableAppProfileDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy BigtableAppProfile without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing AppProfile %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/bigtable/resource_bigtable_app_profile_generated_meta.yaml b/google-beta/services/bigtable/resource_bigtable_app_profile_generated_meta.yaml index a8f00bd2dee..19411b8028c 100644 --- a/google-beta/services/bigtable/resource_bigtable_app_profile_generated_meta.yaml +++ b/google-beta/services/bigtable/resource_bigtable_app_profile_generated_meta.yaml @@ -22,3 +22,5 @@ fields: - api_field: singleClusterRouting.allowTransactionalWrites - api_field: singleClusterRouting.clusterId - api_field: standardIsolation.priority + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/bigtable/resource_bigtable_authorized_view.go b/google-beta/services/bigtable/resource_bigtable_authorized_view.go index 57b9616dc42..08f76ddc609 100644 --- a/google-beta/services/bigtable/resource_bigtable_authorized_view.go +++ b/google-beta/services/bigtable/resource_bigtable_authorized_view.go @@ -72,6 +72,7 @@ func ResourceBigtableAuthorizedView() *schema.Resource { }, CustomizeDiff: customdiff.All( + tpgresource.DefaultProviderDeletionPolicy("DELETE"), tpgresource.DefaultProviderProject, ), @@ -138,6 +139,9 @@ If not provided, currently deletion protection will be set to UNPROTECTED as it }, }, }, + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end }, UseJSONNumber: true, } @@ -269,10 +273,19 @@ func resourceBigtableAuthorizedViewRead(d *schema.ResourceData, meta interface{} return fmt.Errorf("Error parsing server returned subset_view since it's empty") } + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + return nil } func resourceBigtableAuthorizedViewUpdate(d *schema.ResourceData, meta interface{}) error { + + if tpgresource.DeletionPolicyPreUpdate(d, ResourceBigtableAuthorizedView) { + return ResourceBigtableAuthorizedView().Read(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -336,6 +349,13 @@ func resourceBigtableAuthorizedViewUpdate(d *schema.ResourceData, meta interface } func resourceBigtableAuthorizedViewDestroy(d *schema.ResourceData, meta interface{}) error { + + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { + return nil + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/bigtable/resource_bigtable_authorized_view_meta.yaml b/google-beta/services/bigtable/resource_bigtable_authorized_view_meta.yaml index 48fbe3dbe76..4aa4dfd2ee8 100644 --- a/google-beta/services/bigtable/resource_bigtable_authorized_view_meta.yaml +++ b/google-beta/services/bigtable/resource_bigtable_authorized_view_meta.yaml @@ -15,3 +15,5 @@ fields: - field: 'subset_view.family_subsets.qualifiers' - api_field: 'subsetView.rowPrefixes' - field: 'table_name' + - field: 'deletion_policy' + provider_only: true diff --git a/google-beta/services/bigtable/resource_bigtable_gc_policy.go b/google-beta/services/bigtable/resource_bigtable_gc_policy.go index 2ccbeba02ed..9ea9af4b6b4 100644 --- a/google-beta/services/bigtable/resource_bigtable_gc_policy.go +++ b/google-beta/services/bigtable/resource_bigtable_gc_policy.go @@ -26,6 +26,7 @@ import ( "time" "cloud.google.com/go/bigtable" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/structure" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" @@ -111,12 +112,14 @@ func resourceBigtableGCPolicyCustomizeDiff(_ context.Context, d *schema.Resource func ResourceBigtableGCPolicy() *schema.Resource { return &schema.Resource{ - Create: resourceBigtableGCPolicyUpsert, - Read: resourceBigtableGCPolicyRead, - Delete: resourceBigtableGCPolicyDestroy, - Update: resourceBigtableGCPolicyUpsert, - CustomizeDiff: resourceBigtableGCPolicyCustomizeDiff, - + Create: resourceBigtableGCPolicyUpsert, + Read: resourceBigtableGCPolicyRead, + Delete: resourceBigtableGCPolicyDestroy, + Update: resourceBigtableGCPolicyUpsert, + CustomizeDiff: customdiff.All( + tpgresource.DefaultProviderDeletionPolicy("DELETE"), + resourceBigtableGCPolicyCustomizeDiff, + ), Timeouts: &schema.ResourceTimeout{ Create: schema.DefaultTimeout(20 * time.Minute), Delete: schema.DefaultTimeout(20 * time.Minute), @@ -225,14 +228,9 @@ func ResourceBigtableGCPolicy() *schema.Resource { Description: `The ID of the project in which the resource belongs. If it is not provided, the provider project is used.`, }, - "deletion_policy": { - Type: schema.TypeString, - Optional: true, - Description: `The deletion policy for the GC policy. Setting ABANDON allows the resource - to be abandoned rather than deleted. This is useful for GC policy as it cannot be deleted - in a replicated instance. Possible values are: "ABANDON".`, - ValidateFunc: validation.StringInSlice([]string{"ABANDON", ""}, false), - }, + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end "ignore_warnings": { Type: schema.TypeBool, @@ -249,6 +247,11 @@ func ResourceBigtableGCPolicy() *schema.Resource { } func resourceBigtableGCPolicyUpsert(d *schema.ResourceData, meta interface{}) error { + + if tpgresource.DeletionPolicyPreUpdate(d, ResourceBigtableGCPolicy) { + return ResourceBigtableGCPolicy().Read(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -386,6 +389,10 @@ func resourceBigtableGCPolicyRead(d *schema.ResourceData, meta interface{}) erro return fmt.Errorf("Error setting project: %s", err) } + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + return nil } @@ -453,15 +460,15 @@ func GcPolicyToGCRuleString(gc bigtable.GCPolicy, topLevel bool) (map[string]int } func resourceBigtableGCPolicyDestroy(d *schema.ResourceData, meta interface{}) error { - config := meta.(*transport_tpg.Config) - if deletionPolicy := d.Get("deletion_policy"); deletionPolicy == "ABANDON" { - // Allows for the GC policy to be abandoned without deletion to avoid possible - // deletion failure in a replicated instance. - log.Printf("[WARN] The GC policy is abandoned") + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { return nil } + config := meta.(*transport_tpg.Config) + userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { return err diff --git a/google-beta/services/bigtable/resource_bigtable_gc_policy_meta.yaml b/google-beta/services/bigtable/resource_bigtable_gc_policy_meta.yaml index 921d51aa2bd..de6697ead24 100644 --- a/google-beta/services/bigtable/resource_bigtable_gc_policy_meta.yaml +++ b/google-beta/services/bigtable/resource_bigtable_gc_policy_meta.yaml @@ -8,6 +8,7 @@ api_resource_type_kind: 'Table' fields: - field: 'column_family' - field: 'deletion_policy' + provider_only: true - field: 'gc_rules' - field: 'ignore_warnings' - field: 'instance_name' diff --git a/google-beta/services/bigtable/resource_bigtable_instance.go b/google-beta/services/bigtable/resource_bigtable_instance.go index e2047531a79..9cc721fcbe8 100644 --- a/google-beta/services/bigtable/resource_bigtable_instance.go +++ b/google-beta/services/bigtable/resource_bigtable_instance.go @@ -70,6 +70,7 @@ func ResourceBigtableInstance() *schema.Resource { }, CustomizeDiff: customdiff.All( + tpgresource.DefaultProviderDeletionPolicy("DELETE"), tpgresource.DefaultProviderProject, resourceBigtableInstanceClusterReorderTypeList, resourceBigtableInstanceUniqueClusterID, @@ -240,7 +241,9 @@ func ResourceBigtableInstance() *schema.Resource { ForceNew: true, Description: `The ID of the project in which the resource belongs. If it is not provided, the provider project is used.`, }, - + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end "tags": { Type: schema.TypeMap, Optional: true, @@ -409,10 +412,19 @@ func resourceBigtableInstanceRead(d *schema.ResourceData, meta interface{}) erro } } + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + return nil } func resourceBigtableInstanceUpdate(d *schema.ResourceData, meta interface{}) error { + + if tpgresource.DeletionPolicyPreUpdate(d, ResourceBigtableInstance) { + return ResourceBigtableInstance().Read(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -480,6 +492,13 @@ func resourceBigtableInstanceUpdate(d *schema.ResourceData, meta interface{}) er func resourceBigtableInstanceDestroy(d *schema.ResourceData, meta interface{}) error { log.Printf("[DEBUG] Deleting BigTable instance %q", d.Id()) + + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { + return nil + } + if d.Get("deletion_protection").(bool) { return fmt.Errorf("cannot destroy instance without setting deletion_protection=false and running `terraform apply`") } diff --git a/google-beta/services/bigtable/resource_bigtable_instance_meta.yaml b/google-beta/services/bigtable/resource_bigtable_instance_meta.yaml index 926f6e07b81..6350e1e3be7 100644 --- a/google-beta/services/bigtable/resource_bigtable_instance_meta.yaml +++ b/google-beta/services/bigtable/resource_bigtable_instance_meta.yaml @@ -31,3 +31,5 @@ fields: - api_field: 'tags' - field: 'terraform_labels' provider_only: true + - field: 'deletion_policy' + provider_only: true diff --git a/google-beta/services/bigtable/resource_bigtable_logical_view.go b/google-beta/services/bigtable/resource_bigtable_logical_view.go index f31e57d812e..7cee636241c 100644 --- a/google-beta/services/bigtable/resource_bigtable_logical_view.go +++ b/google-beta/services/bigtable/resource_bigtable_logical_view.go @@ -115,6 +115,7 @@ func ResourceBigtableLogicalView() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -175,6 +176,18 @@ func ResourceBigtableLogicalView() *schema.Resource { Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -308,6 +321,19 @@ func resourceBigtableLogicalViewRead(d *schema.ResourceData, meta interface{}) e log.Printf("[DEBUG] Finished reading BigtableLogicalView %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading LogicalView: %s", err) } @@ -345,6 +371,19 @@ func resourceBigtableLogicalViewRead(d *schema.ResourceData, meta interface{}) e } func resourceBigtableLogicalViewUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceBigtableLogicalView().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceBigtableLogicalViewRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -446,6 +485,13 @@ func resourceBigtableLogicalViewUpdate(d *schema.ResourceData, meta interface{}) } func resourceBigtableLogicalViewDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy BigtableLogicalView without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing LogicalView %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/bigtable/resource_bigtable_logical_view_generated_meta.yaml b/google-beta/services/bigtable/resource_bigtable_logical_view_generated_meta.yaml index 2f8107a7ba3..4f82e9706aa 100644 --- a/google-beta/services/bigtable/resource_bigtable_logical_view_generated_meta.yaml +++ b/google-beta/services/bigtable/resource_bigtable_logical_view_generated_meta.yaml @@ -16,3 +16,5 @@ fields: provider_only: true - api_field: name - api_field: query + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/bigtable/resource_bigtable_materialized_view.go b/google-beta/services/bigtable/resource_bigtable_materialized_view.go index b2d139b183b..b8cda425b86 100644 --- a/google-beta/services/bigtable/resource_bigtable_materialized_view.go +++ b/google-beta/services/bigtable/resource_bigtable_materialized_view.go @@ -115,6 +115,7 @@ func ResourceBigtableMaterializedView() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -176,6 +177,18 @@ func ResourceBigtableMaterializedView() *schema.Resource { Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -309,6 +322,19 @@ func resourceBigtableMaterializedViewRead(d *schema.ResourceData, meta interface log.Printf("[DEBUG] Finished reading BigtableMaterializedView %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading MaterializedView: %s", err) } @@ -346,6 +372,19 @@ func resourceBigtableMaterializedViewRead(d *schema.ResourceData, meta interface } func resourceBigtableMaterializedViewUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceBigtableMaterializedView().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceBigtableMaterializedViewRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -437,6 +476,13 @@ func resourceBigtableMaterializedViewUpdate(d *schema.ResourceData, meta interfa } func resourceBigtableMaterializedViewDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy BigtableMaterializedView without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing MaterializedView %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/bigtable/resource_bigtable_materialized_view_generated_meta.yaml b/google-beta/services/bigtable/resource_bigtable_materialized_view_generated_meta.yaml index b94ab519fed..4b56de0117d 100644 --- a/google-beta/services/bigtable/resource_bigtable_materialized_view_generated_meta.yaml +++ b/google-beta/services/bigtable/resource_bigtable_materialized_view_generated_meta.yaml @@ -16,3 +16,5 @@ fields: provider_only: true - api_field: name - api_field: query + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/bigtable/resource_bigtable_schema_bundle.go b/google-beta/services/bigtable/resource_bigtable_schema_bundle.go index bed31fb2a58..7c8936f26c5 100644 --- a/google-beta/services/bigtable/resource_bigtable_schema_bundle.go +++ b/google-beta/services/bigtable/resource_bigtable_schema_bundle.go @@ -115,6 +115,7 @@ func ResourceBigtableSchemaBundle() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -209,6 +210,18 @@ an ABORTED error on a mismatched etag.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -341,6 +354,19 @@ func resourceBigtableSchemaBundleRead(d *schema.ResourceData, meta interface{}) log.Printf("[DEBUG] Finished reading BigtableSchemaBundle %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading SchemaBundle: %s", err) } @@ -384,6 +410,19 @@ func resourceBigtableSchemaBundleRead(d *schema.ResourceData, meta interface{}) } func resourceBigtableSchemaBundleUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceBigtableSchemaBundle().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceBigtableSchemaBundleRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -480,6 +519,13 @@ func resourceBigtableSchemaBundleUpdate(d *schema.ResourceData, meta interface{} } func resourceBigtableSchemaBundleDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy BigtableSchemaBundle without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing SchemaBundle %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/bigtable/resource_bigtable_schema_bundle_generated_meta.yaml b/google-beta/services/bigtable/resource_bigtable_schema_bundle_generated_meta.yaml index 7170633dc72..cb99b17b7cc 100644 --- a/google-beta/services/bigtable/resource_bigtable_schema_bundle_generated_meta.yaml +++ b/google-beta/services/bigtable/resource_bigtable_schema_bundle_generated_meta.yaml @@ -20,3 +20,5 @@ fields: provider_only: true - field: table provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/bigtable/resource_bigtable_table.go b/google-beta/services/bigtable/resource_bigtable_table.go index ada5fc3d0fe..9ee88073dfc 100644 --- a/google-beta/services/bigtable/resource_bigtable_table.go +++ b/google-beta/services/bigtable/resource_bigtable_table.go @@ -70,6 +70,7 @@ func ResourceBigtableTable() *schema.Resource { }, CustomizeDiff: customdiff.All( + tpgresource.DefaultProviderDeletionPolicy("DELETE"), tpgresource.DefaultProviderProject, abpDiffFunc, ), @@ -184,6 +185,9 @@ func ResourceBigtableTable() *schema.Resource { The schema must be a valid JSON encoded string representing a Type's struct protobuf message. Note that for bytes sequence (like delimited_bytes.delimiter) the delimiter must be base64 encoded. For example, if you want to set a delimiter to a single byte character "#", it should be set to "Iw==", which is the base64 encoding of the byte sequence "#".`, }, + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end }, UseJSONNumber: true, } @@ -457,6 +461,10 @@ func resourceBigtableTableRead(d *schema.ResourceData, meta interface{}) error { d.Set("row_key_schema", nil) } + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + return nil } @@ -503,6 +511,11 @@ func familyMapDiffValueTypes(a, b map[string]bigtable.Family) map[string]bigtabl } func resourceBigtableTableUpdate(d *schema.ResourceData, meta interface{}) error { + + if tpgresource.DeletionPolicyPreUpdate(d, ResourceBigtableTable) { + return ResourceBigtableTable().Read(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -648,6 +661,13 @@ func resourceBigtableTableUpdate(d *schema.ResourceData, meta interface{}) error } func resourceBigtableTableDestroy(d *schema.ResourceData, meta interface{}) error { + + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { + return nil + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/bigtable/resource_bigtable_table_meta.yaml b/google-beta/services/bigtable/resource_bigtable_table_meta.yaml index b73a3215dc7..61b9b774fdd 100644 --- a/google-beta/services/bigtable/resource_bigtable_table_meta.yaml +++ b/google-beta/services/bigtable/resource_bigtable_table_meta.yaml @@ -20,3 +20,5 @@ fields: - api_field: 'rowKeySchema' json: true - field: 'split_keys' + - field: 'deletion_policy' + provider_only: true diff --git a/google-beta/services/billingbudgets/resource_billing_budget.go b/google-beta/services/billingbudgets/resource_billing_budget.go index c7ec12abde7..c66ef51593b 100644 --- a/google-beta/services/billingbudgets/resource_billing_budget.go +++ b/google-beta/services/billingbudgets/resource_billing_budget.go @@ -500,6 +500,19 @@ the threshold. Default value: "CURRENT_SPEND" Possible values: ["CURRENT_SPEND", implies the scope of a budget. Values are of the form billingAccounts/{billingAccountId}/budgets/{budgetId}.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -646,6 +659,20 @@ func resourceBillingBudgetsBudgetRead(d *schema.ResourceData, meta interface{}) log.Printf("[DEBUG] Finished reading BillingBudgetsBudget %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceBillingBudgetsBudgetFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -673,6 +700,19 @@ func resourceBillingBudgetsBudgetRead(d *schema.ResourceData, meta interface{}) } func resourceBillingBudgetsBudgetUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceBillingBudgetsBudget().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceBillingBudgetsBudgetRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -817,6 +857,13 @@ func resourceBillingBudgetsBudgetUpdate(d *schema.ResourceData, meta interface{} } func resourceBillingBudgetsBudgetDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy BillingBudgetsBudget without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Budget %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/billingbudgets/resource_billing_budget_generated_meta.yaml b/google-beta/services/billingbudgets/resource_billing_budget_generated_meta.yaml index e1689962e50..1172643a349 100644 --- a/google-beta/services/billingbudgets/resource_billing_budget_generated_meta.yaml +++ b/google-beta/services/billingbudgets/resource_billing_budget_generated_meta.yaml @@ -42,3 +42,5 @@ fields: - api_field: ownershipScope - api_field: thresholdRules.spendBasis - api_field: thresholdRules.thresholdPercent + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/binaryauthorization/resource_binary_authorization_attestor.go b/google-beta/services/binaryauthorization/resource_binary_authorization_attestor.go index 2c7b181ded3..af7376c6f73 100644 --- a/google-beta/services/binaryauthorization/resource_binary_authorization_attestor.go +++ b/google-beta/services/binaryauthorization/resource_binary_authorization_attestor.go @@ -143,6 +143,7 @@ func ResourceBinaryAuthorizationAttestor() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -294,6 +295,18 @@ displayed in chooser dialogs.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -428,6 +441,19 @@ func resourceBinaryAuthorizationAttestorRead(d *schema.ResourceData, meta interf log.Printf("[DEBUG] Finished reading BinaryAuthorizationAttestor %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Attestor: %s", err) } @@ -459,6 +485,19 @@ func resourceBinaryAuthorizationAttestorRead(d *schema.ResourceData, meta interf } func resourceBinaryAuthorizationAttestorUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceBinaryAuthorizationAttestor().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceBinaryAuthorizationAttestorRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -542,6 +581,13 @@ func resourceBinaryAuthorizationAttestorUpdate(d *schema.ResourceData, meta inte } func resourceBinaryAuthorizationAttestorDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy BinaryAuthorizationAttestor without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Attestor %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/binaryauthorization/resource_binary_authorization_attestor_generated_meta.yaml b/google-beta/services/binaryauthorization/resource_binary_authorization_attestor_generated_meta.yaml index 3f7959f93d3..cdddb15b391 100644 --- a/google-beta/services/binaryauthorization/resource_binary_authorization_attestor_generated_meta.yaml +++ b/google-beta/services/binaryauthorization/resource_binary_authorization_attestor_generated_meta.yaml @@ -23,3 +23,5 @@ fields: field: attestation_authority_note.public_keys.pkix_public_key.signature_algorithm - api_field: description - api_field: name + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/binaryauthorization/resource_binary_authorization_policy.go b/google-beta/services/binaryauthorization/resource_binary_authorization_policy.go index 8bbcea02235..e03429f6284 100644 --- a/google-beta/services/binaryauthorization/resource_binary_authorization_policy.go +++ b/google-beta/services/binaryauthorization/resource_binary_authorization_policy.go @@ -130,6 +130,7 @@ func ResourceBinaryAuthorizationPolicy() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -303,6 +304,18 @@ policy will be subject to the project admission policy. Possible values: ["ENABL Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -444,6 +457,19 @@ func resourceBinaryAuthorizationPolicyRead(d *schema.ResourceData, meta interfac log.Printf("[DEBUG] Finished reading BinaryAuthorizationPolicy %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Policy: %s", err) } @@ -469,6 +495,19 @@ func resourceBinaryAuthorizationPolicyRead(d *schema.ResourceData, meta interfac } func resourceBinaryAuthorizationPolicyUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceBinaryAuthorizationPolicy().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceBinaryAuthorizationPolicyRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -559,6 +598,13 @@ func resourceBinaryAuthorizationPolicyUpdate(d *schema.ResourceData, meta interf } func resourceBinaryAuthorizationPolicyDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy BinaryAuthorizationPolicy without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Policy %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/binaryauthorization/resource_binary_authorization_policy_generated_meta.yaml b/google-beta/services/binaryauthorization/resource_binary_authorization_policy_generated_meta.yaml index 23e638222df..319bd1f6400 100644 --- a/google-beta/services/binaryauthorization/resource_binary_authorization_policy_generated_meta.yaml +++ b/google-beta/services/binaryauthorization/resource_binary_authorization_policy_generated_meta.yaml @@ -23,3 +23,5 @@ fields: - api_field: defaultAdmissionRule.requireAttestationsBy - api_field: description - api_field: globalPolicyEvaluationMode + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/blockchainnodeengine/resource_blockchain_node_engine_blockchain_nodes.go b/google-beta/services/blockchainnodeengine/resource_blockchain_node_engine_blockchain_nodes.go index 213613a50fa..ad0d0237876 100644 --- a/google-beta/services/blockchainnodeengine/resource_blockchain_node_engine_blockchain_nodes.go +++ b/google-beta/services/blockchainnodeengine/resource_blockchain_node_engine_blockchain_nodes.go @@ -116,6 +116,7 @@ func ResourceBlockchainNodeEngineBlockchainNodes() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -351,6 +352,18 @@ Please refer to the field 'effective_labels' for all of the labels present on th Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -500,6 +513,19 @@ func resourceBlockchainNodeEngineBlockchainNodesRead(d *schema.ResourceData, met log.Printf("[DEBUG] Finished reading BlockchainNodeEngineBlockchainNodes %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading BlockchainNodes: %s", err) } @@ -537,6 +563,19 @@ func resourceBlockchainNodeEngineBlockchainNodesRead(d *schema.ResourceData, met } func resourceBlockchainNodeEngineBlockchainNodesUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceBlockchainNodeEngineBlockchainNodes().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceBlockchainNodeEngineBlockchainNodesRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -633,6 +672,13 @@ func resourceBlockchainNodeEngineBlockchainNodesUpdate(d *schema.ResourceData, m } func resourceBlockchainNodeEngineBlockchainNodesDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy BlockchainNodeEngineBlockchainNodes without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing BlockchainNodes %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/blockchainnodeengine/resource_blockchain_node_engine_blockchain_nodes_generated_meta.yaml b/google-beta/services/blockchainnodeengine/resource_blockchain_node_engine_blockchain_nodes_generated_meta.yaml index 8e780d371f5..ce744ee1c14 100644 --- a/google-beta/services/blockchainnodeengine/resource_blockchain_node_engine_blockchain_nodes_generated_meta.yaml +++ b/google-beta/services/blockchainnodeengine/resource_blockchain_node_engine_blockchain_nodes_generated_meta.yaml @@ -35,3 +35,5 @@ fields: - field: terraform_labels provider_only: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/certificatemanager/resource_certificate_manager_certificate.go b/google-beta/services/certificatemanager/resource_certificate_manager_certificate.go index aedb8c4a99d..1ab7a4425e8 100644 --- a/google-beta/services/certificatemanager/resource_certificate_manager_certificate.go +++ b/google-beta/services/certificatemanager/resource_certificate_manager_certificate.go @@ -132,6 +132,7 @@ func ResourceCertificateManagerCertificate() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -386,6 +387,18 @@ Leaf certificate comes first, followed by intermediate ones if any.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -547,6 +560,19 @@ func resourceCertificateManagerCertificateRead(d *schema.ResourceData, meta inte log.Printf("[DEBUG] Finished reading CertificateManagerCertificate %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Certificate: %s", err) } @@ -584,6 +610,19 @@ func resourceCertificateManagerCertificateRead(d *schema.ResourceData, meta inte } func resourceCertificateManagerCertificateUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceCertificateManagerCertificate().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceCertificateManagerCertificateRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -692,6 +731,13 @@ func resourceCertificateManagerCertificateUpdate(d *schema.ResourceData, meta in } func resourceCertificateManagerCertificateDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy CertificateManagerCertificate without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Certificate %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/certificatemanager/resource_certificate_manager_certificate_generated_meta.yaml b/google-beta/services/certificatemanager/resource_certificate_manager_certificate_generated_meta.yaml index 4f28a0245f3..4cf0dc4d9e0 100644 --- a/google-beta/services/certificatemanager/resource_certificate_manager_certificate_generated_meta.yaml +++ b/google-beta/services/certificatemanager/resource_certificate_manager_certificate_generated_meta.yaml @@ -33,3 +33,5 @@ fields: - api_field: selfManaged.privateKeyPem - field: terraform_labels provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/certificatemanager/resource_certificate_manager_certificate_issuance_config.go b/google-beta/services/certificatemanager/resource_certificate_manager_certificate_issuance_config.go index 20ab2ecb3b6..aa292f09c3d 100644 --- a/google-beta/services/certificatemanager/resource_certificate_manager_certificate_issuance_config.go +++ b/google-beta/services/certificatemanager/resource_certificate_manager_certificate_issuance_config.go @@ -125,6 +125,7 @@ func ResourceCertificateManagerCertificateIssuanceConfig() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -270,6 +271,18 @@ Examples: "2014-10-02T15:01:23Z" and "2014-10-02T15:01:23.045123456Z".`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -437,6 +450,19 @@ func resourceCertificateManagerCertificateIssuanceConfigRead(d *schema.ResourceD log.Printf("[DEBUG] Finished reading CertificateManagerCertificateIssuanceConfig %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading CertificateIssuanceConfig: %s", err) } @@ -474,11 +500,18 @@ func resourceCertificateManagerCertificateIssuanceConfigRead(d *schema.ResourceD } func resourceCertificateManagerCertificateIssuanceConfigUpdate(d *schema.ResourceData, meta interface{}) error { - // Only the root field "labels", "terraform_labels", and virtual fields are mutable + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable return resourceCertificateManagerCertificateIssuanceConfigRead(d, meta) } func resourceCertificateManagerCertificateIssuanceConfigDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy CertificateManagerCertificateIssuanceConfig without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing CertificateIssuanceConfig %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/certificatemanager/resource_certificate_manager_certificate_issuance_config_generated_meta.yaml b/google-beta/services/certificatemanager/resource_certificate_manager_certificate_issuance_config_generated_meta.yaml index 6e7b5011c8c..5cf60472233 100644 --- a/google-beta/services/certificatemanager/resource_certificate_manager_certificate_issuance_config_generated_meta.yaml +++ b/google-beta/services/certificatemanager/resource_certificate_manager_certificate_issuance_config_generated_meta.yaml @@ -23,3 +23,5 @@ fields: - field: terraform_labels provider_only: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/certificatemanager/resource_certificate_manager_certificate_map.go b/google-beta/services/certificatemanager/resource_certificate_manager_certificate_map.go index 3ba0596b04d..9f86904f45e 100644 --- a/google-beta/services/certificatemanager/resource_certificate_manager_certificate_map.go +++ b/google-beta/services/certificatemanager/resource_certificate_manager_certificate_map.go @@ -116,6 +116,7 @@ func ResourceCertificateManagerCertificateMap() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -238,6 +239,18 @@ Examples: "2014-10-02T15:01:23Z" and "2014-10-02T15:01:23.045123456Z".`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -376,6 +389,19 @@ func resourceCertificateManagerCertificateMapRead(d *schema.ResourceData, meta i log.Printf("[DEBUG] Finished reading CertificateManagerCertificateMap %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading CertificateMap: %s", err) } @@ -407,6 +433,19 @@ func resourceCertificateManagerCertificateMapRead(d *schema.ResourceData, meta i } func resourceCertificateManagerCertificateMapUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceCertificateManagerCertificateMap().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceCertificateManagerCertificateMapRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -510,6 +549,13 @@ func resourceCertificateManagerCertificateMapUpdate(d *schema.ResourceData, meta } func resourceCertificateManagerCertificateMapDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy CertificateManagerCertificateMap without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing CertificateMap %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/certificatemanager/resource_certificate_manager_certificate_map_entry.go b/google-beta/services/certificatemanager/resource_certificate_manager_certificate_map_entry.go index 014860d7689..61228054503 100644 --- a/google-beta/services/certificatemanager/resource_certificate_manager_certificate_map_entry.go +++ b/google-beta/services/certificatemanager/resource_certificate_manager_certificate_map_entry.go @@ -116,6 +116,7 @@ func ResourceCertificateManagerCertificateMapEntry() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -239,6 +240,18 @@ Examples: "2014-10-02T15:01:23Z" and "2014-10-02T15:01:23.045123456Z".`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -406,6 +419,19 @@ func resourceCertificateManagerCertificateMapEntryRead(d *schema.ResourceData, m log.Printf("[DEBUG] Finished reading CertificateManagerCertificateMapEntry %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading CertificateMapEntry: %s", err) } @@ -443,6 +469,19 @@ func resourceCertificateManagerCertificateMapEntryRead(d *schema.ResourceData, m } func resourceCertificateManagerCertificateMapEntryUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceCertificateManagerCertificateMapEntry().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceCertificateManagerCertificateMapEntryRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -561,6 +600,13 @@ func resourceCertificateManagerCertificateMapEntryUpdate(d *schema.ResourceData, } func resourceCertificateManagerCertificateMapEntryDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy CertificateManagerCertificateMapEntry without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing CertificateMapEntry %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/certificatemanager/resource_certificate_manager_certificate_map_entry_generated_meta.yaml b/google-beta/services/certificatemanager/resource_certificate_manager_certificate_map_entry_generated_meta.yaml index e5c2aa90ed3..0546a331b4c 100644 --- a/google-beta/services/certificatemanager/resource_certificate_manager_certificate_map_entry_generated_meta.yaml +++ b/google-beta/services/certificatemanager/resource_certificate_manager_certificate_map_entry_generated_meta.yaml @@ -22,3 +22,5 @@ fields: - field: terraform_labels provider_only: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/certificatemanager/resource_certificate_manager_certificate_map_generated_meta.yaml b/google-beta/services/certificatemanager/resource_certificate_manager_certificate_map_generated_meta.yaml index cb6f49fe9eb..fd8d0f8752b 100644 --- a/google-beta/services/certificatemanager/resource_certificate_manager_certificate_map_generated_meta.yaml +++ b/google-beta/services/certificatemanager/resource_certificate_manager_certificate_map_generated_meta.yaml @@ -21,3 +21,5 @@ fields: - field: terraform_labels provider_only: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/certificatemanager/resource_certificate_manager_dns_authorization.go b/google-beta/services/certificatemanager/resource_certificate_manager_dns_authorization.go index e8ef8b6a29b..df6aea88a0e 100644 --- a/google-beta/services/certificatemanager/resource_certificate_manager_dns_authorization.go +++ b/google-beta/services/certificatemanager/resource_certificate_manager_dns_authorization.go @@ -125,6 +125,7 @@ func ResourceCertificateManagerDnsAuthorization() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -249,6 +250,18 @@ E.g. '_acme-challenge.example.com'.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -404,6 +417,19 @@ func resourceCertificateManagerDnsAuthorizationRead(d *schema.ResourceData, meta log.Printf("[DEBUG] Finished reading CertificateManagerDnsAuthorization %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading DnsAuthorization: %s", err) } @@ -441,6 +467,19 @@ func resourceCertificateManagerDnsAuthorizationRead(d *schema.ResourceData, meta } func resourceCertificateManagerDnsAuthorizationUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceCertificateManagerDnsAuthorization().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceCertificateManagerDnsAuthorizationRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -549,6 +588,13 @@ func resourceCertificateManagerDnsAuthorizationUpdate(d *schema.ResourceData, me } func resourceCertificateManagerDnsAuthorizationDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy CertificateManagerDnsAuthorization without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing DnsAuthorization %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/certificatemanager/resource_certificate_manager_dns_authorization_generated_meta.yaml b/google-beta/services/certificatemanager/resource_certificate_manager_dns_authorization_generated_meta.yaml index 2c6d0fe1379..c4fcba91894 100644 --- a/google-beta/services/certificatemanager/resource_certificate_manager_dns_authorization_generated_meta.yaml +++ b/google-beta/services/certificatemanager/resource_certificate_manager_dns_authorization_generated_meta.yaml @@ -22,3 +22,5 @@ fields: - field: terraform_labels provider_only: true - api_field: type + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/certificatemanager/resource_certificate_manager_trust_config.go b/google-beta/services/certificatemanager/resource_certificate_manager_trust_config.go index 01085baf86a..98fce5a046f 100644 --- a/google-beta/services/certificatemanager/resource_certificate_manager_trust_config.go +++ b/google-beta/services/certificatemanager/resource_certificate_manager_trust_config.go @@ -116,6 +116,7 @@ func ResourceCertificateManagerTrustConfig() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -261,6 +262,18 @@ Examples: "2014-10-02T15:01:23Z" and "2014-10-02T15:01:23.045123456Z".`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -416,6 +429,19 @@ func resourceCertificateManagerTrustConfigRead(d *schema.ResourceData, meta inte log.Printf("[DEBUG] Finished reading CertificateManagerTrustConfig %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading TrustConfig: %s", err) } @@ -453,6 +479,19 @@ func resourceCertificateManagerTrustConfigRead(d *schema.ResourceData, meta inte } func resourceCertificateManagerTrustConfigUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceCertificateManagerTrustConfig().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceCertificateManagerTrustConfigRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -555,6 +594,13 @@ func resourceCertificateManagerTrustConfigUpdate(d *schema.ResourceData, meta in } func resourceCertificateManagerTrustConfigDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy CertificateManagerTrustConfig without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing TrustConfig %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/certificatemanager/resource_certificate_manager_trust_config_generated_meta.yaml b/google-beta/services/certificatemanager/resource_certificate_manager_trust_config_generated_meta.yaml index cb9ad275a80..fd180273e1e 100644 --- a/google-beta/services/certificatemanager/resource_certificate_manager_trust_config_generated_meta.yaml +++ b/google-beta/services/certificatemanager/resource_certificate_manager_trust_config_generated_meta.yaml @@ -22,3 +22,5 @@ fields: - api_field: trustStores.intermediateCas.pemCertificate - api_field: trustStores.trustAnchors.pemCertificate - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/ces/resource_ces_agent.go b/google-beta/services/ces/resource_ces_agent.go index dab1ef641c7..fa29a1f192a 100644 --- a/google-beta/services/ces/resource_ces_agent.go +++ b/google-beta/services/ces/resource_ces_agent.go @@ -115,6 +115,7 @@ func ResourceCESAgent() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -526,6 +527,18 @@ Format: 'projects/{project}/locations/{location}/apps/{app}/agents/{agent}'`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -754,6 +767,19 @@ func resourceCESAgentRead(d *schema.ResourceData, meta interface{}) error { log.Printf("[DEBUG] Finished reading CESAgent %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Agent: %s", err) } @@ -797,6 +823,19 @@ func resourceCESAgentRead(d *schema.ResourceData, meta interface{}) error { } func resourceCESAgentUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceCESAgent().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceCESAgentRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1043,6 +1082,13 @@ func resourceCESAgentUpdate(d *schema.ResourceData, meta interface{}) error { } func resourceCESAgentDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy CESAgent without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Agent %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/ces/resource_ces_agent_generated_meta.yaml b/google-beta/services/ces/resource_ces_agent_generated_meta.yaml index 1f3c51daab4..721ac7b4778 100644 --- a/google-beta/services/ces/resource_ces_agent_generated_meta.yaml +++ b/google-beta/services/ces/resource_ces_agent_generated_meta.yaml @@ -53,3 +53,5 @@ fields: - api_field: toolsets.toolIds - api_field: toolsets.toolset - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/ces/resource_ces_app.go b/google-beta/services/ces/resource_ces_app.go index b366b0c810d..5553e8b27da 100644 --- a/google-beta/services/ces/resource_ces_app.go +++ b/google-beta/services/ces/resource_ces_app.go @@ -115,6 +115,7 @@ func ResourceCESApp() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -933,6 +934,18 @@ Format: 'projects/{project}/locations/{location}/apps/{app}'`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -1187,6 +1200,19 @@ func resourceCESAppRead(d *schema.ResourceData, meta interface{}) error { log.Printf("[DEBUG] Finished reading CESApp %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading App: %s", err) } @@ -1224,6 +1250,19 @@ func resourceCESAppRead(d *schema.ResourceData, meta interface{}) error { } func resourceCESAppUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceCESApp().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceCESAppRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1482,6 +1521,13 @@ func resourceCESAppUpdate(d *schema.ResourceData, meta interface{}) error { } func resourceCESAppDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy CESApp without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing App %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/ces/resource_ces_app_generated_meta.yaml b/google-beta/services/ces/resource_ces_app_generated_meta.yaml index 77917eea319..2ec30a98f56 100644 --- a/google-beta/services/ces/resource_ces_app_generated_meta.yaml +++ b/google-beta/services/ces/resource_ces_app_generated_meta.yaml @@ -92,3 +92,5 @@ fields: - api_field: variableDeclarations.schema.title - api_field: variableDeclarations.schema.type - api_field: variableDeclarations.schema.uniqueItems + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/ces/resource_ces_app_root_agent_association.go b/google-beta/services/ces/resource_ces_app_root_agent_association.go index d1423ad3729..4f310484341 100644 --- a/google-beta/services/ces/resource_ces_app_root_agent_association.go +++ b/google-beta/services/ces/resource_ces_app_root_agent_association.go @@ -115,6 +115,7 @@ func ResourceCESAppRootAgentAssociation() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -169,6 +170,18 @@ root agent of the app.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -310,6 +323,19 @@ func resourceCESAppRootAgentAssociationRead(d *schema.ResourceData, meta interfa return fmt.Errorf("Error setting agent_id: %s", err) } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading AppRootAgentAssociation: %s", err) } @@ -353,6 +379,19 @@ func resourceCESAppRootAgentAssociationRead(d *schema.ResourceData, meta interfa } func resourceCESAppRootAgentAssociationUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceCESAppRootAgentAssociation().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceCESAppRootAgentAssociationRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -423,6 +462,13 @@ func resourceCESAppRootAgentAssociationUpdate(d *schema.ResourceData, meta inter } func resourceCESAppRootAgentAssociationDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy CESAppRootAgentAssociation without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing AppRootAgentAssociation %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/ces/resource_ces_app_root_agent_association_generated_meta.yaml b/google-beta/services/ces/resource_ces_app_root_agent_association_generated_meta.yaml index 47874dc7548..498e2a85270 100644 --- a/google-beta/services/ces/resource_ces_app_root_agent_association_generated_meta.yaml +++ b/google-beta/services/ces/resource_ces_app_root_agent_association_generated_meta.yaml @@ -12,3 +12,5 @@ fields: provider_only: true - field: location provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/ces/resource_ces_app_version.go b/google-beta/services/ces/resource_ces_app_version.go index ebeaac6ce23..98c6ce9cc6a 100644 --- a/google-beta/services/ces/resource_ces_app_version.go +++ b/google-beta/services/ces/resource_ces_app_version.go @@ -100,6 +100,7 @@ func ResourceCESAppVersion() *schema.Resource { return &schema.Resource{ Create: resourceCESAppVersionCreate, Read: resourceCESAppVersionRead, + Update: resourceCESAppVersionUpdate, Delete: resourceCESAppVersionDelete, Importer: &schema.ResourceImporter{ @@ -113,6 +114,7 @@ func ResourceCESAppVersion() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -3287,6 +3289,18 @@ it will replace the placeholder in the schema.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -3431,6 +3445,19 @@ func resourceCESAppVersionRead(d *schema.ResourceData, meta interface{}) error { log.Printf("[DEBUG] Finished reading CESAppVersion %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading AppVersion: %s", err) } @@ -3473,7 +3500,19 @@ func resourceCESAppVersionRead(d *schema.ResourceData, meta interface{}) error { return nil } +func resourceCESAppVersionUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceCESAppVersionRead(d, meta) +} + func resourceCESAppVersionDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy CESAppVersion without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing AppVersion %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/ces/resource_ces_app_version_generated_meta.yaml b/google-beta/services/ces/resource_ces_app_version_generated_meta.yaml index 5cbeab0e10d..0eb84fc416c 100644 --- a/google-beta/services/ces/resource_ces_app_version_generated_meta.yaml +++ b/google-beta/services/ces/resource_ces_app_version_generated_meta.yaml @@ -341,3 +341,5 @@ fields: - api_field: snapshot.toolsets.openApiToolset.tlsConfig.caCerts.displayName - api_field: snapshot.toolsets.openApiToolset.url - api_field: snapshot.toolsets.updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/ces/resource_ces_deployment.go b/google-beta/services/ces/resource_ces_deployment.go index 8a06f4a35b0..d2fd6df8063 100644 --- a/google-beta/services/ces/resource_ces_deployment.go +++ b/google-beta/services/ces/resource_ces_deployment.go @@ -115,6 +115,7 @@ func ResourceCESDeployment() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -293,6 +294,18 @@ projects/{project}/locations/{location}/apps/{app}/deployments/{deployment}`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -443,6 +456,19 @@ func resourceCESDeploymentRead(d *schema.ResourceData, meta interface{}) error { log.Printf("[DEBUG] Finished reading CESDeployment %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Deployment: %s", err) } @@ -486,6 +512,19 @@ func resourceCESDeploymentRead(d *schema.ResourceData, meta interface{}) error { } func resourceCESDeploymentUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceCESDeployment().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceCESDeploymentRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -602,6 +641,13 @@ func resourceCESDeploymentUpdate(d *schema.ResourceData, meta interface{}) error } func resourceCESDeploymentDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy CESDeployment without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Deployment %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/ces/resource_ces_deployment_generated_meta.yaml b/google-beta/services/ces/resource_ces_deployment_generated_meta.yaml index 1689832d203..c1497d3ce4d 100644 --- a/google-beta/services/ces/resource_ces_deployment_generated_meta.yaml +++ b/google-beta/services/ces/resource_ces_deployment_generated_meta.yaml @@ -26,3 +26,5 @@ fields: provider_only: true - api_field: name - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/ces/resource_ces_evaluation.go b/google-beta/services/ces/resource_ces_evaluation.go index 0766a9f7575..4dab290d184 100644 --- a/google-beta/services/ces/resource_ces_evaluation.go +++ b/google-beta/services/ces/resource_ces_evaluation.go @@ -115,6 +115,7 @@ func ResourceCESEvaluation() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -1276,6 +1277,18 @@ Format: 'projects/{project}/locations/{location}/apps/{app}/evaluations/{evaluat Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -1432,6 +1445,19 @@ func resourceCESEvaluationRead(d *schema.ResourceData, meta interface{}) error { log.Printf("[DEBUG] Finished reading CESEvaluation %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Evaluation: %s", err) } @@ -1475,6 +1501,19 @@ func resourceCESEvaluationRead(d *schema.ResourceData, meta interface{}) error { } func resourceCESEvaluationUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceCESEvaluation().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceCESEvaluationRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1611,6 +1650,13 @@ func resourceCESEvaluationUpdate(d *schema.ResourceData, meta interface{}) error } func resourceCESEvaluationDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy CESEvaluation without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Evaluation %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/ces/resource_ces_evaluation_generated_meta.yaml b/google-beta/services/ces/resource_ces_evaluation_generated_meta.yaml index 963482666f5..3d682c0b62f 100644 --- a/google-beta/services/ces/resource_ces_evaluation_generated_meta.yaml +++ b/google-beta/services/ces/resource_ces_evaluation_generated_meta.yaml @@ -135,3 +135,5 @@ fields: - api_field: scenario.variableOverrides - api_field: tags - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/ces/resource_ces_example.go b/google-beta/services/ces/resource_ces_example.go index 810c0ac3798..dffe473c877 100644 --- a/google-beta/services/ces/resource_ces_example.go +++ b/google-beta/services/ces/resource_ces_example.go @@ -115,6 +115,7 @@ func ResourceCESExample() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -412,6 +413,18 @@ Format: Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -574,6 +587,19 @@ func resourceCESExampleRead(d *schema.ResourceData, meta interface{}) error { log.Printf("[DEBUG] Finished reading CESExample %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Example: %s", err) } @@ -617,6 +643,19 @@ func resourceCESExampleRead(d *schema.ResourceData, meta interface{}) error { } func resourceCESExampleUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceCESExample().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceCESExampleRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -753,6 +792,13 @@ func resourceCESExampleUpdate(d *schema.ResourceData, meta interface{}) error { } func resourceCESExampleDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy CESExample without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Example %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/ces/resource_ces_example_generated_meta.yaml b/google-beta/services/ces/resource_ces_example_generated_meta.yaml index 92b8246e7c5..8136f917e50 100644 --- a/google-beta/services/ces/resource_ces_example_generated_meta.yaml +++ b/google-beta/services/ces/resource_ces_example_generated_meta.yaml @@ -44,3 +44,5 @@ fields: - api_field: messages.role - api_field: name - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/ces/resource_ces_guardrail.go b/google-beta/services/ces/resource_ces_guardrail.go index 51cc9268f71..78f4ab4be60 100644 --- a/google-beta/services/ces/resource_ces_guardrail.go +++ b/google-beta/services/ces/resource_ces_guardrail.go @@ -115,6 +115,7 @@ func ResourceCESGuardrail() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -668,6 +669,18 @@ Format: Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -854,6 +867,19 @@ func resourceCESGuardrailRead(d *schema.ResourceData, meta interface{}) error { log.Printf("[DEBUG] Finished reading CESGuardrail %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Guardrail: %s", err) } @@ -897,6 +923,19 @@ func resourceCESGuardrailRead(d *schema.ResourceData, meta interface{}) error { } func resourceCESGuardrailUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceCESGuardrail().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceCESGuardrailRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1073,6 +1112,13 @@ func resourceCESGuardrailUpdate(d *schema.ResourceData, meta interface{}) error } func resourceCESGuardrailDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy CESGuardrail without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Guardrail %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/ces/resource_ces_guardrail_generated_meta.yaml b/google-beta/services/ces/resource_ces_guardrail_generated_meta.yaml index 9e25414dfa9..426433ba4f8 100644 --- a/google-beta/services/ces/resource_ces_guardrail_generated_meta.yaml +++ b/google-beta/services/ces/resource_ces_guardrail_generated_meta.yaml @@ -59,3 +59,5 @@ fields: - api_field: modelSafety.safetySettings.threshold - api_field: name - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/ces/resource_ces_tool.go b/google-beta/services/ces/resource_ces_tool.go index 2ffd95c164e..6473b74b54a 100644 --- a/google-beta/services/ces/resource_ces_tool.go +++ b/google-beta/services/ces/resource_ces_tool.go @@ -115,6 +115,7 @@ func ResourceCESTool() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -1285,6 +1286,18 @@ placeholder in the schema.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -1447,6 +1460,19 @@ func resourceCESToolRead(d *schema.ResourceData, meta interface{}) error { log.Printf("[DEBUG] Finished reading CESTool %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Tool: %s", err) } @@ -1490,6 +1516,19 @@ func resourceCESToolRead(d *schema.ResourceData, meta interface{}) error { } func resourceCESToolUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceCESTool().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceCESToolRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1626,6 +1665,13 @@ func resourceCESToolUpdate(d *schema.ResourceData, meta interface{}) error { } func resourceCESToolDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy CESTool without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Tool %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/ces/resource_ces_tool_generated_meta.yaml b/google-beta/services/ces/resource_ces_tool_generated_meta.yaml index 3e8a7e9d971..4b3a0797b3f 100644 --- a/google-beta/services/ces/resource_ces_tool_generated_meta.yaml +++ b/google-beta/services/ces/resource_ces_tool_generated_meta.yaml @@ -135,3 +135,5 @@ fields: - field: tool_id provider_only: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/ces/resource_ces_toolset.go b/google-beta/services/ces/resource_ces_toolset.go index a45c53fcd17..2d54e78a7c0 100644 --- a/google-beta/services/ces/resource_ces_toolset.go +++ b/google-beta/services/ces/resource_ces_toolset.go @@ -115,6 +115,7 @@ func ResourceCESToolset() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -690,6 +691,18 @@ Format: Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -846,6 +859,19 @@ func resourceCESToolsetRead(d *schema.ResourceData, meta interface{}) error { log.Printf("[DEBUG] Finished reading CESToolset %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Toolset: %s", err) } @@ -889,6 +915,19 @@ func resourceCESToolsetRead(d *schema.ResourceData, meta interface{}) error { } func resourceCESToolsetUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceCESToolset().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceCESToolsetRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1025,6 +1064,13 @@ func resourceCESToolsetUpdate(d *schema.ResourceData, meta interface{}) error { } func resourceCESToolsetDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy CESToolset without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Toolset %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/ces/resource_ces_toolset_generated_meta.yaml b/google-beta/services/ces/resource_ces_toolset_generated_meta.yaml index 10c80899031..e0e30761c37 100644 --- a/google-beta/services/ces/resource_ces_toolset_generated_meta.yaml +++ b/google-beta/services/ces/resource_ces_toolset_generated_meta.yaml @@ -56,3 +56,5 @@ fields: - field: toolset_id provider_only: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/chronicle/resource_chronicle_dashboard_chart.go b/google-beta/services/chronicle/resource_chronicle_dashboard_chart.go index ba032b62b7e..7f75d2728c2 100644 --- a/google-beta/services/chronicle/resource_chronicle_dashboard_chart.go +++ b/google-beta/services/chronicle/resource_chronicle_dashboard_chart.go @@ -115,6 +115,7 @@ func ResourceChronicleDashboardChart() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -1447,6 +1448,18 @@ func ResourceChronicleDashboardChart() *schema.Resource { Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -1609,6 +1622,19 @@ func resourceChronicleDashboardChartRead(d *schema.ResourceData, meta interface{ return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading DashboardChart: %s", err) } @@ -1652,6 +1678,19 @@ func resourceChronicleDashboardChartRead(d *schema.ResourceData, meta interface{ } func resourceChronicleDashboardChartUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceChronicleDashboardChart().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceChronicleDashboardChartRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1795,6 +1834,13 @@ func resourceChronicleDashboardChartUpdate(d *schema.ResourceData, meta interfac } func resourceChronicleDashboardChartDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ChronicleDashboardChart without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing DashboardChart %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/chronicle/resource_chronicle_dashboard_chart_generated_meta.yaml b/google-beta/services/chronicle/resource_chronicle_dashboard_chart_generated_meta.yaml index 3b21bba3afb..657576c6cd9 100644 --- a/google-beta/services/chronicle/resource_chronicle_dashboard_chart_generated_meta.yaml +++ b/google-beta/services/chronicle/resource_chronicle_dashboard_chart_generated_meta.yaml @@ -147,3 +147,5 @@ fields: - api_field: name - field: native_dashboard provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/chronicle/resource_chronicle_data_access_label.go b/google-beta/services/chronicle/resource_chronicle_data_access_label.go index 590278c537e..7e9e275f543 100644 --- a/google-beta/services/chronicle/resource_chronicle_data_access_label.go +++ b/google-beta/services/chronicle/resource_chronicle_data_access_label.go @@ -115,6 +115,7 @@ func ResourceChronicleDataAccessLabel() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -214,6 +215,18 @@ projects/{project}/locations/{location}/instances/{instance}/dataAccessLabels/{d Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -352,6 +365,19 @@ func resourceChronicleDataAccessLabelRead(d *schema.ResourceData, meta interface log.Printf("[DEBUG] Finished reading ChronicleDataAccessLabel %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading DataAccessLabel: %s", err) } @@ -395,6 +421,19 @@ func resourceChronicleDataAccessLabelRead(d *schema.ResourceData, meta interface } func resourceChronicleDataAccessLabelUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceChronicleDataAccessLabel().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceChronicleDataAccessLabelRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -501,6 +540,13 @@ func resourceChronicleDataAccessLabelUpdate(d *schema.ResourceData, meta interfa } func resourceChronicleDataAccessLabelDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ChronicleDataAccessLabel without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing DataAccessLabel %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/chronicle/resource_chronicle_data_access_label_generated_meta.yaml b/google-beta/services/chronicle/resource_chronicle_data_access_label_generated_meta.yaml index 79a76f71924..782d36bfbb9 100644 --- a/google-beta/services/chronicle/resource_chronicle_data_access_label_generated_meta.yaml +++ b/google-beta/services/chronicle/resource_chronicle_data_access_label_generated_meta.yaml @@ -22,3 +22,5 @@ fields: - api_field: name - api_field: udmQuery - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/chronicle/resource_chronicle_data_access_scope.go b/google-beta/services/chronicle/resource_chronicle_data_access_scope.go index c6f77216c2a..2156b2a3bca 100644 --- a/google-beta/services/chronicle/resource_chronicle_data_access_scope.go +++ b/google-beta/services/chronicle/resource_chronicle_data_access_scope.go @@ -115,6 +115,7 @@ func ResourceChronicleDataAccessScope() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -342,6 +343,18 @@ projects/{project}/locations/{location}/instances/{instance}/dataAccessScopes/{d Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -492,6 +505,19 @@ func resourceChronicleDataAccessScopeRead(d *schema.ResourceData, meta interface log.Printf("[DEBUG] Finished reading ChronicleDataAccessScope %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading DataAccessScope: %s", err) } @@ -535,6 +561,19 @@ func resourceChronicleDataAccessScopeRead(d *schema.ResourceData, meta interface } func resourceChronicleDataAccessScopeUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceChronicleDataAccessScope().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceChronicleDataAccessScopeRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -661,6 +700,13 @@ func resourceChronicleDataAccessScopeUpdate(d *schema.ResourceData, meta interfa } func resourceChronicleDataAccessScopeDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ChronicleDataAccessScope without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing DataAccessScope %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/chronicle/resource_chronicle_data_access_scope_generated_meta.yaml b/google-beta/services/chronicle/resource_chronicle_data_access_scope_generated_meta.yaml index 4e0c629b4fd..8c5511bfbc8 100644 --- a/google-beta/services/chronicle/resource_chronicle_data_access_scope_generated_meta.yaml +++ b/google-beta/services/chronicle/resource_chronicle_data_access_scope_generated_meta.yaml @@ -34,3 +34,5 @@ fields: provider_only: true - api_field: name - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/chronicle/resource_chronicle_data_table.go b/google-beta/services/chronicle/resource_chronicle_data_table.go index 76c8cd90c1a..2c606a86b7f 100644 --- a/google-beta/services/chronicle/resource_chronicle_data_table.go +++ b/google-beta/services/chronicle/resource_chronicle_data_table.go @@ -115,6 +115,7 @@ func ResourceChronicleDataTable() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DEFAULT"), ), Identity: &schema.ResourceIdentity{ @@ -319,21 +320,18 @@ SEARCH`, Computed: true, Description: `Table update time`, }, - "deletion_policy": { - Type: schema.TypeString, - Optional: true, - Description: `The policy governing the deletion of the data table. -If set to 'FORCE', allows the deletion of the data table even if it contains rows. -If set to 'DEFAULT',or if the field is omitted, the data table must be empty before it can be deleted. -Possible values: DEFAULT, FORCE`, - Default: "DEFAULT", - }, "project": { Type: schema.TypeString, Optional: true, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `This field uses a custom implementation please refer to documentation under /hashicorp/terraform-provider-google-beta/website/docs/r/chronicle_data_table.html.markdown for specifics`, + }, }, UseJSONNumber: true, } @@ -486,8 +484,15 @@ func resourceChronicleDataTableRead(d *schema.ResourceData, meta interface{}) er // Explicitly set virtual fields to default values if unset if _, ok := d.GetOkExists("deletion_policy"); !ok { - if err := d.Set("deletion_policy", "DEFAULT"); err != nil { - return fmt.Errorf("Error setting deletion_policy: %s", err) + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DEFAULT"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } } } if err := d.Set("project", project); err != nil { @@ -533,6 +538,19 @@ func resourceChronicleDataTableRead(d *schema.ResourceData, meta interface{}) er } func resourceChronicleDataTableUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceChronicleDataTable().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceChronicleDataTableRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -649,6 +667,13 @@ func resourceChronicleDataTableUpdate(d *schema.ResourceData, meta interface{}) } func resourceChronicleDataTableDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ChronicleDataTable without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing DataTable %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -717,9 +742,6 @@ func resourceChronicleDataTableImport(d *schema.ResourceData, meta interface{}) d.SetId(id) // Explicitly set virtual fields to default values on import - if err := d.Set("deletion_policy", "DEFAULT"); err != nil { - return nil, fmt.Errorf("Error setting deletion_policy: %s", err) - } return []*schema.ResourceData{d}, nil } diff --git a/google-beta/services/chronicle/resource_chronicle_data_table_generated_meta.yaml b/google-beta/services/chronicle/resource_chronicle_data_table_generated_meta.yaml index e252cf31392..29cc546c1aa 100644 --- a/google-beta/services/chronicle/resource_chronicle_data_table_generated_meta.yaml +++ b/google-beta/services/chronicle/resource_chronicle_data_table_generated_meta.yaml @@ -19,8 +19,6 @@ fields: - field: data_table_id provider_only: true - api_field: dataTableUuid - - field: deletion_policy - provider_only: true - api_field: description - api_field: displayName - field: instance @@ -35,3 +33,5 @@ fields: - api_field: scopeInfo.dataAccessScopes - api_field: updateSource - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/chronicle/resource_chronicle_data_table_row.go b/google-beta/services/chronicle/resource_chronicle_data_table_row.go index 6d3b190e518..b063f4b8287 100644 --- a/google-beta/services/chronicle/resource_chronicle_data_table_row.go +++ b/google-beta/services/chronicle/resource_chronicle_data_table_row.go @@ -115,6 +115,7 @@ func ResourceChronicleDataTableRow() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -210,6 +211,18 @@ projects/{project}/locations/{location}/instances/{instance}/dataTables/{data_ta Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -359,6 +372,19 @@ func resourceChronicleDataTableRowRead(d *schema.ResourceData, meta interface{}) log.Printf("[DEBUG] Finished reading ChronicleDataTableRow %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading DataTableRow: %s", err) } @@ -408,6 +434,19 @@ func resourceChronicleDataTableRowRead(d *schema.ResourceData, meta interface{}) } func resourceChronicleDataTableRowUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceChronicleDataTableRow().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceChronicleDataTableRowRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -509,6 +548,13 @@ func resourceChronicleDataTableRowUpdate(d *schema.ResourceData, meta interface{ } func resourceChronicleDataTableRowDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ChronicleDataTableRow without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing DataTableRow %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/chronicle/resource_chronicle_data_table_row_generated_meta.yaml b/google-beta/services/chronicle/resource_chronicle_data_table_row_generated_meta.yaml index afddb34f801..3a304ce23f0 100644 --- a/google-beta/services/chronicle/resource_chronicle_data_table_row_generated_meta.yaml +++ b/google-beta/services/chronicle/resource_chronicle_data_table_row_generated_meta.yaml @@ -20,3 +20,5 @@ fields: - api_field: rowTimeToLive - api_field: updateTime - api_field: values + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/chronicle/resource_chronicle_feed.go b/google-beta/services/chronicle/resource_chronicle_feed.go index 1df7b2488ee..772c6196c1f 100644 --- a/google-beta/services/chronicle/resource_chronicle_feed.go +++ b/google-beta/services/chronicle/resource_chronicle_feed.go @@ -115,6 +115,7 @@ func ResourceChronicleFeed() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -4329,6 +4330,18 @@ projects/{project}/locations/{location}/instances/{instance}/feeds/{feed}`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -4562,6 +4575,18 @@ func resourceChronicleFeedRead(d *schema.ResourceData, meta interface{}) error { log.Printf("[DEBUG] Finished reading ChronicleFeed %q: %#v", d.Id(), res) // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Feed: %s", err) } @@ -4605,6 +4630,19 @@ func resourceChronicleFeedRead(d *schema.ResourceData, meta interface{}) error { } func resourceChronicleFeedUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceChronicleFeed().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceChronicleFeedRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -4764,6 +4802,13 @@ func resourceChronicleFeedUpdate(d *schema.ResourceData, meta interface{}) error } func resourceChronicleFeedDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ChronicleFeed without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Feed %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/chronicle/resource_chronicle_feed_generated_meta.yaml b/google-beta/services/chronicle/resource_chronicle_feed_generated_meta.yaml index d784c2524a5..a02d112d03f 100644 --- a/google-beta/services/chronicle/resource_chronicle_feed_generated_meta.yaml +++ b/google-beta/services/chronicle/resource_chronicle_feed_generated_meta.yaml @@ -378,3 +378,5 @@ fields: provider_only: true - api_field: state - api_field: uid + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/chronicle/resource_chronicle_native_dashboard.go b/google-beta/services/chronicle/resource_chronicle_native_dashboard.go index 1c4f3fdd306..c37a167a2f6 100644 --- a/google-beta/services/chronicle/resource_chronicle_native_dashboard.go +++ b/google-beta/services/chronicle/resource_chronicle_native_dashboard.go @@ -115,6 +115,7 @@ func ResourceChronicleNativeDashboard() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -375,6 +376,18 @@ sent on update and delete requests.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -543,6 +556,19 @@ func resourceChronicleNativeDashboardRead(d *schema.ResourceData, meta interface log.Printf("[DEBUG] Finished reading ChronicleNativeDashboard %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading NativeDashboard: %s", err) } @@ -586,6 +612,19 @@ func resourceChronicleNativeDashboardRead(d *schema.ResourceData, meta interface } func resourceChronicleNativeDashboardUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceChronicleNativeDashboard().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceChronicleNativeDashboardRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -744,6 +783,13 @@ func resourceChronicleNativeDashboardUpdate(d *schema.ResourceData, meta interfa } func resourceChronicleNativeDashboardDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ChronicleNativeDashboard without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing NativeDashboard %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/chronicle/resource_chronicle_native_dashboard_generated_meta.yaml b/google-beta/services/chronicle/resource_chronicle_native_dashboard_generated_meta.yaml index 9508fbb97a6..915c96bc83e 100644 --- a/google-beta/services/chronicle/resource_chronicle_native_dashboard_generated_meta.yaml +++ b/google-beta/services/chronicle/resource_chronicle_native_dashboard_generated_meta.yaml @@ -61,3 +61,5 @@ fields: - api_field: type - api_field: updateTime - api_field: updateUserId + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/chronicle/resource_chronicle_reference_list.go b/google-beta/services/chronicle/resource_chronicle_reference_list.go index 5e9dab20e3d..4328624fc65 100644 --- a/google-beta/services/chronicle/resource_chronicle_reference_list.go +++ b/google-beta/services/chronicle/resource_chronicle_reference_list.go @@ -461,6 +461,7 @@ func resourceChronicleReferenceListRead(d *schema.ResourceData, meta interface{} } func resourceChronicleReferenceListUpdate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/chronicle/resource_chronicle_rule.go b/google-beta/services/chronicle/resource_chronicle_rule.go index 6aa5075a8c0..5e4af025cfa 100644 --- a/google-beta/services/chronicle/resource_chronicle_rule.go +++ b/google-beta/services/chronicle/resource_chronicle_rule.go @@ -115,6 +115,7 @@ func ResourceChronicleRule() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DEFAULT"), ), Identity: &schema.ResourceIdentity{ @@ -364,24 +365,18 @@ RULE_TYPE_UNSPECIFIED SINGLE_EVENT MULTI_EVENT`, }, - "deletion_policy": { - Type: schema.TypeString, - Optional: true, - Description: `Policy to determine if the rule should be deleted forcefully. -If deletion_policy = "FORCE", any retrohunts and any detections associated with the rule -will also be deleted. If deletion_policy = "DEFAULT", the call will only succeed if the -rule has no associated retrohunts, including completed retrohunts, and no -associated detections. Regardless of this field's value, the rule -deployment associated with this rule will also be deleted. -Possible values: DEFAULT, FORCE`, - Default: "DEFAULT", - }, "project": { Type: schema.TypeString, Optional: true, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `This field uses a custom implementation please refer to documentation under /hashicorp/terraform-provider-google-beta/website/docs/r/chronicle_rule.html.markdown for specifics`, + }, }, UseJSONNumber: true, } @@ -534,8 +529,15 @@ func resourceChronicleRuleRead(d *schema.ResourceData, meta interface{}) error { // Explicitly set virtual fields to default values if unset if _, ok := d.GetOkExists("deletion_policy"); !ok { - if err := d.Set("deletion_policy", "DEFAULT"); err != nil { - return fmt.Errorf("Error setting deletion_policy: %s", err) + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DEFAULT"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } } } if err := d.Set("project", project); err != nil { @@ -581,6 +583,19 @@ func resourceChronicleRuleRead(d *schema.ResourceData, meta interface{}) error { } func resourceChronicleRuleUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceChronicleRule().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceChronicleRuleRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -697,6 +712,13 @@ func resourceChronicleRuleUpdate(d *schema.ResourceData, meta interface{}) error } func resourceChronicleRuleDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ChronicleRule without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Rule %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -765,9 +787,6 @@ func resourceChronicleRuleImport(d *schema.ResourceData, meta interface{}) ([]*s d.SetId(id) // Explicitly set virtual fields to default values on import - if err := d.Set("deletion_policy", "DEFAULT"); err != nil { - return nil, fmt.Errorf("Error setting deletion_policy: %s", err) - } return []*schema.ResourceData{d}, nil } diff --git a/google-beta/services/chronicle/resource_chronicle_rule_deployment.go b/google-beta/services/chronicle/resource_chronicle_rule_deployment.go index e3096d777fe..f706cf6242f 100644 --- a/google-beta/services/chronicle/resource_chronicle_rule_deployment.go +++ b/google-beta/services/chronicle/resource_chronicle_rule_deployment.go @@ -525,6 +525,7 @@ func resourceChronicleRuleDeploymentRead(d *schema.ResourceData, meta interface{ } func resourceChronicleRuleDeploymentUpdate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/chronicle/resource_chronicle_rule_generated_meta.yaml b/google-beta/services/chronicle/resource_chronicle_rule_generated_meta.yaml index 40f07677e61..d6ef6e861ba 100644 --- a/google-beta/services/chronicle/resource_chronicle_rule_generated_meta.yaml +++ b/google-beta/services/chronicle/resource_chronicle_rule_generated_meta.yaml @@ -20,8 +20,6 @@ fields: - api_field: compilationState - api_field: createTime - api_field: dataTables - - field: deletion_policy - provider_only: true - api_field: displayName - api_field: etag - field: instance @@ -39,3 +37,5 @@ fields: - api_field: severity.displayName - api_field: text - api_field: type + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/chronicle/resource_chronicle_watchlist.go b/google-beta/services/chronicle/resource_chronicle_watchlist.go index eef1e95f7d7..c5106f901ce 100644 --- a/google-beta/services/chronicle/resource_chronicle_watchlist.go +++ b/google-beta/services/chronicle/resource_chronicle_watchlist.go @@ -115,6 +115,7 @@ func ResourceChronicleWatchlist() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -264,6 +265,18 @@ projects/{project}/locations/{location}/instances/{instance}/watchlists/{watchli Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -437,6 +450,19 @@ func resourceChronicleWatchlistRead(d *schema.ResourceData, meta interface{}) er log.Printf("[DEBUG] Finished reading ChronicleWatchlist %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Watchlist: %s", err) } @@ -480,6 +506,19 @@ func resourceChronicleWatchlistRead(d *schema.ResourceData, meta interface{}) er } func resourceChronicleWatchlistUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceChronicleWatchlist().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceChronicleWatchlistRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -621,6 +660,13 @@ func resourceChronicleWatchlistUpdate(d *schema.ResourceData, meta interface{}) } func resourceChronicleWatchlistDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ChronicleWatchlist without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Watchlist %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/chronicle/resource_chronicle_watchlist_generated_meta.yaml b/google-beta/services/chronicle/resource_chronicle_watchlist_generated_meta.yaml index 948b4ee921e..c2fd960b602 100644 --- a/google-beta/services/chronicle/resource_chronicle_watchlist_generated_meta.yaml +++ b/google-beta/services/chronicle/resource_chronicle_watchlist_generated_meta.yaml @@ -23,3 +23,5 @@ fields: - api_field: updateTime - api_field: watchlistId - api_field: watchlistUserPreferences.pinned + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/cloudasset/resource_cloud_asset_folder_feed.go b/google-beta/services/cloudasset/resource_cloud_asset_folder_feed.go index e0da8e6466d..cffee758034 100644 --- a/google-beta/services/cloudasset/resource_cloud_asset_folder_feed.go +++ b/google-beta/services/cloudasset/resource_cloud_asset_folder_feed.go @@ -255,6 +255,19 @@ and folders/[FOLDER_NUMBER] are accepted.`, Computed: true, Description: `The format will be folders/{folder_number}/feeds/{client-assigned_feed_identifier}.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -415,6 +428,20 @@ func resourceCloudAssetFolderFeedRead(d *schema.ResourceData, meta interface{}) log.Printf("[DEBUG] Finished reading CloudAssetFolderFeed %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceCloudAssetFolderFeedFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -442,6 +469,19 @@ func resourceCloudAssetFolderFeedRead(d *schema.ResourceData, meta interface{}) } func resourceCloudAssetFolderFeedUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceCloudAssetFolderFeed().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceCloudAssetFolderFeedRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -570,6 +610,13 @@ func resourceCloudAssetFolderFeedUpdate(d *schema.ResourceData, meta interface{} } func resourceCloudAssetFolderFeedDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy CloudAssetFolderFeed without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing FolderFeed %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/cloudasset/resource_cloud_asset_folder_feed_generated_meta.yaml b/google-beta/services/cloudasset/resource_cloud_asset_folder_feed_generated_meta.yaml index b4055d63818..3c8cd1c8f0d 100644 --- a/google-beta/services/cloudasset/resource_cloud_asset_folder_feed_generated_meta.yaml +++ b/google-beta/services/cloudasset/resource_cloud_asset_folder_feed_generated_meta.yaml @@ -28,3 +28,5 @@ fields: - field: folder_id provider_only: true - api_field: name + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/cloudasset/resource_cloud_asset_organization_feed.go b/google-beta/services/cloudasset/resource_cloud_asset_organization_feed.go index fd540178531..178da911ba3 100644 --- a/google-beta/services/cloudasset/resource_cloud_asset_organization_feed.go +++ b/google-beta/services/cloudasset/resource_cloud_asset_organization_feed.go @@ -249,6 +249,19 @@ This can be used e.g. in UIs which allow to enter the expression.`, Computed: true, Description: `The format will be organizations/{organization_number}/feeds/{client-assigned_feed_identifier}.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -409,6 +422,20 @@ func resourceCloudAssetOrganizationFeedRead(d *schema.ResourceData, meta interfa log.Printf("[DEBUG] Finished reading CloudAssetOrganizationFeed %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceCloudAssetOrganizationFeedFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -436,6 +463,19 @@ func resourceCloudAssetOrganizationFeedRead(d *schema.ResourceData, meta interfa } func resourceCloudAssetOrganizationFeedUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceCloudAssetOrganizationFeed().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceCloudAssetOrganizationFeedRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -564,6 +604,13 @@ func resourceCloudAssetOrganizationFeedUpdate(d *schema.ResourceData, meta inter } func resourceCloudAssetOrganizationFeedDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy CloudAssetOrganizationFeed without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing OrganizationFeed %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/cloudasset/resource_cloud_asset_organization_feed_generated_meta.yaml b/google-beta/services/cloudasset/resource_cloud_asset_organization_feed_generated_meta.yaml index fe3698dc3c1..44de2c86357 100644 --- a/google-beta/services/cloudasset/resource_cloud_asset_organization_feed_generated_meta.yaml +++ b/google-beta/services/cloudasset/resource_cloud_asset_organization_feed_generated_meta.yaml @@ -26,3 +26,5 @@ fields: - api_field: name - field: org_id provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/cloudasset/resource_cloud_asset_project_feed.go b/google-beta/services/cloudasset/resource_cloud_asset_project_feed.go index 461177857e8..4808e3d3461 100644 --- a/google-beta/services/cloudasset/resource_cloud_asset_project_feed.go +++ b/google-beta/services/cloudasset/resource_cloud_asset_project_feed.go @@ -115,6 +115,7 @@ func ResourceCloudAssetProjectFeed() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -254,6 +255,18 @@ This can be used e.g. in UIs which allow to enter the expression.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -418,6 +431,19 @@ func resourceCloudAssetProjectFeedRead(d *schema.ResourceData, meta interface{}) log.Printf("[DEBUG] Finished reading CloudAssetProjectFeed %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading ProjectFeed: %s", err) } @@ -449,6 +475,19 @@ func resourceCloudAssetProjectFeedRead(d *schema.ResourceData, meta interface{}) } func resourceCloudAssetProjectFeedUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceCloudAssetProjectFeed().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceCloudAssetProjectFeedRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -580,6 +619,13 @@ func resourceCloudAssetProjectFeedUpdate(d *schema.ResourceData, meta interface{ } func resourceCloudAssetProjectFeedDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy CloudAssetProjectFeed without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing ProjectFeed %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/cloudasset/resource_cloud_asset_project_feed_generated_meta.yaml b/google-beta/services/cloudasset/resource_cloud_asset_project_feed_generated_meta.yaml index 7a6207fe509..a8a0ccffee3 100644 --- a/google-beta/services/cloudasset/resource_cloud_asset_project_feed_generated_meta.yaml +++ b/google-beta/services/cloudasset/resource_cloud_asset_project_feed_generated_meta.yaml @@ -24,3 +24,5 @@ fields: provider_only: true - api_field: feedOutputConfig.pubsubDestination.topic - api_field: name + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/cloudbilling/resource_billing_project_info.go b/google-beta/services/cloudbilling/resource_billing_project_info.go index c9eb62c8fc3..90b956d6a13 100644 --- a/google-beta/services/cloudbilling/resource_billing_project_info.go +++ b/google-beta/services/cloudbilling/resource_billing_project_info.go @@ -115,6 +115,7 @@ func ResourceCloudBillingProjectInfo() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -146,6 +147,18 @@ For example, '"012345-567890-ABCDEF"' or '""'.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -280,6 +293,19 @@ func resourceCloudBillingProjectInfoRead(d *schema.ResourceData, meta interface{ return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading ProjectInfo: %s", err) } @@ -305,6 +331,19 @@ func resourceCloudBillingProjectInfoRead(d *schema.ResourceData, meta interface{ } func resourceCloudBillingProjectInfoUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceCloudBillingProjectInfo().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceCloudBillingProjectInfoRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -376,6 +415,13 @@ func resourceCloudBillingProjectInfoUpdate(d *schema.ResourceData, meta interfac } func resourceCloudBillingProjectInfoDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy CloudBillingProjectInfo without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing ProjectInfo %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/cloudbilling/resource_billing_project_info_generated_meta.yaml b/google-beta/services/cloudbilling/resource_billing_project_info_generated_meta.yaml index 9b2278b4c99..79e8c6cb032 100644 --- a/google-beta/services/cloudbilling/resource_billing_project_info_generated_meta.yaml +++ b/google-beta/services/cloudbilling/resource_billing_project_info_generated_meta.yaml @@ -10,3 +10,5 @@ cai_asset_name_formats: - //cloudbilling.googleapis.com/projects/{{project}}/billingInfo fields: - api_field: billing_account + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/cloudbuild/resource_cloudbuild_bitbucket_server_config.go b/google-beta/services/cloudbuild/resource_cloudbuild_bitbucket_server_config.go index 59e6dfbab9c..2fcf843afcf 100644 --- a/google-beta/services/cloudbuild/resource_cloudbuild_bitbucket_server_config.go +++ b/google-beta/services/cloudbuild/resource_cloudbuild_bitbucket_server_config.go @@ -115,6 +115,7 @@ func ResourceCloudBuildBitbucketServerConfig() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -234,6 +235,18 @@ projects/{project}/global/networks/{network}, where {project} is a project numbe Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -480,6 +493,19 @@ func resourceCloudBuildBitbucketServerConfigRead(d *schema.ResourceData, meta in log.Printf("[DEBUG] Finished reading CloudBuildBitbucketServerConfig %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading BitbucketServerConfig: %s", err) } @@ -517,6 +543,19 @@ func resourceCloudBuildBitbucketServerConfigRead(d *schema.ResourceData, meta in } func resourceCloudBuildBitbucketServerConfigUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceCloudBuildBitbucketServerConfig().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceCloudBuildBitbucketServerConfigRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -772,6 +811,13 @@ func resourceCloudBuildBitbucketServerConfigUpdate(d *schema.ResourceData, meta } func resourceCloudBuildBitbucketServerConfigDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy CloudBuildBitbucketServerConfig without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing BitbucketServerConfig %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/cloudbuild/resource_cloudbuild_bitbucket_server_config_generated_meta.yaml b/google-beta/services/cloudbuild/resource_cloudbuild_bitbucket_server_config_generated_meta.yaml index be825f5bdff..ff195c9032c 100644 --- a/google-beta/services/cloudbuild/resource_cloudbuild_bitbucket_server_config_generated_meta.yaml +++ b/google-beta/services/cloudbuild/resource_cloudbuild_bitbucket_server_config_generated_meta.yaml @@ -23,3 +23,5 @@ fields: - api_field: sslCa - api_field: username - api_field: webhookKey + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/cloudbuild/resource_cloudbuild_trigger.go b/google-beta/services/cloudbuild/resource_cloudbuild_trigger.go index a8e531f7a3e..6816fe0b034 100644 --- a/google-beta/services/cloudbuild/resource_cloudbuild_trigger.go +++ b/google-beta/services/cloudbuild/resource_cloudbuild_trigger.go @@ -167,6 +167,7 @@ func ResourceCloudBuildTrigger() *schema.Resource { CustomizeDiff: customdiff.All( stepTimeoutCustomizeDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -1564,6 +1565,18 @@ Only populated on get requests.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -1829,6 +1842,19 @@ func resourceCloudBuildTriggerRead(d *schema.ResourceData, meta interface{}) err log.Printf("[DEBUG] Finished reading CloudBuildTrigger %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Trigger: %s", err) } @@ -1866,6 +1892,19 @@ func resourceCloudBuildTriggerRead(d *schema.ResourceData, meta interface{}) err } func resourceCloudBuildTriggerUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceCloudBuildTrigger().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceCloudBuildTriggerRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -2069,6 +2108,13 @@ func resourceCloudBuildTriggerUpdate(d *schema.ResourceData, meta interface{}) e } func resourceCloudBuildTriggerDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy CloudBuildTrigger without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Trigger %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/cloudbuild/resource_cloudbuild_trigger_generated_meta.yaml b/google-beta/services/cloudbuild/resource_cloudbuild_trigger_generated_meta.yaml index 7949de018ff..d1c6a9b9416 100644 --- a/google-beta/services/cloudbuild/resource_cloudbuild_trigger_generated_meta.yaml +++ b/google-beta/services/cloudbuild/resource_cloudbuild_trigger_generated_meta.yaml @@ -165,3 +165,5 @@ fields: - api_field: triggerTemplate.tagName - api_field: webhookConfig.secret - api_field: webhookConfig.state + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/cloudbuild/resource_cloudbuild_worker_pool.go b/google-beta/services/cloudbuild/resource_cloudbuild_worker_pool.go index f4edc3651d7..ad1d381c9e0 100644 --- a/google-beta/services/cloudbuild/resource_cloudbuild_worker_pool.go +++ b/google-beta/services/cloudbuild/resource_cloudbuild_worker_pool.go @@ -52,6 +52,7 @@ func ResourceCloudbuildWorkerPool() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, tpgresource.SetAnnotationsDiff, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Schema: map[string]*schema.Schema{ @@ -155,6 +156,9 @@ func ResourceCloudbuildWorkerPool() *schema.Resource { Computed: true, Description: "Output only. Time at which the request to update the `WorkerPool` was received.", }, + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end }, } } @@ -370,9 +374,18 @@ func resourceCloudbuildWorkerPoolRead(d *schema.ResourceData, meta interface{}) return fmt.Errorf("error setting update_time in state: %s", err) } + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + return nil } func resourceCloudbuildWorkerPoolUpdate(d *schema.ResourceData, meta interface{}) error { + + if tpgresource.DeletionPolicyPreUpdate(d, ResourceCloudbuildWorkerPool) { + return ResourceCloudbuildWorkerPool().Read(d, meta) + } + config := meta.(*transport_tpg.Config) project, err := tpgresource.GetProject(d, config) if err != nil { @@ -423,6 +436,13 @@ func resourceCloudbuildWorkerPoolUpdate(d *schema.ResourceData, meta interface{} } func resourceCloudbuildWorkerPoolDelete(d *schema.ResourceData, meta interface{}) error { + + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { + return nil + } + config := meta.(*transport_tpg.Config) project, err := tpgresource.GetProject(d, config) if err != nil { diff --git a/google-beta/services/cloudbuild/resource_cloudbuild_worker_pool_meta.yaml b/google-beta/services/cloudbuild/resource_cloudbuild_worker_pool_meta.yaml index e3324c0e744..312c174c386 100644 --- a/google-beta/services/cloudbuild/resource_cloudbuild_worker_pool_meta.yaml +++ b/google-beta/services/cloudbuild/resource_cloudbuild_worker_pool_meta.yaml @@ -34,3 +34,5 @@ fields: field: 'worker_config.machine_type' - api_field: 'privatePoolV1Config.networkConfig.egressOption' field: 'worker_config.no_external_ip' + - field: 'deletion_policy' + provider_only: true \ No newline at end of file diff --git a/google-beta/services/cloudbuildv2/resource_cloudbuildv2_connection.go b/google-beta/services/cloudbuildv2/resource_cloudbuildv2_connection.go index ebda495c52f..a7cdca346f0 100644 --- a/google-beta/services/cloudbuildv2/resource_cloudbuildv2_connection.go +++ b/google-beta/services/cloudbuildv2/resource_cloudbuildv2_connection.go @@ -116,6 +116,7 @@ func ResourceCloudbuildv2Connection() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetAnnotationsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -573,6 +574,18 @@ Please refer to the field 'effective_annotations' for all of the annotations pre Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -752,6 +765,19 @@ func resourceCloudbuildv2ConnectionRead(d *schema.ResourceData, meta interface{} log.Printf("[DEBUG] Finished reading Cloudbuildv2Connection %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Connection: %s", err) } @@ -789,6 +815,19 @@ func resourceCloudbuildv2ConnectionRead(d *schema.ResourceData, meta interface{} } func resourceCloudbuildv2ConnectionUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceCloudbuildv2Connection().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceCloudbuildv2ConnectionRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -915,6 +954,13 @@ func resourceCloudbuildv2ConnectionUpdate(d *schema.ResourceData, meta interface } func resourceCloudbuildv2ConnectionDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy Cloudbuildv2Connection without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Connection %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/cloudbuildv2/resource_cloudbuildv2_connection_generated_meta.yaml b/google-beta/services/cloudbuildv2/resource_cloudbuildv2_connection_generated_meta.yaml index 4687254d49b..4864a741a48 100644 --- a/google-beta/services/cloudbuildv2/resource_cloudbuildv2_connection_generated_meta.yaml +++ b/google-beta/services/cloudbuildv2/resource_cloudbuildv2_connection_generated_meta.yaml @@ -57,3 +57,5 @@ fields: provider_only: true - api_field: reconciling - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/cloudbuildv2/resource_cloudbuildv2_repository.go b/google-beta/services/cloudbuildv2/resource_cloudbuildv2_repository.go index 668d2a67c02..5f0f944f1cc 100644 --- a/google-beta/services/cloudbuildv2/resource_cloudbuildv2_repository.go +++ b/google-beta/services/cloudbuildv2/resource_cloudbuildv2_repository.go @@ -100,6 +100,7 @@ func ResourceCloudbuildv2Repository() *schema.Resource { return &schema.Resource{ Create: resourceCloudbuildv2RepositoryCreate, Read: resourceCloudbuildv2RepositoryRead, + Update: resourceCloudbuildv2RepositoryUpdate, Delete: resourceCloudbuildv2RepositoryDelete, Importer: &schema.ResourceImporter{ @@ -114,6 +115,7 @@ func ResourceCloudbuildv2Repository() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetAnnotationsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -208,6 +210,18 @@ Please refer to the field 'effective_annotations' for all of the annotations pre Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -367,6 +381,19 @@ func resourceCloudbuildv2RepositoryRead(d *schema.ResourceData, meta interface{} log.Printf("[DEBUG] Finished reading Cloudbuildv2Repository %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Repository: %s", err) } @@ -409,7 +436,19 @@ func resourceCloudbuildv2RepositoryRead(d *schema.ResourceData, meta interface{} return nil } +func resourceCloudbuildv2RepositoryUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceCloudbuildv2RepositoryRead(d, meta) +} + func resourceCloudbuildv2RepositoryDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy Cloudbuildv2Repository without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Repository %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/cloudbuildv2/resource_cloudbuildv2_repository_generated_meta.yaml b/google-beta/services/cloudbuildv2/resource_cloudbuildv2_repository_generated_meta.yaml index 0a0cbdb9690..3e23cff684c 100644 --- a/google-beta/services/cloudbuildv2/resource_cloudbuildv2_repository_generated_meta.yaml +++ b/google-beta/services/cloudbuildv2/resource_cloudbuildv2_repository_generated_meta.yaml @@ -19,3 +19,5 @@ fields: provider_only: true - api_field: remoteUri - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/clouddeploy/resource_clouddeploy_automation.go b/google-beta/services/clouddeploy/resource_clouddeploy_automation.go index cdd5c28ca8e..bc4b1e784b4 100644 --- a/google-beta/services/clouddeploy/resource_clouddeploy_automation.go +++ b/google-beta/services/clouddeploy/resource_clouddeploy_automation.go @@ -117,6 +117,7 @@ func ResourceClouddeployAutomation() *schema.Resource { tpgresource.SetAnnotationsDiff, tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -470,6 +471,18 @@ Please refer to the field 'effective_labels' for all of the labels present on th Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -648,6 +661,19 @@ func resourceClouddeployAutomationRead(d *schema.ResourceData, meta interface{}) log.Printf("[DEBUG] Finished reading ClouddeployAutomation %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Automation: %s", err) } @@ -691,6 +717,19 @@ func resourceClouddeployAutomationRead(d *schema.ResourceData, meta interface{}) } func resourceClouddeployAutomationUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceClouddeployAutomation().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceClouddeployAutomationRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -854,6 +893,13 @@ func resourceClouddeployAutomationUpdate(d *schema.ResourceData, meta interface{ } func resourceClouddeployAutomationDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ClouddeployAutomation without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Automation %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/clouddeploy/resource_clouddeploy_automation_generated_meta.yaml b/google-beta/services/clouddeploy/resource_clouddeploy_automation_generated_meta.yaml index 0c8daaea149..1c1b671ff1c 100644 --- a/google-beta/services/clouddeploy/resource_clouddeploy_automation_generated_meta.yaml +++ b/google-beta/services/clouddeploy/resource_clouddeploy_automation_generated_meta.yaml @@ -50,3 +50,5 @@ fields: provider_only: true - api_field: uid - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/clouddeploy/resource_clouddeploy_custom_target_type.go b/google-beta/services/clouddeploy/resource_clouddeploy_custom_target_type.go index 46b726d2a87..7b3f905feb8 100644 --- a/google-beta/services/clouddeploy/resource_clouddeploy_custom_target_type.go +++ b/google-beta/services/clouddeploy/resource_clouddeploy_custom_target_type.go @@ -117,6 +117,7 @@ func ResourceClouddeployCustomTargetType() *schema.Resource { tpgresource.SetAnnotationsDiff, tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -444,6 +445,18 @@ Please refer to the field 'effective_labels' for all of the labels present on th Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -605,6 +618,19 @@ func resourceClouddeployCustomTargetTypeRead(d *schema.ResourceData, meta interf log.Printf("[DEBUG] Finished reading ClouddeployCustomTargetType %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading CustomTargetType: %s", err) } @@ -642,6 +668,19 @@ func resourceClouddeployCustomTargetTypeRead(d *schema.ResourceData, meta interf } func resourceClouddeployCustomTargetTypeUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceClouddeployCustomTargetType().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceClouddeployCustomTargetTypeRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -780,6 +819,13 @@ func resourceClouddeployCustomTargetTypeUpdate(d *schema.ResourceData, meta inte } func resourceClouddeployCustomTargetTypeDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ClouddeployCustomTargetType without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing CustomTargetType %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/clouddeploy/resource_clouddeploy_custom_target_type_generated_meta.yaml b/google-beta/services/clouddeploy/resource_clouddeploy_custom_target_type_generated_meta.yaml index efe74fdd4b4..7804a69eea7 100644 --- a/google-beta/services/clouddeploy/resource_clouddeploy_custom_target_type_generated_meta.yaml +++ b/google-beta/services/clouddeploy/resource_clouddeploy_custom_target_type_generated_meta.yaml @@ -44,3 +44,5 @@ fields: provider_only: true - api_field: uid - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/clouddeploy/resource_clouddeploy_delivery_pipeline.go b/google-beta/services/clouddeploy/resource_clouddeploy_delivery_pipeline.go index dddb5716280..f23ce80f9ce 100644 --- a/google-beta/services/clouddeploy/resource_clouddeploy_delivery_pipeline.go +++ b/google-beta/services/clouddeploy/resource_clouddeploy_delivery_pipeline.go @@ -53,6 +53,7 @@ func ResourceClouddeployDeliveryPipeline() *schema.Resource { tpgresource.DefaultProviderProject, tpgresource.SetLabelsDiff, tpgresource.SetAnnotationsDiff, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Schema: map[string]*schema.Schema{ @@ -161,6 +162,9 @@ func ResourceClouddeployDeliveryPipeline() *schema.Resource { Computed: true, Description: "Output only. Most recent time at which the pipeline was updated.", }, + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end }, } } @@ -1105,9 +1109,18 @@ func resourceClouddeployDeliveryPipelineRead(d *schema.ResourceData, meta interf return fmt.Errorf("error setting update_time in state: %s", err) } + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + return nil } func resourceClouddeployDeliveryPipelineUpdate(d *schema.ResourceData, meta interface{}) error { + + if tpgresource.DeletionPolicyPreUpdate(d, ResourceClouddeployDeliveryPipeline) { + return ResourceClouddeployDeliveryPipeline().Read(d, meta) + } + config := meta.(*transport_tpg.Config) project, err := tpgresource.GetProject(d, config) if err != nil { @@ -1158,6 +1171,13 @@ func resourceClouddeployDeliveryPipelineUpdate(d *schema.ResourceData, meta inte } func resourceClouddeployDeliveryPipelineDelete(d *schema.ResourceData, meta interface{}) error { + + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { + return nil + } + config := meta.(*transport_tpg.Config) project, err := tpgresource.GetProject(d, config) if err != nil { diff --git a/google-beta/services/clouddeploy/resource_clouddeploy_delivery_pipeline_meta.yaml b/google-beta/services/clouddeploy/resource_clouddeploy_delivery_pipeline_meta.yaml index 06dde40cdec..a2f90ccab0d 100644 --- a/google-beta/services/clouddeploy/resource_clouddeploy_delivery_pipeline_meta.yaml +++ b/google-beta/services/clouddeploy/resource_clouddeploy_delivery_pipeline_meta.yaml @@ -113,3 +113,5 @@ fields: provider_only: true - api_field: 'uid' - api_field: 'updateTime' + - field: 'deletion_policy' + provider_only: true diff --git a/google-beta/services/clouddeploy/resource_clouddeploy_deploy_policy.go b/google-beta/services/clouddeploy/resource_clouddeploy_deploy_policy.go index a6b91756303..8ee5f5fa961 100644 --- a/google-beta/services/clouddeploy/resource_clouddeploy_deploy_policy.go +++ b/google-beta/services/clouddeploy/resource_clouddeploy_deploy_policy.go @@ -117,6 +117,7 @@ func ResourceClouddeployDeployPolicy() *schema.Resource { tpgresource.SetAnnotationsDiff, tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -537,6 +538,18 @@ Please refer to the field 'effective_labels' for all of the labels present on th Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -704,6 +717,19 @@ func resourceClouddeployDeployPolicyRead(d *schema.ResourceData, meta interface{ log.Printf("[DEBUG] Finished reading ClouddeployDeployPolicy %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading DeployPolicy: %s", err) } @@ -741,6 +767,19 @@ func resourceClouddeployDeployPolicyRead(d *schema.ResourceData, meta interface{ } func resourceClouddeployDeployPolicyUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceClouddeployDeployPolicy().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceClouddeployDeployPolicyRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -889,6 +928,13 @@ func resourceClouddeployDeployPolicyUpdate(d *schema.ResourceData, meta interfac } func resourceClouddeployDeployPolicyDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ClouddeployDeployPolicy without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing DeployPolicy %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/clouddeploy/resource_clouddeploy_deploy_policy_generated_meta.yaml b/google-beta/services/clouddeploy/resource_clouddeploy_deploy_policy_generated_meta.yaml index edeebfa7f51..3434a43bc33 100644 --- a/google-beta/services/clouddeploy/resource_clouddeploy_deploy_policy_generated_meta.yaml +++ b/google-beta/services/clouddeploy/resource_clouddeploy_deploy_policy_generated_meta.yaml @@ -56,3 +56,5 @@ fields: provider_only: true - api_field: uid - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/clouddeploy/resource_clouddeploy_target.go b/google-beta/services/clouddeploy/resource_clouddeploy_target.go index 963e944ef31..979d1aa6077 100644 --- a/google-beta/services/clouddeploy/resource_clouddeploy_target.go +++ b/google-beta/services/clouddeploy/resource_clouddeploy_target.go @@ -53,6 +53,7 @@ func ResourceClouddeployTarget() *schema.Resource { tpgresource.DefaultProviderProject, tpgresource.SetLabelsDiff, tpgresource.SetAnnotationsDiff, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Schema: map[string]*schema.Schema{ @@ -220,6 +221,9 @@ func ResourceClouddeployTarget() *schema.Resource { Computed: true, Description: "Output only. Most recent time at which the `Target` was updated.", }, + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end }, } } @@ -661,9 +665,18 @@ func resourceClouddeployTargetRead(d *schema.ResourceData, meta interface{}) err return fmt.Errorf("error setting update_time in state: %s", err) } + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + return nil } func resourceClouddeployTargetUpdate(d *schema.ResourceData, meta interface{}) error { + + if tpgresource.DeletionPolicyPreUpdate(d, ResourceClouddeployTarget) { + return ResourceClouddeployTarget().Read(d, meta) + } + config := meta.(*transport_tpg.Config) project, err := tpgresource.GetProject(d, config) if err != nil { @@ -721,6 +734,13 @@ func resourceClouddeployTargetUpdate(d *schema.ResourceData, meta interface{}) e } func resourceClouddeployTargetDelete(d *schema.ResourceData, meta interface{}) error { + + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { + return nil + } + config := meta.(*transport_tpg.Config) project, err := tpgresource.GetProject(d, config) if err != nil { diff --git a/google-beta/services/clouddeploy/resource_clouddeploy_target_meta.yaml b/google-beta/services/clouddeploy/resource_clouddeploy_target_meta.yaml index 7e9637c5fa8..675eeffd90f 100644 --- a/google-beta/services/clouddeploy/resource_clouddeploy_target_meta.yaml +++ b/google-beta/services/clouddeploy/resource_clouddeploy_target_meta.yaml @@ -49,3 +49,5 @@ fields: provider_only: true - api_field: 'uid' - api_field: 'updateTime' + - field: 'deletion_policy' + provider_only: true diff --git a/google-beta/services/clouddomains/resource_clouddomains_registration.go b/google-beta/services/clouddomains/resource_clouddomains_registration.go index b5a979bbf86..7d37d64c59c 100644 --- a/google-beta/services/clouddomains/resource_clouddomains_registration.go +++ b/google-beta/services/clouddomains/resource_clouddomains_registration.go @@ -988,7 +988,7 @@ func resourceClouddomainsRegistrationRead(d *schema.ResourceData, meta interface } func resourceClouddomainsRegistrationUpdate(d *schema.ResourceData, meta interface{}) error { - // Only the root field "labels", "terraform_labels", and virtual fields are mutable + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable return resourceClouddomainsRegistrationRead(d, meta) } diff --git a/google-beta/services/cloudfunctions/resource_cloudfunctions_function.go b/google-beta/services/cloudfunctions/resource_cloudfunctions_function.go index a0ce7c3a27e..8d86c7729c0 100644 --- a/google-beta/services/cloudfunctions/resource_cloudfunctions_function.go +++ b/google-beta/services/cloudfunctions/resource_cloudfunctions_function.go @@ -160,6 +160,7 @@ func ResourceCloudFunctionsFunction() *schema.Resource { }, CustomizeDiff: customdiff.All( + tpgresource.DefaultProviderDeletionPolicy("DELETE"), tpgresource.DefaultProviderProject, tpgresource.DefaultProviderRegion, tpgresource.SetLabelsDiff, @@ -550,6 +551,9 @@ func ResourceCloudFunctionsFunction() *schema.Resource { Computed: true, Description: `The version identifier of the Cloud Function. Each deployment attempt results in a new version of a function being created.`, }, + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end }, UseJSONNumber: true, } @@ -884,11 +888,20 @@ func resourceCloudFunctionsRead(d *schema.ResourceData, meta interface{}) error d.Set("automatic_update_policy", nil) } + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + return nil } func resourceCloudFunctionsUpdate(d *schema.ResourceData, meta interface{}) error { log.Printf("[DEBUG]: Updating google_cloudfunctions_function") + + if tpgresource.DeletionPolicyPreUpdate(d, ResourceCloudFunctionsFunction) { + return ResourceCloudFunctionsFunction().Read(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1081,6 +1094,13 @@ func resourceCloudFunctionsUpdate(d *schema.ResourceData, meta interface{}) erro } func resourceCloudFunctionsDestroy(d *schema.ResourceData, meta interface{}) error { + + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { + return nil + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/cloudfunctions/resource_cloudfunctions_function_meta.yaml b/google-beta/services/cloudfunctions/resource_cloudfunctions_function_meta.yaml index b090370cbc9..4adaed2d235 100644 --- a/google-beta/services/cloudfunctions/resource_cloudfunctions_function_meta.yaml +++ b/google-beta/services/cloudfunctions/resource_cloudfunctions_function_meta.yaml @@ -55,3 +55,5 @@ fields: - api_field: 'vpcConnectorEgressSettings' - field: 'automatic_update_policy' - api_field: 'onDeployUpdatePolicy.runtimeVersion' + - field: 'deletion_policy' + provider_only: true diff --git a/google-beta/services/cloudfunctions2/resource_cloudfunctions2_function.go b/google-beta/services/cloudfunctions2/resource_cloudfunctions2_function.go index eab0883af15..c4b598c5f1c 100644 --- a/google-beta/services/cloudfunctions2/resource_cloudfunctions2_function.go +++ b/google-beta/services/cloudfunctions2/resource_cloudfunctions2_function.go @@ -131,6 +131,7 @@ func ResourceCloudfunctions2function() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -681,6 +682,18 @@ timeout period. Defaults to 60 seconds.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -887,6 +900,19 @@ func resourceCloudfunctions2functionRead(d *schema.ResourceData, meta interface{ log.Printf("[DEBUG] Finished reading Cloudfunctions2function %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading function: %s", err) } @@ -924,6 +950,19 @@ func resourceCloudfunctions2functionRead(d *schema.ResourceData, meta interface{ } func resourceCloudfunctions2functionUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceCloudfunctions2function().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceCloudfunctions2functionRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1077,6 +1116,13 @@ func resourceCloudfunctions2functionUpdate(d *schema.ResourceData, meta interfac } func resourceCloudfunctions2functionDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy Cloudfunctions2function without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing function %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/cloudfunctions2/resource_cloudfunctions2_function_generated_meta.yaml b/google-beta/services/cloudfunctions2/resource_cloudfunctions2_function_generated_meta.yaml index 69658730b5a..b3783dd25f1 100644 --- a/google-beta/services/cloudfunctions2/resource_cloudfunctions2_function_generated_meta.yaml +++ b/google-beta/services/cloudfunctions2/resource_cloudfunctions2_function_generated_meta.yaml @@ -78,3 +78,5 @@ fields: provider_only: true - api_field: updateTime - api_field: url + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/cloudidentity/resource_cloud_identity_group.go b/google-beta/services/cloudidentity/resource_cloud_identity_group.go index 4afc710e52f..32376e4e45e 100644 --- a/google-beta/services/cloudidentity/resource_cloud_identity_group.go +++ b/google-beta/services/cloudidentity/resource_cloud_identity_group.go @@ -264,6 +264,19 @@ is the unique ID assigned to the Group.`, Computed: true, Description: `The time when the Group was last updated.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -457,6 +470,20 @@ func resourceCloudIdentityGroupRead(d *schema.ResourceData, meta interface{}) er log.Printf("[DEBUG] Finished reading CloudIdentityGroup %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceCloudIdentityGroupFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -478,6 +505,19 @@ func resourceCloudIdentityGroupRead(d *schema.ResourceData, meta interface{}) er } func resourceCloudIdentityGroupUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceCloudIdentityGroup().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceCloudIdentityGroupRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -577,6 +617,13 @@ func resourceCloudIdentityGroupUpdate(d *schema.ResourceData, meta interface{}) } func resourceCloudIdentityGroupDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy CloudIdentityGroup without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Group %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/cloudidentity/resource_cloud_identity_group_generated_meta.yaml b/google-beta/services/cloudidentity/resource_cloud_identity_group_generated_meta.yaml index ec367e10672..d9159412259 100644 --- a/google-beta/services/cloudidentity/resource_cloud_identity_group_generated_meta.yaml +++ b/google-beta/services/cloudidentity/resource_cloud_identity_group_generated_meta.yaml @@ -20,3 +20,5 @@ fields: - api_field: name - api_field: parent - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/cloudidentity/resource_cloud_identity_group_membership.go b/google-beta/services/cloudidentity/resource_cloud_identity_group_membership.go index 537f7c6e84d..be8d72ec7e5 100644 --- a/google-beta/services/cloudidentity/resource_cloud_identity_group_membership.go +++ b/google-beta/services/cloudidentity/resource_cloud_identity_group_membership.go @@ -250,6 +250,19 @@ and must be in the form of 'identitysources/{identity_source_id}'.`, Description: `If set to true, skip group member creation if a membership with the same name already exists. Defaults to false.`, Default: false, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -500,6 +513,18 @@ func resourceCloudIdentityGroupMembershipRead(d *schema.ResourceData, meta inter return fmt.Errorf("Error setting create_ignore_already_exists: %s", err) } } + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } err = ResourceCloudIdentityGroupMembershipFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { @@ -522,6 +547,19 @@ func resourceCloudIdentityGroupMembershipRead(d *schema.ResourceData, meta inter } func resourceCloudIdentityGroupMembershipUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceCloudIdentityGroupMembership().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceCloudIdentityGroupMembershipRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -651,6 +689,13 @@ func resourceCloudIdentityGroupMembershipUpdate(d *schema.ResourceData, meta int } func resourceCloudIdentityGroupMembershipDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy CloudIdentityGroupMembership without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing GroupMembership %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/cloudidentity/resource_cloud_identity_group_membership_generated_meta.yaml b/google-beta/services/cloudidentity/resource_cloud_identity_group_membership_generated_meta.yaml index 8028f0cbd39..a6cf86cf0fb 100644 --- a/google-beta/services/cloudidentity/resource_cloud_identity_group_membership_generated_meta.yaml +++ b/google-beta/services/cloudidentity/resource_cloud_identity_group_membership_generated_meta.yaml @@ -21,3 +21,5 @@ fields: - api_field: roles.name - api_field: type - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/cloudidentity/resource_cloud_identity_policy.go b/google-beta/services/cloudidentity/resource_cloud_identity_policy.go index 17ed84f23b0..84f316c152f 100644 --- a/google-beta/services/cloudidentity/resource_cloud_identity_policy.go +++ b/google-beta/services/cloudidentity/resource_cloud_identity_policy.go @@ -225,6 +225,19 @@ func ResourceCloudIdentityPolicy() *schema.Resource { Computed: true, Description: `The resource name of the Policy. Format: 'policies/{policy_id}'.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -366,6 +379,20 @@ func resourceCloudIdentityPolicyRead(d *schema.ResourceData, meta interface{}) e log.Printf("[DEBUG] Finished reading CloudIdentityPolicy %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceCloudIdentityPolicyFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -387,6 +414,19 @@ func resourceCloudIdentityPolicyRead(d *schema.ResourceData, meta interface{}) e } func resourceCloudIdentityPolicyUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceCloudIdentityPolicy().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceCloudIdentityPolicyRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -460,6 +500,13 @@ func resourceCloudIdentityPolicyUpdate(d *schema.ResourceData, meta interface{}) } func resourceCloudIdentityPolicyDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy CloudIdentityPolicy without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Policy %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/cloudidentity/resource_cloud_identity_policy_generated_meta.yaml b/google-beta/services/cloudidentity/resource_cloud_identity_policy_generated_meta.yaml index 43d4edd699f..94d60981ccc 100644 --- a/google-beta/services/cloudidentity/resource_cloud_identity_policy_generated_meta.yaml +++ b/google-beta/services/cloudidentity/resource_cloud_identity_policy_generated_meta.yaml @@ -16,3 +16,5 @@ fields: - api_field: setting.type - api_field: setting.value field: setting.value_json + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/cloudids/resource_cloud_ids_endpoint.go b/google-beta/services/cloudids/resource_cloud_ids_endpoint.go index 4ea1ec7c55c..e75df22e060 100644 --- a/google-beta/services/cloudids/resource_cloud_ids_endpoint.go +++ b/google-beta/services/cloudids/resource_cloud_ids_endpoint.go @@ -115,6 +115,7 @@ func ResourceCloudIdsEndpoint() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -206,6 +207,18 @@ func ResourceCloudIdsEndpoint() *schema.Resource { Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -367,6 +380,19 @@ func resourceCloudIdsEndpointRead(d *schema.ResourceData, meta interface{}) erro log.Printf("[DEBUG] Finished reading CloudIdsEndpoint %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Endpoint: %s", err) } @@ -404,6 +430,19 @@ func resourceCloudIdsEndpointRead(d *schema.ResourceData, meta interface{}) erro } func resourceCloudIdsEndpointUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceCloudIdsEndpoint().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceCloudIdsEndpointRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -502,6 +541,13 @@ func resourceCloudIdsEndpointUpdate(d *schema.ResourceData, meta interface{}) er } func resourceCloudIdsEndpointDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy CloudIdsEndpoint without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Endpoint %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/cloudids/resource_cloud_ids_endpoint_generated_meta.yaml b/google-beta/services/cloudids/resource_cloud_ids_endpoint_generated_meta.yaml index a709b2be756..1a6ea454981 100644 --- a/google-beta/services/cloudids/resource_cloud_ids_endpoint_generated_meta.yaml +++ b/google-beta/services/cloudids/resource_cloud_ids_endpoint_generated_meta.yaml @@ -18,3 +18,5 @@ fields: - api_field: severity - api_field: threatExceptions - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/cloudquotas/resource_cloud_quotas_quota_adjuster_settings.go b/google-beta/services/cloudquotas/resource_cloud_quotas_quota_adjuster_settings.go index b4fade10858..bc5a93802e6 100644 --- a/google-beta/services/cloudquotas/resource_cloud_quotas_quota_adjuster_settings.go +++ b/google-beta/services/cloudquotas/resource_cloud_quotas_quota_adjuster_settings.go @@ -294,6 +294,7 @@ func resourceCloudQuotasQuotaAdjusterSettingsRead(d *schema.ResourceData, meta i } func resourceCloudQuotasQuotaAdjusterSettingsUpdate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/cloudquotas/resource_cloud_quotas_quota_preference.go b/google-beta/services/cloudquotas/resource_cloud_quotas_quota_preference.go index 1d9fb14cb49..a5914d09fe8 100644 --- a/google-beta/services/cloudquotas/resource_cloud_quotas_quota_preference.go +++ b/google-beta/services/cloudquotas/resource_cloud_quotas_quota_preference.go @@ -444,6 +444,7 @@ func resourceCloudQuotasQuotaPreferenceRead(d *schema.ResourceData, meta interfa } func resourceCloudQuotasQuotaPreferenceUpdate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/cloudrun/resource_cloud_run_domain_mapping.go b/google-beta/services/cloudrun/resource_cloud_run_domain_mapping.go index 7057133342f..da83f824891 100644 --- a/google-beta/services/cloudrun/resource_cloud_run_domain_mapping.go +++ b/google-beta/services/cloudrun/resource_cloud_run_domain_mapping.go @@ -110,6 +110,7 @@ func ResourceCloudRunDomainMapping() *schema.Resource { return &schema.Resource{ Create: resourceCloudRunDomainMappingCreate, Read: resourceCloudRunDomainMappingRead, + Update: resourceCloudRunDomainMappingUpdate, Delete: resourceCloudRunDomainMappingDelete, Importer: &schema.ResourceImporter{ @@ -135,6 +136,7 @@ func ResourceCloudRunDomainMapping() *schema.Resource { tpgresource.SetMetadataLabelsDiff, tpgresource.SetMetadataAnnotationsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -394,6 +396,18 @@ was last processed by the controller.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -601,6 +615,19 @@ func resourceCloudRunDomainMappingRead(d *schema.ResourceData, meta interface{}) return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading DomainMapping: %s", err) } @@ -637,7 +664,19 @@ func resourceCloudRunDomainMappingRead(d *schema.ResourceData, meta interface{}) return nil } +func resourceCloudRunDomainMappingUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceCloudRunDomainMappingRead(d, meta) +} + func resourceCloudRunDomainMappingDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy CloudRunDomainMapping without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing DomainMapping %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/cloudrun/resource_cloud_run_domain_mapping_generated_meta.yaml b/google-beta/services/cloudrun/resource_cloud_run_domain_mapping_generated_meta.yaml index eb3100df325..dcdce7a4c2b 100644 --- a/google-beta/services/cloudrun/resource_cloud_run_domain_mapping_generated_meta.yaml +++ b/google-beta/services/cloudrun/resource_cloud_run_domain_mapping_generated_meta.yaml @@ -38,3 +38,5 @@ fields: - api_field: status.resourceRecords.name - api_field: status.resourceRecords.rrdata - api_field: status.resourceRecords.type + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/cloudrun/resource_cloud_run_service.go b/google-beta/services/cloudrun/resource_cloud_run_service.go index 1cd49de6a92..5a2e6a0fbdf 100644 --- a/google-beta/services/cloudrun/resource_cloud_run_service.go +++ b/google-beta/services/cloudrun/resource_cloud_run_service.go @@ -175,6 +175,7 @@ func ResourceCloudRunService() *schema.Resource { tpgresource.SetMetadataLabelsDiff, tpgresource.SetMetadataAnnotationsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -1384,6 +1385,18 @@ this field is set to false, the revision name will still autogenerate.)`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -1651,6 +1664,18 @@ func resourceCloudRunServiceRead(d *schema.ResourceData, meta interface{}) error return fmt.Errorf("Error setting autogenerate_revision_name: %s", err) } } + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Service: %s", err) } @@ -1688,6 +1713,19 @@ func resourceCloudRunServiceRead(d *schema.ResourceData, meta interface{}) error } func resourceCloudRunServiceUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceCloudRunService().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceCloudRunServiceRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1781,6 +1819,13 @@ func resourceCloudRunServiceUpdate(d *schema.ResourceData, meta interface{}) err } func resourceCloudRunServiceDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy CloudRunService without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Service %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/cloudrun/resource_cloud_run_service_generated_meta.yaml b/google-beta/services/cloudrun/resource_cloud_run_service_generated_meta.yaml index 7d537ccb102..02a1e592b48 100644 --- a/google-beta/services/cloudrun/resource_cloud_run_service_generated_meta.yaml +++ b/google-beta/services/cloudrun/resource_cloud_run_service_generated_meta.yaml @@ -207,3 +207,5 @@ fields: field: traffic.tag - api_field: spec.traffic.url field: traffic.url + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/cloudrunv2/resource_cloud_run_v2_job.go b/google-beta/services/cloudrunv2/resource_cloud_run_v2_job.go index 459a0cd295e..ee5b763def1 100644 --- a/google-beta/services/cloudrunv2/resource_cloud_run_v2_job.go +++ b/google-beta/services/cloudrunv2/resource_cloud_run_v2_job.go @@ -117,6 +117,7 @@ func ResourceCloudRunV2Job() *schema.Resource { tpgresource.SetLabelsDiff, tpgresource.SetAnnotationsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -1038,6 +1039,18 @@ When the field is set to false, deleting the job is allowed.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -1276,6 +1289,18 @@ func resourceCloudRunV2JobRead(d *schema.ResourceData, meta interface{}) error { return fmt.Errorf("Error setting deletion_protection: %s", err) } } + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Job: %s", err) } @@ -1313,6 +1338,19 @@ func resourceCloudRunV2JobRead(d *schema.ResourceData, meta interface{}) error { } func resourceCloudRunV2JobUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceCloudRunV2Job().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceCloudRunV2JobRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1445,6 +1483,13 @@ func resourceCloudRunV2JobUpdate(d *schema.ResourceData, meta interface{}) error } func resourceCloudRunV2JobDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy CloudRunV2Job without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Job %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/cloudrunv2/resource_cloud_run_v2_job_generated_meta.yaml b/google-beta/services/cloudrunv2/resource_cloud_run_v2_job_generated_meta.yaml index 874f1a4f421..bf6bb3b6aa5 100644 --- a/google-beta/services/cloudrunv2/resource_cloud_run_v2_job_generated_meta.yaml +++ b/google-beta/services/cloudrunv2/resource_cloud_run_v2_job_generated_meta.yaml @@ -118,3 +118,5 @@ fields: provider_only: true - api_field: uid - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/cloudrunv2/resource_cloud_run_v2_service.go b/google-beta/services/cloudrunv2/resource_cloud_run_v2_service.go index 65c84c4d028..8378574502e 100644 --- a/google-beta/services/cloudrunv2/resource_cloud_run_v2_service.go +++ b/google-beta/services/cloudrunv2/resource_cloud_run_v2_service.go @@ -117,6 +117,7 @@ func ResourceCloudRunV2Service() *schema.Resource { tpgresource.SetLabelsDiff, tpgresource.SetAnnotationsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -1527,6 +1528,18 @@ When the field is set to false, deleting the service is allowed.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -1813,6 +1826,18 @@ func resourceCloudRunV2ServiceRead(d *schema.ResourceData, meta interface{}) err return fmt.Errorf("Error setting deletion_protection: %s", err) } } + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Service: %s", err) } @@ -1850,6 +1875,19 @@ func resourceCloudRunV2ServiceRead(d *schema.ResourceData, meta interface{}) err } func resourceCloudRunV2ServiceUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceCloudRunV2Service().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceCloudRunV2ServiceRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -2030,6 +2068,13 @@ func resourceCloudRunV2ServiceUpdate(d *schema.ResourceData, meta interface{}) e } func resourceCloudRunV2ServiceDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy CloudRunV2Service without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Service %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/cloudrunv2/resource_cloud_run_v2_service_generated_meta.yaml b/google-beta/services/cloudrunv2/resource_cloud_run_v2_service_generated_meta.yaml index 38245e77602..a918f4f00b8 100644 --- a/google-beta/services/cloudrunv2/resource_cloud_run_v2_service_generated_meta.yaml +++ b/google-beta/services/cloudrunv2/resource_cloud_run_v2_service_generated_meta.yaml @@ -177,3 +177,5 @@ fields: - api_field: updateTime - api_field: uri - api_field: urls + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/cloudrunv2/resource_cloud_run_v2_worker_pool.go b/google-beta/services/cloudrunv2/resource_cloud_run_v2_worker_pool.go index 3a48f95f9d8..ebc6e39f056 100644 --- a/google-beta/services/cloudrunv2/resource_cloud_run_v2_worker_pool.go +++ b/google-beta/services/cloudrunv2/resource_cloud_run_v2_worker_pool.go @@ -117,6 +117,7 @@ func ResourceCloudRunV2WorkerPool() *schema.Resource { tpgresource.SetLabelsDiff, tpgresource.SetAnnotationsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -1139,6 +1140,18 @@ When the field is set to false, deleting the WorkerPool is allowed.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -1389,6 +1402,18 @@ func resourceCloudRunV2WorkerPoolRead(d *schema.ResourceData, meta interface{}) return fmt.Errorf("Error setting deletion_protection: %s", err) } } + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading WorkerPool: %s", err) } @@ -1426,6 +1451,19 @@ func resourceCloudRunV2WorkerPoolRead(d *schema.ResourceData, meta interface{}) } func resourceCloudRunV2WorkerPoolUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceCloudRunV2WorkerPool().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceCloudRunV2WorkerPoolRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1570,6 +1608,13 @@ func resourceCloudRunV2WorkerPoolUpdate(d *schema.ResourceData, meta interface{} } func resourceCloudRunV2WorkerPoolDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy CloudRunV2WorkerPool without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing WorkerPool %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/cloudrunv2/resource_cloud_run_v2_worker_pool_generated_meta.yaml b/google-beta/services/cloudrunv2/resource_cloud_run_v2_worker_pool_generated_meta.yaml index 7d8aa933c42..1425d123a5c 100644 --- a/google-beta/services/cloudrunv2/resource_cloud_run_v2_worker_pool_generated_meta.yaml +++ b/google-beta/services/cloudrunv2/resource_cloud_run_v2_worker_pool_generated_meta.yaml @@ -133,3 +133,5 @@ fields: provider_only: true - api_field: uid - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/cloudscheduler/resource_cloud_scheduler_job.go b/google-beta/services/cloudscheduler/resource_cloud_scheduler_job.go index f863c7784d9..bff6d0e2d97 100644 --- a/google-beta/services/cloudscheduler/resource_cloud_scheduler_job.go +++ b/google-beta/services/cloudscheduler/resource_cloud_scheduler_job.go @@ -207,6 +207,7 @@ func ResourceCloudSchedulerJob() *schema.Resource { validateAuthHeaders, tpgresource.DefaultProviderProject, tpgresource.DefaultProviderRegion, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -555,6 +556,18 @@ The value of this field must be a time zone name from the tz database.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -771,6 +784,19 @@ func resourceCloudSchedulerJobRead(d *schema.ResourceData, meta interface{}) err log.Printf("[DEBUG] Finished reading CloudSchedulerJob %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Job: %s", err) } @@ -816,6 +842,19 @@ func resourceCloudSchedulerJobRead(d *schema.ResourceData, meta interface{}) err } func resourceCloudSchedulerJobUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceCloudSchedulerJob().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceCloudSchedulerJobRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -978,6 +1017,13 @@ func resourceCloudSchedulerJobUpdate(d *schema.ResourceData, meta interface{}) e } func resourceCloudSchedulerJobDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy CloudSchedulerJob without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Job %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/cloudscheduler/resource_cloud_scheduler_job_generated_meta.yaml b/google-beta/services/cloudscheduler/resource_cloud_scheduler_job_generated_meta.yaml index 36eaf5d7d36..4d119e1845a 100644 --- a/google-beta/services/cloudscheduler/resource_cloud_scheduler_job_generated_meta.yaml +++ b/google-beta/services/cloudscheduler/resource_cloud_scheduler_job_generated_meta.yaml @@ -39,3 +39,5 @@ fields: - api_field: schedule - api_field: state - api_field: timeZone + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/cloudsecuritycompliance/resource_cloud_security_compliance_cloud_control.go b/google-beta/services/cloudsecuritycompliance/resource_cloud_security_compliance_cloud_control.go index 695d98d9e85..62ed0ba8fed 100644 --- a/google-beta/services/cloudsecuritycompliance/resource_cloud_security_compliance_cloud_control.go +++ b/google-beta/services/cloudsecuritycompliance/resource_cloud_security_compliance_cloud_control.go @@ -980,6 +980,19 @@ organizations/{organization}/locations/{location}/cloudControls/{cloud_control_i Type: schema.TypeString, }, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -1148,6 +1161,20 @@ func resourceCloudSecurityComplianceCloudControlRead(d *schema.ResourceData, met log.Printf("[DEBUG] Finished reading CloudSecurityComplianceCloudControl %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceCloudSecurityComplianceCloudControlFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -1181,6 +1208,19 @@ func resourceCloudSecurityComplianceCloudControlRead(d *schema.ResourceData, met } func resourceCloudSecurityComplianceCloudControlUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceCloudSecurityComplianceCloudControl().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceCloudSecurityComplianceCloudControlRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1321,6 +1361,13 @@ func resourceCloudSecurityComplianceCloudControlUpdate(d *schema.ResourceData, m } func resourceCloudSecurityComplianceCloudControlDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy CloudSecurityComplianceCloudControl without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing CloudControl %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/cloudsecuritycompliance/resource_cloud_security_compliance_cloud_control_generated_meta.yaml b/google-beta/services/cloudsecuritycompliance/resource_cloud_security_compliance_cloud_control_generated_meta.yaml index c70e049f44c..1ae5110f8af 100644 --- a/google-beta/services/cloudsecuritycompliance/resource_cloud_security_compliance_cloud_control_generated_meta.yaml +++ b/google-beta/services/cloudsecuritycompliance/resource_cloud_security_compliance_cloud_control_generated_meta.yaml @@ -87,3 +87,5 @@ fields: - api_field: supportedCloudProviders - api_field: supportedEnforcementModes - api_field: supportedTargetResourceTypes + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/cloudsecuritycompliance/resource_cloud_security_compliance_framework.go b/google-beta/services/cloudsecuritycompliance/resource_cloud_security_compliance_framework.go index edfa19c0a54..eb585b2fc78 100644 --- a/google-beta/services/cloudsecuritycompliance/resource_cloud_security_compliance_framework.go +++ b/google-beta/services/cloudsecuritycompliance/resource_cloud_security_compliance_framework.go @@ -357,6 +357,19 @@ Possible values: BUILT_IN CUSTOM`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -489,6 +502,20 @@ func resourceCloudSecurityComplianceFrameworkRead(d *schema.ResourceData, meta i log.Printf("[DEBUG] Finished reading CloudSecurityComplianceFramework %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceCloudSecurityComplianceFrameworkFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -522,6 +549,19 @@ func resourceCloudSecurityComplianceFrameworkRead(d *schema.ResourceData, meta i } func resourceCloudSecurityComplianceFrameworkUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceCloudSecurityComplianceFramework().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceCloudSecurityComplianceFrameworkRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -632,6 +672,13 @@ func resourceCloudSecurityComplianceFrameworkUpdate(d *schema.ResourceData, meta } func resourceCloudSecurityComplianceFrameworkDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy CloudSecurityComplianceFramework without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Framework %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/cloudsecuritycompliance/resource_cloud_security_compliance_framework_deployment.go b/google-beta/services/cloudsecuritycompliance/resource_cloud_security_compliance_framework_deployment.go index 573e6185e0b..f511a5f9a11 100644 --- a/google-beta/services/cloudsecuritycompliance/resource_cloud_security_compliance_framework_deployment.go +++ b/google-beta/services/cloudsecuritycompliance/resource_cloud_security_compliance_framework_deployment.go @@ -100,6 +100,7 @@ func ResourceCloudSecurityComplianceFrameworkDeployment() *schema.Resource { return &schema.Resource{ Create: resourceCloudSecurityComplianceFrameworkDeploymentCreate, Read: resourceCloudSecurityComplianceFrameworkDeploymentRead, + Update: resourceCloudSecurityComplianceFrameworkDeploymentUpdate, Delete: resourceCloudSecurityComplianceFrameworkDeploymentDelete, Importer: &schema.ResourceImporter{ @@ -533,6 +534,19 @@ organizations/{organization}/locations/{location}/frameworkDeployments/{framewor Computed: true, Description: `The time at which the resource last updated.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -676,6 +690,20 @@ func resourceCloudSecurityComplianceFrameworkDeploymentRead(d *schema.ResourceDa log.Printf("[DEBUG] Finished reading CloudSecurityComplianceFrameworkDeployment %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceCloudSecurityComplianceFrameworkDeploymentFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -708,7 +736,19 @@ func resourceCloudSecurityComplianceFrameworkDeploymentRead(d *schema.ResourceDa return nil } +func resourceCloudSecurityComplianceFrameworkDeploymentUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceCloudSecurityComplianceFrameworkDeploymentRead(d, meta) +} + func resourceCloudSecurityComplianceFrameworkDeploymentDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy CloudSecurityComplianceFrameworkDeployment without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing FrameworkDeployment %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/cloudsecuritycompliance/resource_cloud_security_compliance_framework_deployment_generated_meta.yaml b/google-beta/services/cloudsecuritycompliance/resource_cloud_security_compliance_framework_deployment_generated_meta.yaml index a631a62192d..8edcc7943dd 100644 --- a/google-beta/services/cloudsecuritycompliance/resource_cloud_security_compliance_framework_deployment_generated_meta.yaml +++ b/google-beta/services/cloudsecuritycompliance/resource_cloud_security_compliance_framework_deployment_generated_meta.yaml @@ -44,3 +44,5 @@ fields: - api_field: targetResourceConfig.targetResourceCreationConfig.projectCreationConfig.projectDisplayName - api_field: targetResourceDisplayName - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/cloudsecuritycompliance/resource_cloud_security_compliance_framework_generated_meta.yaml b/google-beta/services/cloudsecuritycompliance/resource_cloud_security_compliance_framework_generated_meta.yaml index 55b9193607c..ad1b404bebe 100644 --- a/google-beta/services/cloudsecuritycompliance/resource_cloud_security_compliance_framework_generated_meta.yaml +++ b/google-beta/services/cloudsecuritycompliance/resource_cloud_security_compliance_framework_generated_meta.yaml @@ -35,3 +35,5 @@ fields: - api_field: supportedEnforcementModes - api_field: supportedTargetResourceTypes - api_field: type + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/cloudtasks/resource_cloud_tasks_queue.go b/google-beta/services/cloudtasks/resource_cloud_tasks_queue.go index 773c30ff881..26ac1c8f279 100644 --- a/google-beta/services/cloudtasks/resource_cloud_tasks_queue.go +++ b/google-beta/services/cloudtasks/resource_cloud_tasks_queue.go @@ -123,6 +123,7 @@ func ResourceCloudTasksQueue() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -551,6 +552,18 @@ default and means that no operations are logged.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -731,6 +744,18 @@ func resourceCloudTasksQueueRead(d *schema.ResourceData, meta interface{}) error return fmt.Errorf("Error setting desired_state: %s", err) } } + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Queue: %s", err) } @@ -768,6 +793,19 @@ func resourceCloudTasksQueueRead(d *schema.ResourceData, meta interface{}) error } func resourceCloudTasksQueueUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceCloudTasksQueue().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceCloudTasksQueueRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -934,6 +972,13 @@ func resourceCloudTasksQueueUpdate(d *schema.ResourceData, meta interface{}) err } func resourceCloudTasksQueueDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy CloudTasksQueue without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Queue %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/cloudtasks/resource_cloud_tasks_queue_generated_meta.yaml b/google-beta/services/cloudtasks/resource_cloud_tasks_queue_generated_meta.yaml index be8cc518856..665d6292814 100644 --- a/google-beta/services/cloudtasks/resource_cloud_tasks_queue_generated_meta.yaml +++ b/google-beta/services/cloudtasks/resource_cloud_tasks_queue_generated_meta.yaml @@ -39,3 +39,5 @@ fields: - api_field: retryConfig.minBackoff - api_field: stackdriverLoggingConfig.samplingRatio - api_field: state + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/colab/resource_colab_notebook_execution.go b/google-beta/services/colab/resource_colab_notebook_execution.go index f51670e4d80..696ab655fe4 100644 --- a/google-beta/services/colab/resource_colab_notebook_execution.go +++ b/google-beta/services/colab/resource_colab_notebook_execution.go @@ -100,6 +100,7 @@ func ResourceColabNotebookExecution() *schema.Resource { return &schema.Resource{ Create: resourceColabNotebookExecutionCreate, Read: resourceColabNotebookExecutionRead, + Update: resourceColabNotebookExecutionUpdate, Delete: resourceColabNotebookExecutionDelete, Importer: &schema.ResourceImporter{ @@ -113,6 +114,7 @@ func ResourceColabNotebookExecution() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -359,6 +361,18 @@ func ResourceColabNotebookExecution() *schema.Resource { Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -567,6 +581,19 @@ func resourceColabNotebookExecutionRead(d *schema.ResourceData, meta interface{} log.Printf("[DEBUG] Finished reading ColabNotebookExecution %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading NotebookExecution: %s", err) } @@ -603,7 +630,19 @@ func resourceColabNotebookExecutionRead(d *schema.ResourceData, meta interface{} return nil } +func resourceColabNotebookExecutionUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceColabNotebookExecutionRead(d, meta) +} + func resourceColabNotebookExecutionDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ColabNotebookExecution without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing NotebookExecution %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/colab/resource_colab_notebook_execution_generated_meta.yaml b/google-beta/services/colab/resource_colab_notebook_execution_generated_meta.yaml index 9fe89efe78c..8138221701d 100644 --- a/google-beta/services/colab/resource_colab_notebook_execution_generated_meta.yaml +++ b/google-beta/services/colab/resource_colab_notebook_execution_generated_meta.yaml @@ -30,3 +30,5 @@ fields: provider_only: true - api_field: notebookRuntimeTemplateResourceName - api_field: serviceAccount + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/colab/resource_colab_runtime.go b/google-beta/services/colab/resource_colab_runtime.go index 967009fdeb1..4905aa0d400 100644 --- a/google-beta/services/colab/resource_colab_runtime.go +++ b/google-beta/services/colab/resource_colab_runtime.go @@ -155,6 +155,7 @@ func ResourceColabRuntime() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -265,6 +266,18 @@ func ResourceColabRuntime() *schema.Resource { Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -437,6 +450,18 @@ func resourceColabRuntimeRead(d *schema.ResourceData, meta interface{}) error { return fmt.Errorf("Error setting desired_state: %s", err) } } + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Runtime: %s", err) } @@ -474,6 +499,19 @@ func resourceColabRuntimeRead(d *schema.ResourceData, meta interface{}) error { } func resourceColabRuntimeUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceColabRuntime().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceColabRuntimeRead(d, meta) + } + config := meta.(*transport_tpg.Config) name := d.Get("name").(string) state := d.Get("state").(string) @@ -563,6 +601,13 @@ func resourceColabRuntimeUpdate(d *schema.ResourceData, meta interface{}) error } func resourceColabRuntimeDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ColabRuntime without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Runtime %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/colab/resource_colab_runtime_generated_meta.yaml b/google-beta/services/colab/resource_colab_runtime_generated_meta.yaml index 8e50ef90ec2..9702b2a48f8 100644 --- a/google-beta/services/colab/resource_colab_runtime_generated_meta.yaml +++ b/google-beta/services/colab/resource_colab_runtime_generated_meta.yaml @@ -23,3 +23,5 @@ fields: - api_field: notebookRuntimeType - api_field: runtimeUser - api_field: state + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/colab/resource_colab_runtime_template.go b/google-beta/services/colab/resource_colab_runtime_template.go index 96b7a59c899..9de806d2113 100644 --- a/google-beta/services/colab/resource_colab_runtime_template.go +++ b/google-beta/services/colab/resource_colab_runtime_template.go @@ -116,6 +116,7 @@ func ResourceColabRuntimeTemplate() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -442,6 +443,18 @@ Please refer to the field 'effective_labels' for all of the labels present on th Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -668,6 +681,19 @@ func resourceColabRuntimeTemplateRead(d *schema.ResourceData, meta interface{}) log.Printf("[DEBUG] Finished reading ColabRuntimeTemplate %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading RuntimeTemplate: %s", err) } @@ -705,6 +731,19 @@ func resourceColabRuntimeTemplateRead(d *schema.ResourceData, meta interface{}) } func resourceColabRuntimeTemplateUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceColabRuntimeTemplate().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceColabRuntimeTemplateRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -820,6 +859,13 @@ func resourceColabRuntimeTemplateUpdate(d *schema.ResourceData, meta interface{} } func resourceColabRuntimeTemplateDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ColabRuntimeTemplate without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing RuntimeTemplate %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/colab/resource_colab_runtime_template_generated_meta.yaml b/google-beta/services/colab/resource_colab_runtime_template_generated_meta.yaml index dd1b9a481b2..1accaa045bd 100644 --- a/google-beta/services/colab/resource_colab_runtime_template_generated_meta.yaml +++ b/google-beta/services/colab/resource_colab_runtime_template_generated_meta.yaml @@ -36,3 +36,5 @@ fields: - api_field: softwareConfig.postStartupScriptConfig.postStartupScriptUrl - field: terraform_labels provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/colab/resource_colab_schedule.go b/google-beta/services/colab/resource_colab_schedule.go index bea05494751..6d5d73f59a2 100644 --- a/google-beta/services/colab/resource_colab_schedule.go +++ b/google-beta/services/colab/resource_colab_schedule.go @@ -134,6 +134,7 @@ func ResourceColabSchedule() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -319,6 +320,18 @@ func ResourceColabSchedule() *schema.Resource { Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -512,6 +525,18 @@ func resourceColabScheduleRead(d *schema.ResourceData, meta interface{}) error { return fmt.Errorf("Error setting desired_state: %s", err) } } + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Schedule: %s", err) } @@ -549,6 +574,19 @@ func resourceColabScheduleRead(d *schema.ResourceData, meta interface{}) error { } func resourceColabScheduleUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceColabSchedule().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceColabScheduleRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -729,6 +767,13 @@ func resourceColabScheduleUpdate(d *schema.ResourceData, meta interface{}) error } func resourceColabScheduleDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ColabSchedule without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Schedule %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/colab/resource_colab_schedule_generated_meta.yaml b/google-beta/services/colab/resource_colab_schedule_generated_meta.yaml index af60438d74a..3df9e168388 100644 --- a/google-beta/services/colab/resource_colab_schedule_generated_meta.yaml +++ b/google-beta/services/colab/resource_colab_schedule_generated_meta.yaml @@ -30,3 +30,5 @@ fields: - api_field: name - api_field: startTime - api_field: state + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/composer/resource_composer_environment.go b/google-beta/services/composer/resource_composer_environment.go index e6047c22897..5039d584ea5 100644 --- a/google-beta/services/composer/resource_composer_environment.go +++ b/google-beta/services/composer/resource_composer_environment.go @@ -172,6 +172,7 @@ func ResourceComposerEnvironment() *schema.Resource { }, CustomizeDiff: customdiff.All( + tpgresource.DefaultProviderDeletionPolicy("DELETE"), tpgresource.DefaultProviderProject, tpgresource.DefaultProviderRegion, tpgresource.SetLabelsDiff, @@ -1089,6 +1090,9 @@ func ResourceComposerEnvironment() *schema.Resource { }, }, }, + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end }, UseJSONNumber: true, } @@ -1209,10 +1213,20 @@ func resourceComposerEnvironmentRead(d *schema.ResourceData, meta interface{}) e if err := d.Set("storage_config", flattenComposerStorageConfig(res.StorageConfig)); err != nil { return fmt.Errorf("Error setting Storage: %s", err) } + + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + return nil } func resourceComposerEnvironmentUpdate(d *schema.ResourceData, meta interface{}) error { + + if tpgresource.DeletionPolicyPreUpdate(d, ResourceComposerEnvironment) { + return ResourceComposerEnvironment().Read(d, meta) + } + tfConfig := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, tfConfig.UserAgent) if err != nil { @@ -1639,6 +1653,13 @@ func resourceComposerEnvironmentPatchField(updateMask, userAgent string, env *co } func resourceComposerEnvironmentDelete(d *schema.ResourceData, meta interface{}) error { + + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { + return nil + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/composer/resource_composer_environment_meta.yaml b/google-beta/services/composer/resource_composer_environment_meta.yaml index 57499bbb22d..762204c5472 100644 --- a/google-beta/services/composer/resource_composer_environment_meta.yaml +++ b/google-beta/services/composer/resource_composer_environment_meta.yaml @@ -94,3 +94,5 @@ fields: - api_field: 'storageConfig.bucket' - field: 'terraform_labels' provider_only: true + - field: 'deletion_policy' + provider_only: true diff --git a/google-beta/services/composer/resource_composer_user_workloads_config_map.go b/google-beta/services/composer/resource_composer_user_workloads_config_map.go index 8236da43121..dd0839c822c 100644 --- a/google-beta/services/composer/resource_composer_user_workloads_config_map.go +++ b/google-beta/services/composer/resource_composer_user_workloads_config_map.go @@ -115,6 +115,7 @@ func ResourceComposerUserWorkloadsConfigMap() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -179,6 +180,18 @@ For details see: https://kubernetes.io/docs/concepts/configuration/configmap/`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -317,6 +330,19 @@ func resourceComposerUserWorkloadsConfigMapRead(d *schema.ResourceData, meta int log.Printf("[DEBUG] Finished reading ComposerUserWorkloadsConfigMap %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading UserWorkloadsConfigMap: %s", err) } @@ -360,6 +386,19 @@ func resourceComposerUserWorkloadsConfigMapRead(d *schema.ResourceData, meta int } func resourceComposerUserWorkloadsConfigMapUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceComposerUserWorkloadsConfigMap().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceComposerUserWorkloadsConfigMapRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -447,6 +486,13 @@ func resourceComposerUserWorkloadsConfigMapUpdate(d *schema.ResourceData, meta i } func resourceComposerUserWorkloadsConfigMapDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComposerUserWorkloadsConfigMap without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing UserWorkloadsConfigMap %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/composer/resource_composer_user_workloads_config_map_generated_meta.yaml b/google-beta/services/composer/resource_composer_user_workloads_config_map_generated_meta.yaml index 9f696418c2d..a3a30b6843b 100644 --- a/google-beta/services/composer/resource_composer_user_workloads_config_map_generated_meta.yaml +++ b/google-beta/services/composer/resource_composer_user_workloads_config_map_generated_meta.yaml @@ -13,3 +13,5 @@ fields: - api_field: name - field: region provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/composer/resource_composer_user_workloads_secret.go b/google-beta/services/composer/resource_composer_user_workloads_secret.go index 88387fc23ac..9517b448e67 100644 --- a/google-beta/services/composer/resource_composer_user_workloads_secret.go +++ b/google-beta/services/composer/resource_composer_user_workloads_secret.go @@ -48,6 +48,7 @@ func ResourceComposerUserWorkloadsSecret() *schema.Resource { }, CustomizeDiff: customdiff.All( + tpgresource.DefaultProviderDeletionPolicy("DELETE"), tpgresource.DefaultProviderProject, tpgresource.DefaultProviderRegion, ), @@ -88,6 +89,9 @@ func ResourceComposerUserWorkloadsSecret() *schema.Resource { Sensitive: true, Description: `A map of the secret data.`, }, + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end }, } } @@ -156,10 +160,20 @@ func resourceComposerUserWorkloadsSecretRead(d *schema.ResourceData, meta interf if err := d.Set("name", tpgresource.GetResourceNameFromSelfLink(res.Name)); err != nil { return fmt.Errorf("Error setting UserWorkloadsSecret Name: %s", err) } + + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + return nil } func resourceComposerUserWorkloadsSecretUpdate(d *schema.ResourceData, meta interface{}) error { + + if tpgresource.DeletionPolicyPreUpdate(d, ResourceComposerUserWorkloadsSecret) { + return ResourceComposerUserWorkloadsSecret().Read(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -193,6 +207,13 @@ func resourceComposerUserWorkloadsSecretUpdate(d *schema.ResourceData, meta inte } func resourceComposerUserWorkloadsSecretDelete(d *schema.ResourceData, meta interface{}) error { + + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { + return nil + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/composer/resource_composer_user_workloads_secret_meta.yaml b/google-beta/services/composer/resource_composer_user_workloads_secret_meta.yaml index 525905629a4..0f521a58aae 100644 --- a/google-beta/services/composer/resource_composer_user_workloads_secret_meta.yaml +++ b/google-beta/services/composer/resource_composer_user_workloads_secret_meta.yaml @@ -11,3 +11,5 @@ fields: - api_field: 'name' - field: 'project' - field: 'region' + - field: 'deletion_policy' + provider_only: true diff --git a/google-beta/services/compute/data_source_google_compute_instance_group.go b/google-beta/services/compute/data_source_google_compute_instance_group.go index ffc005c2a73..c71340a2f62 100644 --- a/google-beta/services/compute/data_source_google_compute_instance_group.go +++ b/google-beta/services/compute/data_source_google_compute_instance_group.go @@ -95,6 +95,11 @@ func DataSourceGoogleComputeInstanceGroup() *schema.Resource { Type: schema.TypeInt, Computed: true, }, + + "deletion_policy": { + Type: schema.TypeString, + Computed: true, + }, }, } } diff --git a/google-beta/services/compute/resource_compute_address.go b/google-beta/services/compute/resource_compute_address.go index 2dc0f3df4e6..de1b8cceebb 100644 --- a/google-beta/services/compute/resource_compute_address.go +++ b/google-beta/services/compute/resource_compute_address.go @@ -143,6 +143,7 @@ func ResourceComputeAddress() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -364,6 +365,18 @@ internally during updates.`, Type: schema.TypeString, Computed: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -645,6 +658,19 @@ func resourceComputeAddressRead(d *schema.ResourceData, meta interface{}) error log.Printf("[DEBUG] Finished reading ComputeAddress %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Address: %s", err) } @@ -682,6 +708,19 @@ func resourceComputeAddressRead(d *schema.ResourceData, meta interface{}) error } func resourceComputeAddressUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceComputeAddress().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceComputeAddressRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -776,6 +815,13 @@ func resourceComputeAddressUpdate(d *schema.ResourceData, meta interface{}) erro } func resourceComputeAddressDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeAddress without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Address %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_address_generated_meta.yaml b/google-beta/services/compute/resource_compute_address_generated_meta.yaml index eb03346c868..3a64860b70c 100644 --- a/google-beta/services/compute/resource_compute_address_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_address_generated_meta.yaml @@ -31,3 +31,5 @@ fields: provider_only: true - api_field: users - api_field: selfLink + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_attached_disk.go b/google-beta/services/compute/resource_compute_attached_disk.go index 4e3d4359104..4ba7c7e6325 100644 --- a/google-beta/services/compute/resource_compute_attached_disk.go +++ b/google-beta/services/compute/resource_compute_attached_disk.go @@ -37,6 +37,7 @@ func ResourceComputeAttachedDisk() *schema.Resource { return &schema.Resource{ Create: resourceAttachedDiskCreate, Read: resourceAttachedDiskRead, + Update: resourceAttachedDiskUpdate, Delete: resourceAttachedDiskDelete, Importer: &schema.ResourceImporter{ @@ -49,6 +50,7 @@ func ResourceComputeAttachedDisk() *schema.Resource { }, CustomizeDiff: customdiff.All( + tpgresource.DefaultProviderDeletionPolicy("DELETE"), tpgresource.DefaultProviderProject, computeAttachedDiskDefaultProviderZone, ), @@ -104,6 +106,9 @@ func ResourceComputeAttachedDisk() *schema.Resource { Description: `The disk interface used for attaching this disk. One of SCSI or NVME. (This field is only used for specific cases, please don't specify this field without advice from Google.)`, ValidateFunc: validation.StringInSlice([]string{"SCSI", "NVME"}, false), }, + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end }, UseJSONNumber: true, } @@ -235,10 +240,29 @@ func resourceAttachedDiskRead(d *schema.ResourceData, meta interface{}) error { return fmt.Errorf("Error setting disk: %s", err) } + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + return nil } +// UDP update start +func resourceAttachedDiskUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceAttachedDiskRead(d, meta) +} + +//UDP update end + func resourceAttachedDiskDelete(d *schema.ResourceData, meta interface{}) error { + + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { + return nil + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_attached_disk_meta.yaml b/google-beta/services/compute/resource_compute_attached_disk_meta.yaml index 652fe951a33..80fe0630085 100644 --- a/google-beta/services/compute/resource_compute_attached_disk_meta.yaml +++ b/google-beta/services/compute/resource_compute_attached_disk_meta.yaml @@ -17,3 +17,5 @@ fields: field: 'mode' - field: 'project' - api_field: 'zone' + - field: 'deletion_policy' + provider_only: true diff --git a/google-beta/services/compute/resource_compute_autoscaler.go b/google-beta/services/compute/resource_compute_autoscaler.go index d21a15abbba..258e34f44bd 100644 --- a/google-beta/services/compute/resource_compute_autoscaler.go +++ b/google-beta/services/compute/resource_compute_autoscaler.go @@ -116,6 +116,7 @@ func ResourceComputeAutoscaler() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, tpgresource.DefaultProviderZone, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -522,6 +523,18 @@ character, which cannot be a dash.`, Type: schema.TypeString, Computed: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -683,6 +696,19 @@ func resourceComputeAutoscalerRead(d *schema.ResourceData, meta interface{}) err log.Printf("[DEBUG] Finished reading ComputeAutoscaler %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Autoscaler: %s", err) } @@ -727,6 +753,19 @@ func resourceComputeAutoscalerRead(d *schema.ResourceData, meta interface{}) err } func resourceComputeAutoscalerUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceComputeAutoscaler().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceComputeAutoscalerRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -835,6 +874,13 @@ func resourceComputeAutoscalerUpdate(d *schema.ResourceData, meta interface{}) e } func resourceComputeAutoscalerDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeAutoscaler without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Autoscaler %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_autoscaler_generated_meta.yaml b/google-beta/services/compute/resource_compute_autoscaler_generated_meta.yaml index d960f2e5097..85ad067f830 100644 --- a/google-beta/services/compute/resource_compute_autoscaler_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_autoscaler_generated_meta.yaml @@ -57,3 +57,5 @@ fields: - api_field: target - api_field: zone - api_field: selfLink + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_backend_bucket.go b/google-beta/services/compute/resource_compute_backend_bucket.go index c640fdf2892..1f747453385 100644 --- a/google-beta/services/compute/resource_compute_backend_bucket.go +++ b/google-beta/services/compute/resource_compute_backend_bucket.go @@ -115,6 +115,7 @@ func ResourceComputeBackendBucket() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -368,6 +369,18 @@ and values are in the format tagValues/456.`, Type: schema.TypeString, Computed: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -595,6 +608,19 @@ func resourceComputeBackendBucketRead(d *schema.ResourceData, meta interface{}) log.Printf("[DEBUG] Finished reading ComputeBackendBucket %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading BackendBucket: %s", err) } @@ -626,6 +652,19 @@ func resourceComputeBackendBucketRead(d *schema.ResourceData, meta interface{}) } func resourceComputeBackendBucketUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceComputeBackendBucket().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceComputeBackendBucketRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -799,6 +838,13 @@ func resourceComputeBackendBucketUpdate(d *schema.ResourceData, meta interface{} } func resourceComputeBackendBucketDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeBackendBucket without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing BackendBucket %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_backend_bucket_generated_meta.yaml b/google-beta/services/compute/resource_compute_backend_bucket_generated_meta.yaml index 49fc6c10de4..93396cc466a 100644 --- a/google-beta/services/compute/resource_compute_backend_bucket_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_backend_bucket_generated_meta.yaml @@ -31,3 +31,5 @@ fields: - api_field: name - api_field: params.resourceManagerTags - api_field: selfLink + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_backend_bucket_signed_url_key.go b/google-beta/services/compute/resource_compute_backend_bucket_signed_url_key.go index def6d158f69..e07ce8dc5f7 100644 --- a/google-beta/services/compute/resource_compute_backend_bucket_signed_url_key.go +++ b/google-beta/services/compute/resource_compute_backend_bucket_signed_url_key.go @@ -100,6 +100,7 @@ func ResourceComputeBackendBucketSignedUrlKey() *schema.Resource { return &schema.Resource{ Create: resourceComputeBackendBucketSignedUrlKeyCreate, Read: resourceComputeBackendBucketSignedUrlKeyRead, + Update: resourceComputeBackendBucketSignedUrlKeyUpdate, Delete: resourceComputeBackendBucketSignedUrlKeyDelete, Timeouts: &schema.ResourceTimeout{ @@ -109,6 +110,7 @@ func ResourceComputeBackendBucketSignedUrlKey() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -163,6 +165,18 @@ valid RFC 4648 Section 5 base64url encoded string.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -331,6 +345,19 @@ func resourceComputeBackendBucketSignedUrlKeyRead(d *schema.ResourceData, meta i return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading BackendBucketSignedUrlKey: %s", err) } @@ -367,7 +394,19 @@ func resourceComputeBackendBucketSignedUrlKeyRead(d *schema.ResourceData, meta i return nil } +func resourceComputeBackendBucketSignedUrlKeyUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceComputeBackendBucketSignedUrlKeyRead(d, meta) +} + func resourceComputeBackendBucketSignedUrlKeyDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeBackendBucketSignedUrlKey without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing BackendBucketSignedUrlKey %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_backend_bucket_signed_url_key_generated_meta.yaml b/google-beta/services/compute/resource_compute_backend_bucket_signed_url_key_generated_meta.yaml index 9f4c350de24..75d1ca16fce 100644 --- a/google-beta/services/compute/resource_compute_backend_bucket_signed_url_key_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_backend_bucket_signed_url_key_generated_meta.yaml @@ -13,3 +13,5 @@ fields: field: key_value - api_field: cdnPolicy.signedUrlKeyNames.keyName field: name + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_backend_service.go b/google-beta/services/compute/resource_compute_backend_service.go index 70d7c564e71..43142bf623f 100644 --- a/google-beta/services/compute/resource_compute_backend_service.go +++ b/google-beta/services/compute/resource_compute_backend_service.go @@ -263,6 +263,7 @@ func ResourceComputeBackendService() *schema.Resource { SchemaVersion: 1, CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -1549,6 +1550,18 @@ object. This field is used in optimistic locking.`, Type: schema.TypeString, Computed: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -2203,6 +2216,19 @@ func resourceComputeBackendServiceRead(d *schema.ResourceData, meta interface{}) return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading BackendService: %s", err) } @@ -2234,6 +2260,19 @@ func resourceComputeBackendServiceRead(d *schema.ResourceData, meta interface{}) } func resourceComputeBackendServiceUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceComputeBackendService().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceComputeBackendServiceRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -2613,6 +2652,13 @@ func resourceComputeBackendServiceUpdate(d *schema.ResourceData, meta interface{ } func resourceComputeBackendServiceDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeBackendService without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing BackendService %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_backend_service_generated_meta.yaml b/google-beta/services/compute/resource_compute_backend_service_generated_meta.yaml index 8c20727d68d..cd77319fd5a 100644 --- a/google-beta/services/compute/resource_compute_backend_service_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_backend_service_generated_meta.yaml @@ -149,3 +149,5 @@ fields: - api_field: tlsSettings.subjectAltNames.dnsName - api_field: tlsSettings.subjectAltNames.uniformResourceIdentifier - api_field: selfLink + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_backend_service_signed_url_key.go b/google-beta/services/compute/resource_compute_backend_service_signed_url_key.go index fc2a5cb900d..1950a449559 100644 --- a/google-beta/services/compute/resource_compute_backend_service_signed_url_key.go +++ b/google-beta/services/compute/resource_compute_backend_service_signed_url_key.go @@ -100,6 +100,7 @@ func ResourceComputeBackendServiceSignedUrlKey() *schema.Resource { return &schema.Resource{ Create: resourceComputeBackendServiceSignedUrlKeyCreate, Read: resourceComputeBackendServiceSignedUrlKeyRead, + Update: resourceComputeBackendServiceSignedUrlKeyUpdate, Delete: resourceComputeBackendServiceSignedUrlKeyDelete, Timeouts: &schema.ResourceTimeout{ @@ -109,6 +110,7 @@ func ResourceComputeBackendServiceSignedUrlKey() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -163,6 +165,18 @@ valid RFC 4648 Section 5 base64url encoded string.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -331,6 +345,19 @@ func resourceComputeBackendServiceSignedUrlKeyRead(d *schema.ResourceData, meta return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading BackendServiceSignedUrlKey: %s", err) } @@ -367,7 +394,19 @@ func resourceComputeBackendServiceSignedUrlKeyRead(d *schema.ResourceData, meta return nil } +func resourceComputeBackendServiceSignedUrlKeyUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceComputeBackendServiceSignedUrlKeyRead(d, meta) +} + func resourceComputeBackendServiceSignedUrlKeyDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeBackendServiceSignedUrlKey without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing BackendServiceSignedUrlKey %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_backend_service_signed_url_key_generated_meta.yaml b/google-beta/services/compute/resource_compute_backend_service_signed_url_key_generated_meta.yaml index 89c2bb042ba..c2ea8a91197 100644 --- a/google-beta/services/compute/resource_compute_backend_service_signed_url_key_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_backend_service_signed_url_key_generated_meta.yaml @@ -13,3 +13,5 @@ fields: field: key_value - api_field: cdnPolicy.signedUrlKeyNames.keyName field: name + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_cross_site_network.go b/google-beta/services/compute/resource_compute_cross_site_network.go index 0b6e0cd0b7a..0825edd0a83 100644 --- a/google-beta/services/compute/resource_compute_cross_site_network.go +++ b/google-beta/services/compute/resource_compute_cross_site_network.go @@ -115,6 +115,7 @@ func ResourceComputeCrossSiteNetwork() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -159,6 +160,18 @@ lowercase letter, or digit, except the last character, which cannot be a dash.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -297,6 +310,19 @@ func resourceComputeCrossSiteNetworkRead(d *schema.ResourceData, meta interface{ log.Printf("[DEBUG] Finished reading ComputeCrossSiteNetwork %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading CrossSiteNetwork: %s", err) } @@ -328,6 +354,19 @@ func resourceComputeCrossSiteNetworkRead(d *schema.ResourceData, meta interface{ } func resourceComputeCrossSiteNetworkUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceComputeCrossSiteNetwork().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceComputeCrossSiteNetworkRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -407,6 +446,13 @@ func resourceComputeCrossSiteNetworkUpdate(d *schema.ResourceData, meta interfac } func resourceComputeCrossSiteNetworkDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeCrossSiteNetwork without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing CrossSiteNetwork %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_cross_site_network_generated_meta.yaml b/google-beta/services/compute/resource_compute_cross_site_network_generated_meta.yaml index 192ad2cc4d8..38022089291 100644 --- a/google-beta/services/compute/resource_compute_cross_site_network_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_cross_site_network_generated_meta.yaml @@ -9,3 +9,5 @@ api_resource_type_kind: CrossSiteNetwork fields: - api_field: description - api_field: name + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_disk.go b/google-beta/services/compute/resource_compute_disk.go index c81a4b381ec..239d08eb289 100644 --- a/google-beta/services/compute/resource_compute_disk.go +++ b/google-beta/services/compute/resource_compute_disk.go @@ -462,6 +462,7 @@ func ResourceComputeDisk() *schema.Resource { hyperDiskIopsUpdateDiffSuppress, tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -1040,6 +1041,18 @@ The name of the snapshot by default will be '{{disk-name}}-YYYYMMDD-HHmm'`, Type: schema.TypeString, Computed: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -1386,6 +1399,18 @@ func resourceComputeDiskRead(d *schema.ResourceData, meta interface{}) error { return fmt.Errorf("Error setting create_snapshot_before_destroy: %s", err) } } + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Disk: %s", err) } @@ -1423,6 +1448,19 @@ func resourceComputeDiskRead(d *schema.ResourceData, meta interface{}) error { } func resourceComputeDiskUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceComputeDisk().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceComputeDiskRead(d, meta) + } + config := meta.(*transport_tpg.Config) // 'config' is provided by the boilerplate. @@ -1550,6 +1588,13 @@ func resourceComputeDiskUpdate(d *schema.ResourceData, meta interface{}) error { } func resourceComputeDiskDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeDisk without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Disk %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_disk_async_replication.go b/google-beta/services/compute/resource_compute_disk_async_replication.go index 26ecbbd9d83..66497d3948f 100644 --- a/google-beta/services/compute/resource_compute_disk_async_replication.go +++ b/google-beta/services/compute/resource_compute_disk_async_replication.go @@ -26,6 +26,7 @@ import ( "github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource" transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) @@ -34,12 +35,17 @@ func ResourceComputeDiskAsyncReplication() *schema.Resource { return &schema.Resource{ Create: resourceDiskAsyncReplicationCreate, Read: resourceDiskAsyncReplicationRead, + Update: resourceDiskAsyncReplicationUpdate, Delete: resourceDiskAsyncReplicationDelete, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, + CustomizeDiff: customdiff.All( + tpgresource.DefaultProviderDeletionPolicy("DELETE"), + ), + Timeouts: &schema.ResourceTimeout{ Create: schema.DefaultTimeout(5 * time.Minute), Delete: schema.DefaultTimeout(5 * time.Minute), @@ -76,6 +82,9 @@ func ResourceComputeDiskAsyncReplication() *schema.Resource { }, }, }, + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end }, UseJSONNumber: true, } @@ -288,10 +297,30 @@ func resourceDiskAsyncReplicationRead(d *schema.ResourceData, meta interface{}) return fmt.Errorf("Error setting secondary_disk: %s", err) } d.SetId(resourceId) + + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + return nil } +// UDP update start +func resourceDiskAsyncReplicationUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceDiskAsyncReplicationRead(d, meta) +} + +//UDP update end + func resourceDiskAsyncReplicationDelete(d *schema.ResourceData, meta interface{}) error { + + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { + return nil + } + config, userAgent, err := asyncReplicationGetConfigAndUserAgent(d, meta) if err != nil { return err diff --git a/google-beta/services/compute/resource_compute_disk_async_replication_meta.yaml b/google-beta/services/compute/resource_compute_disk_async_replication_meta.yaml index 05b7ac77b4b..2f5b8cb75cf 100644 --- a/google-beta/services/compute/resource_compute_disk_async_replication_meta.yaml +++ b/google-beta/services/compute/resource_compute_disk_async_replication_meta.yaml @@ -11,3 +11,5 @@ fields: field: 'secondary_disk.disk' - api_field: 'resourceStatus.asyncSecondaryDisks' field: 'secondary_disk.state' + - field: 'deletion_policy' + provider_only: true diff --git a/google-beta/services/compute/resource_compute_disk_generated_meta.yaml b/google-beta/services/compute/resource_compute_disk_generated_meta.yaml index 388ac337bc5..9c5d8d47363 100644 --- a/google-beta/services/compute/resource_compute_disk_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_disk_generated_meta.yaml @@ -73,3 +73,5 @@ fields: - api_field: users - api_field: zone - api_field: selfLink + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_disk_resource_policy_attachment.go b/google-beta/services/compute/resource_compute_disk_resource_policy_attachment.go index c3c0b7f13ea..6628e9a6cf4 100644 --- a/google-beta/services/compute/resource_compute_disk_resource_policy_attachment.go +++ b/google-beta/services/compute/resource_compute_disk_resource_policy_attachment.go @@ -100,6 +100,7 @@ func ResourceComputeDiskResourcePolicyAttachment() *schema.Resource { return &schema.Resource{ Create: resourceComputeDiskResourcePolicyAttachmentCreate, Read: resourceComputeDiskResourcePolicyAttachmentRead, + Update: resourceComputeDiskResourcePolicyAttachmentUpdate, Delete: resourceComputeDiskResourcePolicyAttachmentDelete, Importer: &schema.ResourceImporter{ @@ -114,6 +115,7 @@ func ResourceComputeDiskResourcePolicyAttachment() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, tpgresource.DefaultProviderZone, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -172,6 +174,18 @@ creation. Do not specify the self link.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -343,6 +357,19 @@ func resourceComputeDiskResourcePolicyAttachmentRead(d *schema.ResourceData, met return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading DiskResourcePolicyAttachment: %s", err) } @@ -392,7 +419,19 @@ func resourceComputeDiskResourcePolicyAttachmentRead(d *schema.ResourceData, met return nil } +func resourceComputeDiskResourcePolicyAttachmentUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceComputeDiskResourcePolicyAttachmentRead(d, meta) +} + func resourceComputeDiskResourcePolicyAttachmentDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeDiskResourcePolicyAttachment without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing DiskResourcePolicyAttachment %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_disk_resource_policy_attachment_generated_meta.yaml b/google-beta/services/compute/resource_compute_disk_resource_policy_attachment_generated_meta.yaml index 0fd30aad6c6..d4ad84eb4d1 100644 --- a/google-beta/services/compute/resource_compute_disk_resource_policy_attachment_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_disk_resource_policy_attachment_generated_meta.yaml @@ -13,3 +13,5 @@ fields: field: name - field: zone provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_external_vpn_gateway.go b/google-beta/services/compute/resource_compute_external_vpn_gateway.go index 925f6d950d0..43936d989c3 100644 --- a/google-beta/services/compute/resource_compute_external_vpn_gateway.go +++ b/google-beta/services/compute/resource_compute_external_vpn_gateway.go @@ -116,6 +116,7 @@ func ResourceComputeExternalVpnGateway() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -261,6 +262,18 @@ internally during updates.`, Type: schema.TypeString, Computed: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -429,6 +442,19 @@ func resourceComputeExternalVpnGatewayRead(d *schema.ResourceData, meta interfac log.Printf("[DEBUG] Finished reading ComputeExternalVpnGateway %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading ExternalVpnGateway: %s", err) } @@ -460,6 +486,19 @@ func resourceComputeExternalVpnGatewayRead(d *schema.ResourceData, meta interfac } func resourceComputeExternalVpnGatewayUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceComputeExternalVpnGateway().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceComputeExternalVpnGatewayRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -549,6 +588,13 @@ func resourceComputeExternalVpnGatewayUpdate(d *schema.ResourceData, meta interf } func resourceComputeExternalVpnGatewayDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeExternalVpnGateway without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing ExternalVpnGateway %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_external_vpn_gateway_generated_meta.yaml b/google-beta/services/compute/resource_compute_external_vpn_gateway_generated_meta.yaml index 65dfd9d88ce..9b1bb9b1ad1 100644 --- a/google-beta/services/compute/resource_compute_external_vpn_gateway_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_external_vpn_gateway_generated_meta.yaml @@ -24,3 +24,5 @@ fields: - field: terraform_labels provider_only: true - api_field: selfLink + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_firewall.go b/google-beta/services/compute/resource_compute_firewall.go index 07e6743df0c..b28ded5942b 100644 --- a/google-beta/services/compute/resource_compute_firewall.go +++ b/google-beta/services/compute/resource_compute_firewall.go @@ -221,6 +221,7 @@ func ResourceComputeFirewall() *schema.Resource { resourceComputeFirewallEnableLoggingCustomizeDiff, resourceComputeFirewallSourceFieldsCustomizeDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -479,6 +480,18 @@ instances on the specified network.`, Type: schema.TypeString, Computed: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -761,6 +774,19 @@ func resourceComputeFirewallRead(d *schema.ResourceData, meta interface{}) error log.Printf("[DEBUG] Finished reading ComputeFirewall %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Firewall: %s", err) } @@ -792,6 +818,19 @@ func resourceComputeFirewallRead(d *schema.ResourceData, meta interface{}) error } func resourceComputeFirewallUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceComputeFirewall().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceComputeFirewallRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -943,6 +982,13 @@ func resourceComputeFirewallUpdate(d *schema.ResourceData, meta interface{}) err } func resourceComputeFirewallDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeFirewall without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Firewall %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_firewall_generated_meta.yaml b/google-beta/services/compute/resource_compute_firewall_generated_meta.yaml index 1b7929b7049..bbbeaec7410 100644 --- a/google-beta/services/compute/resource_compute_firewall_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_firewall_generated_meta.yaml @@ -31,3 +31,5 @@ fields: - api_field: targetServiceAccounts - api_field: targetTags - api_field: selfLink + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_firewall_policy.go b/google-beta/services/compute/resource_compute_firewall_policy.go index a3d2544a884..ec42e443897 100644 --- a/google-beta/services/compute/resource_compute_firewall_policy.go +++ b/google-beta/services/compute/resource_compute_firewall_policy.go @@ -115,6 +115,7 @@ func ResourceComputeFirewallPolicy() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Schema: map[string]*schema.Schema{ @@ -173,6 +174,19 @@ Specifically, the name must be 1-63 characters long and match the regular expres Computed: true, Description: `Server-defined URL for this resource with the resource id.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -317,6 +331,20 @@ func resourceComputeFirewallPolicyRead(d *schema.ResourceData, meta interface{}) log.Printf("[DEBUG] Finished reading ComputeFirewallPolicy %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceComputeFirewallPolicyFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -326,6 +354,19 @@ func resourceComputeFirewallPolicyRead(d *schema.ResourceData, meta interface{}) } func resourceComputeFirewallPolicyUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceComputeFirewallPolicy().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceComputeFirewallPolicyRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -391,6 +432,13 @@ func resourceComputeFirewallPolicyUpdate(d *schema.ResourceData, meta interface{ } func resourceComputeFirewallPolicyDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeFirewallPolicy without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing FirewallPolicy %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_firewall_policy_association.go b/google-beta/services/compute/resource_compute_firewall_policy_association.go index a7d0d4c9810..a2f55e2d49c 100644 --- a/google-beta/services/compute/resource_compute_firewall_policy_association.go +++ b/google-beta/services/compute/resource_compute_firewall_policy_association.go @@ -115,6 +115,7 @@ func ResourceComputeFirewallPolicyAssociation() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -167,6 +168,19 @@ on your exisiting firewall policy so as to prevent a situation where your attach Computed: true, Description: `The short name of the firewall policy of the association.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -306,6 +320,20 @@ func resourceComputeFirewallPolicyAssociationRead(d *schema.ResourceData, meta i log.Printf("[DEBUG] Finished reading ComputeFirewallPolicyAssociation %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceComputeFirewallPolicyAssociationFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -333,6 +361,19 @@ func resourceComputeFirewallPolicyAssociationRead(d *schema.ResourceData, meta i } func resourceComputeFirewallPolicyAssociationUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceComputeFirewallPolicyAssociation().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceComputeFirewallPolicyAssociationRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -411,6 +452,13 @@ func resourceComputeFirewallPolicyAssociationUpdate(d *schema.ResourceData, meta } func resourceComputeFirewallPolicyAssociationDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeFirewallPolicyAssociation without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing FirewallPolicyAssociation %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_firewall_policy_association_generated_meta.yaml b/google-beta/services/compute/resource_compute_firewall_policy_association_generated_meta.yaml index a45085e3f97..48b2768d0ae 100644 --- a/google-beta/services/compute/resource_compute_firewall_policy_association_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_firewall_policy_association_generated_meta.yaml @@ -15,3 +15,5 @@ fields: field: name - api_field: associations.shortName field: short_name + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_firewall_policy_generated_meta.yaml b/google-beta/services/compute/resource_compute_firewall_policy_generated_meta.yaml index 35a3edae2ab..6ca4d8216ee 100644 --- a/google-beta/services/compute/resource_compute_firewall_policy_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_firewall_policy_generated_meta.yaml @@ -18,3 +18,5 @@ fields: - api_field: selfLink - api_field: selfLinkWithId - api_field: shortName + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_firewall_policy_rule.go b/google-beta/services/compute/resource_compute_firewall_policy_rule.go index e36573d43a2..21c98807b0a 100644 --- a/google-beta/services/compute/resource_compute_firewall_policy_rule.go +++ b/google-beta/services/compute/resource_compute_firewall_policy_rule.go @@ -115,6 +115,7 @@ func ResourceComputeFirewallPolicyRule() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -426,6 +427,19 @@ Can be set only if action = 'apply_security_profile_group' and cannot be set for Computed: true, Description: `Calculation of the complexity of a single firewall policy rule.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -621,6 +635,20 @@ func resourceComputeFirewallPolicyRuleRead(d *schema.ResourceData, meta interfac log.Printf("[DEBUG] Finished reading ComputeFirewallPolicyRule %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceComputeFirewallPolicyRuleFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -648,6 +676,19 @@ func resourceComputeFirewallPolicyRuleRead(d *schema.ResourceData, meta interfac } func resourceComputeFirewallPolicyRuleUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceComputeFirewallPolicyRule().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceComputeFirewallPolicyRuleRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -802,6 +843,13 @@ func resourceComputeFirewallPolicyRuleUpdate(d *schema.ResourceData, meta interf } func resourceComputeFirewallPolicyRuleDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeFirewallPolicyRule without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing FirewallPolicyRule %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_firewall_policy_rule_generated_meta.yaml b/google-beta/services/compute/resource_compute_firewall_policy_rule_generated_meta.yaml index 3db11eee65c..1b9336ddac2 100644 --- a/google-beta/services/compute/resource_compute_firewall_policy_rule_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_firewall_policy_rule_generated_meta.yaml @@ -77,3 +77,5 @@ fields: field: target_service_accounts - api_field: rules.tlsInspect field: tls_inspect + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_firewall_policy_with_rules.go b/google-beta/services/compute/resource_compute_firewall_policy_with_rules.go index 12103f286b7..8e7a92c4db2 100644 --- a/google-beta/services/compute/resource_compute_firewall_policy_with_rules.go +++ b/google-beta/services/compute/resource_compute_firewall_policy_with_rules.go @@ -809,6 +809,19 @@ It can be set only if action = 'apply_security_profile_group' and cannot be set Computed: true, Description: `Server-defined URL for this resource with the resource id.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -1018,6 +1031,20 @@ func resourceComputeFirewallPolicyWithRulesRead(d *schema.ResourceData, meta int return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceComputeFirewallPolicyWithRulesFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -1039,6 +1066,19 @@ func resourceComputeFirewallPolicyWithRulesRead(d *schema.ResourceData, meta int } func resourceComputeFirewallPolicyWithRulesUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceComputeFirewallPolicyWithRules().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceComputeFirewallPolicyWithRulesRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1126,6 +1166,13 @@ func resourceComputeFirewallPolicyWithRulesUpdate(d *schema.ResourceData, meta i } func resourceComputeFirewallPolicyWithRulesDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeFirewallPolicyWithRules without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing FirewallPolicyWithRules %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_firewall_policy_with_rules_generated_meta.yaml b/google-beta/services/compute/resource_compute_firewall_policy_with_rules_generated_meta.yaml index b82af3af6af..801e58e3b5a 100644 --- a/google-beta/services/compute/resource_compute_firewall_policy_with_rules_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_firewall_policy_with_rules_generated_meta.yaml @@ -110,3 +110,5 @@ fields: - api_field: selfLink - api_field: selfLinkWithId - api_field: shortName + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_forwarding_rule.go b/google-beta/services/compute/resource_compute_forwarding_rule.go index a33bf2f7137..030583ae2b7 100644 --- a/google-beta/services/compute/resource_compute_forwarding_rule.go +++ b/google-beta/services/compute/resource_compute_forwarding_rule.go @@ -222,6 +222,7 @@ func ResourceComputeForwardingRule() *schema.Resource { forwardingRuleCustomizeDiff, tpgresource.SetLabelsDiffWithoutAttributionLabel, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -715,6 +716,18 @@ This field is only used for INTERNAL load balancing.`, Type: schema.TypeString, Computed: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -1068,6 +1081,18 @@ func resourceComputeForwardingRuleRead(d *schema.ResourceData, meta interface{}) return fmt.Errorf("Error setting recreate_closed_psc: %s", err) } } + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading ForwardingRule: %s", err) } @@ -1105,6 +1130,19 @@ func resourceComputeForwardingRuleRead(d *schema.ResourceData, meta interface{}) } func resourceComputeForwardingRuleUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceComputeForwardingRule().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceComputeForwardingRuleRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1357,6 +1395,13 @@ func resourceComputeForwardingRuleUpdate(d *schema.ResourceData, meta interface{ } func resourceComputeForwardingRuleDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeForwardingRule without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing ForwardingRule %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_forwarding_rule_generated_meta.yaml b/google-beta/services/compute/resource_compute_forwarding_rule_generated_meta.yaml index 2c97d0e2995..adcb05f4895 100644 --- a/google-beta/services/compute/resource_compute_forwarding_rule_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_forwarding_rule_generated_meta.yaml @@ -49,3 +49,5 @@ fields: - field: terraform_labels provider_only: true - api_field: selfLink + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_future_reservation.go b/google-beta/services/compute/resource_compute_future_reservation.go index 62c63584e65..92629e8f7c2 100644 --- a/google-beta/services/compute/resource_compute_future_reservation.go +++ b/google-beta/services/compute/resource_compute_future_reservation.go @@ -115,6 +115,7 @@ func ResourceComputeFutureReservation() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -809,6 +810,18 @@ character, which cannot be a dash.`, Type: schema.TypeString, Computed: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -1042,6 +1055,19 @@ func resourceComputeFutureReservationRead(d *schema.ResourceData, meta interface log.Printf("[DEBUG] Finished reading ComputeFutureReservation %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading FutureReservation: %s", err) } @@ -1079,6 +1105,19 @@ func resourceComputeFutureReservationRead(d *schema.ResourceData, meta interface } func resourceComputeFutureReservationUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceComputeFutureReservation().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceComputeFutureReservationRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1322,6 +1361,13 @@ func resourceComputeFutureReservationUpdate(d *schema.ResourceData, meta interfa } func resourceComputeFutureReservationDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeFutureReservation without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing FutureReservation %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_future_reservation_generated_meta.yaml b/google-beta/services/compute/resource_compute_future_reservation_generated_meta.yaml index 406438a69b1..24a00c6de9a 100644 --- a/google-beta/services/compute/resource_compute_future_reservation_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_future_reservation_generated_meta.yaml @@ -85,3 +85,5 @@ fields: - api_field: timeWindow.startTime - api_field: zone - api_field: selfLink + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_global_address.go b/google-beta/services/compute/resource_compute_global_address.go index efe3b6a550e..58f1ecdb3b3 100644 --- a/google-beta/services/compute/resource_compute_global_address.go +++ b/google-beta/services/compute/resource_compute_global_address.go @@ -116,6 +116,7 @@ func ResourceComputeGlobalAddress() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -261,6 +262,18 @@ internally during updates.`, Type: schema.TypeString, Computed: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -512,6 +525,19 @@ func resourceComputeGlobalAddressRead(d *schema.ResourceData, meta interface{}) log.Printf("[DEBUG] Finished reading ComputeGlobalAddress %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading GlobalAddress: %s", err) } @@ -543,6 +569,19 @@ func resourceComputeGlobalAddressRead(d *schema.ResourceData, meta interface{}) } func resourceComputeGlobalAddressUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceComputeGlobalAddress().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceComputeGlobalAddressRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -632,6 +671,13 @@ func resourceComputeGlobalAddressUpdate(d *schema.ResourceData, meta interface{} } func resourceComputeGlobalAddressDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeGlobalAddress without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing GlobalAddress %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_global_address_generated_meta.yaml b/google-beta/services/compute/resource_compute_global_address_generated_meta.yaml index 5cbaedb39dd..3c21e08d009 100644 --- a/google-beta/services/compute/resource_compute_global_address_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_global_address_generated_meta.yaml @@ -23,3 +23,5 @@ fields: - field: terraform_labels provider_only: true - api_field: selfLink + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_global_forwarding_rule.go b/google-beta/services/compute/resource_compute_global_forwarding_rule.go index 56f73aa6583..ea4a343641b 100644 --- a/google-beta/services/compute/resource_compute_global_forwarding_rule.go +++ b/google-beta/services/compute/resource_compute_global_forwarding_rule.go @@ -116,6 +116,7 @@ func ResourceComputeGlobalForwardingRule() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiffWithoutAttributionLabel, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -543,6 +544,18 @@ internally during updates.`, Type: schema.TypeString, Computed: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -857,6 +870,19 @@ func resourceComputeGlobalForwardingRuleRead(d *schema.ResourceData, meta interf log.Printf("[DEBUG] Finished reading ComputeGlobalForwardingRule %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading GlobalForwardingRule: %s", err) } @@ -888,6 +914,19 @@ func resourceComputeGlobalForwardingRuleRead(d *schema.ResourceData, meta interf } func resourceComputeGlobalForwardingRuleUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceComputeGlobalForwardingRule().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceComputeGlobalForwardingRuleRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1079,6 +1118,13 @@ func resourceComputeGlobalForwardingRuleUpdate(d *schema.ResourceData, meta inte } func resourceComputeGlobalForwardingRuleDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeGlobalForwardingRule without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing GlobalForwardingRule %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_global_forwarding_rule_generated_meta.yaml b/google-beta/services/compute/resource_compute_global_forwarding_rule_generated_meta.yaml index c896c981ced..abfc3debcda 100644 --- a/google-beta/services/compute/resource_compute_global_forwarding_rule_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_global_forwarding_rule_generated_meta.yaml @@ -42,3 +42,5 @@ fields: - field: terraform_labels provider_only: true - api_field: selfLink + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_global_network_endpoint.go b/google-beta/services/compute/resource_compute_global_network_endpoint.go index 1531d299d1a..39a48cd7d42 100644 --- a/google-beta/services/compute/resource_compute_global_network_endpoint.go +++ b/google-beta/services/compute/resource_compute_global_network_endpoint.go @@ -100,6 +100,7 @@ func ResourceComputeGlobalNetworkEndpoint() *schema.Resource { return &schema.Resource{ Create: resourceComputeGlobalNetworkEndpointCreate, Read: resourceComputeGlobalNetworkEndpointRead, + Update: resourceComputeGlobalNetworkEndpointUpdate, Delete: resourceComputeGlobalNetworkEndpointDelete, Importer: &schema.ResourceImporter{ @@ -113,6 +114,7 @@ func ResourceComputeGlobalNetworkEndpoint() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -181,6 +183,18 @@ This can only be specified when network_endpoint_type of the NEG is INTERNET_FQD Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -377,6 +391,19 @@ func resourceComputeGlobalNetworkEndpointRead(d *schema.ResourceData, meta inter return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading GlobalNetworkEndpoint: %s", err) } @@ -425,7 +452,19 @@ func resourceComputeGlobalNetworkEndpointRead(d *schema.ResourceData, meta inter return nil } +func resourceComputeGlobalNetworkEndpointUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceComputeGlobalNetworkEndpointRead(d, meta) +} + func resourceComputeGlobalNetworkEndpointDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeGlobalNetworkEndpoint without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing GlobalNetworkEndpoint %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_global_network_endpoint_generated_meta.yaml b/google-beta/services/compute/resource_compute_global_network_endpoint_generated_meta.yaml index ff0ac2b2e62..5881431afe2 100644 --- a/google-beta/services/compute/resource_compute_global_network_endpoint_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_global_network_endpoint_generated_meta.yaml @@ -12,3 +12,5 @@ fields: provider_only: true - api_field: ipAddress - api_field: port + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_global_network_endpoint_group.go b/google-beta/services/compute/resource_compute_global_network_endpoint_group.go index 8c98c87269b..7f69fe58740 100644 --- a/google-beta/services/compute/resource_compute_global_network_endpoint_group.go +++ b/google-beta/services/compute/resource_compute_global_network_endpoint_group.go @@ -100,6 +100,7 @@ func ResourceComputeGlobalNetworkEndpointGroup() *schema.Resource { return &schema.Resource{ Create: resourceComputeGlobalNetworkEndpointGroupCreate, Read: resourceComputeGlobalNetworkEndpointGroupRead, + Update: resourceComputeGlobalNetworkEndpointGroupUpdate, Delete: resourceComputeGlobalNetworkEndpointGroupDelete, Importer: &schema.ResourceImporter{ @@ -113,6 +114,7 @@ func ResourceComputeGlobalNetworkEndpointGroup() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -179,6 +181,18 @@ you create the resource.`, Type: schema.TypeString, Computed: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -329,6 +343,19 @@ func resourceComputeGlobalNetworkEndpointGroupRead(d *schema.ResourceData, meta log.Printf("[DEBUG] Finished reading ComputeGlobalNetworkEndpointGroup %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading GlobalNetworkEndpointGroup: %s", err) } @@ -359,7 +386,19 @@ func resourceComputeGlobalNetworkEndpointGroupRead(d *schema.ResourceData, meta return nil } +func resourceComputeGlobalNetworkEndpointGroupUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceComputeGlobalNetworkEndpointGroupRead(d, meta) +} + func resourceComputeGlobalNetworkEndpointGroupDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeGlobalNetworkEndpointGroup without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing GlobalNetworkEndpointGroup %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_global_network_endpoint_group_generated_meta.yaml b/google-beta/services/compute/resource_compute_global_network_endpoint_group_generated_meta.yaml index 396d59cb2b8..74cc7afb8c2 100644 --- a/google-beta/services/compute/resource_compute_global_network_endpoint_group_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_global_network_endpoint_group_generated_meta.yaml @@ -12,3 +12,5 @@ fields: - api_field: name - api_field: networkEndpointType - api_field: selfLink + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_ha_vpn_gateway.go b/google-beta/services/compute/resource_compute_ha_vpn_gateway.go index 53b1934fb30..f6b8c80800d 100644 --- a/google-beta/services/compute/resource_compute_ha_vpn_gateway.go +++ b/google-beta/services/compute/resource_compute_ha_vpn_gateway.go @@ -125,6 +125,7 @@ func ResourceComputeHaVpnGateway() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -300,6 +301,18 @@ otherwise the request will fail with error 412 conditionNotMet.`, Type: schema.TypeString, Computed: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -491,6 +504,19 @@ func resourceComputeHaVpnGatewayRead(d *schema.ResourceData, meta interface{}) e log.Printf("[DEBUG] Finished reading ComputeHaVpnGateway %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading HaVpnGateway: %s", err) } @@ -528,6 +554,19 @@ func resourceComputeHaVpnGatewayRead(d *schema.ResourceData, meta interface{}) e } func resourceComputeHaVpnGatewayUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceComputeHaVpnGateway().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceComputeHaVpnGatewayRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -622,6 +661,13 @@ func resourceComputeHaVpnGatewayUpdate(d *schema.ResourceData, meta interface{}) } func resourceComputeHaVpnGatewayDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeHaVpnGateway without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing HaVpnGateway %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_ha_vpn_gateway_generated_meta.yaml b/google-beta/services/compute/resource_compute_ha_vpn_gateway_generated_meta.yaml index 400c034003f..4a2c8a2c140 100644 --- a/google-beta/services/compute/resource_compute_ha_vpn_gateway_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_ha_vpn_gateway_generated_meta.yaml @@ -24,3 +24,5 @@ fields: - api_field: vpnInterfaces.interconnectAttachment - api_field: vpnInterfaces.ipAddress - api_field: selfLink + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_health_check.go b/google-beta/services/compute/resource_compute_health_check.go index fb938fb9798..4bf84bd74fb 100644 --- a/google-beta/services/compute/resource_compute_health_check.go +++ b/google-beta/services/compute/resource_compute_health_check.go @@ -199,6 +199,7 @@ func ResourceComputeHealthCheck() *schema.Resource { CustomizeDiff: customdiff.All( healthCheckCustomizeDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -818,6 +819,18 @@ consecutive failures. The default value is 2.`, Type: schema.TypeString, Computed: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -1039,6 +1052,19 @@ func resourceComputeHealthCheckRead(d *schema.ResourceData, meta interface{}) er log.Printf("[DEBUG] Finished reading ComputeHealthCheck %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading HealthCheck: %s", err) } @@ -1070,6 +1096,19 @@ func resourceComputeHealthCheckRead(d *schema.ResourceData, meta interface{}) er } func resourceComputeHealthCheckUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceComputeHealthCheck().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceComputeHealthCheckRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1238,6 +1277,13 @@ func resourceComputeHealthCheckUpdate(d *schema.ResourceData, meta interface{}) } func resourceComputeHealthCheckDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeHealthCheck without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing HealthCheck %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_health_check_generated_meta.yaml b/google-beta/services/compute/resource_compute_health_check_generated_meta.yaml index 3cd62dc28f8..08dd4a0f456 100644 --- a/google-beta/services/compute/resource_compute_health_check_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_health_check_generated_meta.yaml @@ -60,3 +60,5 @@ fields: - api_field: type - api_field: unhealthyThreshold - api_field: selfLink + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_http_health_check.go b/google-beta/services/compute/resource_compute_http_health_check.go index e1e5219ae27..f30a10798d3 100644 --- a/google-beta/services/compute/resource_compute_http_health_check.go +++ b/google-beta/services/compute/resource_compute_http_health_check.go @@ -115,6 +115,7 @@ func ResourceComputeHttpHealthCheck() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -220,6 +221,18 @@ consecutive failures. The default value is 2.`, Type: schema.TypeString, Computed: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -400,6 +413,19 @@ func resourceComputeHttpHealthCheckRead(d *schema.ResourceData, meta interface{} log.Printf("[DEBUG] Finished reading ComputeHttpHealthCheck %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading HttpHealthCheck: %s", err) } @@ -431,6 +457,19 @@ func resourceComputeHttpHealthCheckRead(d *schema.ResourceData, meta interface{} } func resourceComputeHttpHealthCheckUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceComputeHttpHealthCheck().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceComputeHttpHealthCheckRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -558,6 +597,13 @@ func resourceComputeHttpHealthCheckUpdate(d *schema.ResourceData, meta interface } func resourceComputeHttpHealthCheckDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeHttpHealthCheck without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing HttpHealthCheck %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_http_health_check_generated_meta.yaml b/google-beta/services/compute/resource_compute_http_health_check_generated_meta.yaml index 541d671f391..03785e2aa3f 100644 --- a/google-beta/services/compute/resource_compute_http_health_check_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_http_health_check_generated_meta.yaml @@ -18,3 +18,5 @@ fields: - api_field: timeoutSec - api_field: unhealthyThreshold - api_field: selfLink + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_https_health_check.go b/google-beta/services/compute/resource_compute_https_health_check.go index 363a1b4e53e..772be0abdcd 100644 --- a/google-beta/services/compute/resource_compute_https_health_check.go +++ b/google-beta/services/compute/resource_compute_https_health_check.go @@ -115,6 +115,7 @@ func ResourceComputeHttpsHealthCheck() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -220,6 +221,18 @@ consecutive failures. The default value is 2.`, Type: schema.TypeString, Computed: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -400,6 +413,19 @@ func resourceComputeHttpsHealthCheckRead(d *schema.ResourceData, meta interface{ log.Printf("[DEBUG] Finished reading ComputeHttpsHealthCheck %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading HttpsHealthCheck: %s", err) } @@ -431,6 +457,19 @@ func resourceComputeHttpsHealthCheckRead(d *schema.ResourceData, meta interface{ } func resourceComputeHttpsHealthCheckUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceComputeHttpsHealthCheck().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceComputeHttpsHealthCheckRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -558,6 +597,13 @@ func resourceComputeHttpsHealthCheckUpdate(d *schema.ResourceData, meta interfac } func resourceComputeHttpsHealthCheckDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeHttpsHealthCheck without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing HttpsHealthCheck %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_https_health_check_generated_meta.yaml b/google-beta/services/compute/resource_compute_https_health_check_generated_meta.yaml index 834ed919722..c12794365fe 100644 --- a/google-beta/services/compute/resource_compute_https_health_check_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_https_health_check_generated_meta.yaml @@ -18,3 +18,5 @@ fields: - api_field: timeoutSec - api_field: unhealthyThreshold - api_field: selfLink + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_image.go b/google-beta/services/compute/resource_compute_image.go index a4ef32752cb..5733bc91de4 100644 --- a/google-beta/services/compute/resource_compute_image.go +++ b/google-beta/services/compute/resource_compute_image.go @@ -116,6 +116,7 @@ func ResourceComputeImage() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -659,6 +660,18 @@ internally during updates.`, Type: schema.TypeString, Computed: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -913,6 +926,19 @@ func resourceComputeImageRead(d *schema.ResourceData, meta interface{}) error { log.Printf("[DEBUG] Finished reading ComputeImage %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Image: %s", err) } @@ -944,6 +970,19 @@ func resourceComputeImageRead(d *schema.ResourceData, meta interface{}) error { } func resourceComputeImageUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceComputeImage().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceComputeImageRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1033,6 +1072,13 @@ func resourceComputeImageUpdate(d *schema.ResourceData, meta interface{}) error } func resourceComputeImageDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeImage without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Image %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_image_generated_meta.yaml b/google-beta/services/compute/resource_compute_image_generated_meta.yaml index 24a09bb71c0..a2c8511261b 100644 --- a/google-beta/services/compute/resource_compute_image_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_image_generated_meta.yaml @@ -59,3 +59,5 @@ fields: - field: terraform_labels provider_only: true - api_field: selfLink + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_instance.go b/google-beta/services/compute/resource_compute_instance.go index fea893989c8..65a2b91833c 100644 --- a/google-beta/services/compute/resource_compute_instance.go +++ b/google-beta/services/compute/resource_compute_instance.go @@ -1686,8 +1686,12 @@ be from 0 to 999,999,999 inclusive.`, Default: false, Description: `Specifies whether the disks restored from source snapshots or source machine image should erase Windows specific VSS signature.`, }, + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end }, CustomizeDiff: customdiff.All( + tpgresource.DefaultProviderDeletionPolicy("DELETE"), tpgresource.DefaultProviderProject, tpgresource.DefaultProviderZone, customdiff.If( @@ -2344,10 +2348,19 @@ func resourceComputeInstanceRead(d *schema.ResourceData, meta interface{}) error d.SetId(fmt.Sprintf("projects/%s/zones/%s/instances/%s", project, zone, instance.Name)) + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + return nil } func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) error { + + if tpgresource.DeletionPolicyPreUpdate(d, ResourceComputeInstance) { + return ResourceComputeInstance().Read(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -3565,6 +3578,13 @@ func isGracefulMetadataStartupSwitch(d *schema.ResourceDiff) bool { } func resourceComputeInstanceDelete(d *schema.ResourceData, meta interface{}) error { + + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { + return nil + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_instance_from_machine_image_meta.yaml b/google-beta/services/compute/resource_compute_instance_from_machine_image_meta.yaml index bcdf21d5a13..d668f3bcb2b 100644 --- a/google-beta/services/compute/resource_compute_instance_from_machine_image_meta.yaml +++ b/google-beta/services/compute/resource_compute_instance_from_machine_image_meta.yaml @@ -261,3 +261,5 @@ fields: provider_only: true - api_field: 'zone' - api_field: 'eraseWindowsVssSignature' + - field: 'deletion_policy' + provider_only: true diff --git a/google-beta/services/compute/resource_compute_instance_from_template_meta.yaml b/google-beta/services/compute/resource_compute_instance_from_template_meta.yaml index 3154220de9c..cdf516b8828 100644 --- a/google-beta/services/compute/resource_compute_instance_from_template_meta.yaml +++ b/google-beta/services/compute/resource_compute_instance_from_template_meta.yaml @@ -255,3 +255,5 @@ fields: provider_only: true - api_field: 'zone' - api_field: 'eraseWindowsVssSignature' + - field: 'deletion_policy' + provider_only: true diff --git a/google-beta/services/compute/resource_compute_instance_group.go b/google-beta/services/compute/resource_compute_instance_group.go index f0ced35f71f..8d25a0bbb17 100644 --- a/google-beta/services/compute/resource_compute_instance_group.go +++ b/google-beta/services/compute/resource_compute_instance_group.go @@ -51,6 +51,7 @@ func ResourceComputeInstanceGroup() *schema.Resource { }, CustomizeDiff: customdiff.All( + tpgresource.DefaultProviderDeletionPolicy("DELETE"), tpgresource.DefaultProviderProject, tpgresource.DefaultProviderZone, ), @@ -139,6 +140,9 @@ func ResourceComputeInstanceGroup() *schema.Resource { Computed: true, Description: `The number of instances in the group.`, }, + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end }, UseJSONNumber: true, } @@ -418,9 +422,18 @@ func resourceComputeInstanceGroupRead(d *schema.ResourceData, meta interface{}) return fmt.Errorf("Error setting self_link: %s", err) } + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + return nil } func resourceComputeInstanceGroupUpdate(d *schema.ResourceData, meta interface{}) error { + + if tpgresource.DeletionPolicyPreUpdate(d, ResourceComputeInstanceGroup) { + return ResourceComputeInstanceGroup().Read(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -559,6 +572,13 @@ func resourceComputeInstanceGroupUpdate(d *schema.ResourceData, meta interface{} } func resourceComputeInstanceGroupDelete(d *schema.ResourceData, meta interface{}) error { + + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { + return nil + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_instance_group_manager.go b/google-beta/services/compute/resource_compute_instance_group_manager.go index 02afd91c0e1..218d876baa6 100644 --- a/google-beta/services/compute/resource_compute_instance_group_manager.go +++ b/google-beta/services/compute/resource_compute_instance_group_manager.go @@ -50,6 +50,7 @@ func ResourceComputeInstanceGroupManager() *schema.Resource { Delete: schema.DefaultTimeout(15 * time.Minute), }, CustomizeDiff: customdiff.All( + tpgresource.DefaultProviderDeletionPolicy("DELETE"), tpgresource.DefaultProviderProject, tpgresource.DefaultProviderZone, customdiff.ForceNewIfChange("resource_policies.0.workload_policy", ForceNewResourcePoliciesWorkloadPolicyIfNewIsEmpty), @@ -639,6 +640,9 @@ func ResourceComputeInstanceGroupManager() *schema.Resource { }, }, }, + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end }, UseJSONNumber: true, } @@ -1048,6 +1052,10 @@ func resourceComputeInstanceGroupManagerRead(d *schema.ResourceData, meta interf } } + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + return nil } diff --git a/google-beta/services/compute/resource_compute_instance_group_manager_meta.yaml b/google-beta/services/compute/resource_compute_instance_group_manager_meta.yaml index f6940205493..abfe1a55ddf 100644 --- a/google-beta/services/compute/resource_compute_instance_group_manager_meta.yaml +++ b/google-beta/services/compute/resource_compute_instance_group_manager_meta.yaml @@ -88,3 +88,5 @@ fields: - field: 'wait_for_instances_status' provider_only: true - api_field: 'zone' + - field: 'deletion_policy' + provider_only: true diff --git a/google-beta/services/compute/resource_compute_instance_group_membership.go b/google-beta/services/compute/resource_compute_instance_group_membership.go index 8b6e6d57f3c..41ad5fc0e26 100644 --- a/google-beta/services/compute/resource_compute_instance_group_membership.go +++ b/google-beta/services/compute/resource_compute_instance_group_membership.go @@ -100,6 +100,7 @@ func ResourceComputeInstanceGroupMembership() *schema.Resource { return &schema.Resource{ Create: resourceComputeInstanceGroupMembershipCreate, Read: resourceComputeInstanceGroupMembershipRead, + Update: resourceComputeInstanceGroupMembershipUpdate, Delete: resourceComputeInstanceGroupMembershipDelete, Importer: &schema.ResourceImporter{ @@ -113,6 +114,7 @@ func ResourceComputeInstanceGroupMembership() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -170,6 +172,18 @@ func ResourceComputeInstanceGroupMembership() *schema.Resource { Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -336,6 +350,19 @@ func resourceComputeInstanceGroupMembershipRead(d *schema.ResourceData, meta int return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading InstanceGroupMembership: %s", err) } @@ -378,7 +405,19 @@ func resourceComputeInstanceGroupMembershipRead(d *schema.ResourceData, meta int return nil } +func resourceComputeInstanceGroupMembershipUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceComputeInstanceGroupMembershipRead(d, meta) +} + func resourceComputeInstanceGroupMembershipDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeInstanceGroupMembership without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing InstanceGroupMembership %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_instance_group_membership_generated_meta.yaml b/google-beta/services/compute/resource_compute_instance_group_membership_generated_meta.yaml index e6fa6383156..3e0593f3e39 100644 --- a/google-beta/services/compute/resource_compute_instance_group_membership_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_instance_group_membership_generated_meta.yaml @@ -14,3 +14,5 @@ fields: provider_only: true - field: zone provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_instance_group_meta.yaml b/google-beta/services/compute/resource_compute_instance_group_meta.yaml index 96b2a0e628e..b51a78f8d20 100644 --- a/google-beta/services/compute/resource_compute_instance_group_meta.yaml +++ b/google-beta/services/compute/resource_compute_instance_group_meta.yaml @@ -20,3 +20,5 @@ fields: - api_field: 'selfLink' - api_field: 'size' - api_field: 'zone' + - field: 'deletion_policy' + provider_only: true diff --git a/google-beta/services/compute/resource_compute_instance_group_named_port.go b/google-beta/services/compute/resource_compute_instance_group_named_port.go index b729fc3aef2..021f74d6847 100644 --- a/google-beta/services/compute/resource_compute_instance_group_named_port.go +++ b/google-beta/services/compute/resource_compute_instance_group_named_port.go @@ -100,6 +100,7 @@ func ResourceComputeInstanceGroupNamedPort() *schema.Resource { return &schema.Resource{ Create: resourceComputeInstanceGroupNamedPortCreate, Read: resourceComputeInstanceGroupNamedPortRead, + Update: resourceComputeInstanceGroupNamedPortUpdate, Delete: resourceComputeInstanceGroupNamedPortDelete, Importer: &schema.ResourceImporter{ @@ -114,6 +115,7 @@ func ResourceComputeInstanceGroupNamedPort() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, tpgresource.DefaultProviderZone, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -182,6 +184,18 @@ long, and comply with RFC1035.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -365,6 +379,19 @@ func resourceComputeInstanceGroupNamedPortRead(d *schema.ResourceData, meta inte return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading InstanceGroupNamedPort: %s", err) } @@ -420,7 +447,19 @@ func resourceComputeInstanceGroupNamedPortRead(d *schema.ResourceData, meta inte return nil } +func resourceComputeInstanceGroupNamedPortUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceComputeInstanceGroupNamedPortRead(d, meta) +} + func resourceComputeInstanceGroupNamedPortDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeInstanceGroupNamedPort without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing InstanceGroupNamedPort %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_instance_group_named_port_generated_meta.yaml b/google-beta/services/compute/resource_compute_instance_group_named_port_generated_meta.yaml index af04e366ec7..cad11e7d34a 100644 --- a/google-beta/services/compute/resource_compute_instance_group_named_port_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_instance_group_named_port_generated_meta.yaml @@ -17,3 +17,5 @@ fields: field: port - field: zone provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_instance_meta.yaml b/google-beta/services/compute/resource_compute_instance_meta.yaml index 82e0738e63a..b77ef3720a0 100644 --- a/google-beta/services/compute/resource_compute_instance_meta.yaml +++ b/google-beta/services/compute/resource_compute_instance_meta.yaml @@ -257,4 +257,6 @@ fields: - field: 'terraform_labels' provider_only: true - api_field: 'zone' - - api_field: 'eraseWindowsVssSignature' \ No newline at end of file + - api_field: 'eraseWindowsVssSignature' + - field: 'deletion_policy' + provider_only: true diff --git a/google-beta/services/compute/resource_compute_instance_settings.go b/google-beta/services/compute/resource_compute_instance_settings.go index 4c6af82d5e8..d05cacb435d 100644 --- a/google-beta/services/compute/resource_compute_instance_settings.go +++ b/google-beta/services/compute/resource_compute_instance_settings.go @@ -115,6 +115,7 @@ func ResourceComputeInstanceSettings() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Schema: map[string]*schema.Schema{ @@ -152,6 +153,18 @@ internally during updates.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -301,6 +314,19 @@ func resourceComputeInstanceSettingsRead(d *schema.ResourceData, meta interface{ log.Printf("[DEBUG] Finished reading ComputeInstanceSettings %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading InstanceSettings: %s", err) } @@ -314,6 +340,19 @@ func resourceComputeInstanceSettingsRead(d *schema.ResourceData, meta interface{ } func resourceComputeInstanceSettingsUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceComputeInstanceSettings().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceComputeInstanceSettingsRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -411,6 +450,13 @@ func resourceComputeInstanceSettingsUpdate(d *schema.ResourceData, meta interfac } func resourceComputeInstanceSettingsDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeInstanceSettings without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing InstanceSettings %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_instance_settings_generated_meta.yaml b/google-beta/services/compute/resource_compute_instance_settings_generated_meta.yaml index 95b1c442268..cd9f8566e7d 100644 --- a/google-beta/services/compute/resource_compute_instance_settings_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_instance_settings_generated_meta.yaml @@ -12,3 +12,5 @@ fields: - api_field: fingerprint - api_field: metadata.items - api_field: zone + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_instance_template.go b/google-beta/services/compute/resource_compute_instance_template.go index 862cd0789c4..387ced0835e 100644 --- a/google-beta/services/compute/resource_compute_instance_template.go +++ b/google-beta/services/compute/resource_compute_instance_template.go @@ -80,6 +80,7 @@ func ResourceComputeInstanceTemplate() *schema.Resource { }, SchemaVersion: 1, CustomizeDiff: customdiff.All( + tpgresource.DefaultProviderDeletionPolicy("DELETE"), tpgresource.DefaultProviderProject, resourceComputeInstanceTemplateSourceImageCustomizeDiff, resourceComputeInstanceTemplateScratchDiskCustomizeDiff, diff --git a/google-beta/services/compute/resource_compute_instant_snapshot.go b/google-beta/services/compute/resource_compute_instant_snapshot.go index 44e5ee0584c..96bf86ea08a 100644 --- a/google-beta/services/compute/resource_compute_instant_snapshot.go +++ b/google-beta/services/compute/resource_compute_instant_snapshot.go @@ -116,6 +116,7 @@ func ResourceComputeInstantSnapshot() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -248,6 +249,18 @@ internally during updates.`, Type: schema.TypeString, Computed: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -421,6 +434,19 @@ func resourceComputeInstantSnapshotRead(d *schema.ResourceData, meta interface{} log.Printf("[DEBUG] Finished reading ComputeInstantSnapshot %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading InstantSnapshot: %s", err) } @@ -458,6 +484,19 @@ func resourceComputeInstantSnapshotRead(d *schema.ResourceData, meta interface{} } func resourceComputeInstantSnapshotUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceComputeInstantSnapshot().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceComputeInstantSnapshotRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -552,6 +591,13 @@ func resourceComputeInstantSnapshotUpdate(d *schema.ResourceData, meta interface } func resourceComputeInstantSnapshotDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeInstantSnapshot without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing InstantSnapshot %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_instant_snapshot_generated_meta.yaml b/google-beta/services/compute/resource_compute_instant_snapshot_generated_meta.yaml index 511ff0b52ca..ed52921beb4 100644 --- a/google-beta/services/compute/resource_compute_instant_snapshot_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_instant_snapshot_generated_meta.yaml @@ -24,3 +24,5 @@ fields: provider_only: true - api_field: zone - api_field: selfLink + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_interconnect.go b/google-beta/services/compute/resource_compute_interconnect.go index e330c05f95d..cf76dde8738 100644 --- a/google-beta/services/compute/resource_compute_interconnect.go +++ b/google-beta/services/compute/resource_compute_interconnect.go @@ -120,6 +120,7 @@ func ResourceComputeInterconnect() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -637,6 +638,18 @@ This can be used only for ping tests.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -931,6 +944,19 @@ func resourceComputeInterconnectRead(d *schema.ResourceData, meta interface{}) e log.Printf("[DEBUG] Finished reading ComputeInterconnect %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Interconnect: %s", err) } @@ -962,6 +988,19 @@ func resourceComputeInterconnectRead(d *schema.ResourceData, meta interface{}) e } func resourceComputeInterconnectUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceComputeInterconnect().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceComputeInterconnectRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1138,6 +1177,13 @@ func resourceComputeInterconnectUpdate(d *schema.ResourceData, meta interface{}) } func resourceComputeInterconnectDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeInterconnect without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Interconnect %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_interconnect_attachment.go b/google-beta/services/compute/resource_compute_interconnect_attachment.go index a1408d939a2..9fda9e39daf 100644 --- a/google-beta/services/compute/resource_compute_interconnect_attachment.go +++ b/google-beta/services/compute/resource_compute_interconnect_attachment.go @@ -135,6 +135,7 @@ func ResourceComputeInterconnectAttachment() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -588,6 +589,18 @@ Google and the customer, going to and from this network and region.`, Type: schema.TypeString, Computed: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -927,6 +940,19 @@ func resourceComputeInterconnectAttachmentRead(d *schema.ResourceData, meta inte log.Printf("[DEBUG] Finished reading ComputeInterconnectAttachment %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading InterconnectAttachment: %s", err) } @@ -964,6 +990,19 @@ func resourceComputeInterconnectAttachmentRead(d *schema.ResourceData, meta inte } func resourceComputeInterconnectAttachmentUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceComputeInterconnectAttachment().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceComputeInterconnectAttachmentRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1139,6 +1178,13 @@ func resourceComputeInterconnectAttachmentUpdate(d *schema.ResourceData, meta in } func resourceComputeInterconnectAttachmentDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeInterconnectAttachment without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing InterconnectAttachment %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_interconnect_attachment_generated_meta.yaml b/google-beta/services/compute/resource_compute_interconnect_attachment_generated_meta.yaml index 25672428477..b7014f071c6 100644 --- a/google-beta/services/compute/resource_compute_interconnect_attachment_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_interconnect_attachment_generated_meta.yaml @@ -55,3 +55,5 @@ fields: - api_field: type - api_field: vlanTag8021q - api_field: selfLink + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_interconnect_attachment_group.go b/google-beta/services/compute/resource_compute_interconnect_attachment_group.go index a0724643921..216a327c296 100644 --- a/google-beta/services/compute/resource_compute_interconnect_attachment_group.go +++ b/google-beta/services/compute/resource_compute_interconnect_attachment_group.go @@ -115,6 +115,7 @@ func ResourceComputeInterconnectAttachmentGroup() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -399,6 +400,18 @@ Interconnect.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -555,6 +568,19 @@ func resourceComputeInterconnectAttachmentGroupRead(d *schema.ResourceData, meta log.Printf("[DEBUG] Finished reading ComputeInterconnectAttachmentGroup %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading InterconnectAttachmentGroup: %s", err) } @@ -586,6 +612,19 @@ func resourceComputeInterconnectAttachmentGroupRead(d *schema.ResourceData, meta } func resourceComputeInterconnectAttachmentGroupUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceComputeInterconnectAttachmentGroup().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceComputeInterconnectAttachmentGroupRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -683,6 +722,13 @@ func resourceComputeInterconnectAttachmentGroupUpdate(d *schema.ResourceData, me } func resourceComputeInterconnectAttachmentGroupDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeInterconnectAttachmentGroup without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing InterconnectAttachmentGroup %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_interconnect_attachment_group_generated_meta.yaml b/google-beta/services/compute/resource_compute_interconnect_attachment_group_generated_meta.yaml index 43c3884cea6..8c058bde30b 100644 --- a/google-beta/services/compute/resource_compute_interconnect_attachment_group_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_interconnect_attachment_group_generated_meta.yaml @@ -30,3 +30,5 @@ fields: - api_field: logicalStructure.regions.metros.metro - api_field: logicalStructure.regions.region - api_field: name + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_interconnect_generated_meta.yaml b/google-beta/services/compute/resource_compute_interconnect_generated_meta.yaml index 754b3b11739..8fb699a0b7a 100644 --- a/google-beta/services/compute/resource_compute_interconnect_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_interconnect_generated_meta.yaml @@ -64,3 +64,5 @@ fields: - field: terraform_labels provider_only: true - api_field: wireGroups + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_interconnect_group.go b/google-beta/services/compute/resource_compute_interconnect_group.go index dabf84415c5..cf57fbb7d3f 100644 --- a/google-beta/services/compute/resource_compute_interconnect_group.go +++ b/google-beta/services/compute/resource_compute_interconnect_group.go @@ -115,6 +115,7 @@ func ResourceComputeInterconnectGroup() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -371,6 +372,18 @@ Interconnects underneath this.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -521,6 +534,19 @@ func resourceComputeInterconnectGroupRead(d *schema.ResourceData, meta interface log.Printf("[DEBUG] Finished reading ComputeInterconnectGroup %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading InterconnectGroup: %s", err) } @@ -552,6 +578,19 @@ func resourceComputeInterconnectGroupRead(d *schema.ResourceData, meta interface } func resourceComputeInterconnectGroupUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceComputeInterconnectGroup().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceComputeInterconnectGroupRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -643,6 +682,13 @@ func resourceComputeInterconnectGroupUpdate(d *schema.ResourceData, meta interfa } func resourceComputeInterconnectGroupDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeInterconnectGroup without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing InterconnectGroup %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_interconnect_group_generated_meta.yaml b/google-beta/services/compute/resource_compute_interconnect_group_generated_meta.yaml index 9d0fefc1ae7..b7acc66c07b 100644 --- a/google-beta/services/compute/resource_compute_interconnect_group_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_interconnect_group_generated_meta.yaml @@ -27,3 +27,5 @@ fields: - api_field: physicalStructure.metros.facilities.zones.interconnects - api_field: physicalStructure.metros.facilities.zones.zone - api_field: physicalStructure.metros.metro + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_machine_image.go b/google-beta/services/compute/resource_compute_machine_image.go index f059671c9a2..ca7ffa58895 100644 --- a/google-beta/services/compute/resource_compute_machine_image.go +++ b/google-beta/services/compute/resource_compute_machine_image.go @@ -100,6 +100,7 @@ func ResourceComputeMachineImage() *schema.Resource { return &schema.Resource{ Create: resourceComputeMachineImageCreate, Read: resourceComputeMachineImageRead, + Update: resourceComputeMachineImageUpdate, Delete: resourceComputeMachineImageDelete, Importer: &schema.ResourceImporter{ @@ -113,6 +114,7 @@ func ResourceComputeMachineImage() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -241,6 +243,18 @@ and values are in the format tagValues/456.`, Type: schema.TypeString, Computed: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -403,6 +417,19 @@ func resourceComputeMachineImageRead(d *schema.ResourceData, meta interface{}) e log.Printf("[DEBUG] Finished reading ComputeMachineImage %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading MachineImage: %s", err) } @@ -433,7 +460,19 @@ func resourceComputeMachineImageRead(d *schema.ResourceData, meta interface{}) e return nil } +func resourceComputeMachineImageUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceComputeMachineImageRead(d, meta) +} + func resourceComputeMachineImageDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeMachineImage without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing MachineImage %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_machine_image_generated_meta.yaml b/google-beta/services/compute/resource_compute_machine_image_generated_meta.yaml index 26fbbf1209f..54f847582c4 100644 --- a/google-beta/services/compute/resource_compute_machine_image_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_machine_image_generated_meta.yaml @@ -18,3 +18,5 @@ fields: - api_field: sourceInstance - api_field: storageLocations - api_field: selfLink + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_managed_ssl_certificate.go b/google-beta/services/compute/resource_compute_managed_ssl_certificate.go index d3212de1068..e15e6e3ade6 100644 --- a/google-beta/services/compute/resource_compute_managed_ssl_certificate.go +++ b/google-beta/services/compute/resource_compute_managed_ssl_certificate.go @@ -108,6 +108,7 @@ func ResourceComputeManagedSslCertificate() *schema.Resource { return &schema.Resource{ Create: resourceComputeManagedSslCertificateCreate, Read: resourceComputeManagedSslCertificateRead, + Update: resourceComputeManagedSslCertificateUpdate, Delete: resourceComputeManagedSslCertificateDelete, Importer: &schema.ResourceImporter{ @@ -121,6 +122,7 @@ func ResourceComputeManagedSslCertificate() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -229,6 +231,18 @@ which type this is. Default value: "MANAGED" Possible values: ["MANAGED"]`, Type: schema.TypeString, Computed: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -379,6 +393,19 @@ func resourceComputeManagedSslCertificateRead(d *schema.ResourceData, meta inter log.Printf("[DEBUG] Finished reading ComputeManagedSslCertificate %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading ManagedSslCertificate: %s", err) } @@ -409,7 +436,19 @@ func resourceComputeManagedSslCertificateRead(d *schema.ResourceData, meta inter return nil } +func resourceComputeManagedSslCertificateUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceComputeManagedSslCertificateRead(d, meta) +} + func resourceComputeManagedSslCertificateDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeManagedSslCertificate without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing ManagedSslCertificate %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_managed_ssl_certificate_generated_meta.yaml b/google-beta/services/compute/resource_compute_managed_ssl_certificate_generated_meta.yaml index c8084d2984c..8bae3417d1e 100644 --- a/google-beta/services/compute/resource_compute_managed_ssl_certificate_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_managed_ssl_certificate_generated_meta.yaml @@ -17,3 +17,5 @@ fields: - api_field: subjectAlternativeNames - api_field: type - api_field: selfLink + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_network.go b/google-beta/services/compute/resource_compute_network.go index 7faf353a180..69ecb969eb3 100644 --- a/google-beta/services/compute/resource_compute_network.go +++ b/google-beta/services/compute/resource_compute_network.go @@ -115,6 +115,7 @@ func ResourceComputeNetwork() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -308,6 +309,18 @@ immediately after network creation. Defaults to 'false'.`, Type: schema.TypeString, Computed: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -549,6 +562,18 @@ func resourceComputeNetworkRead(d *schema.ResourceData, meta interface{}) error return fmt.Errorf("Error setting delete_default_routes_on_create: %s", err) } } + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Network: %s", err) } @@ -580,6 +605,19 @@ func resourceComputeNetworkRead(d *schema.ResourceData, meta interface{}) error } func resourceComputeNetworkUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceComputeNetwork().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceComputeNetworkRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -797,6 +835,13 @@ func resourceComputeNetworkUpdate(d *schema.ResourceData, meta interface{}) erro } func resourceComputeNetworkDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeNetwork without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Network %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_network_attachment.go b/google-beta/services/compute/resource_compute_network_attachment.go index c5afcc4c6e7..dd67f0f9560 100644 --- a/google-beta/services/compute/resource_compute_network_attachment.go +++ b/google-beta/services/compute/resource_compute_network_attachment.go @@ -115,6 +115,7 @@ func ResourceComputeNetworkAttachment() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Schema: map[string]*schema.Schema{ @@ -246,6 +247,18 @@ Because it is required that all the subnetworks must be from the same network, i Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -404,6 +417,19 @@ func resourceComputeNetworkAttachmentRead(d *schema.ResourceData, meta interface log.Printf("[DEBUG] Finished reading ComputeNetworkAttachment %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading NetworkAttachment: %s", err) } @@ -417,6 +443,19 @@ func resourceComputeNetworkAttachmentRead(d *schema.ResourceData, meta interface } func resourceComputeNetworkAttachmentUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceComputeNetworkAttachment().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceComputeNetworkAttachmentRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -505,6 +544,13 @@ func resourceComputeNetworkAttachmentUpdate(d *schema.ResourceData, meta interfa } func resourceComputeNetworkAttachmentDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeNetworkAttachment without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing NetworkAttachment %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_network_attachment_generated_meta.yaml b/google-beta/services/compute/resource_compute_network_attachment_generated_meta.yaml index 970d757fd45..ea5ee9dd526 100644 --- a/google-beta/services/compute/resource_compute_network_attachment_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_network_attachment_generated_meta.yaml @@ -26,3 +26,5 @@ fields: - api_field: selfLink - api_field: selfLinkWithId - api_field: subnetworks + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_network_edge_security_service.go b/google-beta/services/compute/resource_compute_network_edge_security_service.go index fd9223b2494..8e9a3a3b51b 100644 --- a/google-beta/services/compute/resource_compute_network_edge_security_service.go +++ b/google-beta/services/compute/resource_compute_network_edge_security_service.go @@ -115,6 +115,7 @@ func ResourceComputeNetworkEdgeSecurityService() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -196,6 +197,18 @@ An up-to-date fingerprint must be provided in order to update the NetworkEdgeSec Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -351,6 +364,19 @@ func resourceComputeNetworkEdgeSecurityServiceRead(d *schema.ResourceData, meta log.Printf("[DEBUG] Finished reading ComputeNetworkEdgeSecurityService %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading NetworkEdgeSecurityService: %s", err) } @@ -388,6 +414,19 @@ func resourceComputeNetworkEdgeSecurityServiceRead(d *schema.ResourceData, meta } func resourceComputeNetworkEdgeSecurityServiceUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceComputeNetworkEdgeSecurityService().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceComputeNetworkEdgeSecurityServiceRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -506,6 +545,13 @@ func resourceComputeNetworkEdgeSecurityServiceUpdate(d *schema.ResourceData, met } func resourceComputeNetworkEdgeSecurityServiceDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeNetworkEdgeSecurityService without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing NetworkEdgeSecurityService %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_network_edge_security_service_generated_meta.yaml b/google-beta/services/compute/resource_compute_network_edge_security_service_generated_meta.yaml index f3114c052e5..fda9022c53e 100644 --- a/google-beta/services/compute/resource_compute_network_edge_security_service_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_network_edge_security_service_generated_meta.yaml @@ -19,3 +19,5 @@ fields: field: self_link_with_service_id - api_field: id field: service_id + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_network_endpoint.go b/google-beta/services/compute/resource_compute_network_endpoint.go index 712f59165d4..614835d4517 100644 --- a/google-beta/services/compute/resource_compute_network_endpoint.go +++ b/google-beta/services/compute/resource_compute_network_endpoint.go @@ -100,6 +100,7 @@ func ResourceComputeNetworkEndpoint() *schema.Resource { return &schema.Resource{ Create: resourceComputeNetworkEndpointCreate, Read: resourceComputeNetworkEndpointRead, + Update: resourceComputeNetworkEndpointUpdate, Delete: resourceComputeNetworkEndpointDelete, Importer: &schema.ResourceImporter{ @@ -114,6 +115,7 @@ func ResourceComputeNetworkEndpoint() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, tpgresource.DefaultProviderZone, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -198,6 +200,18 @@ with the type of 'GCE_VM_IP'`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -399,6 +413,19 @@ func resourceComputeNetworkEndpointRead(d *schema.ResourceData, meta interface{} return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading NetworkEndpoint: %s", err) } @@ -460,7 +487,19 @@ func resourceComputeNetworkEndpointRead(d *schema.ResourceData, meta interface{} return nil } +func resourceComputeNetworkEndpointUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceComputeNetworkEndpointRead(d, meta) +} + func resourceComputeNetworkEndpointDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeNetworkEndpoint without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing NetworkEndpoint %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_network_endpoint_generated_meta.yaml b/google-beta/services/compute/resource_compute_network_endpoint_generated_meta.yaml index 69b8e6a3f49..bea09ab0afd 100644 --- a/google-beta/services/compute/resource_compute_network_endpoint_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_network_endpoint_generated_meta.yaml @@ -14,3 +14,5 @@ fields: - api_field: port - field: zone provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_network_endpoint_group.go b/google-beta/services/compute/resource_compute_network_endpoint_group.go index 8ebc74eedf5..39e815f1e18 100644 --- a/google-beta/services/compute/resource_compute_network_endpoint_group.go +++ b/google-beta/services/compute/resource_compute_network_endpoint_group.go @@ -110,6 +110,7 @@ func ResourceComputeNetworkEndpointGroup() *schema.Resource { return &schema.Resource{ Create: resourceComputeNetworkEndpointGroupCreate, Read: resourceComputeNetworkEndpointGroupRead, + Update: resourceComputeNetworkEndpointGroupUpdate, Delete: resourceComputeNetworkEndpointGroupDelete, Importer: &schema.ResourceImporter{ @@ -124,6 +125,7 @@ func ResourceComputeNetworkEndpointGroup() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, tpgresource.DefaultProviderZone, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -236,6 +238,18 @@ Possible values include: GCE_VM_IP, GCE_VM_IP_PORT, NON_GCP_PRIVATE_IP_PORT, INT Type: schema.TypeString, Computed: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -409,6 +423,19 @@ func resourceComputeNetworkEndpointGroupRead(d *schema.ResourceData, meta interf log.Printf("[DEBUG] Finished reading ComputeNetworkEndpointGroup %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading NetworkEndpointGroup: %s", err) } @@ -452,7 +479,19 @@ func resourceComputeNetworkEndpointGroupRead(d *schema.ResourceData, meta interf return nil } +func resourceComputeNetworkEndpointGroupUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceComputeNetworkEndpointGroupRead(d, meta) +} + func resourceComputeNetworkEndpointGroupDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeNetworkEndpointGroup without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing NetworkEndpointGroup %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_network_endpoint_group_generated_meta.yaml b/google-beta/services/compute/resource_compute_network_endpoint_group_generated_meta.yaml index fc4963a9632..fb36a6f29e2 100644 --- a/google-beta/services/compute/resource_compute_network_endpoint_group_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_network_endpoint_group_generated_meta.yaml @@ -18,3 +18,5 @@ fields: - api_field: subnetwork - api_field: zone - api_field: selfLink + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_network_endpoints.go b/google-beta/services/compute/resource_compute_network_endpoints.go index d37fbabedaa..d1b57244b8e 100644 --- a/google-beta/services/compute/resource_compute_network_endpoints.go +++ b/google-beta/services/compute/resource_compute_network_endpoints.go @@ -226,6 +226,7 @@ func ResourceComputeNetworkEndpoints() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, tpgresource.DefaultProviderZone, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -280,6 +281,18 @@ additional information depending on the NEG type.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -482,6 +495,19 @@ func resourceComputeNetworkEndpointsRead(d *schema.ResourceData, meta interface{ return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading NetworkEndpoints: %s", err) } @@ -526,6 +552,19 @@ func resourceComputeNetworkEndpointsRead(d *schema.ResourceData, meta interface{ } func resourceComputeNetworkEndpointsUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceComputeNetworkEndpoints().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceComputeNetworkEndpointsRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -687,6 +726,13 @@ func resourceComputeNetworkEndpointsUpdate(d *schema.ResourceData, meta interfac } func resourceComputeNetworkEndpointsDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeNetworkEndpoints without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing NetworkEndpoints %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_network_endpoints_generated_meta.yaml b/google-beta/services/compute/resource_compute_network_endpoints_generated_meta.yaml index b03bb341c13..a9a22ed8ed4 100644 --- a/google-beta/services/compute/resource_compute_network_endpoints_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_network_endpoints_generated_meta.yaml @@ -14,3 +14,5 @@ fields: - api_field: networkEndpoints.port - field: zone provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_network_firewall_policy.go b/google-beta/services/compute/resource_compute_network_firewall_policy.go index 899cd1b6c4c..9dd25fc6587 100644 --- a/google-beta/services/compute/resource_compute_network_firewall_policy.go +++ b/google-beta/services/compute/resource_compute_network_firewall_policy.go @@ -115,6 +115,7 @@ func ResourceComputeNetworkFirewallPolicy() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -194,6 +195,18 @@ Different policy types may support some of the Firewall Rules features. Possible Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -344,6 +357,19 @@ func resourceComputeNetworkFirewallPolicyRead(d *schema.ResourceData, meta inter log.Printf("[DEBUG] Finished reading ComputeNetworkFirewallPolicy %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading NetworkFirewallPolicy: %s", err) } @@ -375,6 +401,19 @@ func resourceComputeNetworkFirewallPolicyRead(d *schema.ResourceData, meta inter } func resourceComputeNetworkFirewallPolicyUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceComputeNetworkFirewallPolicy().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceComputeNetworkFirewallPolicyRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -460,6 +499,13 @@ func resourceComputeNetworkFirewallPolicyUpdate(d *schema.ResourceData, meta int } func resourceComputeNetworkFirewallPolicyDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeNetworkFirewallPolicy without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing NetworkFirewallPolicy %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_network_firewall_policy_association.go b/google-beta/services/compute/resource_compute_network_firewall_policy_association.go index fe2537baadb..e4ca5d42772 100644 --- a/google-beta/services/compute/resource_compute_network_firewall_policy_association.go +++ b/google-beta/services/compute/resource_compute_network_firewall_policy_association.go @@ -100,6 +100,7 @@ func ResourceComputeNetworkFirewallPolicyAssociation() *schema.Resource { return &schema.Resource{ Create: resourceComputeNetworkFirewallPolicyAssociationCreate, Read: resourceComputeNetworkFirewallPolicyAssociationRead, + Update: resourceComputeNetworkFirewallPolicyAssociationUpdate, Delete: resourceComputeNetworkFirewallPolicyAssociationDelete, Importer: &schema.ResourceImporter{ @@ -113,6 +114,7 @@ func ResourceComputeNetworkFirewallPolicyAssociation() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -170,6 +172,18 @@ func ResourceComputeNetworkFirewallPolicyAssociation() *schema.Resource { Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -313,6 +327,19 @@ func resourceComputeNetworkFirewallPolicyAssociationRead(d *schema.ResourceData, log.Printf("[DEBUG] Finished reading ComputeNetworkFirewallPolicyAssociation %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading NetworkFirewallPolicyAssociation: %s", err) } @@ -349,7 +376,19 @@ func resourceComputeNetworkFirewallPolicyAssociationRead(d *schema.ResourceData, return nil } +func resourceComputeNetworkFirewallPolicyAssociationUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceComputeNetworkFirewallPolicyAssociationRead(d, meta) +} + func resourceComputeNetworkFirewallPolicyAssociationDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeNetworkFirewallPolicyAssociation without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing NetworkFirewallPolicyAssociation %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_network_firewall_policy_association_generated_meta.yaml b/google-beta/services/compute/resource_compute_network_firewall_policy_association_generated_meta.yaml index 9b6097f6c3d..9a15ebd879b 100644 --- a/google-beta/services/compute/resource_compute_network_firewall_policy_association_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_network_firewall_policy_association_generated_meta.yaml @@ -15,3 +15,5 @@ fields: field: name - api_field: associations.shortName field: short_name + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_network_firewall_policy_generated_meta.yaml b/google-beta/services/compute/resource_compute_network_firewall_policy_generated_meta.yaml index dc3b5e38f29..b958066e1ef 100644 --- a/google-beta/services/compute/resource_compute_network_firewall_policy_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_network_firewall_policy_generated_meta.yaml @@ -17,3 +17,5 @@ fields: - api_field: ruleTupleCount - api_field: selfLink - api_field: selfLinkWithId + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_network_firewall_policy_packet_mirroring_rule.go b/google-beta/services/compute/resource_compute_network_firewall_policy_packet_mirroring_rule.go index 778c0b4b38f..4df9f818f93 100644 --- a/google-beta/services/compute/resource_compute_network_firewall_policy_packet_mirroring_rule.go +++ b/google-beta/services/compute/resource_compute_network_firewall_policy_packet_mirroring_rule.go @@ -115,6 +115,7 @@ func ResourceComputeNetworkFirewallPolicyPacketMirroringRule() *schema.Resource CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -290,6 +291,18 @@ Can be set only if action = 'mirror' and cannot be set for other actions.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -482,6 +495,19 @@ func resourceComputeNetworkFirewallPolicyPacketMirroringRuleRead(d *schema.Resou log.Printf("[DEBUG] Finished reading ComputeNetworkFirewallPolicyPacketMirroringRule %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading NetworkFirewallPolicyPacketMirroringRule: %s", err) } @@ -519,6 +545,19 @@ func resourceComputeNetworkFirewallPolicyPacketMirroringRuleRead(d *schema.Resou } func resourceComputeNetworkFirewallPolicyPacketMirroringRuleUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceComputeNetworkFirewallPolicyPacketMirroringRule().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceComputeNetworkFirewallPolicyPacketMirroringRuleRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -658,6 +697,13 @@ func resourceComputeNetworkFirewallPolicyPacketMirroringRuleUpdate(d *schema.Res } func resourceComputeNetworkFirewallPolicyPacketMirroringRuleDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeNetworkFirewallPolicyPacketMirroringRule without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing NetworkFirewallPolicyPacketMirroringRule %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_network_firewall_policy_packet_mirroring_rule_generated_meta.yaml b/google-beta/services/compute/resource_compute_network_firewall_policy_packet_mirroring_rule_generated_meta.yaml index 09fd22c3d57..aa71aa44243 100644 --- a/google-beta/services/compute/resource_compute_network_firewall_policy_packet_mirroring_rule_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_network_firewall_policy_packet_mirroring_rule_generated_meta.yaml @@ -43,3 +43,5 @@ fields: field: target_secure_tags.state - api_field: packetMirroringRules.tlsInspect field: tls_inspect + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_network_firewall_policy_rule.go b/google-beta/services/compute/resource_compute_network_firewall_policy_rule.go index d021411c4e3..b98c38a817f 100644 --- a/google-beta/services/compute/resource_compute_network_firewall_policy_rule.go +++ b/google-beta/services/compute/resource_compute_network_firewall_policy_rule.go @@ -125,6 +125,7 @@ func ResourceComputeNetworkFirewallPolicyRule() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -441,6 +442,18 @@ Can be set only if action = 'apply_security_profile_group' and cannot be set for Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -645,6 +658,19 @@ func resourceComputeNetworkFirewallPolicyRuleRead(d *schema.ResourceData, meta i log.Printf("[DEBUG] Finished reading ComputeNetworkFirewallPolicyRule %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading NetworkFirewallPolicyRule: %s", err) } @@ -682,6 +708,19 @@ func resourceComputeNetworkFirewallPolicyRuleRead(d *schema.ResourceData, meta i } func resourceComputeNetworkFirewallPolicyRuleUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceComputeNetworkFirewallPolicyRule().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceComputeNetworkFirewallPolicyRuleRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -838,6 +877,13 @@ func resourceComputeNetworkFirewallPolicyRuleUpdate(d *schema.ResourceData, meta } func resourceComputeNetworkFirewallPolicyRuleDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeNetworkFirewallPolicyRule without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing NetworkFirewallPolicyRule %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_network_firewall_policy_rule_generated_meta.yaml b/google-beta/services/compute/resource_compute_network_firewall_policy_rule_generated_meta.yaml index f1991ed1d68..f399386839f 100644 --- a/google-beta/services/compute/resource_compute_network_firewall_policy_rule_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_network_firewall_policy_rule_generated_meta.yaml @@ -77,3 +77,5 @@ fields: field: target_service_accounts - api_field: rules.tlsInspect field: tls_inspect + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_network_firewall_policy_with_rules.go b/google-beta/services/compute/resource_compute_network_firewall_policy_with_rules.go index 6dc36806505..89278c87906 100644 --- a/google-beta/services/compute/resource_compute_network_firewall_policy_with_rules.go +++ b/google-beta/services/compute/resource_compute_network_firewall_policy_with_rules.go @@ -169,6 +169,7 @@ func ResourceComputeNetworkFirewallPolicyWithRules() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -811,6 +812,18 @@ It can be set only if action = 'apply_security_profile_group' and cannot be set Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -1016,6 +1029,19 @@ func resourceComputeNetworkFirewallPolicyWithRulesRead(d *schema.ResourceData, m return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading NetworkFirewallPolicyWithRules: %s", err) } @@ -1047,6 +1073,19 @@ func resourceComputeNetworkFirewallPolicyWithRulesRead(d *schema.ResourceData, m } func resourceComputeNetworkFirewallPolicyWithRulesUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceComputeNetworkFirewallPolicyWithRules().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceComputeNetworkFirewallPolicyWithRulesRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1143,6 +1182,13 @@ func resourceComputeNetworkFirewallPolicyWithRulesUpdate(d *schema.ResourceData, } func resourceComputeNetworkFirewallPolicyWithRulesDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeNetworkFirewallPolicyWithRules without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing NetworkFirewallPolicyWithRules %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_network_firewall_policy_with_rules_generated_meta.yaml b/google-beta/services/compute/resource_compute_network_firewall_policy_with_rules_generated_meta.yaml index b5488faecc6..18aa85cadae 100644 --- a/google-beta/services/compute/resource_compute_network_firewall_policy_with_rules_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_network_firewall_policy_with_rules_generated_meta.yaml @@ -107,3 +107,5 @@ fields: - api_field: ruleTupleCount - api_field: selfLink - api_field: selfLinkWithId + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_network_generated_meta.yaml b/google-beta/services/compute/resource_compute_network_generated_meta.yaml index 68e25ad8ef9..541ec415985 100644 --- a/google-beta/services/compute/resource_compute_network_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_network_generated_meta.yaml @@ -34,3 +34,5 @@ fields: - api_field: routingConfig.routingMode field: routing_mode - api_field: selfLink + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_network_peering.go b/google-beta/services/compute/resource_compute_network_peering.go index eed7143b186..50e101b2d6a 100644 --- a/google-beta/services/compute/resource_compute_network_peering.go +++ b/google-beta/services/compute/resource_compute_network_peering.go @@ -24,6 +24,7 @@ import ( "strings" "time" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "google.golang.org/api/googleapi" @@ -53,6 +54,10 @@ func ResourceComputeNetworkPeering() *schema.Resource { Delete: schema.DefaultTimeout(4 * time.Minute), }, + CustomizeDiff: customdiff.All( + tpgresource.DefaultProviderDeletionPolicy("DELETE"), + ), + Schema: map[string]*schema.Schema{ "name": { Type: schema.TypeString, @@ -134,6 +139,9 @@ func ResourceComputeNetworkPeering() *schema.Resource { Description: `The update strategy determines the semantics for updates and deletes to the peering connection configuration. The default value is INDEPENDENT. Possible values: ["INDEPENDENT", "CONSENSUS"]`, Default: "INDEPENDENT", }, + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end }, UseJSONNumber: true, } @@ -238,10 +246,19 @@ func resourceComputeNetworkPeeringRead(d *schema.ResourceData, meta interface{}) return fmt.Errorf("Error setting update_strategy: %s", err) } + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + return nil } func resourceComputeNetworkPeeringUpdate(d *schema.ResourceData, meta interface{}) error { + + if tpgresource.DeletionPolicyPreUpdate(d, ResourceComputeNetworkPeering) { + return ResourceComputeNetworkPeering().Read(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -282,6 +299,13 @@ func resourceComputeNetworkPeeringUpdate(d *schema.ResourceData, meta interface{ } func resourceComputeNetworkPeeringDelete(d *schema.ResourceData, meta interface{}) error { + + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { + return nil + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_network_peering_meta.yaml b/google-beta/services/compute/resource_compute_network_peering_meta.yaml index b73ad992557..c780a6496b9 100644 --- a/google-beta/services/compute/resource_compute_network_peering_meta.yaml +++ b/google-beta/services/compute/resource_compute_network_peering_meta.yaml @@ -27,3 +27,5 @@ fields: field: 'state_details' - api_field: 'peerings.updateStrategy' field: 'update_strategy' + - field: 'deletion_policy' + provider_only: true diff --git a/google-beta/services/compute/resource_compute_network_peering_routes_config.go b/google-beta/services/compute/resource_compute_network_peering_routes_config.go index 09a34fc57db..064e30ab87b 100644 --- a/google-beta/services/compute/resource_compute_network_peering_routes_config.go +++ b/google-beta/services/compute/resource_compute_network_peering_routes_config.go @@ -406,6 +406,7 @@ func resourceComputeNetworkPeeringRoutesConfigRead(d *schema.ResourceData, meta } func resourceComputeNetworkPeeringRoutesConfigUpdate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_node_group.go b/google-beta/services/compute/resource_compute_node_group.go index 54858842319..8c519b4948a 100644 --- a/google-beta/services/compute/resource_compute_node_group.go +++ b/google-beta/services/compute/resource_compute_node_group.go @@ -119,6 +119,7 @@ func ResourceComputeNodeGroup() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -298,6 +299,18 @@ than or equal to max-nodes. The default value is 0.`, Type: schema.TypeString, Computed: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -495,6 +508,19 @@ func resourceComputeNodeGroupRead(d *schema.ResourceData, meta interface{}) erro log.Printf("[DEBUG] Finished reading ComputeNodeGroup %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading NodeGroup: %s", err) } @@ -532,6 +558,19 @@ func resourceComputeNodeGroupRead(d *schema.ResourceData, meta interface{}) erro } func resourceComputeNodeGroupUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceComputeNodeGroup().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceComputeNodeGroupRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -749,6 +788,13 @@ func resourceComputeNodeGroupUpdate(d *schema.ResourceData, meta interface{}) er } func resourceComputeNodeGroupDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeNodeGroup without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing NodeGroup %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_node_group_generated_meta.yaml b/google-beta/services/compute/resource_compute_node_group_generated_meta.yaml index 800bb72caf2..f052be51fb1 100644 --- a/google-beta/services/compute/resource_compute_node_group_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_node_group_generated_meta.yaml @@ -27,3 +27,5 @@ fields: - api_field: size - api_field: zone - api_field: selfLink + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_node_template.go b/google-beta/services/compute/resource_compute_node_template.go index 13ade0ad7c5..0f045d3807c 100644 --- a/google-beta/services/compute/resource_compute_node_template.go +++ b/google-beta/services/compute/resource_compute_node_template.go @@ -100,6 +100,7 @@ func ResourceComputeNodeTemplate() *schema.Resource { return &schema.Resource{ Create: resourceComputeNodeTemplateCreate, Read: resourceComputeNodeTemplateRead, + Update: resourceComputeNodeTemplateUpdate, Delete: resourceComputeNodeTemplateDelete, Importer: &schema.ResourceImporter{ @@ -113,6 +114,7 @@ func ResourceComputeNodeTemplate() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -318,6 +320,18 @@ nodes will experience outages while maintenance is applied. Possible values: ["R Type: schema.TypeString, Computed: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -509,6 +523,19 @@ func resourceComputeNodeTemplateRead(d *schema.ResourceData, meta interface{}) e log.Printf("[DEBUG] Finished reading ComputeNodeTemplate %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading NodeTemplate: %s", err) } @@ -545,7 +572,19 @@ func resourceComputeNodeTemplateRead(d *schema.ResourceData, meta interface{}) e return nil } +func resourceComputeNodeTemplateUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceComputeNodeTemplateRead(d, meta) +} + func resourceComputeNodeTemplateDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeNodeTemplate without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing NodeTemplate %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_node_template_generated_meta.yaml b/google-beta/services/compute/resource_compute_node_template_generated_meta.yaml index c2a95c71ee5..e9b14813ffe 100644 --- a/google-beta/services/compute/resource_compute_node_template_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_node_template_generated_meta.yaml @@ -24,3 +24,5 @@ fields: - api_field: region - api_field: serverBinding.type - api_field: selfLink + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_organization_security_policy.go b/google-beta/services/compute/resource_compute_organization_security_policy.go index b4e5d601762..e4672af3ca5 100644 --- a/google-beta/services/compute/resource_compute_organization_security_policy.go +++ b/google-beta/services/compute/resource_compute_organization_security_policy.go @@ -216,6 +216,19 @@ updates of this resource.`, Computed: true, Description: `The unique identifier for the resource. This identifier is defined by the server.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -379,6 +392,20 @@ func resourceComputeOrganizationSecurityPolicyRead(d *schema.ResourceData, meta log.Printf("[DEBUG] Finished reading ComputeOrganizationSecurityPolicy %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceComputeOrganizationSecurityPolicyFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -388,6 +415,19 @@ func resourceComputeOrganizationSecurityPolicyRead(d *schema.ResourceData, meta } func resourceComputeOrganizationSecurityPolicyUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceComputeOrganizationSecurityPolicy().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceComputeOrganizationSecurityPolicyRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -460,6 +500,13 @@ func resourceComputeOrganizationSecurityPolicyUpdate(d *schema.ResourceData, met } func resourceComputeOrganizationSecurityPolicyDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeOrganizationSecurityPolicy without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing OrganizationSecurityPolicy %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_organization_security_policy_association.go b/google-beta/services/compute/resource_compute_organization_security_policy_association.go index f0c4c9d406b..7ca9838a480 100644 --- a/google-beta/services/compute/resource_compute_organization_security_policy_association.go +++ b/google-beta/services/compute/resource_compute_organization_security_policy_association.go @@ -100,6 +100,7 @@ func ResourceComputeOrganizationSecurityPolicyAssociation() *schema.Resource { return &schema.Resource{ Create: resourceComputeOrganizationSecurityPolicyAssociationCreate, Read: resourceComputeOrganizationSecurityPolicyAssociationRead, + Update: resourceComputeOrganizationSecurityPolicyAssociationUpdate, Delete: resourceComputeOrganizationSecurityPolicyAssociationDelete, Importer: &schema.ResourceImporter{ @@ -172,6 +173,19 @@ func ResourceComputeOrganizationSecurityPolicyAssociation() *schema.Resource { Computed: true, Description: `The display name of the security policy of the association.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -330,6 +344,20 @@ func resourceComputeOrganizationSecurityPolicyAssociationRead(d *schema.Resource log.Printf("[DEBUG] Finished reading ComputeOrganizationSecurityPolicyAssociation %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceComputeOrganizationSecurityPolicyAssociationFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -356,7 +384,19 @@ func resourceComputeOrganizationSecurityPolicyAssociationRead(d *schema.Resource return nil } +func resourceComputeOrganizationSecurityPolicyAssociationUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceComputeOrganizationSecurityPolicyAssociationRead(d, meta) +} + func resourceComputeOrganizationSecurityPolicyAssociationDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeOrganizationSecurityPolicyAssociation without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing OrganizationSecurityPolicyAssociation %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_organization_security_policy_association_generated_meta.yaml b/google-beta/services/compute/resource_compute_organization_security_policy_association_generated_meta.yaml index efbe63ccca1..317b1845b83 100644 --- a/google-beta/services/compute/resource_compute_organization_security_policy_association_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_organization_security_policy_association_generated_meta.yaml @@ -19,3 +19,5 @@ fields: field: name - field: policy_id provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_organization_security_policy_generated_meta.yaml b/google-beta/services/compute/resource_compute_organization_security_policy_generated_meta.yaml index 12b969d0bc6..38d1bc86a13 100644 --- a/google-beta/services/compute/resource_compute_organization_security_policy_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_organization_security_policy_generated_meta.yaml @@ -20,3 +20,5 @@ fields: field: policy_id - api_field: shortName - api_field: type + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_organization_security_policy_rule.go b/google-beta/services/compute/resource_compute_organization_security_policy_rule.go index 081007ccaff..c300ab97a07 100644 --- a/google-beta/services/compute/resource_compute_organization_security_policy_rule.go +++ b/google-beta/services/compute/resource_compute_organization_security_policy_rule.go @@ -496,6 +496,19 @@ instances that are applied with this rule.`, Type: schema.TypeString, }, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -715,6 +728,20 @@ func resourceComputeOrganizationSecurityPolicyRuleRead(d *schema.ResourceData, m return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceComputeOrganizationSecurityPolicyRuleFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -742,6 +769,19 @@ func resourceComputeOrganizationSecurityPolicyRuleRead(d *schema.ResourceData, m } func resourceComputeOrganizationSecurityPolicyRuleUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceComputeOrganizationSecurityPolicyRule().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceComputeOrganizationSecurityPolicyRuleRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -908,6 +948,13 @@ func resourceComputeOrganizationSecurityPolicyRuleUpdate(d *schema.ResourceData, } func resourceComputeOrganizationSecurityPolicyRuleDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeOrganizationSecurityPolicyRule without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing OrganizationSecurityPolicyRule %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_organization_security_policy_rule_generated_meta.yaml b/google-beta/services/compute/resource_compute_organization_security_policy_rule_generated_meta.yaml index 7ca62cf39b1..798a9fca6bf 100644 --- a/google-beta/services/compute/resource_compute_organization_security_policy_rule_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_organization_security_policy_rule_generated_meta.yaml @@ -67,3 +67,5 @@ fields: field: target_resources - api_field: rules.targetServiceAccounts field: target_service_accounts + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_packet_mirroring.go b/google-beta/services/compute/resource_compute_packet_mirroring.go index 6988ebf7b53..90d59c648cb 100644 --- a/google-beta/services/compute/resource_compute_packet_mirroring.go +++ b/google-beta/services/compute/resource_compute_packet_mirroring.go @@ -115,6 +115,7 @@ func ResourceComputePacketMirroring() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -290,6 +291,18 @@ If it is not provided, the provider region is used.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -501,6 +514,19 @@ func resourceComputePacketMirroringRead(d *schema.ResourceData, meta interface{} log.Printf("[DEBUG] Finished reading ComputePacketMirroring %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading PacketMirroring: %s", err) } @@ -538,6 +564,19 @@ func resourceComputePacketMirroringRead(d *schema.ResourceData, meta interface{} } func resourceComputePacketMirroringUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceComputePacketMirroring().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceComputePacketMirroringRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -658,6 +697,13 @@ func resourceComputePacketMirroringUpdate(d *schema.ResourceData, meta interface } func resourceComputePacketMirroringDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputePacketMirroring without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing PacketMirroring %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_packet_mirroring_generated_meta.yaml b/google-beta/services/compute/resource_compute_packet_mirroring_generated_meta.yaml index 5d395fce279..ed5a25ab4c4 100644 --- a/google-beta/services/compute/resource_compute_packet_mirroring_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_packet_mirroring_generated_meta.yaml @@ -20,3 +20,5 @@ fields: - api_field: network.url - api_field: priority - api_field: region + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_per_instance_config.go b/google-beta/services/compute/resource_compute_per_instance_config.go index 8ea3b1ccd9a..ca0e46e3126 100644 --- a/google-beta/services/compute/resource_compute_per_instance_config.go +++ b/google-beta/services/compute/resource_compute_per_instance_config.go @@ -116,6 +116,7 @@ func ResourceComputePerInstanceConfig() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, tpgresource.DefaultProviderZone, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -305,6 +306,18 @@ State will be removed on the next instance recreation or update.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -534,6 +547,18 @@ func resourceComputePerInstanceConfigRead(d *schema.ResourceData, meta interface return fmt.Errorf("Error setting remove_instance_state_on_destroy: %s", err) } } + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading PerInstanceConfig: %s", err) } @@ -584,6 +609,19 @@ func resourceComputePerInstanceConfigRead(d *schema.ResourceData, meta interface } func resourceComputePerInstanceConfigUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceComputePerInstanceConfig().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceComputePerInstanceConfigRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -739,6 +777,13 @@ func resourceComputePerInstanceConfigUpdate(d *schema.ResourceData, meta interfa } func resourceComputePerInstanceConfigDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputePerInstanceConfig without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing PerInstanceConfig %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_per_instance_config_generated_meta.yaml b/google-beta/services/compute/resource_compute_per_instance_config_generated_meta.yaml index 85e4f8c500e..df130e456ae 100644 --- a/google-beta/services/compute/resource_compute_per_instance_config_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_per_instance_config_generated_meta.yaml @@ -43,3 +43,5 @@ fields: provider_only: true - field: zone provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_preview_feature.go b/google-beta/services/compute/resource_compute_preview_feature.go index 33b16ee6396..af40f7622da 100644 --- a/google-beta/services/compute/resource_compute_preview_feature.go +++ b/google-beta/services/compute/resource_compute_preview_feature.go @@ -350,6 +350,7 @@ func resourceComputePreviewFeatureRead(d *schema.ResourceData, meta interface{}) } func resourceComputePreviewFeatureUpdate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_project_cloud_armor_tier.go b/google-beta/services/compute/resource_compute_project_cloud_armor_tier.go index f1e8e00a2c8..58638e0e189 100644 --- a/google-beta/services/compute/resource_compute_project_cloud_armor_tier.go +++ b/google-beta/services/compute/resource_compute_project_cloud_armor_tier.go @@ -115,6 +115,7 @@ func ResourceComputeProjectCloudArmorTier() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -145,6 +146,18 @@ func ResourceComputeProjectCloudArmorTier() *schema.Resource { Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -272,6 +285,19 @@ func resourceComputeProjectCloudArmorTierRead(d *schema.ResourceData, meta inter log.Printf("[DEBUG] Finished reading ComputeProjectCloudArmorTier %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading ProjectCloudArmorTier: %s", err) } @@ -297,6 +323,19 @@ func resourceComputeProjectCloudArmorTierRead(d *schema.ResourceData, meta inter } func resourceComputeProjectCloudArmorTierUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceComputeProjectCloudArmorTier().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceComputeProjectCloudArmorTierRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -371,6 +410,13 @@ func resourceComputeProjectCloudArmorTierUpdate(d *schema.ResourceData, meta int } func resourceComputeProjectCloudArmorTierDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeProjectCloudArmorTier without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing ProjectCloudArmorTier %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_project_cloud_armor_tier_generated_meta.yaml b/google-beta/services/compute/resource_compute_project_cloud_armor_tier_generated_meta.yaml index bd583ea4b5e..cdca1573263 100644 --- a/google-beta/services/compute/resource_compute_project_cloud_armor_tier_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_project_cloud_armor_tier_generated_meta.yaml @@ -8,3 +8,5 @@ api_version: beta api_resource_type_kind: Project fields: - api_field: cloudArmorTier + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_project_default_network_tier.go b/google-beta/services/compute/resource_compute_project_default_network_tier.go index d6a1fb20adf..4ea3f7e71a6 100644 --- a/google-beta/services/compute/resource_compute_project_default_network_tier.go +++ b/google-beta/services/compute/resource_compute_project_default_network_tier.go @@ -48,6 +48,7 @@ func ResourceComputeProjectDefaultNetworkTier() *schema.Resource { }, CustomizeDiff: customdiff.All( + tpgresource.DefaultProviderDeletionPolicy("DELETE"), tpgresource.DefaultProviderProject, ), @@ -131,7 +132,6 @@ func resourceComputeProjectDefaultNetworkTierRead(d *schema.ResourceData, meta i } func resourceComputeProjectDefaultNetworkTierDelete(d *schema.ResourceData, meta interface{}) error { - log.Printf("[WARNING] Default Network Tier will be only removed from Terraform state, but will be left intact on GCP.") return schema.RemoveFromState(d, meta) diff --git a/google-beta/services/compute/resource_compute_project_metadata.go b/google-beta/services/compute/resource_compute_project_metadata.go index fa50b58eff5..694afe6b0b4 100644 --- a/google-beta/services/compute/resource_compute_project_metadata.go +++ b/google-beta/services/compute/resource_compute_project_metadata.go @@ -48,6 +48,7 @@ func ResourceComputeProjectMetadata() *schema.Resource { }, CustomizeDiff: customdiff.All( + tpgresource.DefaultProviderDeletionPolicy("DELETE"), tpgresource.DefaultProviderProject, ), @@ -68,12 +69,20 @@ func ResourceComputeProjectMetadata() *schema.Resource { ForceNew: true, Description: `The ID of the project in which the resource belongs. If it is not provided, the provider project is used.`, }, + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end }, UseJSONNumber: true, } } func resourceComputeProjectMetadataCreateOrUpdate(d *schema.ResourceData, meta interface{}) error { + + if tpgresource.DeletionPolicyPreUpdate(d, ResourceComputeProjectMetadata) { + return ResourceComputeProjectMetadata().Read(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -130,10 +139,21 @@ func resourceComputeProjectMetadataRead(d *schema.ResourceData, meta interface{} return fmt.Errorf("Error setting project: %s", err) } + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + return nil } func resourceComputeProjectMetadataDelete(d *schema.ResourceData, meta interface{}) error { + + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { + return nil + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_project_metadata_item.go b/google-beta/services/compute/resource_compute_project_metadata_item.go index b8f65dbca4e..a9f8a87b50a 100644 --- a/google-beta/services/compute/resource_compute_project_metadata_item.go +++ b/google-beta/services/compute/resource_compute_project_metadata_item.go @@ -49,6 +49,7 @@ func ResourceComputeProjectMetadataItem() *schema.Resource { }, CustomizeDiff: customdiff.All( + tpgresource.DefaultProviderDeletionPolicy("DELETE"), tpgresource.DefaultProviderProject, ), @@ -71,6 +72,9 @@ func ResourceComputeProjectMetadataItem() *schema.Resource { ForceNew: true, Description: `The ID of the project in which the resource belongs. If it is not provided, the provider project is used.`, }, + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end }, Timeouts: &schema.ResourceTimeout{ @@ -142,10 +146,19 @@ func resourceComputeProjectMetadataItemRead(d *schema.ResourceData, meta interfa return fmt.Errorf("Error setting value: %s", err) } + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + return nil } func resourceComputeProjectMetadataItemUpdate(d *schema.ResourceData, meta interface{}) error { + + if tpgresource.DeletionPolicyPreUpdate(d, ResourceComputeProjectMetadataItem) { + return ResourceComputeProjectMetadataItem().Read(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -170,6 +183,13 @@ func resourceComputeProjectMetadataItemUpdate(d *schema.ResourceData, meta inter } func resourceComputeProjectMetadataItemDelete(d *schema.ResourceData, meta interface{}) error { + + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { + return nil + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_project_metadata_item_meta.yaml b/google-beta/services/compute/resource_compute_project_metadata_item_meta.yaml index 941f4c16323..056b101dd33 100644 --- a/google-beta/services/compute/resource_compute_project_metadata_item_meta.yaml +++ b/google-beta/services/compute/resource_compute_project_metadata_item_meta.yaml @@ -11,3 +11,5 @@ fields: - field: 'project' - api_field: 'commonInstanceMetadata.items' field: 'value' + - field: 'deletion_policy' + provider_only: true diff --git a/google-beta/services/compute/resource_compute_project_metadata_meta.yaml b/google-beta/services/compute/resource_compute_project_metadata_meta.yaml index 22d8a0852c4..7634939508d 100644 --- a/google-beta/services/compute/resource_compute_project_metadata_meta.yaml +++ b/google-beta/services/compute/resource_compute_project_metadata_meta.yaml @@ -9,3 +9,5 @@ fields: - api_field: 'commonInstanceMetadata.items' field: 'metadata' - field: 'project' + - field: 'deletion_policy' + provider_only: true diff --git a/google-beta/services/compute/resource_compute_public_advertised_prefix.go b/google-beta/services/compute/resource_compute_public_advertised_prefix.go index c92fb89119e..aaaf545a89c 100644 --- a/google-beta/services/compute/resource_compute_public_advertised_prefix.go +++ b/google-beta/services/compute/resource_compute_public_advertised_prefix.go @@ -100,6 +100,7 @@ func ResourceComputePublicAdvertisedPrefix() *schema.Resource { return &schema.Resource{ Create: resourceComputePublicAdvertisedPrefixCreate, Read: resourceComputePublicAdvertisedPrefixRead, + Update: resourceComputePublicAdvertisedPrefixUpdate, Delete: resourceComputePublicAdvertisedPrefixDelete, Importer: &schema.ResourceImporter{ @@ -113,6 +114,7 @@ func ResourceComputePublicAdvertisedPrefix() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -205,6 +207,18 @@ will take ~4 weeks. Possible values: ["GLOBAL", "REGIONAL"]`, Type: schema.TypeString, Computed: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -367,6 +381,19 @@ func resourceComputePublicAdvertisedPrefixRead(d *schema.ResourceData, meta inte log.Printf("[DEBUG] Finished reading ComputePublicAdvertisedPrefix %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading PublicAdvertisedPrefix: %s", err) } @@ -397,7 +424,19 @@ func resourceComputePublicAdvertisedPrefixRead(d *schema.ResourceData, meta inte return nil } +func resourceComputePublicAdvertisedPrefixUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceComputePublicAdvertisedPrefixRead(d, meta) +} + func resourceComputePublicAdvertisedPrefixDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputePublicAdvertisedPrefix without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing PublicAdvertisedPrefix %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_public_advertised_prefix_generated_meta.yaml b/google-beta/services/compute/resource_compute_public_advertised_prefix_generated_meta.yaml index 4dfeddb901c..285c7a46aed 100644 --- a/google-beta/services/compute/resource_compute_public_advertised_prefix_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_public_advertised_prefix_generated_meta.yaml @@ -15,3 +15,5 @@ fields: - api_field: pdpScope - api_field: sharedSecret - api_field: selfLink + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_public_delegated_prefix.go b/google-beta/services/compute/resource_compute_public_delegated_prefix.go index b7c93d50844..9da0272bb54 100644 --- a/google-beta/services/compute/resource_compute_public_delegated_prefix.go +++ b/google-beta/services/compute/resource_compute_public_delegated_prefix.go @@ -100,6 +100,7 @@ func ResourceComputePublicDelegatedPrefix() *schema.Resource { return &schema.Resource{ Create: resourceComputePublicDelegatedPrefixCreate, Read: resourceComputePublicDelegatedPrefixRead, + Update: resourceComputePublicDelegatedPrefixUpdate, Delete: resourceComputePublicDelegatedPrefixDelete, Importer: &schema.ResourceImporter{ @@ -113,6 +114,7 @@ func ResourceComputePublicDelegatedPrefix() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -301,6 +303,18 @@ from parent prefix and can be one of following: Type: schema.TypeString, Computed: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -474,6 +488,19 @@ func resourceComputePublicDelegatedPrefixRead(d *schema.ResourceData, meta inter log.Printf("[DEBUG] Finished reading ComputePublicDelegatedPrefix %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading PublicDelegatedPrefix: %s", err) } @@ -510,7 +537,19 @@ func resourceComputePublicDelegatedPrefixRead(d *schema.ResourceData, meta inter return nil } +func resourceComputePublicDelegatedPrefixUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceComputePublicDelegatedPrefixRead(d, meta) +} + func resourceComputePublicDelegatedPrefixDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputePublicDelegatedPrefix without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing PublicDelegatedPrefix %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_public_delegated_prefix_generated_meta.yaml b/google-beta/services/compute/resource_compute_public_delegated_prefix_generated_meta.yaml index 2c2e73518ba..d9e7d253600 100644 --- a/google-beta/services/compute/resource_compute_public_delegated_prefix_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_public_delegated_prefix_generated_meta.yaml @@ -30,3 +30,5 @@ fields: - field: region provider_only: true - api_field: selfLink + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_region_autoscaler.go b/google-beta/services/compute/resource_compute_region_autoscaler.go index 972a3d2bac9..76cdc44c89d 100644 --- a/google-beta/services/compute/resource_compute_region_autoscaler.go +++ b/google-beta/services/compute/resource_compute_region_autoscaler.go @@ -116,6 +116,7 @@ func ResourceComputeRegionAutoscaler() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, tpgresource.DefaultProviderRegion, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -520,6 +521,18 @@ character, which cannot be a dash.`, Type: schema.TypeString, Computed: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -681,6 +694,19 @@ func resourceComputeRegionAutoscalerRead(d *schema.ResourceData, meta interface{ log.Printf("[DEBUG] Finished reading ComputeRegionAutoscaler %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading RegionAutoscaler: %s", err) } @@ -726,6 +752,19 @@ func resourceComputeRegionAutoscalerRead(d *schema.ResourceData, meta interface{ } func resourceComputeRegionAutoscalerUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceComputeRegionAutoscaler().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceComputeRegionAutoscalerRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -834,6 +873,13 @@ func resourceComputeRegionAutoscalerUpdate(d *schema.ResourceData, meta interfac } func resourceComputeRegionAutoscalerDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeRegionAutoscaler without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing RegionAutoscaler %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_region_autoscaler_generated_meta.yaml b/google-beta/services/compute/resource_compute_region_autoscaler_generated_meta.yaml index cf96f1257cc..feaea30b707 100644 --- a/google-beta/services/compute/resource_compute_region_autoscaler_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_region_autoscaler_generated_meta.yaml @@ -57,3 +57,5 @@ fields: - api_field: region - api_field: target - api_field: selfLink + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_region_backend_bucket.go b/google-beta/services/compute/resource_compute_region_backend_bucket.go index c0fe8685521..c33ba50c93e 100644 --- a/google-beta/services/compute/resource_compute_region_backend_bucket.go +++ b/google-beta/services/compute/resource_compute_region_backend_bucket.go @@ -115,6 +115,7 @@ func ResourceComputeRegionBackendBucket() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -201,6 +202,18 @@ This field is required for regional backend buckets. Possible values: ["INTERNAL Type: schema.TypeString, Computed: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -356,6 +369,19 @@ func resourceComputeRegionBackendBucketRead(d *schema.ResourceData, meta interfa log.Printf("[DEBUG] Finished reading ComputeRegionBackendBucket %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading RegionBackendBucket: %s", err) } @@ -393,6 +419,19 @@ func resourceComputeRegionBackendBucketRead(d *schema.ResourceData, meta interfa } func resourceComputeRegionBackendBucketUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceComputeRegionBackendBucket().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceComputeRegionBackendBucketRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -495,6 +534,13 @@ func resourceComputeRegionBackendBucketUpdate(d *schema.ResourceData, meta inter } func resourceComputeRegionBackendBucketDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeRegionBackendBucket without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing RegionBackendBucket %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_region_backend_bucket_generated_meta.yaml b/google-beta/services/compute/resource_compute_region_backend_bucket_generated_meta.yaml index 6d255331912..1a5bf7ea537 100644 --- a/google-beta/services/compute/resource_compute_region_backend_bucket_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_region_backend_bucket_generated_meta.yaml @@ -15,3 +15,5 @@ fields: - field: region provider_only: true - api_field: selfLink + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_region_backend_service.go b/google-beta/services/compute/resource_compute_region_backend_service.go index 422c201b087..4789f33aaef 100644 --- a/google-beta/services/compute/resource_compute_region_backend_service.go +++ b/google-beta/services/compute/resource_compute_region_backend_service.go @@ -207,6 +207,7 @@ func ResourceComputeRegionBackendService() *schema.Resource { CustomizeDiff: customdiff.All( customDiffRegionBackendService, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -1458,6 +1459,18 @@ object. This field is used in optimistic locking.`, Type: schema.TypeString, Computed: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -2054,6 +2067,19 @@ func resourceComputeRegionBackendServiceRead(d *schema.ResourceData, meta interf return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading RegionBackendService: %s", err) } @@ -2091,6 +2117,19 @@ func resourceComputeRegionBackendServiceRead(d *schema.ResourceData, meta interf } func resourceComputeRegionBackendServiceUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceComputeRegionBackendService().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceComputeRegionBackendServiceRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -2421,6 +2460,13 @@ func resourceComputeRegionBackendServiceUpdate(d *schema.ResourceData, meta inte } func resourceComputeRegionBackendServiceDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeRegionBackendService without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing RegionBackendService %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_region_backend_service_generated_meta.yaml b/google-beta/services/compute/resource_compute_region_backend_service_generated_meta.yaml index 91c4fcc6fbc..7ecf85db67f 100644 --- a/google-beta/services/compute/resource_compute_region_backend_service_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_region_backend_service_generated_meta.yaml @@ -144,3 +144,5 @@ fields: - api_field: tlsSettings.subjectAltNames.dnsName - api_field: tlsSettings.subjectAltNames.uniformResourceIdentifier - api_field: selfLink + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_region_composite_health_check.go b/google-beta/services/compute/resource_compute_region_composite_health_check.go index 49c481f26bc..9fd3a07bd92 100644 --- a/google-beta/services/compute/resource_compute_region_composite_health_check.go +++ b/google-beta/services/compute/resource_compute_region_composite_health_check.go @@ -115,6 +115,7 @@ func ResourceComputeRegionCompositeHealthCheck() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -223,6 +224,18 @@ CompositeHealthCheck.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -384,6 +397,19 @@ func resourceComputeRegionCompositeHealthCheckRead(d *schema.ResourceData, meta log.Printf("[DEBUG] Finished reading ComputeRegionCompositeHealthCheck %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading RegionCompositeHealthCheck: %s", err) } @@ -421,6 +447,19 @@ func resourceComputeRegionCompositeHealthCheckRead(d *schema.ResourceData, meta } func resourceComputeRegionCompositeHealthCheckUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceComputeRegionCompositeHealthCheck().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceComputeRegionCompositeHealthCheckRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -549,6 +588,13 @@ func resourceComputeRegionCompositeHealthCheckUpdate(d *schema.ResourceData, met } func resourceComputeRegionCompositeHealthCheckDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeRegionCompositeHealthCheck without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing RegionCompositeHealthCheck %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_region_composite_health_check_generated_meta.yaml b/google-beta/services/compute/resource_compute_region_composite_health_check_generated_meta.yaml index 962334590a3..d593109e012 100644 --- a/google-beta/services/compute/resource_compute_region_composite_health_check_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_region_composite_health_check_generated_meta.yaml @@ -17,3 +17,5 @@ fields: - field: region provider_only: true - api_field: selfLinkWithId + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_region_disk.go b/google-beta/services/compute/resource_compute_region_disk.go index f0398aab2c1..0216eeb6fb6 100644 --- a/google-beta/services/compute/resource_compute_region_disk.go +++ b/google-beta/services/compute/resource_compute_region_disk.go @@ -122,6 +122,7 @@ func ResourceComputeRegionDisk() *schema.Resource { hyperDiskIopsUpdateDiffSuppress, tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -584,6 +585,18 @@ The name of the snapshot by default will be '{{disk-name}}-YYYYMMDD-HHmm'`, Type: schema.TypeString, Computed: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -889,6 +902,18 @@ func resourceComputeRegionDiskRead(d *schema.ResourceData, meta interface{}) err return fmt.Errorf("Error setting create_snapshot_before_destroy: %s", err) } } + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading RegionDisk: %s", err) } @@ -926,6 +951,19 @@ func resourceComputeRegionDiskRead(d *schema.ResourceData, meta interface{}) err } func resourceComputeRegionDiskUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceComputeRegionDisk().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceComputeRegionDiskRead(d, meta) + } + config := meta.(*transport_tpg.Config) // 'config' is provided by the boilerplate. @@ -1110,6 +1148,13 @@ func resourceComputeRegionDiskUpdate(d *schema.ResourceData, meta interface{}) e } func resourceComputeRegionDiskDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeRegionDisk without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing RegionDisk %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_region_disk_generated_meta.yaml b/google-beta/services/compute/resource_compute_region_disk_generated_meta.yaml index bacf21aa3ed..aa9e4c9a1ba 100644 --- a/google-beta/services/compute/resource_compute_region_disk_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_region_disk_generated_meta.yaml @@ -61,3 +61,5 @@ fields: - api_field: type - api_field: users - api_field: selfLink + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_region_disk_resource_policy_attachment.go b/google-beta/services/compute/resource_compute_region_disk_resource_policy_attachment.go index 0526a97ff6e..8cfb21348bb 100644 --- a/google-beta/services/compute/resource_compute_region_disk_resource_policy_attachment.go +++ b/google-beta/services/compute/resource_compute_region_disk_resource_policy_attachment.go @@ -100,6 +100,7 @@ func ResourceComputeRegionDiskResourcePolicyAttachment() *schema.Resource { return &schema.Resource{ Create: resourceComputeRegionDiskResourcePolicyAttachmentCreate, Read: resourceComputeRegionDiskResourcePolicyAttachmentRead, + Update: resourceComputeRegionDiskResourcePolicyAttachmentUpdate, Delete: resourceComputeRegionDiskResourcePolicyAttachmentDelete, Importer: &schema.ResourceImporter{ @@ -113,6 +114,7 @@ func ResourceComputeRegionDiskResourcePolicyAttachment() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -171,6 +173,18 @@ creation. Do not specify the self link.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -342,6 +356,19 @@ func resourceComputeRegionDiskResourcePolicyAttachmentRead(d *schema.ResourceDat return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading RegionDiskResourcePolicyAttachment: %s", err) } @@ -384,7 +411,19 @@ func resourceComputeRegionDiskResourcePolicyAttachmentRead(d *schema.ResourceDat return nil } +func resourceComputeRegionDiskResourcePolicyAttachmentUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceComputeRegionDiskResourcePolicyAttachmentRead(d, meta) +} + func resourceComputeRegionDiskResourcePolicyAttachmentDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeRegionDiskResourcePolicyAttachment without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing RegionDiskResourcePolicyAttachment %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_region_disk_resource_policy_attachment_generated_meta.yaml b/google-beta/services/compute/resource_compute_region_disk_resource_policy_attachment_generated_meta.yaml index a0603b3fe12..905e7fb40e2 100644 --- a/google-beta/services/compute/resource_compute_region_disk_resource_policy_attachment_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_region_disk_resource_policy_attachment_generated_meta.yaml @@ -13,3 +13,5 @@ fields: field: name - field: region provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_region_health_aggregation_policy.go b/google-beta/services/compute/resource_compute_region_health_aggregation_policy.go index 9641d35607e..78beb03a233 100644 --- a/google-beta/services/compute/resource_compute_region_health_aggregation_policy.go +++ b/google-beta/services/compute/resource_compute_region_health_aggregation_policy.go @@ -115,6 +115,7 @@ func ResourceComputeRegionHealthAggregationPolicy() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -240,6 +241,18 @@ RegionHealthAggregationPolicy.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -407,6 +420,19 @@ func resourceComputeRegionHealthAggregationPolicyRead(d *schema.ResourceData, me log.Printf("[DEBUG] Finished reading ComputeRegionHealthAggregationPolicy %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading RegionHealthAggregationPolicy: %s", err) } @@ -444,6 +470,19 @@ func resourceComputeRegionHealthAggregationPolicyRead(d *schema.ResourceData, me } func resourceComputeRegionHealthAggregationPolicyUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceComputeRegionHealthAggregationPolicy().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceComputeRegionHealthAggregationPolicyRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -582,6 +621,13 @@ func resourceComputeRegionHealthAggregationPolicyUpdate(d *schema.ResourceData, } func resourceComputeRegionHealthAggregationPolicyDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeRegionHealthAggregationPolicy without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing RegionHealthAggregationPolicy %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_region_health_aggregation_policy_generated_meta.yaml b/google-beta/services/compute/resource_compute_region_health_aggregation_policy_generated_meta.yaml index 87186e149bc..688e3d80977 100644 --- a/google-beta/services/compute/resource_compute_region_health_aggregation_policy_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_region_health_aggregation_policy_generated_meta.yaml @@ -18,3 +18,5 @@ fields: - field: region provider_only: true - api_field: selfLinkWithId + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_region_health_check.go b/google-beta/services/compute/resource_compute_region_health_check.go index 9035255832d..eb31db86632 100644 --- a/google-beta/services/compute/resource_compute_region_health_check.go +++ b/google-beta/services/compute/resource_compute_region_health_check.go @@ -116,6 +116,7 @@ func ResourceComputeRegionHealthCheck() *schema.Resource { CustomizeDiff: customdiff.All( healthCheckCustomizeDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -731,6 +732,18 @@ consecutive failures. The default value is 2.`, Type: schema.TypeString, Computed: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -957,6 +970,19 @@ func resourceComputeRegionHealthCheckRead(d *schema.ResourceData, meta interface log.Printf("[DEBUG] Finished reading ComputeRegionHealthCheck %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading RegionHealthCheck: %s", err) } @@ -994,6 +1020,19 @@ func resourceComputeRegionHealthCheckRead(d *schema.ResourceData, meta interface } func resourceComputeRegionHealthCheckUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceComputeRegionHealthCheck().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceComputeRegionHealthCheckRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1167,6 +1206,13 @@ func resourceComputeRegionHealthCheckUpdate(d *schema.ResourceData, meta interfa } func resourceComputeRegionHealthCheckDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeRegionHealthCheck without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing RegionHealthCheck %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_region_health_check_generated_meta.yaml b/google-beta/services/compute/resource_compute_region_health_check_generated_meta.yaml index dee71eca0bd..576e1b8071b 100644 --- a/google-beta/services/compute/resource_compute_region_health_check_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_region_health_check_generated_meta.yaml @@ -62,3 +62,5 @@ fields: - api_field: type - api_field: unhealthyThreshold - api_field: selfLink + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_region_health_source.go b/google-beta/services/compute/resource_compute_region_health_source.go index 2a965684893..d9354a31eb2 100644 --- a/google-beta/services/compute/resource_compute_region_health_source.go +++ b/google-beta/services/compute/resource_compute_region_health_source.go @@ -115,6 +115,7 @@ func ResourceComputeRegionHealthSource() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -229,6 +230,18 @@ This field is used in optimistic locking.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -396,6 +409,19 @@ func resourceComputeRegionHealthSourceRead(d *schema.ResourceData, meta interfac log.Printf("[DEBUG] Finished reading ComputeRegionHealthSource %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading RegionHealthSource: %s", err) } @@ -433,6 +459,19 @@ func resourceComputeRegionHealthSourceRead(d *schema.ResourceData, meta interfac } func resourceComputeRegionHealthSourceUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceComputeRegionHealthSource().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceComputeRegionHealthSourceRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -561,6 +600,13 @@ func resourceComputeRegionHealthSourceUpdate(d *schema.ResourceData, meta interf } func resourceComputeRegionHealthSourceDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeRegionHealthSource without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing RegionHealthSource %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_region_health_source_generated_meta.yaml b/google-beta/services/compute/resource_compute_region_health_source_generated_meta.yaml index 724366717eb..4da65f98071 100644 --- a/google-beta/services/compute/resource_compute_region_health_source_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_region_health_source_generated_meta.yaml @@ -18,3 +18,5 @@ fields: - api_field: selfLinkWithId - api_field: sourceType - api_field: sources + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_region_instance_group_manager.go b/google-beta/services/compute/resource_compute_region_instance_group_manager.go index a560285b92c..16669ca9451 100644 --- a/google-beta/services/compute/resource_compute_region_instance_group_manager.go +++ b/google-beta/services/compute/resource_compute_region_instance_group_manager.go @@ -50,6 +50,7 @@ func ResourceComputeRegionInstanceGroupManager() *schema.Resource { }, CustomizeDiff: customdiff.All( + tpgresource.DefaultProviderDeletionPolicy("DELETE"), tpgresource.DefaultProviderProject, tpgresource.DefaultProviderRegion, customdiff.ForceNewIfChange("resource_policies.0.workload_policy", ForceNewResourcePoliciesWorkloadPolicyIfNewIsEmpty), @@ -975,6 +976,9 @@ func ResourceComputeRegionInstanceGroupManager() *schema.Resource { }, }, }, + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end }, UseJSONNumber: true, } @@ -1267,10 +1271,19 @@ func resourceComputeRegionInstanceGroupManagerRead(d *schema.ResourceData, meta } } + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + return nil } func resourceComputeRegionInstanceGroupManagerUpdate(d *schema.ResourceData, meta interface{}) error { + + if tpgresource.DeletionPolicyPreUpdate(d, ResourceComputeRegionInstanceGroupManager) { + return ResourceComputeRegionInstanceGroupManager().Read(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) @@ -1449,6 +1462,13 @@ func resourceComputeRegionInstanceGroupManagerUpdate(d *schema.ResourceData, met } func resourceComputeRegionInstanceGroupManagerDelete(d *schema.ResourceData, meta interface{}) error { + + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { + return nil + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) diff --git a/google-beta/services/compute/resource_compute_region_instance_group_manager_meta.yaml b/google-beta/services/compute/resource_compute_region_instance_group_manager_meta.yaml index 9c763ebf4e5..3508ff9fbf8 100644 --- a/google-beta/services/compute/resource_compute_region_instance_group_manager_meta.yaml +++ b/google-beta/services/compute/resource_compute_region_instance_group_manager_meta.yaml @@ -167,3 +167,5 @@ fields: provider_only: true - field: 'wait_for_instances_status' provider_only: true + - field: 'deletion_policy' + provider_only: true diff --git a/google-beta/services/compute/resource_compute_region_instance_template.go b/google-beta/services/compute/resource_compute_region_instance_template.go index e5491b10ec0..169b7052815 100644 --- a/google-beta/services/compute/resource_compute_region_instance_template.go +++ b/google-beta/services/compute/resource_compute_region_instance_template.go @@ -46,6 +46,7 @@ func ResourceComputeRegionInstanceTemplate() *schema.Resource { }, SchemaVersion: 1, CustomizeDiff: customdiff.All( + tpgresource.DefaultProviderDeletionPolicy("DELETE"), tpgresource.DefaultProviderProject, tpgresource.DefaultProviderRegion, resourceComputeInstanceTemplateSourceImageCustomizeDiff, @@ -1278,6 +1279,9 @@ be from 0 to 999,999,999 inclusive.`, ValidateFunc: validation.StringInSlice([]string{"NONE", "STOP", ""}, false), Description: `Action to be taken when a customer's encryption key is revoked. Supports "STOP" and "NONE", with "NONE" being the default.`, }, + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end }, UseJSONNumber: true, } @@ -1418,7 +1422,7 @@ func resourceComputeRegionInstanceTemplateCreate(d *schema.ResourceData, meta in } func resourceComputeRegionInstanceTemplateUpdate(d *schema.ResourceData, meta interface{}) error { - // Only the field "labels" and "terraform_labels" is mutable + // Only the field "deletion_policy", "labels" and "terraform_labels" is mutable return resourceComputeRegionInstanceTemplateRead(d, meta) } @@ -1660,10 +1664,21 @@ func resourceComputeRegionInstanceTemplateRead(d *schema.ResourceData, meta inte } } + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + return nil } func resourceComputeRegionInstanceTemplateDelete(d *schema.ResourceData, meta interface{}) error { + + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { + return nil + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_region_instance_template_meta.yaml b/google-beta/services/compute/resource_compute_region_instance_template_meta.yaml index 17c65d4e700..db0d0109820 100644 --- a/google-beta/services/compute/resource_compute_region_instance_template_meta.yaml +++ b/google-beta/services/compute/resource_compute_region_instance_template_meta.yaml @@ -248,3 +248,5 @@ fields: api_field: 'properties.tags.fingerprint' - field: 'terraform_labels' provider_only: true + - field: 'deletion_policy' + provider_only: true diff --git a/google-beta/services/compute/resource_compute_region_instant_snapshot.go b/google-beta/services/compute/resource_compute_region_instant_snapshot.go index a85e60c0ec9..bc5860854ac 100644 --- a/google-beta/services/compute/resource_compute_region_instant_snapshot.go +++ b/google-beta/services/compute/resource_compute_region_instant_snapshot.go @@ -116,6 +116,7 @@ func ResourceComputeRegionInstantSnapshot() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -282,6 +283,18 @@ internally during updates.`, Type: schema.TypeString, Computed: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -455,6 +468,19 @@ func resourceComputeRegionInstantSnapshotRead(d *schema.ResourceData, meta inter log.Printf("[DEBUG] Finished reading ComputeRegionInstantSnapshot %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading RegionInstantSnapshot: %s", err) } @@ -492,6 +518,19 @@ func resourceComputeRegionInstantSnapshotRead(d *schema.ResourceData, meta inter } func resourceComputeRegionInstantSnapshotUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceComputeRegionInstantSnapshot().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceComputeRegionInstantSnapshotRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -586,6 +625,13 @@ func resourceComputeRegionInstantSnapshotUpdate(d *schema.ResourceData, meta int } func resourceComputeRegionInstantSnapshotDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeRegionInstantSnapshot without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing RegionInstantSnapshot %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_region_instant_snapshot_generated_meta.yaml b/google-beta/services/compute/resource_compute_region_instant_snapshot_generated_meta.yaml index 56336f0eabb..3caca4afdb0 100644 --- a/google-beta/services/compute/resource_compute_region_instant_snapshot_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_region_instant_snapshot_generated_meta.yaml @@ -29,3 +29,5 @@ fields: - field: terraform_labels provider_only: true - api_field: selfLink + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_region_network_endpoint.go b/google-beta/services/compute/resource_compute_region_network_endpoint.go index 01ee4e17547..176bf1d7a56 100644 --- a/google-beta/services/compute/resource_compute_region_network_endpoint.go +++ b/google-beta/services/compute/resource_compute_region_network_endpoint.go @@ -100,6 +100,7 @@ func ResourceComputeRegionNetworkEndpoint() *schema.Resource { return &schema.Resource{ Create: resourceComputeRegionNetworkEndpointCreate, Read: resourceComputeRegionNetworkEndpointRead, + Update: resourceComputeRegionNetworkEndpointUpdate, Delete: resourceComputeRegionNetworkEndpointDelete, Importer: &schema.ResourceImporter{ @@ -114,6 +115,7 @@ func ResourceComputeRegionNetworkEndpoint() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, tpgresource.DefaultProviderRegion, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -216,6 +218,18 @@ This can only be specified when network_endpoint_type of the NEG is INTERNET_IP_ Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -429,6 +443,19 @@ func resourceComputeRegionNetworkEndpointRead(d *schema.ResourceData, meta inter return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading RegionNetworkEndpoint: %s", err) } @@ -491,7 +518,19 @@ func resourceComputeRegionNetworkEndpointRead(d *schema.ResourceData, meta inter return nil } +func resourceComputeRegionNetworkEndpointUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceComputeRegionNetworkEndpointRead(d, meta) +} + func resourceComputeRegionNetworkEndpointDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeRegionNetworkEndpoint without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing RegionNetworkEndpoint %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_region_network_endpoint_generated_meta.yaml b/google-beta/services/compute/resource_compute_region_network_endpoint_generated_meta.yaml index 6462af0f4b1..a0841a0f78f 100644 --- a/google-beta/services/compute/resource_compute_region_network_endpoint_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_region_network_endpoint_generated_meta.yaml @@ -18,3 +18,5 @@ fields: provider_only: true - field: region_network_endpoint_group provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_region_network_endpoint_group.go b/google-beta/services/compute/resource_compute_region_network_endpoint_group.go index eb2676bc25a..6d38c5d1772 100644 --- a/google-beta/services/compute/resource_compute_region_network_endpoint_group.go +++ b/google-beta/services/compute/resource_compute_region_network_endpoint_group.go @@ -100,6 +100,7 @@ func ResourceComputeRegionNetworkEndpointGroup() *schema.Resource { return &schema.Resource{ Create: resourceComputeRegionNetworkEndpointGroupCreate, Read: resourceComputeRegionNetworkEndpointGroupRead, + Update: resourceComputeRegionNetworkEndpointGroupUpdate, Delete: resourceComputeRegionNetworkEndpointGroupDelete, Importer: &schema.ResourceImporter{ @@ -113,6 +114,7 @@ func ResourceComputeRegionNetworkEndpointGroup() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -404,6 +406,18 @@ Optional URL of the subnetwork to which all network endpoints in the NEG belong. Type: schema.TypeString, Computed: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -607,6 +621,19 @@ func resourceComputeRegionNetworkEndpointGroupRead(d *schema.ResourceData, meta log.Printf("[DEBUG] Finished reading ComputeRegionNetworkEndpointGroup %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading RegionNetworkEndpointGroup: %s", err) } @@ -643,7 +670,19 @@ func resourceComputeRegionNetworkEndpointGroupRead(d *schema.ResourceData, meta return nil } +func resourceComputeRegionNetworkEndpointGroupUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceComputeRegionNetworkEndpointGroupRead(d, meta) +} + func resourceComputeRegionNetworkEndpointGroupDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeRegionNetworkEndpointGroup without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing RegionNetworkEndpointGroup %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_region_network_endpoint_group_generated_meta.yaml b/google-beta/services/compute/resource_compute_region_network_endpoint_group_generated_meta.yaml index 935d26d6817..fc7c48f4547 100644 --- a/google-beta/services/compute/resource_compute_region_network_endpoint_group_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_region_network_endpoint_group_generated_meta.yaml @@ -28,3 +28,5 @@ fields: - api_field: serverlessDeployment.version - api_field: subnetwork - api_field: selfLink + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_region_network_firewall_policy.go b/google-beta/services/compute/resource_compute_region_network_firewall_policy.go index 6116bc0bc8b..1385a916558 100644 --- a/google-beta/services/compute/resource_compute_region_network_firewall_policy.go +++ b/google-beta/services/compute/resource_compute_region_network_firewall_policy.go @@ -115,6 +115,7 @@ func ResourceComputeRegionNetworkFirewallPolicy() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -205,6 +206,18 @@ Different policy types may support some of the Firewall Rules features. Possible Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -360,6 +373,19 @@ func resourceComputeRegionNetworkFirewallPolicyRead(d *schema.ResourceData, meta log.Printf("[DEBUG] Finished reading ComputeRegionNetworkFirewallPolicy %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading RegionNetworkFirewallPolicy: %s", err) } @@ -397,6 +423,19 @@ func resourceComputeRegionNetworkFirewallPolicyRead(d *schema.ResourceData, meta } func resourceComputeRegionNetworkFirewallPolicyUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceComputeRegionNetworkFirewallPolicy().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceComputeRegionNetworkFirewallPolicyRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -487,6 +526,13 @@ func resourceComputeRegionNetworkFirewallPolicyUpdate(d *schema.ResourceData, me } func resourceComputeRegionNetworkFirewallPolicyDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeRegionNetworkFirewallPolicy without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing RegionNetworkFirewallPolicy %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_region_network_firewall_policy_association.go b/google-beta/services/compute/resource_compute_region_network_firewall_policy_association.go index ecfa55a9509..162a353f911 100644 --- a/google-beta/services/compute/resource_compute_region_network_firewall_policy_association.go +++ b/google-beta/services/compute/resource_compute_region_network_firewall_policy_association.go @@ -100,6 +100,7 @@ func ResourceComputeRegionNetworkFirewallPolicyAssociation() *schema.Resource { return &schema.Resource{ Create: resourceComputeRegionNetworkFirewallPolicyAssociationCreate, Read: resourceComputeRegionNetworkFirewallPolicyAssociationRead, + Update: resourceComputeRegionNetworkFirewallPolicyAssociationUpdate, Delete: resourceComputeRegionNetworkFirewallPolicyAssociationDelete, Importer: &schema.ResourceImporter{ @@ -113,6 +114,7 @@ func ResourceComputeRegionNetworkFirewallPolicyAssociation() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -188,6 +190,18 @@ func ResourceComputeRegionNetworkFirewallPolicyAssociation() *schema.Resource { Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -342,6 +356,19 @@ func resourceComputeRegionNetworkFirewallPolicyAssociationRead(d *schema.Resourc log.Printf("[DEBUG] Finished reading ComputeRegionNetworkFirewallPolicyAssociation %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading RegionNetworkFirewallPolicyAssociation: %s", err) } @@ -384,7 +411,19 @@ func resourceComputeRegionNetworkFirewallPolicyAssociationRead(d *schema.Resourc return nil } +func resourceComputeRegionNetworkFirewallPolicyAssociationUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceComputeRegionNetworkFirewallPolicyAssociationRead(d, meta) +} + func resourceComputeRegionNetworkFirewallPolicyAssociationDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeRegionNetworkFirewallPolicyAssociation without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing RegionNetworkFirewallPolicyAssociation %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_region_network_firewall_policy_association_generated_meta.yaml b/google-beta/services/compute/resource_compute_region_network_firewall_policy_association_generated_meta.yaml index 3e911ab2688..25e14749cf2 100644 --- a/google-beta/services/compute/resource_compute_region_network_firewall_policy_association_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_region_network_firewall_policy_association_generated_meta.yaml @@ -19,3 +19,5 @@ fields: provider_only: true - api_field: associations.shortName field: short_name + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_region_network_firewall_policy_generated_meta.yaml b/google-beta/services/compute/resource_compute_region_network_firewall_policy_generated_meta.yaml index 05084e40c3b..36678282819 100644 --- a/google-beta/services/compute/resource_compute_region_network_firewall_policy_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_region_network_firewall_policy_generated_meta.yaml @@ -19,3 +19,5 @@ fields: - api_field: ruleTupleCount - api_field: selfLink - api_field: selfLinkWithId + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_region_network_firewall_policy_rule.go b/google-beta/services/compute/resource_compute_region_network_firewall_policy_rule.go index e5505b17e15..c1f7eb7fa85 100644 --- a/google-beta/services/compute/resource_compute_region_network_firewall_policy_rule.go +++ b/google-beta/services/compute/resource_compute_region_network_firewall_policy_rule.go @@ -116,6 +116,7 @@ func ResourceComputeRegionNetworkFirewallPolicyRule() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderRegion, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -468,6 +469,18 @@ Can be set only if action = 'apply_security_profile_group' and cannot be set for Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -689,6 +702,19 @@ func resourceComputeRegionNetworkFirewallPolicyRuleRead(d *schema.ResourceData, log.Printf("[DEBUG] Finished reading ComputeRegionNetworkFirewallPolicyRule %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading RegionNetworkFirewallPolicyRule: %s", err) } @@ -732,6 +758,19 @@ func resourceComputeRegionNetworkFirewallPolicyRuleRead(d *schema.ResourceData, } func resourceComputeRegionNetworkFirewallPolicyRuleUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceComputeRegionNetworkFirewallPolicyRule().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceComputeRegionNetworkFirewallPolicyRuleRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -905,6 +944,13 @@ func resourceComputeRegionNetworkFirewallPolicyRuleUpdate(d *schema.ResourceData } func resourceComputeRegionNetworkFirewallPolicyRuleDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeRegionNetworkFirewallPolicyRule without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing RegionNetworkFirewallPolicyRule %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_region_network_firewall_policy_rule_generated_meta.yaml b/google-beta/services/compute/resource_compute_region_network_firewall_policy_rule_generated_meta.yaml index 00d50897e0d..cce5995d221 100644 --- a/google-beta/services/compute/resource_compute_region_network_firewall_policy_rule_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_region_network_firewall_policy_rule_generated_meta.yaml @@ -83,3 +83,5 @@ fields: field: target_type - api_field: rules.tlsInspect field: tls_inspect + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_region_network_firewall_policy_with_rules.go b/google-beta/services/compute/resource_compute_region_network_firewall_policy_with_rules.go index 8d5e447e23d..e885016a4ee 100644 --- a/google-beta/services/compute/resource_compute_region_network_firewall_policy_with_rules.go +++ b/google-beta/services/compute/resource_compute_region_network_firewall_policy_with_rules.go @@ -167,6 +167,7 @@ func ResourceComputeRegionNetworkFirewallPolicyWithRules() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -820,6 +821,18 @@ It can be set only if action = 'apply_security_profile_group' and cannot be set Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -1030,6 +1043,19 @@ func resourceComputeRegionNetworkFirewallPolicyWithRulesRead(d *schema.ResourceD return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading RegionNetworkFirewallPolicyWithRules: %s", err) } @@ -1067,6 +1093,19 @@ func resourceComputeRegionNetworkFirewallPolicyWithRulesRead(d *schema.ResourceD } func resourceComputeRegionNetworkFirewallPolicyWithRulesUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceComputeRegionNetworkFirewallPolicyWithRules().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceComputeRegionNetworkFirewallPolicyWithRulesRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1168,6 +1207,13 @@ func resourceComputeRegionNetworkFirewallPolicyWithRulesUpdate(d *schema.Resourc } func resourceComputeRegionNetworkFirewallPolicyWithRulesDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeRegionNetworkFirewallPolicyWithRules without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing RegionNetworkFirewallPolicyWithRules %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_region_network_firewall_policy_with_rules_generated_meta.yaml b/google-beta/services/compute/resource_compute_region_network_firewall_policy_with_rules_generated_meta.yaml index 04518842eeb..ad9f4790996 100644 --- a/google-beta/services/compute/resource_compute_region_network_firewall_policy_with_rules_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_region_network_firewall_policy_with_rules_generated_meta.yaml @@ -109,3 +109,5 @@ fields: - api_field: ruleTupleCount - api_field: selfLink - api_field: selfLinkWithId + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_region_per_instance_config.go b/google-beta/services/compute/resource_compute_region_per_instance_config.go index 91ef7339b8f..c48a9c41166 100644 --- a/google-beta/services/compute/resource_compute_region_per_instance_config.go +++ b/google-beta/services/compute/resource_compute_region_per_instance_config.go @@ -116,6 +116,7 @@ func ResourceComputeRegionPerInstanceConfig() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, tpgresource.DefaultProviderRegion, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -305,6 +306,18 @@ State will be removed on the next instance recreation or update.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -534,6 +547,18 @@ func resourceComputeRegionPerInstanceConfigRead(d *schema.ResourceData, meta int return fmt.Errorf("Error setting remove_instance_state_on_destroy: %s", err) } } + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading RegionPerInstanceConfig: %s", err) } @@ -585,6 +610,19 @@ func resourceComputeRegionPerInstanceConfigRead(d *schema.ResourceData, meta int } func resourceComputeRegionPerInstanceConfigUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceComputeRegionPerInstanceConfig().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceComputeRegionPerInstanceConfigRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -740,6 +778,13 @@ func resourceComputeRegionPerInstanceConfigUpdate(d *schema.ResourceData, meta i } func resourceComputeRegionPerInstanceConfigDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeRegionPerInstanceConfig without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing RegionPerInstanceConfig %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_region_per_instance_config_generated_meta.yaml b/google-beta/services/compute/resource_compute_region_per_instance_config_generated_meta.yaml index 51713049f58..a8bb89337a6 100644 --- a/google-beta/services/compute/resource_compute_region_per_instance_config_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_region_per_instance_config_generated_meta.yaml @@ -43,3 +43,5 @@ fields: provider_only: true - field: remove_instance_state_on_destroy provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_region_resize_request.go b/google-beta/services/compute/resource_compute_region_resize_request.go index 9ceac790b02..fccb2a6ba2f 100644 --- a/google-beta/services/compute/resource_compute_region_resize_request.go +++ b/google-beta/services/compute/resource_compute_region_resize_request.go @@ -100,6 +100,7 @@ func ResourceComputeRegionResizeRequest() *schema.Resource { return &schema.Resource{ Create: resourceComputeRegionResizeRequestCreate, Read: resourceComputeRegionResizeRequestRead, + Update: resourceComputeRegionResizeRequestUpdate, Delete: resourceComputeRegionResizeRequestDelete, Importer: &schema.ResourceImporter{ @@ -113,6 +114,7 @@ func ResourceComputeRegionResizeRequest() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -541,6 +543,18 @@ func ResourceComputeRegionResizeRequest() *schema.Resource { Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -707,6 +721,19 @@ func resourceComputeRegionResizeRequestRead(d *schema.ResourceData, meta interfa log.Printf("[DEBUG] Finished reading ComputeRegionResizeRequest %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading RegionResizeRequest: %s", err) } @@ -749,7 +776,19 @@ func resourceComputeRegionResizeRequestRead(d *schema.ResourceData, meta interfa return nil } +func resourceComputeRegionResizeRequestUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceComputeRegionResizeRequestRead(d, meta) +} + func resourceComputeRegionResizeRequestDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeRegionResizeRequest without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing RegionResizeRequest %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_region_resize_request_generated_meta.yaml b/google-beta/services/compute/resource_compute_region_resize_request_generated_meta.yaml index d8260e620c8..994d4640309 100644 --- a/google-beta/services/compute/resource_compute_region_resize_request_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_region_resize_request_generated_meta.yaml @@ -49,3 +49,5 @@ fields: - api_field: status.lastAttempt.error.errors.errorDetails.quotaInfo.rolloutStatus - api_field: status.lastAttempt.error.errors.location - api_field: status.lastAttempt.error.errors.message + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_region_security_policy.go b/google-beta/services/compute/resource_compute_region_security_policy.go index dc6083d5cc3..1637652fc84 100644 --- a/google-beta/services/compute/resource_compute_region_security_policy.go +++ b/google-beta/services/compute/resource_compute_region_security_policy.go @@ -144,6 +144,7 @@ func ResourceComputeRegionSecurityPolicy() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Schema: map[string]*schema.Schema{ @@ -788,6 +789,18 @@ updates of this resource.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -952,6 +965,19 @@ func resourceComputeRegionSecurityPolicyRead(d *schema.ResourceData, meta interf log.Printf("[DEBUG] Finished reading ComputeRegionSecurityPolicy %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading RegionSecurityPolicy: %s", err) } @@ -965,6 +991,19 @@ func resourceComputeRegionSecurityPolicyRead(d *schema.ResourceData, meta interf } func resourceComputeRegionSecurityPolicyUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceComputeRegionSecurityPolicy().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceComputeRegionSecurityPolicyRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1093,6 +1132,13 @@ func resourceComputeRegionSecurityPolicyUpdate(d *schema.ResourceData, meta inte } func resourceComputeRegionSecurityPolicyDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeRegionSecurityPolicy without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing RegionSecurityPolicy %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_region_security_policy_generated_meta.yaml b/google-beta/services/compute/resource_compute_region_security_policy_generated_meta.yaml index a543c8fc2ec..c87ca823c1f 100644 --- a/google-beta/services/compute/resource_compute_region_security_policy_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_region_security_policy_generated_meta.yaml @@ -75,3 +75,5 @@ fields: - api_field: userDefinedFields.name - api_field: userDefinedFields.offset - api_field: userDefinedFields.size + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_region_security_policy_rule.go b/google-beta/services/compute/resource_compute_region_security_policy_rule.go index 6b149d4cb32..5dbca735f12 100644 --- a/google-beta/services/compute/resource_compute_region_security_policy_rule.go +++ b/google-beta/services/compute/resource_compute_region_security_policy_rule.go @@ -115,6 +115,7 @@ func ResourceComputeRegionSecurityPolicyRule() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Schema: map[string]*schema.Schema{ @@ -588,6 +589,18 @@ Valid options are deny(STATUS), where valid values for STATUS are 403, 404, 429, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -757,6 +770,19 @@ func resourceComputeRegionSecurityPolicyRuleRead(d *schema.ResourceData, meta in log.Printf("[DEBUG] Finished reading ComputeRegionSecurityPolicyRule %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading RegionSecurityPolicyRule: %s", err) } @@ -770,6 +796,19 @@ func resourceComputeRegionSecurityPolicyRuleRead(d *schema.ResourceData, meta in } func resourceComputeRegionSecurityPolicyRuleUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceComputeRegionSecurityPolicyRule().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceComputeRegionSecurityPolicyRuleRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -933,6 +972,13 @@ func resourceComputeRegionSecurityPolicyRuleUpdate(d *schema.ResourceData, meta } func resourceComputeRegionSecurityPolicyRuleDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeRegionSecurityPolicyRule without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing RegionSecurityPolicyRule %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_region_security_policy_rule_generated_meta.yaml b/google-beta/services/compute/resource_compute_region_security_policy_rule_generated_meta.yaml index 8461160dcb0..4f734b58e87 100644 --- a/google-beta/services/compute/resource_compute_region_security_policy_rule_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_region_security_policy_rule_generated_meta.yaml @@ -85,3 +85,5 @@ fields: provider_only: true - field: security_policy provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_region_ssl_certificate.go b/google-beta/services/compute/resource_compute_region_ssl_certificate.go index 8f9c4a8b18d..671d354d29c 100644 --- a/google-beta/services/compute/resource_compute_region_ssl_certificate.go +++ b/google-beta/services/compute/resource_compute_region_ssl_certificate.go @@ -111,6 +111,7 @@ func ResourceComputeRegionSslCertificate() *schema.Resource { return &schema.Resource{ Create: resourceComputeRegionSslCertificateCreate, Read: resourceComputeRegionSslCertificateRead, + Update: resourceComputeRegionSslCertificateUpdate, Delete: resourceComputeRegionSslCertificateDelete, Importer: &schema.ResourceImporter{ @@ -124,6 +125,7 @@ func ResourceComputeRegionSslCertificate() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -257,6 +259,18 @@ If it is not provided, the provider region is used.`, Type: schema.TypeString, Computed: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -424,6 +438,19 @@ func resourceComputeRegionSslCertificateRead(d *schema.ResourceData, meta interf log.Printf("[DEBUG] Finished reading ComputeRegionSslCertificate %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading RegionSslCertificate: %s", err) } @@ -460,7 +487,19 @@ func resourceComputeRegionSslCertificateRead(d *schema.ResourceData, meta interf return nil } +func resourceComputeRegionSslCertificateUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceComputeRegionSslCertificateRead(d, meta) +} + func resourceComputeRegionSslCertificateDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeRegionSslCertificate without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing RegionSslCertificate %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_region_ssl_certificate_generated_meta.yaml b/google-beta/services/compute/resource_compute_region_ssl_certificate_generated_meta.yaml index 5c0898f94be..90cd2aad02a 100644 --- a/google-beta/services/compute/resource_compute_region_ssl_certificate_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_region_ssl_certificate_generated_meta.yaml @@ -21,3 +21,5 @@ fields: provider_only: true - api_field: region - api_field: selfLink + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_region_ssl_policy.go b/google-beta/services/compute/resource_compute_region_ssl_policy.go index e8ad96095c3..c4c04095c72 100644 --- a/google-beta/services/compute/resource_compute_region_ssl_policy.go +++ b/google-beta/services/compute/resource_compute_region_ssl_policy.go @@ -133,6 +133,7 @@ func ResourceComputeRegionSslPolicy() *schema.Resource { CustomizeDiff: customdiff.All( regionSslPolicyCustomizeDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -256,6 +257,18 @@ object. This field is used in optimistic locking.`, Type: schema.TypeString, Computed: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -429,6 +442,19 @@ func resourceComputeRegionSslPolicyRead(d *schema.ResourceData, meta interface{} log.Printf("[DEBUG] Finished reading ComputeRegionSslPolicy %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading RegionSslPolicy: %s", err) } @@ -466,6 +492,19 @@ func resourceComputeRegionSslPolicyRead(d *schema.ResourceData, meta interface{} } func resourceComputeRegionSslPolicyUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceComputeRegionSslPolicy().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceComputeRegionSslPolicyRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -568,6 +607,13 @@ func resourceComputeRegionSslPolicyUpdate(d *schema.ResourceData, meta interface } func resourceComputeRegionSslPolicyDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeRegionSslPolicy without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing RegionSslPolicy %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_region_ssl_policy_generated_meta.yaml b/google-beta/services/compute/resource_compute_region_ssl_policy_generated_meta.yaml index 0279ff45552..ecf85ac9759 100644 --- a/google-beta/services/compute/resource_compute_region_ssl_policy_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_region_ssl_policy_generated_meta.yaml @@ -17,3 +17,5 @@ fields: - api_field: profile - api_field: region - api_field: selfLink + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_region_target_http_proxy.go b/google-beta/services/compute/resource_compute_region_target_http_proxy.go index 9e5659d7b95..a4debd1bdae 100644 --- a/google-beta/services/compute/resource_compute_region_target_http_proxy.go +++ b/google-beta/services/compute/resource_compute_region_target_http_proxy.go @@ -115,6 +115,7 @@ func ResourceComputeRegionTargetHttpProxy() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -205,6 +206,18 @@ If it is not provided, the provider region is used.`, Type: schema.TypeString, Computed: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -366,6 +379,19 @@ func resourceComputeRegionTargetHttpProxyRead(d *schema.ResourceData, meta inter log.Printf("[DEBUG] Finished reading ComputeRegionTargetHttpProxy %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading RegionTargetHttpProxy: %s", err) } @@ -403,6 +429,19 @@ func resourceComputeRegionTargetHttpProxyRead(d *schema.ResourceData, meta inter } func resourceComputeRegionTargetHttpProxyUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceComputeRegionTargetHttpProxy().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceComputeRegionTargetHttpProxyRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -491,6 +530,13 @@ func resourceComputeRegionTargetHttpProxyUpdate(d *schema.ResourceData, meta int } func resourceComputeRegionTargetHttpProxyDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeRegionTargetHttpProxy without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing RegionTargetHttpProxy %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_region_target_http_proxy_generated_meta.yaml b/google-beta/services/compute/resource_compute_region_target_http_proxy_generated_meta.yaml index 23d44cb6c0b..ea9ed4b980c 100644 --- a/google-beta/services/compute/resource_compute_region_target_http_proxy_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_region_target_http_proxy_generated_meta.yaml @@ -16,3 +16,5 @@ fields: - api_field: region - api_field: urlMap - api_field: selfLink + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_region_target_https_proxy.go b/google-beta/services/compute/resource_compute_region_target_https_proxy.go index 646ddba363b..059ef05ef18 100644 --- a/google-beta/services/compute/resource_compute_region_target_https_proxy.go +++ b/google-beta/services/compute/resource_compute_region_target_https_proxy.go @@ -115,6 +115,7 @@ func ResourceComputeRegionTargetHttpsProxy() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -256,6 +257,18 @@ resource will not have any SSL policy configured.`, Type: schema.TypeString, Computed: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -458,6 +471,19 @@ func resourceComputeRegionTargetHttpsProxyRead(d *schema.ResourceData, meta inte return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading RegionTargetHttpsProxy: %s", err) } @@ -495,6 +521,19 @@ func resourceComputeRegionTargetHttpsProxyRead(d *schema.ResourceData, meta inte } func resourceComputeRegionTargetHttpsProxyUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceComputeRegionTargetHttpsProxy().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceComputeRegionTargetHttpsProxyRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -790,6 +829,13 @@ func resourceComputeRegionTargetHttpsProxyUpdate(d *schema.ResourceData, meta in } func resourceComputeRegionTargetHttpsProxyDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeRegionTargetHttpsProxy without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing RegionTargetHttpsProxy %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_region_target_https_proxy_generated_meta.yaml b/google-beta/services/compute/resource_compute_region_target_https_proxy_generated_meta.yaml index f3c8452d727..51b27be42d5 100644 --- a/google-beta/services/compute/resource_compute_region_target_https_proxy_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_region_target_https_proxy_generated_meta.yaml @@ -20,3 +20,5 @@ fields: - api_field: sslPolicy - api_field: urlMap - api_field: selfLink + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_region_target_tcp_proxy.go b/google-beta/services/compute/resource_compute_region_target_tcp_proxy.go index 5536342a631..b81ddfd9e5e 100644 --- a/google-beta/services/compute/resource_compute_region_target_tcp_proxy.go +++ b/google-beta/services/compute/resource_compute_region_target_tcp_proxy.go @@ -100,6 +100,7 @@ func ResourceComputeRegionTargetTcpProxy() *schema.Resource { return &schema.Resource{ Create: resourceComputeRegionTargetTcpProxyCreate, Read: resourceComputeRegionTargetTcpProxyRead, + Update: resourceComputeRegionTargetTcpProxyUpdate, Delete: resourceComputeRegionTargetTcpProxyDelete, Importer: &schema.ResourceImporter{ @@ -113,6 +114,7 @@ func ResourceComputeRegionTargetTcpProxy() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -222,6 +224,18 @@ If it is not provided, the provider region is used.`, Type: schema.TypeString, Computed: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -395,6 +409,19 @@ func resourceComputeRegionTargetTcpProxyRead(d *schema.ResourceData, meta interf log.Printf("[DEBUG] Finished reading ComputeRegionTargetTcpProxy %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading RegionTargetTcpProxy: %s", err) } @@ -431,7 +458,19 @@ func resourceComputeRegionTargetTcpProxyRead(d *schema.ResourceData, meta interf return nil } +func resourceComputeRegionTargetTcpProxyUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceComputeRegionTargetTcpProxyRead(d, meta) +} + func resourceComputeRegionTargetTcpProxyDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeRegionTargetTcpProxy without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing RegionTargetTcpProxy %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_region_target_tcp_proxy_generated_meta.yaml b/google-beta/services/compute/resource_compute_region_target_tcp_proxy_generated_meta.yaml index b05bca2fdf9..0f4ea3d661b 100644 --- a/google-beta/services/compute/resource_compute_region_target_tcp_proxy_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_region_target_tcp_proxy_generated_meta.yaml @@ -19,3 +19,5 @@ fields: field: proxy_id - api_field: region - api_field: selfLink + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_region_url_map.go b/google-beta/services/compute/resource_compute_region_url_map.go index 7e24124422d..b3d19c7c0da 100644 --- a/google-beta/services/compute/resource_compute_region_url_map.go +++ b/google-beta/services/compute/resource_compute_region_url_map.go @@ -115,6 +115,7 @@ func ResourceComputeRegionUrlMap() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -2930,6 +2931,18 @@ updates of this resource.`, Type: schema.TypeString, Computed: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -3158,6 +3171,19 @@ func resourceComputeRegionUrlMapRead(d *schema.ResourceData, meta interface{}) e log.Printf("[DEBUG] Finished reading ComputeRegionUrlMap %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading RegionUrlMap: %s", err) } @@ -3195,6 +3221,19 @@ func resourceComputeRegionUrlMapRead(d *schema.ResourceData, meta interface{}) e } func resourceComputeRegionUrlMapUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceComputeRegionUrlMap().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceComputeRegionUrlMapRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -3339,6 +3378,13 @@ func resourceComputeRegionUrlMapUpdate(d *schema.ResourceData, meta interface{}) } func resourceComputeRegionUrlMapDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeRegionUrlMap without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing RegionUrlMap %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_region_url_map_generated_meta.yaml b/google-beta/services/compute/resource_compute_region_url_map_generated_meta.yaml index 28d5c4b806e..83a550a9cf0 100644 --- a/google-beta/services/compute/resource_compute_region_url_map_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_region_url_map_generated_meta.yaml @@ -407,3 +407,5 @@ fields: - api_field: tests.service field: test.service - api_field: selfLink + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_reservation.go b/google-beta/services/compute/resource_compute_reservation.go index 88d4ed86aac..217abd36692 100644 --- a/google-beta/services/compute/resource_compute_reservation.go +++ b/google-beta/services/compute/resource_compute_reservation.go @@ -126,6 +126,7 @@ func ResourceComputeReservation() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Schema: map[string]*schema.Schema{ @@ -608,6 +609,18 @@ reservations that are tied to a commitment.`, Type: schema.TypeString, Computed: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -816,6 +829,18 @@ func resourceComputeReservationRead(d *schema.ResourceData, meta interface{}) er } // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Reservation: %s", err) } @@ -829,6 +854,19 @@ func resourceComputeReservationRead(d *schema.ResourceData, meta interface{}) er } func resourceComputeReservationUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceComputeReservation().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceComputeReservationRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1008,6 +1046,13 @@ func resourceComputeReservationUpdate(d *schema.ResourceData, meta interface{}) } func resourceComputeReservationDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeReservation without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Reservation %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_reservation_generated_meta.yaml b/google-beta/services/compute/resource_compute_reservation_generated_meta.yaml index 75e74e4c4b0..f1bb91a74a9 100644 --- a/google-beta/services/compute/resource_compute_reservation_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_reservation_generated_meta.yaml @@ -66,3 +66,5 @@ fields: - api_field: status - api_field: zone - api_field: selfLink + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_resize_request.go b/google-beta/services/compute/resource_compute_resize_request.go index 9d1ac4bb4ff..9e75a3a195c 100644 --- a/google-beta/services/compute/resource_compute_resize_request.go +++ b/google-beta/services/compute/resource_compute_resize_request.go @@ -100,6 +100,7 @@ func ResourceComputeResizeRequest() *schema.Resource { return &schema.Resource{ Create: resourceComputeResizeRequestCreate, Read: resourceComputeResizeRequestRead, + Update: resourceComputeResizeRequestUpdate, Delete: resourceComputeResizeRequestDelete, Importer: &schema.ResourceImporter{ @@ -113,6 +114,7 @@ func ResourceComputeResizeRequest() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -541,6 +543,18 @@ func ResourceComputeResizeRequest() *schema.Resource { Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -707,6 +721,19 @@ func resourceComputeResizeRequestRead(d *schema.ResourceData, meta interface{}) log.Printf("[DEBUG] Finished reading ComputeResizeRequest %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading ResizeRequest: %s", err) } @@ -749,7 +776,19 @@ func resourceComputeResizeRequestRead(d *schema.ResourceData, meta interface{}) return nil } +func resourceComputeResizeRequestUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceComputeResizeRequestRead(d, meta) +} + func resourceComputeResizeRequestDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeResizeRequest without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing ResizeRequest %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_resize_request_generated_meta.yaml b/google-beta/services/compute/resource_compute_resize_request_generated_meta.yaml index 4a576242972..2f4fa34404b 100644 --- a/google-beta/services/compute/resource_compute_resize_request_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_resize_request_generated_meta.yaml @@ -49,3 +49,5 @@ fields: - api_field: status.lastAttempt.error.errors.location - api_field: status.lastAttempt.error.errors.message - api_field: zone + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_resource_policy.go b/google-beta/services/compute/resource_compute_resource_policy.go index dba68242f26..38ed977e9d2 100644 --- a/google-beta/services/compute/resource_compute_resource_policy.go +++ b/google-beta/services/compute/resource_compute_resource_policy.go @@ -122,6 +122,7 @@ func ResourceComputeResourcePolicy() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, tpgresource.DefaultProviderRegion, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -514,6 +515,18 @@ and cannot be set if accelerator topology or accelerator topology mode is set. P Type: schema.TypeString, Computed: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -712,6 +725,19 @@ func resourceComputeResourcePolicyRead(d *schema.ResourceData, meta interface{}) log.Printf("[DEBUG] Finished reading ComputeResourcePolicy %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading ResourcePolicy: %s", err) } @@ -757,6 +783,19 @@ func resourceComputeResourcePolicyRead(d *schema.ResourceData, meta interface{}) } func resourceComputeResourcePolicyUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceComputeResourcePolicy().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceComputeResourcePolicyRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -877,6 +916,13 @@ func resourceComputeResourcePolicyUpdate(d *schema.ResourceData, meta interface{ } func resourceComputeResourcePolicyDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeResourcePolicy without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing ResourcePolicy %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_resource_policy_attachment.go b/google-beta/services/compute/resource_compute_resource_policy_attachment.go index 5790baacf2a..9d8fbdc6a7d 100644 --- a/google-beta/services/compute/resource_compute_resource_policy_attachment.go +++ b/google-beta/services/compute/resource_compute_resource_policy_attachment.go @@ -100,6 +100,7 @@ func ResourceComputeResourcePolicyAttachment() *schema.Resource { return &schema.Resource{ Create: resourceComputeResourcePolicyAttachmentCreate, Read: resourceComputeResourcePolicyAttachmentRead, + Update: resourceComputeResourcePolicyAttachmentUpdate, Delete: resourceComputeResourcePolicyAttachmentDelete, Importer: &schema.ResourceImporter{ @@ -114,6 +115,7 @@ func ResourceComputeResourcePolicyAttachment() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, tpgresource.DefaultProviderZone, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -172,6 +174,18 @@ operations. Do not specify the self link.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -343,6 +357,19 @@ func resourceComputeResourcePolicyAttachmentRead(d *schema.ResourceData, meta in return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading ResourcePolicyAttachment: %s", err) } @@ -392,7 +419,19 @@ func resourceComputeResourcePolicyAttachmentRead(d *schema.ResourceData, meta in return nil } +func resourceComputeResourcePolicyAttachmentUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceComputeResourcePolicyAttachmentRead(d, meta) +} + func resourceComputeResourcePolicyAttachmentDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeResourcePolicyAttachment without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing ResourcePolicyAttachment %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_resource_policy_attachment_generated_meta.yaml b/google-beta/services/compute/resource_compute_resource_policy_attachment_generated_meta.yaml index f84619c17b6..4da6429ff28 100644 --- a/google-beta/services/compute/resource_compute_resource_policy_attachment_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_resource_policy_attachment_generated_meta.yaml @@ -13,3 +13,5 @@ fields: field: name - field: zone provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_resource_policy_generated_meta.yaml b/google-beta/services/compute/resource_compute_resource_policy_generated_meta.yaml index f39f8a8268e..e5d9962e5c6 100644 --- a/google-beta/services/compute/resource_compute_resource_policy_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_resource_policy_generated_meta.yaml @@ -39,3 +39,5 @@ fields: - api_field: workloadPolicy.maxTopologyDistance - api_field: workloadPolicy.type - api_field: selfLink + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_rollout_plan.go b/google-beta/services/compute/resource_compute_rollout_plan.go index e5640d04b1e..3205402c299 100644 --- a/google-beta/services/compute/resource_compute_rollout_plan.go +++ b/google-beta/services/compute/resource_compute_rollout_plan.go @@ -100,6 +100,7 @@ func ResourceComputeRolloutPlan() *schema.Resource { return &schema.Resource{ Create: resourceComputeRolloutPlanCreate, Read: resourceComputeRolloutPlanRead, + Update: resourceComputeRolloutPlanUpdate, Delete: resourceComputeRolloutPlanDelete, Importer: &schema.ResourceImporter{ @@ -113,6 +114,7 @@ func ResourceComputeRolloutPlan() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -346,6 +348,18 @@ after all changes in the wave are rolled out.`, Type: schema.TypeString, Computed: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -496,6 +510,19 @@ func resourceComputeRolloutPlanRead(d *schema.ResourceData, meta interface{}) er log.Printf("[DEBUG] Finished reading ComputeRolloutPlan %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading RolloutPlan: %s", err) } @@ -526,7 +553,19 @@ func resourceComputeRolloutPlanRead(d *schema.ResourceData, meta interface{}) er return nil } +func resourceComputeRolloutPlanUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceComputeRolloutPlanRead(d, meta) +} + func resourceComputeRolloutPlanDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeRolloutPlan without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing RolloutPlan %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_rollout_plan_generated_meta.yaml b/google-beta/services/compute/resource_compute_rollout_plan_generated_meta.yaml index 3416c75f296..5a5dec1c03d 100644 --- a/google-beta/services/compute/resource_compute_rollout_plan_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_rollout_plan_generated_meta.yaml @@ -24,3 +24,5 @@ fields: - api_field: waves.validation.timeBasedValidationMetadata.waitDuration - api_field: waves.validation.type - api_field: selfLink + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_route.go b/google-beta/services/compute/resource_compute_route.go index f91681ca29d..a0e898a1ce9 100644 --- a/google-beta/services/compute/resource_compute_route.go +++ b/google-beta/services/compute/resource_compute_route.go @@ -115,6 +115,7 @@ func ResourceComputeRoute() *schema.Resource { return &schema.Resource{ Create: resourceComputeRouteCreate, Read: resourceComputeRouteRead, + Update: resourceComputeRouteUpdate, Delete: resourceComputeRouteDelete, Importer: &schema.ResourceImporter{ @@ -128,6 +129,7 @@ func ResourceComputeRoute() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -430,6 +432,18 @@ NO_RESULTS_ON_PAGE if there are no results in the response.`, Type: schema.TypeString, Computed: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -649,6 +663,19 @@ func resourceComputeRouteRead(d *schema.ResourceData, meta interface{}) error { return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Route: %s", err) } @@ -679,7 +706,19 @@ func resourceComputeRouteRead(d *schema.ResourceData, meta interface{}) error { return nil } +func resourceComputeRouteUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceComputeRouteRead(d, meta) +} + func resourceComputeRouteDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeRoute without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Route %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_route_generated_meta.yaml b/google-beta/services/compute/resource_compute_route_generated_meta.yaml index eb89b7e73d3..1ca436d52e2 100644 --- a/google-beta/services/compute/resource_compute_route_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_route_generated_meta.yaml @@ -35,3 +35,5 @@ fields: - api_field: warnings.data.value - api_field: warnings.message - api_field: selfLink + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_router.go b/google-beta/services/compute/resource_compute_router.go index 6e102456697..1b0bc46b1ba 100644 --- a/google-beta/services/compute/resource_compute_router.go +++ b/google-beta/services/compute/resource_compute_router.go @@ -134,6 +134,7 @@ func ResourceComputeRouter() *schema.Resource { CustomizeDiff: customdiff.All( resourceComputeRouterCustomDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -339,6 +340,18 @@ and values are in the format tagValues/456.`, Type: schema.TypeString, Computed: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -549,6 +562,19 @@ func resourceComputeRouterRead(d *schema.ResourceData, meta interface{}) error { log.Printf("[DEBUG] Finished reading ComputeRouter %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Router: %s", err) } @@ -586,6 +612,19 @@ func resourceComputeRouterRead(d *schema.ResourceData, meta interface{}) error { } func resourceComputeRouterUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceComputeRouter().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceComputeRouterRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -689,6 +728,13 @@ func resourceComputeRouterUpdate(d *schema.ResourceData, meta interface{}) error } func resourceComputeRouterDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeRouter without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Router %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_router_generated_meta.yaml b/google-beta/services/compute/resource_compute_router_generated_meta.yaml index b65d4da6ce7..dd352fb57da 100644 --- a/google-beta/services/compute/resource_compute_router_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_router_generated_meta.yaml @@ -25,3 +25,5 @@ fields: - api_field: params.resourceManagerTags - api_field: region - api_field: selfLink + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_router_interface.go b/google-beta/services/compute/resource_compute_router_interface.go index 8c06f20e58b..8ff22d9842e 100644 --- a/google-beta/services/compute/resource_compute_router_interface.go +++ b/google-beta/services/compute/resource_compute_router_interface.go @@ -39,6 +39,7 @@ func ResourceComputeRouterInterface() *schema.Resource { return &schema.Resource{ Create: resourceComputeRouterInterfaceCreate, Read: resourceComputeRouterInterfaceRead, + Update: resourceComputeRouterInterfaceUpdate, Delete: resourceComputeRouterInterfaceDelete, Importer: &schema.ResourceImporter{ State: resourceComputeRouterInterfaceImportState, @@ -50,6 +51,7 @@ func ResourceComputeRouterInterface() *schema.Resource { }, CustomizeDiff: customdiff.All( + tpgresource.DefaultProviderDeletionPolicy("DELETE"), tpgresource.DefaultProviderProject, tpgresource.DefaultProviderRegion, ), @@ -138,6 +140,9 @@ func ResourceComputeRouterInterface() *schema.Resource { ForceNew: true, Description: `The name of the interface that is redundant to this interface. Changing this forces a new interface to be created.`, }, + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end }, UseJSONNumber: true, } @@ -312,6 +317,11 @@ func resourceComputeRouterInterfaceRead(d *schema.ResourceData, meta interface{} if err := d.Set("redundant_interface", iface.RedundantInterface); err != nil { return fmt.Errorf("Error setting redundant interface: %s", err) } + + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + return nil } } @@ -321,7 +331,22 @@ func resourceComputeRouterInterfaceRead(d *schema.ResourceData, meta interface{} return nil } +// UDP update start +func resourceComputeRouterInterfaceUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceComputeRouterInterfaceRead(d, meta) +} + +//UDP update end + func resourceComputeRouterInterfaceDelete(d *schema.ResourceData, meta interface{}) error { + + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { + return nil + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_router_interface_meta.yaml b/google-beta/services/compute/resource_compute_router_interface_meta.yaml index ef9f78097d1..e6016493647 100644 --- a/google-beta/services/compute/resource_compute_router_interface_meta.yaml +++ b/google-beta/services/compute/resource_compute_router_interface_meta.yaml @@ -24,3 +24,5 @@ fields: field: 'subnetwork' - api_field: 'interfaces.linkedVpnTunnel' field: 'vpn_tunnel' + - field: 'deletion_policy' + provider_only: true diff --git a/google-beta/services/compute/resource_compute_router_named_set.go b/google-beta/services/compute/resource_compute_router_named_set.go index e59096482d6..e36694124f4 100644 --- a/google-beta/services/compute/resource_compute_router_named_set.go +++ b/google-beta/services/compute/resource_compute_router_named_set.go @@ -115,6 +115,7 @@ func ResourceComputeRouterNamedSet() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -219,6 +220,18 @@ internally during updates.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -397,6 +410,19 @@ func resourceComputeRouterNamedSetRead(d *schema.ResourceData, meta interface{}) return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading RouterNamedSet: %s", err) } @@ -440,6 +466,19 @@ func resourceComputeRouterNamedSetRead(d *schema.ResourceData, meta interface{}) } func resourceComputeRouterNamedSetUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceComputeRouterNamedSet().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceComputeRouterNamedSetRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -583,6 +622,13 @@ func resourceComputeRouterNamedSetUpdate(d *schema.ResourceData, meta interface{ } func resourceComputeRouterNamedSetDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeRouterNamedSet without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing RouterNamedSet %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_router_named_set_generated_meta.yaml b/google-beta/services/compute/resource_compute_router_named_set_generated_meta.yaml index 01c3575bf0b..65bceb4f6c6 100644 --- a/google-beta/services/compute/resource_compute_router_named_set_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_router_named_set_generated_meta.yaml @@ -27,3 +27,5 @@ fields: provider_only: true - api_field: resource.type field: type + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_router_nat.go b/google-beta/services/compute/resource_compute_router_nat.go index d8f3f339b35..413db7c3072 100644 --- a/google-beta/services/compute/resource_compute_router_nat.go +++ b/google-beta/services/compute/resource_compute_router_nat.go @@ -271,6 +271,7 @@ func ResourceComputeRouterNat() *schema.Resource { CustomizeDiff: customdiff.All( resourceComputeRouterNatDrainNatIpsCustomDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -545,6 +546,18 @@ If 'PRIVATE' NAT used for private IP translation. Default value: "PUBLIC" Possib Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -1020,6 +1033,19 @@ func resourceComputeRouterNatRead(d *schema.ResourceData, meta interface{}) erro return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading RouterNat: %s", err) } @@ -1063,6 +1089,19 @@ func resourceComputeRouterNatRead(d *schema.ResourceData, meta interface{}) erro } func resourceComputeRouterNatUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceComputeRouterNat().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceComputeRouterNatRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1303,6 +1342,13 @@ func resourceComputeRouterNatUpdate(d *schema.ResourceData, meta interface{}) er } func resourceComputeRouterNatDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeRouterNat without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing RouterNat %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_router_nat_address.go b/google-beta/services/compute/resource_compute_router_nat_address.go index 0358bd11c80..43582913af2 100644 --- a/google-beta/services/compute/resource_compute_router_nat_address.go +++ b/google-beta/services/compute/resource_compute_router_nat_address.go @@ -196,6 +196,7 @@ func ResourceComputeRouterNatAddress() *schema.Resource { CustomizeDiff: customdiff.All( resourceComputeRouterNatAddressDrainNatIpsCustomDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -276,6 +277,18 @@ valid static external IPs that have been assigned to the NAT.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -430,6 +443,19 @@ func resourceComputeRouterNatAddressRead(d *schema.ResourceData, meta interface{ return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading RouterNatAddress: %s", err) } @@ -473,6 +499,19 @@ func resourceComputeRouterNatAddressRead(d *schema.ResourceData, meta interface{ } func resourceComputeRouterNatAddressUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceComputeRouterNatAddress().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceComputeRouterNatAddressRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -585,6 +624,13 @@ func resourceComputeRouterNatAddressUpdate(d *schema.ResourceData, meta interfac } func resourceComputeRouterNatAddressDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeRouterNatAddress without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing RouterNatAddress %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_router_nat_address_generated_meta.yaml b/google-beta/services/compute/resource_compute_router_nat_address_generated_meta.yaml index c3609124d50..6fa6b5cfe08 100644 --- a/google-beta/services/compute/resource_compute_router_nat_address_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_router_nat_address_generated_meta.yaml @@ -17,3 +17,5 @@ fields: provider_only: true - api_field: nats.name field: router_nat + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_router_nat_generated_meta.yaml b/google-beta/services/compute/resource_compute_router_nat_generated_meta.yaml index 2a9af6cdee2..672c6be6e4b 100644 --- a/google-beta/services/compute/resource_compute_router_nat_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_router_nat_generated_meta.yaml @@ -75,3 +75,5 @@ fields: field: type - api_field: nats.udpIdleTimeoutSec field: udp_idle_timeout_sec + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_router_peer.go b/google-beta/services/compute/resource_compute_router_peer.go index 73628a4149d..d00a7f3f617 100644 --- a/google-beta/services/compute/resource_compute_router_peer.go +++ b/google-beta/services/compute/resource_compute_router_peer.go @@ -66,6 +66,7 @@ func ResourceComputeRouterBgpPeer() *schema.Resource { }, CustomizeDiff: customdiff.All( + tpgresource.DefaultProviderDeletionPolicy("DELETE"), tpgresource.DefaultProviderProject, ), @@ -388,6 +389,9 @@ Must be unique within a router. Must be referenced by exactly one bgpPeer. Must }, }, }, + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end }, UseJSONNumber: true, } @@ -785,10 +789,19 @@ func resourceComputeRouterBgpPeerRead(d *schema.ResourceData, meta interface{}) return fmt.Errorf("Error reading RouterBgpPeer: %s", err) } + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + return nil } func resourceComputeRouterBgpPeerUpdate(d *schema.ResourceData, meta interface{}) error { + + if tpgresource.DeletionPolicyPreUpdate(d, ResourceComputeRouterBgpPeer) { + return ResourceComputeRouterBgpPeer().Read(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1019,6 +1032,13 @@ func resourceComputeRouterBgpPeerUpdate(d *schema.ResourceData, meta interface{} } func resourceComputeRouterBgpPeerDelete(d *schema.ResourceData, meta interface{}) error { + + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { + return nil + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_router_peer_meta.yaml b/google-beta/services/compute/resource_compute_router_peer_meta.yaml index 095fcc1c627..8e747f57c5d 100644 --- a/google-beta/services/compute/resource_compute_router_peer_meta.yaml +++ b/google-beta/services/compute/resource_compute_router_peer_meta.yaml @@ -74,3 +74,5 @@ fields: provider_only: true - field: 'zero_custom_learned_route_priority' provider_only: true + - field: 'deletion_policy' + provider_only: true diff --git a/google-beta/services/compute/resource_compute_router_route_policy.go b/google-beta/services/compute/resource_compute_router_route_policy.go index 28b92854a53..53c989cc1b3 100644 --- a/google-beta/services/compute/resource_compute_router_route_policy.go +++ b/google-beta/services/compute/resource_compute_router_route_policy.go @@ -115,6 +115,7 @@ func ResourceComputeRouterRoutePolicy() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -260,6 +261,18 @@ internally during updates.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -432,6 +445,19 @@ func resourceComputeRouterRoutePolicyRead(d *schema.ResourceData, meta interface return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading RouterRoutePolicy: %s", err) } @@ -475,6 +501,19 @@ func resourceComputeRouterRoutePolicyRead(d *schema.ResourceData, meta interface } func resourceComputeRouterRoutePolicyUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceComputeRouterRoutePolicy().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceComputeRouterRoutePolicyRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -608,6 +647,13 @@ func resourceComputeRouterRoutePolicyUpdate(d *schema.ResourceData, meta interfa } func resourceComputeRouterRoutePolicyDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeRouterRoutePolicy without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing RouterRoutePolicy %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_router_route_policy_generated_meta.yaml b/google-beta/services/compute/resource_compute_router_route_policy_generated_meta.yaml index 4b9b0b5f5db..79bafd48bf8 100644 --- a/google-beta/services/compute/resource_compute_router_route_policy_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_router_route_policy_generated_meta.yaml @@ -23,3 +23,5 @@ fields: - api_field: terms.match.title - api_field: terms.priority - api_field: type + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_security_policy.go b/google-beta/services/compute/resource_compute_security_policy.go index eca9b7cf7e9..5ae94d53897 100644 --- a/google-beta/services/compute/resource_compute_security_policy.go +++ b/google-beta/services/compute/resource_compute_security_policy.go @@ -77,6 +77,7 @@ func ResourceComputeSecurityPolicy() *schema.Resource { State: resourceSecurityPolicyStateImporter, }, CustomizeDiff: customdiff.All( + tpgresource.DefaultProviderDeletionPolicy("DELETE"), tpgresource.DefaultProviderProject, tpgresource.SetLabelsDiff, rulesCustomizeDiff, @@ -741,6 +742,9 @@ Please refer to the field 'effective_labels' for all of the labels present on th Computed: true, Description: `The unique fingerprint of the labels.`, }, + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end }, UseJSONNumber: true, } @@ -959,10 +963,19 @@ func resourceComputeSecurityPolicyRead(d *schema.ResourceData, meta interface{}) return fmt.Errorf("Error setting label_fingerprint: %s", err) } + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + return nil } func resourceComputeSecurityPolicyUpdate(d *schema.ResourceData, meta interface{}) error { + + if tpgresource.DeletionPolicyPreUpdate(d, ResourceComputeSecurityPolicy) { + return ResourceComputeSecurityPolicy().Read(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1161,6 +1174,13 @@ func resourceComputeSecurityPolicyUpdate(d *schema.ResourceData, meta interface{ } func resourceComputeSecurityPolicyDelete(d *schema.ResourceData, meta interface{}) error { + + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { + return nil + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_security_policy_meta.yaml b/google-beta/services/compute/resource_compute_security_policy_meta.yaml index 0e894c71e9e..69047e6592f 100644 --- a/google-beta/services/compute/resource_compute_security_policy_meta.yaml +++ b/google-beta/services/compute/resource_compute_security_policy_meta.yaml @@ -125,4 +125,6 @@ fields: - api_field: 'selfLink' - field: 'terraform_labels' provider_only: true - - api_field: 'type' \ No newline at end of file + - api_field: 'type' + - field: 'deletion_policy' + provider_only: true \ No newline at end of file diff --git a/google-beta/services/compute/resource_compute_security_policy_rule.go b/google-beta/services/compute/resource_compute_security_policy_rule.go index 0a1ed0b1093..5e3755dd156 100644 --- a/google-beta/services/compute/resource_compute_security_policy_rule.go +++ b/google-beta/services/compute/resource_compute_security_policy_rule.go @@ -115,6 +115,7 @@ func ResourceComputeSecurityPolicyRule() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -642,6 +643,18 @@ Valid options are deny(STATUS), where valid values for STATUS are 403, 404, 429, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -839,6 +852,19 @@ func resourceComputeSecurityPolicyRuleRead(d *schema.ResourceData, meta interfac log.Printf("[DEBUG] Finished reading ComputeSecurityPolicyRule %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading SecurityPolicyRule: %s", err) } @@ -876,6 +902,19 @@ func resourceComputeSecurityPolicyRuleRead(d *schema.ResourceData, meta interfac } func resourceComputeSecurityPolicyRuleUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceComputeSecurityPolicyRule().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceComputeSecurityPolicyRuleRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1064,6 +1103,13 @@ func resourceComputeSecurityPolicyRuleUpdate(d *schema.ResourceData, meta interf } func resourceComputeSecurityPolicyRuleDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeSecurityPolicyRule without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing SecurityPolicyRule %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_security_policy_rule_generated_meta.yaml b/google-beta/services/compute/resource_compute_security_policy_rule_generated_meta.yaml index 85cefadf65f..342b6806bca 100644 --- a/google-beta/services/compute/resource_compute_security_policy_rule_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_security_policy_rule_generated_meta.yaml @@ -85,3 +85,5 @@ fields: field: redirect_options.type - field: security_policy provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_service_attachment.go b/google-beta/services/compute/resource_compute_service_attachment.go index 14b4ae0c896..205e5dfffd5 100644 --- a/google-beta/services/compute/resource_compute_service_attachment.go +++ b/google-beta/services/compute/resource_compute_service_attachment.go @@ -152,6 +152,7 @@ func ResourceComputeServiceAttachment() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, tpgresource.DefaultProviderRegion, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -397,6 +398,18 @@ Defaults to false.`, Type: schema.TypeString, Computed: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -656,6 +669,18 @@ func resourceComputeServiceAttachmentRead(d *schema.ResourceData, meta interface return fmt.Errorf("Error setting send_propagated_connection_limit_if_zero: %s", err) } } + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading ServiceAttachment: %s", err) } @@ -701,6 +726,19 @@ func resourceComputeServiceAttachmentRead(d *schema.ResourceData, meta interface } func resourceComputeServiceAttachmentUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceComputeServiceAttachment().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceComputeServiceAttachmentRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -850,6 +888,13 @@ func resourceComputeServiceAttachmentUpdate(d *schema.ResourceData, meta interfa } func resourceComputeServiceAttachmentDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeServiceAttachment without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing ServiceAttachment %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_service_attachment_generated_meta.yaml b/google-beta/services/compute/resource_compute_service_attachment_generated_meta.yaml index 745fbaf5521..e135d08e8a2 100644 --- a/google-beta/services/compute/resource_compute_service_attachment_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_service_attachment_generated_meta.yaml @@ -38,3 +38,5 @@ fields: - api_field: tunnelingConfig.encapsulationProfile - api_field: tunnelingConfig.routingMode - api_field: selfLink + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_shared_vpc_host_project.go b/google-beta/services/compute/resource_compute_shared_vpc_host_project.go index d27680182da..56d1bbc0458 100644 --- a/google-beta/services/compute/resource_compute_shared_vpc_host_project.go +++ b/google-beta/services/compute/resource_compute_shared_vpc_host_project.go @@ -21,6 +21,7 @@ import ( "log" "time" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-google-beta/google-beta/registry" "github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource" @@ -31,6 +32,7 @@ func ResourceComputeSharedVpcHostProject() *schema.Resource { return &schema.Resource{ Create: resourceComputeSharedVpcHostProjectCreate, Read: resourceComputeSharedVpcHostProjectRead, + Update: resourceComputeSharedVpcHostProjectUpdate, Delete: resourceComputeSharedVpcHostProjectDelete, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, @@ -41,6 +43,10 @@ func ResourceComputeSharedVpcHostProject() *schema.Resource { Delete: schema.DefaultTimeout(4 * time.Minute), }, + CustomizeDiff: customdiff.All( + tpgresource.DefaultProviderDeletionPolicy("DELETE"), + ), + Schema: map[string]*schema.Schema{ "project": { Type: schema.TypeString, @@ -48,6 +54,9 @@ func ResourceComputeSharedVpcHostProject() *schema.Resource { ForceNew: true, Description: `The ID of the project that will serve as a Shared VPC host project`, }, + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end }, UseJSONNumber: true, } @@ -100,10 +109,29 @@ func resourceComputeSharedVpcHostProjectRead(d *schema.ResourceData, meta interf return fmt.Errorf("Error setting project: %s", err) } + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + return nil } +// UDP update start +func resourceComputeSharedVpcHostProjectUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceComputeSharedVpcHostProjectRead(d, meta) +} + +//UDP update end + func resourceComputeSharedVpcHostProjectDelete(d *schema.ResourceData, meta interface{}) error { + + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { + return nil + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_shared_vpc_host_project_meta.yaml b/google-beta/services/compute/resource_compute_shared_vpc_host_project_meta.yaml index 0994d3e1691..323a0d6ccbe 100644 --- a/google-beta/services/compute/resource_compute_shared_vpc_host_project_meta.yaml +++ b/google-beta/services/compute/resource_compute_shared_vpc_host_project_meta.yaml @@ -7,3 +7,5 @@ api_version: 'beta' api_resource_type_kind: 'Project' fields: - field: 'project' + - field: 'deletion_policy' + provider_only: true diff --git a/google-beta/services/compute/resource_compute_snapshot.go b/google-beta/services/compute/resource_compute_snapshot.go index 336c81e41e8..e3db8252e45 100644 --- a/google-beta/services/compute/resource_compute_snapshot.go +++ b/google-beta/services/compute/resource_compute_snapshot.go @@ -116,6 +116,7 @@ func ResourceComputeSnapshot() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -386,6 +387,18 @@ creation/deletion.`, Type: schema.TypeString, Computed: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -611,6 +624,19 @@ func resourceComputeSnapshotRead(d *schema.ResourceData, meta interface{}) error return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Snapshot: %s", err) } @@ -642,6 +668,19 @@ func resourceComputeSnapshotRead(d *schema.ResourceData, meta interface{}) error } func resourceComputeSnapshotUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceComputeSnapshot().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceComputeSnapshotRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -731,6 +770,13 @@ func resourceComputeSnapshotUpdate(d *schema.ResourceData, meta interface{}) err } func resourceComputeSnapshotDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeSnapshot without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Snapshot %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_snapshot_generated_meta.yaml b/google-beta/services/compute/resource_compute_snapshot_generated_meta.yaml index b936bda9d54..ecd82532538 100644 --- a/google-beta/services/compute/resource_compute_snapshot_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_snapshot_generated_meta.yaml @@ -40,3 +40,5 @@ fields: provider_only: true - api_field: zone - api_field: selfLink + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_snapshot_settings.go b/google-beta/services/compute/resource_compute_snapshot_settings.go index 13f7e4418f0..ef44fa735f8 100644 --- a/google-beta/services/compute/resource_compute_snapshot_settings.go +++ b/google-beta/services/compute/resource_compute_snapshot_settings.go @@ -334,6 +334,7 @@ func resourceComputeSnapshotSettingsRead(d *schema.ResourceData, meta interface{ } func resourceComputeSnapshotSettingsUpdate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_ssl_certificate.go b/google-beta/services/compute/resource_compute_ssl_certificate.go index af658125847..f20e1757df2 100644 --- a/google-beta/services/compute/resource_compute_ssl_certificate.go +++ b/google-beta/services/compute/resource_compute_ssl_certificate.go @@ -100,6 +100,7 @@ func ResourceComputeSslCertificate() *schema.Resource { return &schema.Resource{ Create: resourceComputeSslCertificateCreate, Read: resourceComputeSslCertificateRead, + Update: resourceComputeSslCertificateUpdate, Delete: resourceComputeSslCertificateDelete, Importer: &schema.ResourceImporter{ @@ -113,6 +114,7 @@ func ResourceComputeSslCertificate() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -233,6 +235,18 @@ These are in the same namespace as the managed SSL certificates.`, Type: schema.TypeString, Computed: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -389,6 +403,19 @@ func resourceComputeSslCertificateRead(d *schema.ResourceData, meta interface{}) log.Printf("[DEBUG] Finished reading ComputeSslCertificate %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading SslCertificate: %s", err) } @@ -419,7 +446,19 @@ func resourceComputeSslCertificateRead(d *schema.ResourceData, meta interface{}) return nil } +func resourceComputeSslCertificateUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceComputeSslCertificateRead(d, meta) +} + func resourceComputeSslCertificateDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeSslCertificate without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing SslCertificate %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_ssl_certificate_generated_meta.yaml b/google-beta/services/compute/resource_compute_ssl_certificate_generated_meta.yaml index e8e2790bbab..d1f2b306e66 100644 --- a/google-beta/services/compute/resource_compute_ssl_certificate_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_ssl_certificate_generated_meta.yaml @@ -20,3 +20,5 @@ fields: - field: private_key_wo_version provider_only: true - api_field: selfLink + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_ssl_policy.go b/google-beta/services/compute/resource_compute_ssl_policy.go index ae9ae420875..e328d9271ad 100644 --- a/google-beta/services/compute/resource_compute_ssl_policy.go +++ b/google-beta/services/compute/resource_compute_ssl_policy.go @@ -137,6 +137,7 @@ func ResourceComputeSslPolicy() *schema.Resource { CustomizeDiff: customdiff.All( sslPolicyCustomizeDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -250,6 +251,18 @@ object. This field is used in optimistic locking.`, Type: schema.TypeString, Computed: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -406,6 +419,19 @@ func resourceComputeSslPolicyRead(d *schema.ResourceData, meta interface{}) erro log.Printf("[DEBUG] Finished reading ComputeSslPolicy %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading SslPolicy: %s", err) } @@ -437,6 +463,19 @@ func resourceComputeSslPolicyRead(d *schema.ResourceData, meta interface{}) erro } func resourceComputeSslPolicyUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceComputeSslPolicy().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceComputeSslPolicyRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -533,6 +572,13 @@ func resourceComputeSslPolicyUpdate(d *schema.ResourceData, meta interface{}) er } func resourceComputeSslPolicyDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeSslPolicy without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing SslPolicy %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_ssl_policy_generated_meta.yaml b/google-beta/services/compute/resource_compute_ssl_policy_generated_meta.yaml index 2f2f9f70ac8..b865fc0402b 100644 --- a/google-beta/services/compute/resource_compute_ssl_policy_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_ssl_policy_generated_meta.yaml @@ -16,3 +16,5 @@ fields: - api_field: name - api_field: profile - api_field: selfLink + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_storage_pool.go b/google-beta/services/compute/resource_compute_storage_pool.go index a7acbc8ec60..edb20246254 100644 --- a/google-beta/services/compute/resource_compute_storage_pool.go +++ b/google-beta/services/compute/resource_compute_storage_pool.go @@ -116,6 +116,7 @@ func ResourceComputeStoragePool() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -422,6 +423,18 @@ When the field is set to false, deleting the StoragePool is allowed.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -631,6 +644,18 @@ func resourceComputeStoragePoolRead(d *schema.ResourceData, meta interface{}) er return fmt.Errorf("Error setting deletion_protection: %s", err) } } + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading StoragePool: %s", err) } @@ -668,6 +693,19 @@ func resourceComputeStoragePoolRead(d *schema.ResourceData, meta interface{}) er } func resourceComputeStoragePoolUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceComputeStoragePool().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceComputeStoragePoolRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -782,6 +820,13 @@ func resourceComputeStoragePoolUpdate(d *schema.ResourceData, meta interface{}) } func resourceComputeStoragePoolDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeStoragePool without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing StoragePool %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_storage_pool_generated_meta.yaml b/google-beta/services/compute/resource_compute_storage_pool_generated_meta.yaml index 5de78526dd4..dc8c84a7779 100644 --- a/google-beta/services/compute/resource_compute_storage_pool_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_storage_pool_generated_meta.yaml @@ -48,3 +48,5 @@ fields: - field: terraform_labels provider_only: true - api_field: zone + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_subnetwork.go b/google-beta/services/compute/resource_compute_subnetwork.go index 3e8491542fc..104ad66fd7a 100644 --- a/google-beta/services/compute/resource_compute_subnetwork.go +++ b/google-beta/services/compute/resource_compute_subnetwork.go @@ -206,6 +206,7 @@ func ResourceComputeSubnetwork() *schema.Resource { customdiff.ForceNewIfChange("ip_cidr_range", IsShrinkageIpCidr), sendSecondaryIpRangeIfEmptyDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -581,6 +582,18 @@ Defaults to false.`, Type: schema.TypeString, Computed: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -875,6 +888,18 @@ func resourceComputeSubnetworkRead(d *schema.ResourceData, meta interface{}) err log.Printf("[DEBUG] Finished reading ComputeSubnetwork %q: %#v", d.Id(), res) // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Subnetwork: %s", err) } @@ -912,6 +937,19 @@ func resourceComputeSubnetworkRead(d *schema.ResourceData, meta interface{}) err } func resourceComputeSubnetworkUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceComputeSubnetwork().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceComputeSubnetworkRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1536,6 +1574,13 @@ func resourceComputeSubnetworkUpdate(d *schema.ResourceData, meta interface{}) e } func resourceComputeSubnetworkDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeSubnetwork without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Subnetwork %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_subnetwork_generated_meta.yaml b/google-beta/services/compute/resource_compute_subnetwork_generated_meta.yaml index 03700d09302..fbcd65107eb 100644 --- a/google-beta/services/compute/resource_compute_subnetwork_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_subnetwork_generated_meta.yaml @@ -46,3 +46,5 @@ fields: - api_field: id field: subnetwork_id - api_field: selfLink + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_target_grpc_proxy.go b/google-beta/services/compute/resource_compute_target_grpc_proxy.go index 9a4a65ddb02..09efbab8c61 100644 --- a/google-beta/services/compute/resource_compute_target_grpc_proxy.go +++ b/google-beta/services/compute/resource_compute_target_grpc_proxy.go @@ -115,6 +115,7 @@ func ResourceComputeTargetGrpcProxy() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -209,6 +210,18 @@ request to retrieve the TargetGrpcProxy. A base64-encoded string.`, Type: schema.TypeString, Computed: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -365,6 +378,19 @@ func resourceComputeTargetGrpcProxyRead(d *schema.ResourceData, meta interface{} log.Printf("[DEBUG] Finished reading ComputeTargetGrpcProxy %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading TargetGrpcProxy: %s", err) } @@ -396,6 +422,19 @@ func resourceComputeTargetGrpcProxyRead(d *schema.ResourceData, meta interface{} } func resourceComputeTargetGrpcProxyUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceComputeTargetGrpcProxy().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceComputeTargetGrpcProxyRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -481,6 +520,13 @@ func resourceComputeTargetGrpcProxyUpdate(d *schema.ResourceData, meta interface } func resourceComputeTargetGrpcProxyDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeTargetGrpcProxy without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing TargetGrpcProxy %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_target_grpc_proxy_generated_meta.yaml b/google-beta/services/compute/resource_compute_target_grpc_proxy_generated_meta.yaml index 2f0aca169f2..70d344d2368 100644 --- a/google-beta/services/compute/resource_compute_target_grpc_proxy_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_target_grpc_proxy_generated_meta.yaml @@ -15,3 +15,5 @@ fields: - api_field: urlMap - api_field: validateForProxyless - api_field: selfLink + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_target_http_proxy.go b/google-beta/services/compute/resource_compute_target_http_proxy.go index b7c72d35431..3d912c4abeb 100644 --- a/google-beta/services/compute/resource_compute_target_http_proxy.go +++ b/google-beta/services/compute/resource_compute_target_http_proxy.go @@ -115,6 +115,7 @@ func ResourceComputeTargetHttpProxy() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -213,6 +214,18 @@ A base64-encoded string.`, Type: schema.TypeString, Computed: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -375,6 +388,19 @@ func resourceComputeTargetHttpProxyRead(d *schema.ResourceData, meta interface{} log.Printf("[DEBUG] Finished reading ComputeTargetHttpProxy %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading TargetHttpProxy: %s", err) } @@ -406,6 +432,19 @@ func resourceComputeTargetHttpProxyRead(d *schema.ResourceData, meta interface{} } func resourceComputeTargetHttpProxyUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceComputeTargetHttpProxy().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceComputeTargetHttpProxyRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -489,6 +528,13 @@ func resourceComputeTargetHttpProxyUpdate(d *schema.ResourceData, meta interface } func resourceComputeTargetHttpProxyDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeTargetHttpProxy without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing TargetHttpProxy %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_target_http_proxy_generated_meta.yaml b/google-beta/services/compute/resource_compute_target_http_proxy_generated_meta.yaml index 8621cc744bd..a6a590cd397 100644 --- a/google-beta/services/compute/resource_compute_target_http_proxy_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_target_http_proxy_generated_meta.yaml @@ -17,3 +17,5 @@ fields: field: proxy_id - api_field: urlMap - api_field: selfLink + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_target_https_proxy.go b/google-beta/services/compute/resource_compute_target_https_proxy.go index e9e74d7df6d..7a06cab96ed 100644 --- a/google-beta/services/compute/resource_compute_target_https_proxy.go +++ b/google-beta/services/compute/resource_compute_target_https_proxy.go @@ -115,6 +115,7 @@ func ResourceComputeTargetHttpsProxy() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -295,6 +296,18 @@ A base64-encoded string.`, Type: schema.TypeString, Computed: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -516,6 +529,19 @@ func resourceComputeTargetHttpsProxyRead(d *schema.ResourceData, meta interface{ return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading TargetHttpsProxy: %s", err) } @@ -547,6 +573,19 @@ func resourceComputeTargetHttpsProxyRead(d *schema.ResourceData, meta interface{ } func resourceComputeTargetHttpsProxyUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceComputeTargetHttpsProxy().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceComputeTargetHttpsProxyRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -914,6 +953,13 @@ func resourceComputeTargetHttpsProxyUpdate(d *schema.ResourceData, meta interfac } func resourceComputeTargetHttpsProxyDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeTargetHttpsProxy without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing TargetHttpsProxy %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_target_https_proxy_generated_meta.yaml b/google-beta/services/compute/resource_compute_target_https_proxy_generated_meta.yaml index 5c28a683952..cd979cd2a69 100644 --- a/google-beta/services/compute/resource_compute_target_https_proxy_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_target_https_proxy_generated_meta.yaml @@ -24,3 +24,5 @@ fields: - api_field: tlsEarlyData - api_field: urlMap - api_field: selfLink + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_target_instance.go b/google-beta/services/compute/resource_compute_target_instance.go index d3247e4b0a9..beccd6cac97 100644 --- a/google-beta/services/compute/resource_compute_target_instance.go +++ b/google-beta/services/compute/resource_compute_target_instance.go @@ -115,6 +115,7 @@ func ResourceComputeTargetInstance() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Schema: map[string]*schema.Schema{ @@ -191,6 +192,18 @@ Currently only NO_NAT (default value) is supported. Default value: "NO_NAT" Poss Type: schema.TypeString, Computed: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -376,6 +389,19 @@ func resourceComputeTargetInstanceRead(d *schema.ResourceData, meta interface{}) log.Printf("[DEBUG] Finished reading ComputeTargetInstance %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading TargetInstance: %s", err) } @@ -389,6 +415,19 @@ func resourceComputeTargetInstanceRead(d *schema.ResourceData, meta interface{}) } func resourceComputeTargetInstanceUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceComputeTargetInstance().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceComputeTargetInstanceRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -457,6 +496,13 @@ func resourceComputeTargetInstanceUpdate(d *schema.ResourceData, meta interface{ } func resourceComputeTargetInstanceDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeTargetInstance without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing TargetInstance %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_target_instance_generated_meta.yaml b/google-beta/services/compute/resource_compute_target_instance_generated_meta.yaml index e4647b50350..c4c3f04f44a 100644 --- a/google-beta/services/compute/resource_compute_target_instance_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_target_instance_generated_meta.yaml @@ -16,3 +16,5 @@ fields: - api_field: securityPolicy - api_field: zone - api_field: selfLink + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_target_pool.go b/google-beta/services/compute/resource_compute_target_pool.go index 6eec4795a22..5fb730b8e9d 100644 --- a/google-beta/services/compute/resource_compute_target_pool.go +++ b/google-beta/services/compute/resource_compute_target_pool.go @@ -53,6 +53,7 @@ func ResourceComputeTargetPool() *schema.Resource { }, CustomizeDiff: customdiff.All( + tpgresource.DefaultProviderDeletionPolicy("DELETE"), tpgresource.DefaultProviderProject, tpgresource.DefaultProviderRegion, ), @@ -150,6 +151,9 @@ func ResourceComputeTargetPool() *schema.Resource { Optional: true, Description: `The resource URL for the security policy associated with this target pool.`, }, + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end }, UseJSONNumber: true, } @@ -312,6 +316,11 @@ func resourceComputeTargetPoolCreate(d *schema.ResourceData, meta interface{}) e } func resourceComputeTargetPoolUpdate(d *schema.ResourceData, meta interface{}) error { + + if tpgresource.DeletionPolicyPreUpdate(d, ResourceComputeTargetPool) { + return ResourceComputeTargetPool().Read(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -556,10 +565,22 @@ func resourceComputeTargetPoolRead(d *schema.ResourceData, meta interface{}) err if err := d.Set("security_policy", tpool.SecurityPolicy); err != nil { return fmt.Errorf("Error setting security_policy: %s", err) } + + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + return nil } func resourceComputeTargetPoolDelete(d *schema.ResourceData, meta interface{}) error { + + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { + return nil + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_target_pool_meta.yaml b/google-beta/services/compute/resource_compute_target_pool_meta.yaml index da7913dbabe..67f9de13a58 100644 --- a/google-beta/services/compute/resource_compute_target_pool_meta.yaml +++ b/google-beta/services/compute/resource_compute_target_pool_meta.yaml @@ -17,3 +17,5 @@ fields: - api_field: 'securityPolicy' - api_field: 'selfLink' - api_field: 'sessionAffinity' + - field: 'deletion_policy' + provider_only: true diff --git a/google-beta/services/compute/resource_compute_target_ssl_proxy.go b/google-beta/services/compute/resource_compute_target_ssl_proxy.go index 6b47eac5615..16a351ca498 100644 --- a/google-beta/services/compute/resource_compute_target_ssl_proxy.go +++ b/google-beta/services/compute/resource_compute_target_ssl_proxy.go @@ -115,6 +115,7 @@ func ResourceComputeTargetSslProxy() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -215,6 +216,18 @@ resource will not have any SSL policy configured.`, Type: schema.TypeString, Computed: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -383,6 +396,19 @@ func resourceComputeTargetSslProxyRead(d *schema.ResourceData, meta interface{}) log.Printf("[DEBUG] Finished reading ComputeTargetSslProxy %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading TargetSslProxy: %s", err) } @@ -414,6 +440,19 @@ func resourceComputeTargetSslProxyRead(d *schema.ResourceData, meta interface{}) } func resourceComputeTargetSslProxyUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceComputeTargetSslProxy().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceComputeTargetSslProxyRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -677,6 +716,13 @@ func resourceComputeTargetSslProxyUpdate(d *schema.ResourceData, meta interface{ } func resourceComputeTargetSslProxyDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeTargetSslProxy without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing TargetSslProxy %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_target_ssl_proxy_generated_meta.yaml b/google-beta/services/compute/resource_compute_target_ssl_proxy_generated_meta.yaml index db287012c40..af89b55a1f2 100644 --- a/google-beta/services/compute/resource_compute_target_ssl_proxy_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_target_ssl_proxy_generated_meta.yaml @@ -19,3 +19,5 @@ fields: - api_field: sslCertificates - api_field: sslPolicy - api_field: selfLink + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_target_tcp_proxy.go b/google-beta/services/compute/resource_compute_target_tcp_proxy.go index 7ae0a8f7b36..fa3bce696ae 100644 --- a/google-beta/services/compute/resource_compute_target_tcp_proxy.go +++ b/google-beta/services/compute/resource_compute_target_tcp_proxy.go @@ -115,6 +115,7 @@ func ResourceComputeTargetTcpProxy() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -209,6 +210,18 @@ the backend. Default value: "NONE" Possible values: ["NONE", "PROXY_V1"]`, Type: schema.TypeString, Computed: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -371,6 +384,19 @@ func resourceComputeTargetTcpProxyRead(d *schema.ResourceData, meta interface{}) log.Printf("[DEBUG] Finished reading ComputeTargetTcpProxy %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading TargetTcpProxy: %s", err) } @@ -402,6 +428,19 @@ func resourceComputeTargetTcpProxyRead(d *schema.ResourceData, meta interface{}) } func resourceComputeTargetTcpProxyUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceComputeTargetTcpProxy().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceComputeTargetTcpProxyRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -530,6 +569,13 @@ func resourceComputeTargetTcpProxyUpdate(d *schema.ResourceData, meta interface{ } func resourceComputeTargetTcpProxyDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeTargetTcpProxy without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing TargetTcpProxy %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_target_tcp_proxy_generated_meta.yaml b/google-beta/services/compute/resource_compute_target_tcp_proxy_generated_meta.yaml index 6ed5eca5ae8..a65e5d861e2 100644 --- a/google-beta/services/compute/resource_compute_target_tcp_proxy_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_target_tcp_proxy_generated_meta.yaml @@ -18,3 +18,5 @@ fields: - api_field: id field: proxy_id - api_field: selfLink + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_url_map.go b/google-beta/services/compute/resource_compute_url_map.go index 1e2ee201ddd..aa94263f3b0 100644 --- a/google-beta/services/compute/resource_compute_url_map.go +++ b/google-beta/services/compute/resource_compute_url_map.go @@ -115,6 +115,7 @@ func ResourceComputeUrlMap() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -4655,6 +4656,18 @@ field is used in optimistic locking.`, Type: schema.TypeString, Computed: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -4877,6 +4890,19 @@ func resourceComputeUrlMapRead(d *schema.ResourceData, meta interface{}) error { log.Printf("[DEBUG] Finished reading ComputeUrlMap %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading UrlMap: %s", err) } @@ -4908,6 +4934,19 @@ func resourceComputeUrlMapRead(d *schema.ResourceData, meta interface{}) error { } func resourceComputeUrlMapUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceComputeUrlMap().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceComputeUrlMapRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -5047,6 +5086,13 @@ func resourceComputeUrlMapUpdate(d *schema.ResourceData, meta interface{}) error } func resourceComputeUrlMapDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeUrlMap without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing UrlMap %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_url_map_generated_meta.yaml b/google-beta/services/compute/resource_compute_url_map_generated_meta.yaml index 62146566173..b5c978bf968 100644 --- a/google-beta/services/compute/resource_compute_url_map_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_url_map_generated_meta.yaml @@ -619,3 +619,5 @@ fields: - api_field: tests.service field: test.service - api_field: selfLink + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_vpn_gateway.go b/google-beta/services/compute/resource_compute_vpn_gateway.go index 9b69708df70..cee619a57ce 100644 --- a/google-beta/services/compute/resource_compute_vpn_gateway.go +++ b/google-beta/services/compute/resource_compute_vpn_gateway.go @@ -100,6 +100,7 @@ func ResourceComputeVpnGateway() *schema.Resource { return &schema.Resource{ Create: resourceComputeVpnGatewayCreate, Read: resourceComputeVpnGatewayRead, + Update: resourceComputeVpnGatewayUpdate, Delete: resourceComputeVpnGatewayDelete, Importer: &schema.ResourceImporter{ @@ -113,6 +114,7 @@ func ResourceComputeVpnGateway() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -212,6 +214,18 @@ and values are in the format tagValues/456.`, Type: schema.TypeString, Computed: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -373,6 +387,19 @@ func resourceComputeVpnGatewayRead(d *schema.ResourceData, meta interface{}) err log.Printf("[DEBUG] Finished reading ComputeVpnGateway %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading VpnGateway: %s", err) } @@ -409,7 +436,19 @@ func resourceComputeVpnGatewayRead(d *schema.ResourceData, meta interface{}) err return nil } +func resourceComputeVpnGatewayUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceComputeVpnGatewayRead(d, meta) +} + func resourceComputeVpnGatewayDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeVpnGateway without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing VpnGateway %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_vpn_gateway_generated_meta.yaml b/google-beta/services/compute/resource_compute_vpn_gateway_generated_meta.yaml index 9a74f806125..af440bae996 100644 --- a/google-beta/services/compute/resource_compute_vpn_gateway_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_vpn_gateway_generated_meta.yaml @@ -16,3 +16,5 @@ fields: - api_field: params.resourceManagerTags - api_field: region - api_field: selfLink + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_vpn_tunnel.go b/google-beta/services/compute/resource_compute_vpn_tunnel.go index 63d94869d4b..c99bdaaa710 100644 --- a/google-beta/services/compute/resource_compute_vpn_tunnel.go +++ b/google-beta/services/compute/resource_compute_vpn_tunnel.go @@ -219,6 +219,7 @@ func ResourceComputeVpnTunnel() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -570,6 +571,18 @@ internally during updates.`, Type: schema.TypeString, Computed: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -886,6 +899,19 @@ func resourceComputeVpnTunnelRead(d *schema.ResourceData, meta interface{}) erro log.Printf("[DEBUG] Finished reading ComputeVpnTunnel %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading VpnTunnel: %s", err) } @@ -923,6 +949,19 @@ func resourceComputeVpnTunnelRead(d *schema.ResourceData, meta interface{}) erro } func resourceComputeVpnTunnelUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceComputeVpnTunnel().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceComputeVpnTunnelRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1017,6 +1056,13 @@ func resourceComputeVpnTunnelUpdate(d *schema.ResourceData, meta interface{}) er } func resourceComputeVpnTunnelDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeVpnTunnel without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing VpnTunnel %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_vpn_tunnel_generated_meta.yaml b/google-beta/services/compute/resource_compute_vpn_tunnel_generated_meta.yaml index 4b9889dac30..ef60bb3d2d6 100644 --- a/google-beta/services/compute/resource_compute_vpn_tunnel_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_vpn_tunnel_generated_meta.yaml @@ -46,3 +46,5 @@ fields: - api_field: vpnGateway - api_field: vpnGatewayInterface - api_field: selfLink + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_compute_wire_group.go b/google-beta/services/compute/resource_compute_wire_group.go index d57409f6456..8871c63f6da 100644 --- a/google-beta/services/compute/resource_compute_wire_group.go +++ b/google-beta/services/compute/resource_compute_wire_group.go @@ -115,6 +115,7 @@ func ResourceComputeWireGroup() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -352,6 +353,18 @@ DISABLE_PORT: set the port line protocol down when inline probes detect a fault. Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -519,6 +532,19 @@ func resourceComputeWireGroupRead(d *schema.ResourceData, meta interface{}) erro log.Printf("[DEBUG] Finished reading ComputeWireGroup %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading WireGroup: %s", err) } @@ -556,6 +582,19 @@ func resourceComputeWireGroupRead(d *schema.ResourceData, meta interface{}) erro } func resourceComputeWireGroupUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceComputeWireGroup().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceComputeWireGroupRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -704,6 +743,13 @@ func resourceComputeWireGroupUpdate(d *schema.ResourceData, meta interface{}) er } func resourceComputeWireGroupDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ComputeWireGroup without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing WireGroup %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_compute_wire_group_generated_meta.yaml b/google-beta/services/compute/resource_compute_wire_group_generated_meta.yaml index 83779805938..81979ada937 100644 --- a/google-beta/services/compute/resource_compute_wire_group_generated_meta.yaml +++ b/google-beta/services/compute/resource_compute_wire_group_generated_meta.yaml @@ -33,3 +33,5 @@ fields: - api_field: wires.label - api_field: wires.wireProperties.bandwidthUnmetered - api_field: wires.wireProperties.faultResponse + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/compute/resource_project_usage_export_bucket.go b/google-beta/services/compute/resource_project_usage_export_bucket.go index 1c22f22f567..08df4b45b90 100644 --- a/google-beta/services/compute/resource_project_usage_export_bucket.go +++ b/google-beta/services/compute/resource_project_usage_export_bucket.go @@ -35,6 +35,7 @@ func ResourceProjectUsageBucket() *schema.Resource { return &schema.Resource{ Create: resourceProjectUsageBucketCreate, Read: resourceProjectUsageBucketRead, + Update: resourceProjectUsageBucketUpdate, Delete: resourceProjectUsageBucketDelete, Importer: &schema.ResourceImporter{ State: resourceProjectUsageBucketImportState, @@ -47,6 +48,7 @@ func ResourceProjectUsageBucket() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Schema: map[string]*schema.Schema{ @@ -69,6 +71,9 @@ func ResourceProjectUsageBucket() *schema.Resource { ForceNew: true, Description: `The project to set the export bucket on. If it is not provided, the provider project is used.`, }, + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end }, UseJSONNumber: true, } @@ -106,6 +111,11 @@ func resourceProjectUsageBucketRead(d *schema.ResourceData, meta interface{}) er if err := d.Set("bucket_name", p.UsageExportLocation.BucketName); err != nil { return fmt.Errorf("Error setting bucket_name: %s", err) } + + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + return nil } @@ -142,7 +152,22 @@ func resourceProjectUsageBucketCreate(d *schema.ResourceData, meta interface{}) return resourceProjectUsageBucketRead(d, meta) } +// UDP update start +func resourceProjectUsageBucketUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceProjectUsageBucketRead(d, meta) +} + +//UDP update end + func resourceProjectUsageBucketDelete(d *schema.ResourceData, meta interface{}) error { + + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { + return nil + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/compute/resource_project_usage_export_bucket_meta.yaml b/google-beta/services/compute/resource_project_usage_export_bucket_meta.yaml index b9f2aab38b2..54ca6510249 100644 --- a/google-beta/services/compute/resource_project_usage_export_bucket_meta.yaml +++ b/google-beta/services/compute/resource_project_usage_export_bucket_meta.yaml @@ -11,3 +11,5 @@ fields: - api_field: 'usageExportLocation.reportNamePrefix' field: 'prefix' - field: 'project' + - field: 'deletion_policy' + provider_only: true diff --git a/google-beta/services/contactcenterinsights/resource_contact_center_insights_analysis_rule.go b/google-beta/services/contactcenterinsights/resource_contact_center_insights_analysis_rule.go index ee39f5549e5..ebc40b9403a 100644 --- a/google-beta/services/contactcenterinsights/resource_contact_center_insights_analysis_rule.go +++ b/google-beta/services/contactcenterinsights/resource_contact_center_insights_analysis_rule.go @@ -115,6 +115,7 @@ func ResourceContactCenterInsightsAnalysisRule() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -331,6 +332,18 @@ for details.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -488,6 +501,19 @@ func resourceContactCenterInsightsAnalysisRuleRead(d *schema.ResourceData, meta log.Printf("[DEBUG] Finished reading ContactCenterInsightsAnalysisRule %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading AnalysisRule: %s", err) } @@ -525,6 +551,19 @@ func resourceContactCenterInsightsAnalysisRuleRead(d *schema.ResourceData, meta } func resourceContactCenterInsightsAnalysisRuleUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceContactCenterInsightsAnalysisRule().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceContactCenterInsightsAnalysisRuleRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -656,6 +695,13 @@ func resourceContactCenterInsightsAnalysisRuleUpdate(d *schema.ResourceData, met } func resourceContactCenterInsightsAnalysisRuleDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ContactCenterInsightsAnalysisRule without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing AnalysisRule %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/contactcenterinsights/resource_contact_center_insights_analysis_rule_generated_meta.yaml b/google-beta/services/contactcenterinsights/resource_contact_center_insights_analysis_rule_generated_meta.yaml index 50d9af33782..12cb7174a31 100644 --- a/google-beta/services/contactcenterinsights/resource_contact_center_insights_analysis_rule_generated_meta.yaml +++ b/google-beta/services/contactcenterinsights/resource_contact_center_insights_analysis_rule_generated_meta.yaml @@ -31,3 +31,5 @@ fields: provider_only: true - api_field: name - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/contactcenterinsights/resource_contact_center_insights_assessment_rule.go b/google-beta/services/contactcenterinsights/resource_contact_center_insights_assessment_rule.go index 407a165fb87..fca50682fca 100644 --- a/google-beta/services/contactcenterinsights/resource_contact_center_insights_assessment_rule.go +++ b/google-beta/services/contactcenterinsights/resource_contact_center_insights_assessment_rule.go @@ -115,6 +115,7 @@ func ResourceContactCenterInsightsAssessmentRule() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -275,6 +276,18 @@ projects/{project}/locations/{location}/assessmentRules/{assessment_rule}`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -426,6 +439,19 @@ func resourceContactCenterInsightsAssessmentRuleRead(d *schema.ResourceData, met log.Printf("[DEBUG] Finished reading ContactCenterInsightsAssessmentRule %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading AssessmentRule: %s", err) } @@ -463,6 +489,19 @@ func resourceContactCenterInsightsAssessmentRuleRead(d *schema.ResourceData, met } func resourceContactCenterInsightsAssessmentRuleUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceContactCenterInsightsAssessmentRule().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceContactCenterInsightsAssessmentRuleRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -584,6 +623,13 @@ func resourceContactCenterInsightsAssessmentRuleUpdate(d *schema.ResourceData, m } func resourceContactCenterInsightsAssessmentRuleDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ContactCenterInsightsAssessmentRule without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing AssessmentRule %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/contactcenterinsights/resource_contact_center_insights_assessment_rule_generated_meta.yaml b/google-beta/services/contactcenterinsights/resource_contact_center_insights_assessment_rule_generated_meta.yaml index b8179933bc6..23ca1f3ebc1 100644 --- a/google-beta/services/contactcenterinsights/resource_contact_center_insights_assessment_rule_generated_meta.yaml +++ b/google-beta/services/contactcenterinsights/resource_contact_center_insights_assessment_rule_generated_meta.yaml @@ -25,3 +25,5 @@ fields: - api_field: scheduleInfo.startTime - api_field: scheduleInfo.timeZone - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/contactcenterinsights/resource_contact_center_insights_auto_labeling_rule.go b/google-beta/services/contactcenterinsights/resource_contact_center_insights_auto_labeling_rule.go index 160225e3307..ba61d3b1517 100644 --- a/google-beta/services/contactcenterinsights/resource_contact_center_insights_auto_labeling_rule.go +++ b/google-beta/services/contactcenterinsights/resource_contact_center_insights_auto_labeling_rule.go @@ -115,6 +115,7 @@ func ResourceContactCenterInsightsAutoLabelingRule() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -228,6 +229,18 @@ projects/{project}/locations/{location}/autoLabelingRules/{auto_labeling_rule}`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -391,6 +404,19 @@ func resourceContactCenterInsightsAutoLabelingRuleRead(d *schema.ResourceData, m log.Printf("[DEBUG] Finished reading ContactCenterInsightsAutoLabelingRule %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading AutoLabelingRule: %s", err) } @@ -428,6 +454,19 @@ func resourceContactCenterInsightsAutoLabelingRuleRead(d *schema.ResourceData, m } func resourceContactCenterInsightsAutoLabelingRuleUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceContactCenterInsightsAutoLabelingRule().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceContactCenterInsightsAutoLabelingRuleRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -569,6 +608,13 @@ func resourceContactCenterInsightsAutoLabelingRuleUpdate(d *schema.ResourceData, } func resourceContactCenterInsightsAutoLabelingRuleDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ContactCenterInsightsAutoLabelingRule without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing AutoLabelingRule %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/contactcenterinsights/resource_contact_center_insights_auto_labeling_rule_generated_meta.yaml b/google-beta/services/contactcenterinsights/resource_contact_center_insights_auto_labeling_rule_generated_meta.yaml index 3c818cb19dd..b75a036c50e 100644 --- a/google-beta/services/contactcenterinsights/resource_contact_center_insights_auto_labeling_rule_generated_meta.yaml +++ b/google-beta/services/contactcenterinsights/resource_contact_center_insights_auto_labeling_rule_generated_meta.yaml @@ -22,3 +22,5 @@ fields: provider_only: true - api_field: name - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/contactcenterinsights/resource_contact_center_insights_qa_question.go b/google-beta/services/contactcenterinsights/resource_contact_center_insights_qa_question.go index 2ebe2304743..02aebb2d2a8 100644 --- a/google-beta/services/contactcenterinsights/resource_contact_center_insights_qa_question.go +++ b/google-beta/services/contactcenterinsights/resource_contact_center_insights_qa_question.go @@ -115,6 +115,7 @@ func ResourceContactCenterInsightsQaQuestion() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -371,6 +372,18 @@ projects/{project}/locations/{location}/qaScorecards/{qa_scorecard}/revisions/{r Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -574,6 +587,19 @@ func resourceContactCenterInsightsQaQuestionRead(d *schema.ResourceData, meta in log.Printf("[DEBUG] Finished reading ContactCenterInsightsQaQuestion %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading QaQuestion: %s", err) } @@ -623,6 +649,19 @@ func resourceContactCenterInsightsQaQuestionRead(d *schema.ResourceData, meta in } func resourceContactCenterInsightsQaQuestionUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceContactCenterInsightsQaQuestion().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceContactCenterInsightsQaQuestionRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -824,6 +863,13 @@ func resourceContactCenterInsightsQaQuestionUpdate(d *schema.ResourceData, meta } func resourceContactCenterInsightsQaQuestionDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ContactCenterInsightsQaQuestion without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing QaQuestion %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/contactcenterinsights/resource_contact_center_insights_qa_question_generated_meta.yaml b/google-beta/services/contactcenterinsights/resource_contact_center_insights_qa_question_generated_meta.yaml index 33d3580415d..fb93774110a 100644 --- a/google-beta/services/contactcenterinsights/resource_contact_center_insights_qa_question_generated_meta.yaml +++ b/google-beta/services/contactcenterinsights/resource_contact_center_insights_qa_question_generated_meta.yaml @@ -35,3 +35,5 @@ fields: - api_field: tuningMetadata.totalValidLabelCount - api_field: tuningMetadata.tuningError - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/contactcenterinsights/resource_contact_center_insights_qa_scorecard.go b/google-beta/services/contactcenterinsights/resource_contact_center_insights_qa_scorecard.go index 5832017c293..8df6cef5fe9 100644 --- a/google-beta/services/contactcenterinsights/resource_contact_center_insights_qa_scorecard.go +++ b/google-beta/services/contactcenterinsights/resource_contact_center_insights_qa_scorecard.go @@ -115,6 +115,7 @@ func ResourceContactCenterInsightsQaScorecard() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -205,6 +206,18 @@ projects/{project}/locations/{location}/qaScorecards/{qa_scorecard}`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -350,6 +363,19 @@ func resourceContactCenterInsightsQaScorecardRead(d *schema.ResourceData, meta i log.Printf("[DEBUG] Finished reading ContactCenterInsightsQaScorecard %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading QaScorecard: %s", err) } @@ -387,6 +413,19 @@ func resourceContactCenterInsightsQaScorecardRead(d *schema.ResourceData, meta i } func resourceContactCenterInsightsQaScorecardUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceContactCenterInsightsQaScorecard().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceContactCenterInsightsQaScorecardRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -508,6 +547,13 @@ func resourceContactCenterInsightsQaScorecardUpdate(d *schema.ResourceData, meta } func resourceContactCenterInsightsQaScorecardDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ContactCenterInsightsQaScorecard without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing QaScorecard %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/contactcenterinsights/resource_contact_center_insights_qa_scorecard_generated_meta.yaml b/google-beta/services/contactcenterinsights/resource_contact_center_insights_qa_scorecard_generated_meta.yaml index a5d3c358dc0..14386536314 100644 --- a/google-beta/services/contactcenterinsights/resource_contact_center_insights_qa_scorecard_generated_meta.yaml +++ b/google-beta/services/contactcenterinsights/resource_contact_center_insights_qa_scorecard_generated_meta.yaml @@ -19,3 +19,5 @@ fields: provider_only: true - api_field: source - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/contactcenterinsights/resource_contact_center_insights_view.go b/google-beta/services/contactcenterinsights/resource_contact_center_insights_view.go index d240a6f35e1..64b1f0541f4 100644 --- a/google-beta/services/contactcenterinsights/resource_contact_center_insights_view.go +++ b/google-beta/services/contactcenterinsights/resource_contact_center_insights_view.go @@ -115,6 +115,7 @@ func ResourceContactCenterInsightsView() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -180,6 +181,18 @@ for details.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -319,6 +332,19 @@ func resourceContactCenterInsightsViewRead(d *schema.ResourceData, meta interfac log.Printf("[DEBUG] Finished reading ContactCenterInsightsView %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading View: %s", err) } @@ -356,6 +382,19 @@ func resourceContactCenterInsightsViewRead(d *schema.ResourceData, meta interfac } func resourceContactCenterInsightsViewUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceContactCenterInsightsView().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceContactCenterInsightsViewRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -457,6 +496,13 @@ func resourceContactCenterInsightsViewUpdate(d *schema.ResourceData, meta interf } func resourceContactCenterInsightsViewDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ContactCenterInsightsView without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing View %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/contactcenterinsights/resource_contact_center_insights_view_generated_meta.yaml b/google-beta/services/contactcenterinsights/resource_contact_center_insights_view_generated_meta.yaml index 686e508e6c6..45642ee59dd 100644 --- a/google-beta/services/contactcenterinsights/resource_contact_center_insights_view_generated_meta.yaml +++ b/google-beta/services/contactcenterinsights/resource_contact_center_insights_view_generated_meta.yaml @@ -15,3 +15,5 @@ fields: - api_field: name - api_field: updateTime - api_field: value + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/container/resource_container_cluster.go b/google-beta/services/container/resource_container_cluster.go index 297807b4ee3..3088446d502 100644 --- a/google-beta/services/container/resource_container_cluster.go +++ b/google-beta/services/container/resource_container_cluster.go @@ -241,6 +241,7 @@ func ResourceContainerCluster() *schema.Resource { Delete: resourceContainerClusterDelete, CustomizeDiff: customdiff.All( + tpgresource.DefaultProviderDeletionPolicy("DELETE"), resourceNodeConfigEmptyGuestAccelerator, customdiff.ForceNewIfChange("enable_l4_ilb_subsetting", isBeenEnabled), customdiff.ForceNewIfChange("enable_fqdn_network_policy", isBeenEnabled), @@ -2842,6 +2843,9 @@ func ResourceContainerCluster() *schema.Resource { }, }, }, + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end }, } } @@ -3808,10 +3812,19 @@ func resourceContainerClusterRead(d *schema.ResourceData, meta interface{}) erro return err } + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + return nil } func resourceContainerClusterUpdate(d *schema.ResourceData, meta interface{}) error { + + if tpgresource.DeletionPolicyPreUpdate(d, ResourceContainerCluster) { + return ResourceContainerCluster().Read(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -5590,6 +5603,13 @@ func resourceContainerClusterUpdate(d *schema.ResourceData, meta interface{}) er } func resourceContainerClusterDelete(d *schema.ResourceData, meta interface{}) error { + + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { + return nil + } + if d.Get("deletion_protection").(bool) { return fmt.Errorf("Cannot destroy cluster because deletion_protection is set to true. Set it to false to proceed with cluster deletion.") } diff --git a/google-beta/services/container/resource_container_cluster_meta.yaml b/google-beta/services/container/resource_container_cluster_meta.yaml index 6e01b72cf1f..2ee02858c56 100644 --- a/google-beta/services/container/resource_container_cluster_meta.yaml +++ b/google-beta/services/container/resource_container_cluster_meta.yaml @@ -841,3 +841,5 @@ fields: - api_field: 'verticalPodAutoscaling.enabled' - api_field: 'workloadAltsConfig.enableAlts' - api_field: 'workloadIdentityConfig.workloadPool' + - field: 'deletion_policy' + provider_only: true diff --git a/google-beta/services/container/resource_container_node_pool.go b/google-beta/services/container/resource_container_node_pool.go index e634f0f8249..d7ff1539f17 100644 --- a/google-beta/services/container/resource_container_node_pool.go +++ b/google-beta/services/container/resource_container_node_pool.go @@ -212,6 +212,7 @@ func ResourceContainerNodePool() *schema.Resource { }, CustomizeDiff: customdiff.All( + tpgresource.DefaultProviderDeletionPolicy("DELETE"), tpgresource.DefaultProviderProject, resourceNodeConfigEmptyGuestAccelerator, nodePoolAcceleratorNetworkProfileCustomizeDiff, @@ -246,6 +247,9 @@ func ResourceContainerNodePool() *schema.Resource { Type: schema.TypeString, Computed: true, }, + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end }), } } @@ -946,10 +950,19 @@ func resourceContainerNodePoolRead(d *schema.ResourceData, meta interface{}) err return fmt.Errorf("Error setting project: %s", err) } + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + return nil } func resourceContainerNodePoolUpdate(d *schema.ResourceData, meta interface{}) error { + + if tpgresource.DeletionPolicyPreUpdate(d, ResourceContainerNodePool) { + return ResourceContainerNodePool().Read(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -989,6 +1002,13 @@ func resourceContainerNodePoolUpdate(d *schema.ResourceData, meta interface{}) e } func resourceContainerNodePoolDelete(d *schema.ResourceData, meta interface{}) error { + + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { + return nil + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/container/resource_container_node_pool_meta.yaml b/google-beta/services/container/resource_container_node_pool_meta.yaml index 01881b7fef6..92ac858b1e9 100644 --- a/google-beta/services/container/resource_container_node_pool_meta.yaml +++ b/google-beta/services/container/resource_container_node_pool_meta.yaml @@ -326,3 +326,5 @@ fields: - api_field: 'upgradeSettings.maxUnavailable' - api_field: 'upgradeSettings.strategy' - api_field: 'version' + - field: 'deletion_policy' + provider_only: true diff --git a/google-beta/services/containeranalysis/resource_container_analysis_note.go b/google-beta/services/containeranalysis/resource_container_analysis_note.go index f6b825d5adb..036c0c6a0ab 100644 --- a/google-beta/services/containeranalysis/resource_container_analysis_note.go +++ b/google-beta/services/containeranalysis/resource_container_analysis_note.go @@ -115,6 +115,7 @@ func ResourceContainerAnalysisNote() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -236,6 +237,18 @@ example "qa".`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -435,6 +448,19 @@ func resourceContainerAnalysisNoteRead(d *schema.ResourceData, meta interface{}) return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Note: %s", err) } @@ -466,6 +492,19 @@ func resourceContainerAnalysisNoteRead(d *schema.ResourceData, meta interface{}) } func resourceContainerAnalysisNoteUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceContainerAnalysisNote().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceContainerAnalysisNoteRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -614,6 +653,13 @@ func resourceContainerAnalysisNoteUpdate(d *schema.ResourceData, meta interface{ } func resourceContainerAnalysisNoteDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ContainerAnalysisNote without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Note %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/containeranalysis/resource_container_analysis_note_generated_meta.yaml b/google-beta/services/containeranalysis/resource_container_analysis_note_generated_meta.yaml index 33e771f0f76..8114ebb7a85 100644 --- a/google-beta/services/containeranalysis/resource_container_analysis_note_generated_meta.yaml +++ b/google-beta/services/containeranalysis/resource_container_analysis_note_generated_meta.yaml @@ -18,3 +18,5 @@ fields: - api_field: relatedUrl.url - api_field: shortDescription - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/containeranalysis/resource_container_analysis_occurrence.go b/google-beta/services/containeranalysis/resource_container_analysis_occurrence.go index 0ed91fa4a61..ff660bafa5a 100644 --- a/google-beta/services/containeranalysis/resource_container_analysis_occurrence.go +++ b/google-beta/services/containeranalysis/resource_container_analysis_occurrence.go @@ -115,6 +115,7 @@ func ResourceContainerAnalysisOccurrence() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -220,6 +221,18 @@ requests.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -423,6 +436,19 @@ func resourceContainerAnalysisOccurrenceRead(d *schema.ResourceData, meta interf return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Occurrence: %s", err) } @@ -454,6 +480,19 @@ func resourceContainerAnalysisOccurrenceRead(d *schema.ResourceData, meta interf } func resourceContainerAnalysisOccurrenceUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceContainerAnalysisOccurrence().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceContainerAnalysisOccurrenceRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -562,6 +601,13 @@ func resourceContainerAnalysisOccurrenceUpdate(d *schema.ResourceData, meta inte } func resourceContainerAnalysisOccurrenceDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ContainerAnalysisOccurrence without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Occurrence %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/containeranalysis/resource_container_analysis_occurrence_generated_meta.yaml b/google-beta/services/containeranalysis/resource_container_analysis_occurrence_generated_meta.yaml index 11cfa487312..370a0ba4b84 100644 --- a/google-beta/services/containeranalysis/resource_container_analysis_occurrence_generated_meta.yaml +++ b/google-beta/services/containeranalysis/resource_container_analysis_occurrence_generated_meta.yaml @@ -17,3 +17,5 @@ fields: - api_field: remediation - api_field: resourceUri - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/containerattached/resource_container_attached_cluster.go b/google-beta/services/containerattached/resource_container_attached_cluster.go index ea08a4f2f96..d239872734f 100644 --- a/google-beta/services/containerattached/resource_container_attached_cluster.go +++ b/google-beta/services/containerattached/resource_container_attached_cluster.go @@ -127,6 +127,7 @@ func ResourceContainerAttachedCluster() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetAnnotationsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -497,18 +498,18 @@ the Workload Identity Pool.`, }, }, }, - "deletion_policy": { - Type: schema.TypeString, - Optional: true, - Description: `Policy to determine what flags to send on delete. Possible values: DELETE, DELETE_IGNORE_ERRORS`, - Default: "DELETE", - }, "project": { Type: schema.TypeString, Optional: true, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `This field uses a custom implementation please refer to documentation under /hashicorp/terraform-provider-google-beta/website/docs/r/container_attached_cluster.html.markdown for specifics`, + }, }, UseJSONNumber: true, } @@ -720,8 +721,15 @@ func resourceContainerAttachedClusterRead(d *schema.ResourceData, meta interface // Explicitly set virtual fields to default values if unset if _, ok := d.GetOkExists("deletion_policy"); !ok { - if err := d.Set("deletion_policy", "DELETE"); err != nil { - return fmt.Errorf("Error setting deletion_policy: %s", err) + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } } } if err := d.Set("project", project); err != nil { @@ -761,6 +769,19 @@ func resourceContainerAttachedClusterRead(d *schema.ResourceData, meta interface } func resourceContainerAttachedClusterUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceContainerAttachedCluster().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceContainerAttachedClusterRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -995,6 +1016,13 @@ func resourceContainerAttachedClusterUpdate(d *schema.ResourceData, meta interfa } func resourceContainerAttachedClusterDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ContainerAttachedCluster without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Cluster %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1075,9 +1103,6 @@ func resourceContainerAttachedClusterImport(d *schema.ResourceData, meta interfa d.SetId(id) // Explicitly set virtual fields to default values on import - if err := d.Set("deletion_policy", "DELETE"); err != nil { - return nil, fmt.Errorf("Error setting deletion_policy: %s", err) - } return []*schema.ResourceData{d}, nil } diff --git a/google-beta/services/containerattached/resource_container_attached_cluster_generated_meta.yaml b/google-beta/services/containerattached/resource_container_attached_cluster_generated_meta.yaml index 08f606cb5f7..21011d31d7b 100644 --- a/google-beta/services/containerattached/resource_container_attached_cluster_generated_meta.yaml +++ b/google-beta/services/containerattached/resource_container_attached_cluster_generated_meta.yaml @@ -13,8 +13,6 @@ fields: - api_field: binaryAuthorization.evaluationMode - api_field: clusterRegion - api_field: createTime - - field: deletion_policy - provider_only: true - api_field: description - api_field: distribution - field: effective_annotations @@ -41,3 +39,5 @@ fields: - api_field: workloadIdentityConfig.identityProvider - api_field: workloadIdentityConfig.issuerUri - api_field: workloadIdentityConfig.workloadPool + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/containeraws/resource_container_aws_cluster.go b/google-beta/services/containeraws/resource_container_aws_cluster.go index c08535b36bf..ae4ced9b127 100644 --- a/google-beta/services/containeraws/resource_container_aws_cluster.go +++ b/google-beta/services/containeraws/resource_container_aws_cluster.go @@ -49,6 +49,7 @@ func ResourceContainerAwsCluster() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, tpgresource.SetAnnotationsDiff, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Schema: map[string]*schema.Schema{ @@ -200,6 +201,9 @@ func ResourceContainerAwsCluster() *schema.Resource { Description: "Output only. Workload Identity settings.", Elem: ContainerAwsClusterWorkloadIdentityConfigSchema(), }, + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end }, } } @@ -829,9 +833,18 @@ func resourceContainerAwsClusterRead(d *schema.ResourceData, meta interface{}) e return fmt.Errorf("error setting workload_identity_config in state: %s", err) } + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + return nil } func resourceContainerAwsClusterUpdate(d *schema.ResourceData, meta interface{}) error { + + if tpgresource.DeletionPolicyPreUpdate(d, ResourceContainerAwsCluster) { + return ResourceContainerAwsCluster().Read(d, meta) + } + config := meta.(*transport_tpg.Config) project, err := tpgresource.GetProject(d, config) if err != nil { @@ -886,6 +899,13 @@ func resourceContainerAwsClusterUpdate(d *schema.ResourceData, meta interface{}) } func resourceContainerAwsClusterDelete(d *schema.ResourceData, meta interface{}) error { + + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { + return nil + } + config := meta.(*transport_tpg.Config) project, err := tpgresource.GetProject(d, config) if err != nil { diff --git a/google-beta/services/containeraws/resource_container_aws_cluster_meta.yaml b/google-beta/services/containeraws/resource_container_aws_cluster_meta.yaml index 015dae4cb62..b14e342366c 100644 --- a/google-beta/services/containeraws/resource_container_aws_cluster_meta.yaml +++ b/google-beta/services/containeraws/resource_container_aws_cluster_meta.yaml @@ -58,3 +58,5 @@ fields: - api_field: 'workloadIdentityConfig.identityProvider' - api_field: 'workloadIdentityConfig.issuerUri' - api_field: 'workloadIdentityConfig.workloadPool' + - field: 'deletion_policy' + provider_only: true diff --git a/google-beta/services/containeraws/resource_container_aws_node_pool.go b/google-beta/services/containeraws/resource_container_aws_node_pool.go index cf10bcef1a6..7c8565b071e 100644 --- a/google-beta/services/containeraws/resource_container_aws_node_pool.go +++ b/google-beta/services/containeraws/resource_container_aws_node_pool.go @@ -50,6 +50,7 @@ func ResourceContainerAwsNodePool() *schema.Resource { tpgresource.DefaultProviderProject, dcl.ResourceContainerAwsNodePoolCustomizeDiffFunc, tpgresource.SetAnnotationsDiff, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Schema: map[string]*schema.Schema{ @@ -198,6 +199,10 @@ func ResourceContainerAwsNodePool() *schema.Resource { Computed: true, Description: "Output only. The time at which this node pool was last updated.", }, + + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end }, } } @@ -754,9 +759,18 @@ func resourceContainerAwsNodePoolRead(d *schema.ResourceData, meta interface{}) return fmt.Errorf("error setting update_time in state: %s", err) } + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + return nil } func resourceContainerAwsNodePoolUpdate(d *schema.ResourceData, meta interface{}) error { + + if tpgresource.DeletionPolicyPreUpdate(d, ResourceContainerAwsNodePool) { + return ResourceContainerAwsNodePool().Read(d, meta) + } + config := meta.(*transport_tpg.Config) project, err := tpgresource.GetProject(d, config) if err != nil { @@ -812,6 +826,13 @@ func resourceContainerAwsNodePoolUpdate(d *schema.ResourceData, meta interface{} } func resourceContainerAwsNodePoolDelete(d *schema.ResourceData, meta interface{}) error { + + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { + return nil + } + config := meta.(*transport_tpg.Config) project, err := tpgresource.GetProject(d, config) if err != nil { diff --git a/google-beta/services/containeraws/resource_container_aws_node_pool_meta.yaml b/google-beta/services/containeraws/resource_container_aws_node_pool_meta.yaml index 84038ff8c6c..cc1ec936f61 100644 --- a/google-beta/services/containeraws/resource_container_aws_node_pool_meta.yaml +++ b/google-beta/services/containeraws/resource_container_aws_node_pool_meta.yaml @@ -53,3 +53,5 @@ fields: - api_field: 'updateSettings.surgeSettings.maxUnavailable' - api_field: 'updateTime' - api_field: 'version' + - field: 'deletion_policy' + provider_only: true diff --git a/google-beta/services/containerazure/resource_container_azure_client.go b/google-beta/services/containerazure/resource_container_azure_client.go index a631b30e968..24c4e69a879 100644 --- a/google-beta/services/containerazure/resource_container_azure_client.go +++ b/google-beta/services/containerazure/resource_container_azure_client.go @@ -37,6 +37,7 @@ func ResourceContainerAzureClient() *schema.Resource { return &schema.Resource{ Create: resourceContainerAzureClientCreate, Read: resourceContainerAzureClientRead, + Update: resourceContainerAzureClientUpdate, Delete: resourceContainerAzureClientDelete, Importer: &schema.ResourceImporter{ @@ -49,6 +50,7 @@ func ResourceContainerAzureClient() *schema.Resource { }, CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Schema: map[string]*schema.Schema{ @@ -106,6 +108,9 @@ func ResourceContainerAzureClient() *schema.Resource { Computed: true, Description: "Output only. A globally unique identifier for the client.", }, + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end }, } } @@ -224,10 +229,29 @@ func resourceContainerAzureClientRead(d *schema.ResourceData, meta interface{}) return fmt.Errorf("error setting uid in state: %s", err) } + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + return nil } +// UDP update start +func resourceContainerAzureClientUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceContainerAzureClientRead(d, meta) +} + +//UDP update end + func resourceContainerAzureClientDelete(d *schema.ResourceData, meta interface{}) error { + + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { + return nil + } + config := meta.(*transport_tpg.Config) project, err := tpgresource.GetProject(d, config) if err != nil { diff --git a/google-beta/services/containerazure/resource_container_azure_client_meta.yaml b/google-beta/services/containerazure/resource_container_azure_client_meta.yaml index 0a4ff210698..e66b01f4917 100644 --- a/google-beta/services/containerazure/resource_container_azure_client_meta.yaml +++ b/google-beta/services/containerazure/resource_container_azure_client_meta.yaml @@ -14,3 +14,5 @@ fields: - field: 'project' - api_field: 'tenantId' - api_field: 'uid' + - field: 'deletion_policy' + provider_only: true diff --git a/google-beta/services/containerazure/resource_container_azure_cluster.go b/google-beta/services/containerazure/resource_container_azure_cluster.go index 8b4d8337fce..686a3b54432 100644 --- a/google-beta/services/containerazure/resource_container_azure_cluster.go +++ b/google-beta/services/containerazure/resource_container_azure_cluster.go @@ -49,6 +49,7 @@ func ResourceContainerAzureCluster() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, tpgresource.SetAnnotationsDiff, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Schema: map[string]*schema.Schema{ @@ -216,6 +217,9 @@ func ResourceContainerAzureCluster() *schema.Resource { Description: "Output only. Workload Identity settings.", Elem: ContainerAzureClusterWorkloadIdentityConfigSchema(), }, + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end }, } } @@ -744,9 +748,18 @@ func resourceContainerAzureClusterRead(d *schema.ResourceData, meta interface{}) return fmt.Errorf("error setting workload_identity_config in state: %s", err) } + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + return nil } func resourceContainerAzureClusterUpdate(d *schema.ResourceData, meta interface{}) error { + + if tpgresource.DeletionPolicyPreUpdate(d, ResourceContainerAzureCluster) { + return ResourceContainerAzureCluster().Read(d, meta) + } + config := meta.(*transport_tpg.Config) project, err := tpgresource.GetProject(d, config) if err != nil { @@ -803,6 +816,13 @@ func resourceContainerAzureClusterUpdate(d *schema.ResourceData, meta interface{ } func resourceContainerAzureClusterDelete(d *schema.ResourceData, meta interface{}) error { + + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { + return nil + } + config := meta.(*transport_tpg.Config) project, err := tpgresource.GetProject(d, config) if err != nil { diff --git a/google-beta/services/containerazure/resource_container_azure_cluster_meta.yaml b/google-beta/services/containerazure/resource_container_azure_cluster_meta.yaml index b96be36a39a..a6370c56949 100644 --- a/google-beta/services/containerazure/resource_container_azure_cluster_meta.yaml +++ b/google-beta/services/containerazure/resource_container_azure_cluster_meta.yaml @@ -48,3 +48,5 @@ fields: - api_field: 'workloadIdentityConfig.identityProvider' - api_field: 'workloadIdentityConfig.issuerUri' - api_field: 'workloadIdentityConfig.workloadPool' + - field: 'deletion_policy' + provider_only: true diff --git a/google-beta/services/containerazure/resource_container_azure_node_pool.go b/google-beta/services/containerazure/resource_container_azure_node_pool.go index 039e9e055be..f7b8aa4473d 100644 --- a/google-beta/services/containerazure/resource_container_azure_node_pool.go +++ b/google-beta/services/containerazure/resource_container_azure_node_pool.go @@ -49,6 +49,7 @@ func ResourceContainerAzureNodePool() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, tpgresource.SetAnnotationsDiff, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Schema: map[string]*schema.Schema{ @@ -186,6 +187,9 @@ func ResourceContainerAzureNodePool() *schema.Resource { Computed: true, Description: "Output only. The time at which this node pool was last updated.", }, + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end }, } } @@ -506,9 +510,18 @@ func resourceContainerAzureNodePoolRead(d *schema.ResourceData, meta interface{} return fmt.Errorf("error setting update_time in state: %s", err) } + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + return nil } func resourceContainerAzureNodePoolUpdate(d *schema.ResourceData, meta interface{}) error { + + if tpgresource.DeletionPolicyPreUpdate(d, ResourceContainerAzureNodePool) { + return ResourceContainerAzureNodePool().Read(d, meta) + } + config := meta.(*transport_tpg.Config) project, err := tpgresource.GetProject(d, config) if err != nil { @@ -563,6 +576,13 @@ func resourceContainerAzureNodePoolUpdate(d *schema.ResourceData, meta interface } func resourceContainerAzureNodePoolDelete(d *schema.ResourceData, meta interface{}) error { + + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { + return nil + } + config := meta.(*transport_tpg.Config) project, err := tpgresource.GetProject(d, config) if err != nil { diff --git a/google-beta/services/containerazure/resource_container_azure_node_pool_meta.yaml b/google-beta/services/containerazure/resource_container_azure_node_pool_meta.yaml index 7f18389ef92..aca37713929 100644 --- a/google-beta/services/containerazure/resource_container_azure_node_pool_meta.yaml +++ b/google-beta/services/containerazure/resource_container_azure_node_pool_meta.yaml @@ -34,3 +34,5 @@ fields: - api_field: 'uid' - api_field: 'updateTime' - api_field: 'version' + - field: 'deletion_policy' + provider_only: true diff --git a/google-beta/services/databasemigrationservice/resource_database_migration_service_connection_profile.go b/google-beta/services/databasemigrationservice/resource_database_migration_service_connection_profile.go index db4bcf869e0..272b2053db2 100644 --- a/google-beta/services/databasemigrationservice/resource_database_migration_service_connection_profile.go +++ b/google-beta/services/databasemigrationservice/resource_database_migration_service_connection_profile.go @@ -116,6 +116,7 @@ func ResourceDatabaseMigrationServiceConnectionProfile() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -875,6 +876,18 @@ If this field is used then the 'clientCertificate' field is mandatory.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -1048,6 +1061,19 @@ func resourceDatabaseMigrationServiceConnectionProfileRead(d *schema.ResourceDat log.Printf("[DEBUG] Finished reading DatabaseMigrationServiceConnectionProfile %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading ConnectionProfile: %s", err) } @@ -1085,6 +1111,19 @@ func resourceDatabaseMigrationServiceConnectionProfileRead(d *schema.ResourceDat } func resourceDatabaseMigrationServiceConnectionProfileUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceDatabaseMigrationServiceConnectionProfile().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceDatabaseMigrationServiceConnectionProfileRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1243,6 +1282,13 @@ func resourceDatabaseMigrationServiceConnectionProfileUpdate(d *schema.ResourceD } func resourceDatabaseMigrationServiceConnectionProfileDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DatabaseMigrationServiceConnectionProfile without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing ConnectionProfile %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/databasemigrationservice/resource_database_migration_service_connection_profile_generated_meta.yaml b/google-beta/services/databasemigrationservice/resource_database_migration_service_connection_profile_generated_meta.yaml index 9ccadae8c12..4efd29d58fe 100644 --- a/google-beta/services/databasemigrationservice/resource_database_migration_service_connection_profile_generated_meta.yaml +++ b/google-beta/services/databasemigrationservice/resource_database_migration_service_connection_profile_generated_meta.yaml @@ -101,3 +101,5 @@ fields: - api_field: state - field: terraform_labels provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/databasemigrationservice/resource_database_migration_service_migration_job.go b/google-beta/services/databasemigrationservice/resource_database_migration_service_migration_job.go index 3026a7ba0c8..1e6d2aaf7aa 100644 --- a/google-beta/services/databasemigrationservice/resource_database_migration_service_migration_job.go +++ b/google-beta/services/databasemigrationservice/resource_database_migration_service_migration_job.go @@ -116,6 +116,7 @@ func ResourceDatabaseMigrationServiceMigrationJob() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -463,6 +464,18 @@ Cloud SQL console or using Cloud SQL APIs.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -672,6 +685,19 @@ func resourceDatabaseMigrationServiceMigrationJobRead(d *schema.ResourceData, me log.Printf("[DEBUG] Finished reading DatabaseMigrationServiceMigrationJob %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading MigrationJob: %s", err) } @@ -709,6 +735,19 @@ func resourceDatabaseMigrationServiceMigrationJobRead(d *schema.ResourceData, me } func resourceDatabaseMigrationServiceMigrationJobUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceDatabaseMigrationServiceMigrationJob().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceDatabaseMigrationServiceMigrationJobRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -887,6 +926,13 @@ func resourceDatabaseMigrationServiceMigrationJobUpdate(d *schema.ResourceData, } func resourceDatabaseMigrationServiceMigrationJobDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DatabaseMigrationServiceMigrationJob without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing MigrationJob %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/databasemigrationservice/resource_database_migration_service_migration_job_generated_meta.yaml b/google-beta/services/databasemigrationservice/resource_database_migration_service_migration_job_generated_meta.yaml index 5fe386d9c36..28ef562b8fc 100644 --- a/google-beta/services/databasemigrationservice/resource_database_migration_service_migration_job_generated_meta.yaml +++ b/google-beta/services/databasemigrationservice/resource_database_migration_service_migration_job_generated_meta.yaml @@ -43,3 +43,5 @@ fields: provider_only: true - api_field: type - api_field: vpcPeeringConnectivity.vpc + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/databasemigrationservice/resource_database_migration_service_private_connection.go b/google-beta/services/databasemigrationservice/resource_database_migration_service_private_connection.go index 9b3d050bd05..f9ec661bf73 100644 --- a/google-beta/services/databasemigrationservice/resource_database_migration_service_private_connection.go +++ b/google-beta/services/databasemigrationservice/resource_database_migration_service_private_connection.go @@ -116,6 +116,7 @@ func ResourceDatabaseMigrationServicePrivateConnection() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -252,6 +253,18 @@ Please refer to the field 'effective_labels' for all of the labels present on th Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -401,6 +414,19 @@ func resourceDatabaseMigrationServicePrivateConnectionRead(d *schema.ResourceDat log.Printf("[DEBUG] Finished reading DatabaseMigrationServicePrivateConnection %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading PrivateConnection: %s", err) } @@ -438,11 +464,18 @@ func resourceDatabaseMigrationServicePrivateConnectionRead(d *schema.ResourceDat } func resourceDatabaseMigrationServicePrivateConnectionUpdate(d *schema.ResourceData, meta interface{}) error { - // Only the root field "labels", "terraform_labels", and virtual fields are mutable + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable return resourceDatabaseMigrationServicePrivateConnectionRead(d, meta) } func resourceDatabaseMigrationServicePrivateConnectionDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DatabaseMigrationServicePrivateConnection without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing PrivateConnection %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/databasemigrationservice/resource_database_migration_service_private_connection_generated_meta.yaml b/google-beta/services/databasemigrationservice/resource_database_migration_service_private_connection_generated_meta.yaml index 11e42d9b19f..5a24efa914d 100644 --- a/google-beta/services/databasemigrationservice/resource_database_migration_service_private_connection_generated_meta.yaml +++ b/google-beta/services/databasemigrationservice/resource_database_migration_service_private_connection_generated_meta.yaml @@ -25,3 +25,5 @@ fields: provider_only: true - api_field: vpcPeeringConfig.subnet - api_field: vpcPeeringConfig.vpcName + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/datacatalog/resource_data_catalog_entry.go b/google-beta/services/datacatalog/resource_data_catalog_entry.go index 0f76755e46c..9c5a3064aae 100644 --- a/google-beta/services/datacatalog/resource_data_catalog_entry.go +++ b/google-beta/services/datacatalog/resource_data_catalog_entry.go @@ -335,6 +335,19 @@ Otherwise, groupedEntry is empty.`, Example: projects/{project_id}/locations/{location}/entryGroups/{entryGroupId}/entries/{entryId}. Note that this Entry and its child resources may not actually be stored in the location in this name.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -496,6 +509,20 @@ func resourceDataCatalogEntryRead(d *schema.ResourceData, meta interface{}) erro log.Printf("[DEBUG] Finished reading DataCatalogEntry %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceDataCatalogEntryFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -517,6 +544,19 @@ func resourceDataCatalogEntryRead(d *schema.ResourceData, meta interface{}) erro } func resourceDataCatalogEntryUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceDataCatalogEntry().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceDataCatalogEntryRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -655,6 +695,13 @@ func resourceDataCatalogEntryUpdate(d *schema.ResourceData, meta interface{}) er } func resourceDataCatalogEntryDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DataCatalogEntry without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Entry %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/datacatalog/resource_data_catalog_entry_generated_meta.yaml b/google-beta/services/datacatalog/resource_data_catalog_entry_generated_meta.yaml index 42242ccf0c5..cfee548d043 100644 --- a/google-beta/services/datacatalog/resource_data_catalog_entry_generated_meta.yaml +++ b/google-beta/services/datacatalog/resource_data_catalog_entry_generated_meta.yaml @@ -30,3 +30,5 @@ fields: - api_field: type - api_field: userSpecifiedSystem - api_field: userSpecifiedType + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/datacatalog/resource_data_catalog_entry_group.go b/google-beta/services/datacatalog/resource_data_catalog_entry_group.go index 5d0c53248f1..ed9906fc62c 100644 --- a/google-beta/services/datacatalog/resource_data_catalog_entry_group.go +++ b/google-beta/services/datacatalog/resource_data_catalog_entry_group.go @@ -116,6 +116,7 @@ func ResourceDataCatalogEntryGroup() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, tpgresource.DefaultProviderRegion, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), DeprecationMessage: "`google_data_catalog_entry_group` is deprecated and will be removed in a future major release. Use `google_dataplex_entry_group` instead. For steps to transition your Data Catalog users, workloads, and content to Dataplex Catalog, see https://cloud.google.com/dataplex/docs/transition-to-dataplex-catalog.", @@ -172,6 +173,18 @@ contain only English letters, numbers and underscores, and be at most 64 charact Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -301,6 +314,19 @@ func resourceDataCatalogEntryGroupRead(d *schema.ResourceData, meta interface{}) log.Printf("[DEBUG] Finished reading DataCatalogEntryGroup %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading EntryGroup: %s", err) } @@ -334,6 +360,19 @@ func resourceDataCatalogEntryGroupRead(d *schema.ResourceData, meta interface{}) } func resourceDataCatalogEntryGroupUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceDataCatalogEntryGroup().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceDataCatalogEntryGroupRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -425,6 +464,13 @@ func resourceDataCatalogEntryGroupUpdate(d *schema.ResourceData, meta interface{ } func resourceDataCatalogEntryGroupDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DataCatalogEntryGroup without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing EntryGroup %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/datacatalog/resource_data_catalog_entry_group_generated_meta.yaml b/google-beta/services/datacatalog/resource_data_catalog_entry_group_generated_meta.yaml index 0bef4c99c34..b5d166b019b 100644 --- a/google-beta/services/datacatalog/resource_data_catalog_entry_group_generated_meta.yaml +++ b/google-beta/services/datacatalog/resource_data_catalog_entry_group_generated_meta.yaml @@ -14,3 +14,5 @@ fields: - api_field: name - field: region provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/datacatalog/resource_data_catalog_policy_tag.go b/google-beta/services/datacatalog/resource_data_catalog_policy_tag.go index a81828dad7a..520ad2c9499 100644 --- a/google-beta/services/datacatalog/resource_data_catalog_policy_tag.go +++ b/google-beta/services/datacatalog/resource_data_catalog_policy_tag.go @@ -156,6 +156,19 @@ If not set, defaults to an empty string.`, Description: `Resource name of this policy tag, whose format is: "projects/{project}/locations/{region}/taxonomies/{taxonomy}/policyTags/{policytag}"`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -268,6 +281,20 @@ func resourceDataCatalogPolicyTagRead(d *schema.ResourceData, meta interface{}) log.Printf("[DEBUG] Finished reading DataCatalogPolicyTag %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceDataCatalogPolicyTagFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -277,6 +304,19 @@ func resourceDataCatalogPolicyTagRead(d *schema.ResourceData, meta interface{}) } func resourceDataCatalogPolicyTagUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceDataCatalogPolicyTag().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceDataCatalogPolicyTagRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -362,6 +402,13 @@ func resourceDataCatalogPolicyTagUpdate(d *schema.ResourceData, meta interface{} } func resourceDataCatalogPolicyTagDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DataCatalogPolicyTag without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing PolicyTag %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/datacatalog/resource_data_catalog_policy_tag_generated_meta.yaml b/google-beta/services/datacatalog/resource_data_catalog_policy_tag_generated_meta.yaml index 47f04a3d86c..fe198242c10 100644 --- a/google-beta/services/datacatalog/resource_data_catalog_policy_tag_generated_meta.yaml +++ b/google-beta/services/datacatalog/resource_data_catalog_policy_tag_generated_meta.yaml @@ -14,3 +14,5 @@ fields: - api_field: parentPolicyTag - field: taxonomy provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/datacatalog/resource_data_catalog_tag.go b/google-beta/services/datacatalog/resource_data_catalog_tag.go index fcbbcf841f2..db4a03ab32b 100644 --- a/google-beta/services/datacatalog/resource_data_catalog_tag.go +++ b/google-beta/services/datacatalog/resource_data_catalog_tag.go @@ -220,6 +220,19 @@ where tag_id is a system-generated identifier. Note that this Tag may not actual Computed: true, Description: `The display name of the tag template.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -360,6 +373,20 @@ func resourceDataCatalogTagRead(d *schema.ResourceData, meta interface{}) error return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceDataCatalogTagFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -381,6 +408,19 @@ func resourceDataCatalogTagRead(d *schema.ResourceData, meta interface{}) error } func resourceDataCatalogTagUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceDataCatalogTag().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceDataCatalogTagRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -471,6 +511,13 @@ func resourceDataCatalogTagUpdate(d *schema.ResourceData, meta interface{}) erro } func resourceDataCatalogTagDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DataCatalogTag without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Tag %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/datacatalog/resource_data_catalog_tag_generated_meta.yaml b/google-beta/services/datacatalog/resource_data_catalog_tag_generated_meta.yaml index d41e6d38284..f8ea9186259 100644 --- a/google-beta/services/datacatalog/resource_data_catalog_tag_generated_meta.yaml +++ b/google-beta/services/datacatalog/resource_data_catalog_tag_generated_meta.yaml @@ -28,3 +28,5 @@ fields: - api_field: template - api_field: templateDisplayName field: template_displayname + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/datacatalog/resource_data_catalog_tag_template.go b/google-beta/services/datacatalog/resource_data_catalog_tag_template.go index a3f36c9121b..5a83643a8a6 100644 --- a/google-beta/services/datacatalog/resource_data_catalog_tag_template.go +++ b/google-beta/services/datacatalog/resource_data_catalog_tag_template.go @@ -176,6 +176,7 @@ func ResourceDataCatalogTagTemplate() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, tpgresource.DefaultProviderRegion, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), DeprecationMessage: "`google_data_catalog_tag_template` is deprecated and will be removed in a future major release. Use `google_dataplex_aspect_type` instead. For steps to transition your Data Catalog users, workloads, and content to Dataplex Catalog, see https://cloud.google.com/dataplex/docs/transition-to-dataplex-catalog.", @@ -316,6 +317,18 @@ Multiple fields can have the same order, and field orders within a tag do not ha Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -457,6 +470,19 @@ func resourceDataCatalogTagTemplateRead(d *schema.ResourceData, meta interface{} log.Printf("[DEBUG] Finished reading DataCatalogTagTemplate %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading TagTemplate: %s", err) } @@ -490,6 +516,19 @@ func resourceDataCatalogTagTemplateRead(d *schema.ResourceData, meta interface{} } func resourceDataCatalogTagTemplateUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceDataCatalogTagTemplate().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceDataCatalogTagTemplateRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -708,6 +747,13 @@ func resourceDataCatalogTagTemplateUpdate(d *schema.ResourceData, meta interface } func resourceDataCatalogTagTemplateDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DataCatalogTagTemplate without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing TagTemplate %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/datacatalog/resource_data_catalog_tag_template_generated_meta.yaml b/google-beta/services/datacatalog/resource_data_catalog_tag_template_generated_meta.yaml index e55ce57c025..a4830630efc 100644 --- a/google-beta/services/datacatalog/resource_data_catalog_tag_template_generated_meta.yaml +++ b/google-beta/services/datacatalog/resource_data_catalog_tag_template_generated_meta.yaml @@ -31,3 +31,5 @@ fields: provider_only: true - field: tag_template_id provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/datacatalog/resource_data_catalog_taxonomy.go b/google-beta/services/datacatalog/resource_data_catalog_taxonomy.go index a832b2b378a..e059c0857cd 100644 --- a/google-beta/services/datacatalog/resource_data_catalog_taxonomy.go +++ b/google-beta/services/datacatalog/resource_data_catalog_taxonomy.go @@ -115,6 +115,7 @@ func ResourceDataCatalogTaxonomy() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -178,6 +179,18 @@ long when encoded in UTF-8. If not set, defaults to an empty description.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -313,6 +326,19 @@ func resourceDataCatalogTaxonomyRead(d *schema.ResourceData, meta interface{}) e log.Printf("[DEBUG] Finished reading DataCatalogTaxonomy %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Taxonomy: %s", err) } @@ -338,6 +364,19 @@ func resourceDataCatalogTaxonomyRead(d *schema.ResourceData, meta interface{}) e } func resourceDataCatalogTaxonomyUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceDataCatalogTaxonomy().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceDataCatalogTaxonomyRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -439,6 +478,13 @@ func resourceDataCatalogTaxonomyUpdate(d *schema.ResourceData, meta interface{}) } func resourceDataCatalogTaxonomyDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DataCatalogTaxonomy without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Taxonomy %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/datacatalog/resource_data_catalog_taxonomy_generated_meta.yaml b/google-beta/services/datacatalog/resource_data_catalog_taxonomy_generated_meta.yaml index a37f250bdb7..a395460f733 100644 --- a/google-beta/services/datacatalog/resource_data_catalog_taxonomy_generated_meta.yaml +++ b/google-beta/services/datacatalog/resource_data_catalog_taxonomy_generated_meta.yaml @@ -13,3 +13,5 @@ fields: - api_field: name - field: region provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/dataflow/resource_dataflow_flex_template_job.go b/google-beta/services/dataflow/resource_dataflow_flex_template_job.go index 1ec18ee0d2c..6f65cc2e0c3 100644 --- a/google-beta/services/dataflow/resource_dataflow_flex_template_job.go +++ b/google-beta/services/dataflow/resource_dataflow_flex_template_job.go @@ -274,6 +274,9 @@ func ResourceDataflowFlexTemplateJob() *schema.Resource { Default: false, Description: `If true, treat DRAINING and CANCELLING as terminal job states and do not wait for further changes before removing from terraform state and moving on. WARNING: this will lead to job name conflicts if you do not ensure that the job names are different, e.g. by embedding a release ID or by using a random_id.`, }, + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end }, UseJSONNumber: true, } @@ -538,6 +541,10 @@ func resourceDataflowFlexTemplateJobRead(d *schema.ResourceData, meta interface{ return nil } + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + return nil } @@ -586,6 +593,10 @@ func resourceDataflowFlexTemplateJobUpdate(d *schema.ResourceData, meta interfac return nil } + if tpgresource.DeletionPolicyPreUpdate(d, ResourceDataflowFlexTemplateJob) { + return ResourceDataflowFlexTemplateJob().Read(d, meta) + } + if jobHasUpdate(d, ResourceDataflowFlexTemplateJob().Schema) { config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) @@ -651,6 +662,13 @@ func resourceDataflowFlexTemplateJobUpdate(d *schema.ResourceData, meta interfac } func resourceDataflowFlexTemplateJobDelete(d *schema.ResourceData, meta interface{}) error { + + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { + return nil + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/dataflow/resource_dataflow_flex_template_job_meta.yaml b/google-beta/services/dataflow/resource_dataflow_flex_template_job_meta.yaml index 7457421b2d4..f8c3d90a0c2 100644 --- a/google-beta/services/dataflow/resource_dataflow_flex_template_job_meta.yaml +++ b/google-beta/services/dataflow/resource_dataflow_flex_template_job_meta.yaml @@ -38,3 +38,5 @@ fields: provider_only: true - api_field: 'transformNameMapping' - api_field: 'type' + - field: 'deletion_policy' + provider_only: true diff --git a/google-beta/services/dataflow/resource_dataflow_job.go b/google-beta/services/dataflow/resource_dataflow_job.go index 0c1dd12ae30..e5ae973bea1 100644 --- a/google-beta/services/dataflow/resource_dataflow_job.go +++ b/google-beta/services/dataflow/resource_dataflow_job.go @@ -107,6 +107,7 @@ func ResourceDataflowJob() *schema.Resource { Update: schema.DefaultTimeout(10 * time.Minute), }, CustomizeDiff: customdiff.All( + tpgresource.DefaultProviderDeletionPolicy("DELETE"), tpgresource.SetLabelsDiff, resourceDataflowJobTypeCustomizeDiff, ), @@ -294,6 +295,9 @@ func ResourceDataflowJob() *schema.Resource { Default: false, Description: `If true, treat DRAINING and CANCELLING as terminal job states and do not wait for further changes before removing from terraform state and moving on. WARNING: this will lead to job name conflicts if you do not ensure that the job names are different, e.g. by embedding a release ID or by using a random_id.`, }, + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end }, UseJSONNumber: true, } @@ -461,6 +465,10 @@ func resourceDataflowJobRead(d *schema.ResourceData, meta interface{}) error { } d.SetId(job.Id) + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + return nil } @@ -471,6 +479,10 @@ func resourceDataflowJobUpdateByReplacement(d *schema.ResourceData, meta interfa return nil } + if tpgresource.DeletionPolicyPreUpdate(d, ResourceDataflowJob) { + return ResourceDataflowJob().Read(d, meta) + } + if jobHasUpdate(d, ResourceDataflowJob().Schema) { config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) @@ -527,6 +539,13 @@ func resourceDataflowJobUpdateByReplacement(d *schema.ResourceData, meta interfa } func resourceDataflowJobDelete(d *schema.ResourceData, meta interface{}) error { + + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { + return nil + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/dataflow/resource_dataflow_job_meta.yaml b/google-beta/services/dataflow/resource_dataflow_job_meta.yaml index 4333b645ac8..92ca6c8cc80 100644 --- a/google-beta/services/dataflow/resource_dataflow_job_meta.yaml +++ b/google-beta/services/dataflow/resource_dataflow_job_meta.yaml @@ -33,3 +33,5 @@ fields: - api_field: 'transformNameMapping' - api_field: 'type' - field: 'zone' + - field: 'deletion_policy' + provider_only: true diff --git a/google-beta/services/dataform/resource_dataform_config.go b/google-beta/services/dataform/resource_dataform_config.go index 5d8ab851219..5be74e040a1 100644 --- a/google-beta/services/dataform/resource_dataform_config.go +++ b/google-beta/services/dataform/resource_dataform_config.go @@ -307,6 +307,7 @@ func resourceDataformConfigRead(d *schema.ResourceData, meta interface{}) error } func resourceDataformConfigUpdate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/dataform/resource_dataform_folder.go b/google-beta/services/dataform/resource_dataform_folder.go index 71c7280b0ad..d76162259e4 100644 --- a/google-beta/services/dataform/resource_dataform_folder.go +++ b/google-beta/services/dataform/resource_dataform_folder.go @@ -115,6 +115,7 @@ func ResourceDataformFolder() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -174,6 +175,18 @@ Format: 'projects/*/locations/*/folders/*' or 'projects/*/locations/*/teamFolder Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -316,6 +329,19 @@ func resourceDataformFolderRead(d *schema.ResourceData, meta interface{}) error log.Printf("[DEBUG] Finished reading DataformFolder %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Folder: %s", err) } @@ -353,6 +379,19 @@ func resourceDataformFolderRead(d *schema.ResourceData, meta interface{}) error } func resourceDataformFolderUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceDataformFolder().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceDataformFolderRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -454,6 +493,13 @@ func resourceDataformFolderUpdate(d *schema.ResourceData, meta interface{}) erro } func resourceDataformFolderDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DataformFolder without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Folder %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/dataform/resource_dataform_folder_generated_meta.yaml b/google-beta/services/dataform/resource_dataform_folder_generated_meta.yaml index 8e032587d1e..7eb79592039 100644 --- a/google-beta/services/dataform/resource_dataform_folder_generated_meta.yaml +++ b/google-beta/services/dataform/resource_dataform_folder_generated_meta.yaml @@ -14,3 +14,5 @@ fields: - api_field: name - field: region provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/dataform/resource_dataform_repository.go b/google-beta/services/dataform/resource_dataform_repository.go index 390af88bbc3..43c92da5b70 100644 --- a/google-beta/services/dataform/resource_dataform_repository.go +++ b/google-beta/services/dataform/resource_dataform_repository.go @@ -116,6 +116,7 @@ func ResourceDataformRepository() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -276,19 +277,18 @@ Please refer to the field 'effective_labels' for all of the labels present on th and default labels configured on the provider.`, Elem: &schema.Schema{Type: schema.TypeString}, }, - "deletion_policy": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: verify.ValidateEnum([]string{"DELETE", "FORCE", ""}), - Description: `Policy to control how the repository and its child resources are deleted. When set to 'FORCE', any child resources of this repository will also be deleted. Possible values: 'DELETE', 'FORCE'. Defaults to 'DELETE'. Default value: "DELETE" Possible values: ["DELETE", "FORCE"]`, - Default: "DELETE", - }, "project": { Type: schema.TypeString, Optional: true, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `This field uses a custom implementation please refer to documentation under /hashicorp/terraform-provider-google-beta/website/docs/r/dataform_repository.html.markdown for specifics`, + }, }, UseJSONNumber: true, } @@ -460,8 +460,15 @@ func resourceDataformRepositoryRead(d *schema.ResourceData, meta interface{}) er // Explicitly set virtual fields to default values if unset if _, ok := d.GetOkExists("deletion_policy"); !ok { - if err := d.Set("deletion_policy", "DELETE"); err != nil { - return fmt.Errorf("Error setting deletion_policy: %s", err) + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } } } if err := d.Set("project", project); err != nil { @@ -501,6 +508,19 @@ func resourceDataformRepositoryRead(d *schema.ResourceData, meta interface{}) er } func resourceDataformRepositoryUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceDataformRepository().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceDataformRepositoryRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -613,6 +633,13 @@ func resourceDataformRepositoryUpdate(d *schema.ResourceData, meta interface{}) } func resourceDataformRepositoryDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DataformRepository without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Repository %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -688,9 +715,6 @@ func resourceDataformRepositoryImport(d *schema.ResourceData, meta interface{}) d.SetId(id) // Explicitly set virtual fields to default values on import - if err := d.Set("deletion_policy", "DELETE"); err != nil { - return nil, fmt.Errorf("Error setting deletion_policy: %s", err) - } return []*schema.ResourceData{d}, nil } diff --git a/google-beta/services/dataform/resource_dataform_repository_generated_meta.yaml b/google-beta/services/dataform/resource_dataform_repository_generated_meta.yaml index 8a586ea85c9..789776acdb6 100644 --- a/google-beta/services/dataform/resource_dataform_repository_generated_meta.yaml +++ b/google-beta/services/dataform/resource_dataform_repository_generated_meta.yaml @@ -7,8 +7,6 @@ api_service_name: dataform.googleapis.com api_version: v1beta1 api_resource_type_kind: Repository fields: - - field: deletion_policy - provider_only: true - api_field: displayName - field: effective_labels provider_only: true @@ -30,3 +28,5 @@ fields: - api_field: workspaceCompilationOverrides.defaultDatabase - api_field: workspaceCompilationOverrides.schemaSuffix - api_field: workspaceCompilationOverrides.tablePrefix + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/dataform/resource_dataform_repository_release_config.go b/google-beta/services/dataform/resource_dataform_repository_release_config.go index 2474497b307..6e129b54848 100644 --- a/google-beta/services/dataform/resource_dataform_repository_release_config.go +++ b/google-beta/services/dataform/resource_dataform_repository_release_config.go @@ -115,6 +115,7 @@ func ResourceDataformRepositoryReleaseConfig() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -281,6 +282,18 @@ Example: { "name": "wrench", "mass": "1.3kg", "count": "3" }.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -443,6 +456,19 @@ func resourceDataformRepositoryReleaseConfigRead(d *schema.ResourceData, meta in log.Printf("[DEBUG] Finished reading DataformRepositoryReleaseConfig %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading RepositoryReleaseConfig: %s", err) } @@ -486,6 +512,19 @@ func resourceDataformRepositoryReleaseConfigRead(d *schema.ResourceData, meta in } func resourceDataformRepositoryReleaseConfigUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceDataformRepositoryReleaseConfig().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceDataformRepositoryReleaseConfigRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -591,6 +630,13 @@ func resourceDataformRepositoryReleaseConfigUpdate(d *schema.ResourceData, meta } func resourceDataformRepositoryReleaseConfigDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DataformRepositoryReleaseConfig without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing RepositoryReleaseConfig %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/dataform/resource_dataform_repository_release_config_generated_meta.yaml b/google-beta/services/dataform/resource_dataform_repository_release_config_generated_meta.yaml index e95e358024b..9ae25c4d827 100644 --- a/google-beta/services/dataform/resource_dataform_repository_release_config_generated_meta.yaml +++ b/google-beta/services/dataform/resource_dataform_repository_release_config_generated_meta.yaml @@ -28,3 +28,5 @@ fields: - field: repository provider_only: true - api_field: timeZone + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/dataform/resource_dataform_repository_workflow_config.go b/google-beta/services/dataform/resource_dataform_repository_workflow_config.go index 59e0a909177..d6ec2aaded2 100644 --- a/google-beta/services/dataform/resource_dataform_repository_workflow_config.go +++ b/google-beta/services/dataform/resource_dataform_repository_workflow_config.go @@ -115,6 +115,7 @@ func ResourceDataformRepositoryWorkflowConfig() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -284,6 +285,18 @@ func ResourceDataformRepositoryWorkflowConfig() *schema.Resource { Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -440,6 +453,19 @@ func resourceDataformRepositoryWorkflowConfigRead(d *schema.ResourceData, meta i log.Printf("[DEBUG] Finished reading DataformRepositoryWorkflowConfig %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading RepositoryWorkflowConfig: %s", err) } @@ -483,6 +509,19 @@ func resourceDataformRepositoryWorkflowConfigRead(d *schema.ResourceData, meta i } func resourceDataformRepositoryWorkflowConfigUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceDataformRepositoryWorkflowConfig().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceDataformRepositoryWorkflowConfigRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -582,6 +621,13 @@ func resourceDataformRepositoryWorkflowConfigUpdate(d *schema.ResourceData, meta } func resourceDataformRepositoryWorkflowConfigDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DataformRepositoryWorkflowConfig without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing RepositoryWorkflowConfig %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/dataform/resource_dataform_repository_workflow_config_generated_meta.yaml b/google-beta/services/dataform/resource_dataform_repository_workflow_config_generated_meta.yaml index 58e516d55a4..70018a0c09b 100644 --- a/google-beta/services/dataform/resource_dataform_repository_workflow_config_generated_meta.yaml +++ b/google-beta/services/dataform/resource_dataform_repository_workflow_config_generated_meta.yaml @@ -27,3 +27,5 @@ fields: - field: repository provider_only: true - api_field: timeZone + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/dataform/resource_dataform_team_folder.go b/google-beta/services/dataform/resource_dataform_team_folder.go index b1fe1f1e24f..181c3bdb938 100644 --- a/google-beta/services/dataform/resource_dataform_team_folder.go +++ b/google-beta/services/dataform/resource_dataform_team_folder.go @@ -115,6 +115,7 @@ func ResourceDataformTeamFolder() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -168,6 +169,18 @@ func ResourceDataformTeamFolder() *schema.Resource { Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -304,6 +317,19 @@ func resourceDataformTeamFolderRead(d *schema.ResourceData, meta interface{}) er log.Printf("[DEBUG] Finished reading DataformTeamFolder %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading TeamFolder: %s", err) } @@ -341,6 +367,19 @@ func resourceDataformTeamFolderRead(d *schema.ResourceData, meta interface{}) er } func resourceDataformTeamFolderUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceDataformTeamFolder().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceDataformTeamFolderRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -432,6 +471,13 @@ func resourceDataformTeamFolderUpdate(d *schema.ResourceData, meta interface{}) } func resourceDataformTeamFolderDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DataformTeamFolder without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing TeamFolder %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/dataform/resource_dataform_team_folder_generated_meta.yaml b/google-beta/services/dataform/resource_dataform_team_folder_generated_meta.yaml index 81787f06e56..1ef9b7201fa 100644 --- a/google-beta/services/dataform/resource_dataform_team_folder_generated_meta.yaml +++ b/google-beta/services/dataform/resource_dataform_team_folder_generated_meta.yaml @@ -13,3 +13,5 @@ fields: provider_only: true - api_field: name field: teamfolder_id + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/datafusion/resource_data_fusion_instance.go b/google-beta/services/datafusion/resource_data_fusion_instance.go index 85de0265968..4326f8e3c54 100644 --- a/google-beta/services/datafusion/resource_data_fusion_instance.go +++ b/google-beta/services/datafusion/resource_data_fusion_instance.go @@ -139,6 +139,7 @@ func ResourceDataFusionInstance() *schema.Resource { tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, tpgresource.DefaultProviderRegion, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -492,6 +493,18 @@ The field is ignored (both PUT & PATCH) when empty.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -737,6 +750,19 @@ func resourceDataFusionInstanceRead(d *schema.ResourceData, meta interface{}) er log.Printf("[DEBUG] Finished reading DataFusionInstance %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Instance: %s", err) } @@ -782,6 +808,19 @@ func resourceDataFusionInstanceRead(d *schema.ResourceData, meta interface{}) er } func resourceDataFusionInstanceUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceDataFusionInstance().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceDataFusionInstanceRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -929,6 +968,13 @@ func resourceDataFusionInstanceUpdate(d *schema.ResourceData, meta interface{}) } func resourceDataFusionInstanceDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DataFusionInstance without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Instance %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/datafusion/resource_data_fusion_instance_generated_meta.yaml b/google-beta/services/datafusion/resource_data_fusion_instance_generated_meta.yaml index 8abc1b86079..64b72dd748b 100644 --- a/google-beta/services/datafusion/resource_data_fusion_instance_generated_meta.yaml +++ b/google-beta/services/datafusion/resource_data_fusion_instance_generated_meta.yaml @@ -49,3 +49,5 @@ fields: - api_field: updateTime - api_field: version - api_field: zone + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/datalineage/resource_data_lineage_config.go b/google-beta/services/datalineage/resource_data_lineage_config.go index c12248acc60..de002c7a314 100644 --- a/google-beta/services/datalineage/resource_data_lineage_config.go +++ b/google-beta/services/datalineage/resource_data_lineage_config.go @@ -211,6 +211,19 @@ folders/{folder_id}/locations/{location}/config, projects/{project_id}/locations/{location}/config, or projects/{project_number}/locations/{location}/config.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -327,6 +340,20 @@ func resourceDataLineageConfigRead(d *schema.ResourceData, meta interface{}) err log.Printf("[DEBUG] Finished reading DataLineageConfig %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceDataLineageConfigFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -354,6 +381,19 @@ func resourceDataLineageConfigRead(d *schema.ResourceData, meta interface{}) err } func resourceDataLineageConfigUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceDataLineageConfig().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceDataLineageConfigRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -425,6 +465,13 @@ func resourceDataLineageConfigUpdate(d *schema.ResourceData, meta interface{}) e } func resourceDataLineageConfigDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DataLineageConfig without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Config %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/datalineage/resource_data_lineage_config_generated_meta.yaml b/google-beta/services/datalineage/resource_data_lineage_config_generated_meta.yaml index f8aca66f26f..0bb8e7cb4d0 100644 --- a/google-beta/services/datalineage/resource_data_lineage_config_generated_meta.yaml +++ b/google-beta/services/datalineage/resource_data_lineage_config_generated_meta.yaml @@ -21,3 +21,5 @@ fields: - api_field: name - field: parent provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/datalossprevention/resource_data_loss_prevention_deidentify_template.go b/google-beta/services/datalossprevention/resource_data_loss_prevention_deidentify_template.go index 771707192c1..496fd8088f0 100644 --- a/google-beta/services/datalossprevention/resource_data_loss_prevention_deidentify_template.go +++ b/google-beta/services/datalossprevention/resource_data_loss_prevention_deidentify_template.go @@ -4286,6 +4286,19 @@ that is, it must match the regular expression: [a-zA-Z\d-_]+. The maximum length Computed: true, Description: `The last update timestamp of an deidentifyTemplate. Set by the server.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -4431,6 +4444,20 @@ func resourceDataLossPreventionDeidentifyTemplateRead(d *schema.ResourceData, me return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceDataLossPreventionDeidentifyTemplateFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -4458,6 +4485,19 @@ func resourceDataLossPreventionDeidentifyTemplateRead(d *schema.ResourceData, me } func resourceDataLossPreventionDeidentifyTemplateUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceDataLossPreventionDeidentifyTemplate().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceDataLossPreventionDeidentifyTemplateRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -4563,6 +4603,13 @@ func resourceDataLossPreventionDeidentifyTemplateUpdate(d *schema.ResourceData, } func resourceDataLossPreventionDeidentifyTemplateDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DataLossPreventionDeidentifyTemplate without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing DeidentifyTemplate %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/datalossprevention/resource_data_loss_prevention_deidentify_template_generated_meta.yaml b/google-beta/services/datalossprevention/resource_data_loss_prevention_deidentify_template_generated_meta.yaml index c05a747592e..46b0dcdd5b6 100644 --- a/google-beta/services/datalossprevention/resource_data_loss_prevention_deidentify_template_generated_meta.yaml +++ b/google-beta/services/datalossprevention/resource_data_loss_prevention_deidentify_template_generated_meta.yaml @@ -366,3 +366,5 @@ fields: - field: template_id provider_only: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/datalossprevention/resource_data_loss_prevention_discovery_config.go b/google-beta/services/datalossprevention/resource_data_loss_prevention_discovery_config.go index ca16e808ec4..ab637a757b5 100644 --- a/google-beta/services/datalossprevention/resource_data_loss_prevention_discovery_config.go +++ b/google-beta/services/datalossprevention/resource_data_loss_prevention_discovery_config.go @@ -1449,6 +1449,19 @@ an organization parent, or "my-project/sensitive" for a project parent.`, Computed: true, Description: `Output only. The last update timestamp of a DiscoveryConfig.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -1618,6 +1631,20 @@ func resourceDataLossPreventionDiscoveryConfigRead(d *schema.ResourceData, meta return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceDataLossPreventionDiscoveryConfigFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -1645,6 +1672,19 @@ func resourceDataLossPreventionDiscoveryConfigRead(d *schema.ResourceData, meta } func resourceDataLossPreventionDiscoveryConfigUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceDataLossPreventionDiscoveryConfig().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceDataLossPreventionDiscoveryConfigRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1790,6 +1830,13 @@ func resourceDataLossPreventionDiscoveryConfigUpdate(d *schema.ResourceData, met } func resourceDataLossPreventionDiscoveryConfigDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DataLossPreventionDiscoveryConfig without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing DiscoveryConfig %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/datalossprevention/resource_data_loss_prevention_discovery_config_generated_meta.yaml b/google-beta/services/datalossprevention/resource_data_loss_prevention_discovery_config_generated_meta.yaml index 3aae7b118ca..c2ffa07b841 100644 --- a/google-beta/services/datalossprevention/resource_data_loss_prevention_discovery_config_generated_meta.yaml +++ b/google-beta/services/datalossprevention/resource_data_loss_prevention_discovery_config_generated_meta.yaml @@ -107,3 +107,5 @@ fields: - api_field: targets.otherCloudTarget.generationCadence.refreshFrequency - api_field: targets.secretsTarget - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/datalossprevention/resource_data_loss_prevention_inspect_template.go b/google-beta/services/datalossprevention/resource_data_loss_prevention_inspect_template.go index f350893270b..166b4b53894 100644 --- a/google-beta/services/datalossprevention/resource_data_loss_prevention_inspect_template.go +++ b/google-beta/services/datalossprevention/resource_data_loss_prevention_inspect_template.go @@ -823,6 +823,19 @@ that is, it must match the regular expression: [a-zA-Z\d-_]+. The maximum length Computed: true, Description: `The resource name of the inspect template. Set by the server.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -968,6 +981,20 @@ func resourceDataLossPreventionInspectTemplateRead(d *schema.ResourceData, meta return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceDataLossPreventionInspectTemplateFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -995,6 +1022,19 @@ func resourceDataLossPreventionInspectTemplateRead(d *schema.ResourceData, meta } func resourceDataLossPreventionInspectTemplateUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceDataLossPreventionInspectTemplate().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceDataLossPreventionInspectTemplateRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1100,6 +1140,13 @@ func resourceDataLossPreventionInspectTemplateUpdate(d *schema.ResourceData, met } func resourceDataLossPreventionInspectTemplateDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DataLossPreventionInspectTemplate without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing InspectTemplate %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/datalossprevention/resource_data_loss_prevention_inspect_template_generated_meta.yaml b/google-beta/services/datalossprevention/resource_data_loss_prevention_inspect_template_generated_meta.yaml index d5ded635879..ed6fce13b29 100644 --- a/google-beta/services/datalossprevention/resource_data_loss_prevention_inspect_template_generated_meta.yaml +++ b/google-beta/services/datalossprevention/resource_data_loss_prevention_inspect_template_generated_meta.yaml @@ -60,3 +60,5 @@ fields: provider_only: true - field: template_id provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/datalossprevention/resource_data_loss_prevention_job_trigger.go b/google-beta/services/datalossprevention/resource_data_loss_prevention_job_trigger.go index 3532cfb2867..892a4bb03f5 100644 --- a/google-beta/services/datalossprevention/resource_data_loss_prevention_job_trigger.go +++ b/google-beta/services/datalossprevention/resource_data_loss_prevention_job_trigger.go @@ -1523,6 +1523,19 @@ The maximum length is 100 characters. Can be empty to allow the system to genera Computed: true, Description: `The last update timestamp of an inspectTemplate. Set by the server.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -1680,6 +1693,20 @@ func resourceDataLossPreventionJobTriggerRead(d *schema.ResourceData, meta inter return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceDataLossPreventionJobTriggerFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -1707,6 +1734,19 @@ func resourceDataLossPreventionJobTriggerRead(d *schema.ResourceData, meta inter } func resourceDataLossPreventionJobTriggerUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceDataLossPreventionJobTrigger().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceDataLossPreventionJobTriggerRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1832,6 +1872,13 @@ func resourceDataLossPreventionJobTriggerUpdate(d *schema.ResourceData, meta int } func resourceDataLossPreventionJobTriggerDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DataLossPreventionJobTrigger without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing JobTrigger %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/datalossprevention/resource_data_loss_prevention_job_trigger_generated_meta.yaml b/google-beta/services/datalossprevention/resource_data_loss_prevention_job_trigger_generated_meta.yaml index 2029d2e089a..ba7b38b60ce 100644 --- a/google-beta/services/datalossprevention/resource_data_loss_prevention_job_trigger_generated_meta.yaml +++ b/google-beta/services/datalossprevention/resource_data_loss_prevention_job_trigger_generated_meta.yaml @@ -115,3 +115,5 @@ fields: - api_field: triggers.manual - api_field: triggers.schedule.recurrencePeriodDuration - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/datalossprevention/resource_data_loss_prevention_stored_info_type.go b/google-beta/services/datalossprevention/resource_data_loss_prevention_stored_info_type.go index df11faec416..1cc951db1dd 100644 --- a/google-beta/services/datalossprevention/resource_data_loss_prevention_stored_info_type.go +++ b/google-beta/services/datalossprevention/resource_data_loss_prevention_stored_info_type.go @@ -141,6 +141,7 @@ func ResourceDataLossPreventionStoredInfoType() *schema.Resource { CustomizeDiff: customdiff.All( storedInfoTypeCustomizeDiff, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -364,6 +365,19 @@ characters. Can be empty to allow the system to generate one.`, Computed: true, Description: `The resource name of the info type. Set by the server.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -569,6 +583,20 @@ func resourceDataLossPreventionStoredInfoTypeRead(d *schema.ResourceData, meta i return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceDataLossPreventionStoredInfoTypeFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -596,6 +624,19 @@ func resourceDataLossPreventionStoredInfoTypeRead(d *schema.ResourceData, meta i } func resourceDataLossPreventionStoredInfoTypeUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceDataLossPreventionStoredInfoType().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceDataLossPreventionStoredInfoTypeRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -721,6 +762,13 @@ func resourceDataLossPreventionStoredInfoTypeUpdate(d *schema.ResourceData, meta } func resourceDataLossPreventionStoredInfoTypeDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DataLossPreventionStoredInfoType without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing StoredInfoType %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/datalossprevention/resource_data_loss_prevention_stored_info_type_generated_meta.yaml b/google-beta/services/datalossprevention/resource_data_loss_prevention_stored_info_type_generated_meta.yaml index 51e256f1a44..17ff6f5047f 100644 --- a/google-beta/services/datalossprevention/resource_data_loss_prevention_stored_info_type_generated_meta.yaml +++ b/google-beta/services/datalossprevention/resource_data_loss_prevention_stored_info_type_generated_meta.yaml @@ -24,3 +24,5 @@ fields: - api_field: regex.pattern - field: stored_info_type_id provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/datapipeline/resource_data_pipeline_pipeline.go b/google-beta/services/datapipeline/resource_data_pipeline_pipeline.go index 1c1ed5e8b85..6bbfa2947cd 100644 --- a/google-beta/services/datapipeline/resource_data_pipeline_pipeline.go +++ b/google-beta/services/datapipeline/resource_data_pipeline_pipeline.go @@ -115,6 +115,7 @@ func ResourceDataPipelinePipeline() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -592,6 +593,18 @@ A timestamp in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to n Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -761,6 +774,19 @@ func resourceDataPipelinePipelineRead(d *schema.ResourceData, meta interface{}) log.Printf("[DEBUG] Finished reading DataPipelinePipeline %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Pipeline: %s", err) } @@ -798,6 +824,19 @@ func resourceDataPipelinePipelineRead(d *schema.ResourceData, meta interface{}) } func resourceDataPipelinePipelineUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceDataPipelinePipeline().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceDataPipelinePipelineRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -919,6 +958,13 @@ func resourceDataPipelinePipelineUpdate(d *schema.ResourceData, meta interface{} } func resourceDataPipelinePipelineDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DataPipelinePipeline without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Pipeline %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/datapipeline/resource_data_pipeline_pipeline_generated_meta.yaml b/google-beta/services/datapipeline/resource_data_pipeline_pipeline_generated_meta.yaml index 04d7a674450..96bb33677f2 100644 --- a/google-beta/services/datapipeline/resource_data_pipeline_pipeline_generated_meta.yaml +++ b/google-beta/services/datapipeline/resource_data_pipeline_pipeline_generated_meta.yaml @@ -70,3 +70,5 @@ fields: - api_field: workload.dataflowLaunchTemplateRequest.location - api_field: workload.dataflowLaunchTemplateRequest.projectId - api_field: workload.dataflowLaunchTemplateRequest.validateOnly + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/dataplex/resource_dataplex_aspect_type.go b/google-beta/services/dataplex/resource_dataplex_aspect_type.go index 2738a7e478f..4fac279ddfb 100644 --- a/google-beta/services/dataplex/resource_dataplex_aspect_type.go +++ b/google-beta/services/dataplex/resource_dataplex_aspect_type.go @@ -116,6 +116,7 @@ func ResourceDataplexAspectType() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -237,6 +238,18 @@ for Aspect Type created from Dataplex API.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -398,6 +411,19 @@ func resourceDataplexAspectTypeRead(d *schema.ResourceData, meta interface{}) er log.Printf("[DEBUG] Finished reading DataplexAspectType %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading AspectType: %s", err) } @@ -435,6 +461,19 @@ func resourceDataplexAspectTypeRead(d *schema.ResourceData, meta interface{}) er } func resourceDataplexAspectTypeUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceDataplexAspectType().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceDataplexAspectTypeRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -563,6 +602,13 @@ func resourceDataplexAspectTypeUpdate(d *schema.ResourceData, meta interface{}) } func resourceDataplexAspectTypeDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DataplexAspectType without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing AspectType %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/dataplex/resource_dataplex_aspect_type_generated_meta.yaml b/google-beta/services/dataplex/resource_dataplex_aspect_type_generated_meta.yaml index f15845f0f55..faf10e7857a 100644 --- a/google-beta/services/dataplex/resource_dataplex_aspect_type_generated_meta.yaml +++ b/google-beta/services/dataplex/resource_dataplex_aspect_type_generated_meta.yaml @@ -26,3 +26,5 @@ fields: - api_field: transferStatus - api_field: uid - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/dataplex/resource_dataplex_asset.go b/google-beta/services/dataplex/resource_dataplex_asset.go index c3afa8e1409..5e1458c36e1 100644 --- a/google-beta/services/dataplex/resource_dataplex_asset.go +++ b/google-beta/services/dataplex/resource_dataplex_asset.go @@ -52,6 +52,7 @@ func ResourceDataplexAsset() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, tpgresource.SetLabelsDiff, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Schema: map[string]*schema.Schema{ @@ -182,6 +183,9 @@ func ResourceDataplexAsset() *schema.Resource { Computed: true, Description: "Output only. The time when the asset was last updated.", }, + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end }, } } @@ -589,9 +593,18 @@ func resourceDataplexAssetRead(d *schema.ResourceData, meta interface{}) error { return fmt.Errorf("error setting update_time in state: %s", err) } + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + return nil } func resourceDataplexAssetUpdate(d *schema.ResourceData, meta interface{}) error { + + if tpgresource.DeletionPolicyPreUpdate(d, ResourceDataplexAsset) { + return ResourceDataplexAsset().Read(d, meta) + } + config := meta.(*transport_tpg.Config) project, err := tpgresource.GetProject(d, config) if err != nil { @@ -644,6 +657,13 @@ func resourceDataplexAssetUpdate(d *schema.ResourceData, meta interface{}) error } func resourceDataplexAssetDelete(d *schema.ResourceData, meta interface{}) error { + + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { + return nil + } + config := meta.(*transport_tpg.Config) project, err := tpgresource.GetProject(d, config) if err != nil { diff --git a/google-beta/services/dataplex/resource_dataplex_asset_meta.yaml b/google-beta/services/dataplex/resource_dataplex_asset_meta.yaml index 4eca8d006ed..1073d96dd16 100644 --- a/google-beta/services/dataplex/resource_dataplex_asset_meta.yaml +++ b/google-beta/services/dataplex/resource_dataplex_asset_meta.yaml @@ -50,3 +50,5 @@ fields: provider_only: true - api_field: 'uid' - api_field: 'updateTime' + - field: 'deletion_policy' + provider_only: true diff --git a/google-beta/services/dataplex/resource_dataplex_data_asset.go b/google-beta/services/dataplex/resource_dataplex_data_asset.go index 9b7f219596c..1247678074a 100644 --- a/google-beta/services/dataplex/resource_dataplex_data_asset.go +++ b/google-beta/services/dataplex/resource_dataplex_data_asset.go @@ -116,6 +116,7 @@ func ResourceDataplexDataAsset() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), DeprecationMessage: "`google_dataplex_data_asset` is deprecated and will be removed in a future major release. Please use `google_dataplex_data_product_data_asset` resource instead.", @@ -226,6 +227,18 @@ Please refer to the field 'effective_labels' for all of the labels present on th Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -380,6 +393,19 @@ func resourceDataplexDataAssetRead(d *schema.ResourceData, meta interface{}) err log.Printf("[DEBUG] Finished reading DataplexDataAsset %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading DataAsset: %s", err) } @@ -423,6 +449,19 @@ func resourceDataplexDataAssetRead(d *schema.ResourceData, meta interface{}) err } func resourceDataplexDataAssetUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceDataplexDataAsset().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceDataplexDataAssetRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -536,6 +575,13 @@ func resourceDataplexDataAssetUpdate(d *schema.ResourceData, meta interface{}) e } func resourceDataplexDataAssetDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DataplexDataAsset without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing DataAsset %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/dataplex/resource_dataplex_data_asset_generated_meta.yaml b/google-beta/services/dataplex/resource_dataplex_data_asset_generated_meta.yaml index 75daded5105..1e0ec96eadb 100644 --- a/google-beta/services/dataplex/resource_dataplex_data_asset_generated_meta.yaml +++ b/google-beta/services/dataplex/resource_dataplex_data_asset_generated_meta.yaml @@ -24,3 +24,5 @@ fields: - field: terraform_labels provider_only: true - api_field: uid + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/dataplex/resource_dataplex_data_product.go b/google-beta/services/dataplex/resource_dataplex_data_product.go index 11faf36cb71..c3bf59c62b6 100644 --- a/google-beta/services/dataplex/resource_dataplex_data_product.go +++ b/google-beta/services/dataplex/resource_dataplex_data_product.go @@ -116,6 +116,7 @@ func ResourceDataplexDataProduct() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -268,6 +269,18 @@ Please refer to the field 'effective_labels' for all of the labels present on th Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -429,6 +442,19 @@ func resourceDataplexDataProductRead(d *schema.ResourceData, meta interface{}) e log.Printf("[DEBUG] Finished reading DataplexDataProduct %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading DataProduct: %s", err) } @@ -466,6 +492,19 @@ func resourceDataplexDataProductRead(d *schema.ResourceData, meta interface{}) e } func resourceDataplexDataProductUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceDataplexDataProduct().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceDataplexDataProductRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -604,6 +643,13 @@ func resourceDataplexDataProductUpdate(d *schema.ResourceData, meta interface{}) } func resourceDataplexDataProductDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DataplexDataProduct without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing DataProduct %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/dataplex/resource_dataplex_data_product_data_asset.go b/google-beta/services/dataplex/resource_dataplex_data_product_data_asset.go index 22b83a8088c..3e55c4db28c 100644 --- a/google-beta/services/dataplex/resource_dataplex_data_product_data_asset.go +++ b/google-beta/services/dataplex/resource_dataplex_data_product_data_asset.go @@ -116,6 +116,7 @@ func ResourceDataplexDataProductDataAsset() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -224,6 +225,18 @@ Please refer to the field 'effective_labels' for all of the labels present on th Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -378,6 +391,19 @@ func resourceDataplexDataProductDataAssetRead(d *schema.ResourceData, meta inter log.Printf("[DEBUG] Finished reading DataplexDataProductDataAsset %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading DataProductDataAsset: %s", err) } @@ -421,6 +447,19 @@ func resourceDataplexDataProductDataAssetRead(d *schema.ResourceData, meta inter } func resourceDataplexDataProductDataAssetUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceDataplexDataProductDataAsset().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceDataplexDataProductDataAssetRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -534,6 +573,13 @@ func resourceDataplexDataProductDataAssetUpdate(d *schema.ResourceData, meta int } func resourceDataplexDataProductDataAssetDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DataplexDataProductDataAsset without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing DataProductDataAsset %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/dataplex/resource_dataplex_data_product_data_asset_generated_meta.yaml b/google-beta/services/dataplex/resource_dataplex_data_product_data_asset_generated_meta.yaml index 5bd8ae9553f..f5475688d9d 100644 --- a/google-beta/services/dataplex/resource_dataplex_data_product_data_asset_generated_meta.yaml +++ b/google-beta/services/dataplex/resource_dataplex_data_product_data_asset_generated_meta.yaml @@ -24,3 +24,5 @@ fields: - field: terraform_labels provider_only: true - api_field: uid + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/dataplex/resource_dataplex_data_product_generated_meta.yaml b/google-beta/services/dataplex/resource_dataplex_data_product_generated_meta.yaml index 866ecdf103a..1b906c9244c 100644 --- a/google-beta/services/dataplex/resource_dataplex_data_product_generated_meta.yaml +++ b/google-beta/services/dataplex/resource_dataplex_data_product_generated_meta.yaml @@ -34,3 +34,5 @@ fields: provider_only: true - api_field: uid - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/dataplex/resource_dataplex_datascan.go b/google-beta/services/dataplex/resource_dataplex_datascan.go index 137663d02a8..a11d7bf7d66 100644 --- a/google-beta/services/dataplex/resource_dataplex_datascan.go +++ b/google-beta/services/dataplex/resource_dataplex_datascan.go @@ -116,6 +116,7 @@ func ResourceDataplexDatascan() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiffWithoutAttributionLabel, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -1000,6 +1001,18 @@ Please refer to the field 'effective_labels' for all of the labels present on th Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -1191,6 +1204,19 @@ func resourceDataplexDatascanRead(d *schema.ResourceData, meta interface{}) erro log.Printf("[DEBUG] Finished reading DataplexDatascan %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Datascan: %s", err) } @@ -1228,6 +1254,19 @@ func resourceDataplexDatascanRead(d *schema.ResourceData, meta interface{}) erro } func resourceDataplexDatascanUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceDataplexDatascan().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceDataplexDatascanRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1396,6 +1435,13 @@ func resourceDataplexDatascanUpdate(d *schema.ResourceData, meta interface{}) er } func resourceDataplexDatascanDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DataplexDatascan without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Datascan %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/dataplex/resource_dataplex_datascan_generated_meta.yaml b/google-beta/services/dataplex/resource_dataplex_datascan_generated_meta.yaml index 4e855a52ad8..7360099718b 100644 --- a/google-beta/services/dataplex/resource_dataplex_datascan_generated_meta.yaml +++ b/google-beta/services/dataplex/resource_dataplex_datascan_generated_meta.yaml @@ -94,3 +94,5 @@ fields: - api_field: type - api_field: uid - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/dataplex/resource_dataplex_entry.go b/google-beta/services/dataplex/resource_dataplex_entry.go index 9fac0d5a92a..67a80ee97c6 100644 --- a/google-beta/services/dataplex/resource_dataplex_entry.go +++ b/google-beta/services/dataplex/resource_dataplex_entry.go @@ -309,6 +309,7 @@ func ResourceDataplexEntry() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -536,6 +537,18 @@ The maximum size of the field is 4000 characters.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -721,6 +734,19 @@ func resourceDataplexEntryRead(d *schema.ResourceData, meta interface{}) error { return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Entry: %s", err) } @@ -764,6 +790,19 @@ func resourceDataplexEntryRead(d *schema.ResourceData, meta interface{}) error { } func resourceDataplexEntryUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceDataplexEntry().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceDataplexEntryRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -927,6 +966,13 @@ func resourceDataplexEntryUpdate(d *schema.ResourceData, meta interface{}) error } func resourceDataplexEntryDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DataplexEntry without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Entry %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/dataplex/resource_dataplex_entry_generated_meta.yaml b/google-beta/services/dataplex/resource_dataplex_entry_generated_meta.yaml index febe580e395..b8281d35d9e 100644 --- a/google-beta/services/dataplex/resource_dataplex_entry_generated_meta.yaml +++ b/google-beta/services/dataplex/resource_dataplex_entry_generated_meta.yaml @@ -37,3 +37,5 @@ fields: - api_field: name - api_field: parentEntry - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/dataplex/resource_dataplex_entry_group.go b/google-beta/services/dataplex/resource_dataplex_entry_group.go index 379c74c20f4..fe0208b6e29 100644 --- a/google-beta/services/dataplex/resource_dataplex_entry_group.go +++ b/google-beta/services/dataplex/resource_dataplex_entry_group.go @@ -116,6 +116,7 @@ func ResourceDataplexEntryGroup() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -219,6 +220,18 @@ for Entry Group created from Dataplex API.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -368,6 +381,19 @@ func resourceDataplexEntryGroupRead(d *schema.ResourceData, meta interface{}) er log.Printf("[DEBUG] Finished reading DataplexEntryGroup %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading EntryGroup: %s", err) } @@ -405,6 +431,19 @@ func resourceDataplexEntryGroupRead(d *schema.ResourceData, meta interface{}) er } func resourceDataplexEntryGroupUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceDataplexEntryGroup().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceDataplexEntryGroupRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -523,6 +562,13 @@ func resourceDataplexEntryGroupUpdate(d *schema.ResourceData, meta interface{}) } func resourceDataplexEntryGroupDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DataplexEntryGroup without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing EntryGroup %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/dataplex/resource_dataplex_entry_group_generated_meta.yaml b/google-beta/services/dataplex/resource_dataplex_entry_group_generated_meta.yaml index 32b9daec77c..b36cd036bad 100644 --- a/google-beta/services/dataplex/resource_dataplex_entry_group_generated_meta.yaml +++ b/google-beta/services/dataplex/resource_dataplex_entry_group_generated_meta.yaml @@ -23,3 +23,5 @@ fields: - api_field: transferStatus - api_field: uid - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/dataplex/resource_dataplex_entry_link.go b/google-beta/services/dataplex/resource_dataplex_entry_link.go index 52da9d6934c..433631ce60c 100644 --- a/google-beta/services/dataplex/resource_dataplex_entry_link.go +++ b/google-beta/services/dataplex/resource_dataplex_entry_link.go @@ -268,6 +268,7 @@ func ResourceDataplexEntryLink() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -429,6 +430,18 @@ projects/{project_id_or_number}/locations/{location_id}/entryGroups/{entry_group Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -592,6 +605,19 @@ func resourceDataplexEntryLinkRead(d *schema.ResourceData, meta interface{}) err return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading EntryLink: %s", err) } @@ -635,6 +661,19 @@ func resourceDataplexEntryLinkRead(d *schema.ResourceData, meta interface{}) err } func resourceDataplexEntryLinkUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceDataplexEntryLink().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceDataplexEntryLinkRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -722,6 +761,13 @@ func resourceDataplexEntryLinkUpdate(d *schema.ResourceData, meta interface{}) e } func resourceDataplexEntryLinkDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DataplexEntryLink without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing EntryLink %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/dataplex/resource_dataplex_entry_link_generated_meta.yaml b/google-beta/services/dataplex/resource_dataplex_entry_link_generated_meta.yaml index b36cf62ad9f..9e636a5036a 100644 --- a/google-beta/services/dataplex/resource_dataplex_entry_link_generated_meta.yaml +++ b/google-beta/services/dataplex/resource_dataplex_entry_link_generated_meta.yaml @@ -27,3 +27,5 @@ fields: provider_only: true - api_field: name - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/dataplex/resource_dataplex_entry_type.go b/google-beta/services/dataplex/resource_dataplex_entry_type.go index eda12b41881..ba7423912cc 100644 --- a/google-beta/services/dataplex/resource_dataplex_entry_type.go +++ b/google-beta/services/dataplex/resource_dataplex_entry_type.go @@ -116,6 +116,7 @@ func ResourceDataplexEntryType() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -245,6 +246,18 @@ Please refer to the field 'effective_labels' for all of the labels present on th Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -418,6 +431,19 @@ func resourceDataplexEntryTypeRead(d *schema.ResourceData, meta interface{}) err log.Printf("[DEBUG] Finished reading DataplexEntryType %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading EntryType: %s", err) } @@ -455,6 +481,19 @@ func resourceDataplexEntryTypeRead(d *schema.ResourceData, meta interface{}) err } func resourceDataplexEntryTypeUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceDataplexEntryType().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceDataplexEntryTypeRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -613,6 +652,13 @@ func resourceDataplexEntryTypeUpdate(d *schema.ResourceData, meta interface{}) e } func resourceDataplexEntryTypeDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DataplexEntryType without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing EntryType %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/dataplex/resource_dataplex_entry_type_generated_meta.yaml b/google-beta/services/dataplex/resource_dataplex_entry_type_generated_meta.yaml index b9247ef9847..c9941ebbf24 100644 --- a/google-beta/services/dataplex/resource_dataplex_entry_type_generated_meta.yaml +++ b/google-beta/services/dataplex/resource_dataplex_entry_type_generated_meta.yaml @@ -26,3 +26,5 @@ fields: - api_field: typeAliases - api_field: uid - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/dataplex/resource_dataplex_glossary.go b/google-beta/services/dataplex/resource_dataplex_glossary.go index fe30da671b9..c6b529cb53e 100644 --- a/google-beta/services/dataplex/resource_dataplex_glossary.go +++ b/google-beta/services/dataplex/resource_dataplex_glossary.go @@ -116,6 +116,7 @@ func ResourceDataplexGlossary() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -223,6 +224,18 @@ Please refer to the field 'effective_labels' for all of the labels present on th Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -372,6 +385,19 @@ func resourceDataplexGlossaryRead(d *schema.ResourceData, meta interface{}) erro log.Printf("[DEBUG] Finished reading DataplexGlossary %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Glossary: %s", err) } @@ -409,6 +435,19 @@ func resourceDataplexGlossaryRead(d *schema.ResourceData, meta interface{}) erro } func resourceDataplexGlossaryUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceDataplexGlossary().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceDataplexGlossaryRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -527,6 +566,13 @@ func resourceDataplexGlossaryUpdate(d *schema.ResourceData, meta interface{}) er } func resourceDataplexGlossaryDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DataplexGlossary without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Glossary %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/dataplex/resource_dataplex_glossary_category.go b/google-beta/services/dataplex/resource_dataplex_glossary_category.go index 0cd9e760772..46ef1fda886 100644 --- a/google-beta/services/dataplex/resource_dataplex_glossary_category.go +++ b/google-beta/services/dataplex/resource_dataplex_glossary_category.go @@ -116,6 +116,7 @@ func ResourceDataplexGlossaryCategory() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -228,6 +229,18 @@ Please refer to the field 'effective_labels' for all of the labels present on th Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -378,6 +391,19 @@ func resourceDataplexGlossaryCategoryRead(d *schema.ResourceData, meta interface log.Printf("[DEBUG] Finished reading DataplexGlossaryCategory %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading GlossaryCategory: %s", err) } @@ -421,6 +447,19 @@ func resourceDataplexGlossaryCategoryRead(d *schema.ResourceData, meta interface } func resourceDataplexGlossaryCategoryUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceDataplexGlossaryCategory().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceDataplexGlossaryCategoryRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -547,6 +586,13 @@ func resourceDataplexGlossaryCategoryUpdate(d *schema.ResourceData, meta interfa } func resourceDataplexGlossaryCategoryDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DataplexGlossaryCategory without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing GlossaryCategory %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/dataplex/resource_dataplex_glossary_category_generated_meta.yaml b/google-beta/services/dataplex/resource_dataplex_glossary_category_generated_meta.yaml index 3bd106c377a..c5d85f8d942 100644 --- a/google-beta/services/dataplex/resource_dataplex_glossary_category_generated_meta.yaml +++ b/google-beta/services/dataplex/resource_dataplex_glossary_category_generated_meta.yaml @@ -25,3 +25,5 @@ fields: provider_only: true - api_field: uid - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/dataplex/resource_dataplex_glossary_generated_meta.yaml b/google-beta/services/dataplex/resource_dataplex_glossary_generated_meta.yaml index f8eca65e71c..5ac6d131b32 100644 --- a/google-beta/services/dataplex/resource_dataplex_glossary_generated_meta.yaml +++ b/google-beta/services/dataplex/resource_dataplex_glossary_generated_meta.yaml @@ -24,3 +24,5 @@ fields: provider_only: true - api_field: uid - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/dataplex/resource_dataplex_glossary_term.go b/google-beta/services/dataplex/resource_dataplex_glossary_term.go index 27eedc5a168..9345d94e7e3 100644 --- a/google-beta/services/dataplex/resource_dataplex_glossary_term.go +++ b/google-beta/services/dataplex/resource_dataplex_glossary_term.go @@ -116,6 +116,7 @@ func ResourceDataplexGlossaryTerm() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -228,6 +229,18 @@ Please refer to the field 'effective_labels' for all of the labels present on th Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -378,6 +391,19 @@ func resourceDataplexGlossaryTermRead(d *schema.ResourceData, meta interface{}) log.Printf("[DEBUG] Finished reading DataplexGlossaryTerm %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading GlossaryTerm: %s", err) } @@ -421,6 +447,19 @@ func resourceDataplexGlossaryTermRead(d *schema.ResourceData, meta interface{}) } func resourceDataplexGlossaryTermUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceDataplexGlossaryTerm().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceDataplexGlossaryTermRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -547,6 +586,13 @@ func resourceDataplexGlossaryTermUpdate(d *schema.ResourceData, meta interface{} } func resourceDataplexGlossaryTermDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DataplexGlossaryTerm without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing GlossaryTerm %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/dataplex/resource_dataplex_glossary_term_generated_meta.yaml b/google-beta/services/dataplex/resource_dataplex_glossary_term_generated_meta.yaml index 00aa48a1f99..36f92754748 100644 --- a/google-beta/services/dataplex/resource_dataplex_glossary_term_generated_meta.yaml +++ b/google-beta/services/dataplex/resource_dataplex_glossary_term_generated_meta.yaml @@ -25,3 +25,5 @@ fields: provider_only: true - api_field: uid - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/dataplex/resource_dataplex_lake.go b/google-beta/services/dataplex/resource_dataplex_lake.go index d2e6c1958fd..fb321fbaf75 100644 --- a/google-beta/services/dataplex/resource_dataplex_lake.go +++ b/google-beta/services/dataplex/resource_dataplex_lake.go @@ -52,6 +52,7 @@ func ResourceDataplexLake() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, tpgresource.SetLabelsDiff, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Schema: map[string]*schema.Schema{ @@ -160,6 +161,9 @@ func ResourceDataplexLake() *schema.Resource { Computed: true, Description: "Output only. The time when the lake was last updated.", }, + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end }, } } @@ -372,9 +376,18 @@ func resourceDataplexLakeRead(d *schema.ResourceData, meta interface{}) error { return fmt.Errorf("error setting update_time in state: %s", err) } + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + return nil } func resourceDataplexLakeUpdate(d *schema.ResourceData, meta interface{}) error { + + if tpgresource.DeletionPolicyPreUpdate(d, ResourceDataplexLake) { + return ResourceDataplexLake().Read(d, meta) + } + config := meta.(*transport_tpg.Config) project, err := tpgresource.GetProject(d, config) if err != nil { @@ -424,6 +437,13 @@ func resourceDataplexLakeUpdate(d *schema.ResourceData, meta interface{}) error } func resourceDataplexLakeDelete(d *schema.ResourceData, meta interface{}) error { + + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { + return nil + } + config := meta.(*transport_tpg.Config) project, err := tpgresource.GetProject(d, config) if err != nil { diff --git a/google-beta/services/dataplex/resource_dataplex_lake_meta.yaml b/google-beta/services/dataplex/resource_dataplex_lake_meta.yaml index 119d137fc63..844d4e63ab1 100644 --- a/google-beta/services/dataplex/resource_dataplex_lake_meta.yaml +++ b/google-beta/services/dataplex/resource_dataplex_lake_meta.yaml @@ -29,3 +29,5 @@ fields: provider_only: true - api_field: 'uid' - api_field: 'updateTime' + - field: 'deletion_policy' + provider_only: true diff --git a/google-beta/services/dataplex/resource_dataplex_task.go b/google-beta/services/dataplex/resource_dataplex_task.go index cdea228ecfa..39d86b806cd 100644 --- a/google-beta/services/dataplex/resource_dataplex_task.go +++ b/google-beta/services/dataplex/resource_dataplex_task.go @@ -116,6 +116,7 @@ func ResourceDataplexTask() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiffWithoutAttributionLabel, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -656,6 +657,18 @@ Please refer to the field 'effective_labels' for all of the labels present on th Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -834,6 +847,19 @@ func resourceDataplexTaskRead(d *schema.ResourceData, meta interface{}) error { log.Printf("[DEBUG] Finished reading DataplexTask %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Task: %s", err) } @@ -877,6 +903,19 @@ func resourceDataplexTaskRead(d *schema.ResourceData, meta interface{}) error { } func resourceDataplexTaskUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceDataplexTask().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceDataplexTaskRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1040,6 +1079,13 @@ func resourceDataplexTaskUpdate(d *schema.ResourceData, meta interface{}) error } func resourceDataplexTaskDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DataplexTask without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Task %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/dataplex/resource_dataplex_task_generated_meta.yaml b/google-beta/services/dataplex/resource_dataplex_task_generated_meta.yaml index f2cdf819e35..44cfabd3d60 100644 --- a/google-beta/services/dataplex/resource_dataplex_task_generated_meta.yaml +++ b/google-beta/services/dataplex/resource_dataplex_task_generated_meta.yaml @@ -73,3 +73,5 @@ fields: - api_field: triggerSpec.type - api_field: uid - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/dataplex/resource_dataplex_zone.go b/google-beta/services/dataplex/resource_dataplex_zone.go index e9c727e4bc6..11a62f35409 100644 --- a/google-beta/services/dataplex/resource_dataplex_zone.go +++ b/google-beta/services/dataplex/resource_dataplex_zone.go @@ -52,6 +52,7 @@ func ResourceDataplexZone() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, tpgresource.SetLabelsDiff, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Schema: map[string]*schema.Schema{ @@ -170,6 +171,9 @@ func ResourceDataplexZone() *schema.Resource { Computed: true, Description: "Output only. The time when the zone was last updated.", }, + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end }, } } @@ -461,9 +465,18 @@ func resourceDataplexZoneRead(d *schema.ResourceData, meta interface{}) error { return fmt.Errorf("error setting update_time in state: %s", err) } + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + return nil } func resourceDataplexZoneUpdate(d *schema.ResourceData, meta interface{}) error { + + if tpgresource.DeletionPolicyPreUpdate(d, ResourceDataplexZone) { + return ResourceDataplexZone().Read(d, meta) + } + config := meta.(*transport_tpg.Config) project, err := tpgresource.GetProject(d, config) if err != nil { @@ -516,6 +529,13 @@ func resourceDataplexZoneUpdate(d *schema.ResourceData, meta interface{}) error } func resourceDataplexZoneDelete(d *schema.ResourceData, meta interface{}) error { + + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { + return nil + } + config := meta.(*transport_tpg.Config) project, err := tpgresource.GetProject(d, config) if err != nil { diff --git a/google-beta/services/dataplex/resource_dataplex_zone_meta.yaml b/google-beta/services/dataplex/resource_dataplex_zone_meta.yaml index aa68c213379..1666232f493 100644 --- a/google-beta/services/dataplex/resource_dataplex_zone_meta.yaml +++ b/google-beta/services/dataplex/resource_dataplex_zone_meta.yaml @@ -36,3 +36,5 @@ fields: - api_field: 'type' - api_field: 'uid' - api_field: 'updateTime' + - field: 'deletion_policy' + provider_only: true diff --git a/google-beta/services/dataproc/resource_dataproc_autoscaling_policy.go b/google-beta/services/dataproc/resource_dataproc_autoscaling_policy.go index 642f57829a0..c66d471d132 100644 --- a/google-beta/services/dataproc/resource_dataproc_autoscaling_policy.go +++ b/google-beta/services/dataproc/resource_dataproc_autoscaling_policy.go @@ -115,6 +115,7 @@ func ResourceDataprocAutoscalingPolicy() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -335,6 +336,18 @@ only on primary workers, the cluster will use primary workers only and no second Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -480,6 +493,19 @@ func resourceDataprocAutoscalingPolicyRead(d *schema.ResourceData, meta interfac log.Printf("[DEBUG] Finished reading DataprocAutoscalingPolicy %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading AutoscalingPolicy: %s", err) } @@ -517,6 +543,19 @@ func resourceDataprocAutoscalingPolicyRead(d *schema.ResourceData, meta interfac } func resourceDataprocAutoscalingPolicyUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceDataprocAutoscalingPolicy().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceDataprocAutoscalingPolicyRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -611,6 +650,13 @@ func resourceDataprocAutoscalingPolicyUpdate(d *schema.ResourceData, meta interf } func resourceDataprocAutoscalingPolicyDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DataprocAutoscalingPolicy without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing AutoscalingPolicy %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/dataproc/resource_dataproc_autoscaling_policy_generated_meta.yaml b/google-beta/services/dataproc/resource_dataproc_autoscaling_policy_generated_meta.yaml index a5c2612aedc..f5909695d85 100644 --- a/google-beta/services/dataproc/resource_dataproc_autoscaling_policy_generated_meta.yaml +++ b/google-beta/services/dataproc/resource_dataproc_autoscaling_policy_generated_meta.yaml @@ -28,3 +28,5 @@ fields: - api_field: workerConfig.maxInstances - api_field: workerConfig.minInstances - api_field: workerConfig.weight + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/dataproc/resource_dataproc_batch.go b/google-beta/services/dataproc/resource_dataproc_batch.go index f80351aaf19..f90e4efba7a 100644 --- a/google-beta/services/dataproc/resource_dataproc_batch.go +++ b/google-beta/services/dataproc/resource_dataproc_batch.go @@ -132,6 +132,7 @@ func ResourceDataprocBatch() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -776,6 +777,18 @@ properties, such as --conf, since a collision can occur that causes an incorrect Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -961,6 +974,19 @@ func resourceDataprocBatchRead(d *schema.ResourceData, meta interface{}) error { return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Batch: %s", err) } @@ -998,11 +1024,18 @@ func resourceDataprocBatchRead(d *schema.ResourceData, meta interface{}) error { } func resourceDataprocBatchUpdate(d *schema.ResourceData, meta interface{}) error { - // Only the root field "labels", "terraform_labels", and virtual fields are mutable + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable return resourceDataprocBatchRead(d, meta) } func resourceDataprocBatchDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DataprocBatch without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Batch %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/dataproc/resource_dataproc_batch_generated_meta.yaml b/google-beta/services/dataproc/resource_dataproc_batch_generated_meta.yaml index e346b5ffd1c..bdaba179d7c 100644 --- a/google-beta/services/dataproc/resource_dataproc_batch_generated_meta.yaml +++ b/google-beta/services/dataproc/resource_dataproc_batch_generated_meta.yaml @@ -78,3 +78,5 @@ fields: - field: terraform_labels provider_only: true - api_field: uuid + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/dataproc/resource_dataproc_cluster.go b/google-beta/services/dataproc/resource_dataproc_cluster.go index 3949b780d55..e15a37e27f9 100644 --- a/google-beta/services/dataproc/resource_dataproc_cluster.go +++ b/google-beta/services/dataproc/resource_dataproc_cluster.go @@ -215,6 +215,7 @@ func ResourceDataprocCluster() *schema.Resource { }, CustomizeDiff: customdiff.All( + tpgresource.DefaultProviderDeletionPolicy("DELETE"), tpgresource.DefaultProviderProject, // User labels are not supported in Dataproc Virtual Cluster tpgresource.SetLabelsDiffWithoutAttributionLabel, @@ -2052,6 +2053,9 @@ by Dataproc`, }, }, }, + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end }, UseJSONNumber: true, } @@ -3026,6 +3030,11 @@ func expandAccelerators(configured []interface{}) []*dataproc.AcceleratorConfig } func resourceDataprocClusterUpdate(d *schema.ResourceData, meta interface{}) error { + + if tpgresource.DeletionPolicyPreUpdate(d, ResourceDataprocCluster) { + return ResourceDataprocCluster().Read(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -3217,6 +3226,10 @@ func resourceDataprocClusterRead(d *schema.ResourceData, meta interface{}) error return err } + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + return nil } @@ -3858,6 +3871,13 @@ func ExtractInitTimeout(t string) (int, error) { } func resourceDataprocClusterDelete(d *schema.ResourceData, meta interface{}) error { + + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { + return nil + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/dataproc/resource_dataproc_cluster_meta.yaml b/google-beta/services/dataproc/resource_dataproc_cluster_meta.yaml index e3790bbd7d4..a7f36b2f7a3 100644 --- a/google-beta/services/dataproc/resource_dataproc_cluster_meta.yaml +++ b/google-beta/services/dataproc/resource_dataproc_cluster_meta.yaml @@ -154,3 +154,5 @@ fields: - api_field: 'virtualClusterConfig.kubernetesClusterConfig.kubernetesSoftwareConfig.componentVersion' - api_field: 'virtualClusterConfig.kubernetesClusterConfig.kubernetesSoftwareConfig.properties' - api_field: 'virtualClusterConfig.stagingBucket' + - field: 'deletion_policy' + provider_only: true diff --git a/google-beta/services/dataproc/resource_dataproc_job.go b/google-beta/services/dataproc/resource_dataproc_job.go index 4c3e80dd734..e0c3ad26b26 100644 --- a/google-beta/services/dataproc/resource_dataproc_job.go +++ b/google-beta/services/dataproc/resource_dataproc_job.go @@ -48,6 +48,7 @@ func ResourceDataprocJob() *schema.Resource { }, CustomizeDiff: customdiff.All( + tpgresource.DefaultProviderDeletionPolicy("DELETE"), tpgresource.DefaultProviderProject, tpgresource.SetLabelsDiff, ), @@ -229,6 +230,9 @@ func ResourceDataprocJob() *schema.Resource { "pig_config": pigSchema, "sparksql_config": sparkSqlSchema, "presto_config": prestoSchema, + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end }, UseJSONNumber: true, } @@ -429,10 +433,22 @@ func resourceDataprocJobRead(d *schema.ResourceData, meta interface{}) error { return fmt.Errorf("Error setting presto_config: %s", err) } } + + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + return nil } func resourceDataprocJobDelete(d *schema.ResourceData, meta interface{}) error { + + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { + return nil + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/dataproc/resource_dataproc_job_meta.yaml b/google-beta/services/dataproc/resource_dataproc_job_meta.yaml index 75e54371429..038f633a0db 100644 --- a/google-beta/services/dataproc/resource_dataproc_job_meta.yaml +++ b/google-beta/services/dataproc/resource_dataproc_job_meta.yaml @@ -77,3 +77,5 @@ fields: provider_only: true - field: 'wait_for_completion' provider_only: true + - field: 'deletion_policy' + provider_only: true diff --git a/google-beta/services/dataproc/resource_dataproc_session_template.go b/google-beta/services/dataproc/resource_dataproc_session_template.go index 3c19182507d..7d35ffb579a 100644 --- a/google-beta/services/dataproc/resource_dataproc_session_template.go +++ b/google-beta/services/dataproc/resource_dataproc_session_template.go @@ -116,6 +116,7 @@ func ResourceDataprocSessionTemplate() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -381,6 +382,18 @@ Please refer to the field 'effective_labels' for all of the labels present on th Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -528,6 +541,19 @@ func resourceDataprocSessionTemplateRead(d *schema.ResourceData, meta interface{ log.Printf("[DEBUG] Finished reading DataprocSessionTemplate %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading SessionTemplate: %s", err) } @@ -553,6 +579,19 @@ func resourceDataprocSessionTemplateRead(d *schema.ResourceData, meta interface{ } func resourceDataprocSessionTemplateUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceDataprocSessionTemplate().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceDataprocSessionTemplateRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -643,6 +682,13 @@ func resourceDataprocSessionTemplateUpdate(d *schema.ResourceData, meta interfac } func resourceDataprocSessionTemplateDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DataprocSessionTemplate without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing SessionTemplate %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/dataproc/resource_dataproc_session_template_generated_meta.yaml b/google-beta/services/dataproc/resource_dataproc_session_template_generated_meta.yaml index f116a772c03..d1f45991990 100644 --- a/google-beta/services/dataproc/resource_dataproc_session_template_generated_meta.yaml +++ b/google-beta/services/dataproc/resource_dataproc_session_template_generated_meta.yaml @@ -38,3 +38,5 @@ fields: provider_only: true - api_field: updateTime - api_field: uuid + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/dataproc/resource_dataproc_workflow_template.go b/google-beta/services/dataproc/resource_dataproc_workflow_template.go index a869ff98c2e..b05f186a41d 100644 --- a/google-beta/services/dataproc/resource_dataproc_workflow_template.go +++ b/google-beta/services/dataproc/resource_dataproc_workflow_template.go @@ -48,6 +48,7 @@ func ResourceDataprocWorkflowTemplate() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, tpgresource.SetLabelsDiff, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), SchemaVersion: 1, StateUpgraders: []schema.StateUpgrader{ @@ -163,6 +164,9 @@ func ResourceDataprocWorkflowTemplate() *schema.Resource { Computed: true, Description: "Output only. The time template was last updated.", }, + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end }, } } @@ -2327,6 +2331,10 @@ func resourceDataprocWorkflowTemplateRead(d *schema.ResourceData, meta interface return fmt.Errorf("error setting update_time in state: %s", err) } + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + return nil } func resourceDataprocWorkflowTemplateUpdate(d *schema.ResourceData, meta interface{}) error { @@ -2336,6 +2344,13 @@ func resourceDataprocWorkflowTemplateUpdate(d *schema.ResourceData, meta interfa } func resourceDataprocWorkflowTemplateDelete(d *schema.ResourceData, meta interface{}) error { + + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { + return nil + } + config := meta.(*transport_tpg.Config) project, err := tpgresource.GetProject(d, config) if err != nil { diff --git a/google-beta/services/dataproc/resource_dataproc_workflow_template_meta.yaml b/google-beta/services/dataproc/resource_dataproc_workflow_template_meta.yaml index 8ae404721ab..bbcef6e7afe 100644 --- a/google-beta/services/dataproc/resource_dataproc_workflow_template_meta.yaml +++ b/google-beta/services/dataproc/resource_dataproc_workflow_template_meta.yaml @@ -183,3 +183,5 @@ fields: provider_only: true - api_field: 'updateTime' - api_field: 'version' + - field: 'deletion_policy' + provider_only: true diff --git a/google-beta/services/dataprocgdc/resource_dataproc_gdc_application_environment.go b/google-beta/services/dataprocgdc/resource_dataproc_gdc_application_environment.go index 7e66eda06f0..b44b13720ea 100644 --- a/google-beta/services/dataprocgdc/resource_dataproc_gdc_application_environment.go +++ b/google-beta/services/dataprocgdc/resource_dataproc_gdc_application_environment.go @@ -117,6 +117,7 @@ func ResourceDataprocGdcApplicationEnvironment() *schema.Resource { tpgresource.SetLabelsDiff, tpgresource.SetAnnotationsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -259,6 +260,18 @@ Please refer to the field 'effective_labels' for all of the labels present on th Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -415,6 +428,19 @@ func resourceDataprocGdcApplicationEnvironmentRead(d *schema.ResourceData, meta log.Printf("[DEBUG] Finished reading DataprocGdcApplicationEnvironment %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading ApplicationEnvironment: %s", err) } @@ -458,6 +484,19 @@ func resourceDataprocGdcApplicationEnvironmentRead(d *schema.ResourceData, meta } func resourceDataprocGdcApplicationEnvironmentUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceDataprocGdcApplicationEnvironment().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceDataprocGdcApplicationEnvironmentRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -594,6 +633,13 @@ func resourceDataprocGdcApplicationEnvironmentUpdate(d *schema.ResourceData, met } func resourceDataprocGdcApplicationEnvironmentDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DataprocGdcApplicationEnvironment without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing ApplicationEnvironment %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/dataprocgdc/resource_dataproc_gdc_application_environment_generated_meta.yaml b/google-beta/services/dataprocgdc/resource_dataproc_gdc_application_environment_generated_meta.yaml index cbad21a4dcc..ad7a5131bc7 100644 --- a/google-beta/services/dataprocgdc/resource_dataproc_gdc_application_environment_generated_meta.yaml +++ b/google-beta/services/dataprocgdc/resource_dataproc_gdc_application_environment_generated_meta.yaml @@ -30,3 +30,5 @@ fields: provider_only: true - api_field: uid - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/dataprocgdc/resource_dataproc_gdc_service_instance.go b/google-beta/services/dataprocgdc/resource_dataproc_gdc_service_instance.go index 575ad8191aa..0dcf2f9c434 100644 --- a/google-beta/services/dataprocgdc/resource_dataproc_gdc_service_instance.go +++ b/google-beta/services/dataprocgdc/resource_dataproc_gdc_service_instance.go @@ -116,6 +116,7 @@ func ResourceDataprocGdcServiceInstance() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -285,6 +286,18 @@ Please refer to the field 'effective_labels' for all of the labels present on th Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -446,6 +459,19 @@ func resourceDataprocGdcServiceInstanceRead(d *schema.ResourceData, meta interfa log.Printf("[DEBUG] Finished reading DataprocGdcServiceInstance %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading ServiceInstance: %s", err) } @@ -483,11 +509,18 @@ func resourceDataprocGdcServiceInstanceRead(d *schema.ResourceData, meta interfa } func resourceDataprocGdcServiceInstanceUpdate(d *schema.ResourceData, meta interface{}) error { - // Only the root field "labels", "terraform_labels", and virtual fields are mutable + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable return resourceDataprocGdcServiceInstanceRead(d, meta) } func resourceDataprocGdcServiceInstanceDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DataprocGdcServiceInstance without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing ServiceInstance %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/dataprocgdc/resource_dataproc_gdc_service_instance_generated_meta.yaml b/google-beta/services/dataprocgdc/resource_dataproc_gdc_service_instance_generated_meta.yaml index 769394ba84a..819f782fa6d 100644 --- a/google-beta/services/dataprocgdc/resource_dataproc_gdc_service_instance_generated_meta.yaml +++ b/google-beta/services/dataprocgdc/resource_dataproc_gdc_service_instance_generated_meta.yaml @@ -30,3 +30,5 @@ fields: provider_only: true - api_field: uid - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/dataprocgdc/resource_dataproc_gdc_spark_application.go b/google-beta/services/dataprocgdc/resource_dataproc_gdc_spark_application.go index 235483eb236..0d6eca3f464 100644 --- a/google-beta/services/dataprocgdc/resource_dataproc_gdc_spark_application.go +++ b/google-beta/services/dataprocgdc/resource_dataproc_gdc_spark_application.go @@ -117,6 +117,7 @@ func ResourceDataprocGdcSparkApplication() *schema.Resource { tpgresource.SetLabelsDiff, tpgresource.SetAnnotationsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -526,6 +527,18 @@ Possible values: Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -734,6 +747,19 @@ func resourceDataprocGdcSparkApplicationRead(d *schema.ResourceData, meta interf log.Printf("[DEBUG] Finished reading DataprocGdcSparkApplication %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading SparkApplication: %s", err) } @@ -777,11 +803,18 @@ func resourceDataprocGdcSparkApplicationRead(d *schema.ResourceData, meta interf } func resourceDataprocGdcSparkApplicationUpdate(d *schema.ResourceData, meta interface{}) error { - // Only the root field "labels", "terraform_labels", and virtual fields are mutable + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable return resourceDataprocGdcSparkApplicationRead(d, meta) } func resourceDataprocGdcSparkApplicationDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DataprocGdcSparkApplication without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing SparkApplication %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/dataprocgdc/resource_dataproc_gdc_spark_application_generated_meta.yaml b/google-beta/services/dataprocgdc/resource_dataproc_gdc_spark_application_generated_meta.yaml index 28c5a20ea10..9f3f2662238 100644 --- a/google-beta/services/dataprocgdc/resource_dataproc_gdc_spark_application_generated_meta.yaml +++ b/google-beta/services/dataprocgdc/resource_dataproc_gdc_spark_application_generated_meta.yaml @@ -57,3 +57,5 @@ fields: - api_field: uid - api_field: updateTime - api_field: version + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/dataprocmetastore/resource_dataproc_metastore_federation.go b/google-beta/services/dataprocmetastore/resource_dataproc_metastore_federation.go index eae69c68074..ffc8fc16ad4 100644 --- a/google-beta/services/dataprocmetastore/resource_dataproc_metastore_federation.go +++ b/google-beta/services/dataprocmetastore/resource_dataproc_metastore_federation.go @@ -116,6 +116,7 @@ func ResourceDataprocMetastoreFederation() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -266,6 +267,18 @@ or 'terraform destroy' that would delete the federation will fail.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -427,6 +440,18 @@ func resourceDataprocMetastoreFederationRead(d *schema.ResourceData, meta interf return fmt.Errorf("Error setting deletion_protection: %s", err) } } + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Federation: %s", err) } @@ -464,6 +489,19 @@ func resourceDataprocMetastoreFederationRead(d *schema.ResourceData, meta interf } func resourceDataprocMetastoreFederationUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceDataprocMetastoreFederation().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceDataprocMetastoreFederationRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -572,6 +610,13 @@ func resourceDataprocMetastoreFederationUpdate(d *schema.ResourceData, meta inte } func resourceDataprocMetastoreFederationDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DataprocMetastoreFederation without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Federation %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/dataprocmetastore/resource_dataproc_metastore_federation_generated_meta.yaml b/google-beta/services/dataprocmetastore/resource_dataproc_metastore_federation_generated_meta.yaml index 85482940412..31413249e2f 100644 --- a/google-beta/services/dataprocmetastore/resource_dataproc_metastore_federation_generated_meta.yaml +++ b/google-beta/services/dataprocmetastore/resource_dataproc_metastore_federation_generated_meta.yaml @@ -33,3 +33,5 @@ fields: - api_field: uid - api_field: updateTime - api_field: version + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/dataprocmetastore/resource_dataproc_metastore_service.go b/google-beta/services/dataprocmetastore/resource_dataproc_metastore_service.go index 4c5ee0b6875..74d13d3e741 100644 --- a/google-beta/services/dataprocmetastore/resource_dataproc_metastore_service.go +++ b/google-beta/services/dataprocmetastore/resource_dataproc_metastore_service.go @@ -116,6 +116,7 @@ func ResourceDataprocMetastoreService() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -599,6 +600,18 @@ Keys must be in the format tagKeys/{tag_key_id}, and values are in the format ta Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -826,6 +839,19 @@ func resourceDataprocMetastoreServiceRead(d *schema.ResourceData, meta interface log.Printf("[DEBUG] Finished reading DataprocMetastoreService %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Service: %s", err) } @@ -863,6 +889,19 @@ func resourceDataprocMetastoreServiceRead(d *schema.ResourceData, meta interface } func resourceDataprocMetastoreServiceUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceDataprocMetastoreService().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceDataprocMetastoreServiceRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1061,6 +1100,13 @@ func resourceDataprocMetastoreServiceUpdate(d *schema.ResourceData, meta interfa } func resourceDataprocMetastoreServiceDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DataprocMetastoreService without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Service %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/dataprocmetastore/resource_dataproc_metastore_service_generated_meta.yaml b/google-beta/services/dataprocmetastore/resource_dataproc_metastore_service_generated_meta.yaml index 546ce00de22..665e2ba22f9 100644 --- a/google-beta/services/dataprocmetastore/resource_dataproc_metastore_service_generated_meta.yaml +++ b/google-beta/services/dataprocmetastore/resource_dataproc_metastore_service_generated_meta.yaml @@ -60,3 +60,5 @@ fields: - api_field: tier - api_field: uid - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/datastream/resource_datastream_connection_profile.go b/google-beta/services/datastream/resource_datastream_connection_profile.go index f81b38a75ab..845d377c332 100644 --- a/google-beta/services/datastream/resource_datastream_connection_profile.go +++ b/google-beta/services/datastream/resource_datastream_connection_profile.go @@ -127,6 +127,7 @@ func ResourceDatastreamConnectionProfile() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -839,6 +840,18 @@ https://spanner.{region}.rep.googleapis.com.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -1053,6 +1066,19 @@ func resourceDatastreamConnectionProfileRead(d *schema.ResourceData, meta interf log.Printf("[DEBUG] Finished reading DatastreamConnectionProfile %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading ConnectionProfile: %s", err) } @@ -1090,6 +1116,19 @@ func resourceDatastreamConnectionProfileRead(d *schema.ResourceData, meta interf } func resourceDatastreamConnectionProfileUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceDatastreamConnectionProfile().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceDatastreamConnectionProfileRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1336,6 +1375,13 @@ func resourceDatastreamConnectionProfileUpdate(d *schema.ResourceData, meta inte } func resourceDatastreamConnectionProfileDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DatastreamConnectionProfile without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing ConnectionProfile %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/datastream/resource_datastream_connection_profile_generated_meta.yaml b/google-beta/services/datastream/resource_datastream_connection_profile_generated_meta.yaml index 5576231ca00..c767440bc90 100644 --- a/google-beta/services/datastream/resource_datastream_connection_profile_generated_meta.yaml +++ b/google-beta/services/datastream/resource_datastream_connection_profile_generated_meta.yaml @@ -89,3 +89,5 @@ fields: - api_field: sqlServerProfile.username - field: terraform_labels provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/datastream/resource_datastream_private_connection.go b/google-beta/services/datastream/resource_datastream_private_connection.go index f6ed4af4491..3ac9746c2f0 100644 --- a/google-beta/services/datastream/resource_datastream_private_connection.go +++ b/google-beta/services/datastream/resource_datastream_private_connection.go @@ -157,6 +157,7 @@ func ResourceDatastreamPrivateConnection() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("FORCE"), ), Identity: &schema.ResourceIdentity{ @@ -312,21 +313,18 @@ Format: projects/{project}/global/{networks}/{name}`, and default labels configured on the provider.`, Elem: &schema.Schema{Type: schema.TypeString}, }, - "deletion_policy": { - Type: schema.TypeString, - Optional: true, - Description: `The deletion policy for the private connection. Setting 'FORCE' will also delete any child -routes that belong to this private connection. Setting 'DEFAULT' will fail the delete if -child routes exist. Defaults to 'FORCE' for backwards compatibility. -Possible values: 'DEFAULT', 'FORCE'.`, - Default: "FORCE", - }, "project": { Type: schema.TypeString, Optional: true, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `This field uses a custom implementation please refer to documentation under /hashicorp/terraform-provider-google-beta/website/docs/r/datastream_private_connection.html.markdown for specifics`, + }, }, UseJSONNumber: true, } @@ -488,8 +486,15 @@ func resourceDatastreamPrivateConnectionRead(d *schema.ResourceData, meta interf // Explicitly set virtual fields to default values if unset if _, ok := d.GetOkExists("deletion_policy"); !ok { - if err := d.Set("deletion_policy", "FORCE"); err != nil { - return fmt.Errorf("Error setting deletion_policy: %s", err) + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "FORCE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } } } if err := d.Set("project", project); err != nil { @@ -529,11 +534,18 @@ func resourceDatastreamPrivateConnectionRead(d *schema.ResourceData, meta interf } func resourceDatastreamPrivateConnectionUpdate(d *schema.ResourceData, meta interface{}) error { - // Only the root field "labels", "terraform_labels", and virtual fields are mutable + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable return resourceDatastreamPrivateConnectionRead(d, meta) } func resourceDatastreamPrivateConnectionDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DatastreamPrivateConnection without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing PrivateConnection %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -613,9 +625,6 @@ func resourceDatastreamPrivateConnectionImport(d *schema.ResourceData, meta inte d.SetId(id) // Explicitly set virtual fields to default values on import - if err := d.Set("deletion_policy", "FORCE"); err != nil { - return nil, fmt.Errorf("Error setting deletion_policy: %s", err) - } if err := waitForPrivateConnectionReady(d, config, d.Timeout(schema.TimeoutCreate)-time.Minute); err != nil { return nil, fmt.Errorf("Error waiting for PrivateConnection %q to be CREATED during importing: %q", d.Get("name").(string), err) } diff --git a/google-beta/services/datastream/resource_datastream_private_connection_generated_meta.yaml b/google-beta/services/datastream/resource_datastream_private_connection_generated_meta.yaml index 608b5aaacb4..376e73cf08d 100644 --- a/google-beta/services/datastream/resource_datastream_private_connection_generated_meta.yaml +++ b/google-beta/services/datastream/resource_datastream_private_connection_generated_meta.yaml @@ -9,8 +9,6 @@ api_resource_type_kind: PrivateConnection fields: - field: create_without_validation provider_only: true - - field: deletion_policy - provider_only: true - api_field: displayName - field: effective_labels provider_only: true @@ -28,3 +26,5 @@ fields: provider_only: true - api_field: vpcPeeringConfig.subnet - api_field: vpcPeeringConfig.vpc + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/datastream/resource_datastream_stream.go b/google-beta/services/datastream/resource_datastream_stream.go index 80bb39a1b12..42e0e8e168f 100644 --- a/google-beta/services/datastream/resource_datastream_stream.go +++ b/google-beta/services/datastream/resource_datastream_stream.go @@ -182,6 +182,7 @@ func ResourceDatastreamStream() *schema.Resource { resourceDatastreamStreamCustomDiff, tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -2653,6 +2654,18 @@ Possible values: NOT_STARTED, RUNNING, PAUSED. Default: NOT_STARTED`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -2854,6 +2867,18 @@ func resourceDatastreamStreamRead(d *schema.ResourceData, meta interface{}) erro return fmt.Errorf("Error setting desired_state: %s", err) } } + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Stream: %s", err) } @@ -2891,6 +2916,19 @@ func resourceDatastreamStreamRead(d *schema.ResourceData, meta interface{}) erro } func resourceDatastreamStreamUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceDatastreamStream().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceDatastreamStreamRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -3089,6 +3127,13 @@ func resourceDatastreamStreamUpdate(d *schema.ResourceData, meta interface{}) er } func resourceDatastreamStreamDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DatastreamStream without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Stream %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/datastream/resource_datastream_stream_generated_meta.yaml b/google-beta/services/datastream/resource_datastream_stream_generated_meta.yaml index c884bffbb24..90c5e3e2781 100644 --- a/google-beta/services/datastream/resource_datastream_stream_generated_meta.yaml +++ b/google-beta/services/datastream/resource_datastream_stream_generated_meta.yaml @@ -244,3 +244,5 @@ fields: provider_only: true - field: terraform_labels provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/deploymentmanager/resource_deployment_manager_deployment.go b/google-beta/services/deploymentmanager/resource_deployment_manager_deployment.go index 9ec2333437e..bd82d101117 100644 --- a/google-beta/services/deploymentmanager/resource_deployment_manager_deployment.go +++ b/google-beta/services/deploymentmanager/resource_deployment_manager_deployment.go @@ -141,6 +141,7 @@ func ResourceDeploymentManagerDeployment() *schema.Resource { CustomizeDiff: customdiff.All( customDiffDeploymentManagerDeployment, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -289,6 +290,18 @@ was successfully deployed.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -457,6 +470,19 @@ func resourceDeploymentManagerDeploymentRead(d *schema.ResourceData, meta interf log.Printf("[DEBUG] Finished reading DeploymentManagerDeployment %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Deployment: %s", err) } @@ -488,6 +514,19 @@ func resourceDeploymentManagerDeploymentRead(d *schema.ResourceData, meta interf } func resourceDeploymentManagerDeploymentUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceDeploymentManagerDeployment().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceDeploymentManagerDeploymentRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -667,6 +706,13 @@ func resourceDeploymentManagerDeploymentUpdate(d *schema.ResourceData, meta inte } func resourceDeploymentManagerDeploymentDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DeploymentManagerDeployment without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Deployment %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/deploymentmanager/resource_deployment_manager_deployment_generated_meta.yaml b/google-beta/services/deploymentmanager/resource_deployment_manager_deployment_generated_meta.yaml index afcf132d740..68ed0fd8ea4 100644 --- a/google-beta/services/deploymentmanager/resource_deployment_manager_deployment_generated_meta.yaml +++ b/google-beta/services/deploymentmanager/resource_deployment_manager_deployment_generated_meta.yaml @@ -24,3 +24,5 @@ fields: - api_field: target.config.content - api_field: target.imports.content - api_field: target.imports.name + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/developerconnect/resource_developer_connect_account_connector.go b/google-beta/services/developerconnect/resource_developer_connect_account_connector.go index d978b7775e2..b32c388779d 100644 --- a/google-beta/services/developerconnect/resource_developer_connect_account_connector.go +++ b/google-beta/services/developerconnect/resource_developer_connect_account_connector.go @@ -117,6 +117,7 @@ func ResourceDeveloperConnectAccountConnector() *schema.Resource { tpgresource.SetAnnotationsDiff, tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -368,6 +369,18 @@ behalf of the user configured under the account connector.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -535,6 +548,19 @@ func resourceDeveloperConnectAccountConnectorRead(d *schema.ResourceData, meta i log.Printf("[DEBUG] Finished reading DeveloperConnectAccountConnector %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading AccountConnector: %s", err) } @@ -572,6 +598,19 @@ func resourceDeveloperConnectAccountConnectorRead(d *schema.ResourceData, meta i } func resourceDeveloperConnectAccountConnectorUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceDeveloperConnectAccountConnector().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceDeveloperConnectAccountConnectorRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -720,6 +759,13 @@ func resourceDeveloperConnectAccountConnectorUpdate(d *schema.ResourceData, meta } func resourceDeveloperConnectAccountConnectorDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DeveloperConnectAccountConnector without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing AccountConnector %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/developerconnect/resource_developer_connect_account_connector_generated_meta.yaml b/google-beta/services/developerconnect/resource_developer_connect_account_connector_generated_meta.yaml index de0874e2168..94f1e3155bf 100644 --- a/google-beta/services/developerconnect/resource_developer_connect_account_connector_generated_meta.yaml +++ b/google-beta/services/developerconnect/resource_developer_connect_account_connector_generated_meta.yaml @@ -39,3 +39,5 @@ fields: - field: terraform_labels provider_only: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/developerconnect/resource_developer_connect_connection.go b/google-beta/services/developerconnect/resource_developer_connect_connection.go index c45fe12f4af..35e0ecb3b6f 100644 --- a/google-beta/services/developerconnect/resource_developer_connect_connection.go +++ b/google-beta/services/developerconnect/resource_developer_connect_connection.go @@ -117,6 +117,7 @@ func ResourceDeveloperConnectConnection() *schema.Resource { tpgresource.SetLabelsDiff, tpgresource.SetAnnotationsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -833,6 +834,18 @@ background.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -1036,6 +1049,19 @@ func resourceDeveloperConnectConnectionRead(d *schema.ResourceData, meta interfa log.Printf("[DEBUG] Finished reading DeveloperConnectConnection %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Connection: %s", err) } @@ -1073,6 +1099,19 @@ func resourceDeveloperConnectConnectionRead(d *schema.ResourceData, meta interfa } func resourceDeveloperConnectConnectionUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceDeveloperConnectConnection().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceDeveloperConnectConnectionRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1281,6 +1320,13 @@ func resourceDeveloperConnectConnectionUpdate(d *schema.ResourceData, meta inter } func resourceDeveloperConnectConnectionDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DeveloperConnectConnection without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Connection %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/developerconnect/resource_developer_connect_connection_generated_meta.yaml b/google-beta/services/developerconnect/resource_developer_connect_connection_generated_meta.yaml index 1a7e47172a0..cc99d444a24 100644 --- a/google-beta/services/developerconnect/resource_developer_connect_connection_generated_meta.yaml +++ b/google-beta/services/developerconnect/resource_developer_connect_connection_generated_meta.yaml @@ -82,3 +82,5 @@ fields: provider_only: true - api_field: uid - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/developerconnect/resource_developer_connect_git_repository_link.go b/google-beta/services/developerconnect/resource_developer_connect_git_repository_link.go index ff49bb5b229..6e21808e2a7 100644 --- a/google-beta/services/developerconnect/resource_developer_connect_git_repository_link.go +++ b/google-beta/services/developerconnect/resource_developer_connect_git_repository_link.go @@ -117,6 +117,7 @@ func ResourceDeveloperConnectGitRepositoryLink() *schema.Resource { tpgresource.SetLabelsDiff, tpgresource.SetAnnotationsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -259,6 +260,18 @@ background.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -419,6 +432,19 @@ func resourceDeveloperConnectGitRepositoryLinkRead(d *schema.ResourceData, meta log.Printf("[DEBUG] Finished reading DeveloperConnectGitRepositoryLink %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading GitRepositoryLink: %s", err) } @@ -462,11 +488,18 @@ func resourceDeveloperConnectGitRepositoryLinkRead(d *schema.ResourceData, meta } func resourceDeveloperConnectGitRepositoryLinkUpdate(d *schema.ResourceData, meta interface{}) error { - // Only the root field "labels", "terraform_labels", and virtual fields are mutable + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable return resourceDeveloperConnectGitRepositoryLinkRead(d, meta) } func resourceDeveloperConnectGitRepositoryLinkDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DeveloperConnectGitRepositoryLink without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing GitRepositoryLink %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/developerconnect/resource_developer_connect_git_repository_link_generated_meta.yaml b/google-beta/services/developerconnect/resource_developer_connect_git_repository_link_generated_meta.yaml index bf772bdaa4a..c62b0a420a6 100644 --- a/google-beta/services/developerconnect/resource_developer_connect_git_repository_link_generated_meta.yaml +++ b/google-beta/services/developerconnect/resource_developer_connect_git_repository_link_generated_meta.yaml @@ -30,3 +30,5 @@ fields: provider_only: true - api_field: uid - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/developerconnect/resource_developer_connect_insights_config.go b/google-beta/services/developerconnect/resource_developer_connect_insights_config.go index 59865c2d9c6..2cf3b85b3f5 100644 --- a/google-beta/services/developerconnect/resource_developer_connect_insights_config.go +++ b/google-beta/services/developerconnect/resource_developer_connect_insights_config.go @@ -117,6 +117,7 @@ func ResourceDeveloperConnectInsightsConfig() *schema.Resource { tpgresource.SetAnnotationsDiff, tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -436,6 +437,18 @@ ERROR`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -597,6 +610,19 @@ func resourceDeveloperConnectInsightsConfigRead(d *schema.ResourceData, meta int log.Printf("[DEBUG] Finished reading DeveloperConnectInsightsConfig %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading InsightsConfig: %s", err) } @@ -634,6 +660,19 @@ func resourceDeveloperConnectInsightsConfigRead(d *schema.ResourceData, meta int } func resourceDeveloperConnectInsightsConfigUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceDeveloperConnectInsightsConfig().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceDeveloperConnectInsightsConfigRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -762,6 +801,13 @@ func resourceDeveloperConnectInsightsConfigUpdate(d *schema.ResourceData, meta i } func resourceDeveloperConnectInsightsConfigDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DeveloperConnectInsightsConfig without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing InsightsConfig %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/developerconnect/resource_developer_connect_insights_config_generated_meta.yaml b/google-beta/services/developerconnect/resource_developer_connect_insights_config_generated_meta.yaml index 08784037385..6a5ed731f22 100644 --- a/google-beta/services/developerconnect/resource_developer_connect_insights_config_generated_meta.yaml +++ b/google-beta/services/developerconnect/resource_developer_connect_insights_config_generated_meta.yaml @@ -42,3 +42,5 @@ fields: - field: terraform_labels provider_only: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/dialogflow/resource_dialogflow_agent.go b/google-beta/services/dialogflow/resource_dialogflow_agent.go index 58ad07d1d92..25d74f84b4f 100644 --- a/google-beta/services/dialogflow/resource_dialogflow_agent.go +++ b/google-beta/services/dialogflow/resource_dialogflow_agent.go @@ -115,6 +115,7 @@ func ResourceDialogflowAgent() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -232,6 +233,18 @@ the [avatarUri] field can be used.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -409,6 +422,19 @@ func resourceDialogflowAgentRead(d *schema.ResourceData, meta interface{}) error log.Printf("[DEBUG] Finished reading DialogflowAgent %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Agent: %s", err) } @@ -434,6 +460,19 @@ func resourceDialogflowAgentRead(d *schema.ResourceData, meta interface{}) error } func resourceDialogflowAgentUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceDialogflowAgent().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceDialogflowAgentRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -560,6 +599,13 @@ func resourceDialogflowAgentUpdate(d *schema.ResourceData, meta interface{}) err } func resourceDialogflowAgentDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DialogflowAgent without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Agent %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/dialogflow/resource_dialogflow_agent_generated_meta.yaml b/google-beta/services/dialogflow/resource_dialogflow_agent_generated_meta.yaml index 969c8fe7e18..753e6673331 100644 --- a/google-beta/services/dialogflow/resource_dialogflow_agent_generated_meta.yaml +++ b/google-beta/services/dialogflow/resource_dialogflow_agent_generated_meta.yaml @@ -20,3 +20,5 @@ fields: - api_field: supportedLanguageCodes - api_field: tier - api_field: timeZone + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/dialogflow/resource_dialogflow_conversation_profile.go b/google-beta/services/dialogflow/resource_dialogflow_conversation_profile.go index 05ae8646df3..8c8051758fb 100644 --- a/google-beta/services/dialogflow/resource_dialogflow_conversation_profile.go +++ b/google-beta/services/dialogflow/resource_dialogflow_conversation_profile.go @@ -115,6 +115,7 @@ func ResourceDialogflowConversationProfile() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -975,6 +976,18 @@ Leave this field unspecified to use Agent Speech settings for model selection.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -1218,6 +1231,19 @@ func resourceDialogflowConversationProfileRead(d *schema.ResourceData, meta inte log.Printf("[DEBUG] Finished reading DialogflowConversationProfile %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading ConversationProfile: %s", err) } @@ -1243,6 +1269,19 @@ func resourceDialogflowConversationProfileRead(d *schema.ResourceData, meta inte } func resourceDialogflowConversationProfileUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceDialogflowConversationProfile().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceDialogflowConversationProfileRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1466,6 +1505,13 @@ func resourceDialogflowConversationProfileUpdate(d *schema.ResourceData, meta in } func resourceDialogflowConversationProfileDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DialogflowConversationProfile without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing ConversationProfile %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/dialogflow/resource_dialogflow_conversation_profile_generated_meta.yaml b/google-beta/services/dialogflow/resource_dialogflow_conversation_profile_generated_meta.yaml index d3f7e0d9c6c..7ebcad7fbd1 100644 --- a/google-beta/services/dialogflow/resource_dialogflow_conversation_profile_generated_meta.yaml +++ b/google-beta/services/dialogflow/resource_dialogflow_conversation_profile_generated_meta.yaml @@ -88,3 +88,5 @@ fields: - api_field: ttsConfig.voice.ssmlGender - api_field: ttsConfig.volumeGainDb - api_field: useBidiStreaming + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/dialogflow/resource_dialogflow_entity_type.go b/google-beta/services/dialogflow/resource_dialogflow_entity_type.go index 3df9ca796e6..cdbd5b38174 100644 --- a/google-beta/services/dialogflow/resource_dialogflow_entity_type.go +++ b/google-beta/services/dialogflow/resource_dialogflow_entity_type.go @@ -115,6 +115,7 @@ func ResourceDialogflowEntityType() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -195,6 +196,18 @@ Format: projects//agent/entityTypes/.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -336,6 +349,19 @@ func resourceDialogflowEntityTypeRead(d *schema.ResourceData, meta interface{}) log.Printf("[DEBUG] Finished reading DialogflowEntityType %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading EntityType: %s", err) } @@ -361,6 +387,19 @@ func resourceDialogflowEntityTypeRead(d *schema.ResourceData, meta interface{}) } func resourceDialogflowEntityTypeUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceDialogflowEntityType().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceDialogflowEntityTypeRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -445,6 +484,13 @@ func resourceDialogflowEntityTypeUpdate(d *schema.ResourceData, meta interface{} } func resourceDialogflowEntityTypeDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DialogflowEntityType without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing EntityType %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/dialogflow/resource_dialogflow_entity_type_generated_meta.yaml b/google-beta/services/dialogflow/resource_dialogflow_entity_type_generated_meta.yaml index 41389f07522..4b35c9c4c59 100644 --- a/google-beta/services/dialogflow/resource_dialogflow_entity_type_generated_meta.yaml +++ b/google-beta/services/dialogflow/resource_dialogflow_entity_type_generated_meta.yaml @@ -13,3 +13,5 @@ fields: - api_field: entities.value - api_field: kind - api_field: name + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/dialogflow/resource_dialogflow_environment.go b/google-beta/services/dialogflow/resource_dialogflow_environment.go index bee321e02ea..20302545ecf 100644 --- a/google-beta/services/dialogflow/resource_dialogflow_environment.go +++ b/google-beta/services/dialogflow/resource_dialogflow_environment.go @@ -115,6 +115,7 @@ func ResourceDialogflowEnvironment() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -331,6 +332,18 @@ func ResourceDialogflowEnvironment() *schema.Resource { Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -476,6 +489,19 @@ func resourceDialogflowEnvironmentRead(d *schema.ResourceData, meta interface{}) log.Printf("[DEBUG] Finished reading DialogflowEnvironment %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Environment: %s", err) } @@ -513,6 +539,19 @@ func resourceDialogflowEnvironmentRead(d *schema.ResourceData, meta interface{}) } func resourceDialogflowEnvironmentUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceDialogflowEnvironment().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceDialogflowEnvironmentRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -634,6 +673,13 @@ func resourceDialogflowEnvironmentUpdate(d *schema.ResourceData, meta interface{ } func resourceDialogflowEnvironmentDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DialogflowEnvironment without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Environment %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/dialogflow/resource_dialogflow_environment_generated_meta.yaml b/google-beta/services/dialogflow/resource_dialogflow_environment_generated_meta.yaml index cbd464278e4..9151e85fbf5 100644 --- a/google-beta/services/dialogflow/resource_dialogflow_environment_generated_meta.yaml +++ b/google-beta/services/dialogflow/resource_dialogflow_environment_generated_meta.yaml @@ -39,3 +39,5 @@ fields: field: text_to_speech_settings.synthesize_speech_configs.voice.ssml_gender - api_field: textToSpeechSettings.synthesizeSpeechConfigs.value.volumeGainDb field: text_to_speech_settings.synthesize_speech_configs.volume_gain_db + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/dialogflow/resource_dialogflow_fulfillment.go b/google-beta/services/dialogflow/resource_dialogflow_fulfillment.go index 32478220ac1..0176746ff9b 100644 --- a/google-beta/services/dialogflow/resource_dialogflow_fulfillment.go +++ b/google-beta/services/dialogflow/resource_dialogflow_fulfillment.go @@ -115,6 +115,7 @@ func ResourceDialogflowFulfillment() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -202,6 +203,18 @@ Format: projects//agent/fulfillment - projects//location Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -343,6 +356,19 @@ func resourceDialogflowFulfillmentRead(d *schema.ResourceData, meta interface{}) log.Printf("[DEBUG] Finished reading DialogflowFulfillment %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Fulfillment: %s", err) } @@ -368,6 +394,19 @@ func resourceDialogflowFulfillmentRead(d *schema.ResourceData, meta interface{}) } func resourceDialogflowFulfillmentUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceDialogflowFulfillment().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceDialogflowFulfillmentRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -479,6 +518,13 @@ func resourceDialogflowFulfillmentUpdate(d *schema.ResourceData, meta interface{ } func resourceDialogflowFulfillmentDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DialogflowFulfillment without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Fulfillment %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/dialogflow/resource_dialogflow_fulfillment_generated_meta.yaml b/google-beta/services/dialogflow/resource_dialogflow_fulfillment_generated_meta.yaml index 87e56a289e1..8b05e48931e 100644 --- a/google-beta/services/dialogflow/resource_dialogflow_fulfillment_generated_meta.yaml +++ b/google-beta/services/dialogflow/resource_dialogflow_fulfillment_generated_meta.yaml @@ -15,3 +15,5 @@ fields: - api_field: genericWebService.uri - api_field: genericWebService.username - api_field: name + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/dialogflow/resource_dialogflow_generator.go b/google-beta/services/dialogflow/resource_dialogflow_generator.go index 48c670e46b2..042f105a41f 100644 --- a/google-beta/services/dialogflow/resource_dialogflow_generator.go +++ b/google-beta/services/dialogflow/resource_dialogflow_generator.go @@ -115,6 +115,7 @@ func ResourceDialogflowGenerator() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -384,6 +385,18 @@ func ResourceDialogflowGenerator() *schema.Resource { Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -589,6 +602,19 @@ func resourceDialogflowGeneratorRead(d *schema.ResourceData, meta interface{}) e log.Printf("[DEBUG] Finished reading DialogflowGenerator %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Generator: %s", err) } @@ -626,6 +652,19 @@ func resourceDialogflowGeneratorRead(d *schema.ResourceData, meta interface{}) e } func resourceDialogflowGeneratorUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceDialogflowGenerator().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceDialogflowGeneratorRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -779,6 +818,13 @@ func resourceDialogflowGeneratorUpdate(d *schema.ResourceData, meta interface{}) } func resourceDialogflowGeneratorDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DialogflowGenerator without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Generator %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/dialogflow/resource_dialogflow_generator_generated_meta.yaml b/google-beta/services/dialogflow/resource_dialogflow_generator_generated_meta.yaml index a179b241b2c..a73089ec2c3 100644 --- a/google-beta/services/dialogflow/resource_dialogflow_generator_generated_meta.yaml +++ b/google-beta/services/dialogflow/resource_dialogflow_generator_generated_meta.yaml @@ -33,3 +33,5 @@ fields: - api_field: summarizationContext.summarizationSections.type - api_field: summarizationContext.version - api_field: triggerEvent + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/dialogflow/resource_dialogflow_intent.go b/google-beta/services/dialogflow/resource_dialogflow_intent.go index a97b2ad8ba9..cf2acd46ce5 100644 --- a/google-beta/services/dialogflow/resource_dialogflow_intent.go +++ b/google-beta/services/dialogflow/resource_dialogflow_intent.go @@ -115,6 +115,7 @@ func ResourceDialogflowIntent() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -262,6 +263,18 @@ Format: projects//agent/intents/.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -445,6 +458,19 @@ func resourceDialogflowIntentRead(d *schema.ResourceData, meta interface{}) erro log.Printf("[DEBUG] Finished reading DialogflowIntent %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Intent: %s", err) } @@ -470,6 +496,19 @@ func resourceDialogflowIntentRead(d *schema.ResourceData, meta interface{}) erro } func resourceDialogflowIntentUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceDialogflowIntent().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceDialogflowIntentRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -590,6 +629,13 @@ func resourceDialogflowIntentUpdate(d *schema.ResourceData, meta interface{}) er } func resourceDialogflowIntentDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DialogflowIntent without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Intent %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/dialogflow/resource_dialogflow_intent_generated_meta.yaml b/google-beta/services/dialogflow/resource_dialogflow_intent_generated_meta.yaml index 21012755184..dadf7e95be7 100644 --- a/google-beta/services/dialogflow/resource_dialogflow_intent_generated_meta.yaml +++ b/google-beta/services/dialogflow/resource_dialogflow_intent_generated_meta.yaml @@ -22,3 +22,5 @@ fields: - api_field: resetContexts - api_field: rootFollowupIntentName - api_field: webhookState + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/dialogflow/resource_dialogflow_version.go b/google-beta/services/dialogflow/resource_dialogflow_version.go index c9ef7bde654..980cb6bf5c1 100644 --- a/google-beta/services/dialogflow/resource_dialogflow_version.go +++ b/google-beta/services/dialogflow/resource_dialogflow_version.go @@ -160,6 +160,19 @@ Format: projects//agent.`, Computed: true, Description: `The sequential number of this version.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -276,6 +289,20 @@ func resourceDialogflowVersionRead(d *schema.ResourceData, meta interface{}) err log.Printf("[DEBUG] Finished reading DialogflowVersion %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceDialogflowVersionFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -303,6 +330,19 @@ func resourceDialogflowVersionRead(d *schema.ResourceData, meta interface{}) err } func resourceDialogflowVersionUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceDialogflowVersion().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceDialogflowVersionRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -383,6 +423,13 @@ func resourceDialogflowVersionUpdate(d *schema.ResourceData, meta interface{}) e } func resourceDialogflowVersionDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DialogflowVersion without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Version %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/dialogflow/resource_dialogflow_version_generated_meta.yaml b/google-beta/services/dialogflow/resource_dialogflow_version_generated_meta.yaml index 0648b89c3e2..ddbe3301ebb 100644 --- a/google-beta/services/dialogflow/resource_dialogflow_version_generated_meta.yaml +++ b/google-beta/services/dialogflow/resource_dialogflow_version_generated_meta.yaml @@ -13,3 +13,5 @@ fields: provider_only: true - api_field: status - api_field: versionNumber + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/dialogflowcx/resource_dialogflow_cx_agent.go b/google-beta/services/dialogflowcx/resource_dialogflow_cx_agent.go index 5686618911a..52f94d69449 100644 --- a/google-beta/services/dialogflowcx/resource_dialogflow_cx_agent.go +++ b/google-beta/services/dialogflowcx/resource_dialogflow_cx_agent.go @@ -115,6 +115,7 @@ func ResourceDialogflowCXAgent() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -550,6 +551,18 @@ The ID of the implicitly created engine is stored in the 'genAppBuilderSettings' Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -803,6 +816,18 @@ func resourceDialogflowCXAgentRead(d *schema.ResourceData, meta interface{}) err return fmt.Errorf("Error setting delete_chat_engine_on_destroy: %s", err) } } + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Agent: %s", err) } @@ -840,6 +865,19 @@ func resourceDialogflowCXAgentRead(d *schema.ResourceData, meta interface{}) err } func resourceDialogflowCXAgentUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceDialogflowCXAgent().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceDialogflowCXAgentRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1111,6 +1149,13 @@ func resourceDialogflowCXAgentUpdate(d *schema.ResourceData, meta interface{}) e } func resourceDialogflowCXAgentDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DialogflowCXAgent without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Agent %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/dialogflowcx/resource_dialogflow_cx_agent_generated_meta.yaml b/google-beta/services/dialogflowcx/resource_dialogflow_cx_agent_generated_meta.yaml index b96b1965344..2c7b1d03750 100644 --- a/google-beta/services/dialogflowcx/resource_dialogflow_cx_agent_generated_meta.yaml +++ b/google-beta/services/dialogflowcx/resource_dialogflow_cx_agent_generated_meta.yaml @@ -53,3 +53,5 @@ fields: - api_field: textToSpeechSettings.synthesizeSpeechConfigs json: true - api_field: timeZone + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/dialogflowcx/resource_dialogflow_cx_entity_type.go b/google-beta/services/dialogflowcx/resource_dialogflow_cx_entity_type.go index 2c5a72d6733..9ec3efb2e1c 100644 --- a/google-beta/services/dialogflowcx/resource_dialogflow_cx_entity_type.go +++ b/google-beta/services/dialogflowcx/resource_dialogflow_cx_entity_type.go @@ -229,6 +229,19 @@ Format: projects//locations//agents/.`, Description: `The unique identifier of the entity type. Format: projects//locations//agents//entityTypes/.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -421,6 +434,20 @@ func resourceDialogflowCXEntityTypeRead(d *schema.ResourceData, meta interface{} log.Printf("[DEBUG] Finished reading DialogflowCXEntityType %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceDialogflowCXEntityTypeFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -448,6 +475,19 @@ func resourceDialogflowCXEntityTypeRead(d *schema.ResourceData, meta interface{} } func resourceDialogflowCXEntityTypeUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceDialogflowCXEntityType().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceDialogflowCXEntityTypeRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -608,6 +648,13 @@ func resourceDialogflowCXEntityTypeUpdate(d *schema.ResourceData, meta interface } func resourceDialogflowCXEntityTypeDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DialogflowCXEntityType without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing EntityType %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/dialogflowcx/resource_dialogflow_cx_entity_type_generated_meta.yaml b/google-beta/services/dialogflowcx/resource_dialogflow_cx_entity_type_generated_meta.yaml index a8c26f9c150..0fa110611b5 100644 --- a/google-beta/services/dialogflowcx/resource_dialogflow_cx_entity_type_generated_meta.yaml +++ b/google-beta/services/dialogflowcx/resource_dialogflow_cx_entity_type_generated_meta.yaml @@ -20,3 +20,5 @@ fields: - field: parent provider_only: true - api_field: redact + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/dialogflowcx/resource_dialogflow_cx_environment.go b/google-beta/services/dialogflowcx/resource_dialogflow_cx_environment.go index 23bd60ce6f2..a4080fdd5b0 100644 --- a/google-beta/services/dialogflowcx/resource_dialogflow_cx_environment.go +++ b/google-beta/services/dialogflowcx/resource_dialogflow_cx_environment.go @@ -115,6 +115,7 @@ func ResourceDialogflowCXEnvironment() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -180,6 +181,19 @@ Format: projects//locations//agents/.`, Computed: true, Description: `Update time of this environment. A timestamp in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine fractional digits. Examples: "2014-10-02T15:01:23Z" and "2014-10-02T15:01:23.045123456Z".`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -366,6 +380,20 @@ func resourceDialogflowCXEnvironmentRead(d *schema.ResourceData, meta interface{ log.Printf("[DEBUG] Finished reading DialogflowCXEnvironment %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceDialogflowCXEnvironmentFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -393,6 +421,19 @@ func resourceDialogflowCXEnvironmentRead(d *schema.ResourceData, meta interface{ } func resourceDialogflowCXEnvironmentUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceDialogflowCXEnvironment().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceDialogflowCXEnvironmentRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -520,6 +561,13 @@ func resourceDialogflowCXEnvironmentUpdate(d *schema.ResourceData, meta interfac } func resourceDialogflowCXEnvironmentDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DialogflowCXEnvironment without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Environment %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/dialogflowcx/resource_dialogflow_cx_environment_generated_meta.yaml b/google-beta/services/dialogflowcx/resource_dialogflow_cx_environment_generated_meta.yaml index 9160be31f08..42a9bffbbca 100644 --- a/google-beta/services/dialogflowcx/resource_dialogflow_cx_environment_generated_meta.yaml +++ b/google-beta/services/dialogflowcx/resource_dialogflow_cx_environment_generated_meta.yaml @@ -14,3 +14,5 @@ fields: provider_only: true - api_field: updateTime - api_field: versionConfigs.version + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/dialogflowcx/resource_dialogflow_cx_flow.go b/google-beta/services/dialogflowcx/resource_dialogflow_cx_flow.go index 1e615f16283..1b197b69508 100644 --- a/google-beta/services/dialogflowcx/resource_dialogflow_cx_flow.go +++ b/google-beta/services/dialogflowcx/resource_dialogflow_cx_flow.go @@ -1305,6 +1305,19 @@ The Default Start Flow cannot be deleted; deleting the 'google_dialogflow_cx_flo ~> Avoid having multiple 'google_dialogflow_cx_flow' resources linked to the same agent with 'is_default_start_flow = true' because they will compete to control a single Default Start Flow resource in GCP.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -1535,6 +1548,18 @@ func resourceDialogflowCXFlowRead(d *schema.ResourceData, meta interface{}) erro log.Printf("[DEBUG] Finished reading DialogflowCXFlow %q: %#v", d.Id(), res) // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } err = ResourceDialogflowCXFlowFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { @@ -1563,6 +1588,19 @@ func resourceDialogflowCXFlowRead(d *schema.ResourceData, meta interface{}) erro } func resourceDialogflowCXFlowUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceDialogflowCXFlow().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceDialogflowCXFlowRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1733,6 +1771,13 @@ func resourceDialogflowCXFlowUpdate(d *schema.ResourceData, meta interface{}) er } func resourceDialogflowCXFlowDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DialogflowCXFlow without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Flow %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/dialogflowcx/resource_dialogflow_cx_flow_generated_meta.yaml b/google-beta/services/dialogflowcx/resource_dialogflow_cx_flow_generated_meta.yaml index 89119dd39ae..e2ca001cdaa 100644 --- a/google-beta/services/dialogflowcx/resource_dialogflow_cx_flow_generated_meta.yaml +++ b/google-beta/services/dialogflowcx/resource_dialogflow_cx_flow_generated_meta.yaml @@ -133,3 +133,5 @@ fields: json: true - api_field: transitionRoutes.triggerFulfillment.tag - api_field: transitionRoutes.triggerFulfillment.webhook + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/dialogflowcx/resource_dialogflow_cx_generative_settings.go b/google-beta/services/dialogflowcx/resource_dialogflow_cx_generative_settings.go index f0c6470e5b8..7eede5870a3 100644 --- a/google-beta/services/dialogflowcx/resource_dialogflow_cx_generative_settings.go +++ b/google-beta/services/dialogflowcx/resource_dialogflow_cx_generative_settings.go @@ -459,6 +459,7 @@ func resourceDialogflowCXGenerativeSettingsRead(d *schema.ResourceData, meta int } func resourceDialogflowCXGenerativeSettingsUpdate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/dialogflowcx/resource_dialogflow_cx_generator.go b/google-beta/services/dialogflowcx/resource_dialogflow_cx_generator.go index b439d81b366..c2f324b4978 100644 --- a/google-beta/services/dialogflowcx/resource_dialogflow_cx_generator.go +++ b/google-beta/services/dialogflowcx/resource_dialogflow_cx_generator.go @@ -247,6 +247,19 @@ Format: projects//locations//agents/.`, Description: `The unique identifier of the Generator. Format: projects//locations//agents//generators/.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -431,6 +444,20 @@ func resourceDialogflowCXGeneratorRead(d *schema.ResourceData, meta interface{}) log.Printf("[DEBUG] Finished reading DialogflowCXGenerator %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceDialogflowCXGeneratorFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -458,6 +485,19 @@ func resourceDialogflowCXGeneratorRead(d *schema.ResourceData, meta interface{}) } func resourceDialogflowCXGeneratorUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceDialogflowCXGenerator().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceDialogflowCXGeneratorRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -598,6 +638,13 @@ func resourceDialogflowCXGeneratorUpdate(d *schema.ResourceData, meta interface{ } func resourceDialogflowCXGeneratorDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DialogflowCXGenerator without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Generator %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/dialogflowcx/resource_dialogflow_cx_generator_generated_meta.yaml b/google-beta/services/dialogflowcx/resource_dialogflow_cx_generator_generated_meta.yaml index 8d4b400376c..ae94114bcf0 100644 --- a/google-beta/services/dialogflowcx/resource_dialogflow_cx_generator_generated_meta.yaml +++ b/google-beta/services/dialogflowcx/resource_dialogflow_cx_generator_generated_meta.yaml @@ -22,3 +22,5 @@ fields: - api_field: placeholders.id - api_field: placeholders.name - api_field: promptText.text + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/dialogflowcx/resource_dialogflow_cx_intent.go b/google-beta/services/dialogflowcx/resource_dialogflow_cx_intent.go index 8965a024d6b..0702a7296b3 100644 --- a/google-beta/services/dialogflowcx/resource_dialogflow_cx_intent.go +++ b/google-beta/services/dialogflowcx/resource_dialogflow_cx_intent.go @@ -115,6 +115,7 @@ func ResourceDialogflowCXIntent() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -302,6 +303,19 @@ The Default Negative Intent cannot be deleted; deleting the 'google_dialogflow_c ~> Avoid having multiple 'google_dialogflow_cx_intent' resources linked to the same agent with 'is_default_negative_intent = true' because they will compete to control a single Default Negative Intent resource in GCP.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -526,6 +540,18 @@ func resourceDialogflowCXIntentRead(d *schema.ResourceData, meta interface{}) er log.Printf("[DEBUG] Finished reading DialogflowCXIntent %q: %#v", d.Id(), res) // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } err = ResourceDialogflowCXIntentFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { @@ -554,6 +580,19 @@ func resourceDialogflowCXIntentRead(d *schema.ResourceData, meta interface{}) er } func resourceDialogflowCXIntentUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceDialogflowCXIntent().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceDialogflowCXIntentRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -714,6 +753,13 @@ func resourceDialogflowCXIntentUpdate(d *schema.ResourceData, meta interface{}) } func resourceDialogflowCXIntentDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DialogflowCXIntent without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Intent %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/dialogflowcx/resource_dialogflow_cx_intent_generated_meta.yaml b/google-beta/services/dialogflowcx/resource_dialogflow_cx_intent_generated_meta.yaml index fe04955f2b3..b758ed4bb27 100644 --- a/google-beta/services/dialogflowcx/resource_dialogflow_cx_intent_generated_meta.yaml +++ b/google-beta/services/dialogflowcx/resource_dialogflow_cx_intent_generated_meta.yaml @@ -32,3 +32,5 @@ fields: - api_field: trainingPhrases.parts.parameterId - api_field: trainingPhrases.parts.text - api_field: trainingPhrases.repeatCount + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/dialogflowcx/resource_dialogflow_cx_page.go b/google-beta/services/dialogflowcx/resource_dialogflow_cx_page.go index fe4864e36d0..29bf17755d7 100644 --- a/google-beta/services/dialogflowcx/resource_dialogflow_cx_page.go +++ b/google-beta/services/dialogflowcx/resource_dialogflow_cx_page.go @@ -1946,6 +1946,19 @@ You may set this, for example: Description: `The unique identifier of the page. Format: projects//locations//agents//flows//pages/.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -2150,6 +2163,20 @@ func resourceDialogflowCXPageRead(d *schema.ResourceData, meta interface{}) erro log.Printf("[DEBUG] Finished reading DialogflowCXPage %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceDialogflowCXPageFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -2177,6 +2204,19 @@ func resourceDialogflowCXPageRead(d *schema.ResourceData, meta interface{}) erro } func resourceDialogflowCXPageUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceDialogflowCXPage().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceDialogflowCXPageRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -2347,6 +2387,13 @@ func resourceDialogflowCXPageUpdate(d *schema.ResourceData, meta interface{}) er } func resourceDialogflowCXPageDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DialogflowCXPage without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Page %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/dialogflowcx/resource_dialogflow_cx_page_generated_meta.yaml b/google-beta/services/dialogflowcx/resource_dialogflow_cx_page_generated_meta.yaml index 370aa45ad14..5dbacf37749 100644 --- a/google-beta/services/dialogflowcx/resource_dialogflow_cx_page_generated_meta.yaml +++ b/google-beta/services/dialogflowcx/resource_dialogflow_cx_page_generated_meta.yaml @@ -201,3 +201,5 @@ fields: json: true - api_field: transitionRoutes.triggerFulfillment.tag - api_field: transitionRoutes.triggerFulfillment.webhook + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/dialogflowcx/resource_dialogflow_cx_playbook.go b/google-beta/services/dialogflowcx/resource_dialogflow_cx_playbook.go index e0eacccc8ca..bbe328c4034 100644 --- a/google-beta/services/dialogflowcx/resource_dialogflow_cx_playbook.go +++ b/google-beta/services/dialogflowcx/resource_dialogflow_cx_playbook.go @@ -263,6 +263,19 @@ Format: projects//locations//agents//playbook Uses RFC 3339, where generated output will always be Z-normalized and uses 0, 3, 6 or 9 fractional digits. Offsets other than "Z" are also accepted. Examples: "2014-10-02T15:01:23Z", "2014-10-02T15:01:23.045123456Z" or "2014-10-02T15:01:23+05:30".`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -449,6 +462,20 @@ func resourceDialogflowCXPlaybookRead(d *schema.ResourceData, meta interface{}) log.Printf("[DEBUG] Finished reading DialogflowCXPlaybook %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceDialogflowCXPlaybookFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -476,6 +503,19 @@ func resourceDialogflowCXPlaybookRead(d *schema.ResourceData, meta interface{}) } func resourceDialogflowCXPlaybookUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceDialogflowCXPlaybook().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceDialogflowCXPlaybookRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -647,6 +687,13 @@ func resourceDialogflowCXPlaybookUpdate(d *schema.ResourceData, meta interface{} } func resourceDialogflowCXPlaybookDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DialogflowCXPlaybook without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Playbook %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/dialogflowcx/resource_dialogflow_cx_playbook_generated_meta.yaml b/google-beta/services/dialogflowcx/resource_dialogflow_cx_playbook_generated_meta.yaml index c1080d30039..30e325f0ae6 100644 --- a/google-beta/services/dialogflowcx/resource_dialogflow_cx_playbook_generated_meta.yaml +++ b/google-beta/services/dialogflowcx/resource_dialogflow_cx_playbook_generated_meta.yaml @@ -25,3 +25,5 @@ fields: - api_field: referencedTools - api_field: tokenCount - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/dialogflowcx/resource_dialogflow_cx_security_settings.go b/google-beta/services/dialogflowcx/resource_dialogflow_cx_security_settings.go index 38cc75480a0..7bfb06b91d0 100644 --- a/google-beta/services/dialogflowcx/resource_dialogflow_cx_security_settings.go +++ b/google-beta/services/dialogflowcx/resource_dialogflow_cx_security_settings.go @@ -115,6 +115,7 @@ func ResourceDialogflowCXSecuritySettings() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -270,6 +271,18 @@ Format: projects//locations//securitySettings//locations//agents//testCase Description: `The unique identifier of the test case. Format: projects//locations//agents//testCases/.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -853,6 +866,20 @@ func resourceDialogflowCXTestCaseRead(d *schema.ResourceData, meta interface{}) log.Printf("[DEBUG] Finished reading DialogflowCXTestCase %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceDialogflowCXTestCaseFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -880,6 +907,19 @@ func resourceDialogflowCXTestCaseRead(d *schema.ResourceData, meta interface{}) } func resourceDialogflowCXTestCaseUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceDialogflowCXTestCase().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceDialogflowCXTestCaseRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1020,6 +1060,13 @@ func resourceDialogflowCXTestCaseUpdate(d *schema.ResourceData, meta interface{} } func resourceDialogflowCXTestCaseDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DialogflowCXTestCase without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing TestCase %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/dialogflowcx/resource_dialogflow_cx_test_case_generated_meta.yaml b/google-beta/services/dialogflowcx/resource_dialogflow_cx_test_case_generated_meta.yaml index fe760a63c00..88083b40190 100644 --- a/google-beta/services/dialogflowcx/resource_dialogflow_cx_test_case_generated_meta.yaml +++ b/google-beta/services/dialogflowcx/resource_dialogflow_cx_test_case_generated_meta.yaml @@ -59,3 +59,5 @@ fields: - api_field: testConfig.flow - api_field: testConfig.page - api_field: testConfig.trackingParameters + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/dialogflowcx/resource_dialogflow_cx_tool.go b/google-beta/services/dialogflowcx/resource_dialogflow_cx_tool.go index a8969977640..6cdb4c47447 100644 --- a/google-beta/services/dialogflowcx/resource_dialogflow_cx_tool.go +++ b/google-beta/services/dialogflowcx/resource_dialogflow_cx_tool.go @@ -567,6 +567,19 @@ Format: projects//locations//agents//tools//locations//agents//webhooks Computed: true, Description: `Deprecated. Name of the start flow in this agent. A start flow will be automatically created when the agent is created, and can only be deleted by deleting the agent. Format: projects//locations//agents//flows/.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -736,6 +749,20 @@ func resourceDialogflowCXWebhookRead(d *schema.ResourceData, meta interface{}) e log.Printf("[DEBUG] Finished reading DialogflowCXWebhook %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceDialogflowCXWebhookFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -763,6 +790,19 @@ func resourceDialogflowCXWebhookRead(d *schema.ResourceData, meta interface{}) e } func resourceDialogflowCXWebhookUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceDialogflowCXWebhook().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceDialogflowCXWebhookRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -933,6 +973,13 @@ func resourceDialogflowCXWebhookUpdate(d *schema.ResourceData, meta interface{}) } func resourceDialogflowCXWebhookDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DialogflowCXWebhook without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Webhook %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/dialogflowcx/resource_dialogflow_cx_webhook_generated_meta.yaml b/google-beta/services/dialogflowcx/resource_dialogflow_cx_webhook_generated_meta.yaml index 10b08c1ccc9..c1696e8b074 100644 --- a/google-beta/services/dialogflowcx/resource_dialogflow_cx_webhook_generated_meta.yaml +++ b/google-beta/services/dialogflowcx/resource_dialogflow_cx_webhook_generated_meta.yaml @@ -54,3 +54,5 @@ fields: - api_field: serviceDirectory.service - api_field: startFlow - api_field: timeout + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/discoveryengine/resource_discovery_engine_acl_config.go b/google-beta/services/discoveryengine/resource_discovery_engine_acl_config.go index fdf07447a33..960447b7d21 100644 --- a/google-beta/services/discoveryengine/resource_discovery_engine_acl_config.go +++ b/google-beta/services/discoveryengine/resource_discovery_engine_acl_config.go @@ -340,6 +340,7 @@ func resourceDiscoveryEngineAclConfigRead(d *schema.ResourceData, meta interface } func resourceDiscoveryEngineAclConfigUpdate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/discoveryengine/resource_discovery_engine_assistant.go b/google-beta/services/discoveryengine/resource_discovery_engine_assistant.go index ade021922eb..0004826d112 100644 --- a/google-beta/services/discoveryengine/resource_discovery_engine_assistant.go +++ b/google-beta/services/discoveryengine/resource_discovery_engine_assistant.go @@ -115,6 +115,7 @@ func ResourceDiscoveryEngineAssistant() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -312,6 +313,18 @@ It must be a UTF-8 encoded string with a length limit of 1024 characters.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -473,6 +486,19 @@ func resourceDiscoveryEngineAssistantRead(d *schema.ResourceData, meta interface log.Printf("[DEBUG] Finished reading DiscoveryEngineAssistant %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Assistant: %s", err) } @@ -522,6 +548,19 @@ func resourceDiscoveryEngineAssistantRead(d *schema.ResourceData, meta interface } func resourceDiscoveryEngineAssistantUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceDiscoveryEngineAssistant().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceDiscoveryEngineAssistantRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -663,6 +702,13 @@ func resourceDiscoveryEngineAssistantUpdate(d *schema.ResourceData, meta interfa } func resourceDiscoveryEngineAssistantDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DiscoveryEngineAssistant without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Assistant %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/discoveryengine/resource_discovery_engine_assistant_generated_meta.yaml b/google-beta/services/discoveryengine/resource_discovery_engine_assistant_generated_meta.yaml index d27ff4810f6..bb32b68bb00 100644 --- a/google-beta/services/discoveryengine/resource_discovery_engine_assistant_generated_meta.yaml +++ b/google-beta/services/discoveryengine/resource_discovery_engine_assistant_generated_meta.yaml @@ -27,3 +27,5 @@ fields: provider_only: true - api_field: name - api_field: webGroundingType + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/discoveryengine/resource_discovery_engine_chat_engine.go b/google-beta/services/discoveryengine/resource_discovery_engine_chat_engine.go index e4de8db649f..06746354928 100644 --- a/google-beta/services/discoveryengine/resource_discovery_engine_chat_engine.go +++ b/google-beta/services/discoveryengine/resource_discovery_engine_chat_engine.go @@ -115,6 +115,7 @@ func ResourceDiscoveryEngineChatEngine() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -305,6 +306,18 @@ characters.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -476,6 +489,19 @@ func resourceDiscoveryEngineChatEngineRead(d *schema.ResourceData, meta interfac log.Printf("[DEBUG] Finished reading DiscoveryEngineChatEngine %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading ChatEngine: %s", err) } @@ -519,6 +545,19 @@ func resourceDiscoveryEngineChatEngineRead(d *schema.ResourceData, meta interfac } func resourceDiscoveryEngineChatEngineUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceDiscoveryEngineChatEngine().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceDiscoveryEngineChatEngineRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -630,6 +669,13 @@ func resourceDiscoveryEngineChatEngineUpdate(d *schema.ResourceData, meta interf } func resourceDiscoveryEngineChatEngineDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DiscoveryEngineChatEngine without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing ChatEngine %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/discoveryengine/resource_discovery_engine_chat_engine_generated_meta.yaml b/google-beta/services/discoveryengine/resource_discovery_engine_chat_engine_generated_meta.yaml index ef7912b5330..9d2781e345f 100644 --- a/google-beta/services/discoveryengine/resource_discovery_engine_chat_engine_generated_meta.yaml +++ b/google-beta/services/discoveryengine/resource_discovery_engine_chat_engine_generated_meta.yaml @@ -27,3 +27,5 @@ fields: provider_only: true - api_field: name - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/discoveryengine/resource_discovery_engine_cmek_config.go b/google-beta/services/discoveryengine/resource_discovery_engine_cmek_config.go index 03934705b7a..da10390f21c 100644 --- a/google-beta/services/discoveryengine/resource_discovery_engine_cmek_config.go +++ b/google-beta/services/discoveryengine/resource_discovery_engine_cmek_config.go @@ -115,6 +115,7 @@ func ResourceDiscoveryEngineCmekConfig() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -225,6 +226,18 @@ characters.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -368,6 +381,19 @@ func resourceDiscoveryEngineCmekConfigRead(d *schema.ResourceData, meta interfac log.Printf("[DEBUG] Finished reading DiscoveryEngineCmekConfig %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading CmekConfig: %s", err) } @@ -405,6 +431,19 @@ func resourceDiscoveryEngineCmekConfigRead(d *schema.ResourceData, meta interfac } func resourceDiscoveryEngineCmekConfigUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceDiscoveryEngineCmekConfig().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceDiscoveryEngineCmekConfigRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -494,6 +533,13 @@ func resourceDiscoveryEngineCmekConfigUpdate(d *schema.ResourceData, meta interf } func resourceDiscoveryEngineCmekConfigDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DiscoveryEngineCmekConfig without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing CmekConfig %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/discoveryengine/resource_discovery_engine_cmek_config_generated_meta.yaml b/google-beta/services/discoveryengine/resource_discovery_engine_cmek_config_generated_meta.yaml index 7809a57ad3b..e610c8559d1 100644 --- a/google-beta/services/discoveryengine/resource_discovery_engine_cmek_config_generated_meta.yaml +++ b/google-beta/services/discoveryengine/resource_discovery_engine_cmek_config_generated_meta.yaml @@ -21,3 +21,5 @@ fields: provider_only: true - api_field: singleRegionKeys.kmsKey - api_field: state + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/discoveryengine/resource_discovery_engine_control.go b/google-beta/services/discoveryengine/resource_discovery_engine_control.go index 52e92393299..15e4da67fc5 100644 --- a/google-beta/services/discoveryengine/resource_discovery_engine_control.go +++ b/google-beta/services/discoveryengine/resource_discovery_engine_control.go @@ -115,6 +115,7 @@ func ResourceDiscoveryEngineControl() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -451,6 +452,18 @@ characters.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -636,6 +649,19 @@ func resourceDiscoveryEngineControlRead(d *schema.ResourceData, meta interface{} log.Printf("[DEBUG] Finished reading DiscoveryEngineControl %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Control: %s", err) } @@ -685,6 +711,19 @@ func resourceDiscoveryEngineControlRead(d *schema.ResourceData, meta interface{} } func resourceDiscoveryEngineControlUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceDiscoveryEngineControl().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceDiscoveryEngineControlRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -859,6 +898,13 @@ func resourceDiscoveryEngineControlUpdate(d *schema.ResourceData, meta interface } func resourceDiscoveryEngineControlDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DiscoveryEngineControl without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Control %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/discoveryengine/resource_discovery_engine_control_generated_meta.yaml b/google-beta/services/discoveryengine/resource_discovery_engine_control_generated_meta.yaml index 73328abb182..bbfdcf83f52 100644 --- a/google-beta/services/discoveryengine/resource_discovery_engine_control_generated_meta.yaml +++ b/google-beta/services/discoveryengine/resource_discovery_engine_control_generated_meta.yaml @@ -43,3 +43,5 @@ fields: - api_field: solutionType - api_field: synonymsAction.synonyms - api_field: useCases + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/discoveryengine/resource_discovery_engine_data_connector.go b/google-beta/services/discoveryengine/resource_discovery_engine_data_connector.go index e7c6d21411e..58644e48fc1 100644 --- a/google-beta/services/discoveryengine/resource_discovery_engine_data_connector.go +++ b/google-beta/services/discoveryengine/resource_discovery_engine_data_connector.go @@ -128,6 +128,7 @@ func ResourceDiscoveryEngineDataConnector() *schema.Resource { }, CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -587,6 +588,18 @@ This project must be allowlisted by in order for the connector to function.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -814,6 +827,19 @@ func resourceDiscoveryEngineDataConnectorRead(d *schema.ResourceData, meta inter log.Printf("[DEBUG] Finished reading DiscoveryEngineDataConnector %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading DataConnector: %s", err) } @@ -851,6 +877,19 @@ func resourceDiscoveryEngineDataConnectorRead(d *schema.ResourceData, meta inter } func resourceDiscoveryEngineDataConnectorUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceDiscoveryEngineDataConnector().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceDiscoveryEngineDataConnectorRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1063,6 +1102,13 @@ func resourceDiscoveryEngineDataConnectorUpdate(d *schema.ResourceData, meta int } func resourceDiscoveryEngineDataConnectorDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DiscoveryEngineDataConnector without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing DataConnector %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/discoveryengine/resource_discovery_engine_data_connector_generated_meta.yaml b/google-beta/services/discoveryengine/resource_discovery_engine_data_connector_generated_meta.yaml index c6462666a6a..71aee449c41 100644 --- a/google-beta/services/discoveryengine/resource_discovery_engine_data_connector_generated_meta.yaml +++ b/google-beta/services/discoveryengine/resource_discovery_engine_data_connector_generated_meta.yaml @@ -56,3 +56,5 @@ fields: - api_field: staticIpEnabled - api_field: syncMode - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/discoveryengine/resource_discovery_engine_data_store.go b/google-beta/services/discoveryengine/resource_discovery_engine_data_store.go index 72f937b120e..d2de37f1293 100644 --- a/google-beta/services/discoveryengine/resource_discovery_engine_data_store.go +++ b/google-beta/services/discoveryengine/resource_discovery_engine_data_store.go @@ -115,6 +115,7 @@ func ResourceDiscoveryEngineDataStore() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -495,6 +496,18 @@ characters.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -668,6 +681,19 @@ func resourceDiscoveryEngineDataStoreRead(d *schema.ResourceData, meta interface log.Printf("[DEBUG] Finished reading DiscoveryEngineDataStore %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading DataStore: %s", err) } @@ -705,6 +731,19 @@ func resourceDiscoveryEngineDataStoreRead(d *schema.ResourceData, meta interface } func resourceDiscoveryEngineDataStoreUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceDiscoveryEngineDataStore().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceDiscoveryEngineDataStoreRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -806,6 +845,13 @@ func resourceDiscoveryEngineDataStoreUpdate(d *schema.ResourceData, meta interfa } func resourceDiscoveryEngineDataStoreDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DiscoveryEngineDataStore without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing DataStore %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/discoveryengine/resource_discovery_engine_data_store_generated_meta.yaml b/google-beta/services/discoveryengine/resource_discovery_engine_data_store_generated_meta.yaml index 1405316147d..fe0c8644a17 100644 --- a/google-beta/services/discoveryengine/resource_discovery_engine_data_store_generated_meta.yaml +++ b/google-beta/services/discoveryengine/resource_discovery_engine_data_store_generated_meta.yaml @@ -56,3 +56,5 @@ fields: - field: skip_default_schema_creation provider_only: true - api_field: solutionTypes + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/discoveryengine/resource_discovery_engine_license_config.go b/google-beta/services/discoveryengine/resource_discovery_engine_license_config.go index 2c82c177120..890b7dbd797 100644 --- a/google-beta/services/discoveryengine/resource_discovery_engine_license_config.go +++ b/google-beta/services/discoveryengine/resource_discovery_engine_license_config.go @@ -443,6 +443,7 @@ func resourceDiscoveryEngineLicenseConfigRead(d *schema.ResourceData, meta inter } func resourceDiscoveryEngineLicenseConfigUpdate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/discoveryengine/resource_discovery_engine_recommendation_engine.go b/google-beta/services/discoveryengine/resource_discovery_engine_recommendation_engine.go index 82525073a2c..30211e40397 100644 --- a/google-beta/services/discoveryengine/resource_discovery_engine_recommendation_engine.go +++ b/google-beta/services/discoveryengine/resource_discovery_engine_recommendation_engine.go @@ -115,6 +115,7 @@ func ResourceDiscoveryEngineRecommendationEngine() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -331,6 +332,18 @@ This field must be a UTF-8 encoded string with a length limit of 1024 characters Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -497,6 +510,19 @@ func resourceDiscoveryEngineRecommendationEngineRead(d *schema.ResourceData, met log.Printf("[DEBUG] Finished reading DiscoveryEngineRecommendationEngine %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading RecommendationEngine: %s", err) } @@ -534,6 +560,19 @@ func resourceDiscoveryEngineRecommendationEngineRead(d *schema.ResourceData, met } func resourceDiscoveryEngineRecommendationEngineUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceDiscoveryEngineRecommendationEngine().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceDiscoveryEngineRecommendationEngineRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -650,6 +689,13 @@ func resourceDiscoveryEngineRecommendationEngineUpdate(d *schema.ResourceData, m } func resourceDiscoveryEngineRecommendationEngineDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DiscoveryEngineRecommendationEngine without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing RecommendationEngine %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/discoveryengine/resource_discovery_engine_recommendation_engine_generated_meta.yaml b/google-beta/services/discoveryengine/resource_discovery_engine_recommendation_engine_generated_meta.yaml index d4ce9a8d231..f6cb4a4b269 100644 --- a/google-beta/services/discoveryengine/resource_discovery_engine_recommendation_engine_generated_meta.yaml +++ b/google-beta/services/discoveryengine/resource_discovery_engine_recommendation_engine_generated_meta.yaml @@ -25,3 +25,5 @@ fields: - api_field: mediaRecommendationEngineConfig.type - api_field: name - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/discoveryengine/resource_discovery_engine_schema.go b/google-beta/services/discoveryengine/resource_discovery_engine_schema.go index c8ac90b747c..cd1a663d431 100644 --- a/google-beta/services/discoveryengine/resource_discovery_engine_schema.go +++ b/google-beta/services/discoveryengine/resource_discovery_engine_schema.go @@ -100,6 +100,7 @@ func ResourceDiscoveryEngineSchema() *schema.Resource { return &schema.Resource{ Create: resourceDiscoveryEngineSchemaCreate, Read: resourceDiscoveryEngineSchemaRead, + Update: resourceDiscoveryEngineSchemaUpdate, Delete: resourceDiscoveryEngineSchemaDelete, Importer: &schema.ResourceImporter{ @@ -113,6 +114,7 @@ func ResourceDiscoveryEngineSchema() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -185,6 +187,18 @@ characters.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -327,6 +341,19 @@ func resourceDiscoveryEngineSchemaRead(d *schema.ResourceData, meta interface{}) log.Printf("[DEBUG] Finished reading DiscoveryEngineSchema %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Schema: %s", err) } @@ -369,7 +396,19 @@ func resourceDiscoveryEngineSchemaRead(d *schema.ResourceData, meta interface{}) return nil } +func resourceDiscoveryEngineSchemaUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceDiscoveryEngineSchemaRead(d, meta) +} + func resourceDiscoveryEngineSchemaDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DiscoveryEngineSchema without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Schema %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/discoveryengine/resource_discovery_engine_schema_generated_meta.yaml b/google-beta/services/discoveryengine/resource_discovery_engine_schema_generated_meta.yaml index 920e6447a20..3caad14270f 100644 --- a/google-beta/services/discoveryengine/resource_discovery_engine_schema_generated_meta.yaml +++ b/google-beta/services/discoveryengine/resource_discovery_engine_schema_generated_meta.yaml @@ -17,3 +17,5 @@ fields: - api_field: name - field: schema_id provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/discoveryengine/resource_discovery_engine_search_engine.go b/google-beta/services/discoveryengine/resource_discovery_engine_search_engine.go index 432ef1f4ac3..3b97d4a9ca8 100644 --- a/google-beta/services/discoveryengine/resource_discovery_engine_search_engine.go +++ b/google-beta/services/discoveryengine/resource_discovery_engine_search_engine.go @@ -115,6 +115,7 @@ func ResourceDiscoveryEngineSearchEngine() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -354,6 +355,18 @@ characters.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -555,6 +568,19 @@ func resourceDiscoveryEngineSearchEngineRead(d *schema.ResourceData, meta interf log.Printf("[DEBUG] Finished reading DiscoveryEngineSearchEngine %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading SearchEngine: %s", err) } @@ -598,6 +624,19 @@ func resourceDiscoveryEngineSearchEngineRead(d *schema.ResourceData, meta interf } func resourceDiscoveryEngineSearchEngineUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceDiscoveryEngineSearchEngine().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceDiscoveryEngineSearchEngineRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -759,6 +798,13 @@ func resourceDiscoveryEngineSearchEngineUpdate(d *schema.ResourceData, meta inte } func resourceDiscoveryEngineSearchEngineDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DiscoveryEngineSearchEngine without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing SearchEngine %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/discoveryengine/resource_discovery_engine_search_engine_generated_meta.yaml b/google-beta/services/discoveryengine/resource_discovery_engine_search_engine_generated_meta.yaml index 25539944256..99db97b0546 100644 --- a/google-beta/services/discoveryengine/resource_discovery_engine_search_engine_generated_meta.yaml +++ b/google-beta/services/discoveryengine/resource_discovery_engine_search_engine_generated_meta.yaml @@ -34,3 +34,5 @@ fields: - api_field: searchEngineConfig.searchAddOns - api_field: searchEngineConfig.searchTier - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/discoveryengine/resource_discovery_engine_serving_config.go b/google-beta/services/discoveryengine/resource_discovery_engine_serving_config.go index 1eba09b00de..36051135ccc 100644 --- a/google-beta/services/discoveryengine/resource_discovery_engine_serving_config.go +++ b/google-beta/services/discoveryengine/resource_discovery_engine_serving_config.go @@ -438,6 +438,7 @@ func resourceDiscoveryEngineServingConfigRead(d *schema.ResourceData, meta inter } func resourceDiscoveryEngineServingConfigUpdate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/discoveryengine/resource_discovery_engine_sitemap.go b/google-beta/services/discoveryengine/resource_discovery_engine_sitemap.go index 5021046514a..dd07264a601 100644 --- a/google-beta/services/discoveryengine/resource_discovery_engine_sitemap.go +++ b/google-beta/services/discoveryengine/resource_discovery_engine_sitemap.go @@ -100,6 +100,7 @@ func ResourceDiscoveryEngineSitemap() *schema.Resource { return &schema.Resource{ Create: resourceDiscoveryEngineSitemapCreate, Read: resourceDiscoveryEngineSitemapRead, + Update: resourceDiscoveryEngineSitemapUpdate, Delete: resourceDiscoveryEngineSitemapDelete, Importer: &schema.ResourceImporter{ @@ -113,6 +114,7 @@ func ResourceDiscoveryEngineSitemap() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -174,6 +176,18 @@ characters.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -350,6 +364,19 @@ func resourceDiscoveryEngineSitemapRead(d *schema.ResourceData, meta interface{} res = sitemapData + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Sitemap: %s", err) } @@ -374,7 +401,19 @@ func resourceDiscoveryEngineSitemapRead(d *schema.ResourceData, meta interface{} return nil } +func resourceDiscoveryEngineSitemapUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceDiscoveryEngineSitemapRead(d, meta) +} + func resourceDiscoveryEngineSitemapDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DiscoveryEngineSitemap without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Sitemap %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/discoveryengine/resource_discovery_engine_sitemap_generated_meta.yaml b/google-beta/services/discoveryengine/resource_discovery_engine_sitemap_generated_meta.yaml index a5f4c1307b3..b626b3aebad 100644 --- a/google-beta/services/discoveryengine/resource_discovery_engine_sitemap_generated_meta.yaml +++ b/google-beta/services/discoveryengine/resource_discovery_engine_sitemap_generated_meta.yaml @@ -16,3 +16,5 @@ fields: - field: sitemap_id provider_only: true - api_field: uri + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/discoveryengine/resource_discovery_engine_target_site.go b/google-beta/services/discoveryengine/resource_discovery_engine_target_site.go index 76abda4001f..a475abaef7e 100644 --- a/google-beta/services/discoveryengine/resource_discovery_engine_target_site.go +++ b/google-beta/services/discoveryengine/resource_discovery_engine_target_site.go @@ -100,6 +100,7 @@ func ResourceDiscoveryEngineTargetSite() *schema.Resource { return &schema.Resource{ Create: resourceDiscoveryEngineTargetSiteCreate, Read: resourceDiscoveryEngineTargetSiteRead, + Update: resourceDiscoveryEngineTargetSiteUpdate, Delete: resourceDiscoveryEngineTargetSiteDelete, Importer: &schema.ResourceImporter{ @@ -113,6 +114,7 @@ func ResourceDiscoveryEngineTargetSite() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -266,6 +268,18 @@ characters.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -434,6 +448,19 @@ func resourceDiscoveryEngineTargetSiteRead(d *schema.ResourceData, meta interfac log.Printf("[DEBUG] Finished reading DiscoveryEngineTargetSite %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading TargetSite: %s", err) } @@ -476,7 +503,19 @@ func resourceDiscoveryEngineTargetSiteRead(d *schema.ResourceData, meta interfac return nil } +func resourceDiscoveryEngineTargetSiteUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceDiscoveryEngineTargetSiteRead(d, meta) +} + func resourceDiscoveryEngineTargetSiteDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DiscoveryEngineTargetSite without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing TargetSite %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/discoveryengine/resource_discovery_engine_target_site_generated_meta.yaml b/google-beta/services/discoveryengine/resource_discovery_engine_target_site_generated_meta.yaml index 906e4a0d5ce..2e5a238431b 100644 --- a/google-beta/services/discoveryengine/resource_discovery_engine_target_site_generated_meta.yaml +++ b/google-beta/services/discoveryengine/resource_discovery_engine_target_site_generated_meta.yaml @@ -26,3 +26,5 @@ fields: provider_only: true - api_field: type - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/discoveryengine/resource_discovery_engine_user_store.go b/google-beta/services/discoveryengine/resource_discovery_engine_user_store.go index ee90ea34631..9560edaddb9 100644 --- a/google-beta/services/discoveryengine/resource_discovery_engine_user_store.go +++ b/google-beta/services/discoveryengine/resource_discovery_engine_user_store.go @@ -369,6 +369,7 @@ func resourceDiscoveryEngineUserStoreRead(d *schema.ResourceData, meta interface } func resourceDiscoveryEngineUserStoreUpdate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/discoveryengine/resource_discovery_engine_widget_config.go b/google-beta/services/discoveryengine/resource_discovery_engine_widget_config.go index 8f871e2c92b..213efc7a2c8 100644 --- a/google-beta/services/discoveryengine/resource_discovery_engine_widget_config.go +++ b/google-beta/services/discoveryengine/resource_discovery_engine_widget_config.go @@ -746,6 +746,7 @@ func resourceDiscoveryEngineWidgetConfigRead(d *schema.ResourceData, meta interf } func resourceDiscoveryEngineWidgetConfigUpdate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/dns/resource_dns_managed_zone.go b/google-beta/services/dns/resource_dns_managed_zone.go index b778d978647..f58d7a880da 100644 --- a/google-beta/services/dns/resource_dns_managed_zone.go +++ b/google-beta/services/dns/resource_dns_managed_zone.go @@ -120,6 +120,7 @@ func ResourceDNSManagedZone() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -465,6 +466,18 @@ defined by the server`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -708,6 +721,18 @@ func resourceDNSManagedZoneRead(d *schema.ResourceData, meta interface{}) error return fmt.Errorf("Error setting force_destroy: %s", err) } } + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading ManagedZone: %s", err) } @@ -739,6 +764,19 @@ func resourceDNSManagedZoneRead(d *schema.ResourceData, meta interface{}) error } func resourceDNSManagedZoneUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceDNSManagedZone().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceDNSManagedZoneRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -881,6 +919,13 @@ func resourceDNSManagedZoneUpdate(d *schema.ResourceData, meta interface{}) erro } func resourceDNSManagedZoneDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DNSManagedZone without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing ManagedZone %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/dns/resource_dns_managed_zone_generated_meta.yaml b/google-beta/services/dns/resource_dns_managed_zone_generated_meta.yaml index b556eead016..6fc7fc5db6e 100644 --- a/google-beta/services/dns/resource_dns_managed_zone_generated_meta.yaml +++ b/google-beta/services/dns/resource_dns_managed_zone_generated_meta.yaml @@ -40,3 +40,5 @@ fields: - field: terraform_labels provider_only: true - api_field: visibility + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/dns/resource_dns_policy.go b/google-beta/services/dns/resource_dns_policy.go index 48dd21b13c2..652ba2f2de7 100644 --- a/google-beta/services/dns/resource_dns_policy.go +++ b/google-beta/services/dns/resource_dns_policy.go @@ -115,6 +115,7 @@ func ResourceDNSPolicy() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -242,6 +243,18 @@ Defaults to no logging if not set.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -435,6 +448,19 @@ func resourceDNSPolicyRead(d *schema.ResourceData, meta interface{}) error { log.Printf("[DEBUG] Finished reading DNSPolicy %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Policy: %s", err) } @@ -466,6 +492,19 @@ func resourceDNSPolicyRead(d *schema.ResourceData, meta interface{}) error { } func resourceDNSPolicyUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceDNSPolicy().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceDNSPolicyRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -567,6 +606,13 @@ func resourceDNSPolicyUpdate(d *schema.ResourceData, meta interface{}) error { } func resourceDNSPolicyDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DNSPolicy without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Policy %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/dns/resource_dns_policy_generated_meta.yaml b/google-beta/services/dns/resource_dns_policy_generated_meta.yaml index c3846411b1b..9dbca6b51d4 100644 --- a/google-beta/services/dns/resource_dns_policy_generated_meta.yaml +++ b/google-beta/services/dns/resource_dns_policy_generated_meta.yaml @@ -15,3 +15,5 @@ fields: - api_field: enableLogging - api_field: name - api_field: networks.networkUrl + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/dns/resource_dns_record_set.go b/google-beta/services/dns/resource_dns_record_set.go index 2ff908bb8d5..95605024256 100644 --- a/google-beta/services/dns/resource_dns_record_set.go +++ b/google-beta/services/dns/resource_dns_record_set.go @@ -113,6 +113,7 @@ func ResourceDnsRecordSet() *schema.Resource { }, CustomizeDiff: customdiff.All( + tpgresource.DefaultProviderDeletionPolicy("DELETE"), tpgresource.DefaultProviderProject, ), @@ -259,6 +260,9 @@ func ResourceDnsRecordSet() *schema.Resource { ForceNew: true, Description: `The ID of the project in which the resource belongs. If it is not provided, the provider project is used.`, }, + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end }, UseJSONNumber: true, } @@ -493,10 +497,21 @@ func resourceDnsRecordSetRead(d *schema.ResourceData, meta interface{}) error { return fmt.Errorf("Error setting project: %s", err) } + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + return nil } func resourceDnsRecordSetDelete(d *schema.ResourceData, meta interface{}) error { + + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { + return nil + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -583,6 +598,11 @@ func resourceDnsRecordSetDelete(d *schema.ResourceData, meta interface{}) error } func resourceDnsRecordSetUpdate(d *schema.ResourceData, meta interface{}) error { + + if tpgresource.DeletionPolicyPreUpdate(d, ResourceDnsRecordSet) { + return ResourceDnsRecordSet().Read(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/dns/resource_dns_record_set_meta.yaml b/google-beta/services/dns/resource_dns_record_set_meta.yaml index e06078f0e7e..7b26a18bb82 100644 --- a/google-beta/services/dns/resource_dns_record_set_meta.yaml +++ b/google-beta/services/dns/resource_dns_record_set_meta.yaml @@ -54,3 +54,5 @@ fields: - api_field: 'rrdatas' - api_field: 'ttl' - api_field: 'type' + - field: 'deletion_policy' + provider_only: true diff --git a/google-beta/services/dns/resource_dns_response_policy.go b/google-beta/services/dns/resource_dns_response_policy.go index 00c5e30c571..0b667c7cc65 100644 --- a/google-beta/services/dns/resource_dns_response_policy.go +++ b/google-beta/services/dns/resource_dns_response_policy.go @@ -115,6 +115,7 @@ func ResourceDNSResponsePolicy() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -188,6 +189,18 @@ This should be formatted like Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -328,6 +341,19 @@ func resourceDNSResponsePolicyRead(d *schema.ResourceData, meta interface{}) err log.Printf("[DEBUG] Finished reading DNSResponsePolicy %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading ResponsePolicy: %s", err) } @@ -359,6 +385,19 @@ func resourceDNSResponsePolicyRead(d *schema.ResourceData, meta interface{}) err } func resourceDNSResponsePolicyUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceDNSResponsePolicy().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceDNSResponsePolicyRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -442,6 +481,13 @@ func resourceDNSResponsePolicyUpdate(d *schema.ResourceData, meta interface{}) e } func resourceDNSResponsePolicyDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DNSResponsePolicy without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing ResponsePolicy %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/dns/resource_dns_response_policy_generated_meta.yaml b/google-beta/services/dns/resource_dns_response_policy_generated_meta.yaml index 35b2de088d0..3f653955df3 100644 --- a/google-beta/services/dns/resource_dns_response_policy_generated_meta.yaml +++ b/google-beta/services/dns/resource_dns_response_policy_generated_meta.yaml @@ -11,3 +11,5 @@ fields: - api_field: gkeClusters.gkeClusterName - api_field: networks.networkUrl - api_field: responsePolicyName + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/dns/resource_dns_response_policy_rule.go b/google-beta/services/dns/resource_dns_response_policy_rule.go index 0f58bf6bc38..94b194af196 100644 --- a/google-beta/services/dns/resource_dns_response_policy_rule.go +++ b/google-beta/services/dns/resource_dns_response_policy_rule.go @@ -115,6 +115,7 @@ func ResourceDNSResponsePolicyRule() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -216,6 +217,18 @@ resolvers.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -361,6 +374,19 @@ func resourceDNSResponsePolicyRuleRead(d *schema.ResourceData, meta interface{}) log.Printf("[DEBUG] Finished reading DNSResponsePolicyRule %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading ResponsePolicyRule: %s", err) } @@ -398,6 +424,19 @@ func resourceDNSResponsePolicyRuleRead(d *schema.ResourceData, meta interface{}) } func resourceDNSResponsePolicyRuleUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceDNSResponsePolicyRule().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceDNSResponsePolicyRuleRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -486,6 +525,13 @@ func resourceDNSResponsePolicyRuleUpdate(d *schema.ResourceData, meta interface{ } func resourceDNSResponsePolicyRuleDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DNSResponsePolicyRule without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing ResponsePolicyRule %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/dns/resource_dns_response_policy_rule_generated_meta.yaml b/google-beta/services/dns/resource_dns_response_policy_rule_generated_meta.yaml index 1bcd8a7ed2d..644faa3ddad 100644 --- a/google-beta/services/dns/resource_dns_response_policy_rule_generated_meta.yaml +++ b/google-beta/services/dns/resource_dns_response_policy_rule_generated_meta.yaml @@ -16,3 +16,5 @@ fields: - field: response_policy provider_only: true - api_field: ruleName + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/documentai/resource_document_ai_processor.go b/google-beta/services/documentai/resource_document_ai_processor.go index d3659df9426..bc25c56bd9a 100644 --- a/google-beta/services/documentai/resource_document_ai_processor.go +++ b/google-beta/services/documentai/resource_document_ai_processor.go @@ -100,6 +100,7 @@ func ResourceDocumentAIProcessor() *schema.Resource { return &schema.Resource{ Create: resourceDocumentAIProcessorCreate, Read: resourceDocumentAIProcessorRead, + Update: resourceDocumentAIProcessorUpdate, Delete: resourceDocumentAIProcessorDelete, Importer: &schema.ResourceImporter{ @@ -113,6 +114,7 @@ func ResourceDocumentAIProcessor() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -174,6 +176,18 @@ func ResourceDocumentAIProcessor() *schema.Resource { Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -319,6 +333,19 @@ func resourceDocumentAIProcessorRead(d *schema.ResourceData, meta interface{}) e log.Printf("[DEBUG] Finished reading DocumentAIProcessor %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Processor: %s", err) } @@ -355,7 +382,19 @@ func resourceDocumentAIProcessorRead(d *schema.ResourceData, meta interface{}) e return nil } +func resourceDocumentAIProcessorUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceDocumentAIProcessorRead(d, meta) +} + func resourceDocumentAIProcessorDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DocumentAIProcessor without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Processor %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/documentai/resource_document_ai_processor_generated_meta.yaml b/google-beta/services/documentai/resource_document_ai_processor_generated_meta.yaml index 71f4ef1ed36..9a68ba1f6eb 100644 --- a/google-beta/services/documentai/resource_document_ai_processor_generated_meta.yaml +++ b/google-beta/services/documentai/resource_document_ai_processor_generated_meta.yaml @@ -13,3 +13,5 @@ fields: provider_only: true - api_field: name - api_field: type + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/documentai/resource_document_ai_schema.go b/google-beta/services/documentai/resource_document_ai_schema.go index 182bcff9f51..35e94cdb530 100644 --- a/google-beta/services/documentai/resource_document_ai_schema.go +++ b/google-beta/services/documentai/resource_document_ai_schema.go @@ -116,6 +116,7 @@ func ResourceDocumentAISchema() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -197,6 +198,18 @@ Please refer to the field 'effective_labels' for all of the labels present on th Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -336,6 +349,19 @@ func resourceDocumentAISchemaRead(d *schema.ResourceData, meta interface{}) erro log.Printf("[DEBUG] Finished reading DocumentAISchema %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Schema: %s", err) } @@ -373,6 +399,19 @@ func resourceDocumentAISchemaRead(d *schema.ResourceData, meta interface{}) erro } func resourceDocumentAISchemaUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceDocumentAISchema().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceDocumentAISchemaRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -474,6 +513,13 @@ func resourceDocumentAISchemaUpdate(d *schema.ResourceData, meta interface{}) er } func resourceDocumentAISchemaDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DocumentAISchema without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Schema %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/documentai/resource_document_ai_schema_generated_meta.yaml b/google-beta/services/documentai/resource_document_ai_schema_generated_meta.yaml index c330e7256ef..37fe64a408f 100644 --- a/google-beta/services/documentai/resource_document_ai_schema_generated_meta.yaml +++ b/google-beta/services/documentai/resource_document_ai_schema_generated_meta.yaml @@ -18,3 +18,5 @@ fields: - field: terraform_labels provider_only: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/documentaiwarehouse/resource_document_ai_warehouse_document_schema.go b/google-beta/services/documentaiwarehouse/resource_document_ai_warehouse_document_schema.go index 81b89b4a661..5ad9e7e8643 100644 --- a/google-beta/services/documentaiwarehouse/resource_document_ai_warehouse_document_schema.go +++ b/google-beta/services/documentaiwarehouse/resource_document_ai_warehouse_document_schema.go @@ -100,6 +100,7 @@ func ResourceDocumentAIWarehouseDocumentSchema() *schema.Resource { return &schema.Resource{ Create: resourceDocumentAIWarehouseDocumentSchemaCreate, Read: resourceDocumentAIWarehouseDocumentSchemaRead, + Update: resourceDocumentAIWarehouseDocumentSchemaUpdate, Delete: resourceDocumentAIWarehouseDocumentSchemaDelete, Importer: &schema.ResourceImporter{ @@ -509,6 +510,19 @@ func ResourceDocumentAIWarehouseDocumentSchema() *schema.Resource { Computed: true, Description: `The resource name of the document schema.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -642,6 +656,20 @@ func resourceDocumentAIWarehouseDocumentSchemaRead(d *schema.ResourceData, meta log.Printf("[DEBUG] Finished reading DocumentAIWarehouseDocumentSchema %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceDocumentAIWarehouseDocumentSchemaFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -674,7 +702,19 @@ func resourceDocumentAIWarehouseDocumentSchemaRead(d *schema.ResourceData, meta return nil } +func resourceDocumentAIWarehouseDocumentSchemaUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceDocumentAIWarehouseDocumentSchemaRead(d, meta) +} + func resourceDocumentAIWarehouseDocumentSchemaDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy DocumentAIWarehouseDocumentSchema without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing DocumentSchema %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/documentaiwarehouse/resource_document_ai_warehouse_document_schema_generated_meta.yaml b/google-beta/services/documentaiwarehouse/resource_document_ai_warehouse_document_schema_generated_meta.yaml index 0adef49289b..98b95e1de39 100644 --- a/google-beta/services/documentaiwarehouse/resource_document_ai_warehouse_document_schema_generated_meta.yaml +++ b/google-beta/services/documentaiwarehouse/resource_document_ai_warehouse_document_schema_generated_meta.yaml @@ -52,3 +52,5 @@ fields: - api_field: propertyDefinitions.schemaSources.processorType - api_field: propertyDefinitions.textTypeOptions - api_field: propertyDefinitions.timestampTypeOptions + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/edgecontainer/resource_edgecontainer_cluster.go b/google-beta/services/edgecontainer/resource_edgecontainer_cluster.go index 8b21495cdc9..b23d0abaaef 100644 --- a/google-beta/services/edgecontainer/resource_edgecontainer_cluster.go +++ b/google-beta/services/edgecontainer/resource_edgecontainer_cluster.go @@ -116,6 +116,7 @@ func ResourceEdgecontainerCluster() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -710,6 +711,18 @@ if the cluster does not have any worker nodes.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -913,6 +926,19 @@ func resourceEdgecontainerClusterRead(d *schema.ResourceData, meta interface{}) log.Printf("[DEBUG] Finished reading EdgecontainerCluster %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Cluster: %s", err) } @@ -950,6 +976,19 @@ func resourceEdgecontainerClusterRead(d *schema.ResourceData, meta interface{}) } func resourceEdgecontainerClusterUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceEdgecontainerCluster().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceEdgecontainerClusterRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1177,6 +1216,13 @@ func resourceEdgecontainerClusterUpdate(d *schema.ResourceData, meta interface{} } func resourceEdgecontainerClusterDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy EdgecontainerCluster without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Cluster %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/edgecontainer/resource_edgecontainer_cluster_generated_meta.yaml b/google-beta/services/edgecontainer/resource_edgecontainer_cluster_generated_meta.yaml index c860f0181fb..0115a94f16d 100644 --- a/google-beta/services/edgecontainer/resource_edgecontainer_cluster_generated_meta.yaml +++ b/google-beta/services/edgecontainer/resource_edgecontainer_cluster_generated_meta.yaml @@ -64,3 +64,5 @@ fields: - field: terraform_labels provider_only: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/edgecontainer/resource_edgecontainer_node_pool.go b/google-beta/services/edgecontainer/resource_edgecontainer_node_pool.go index dec0b892beb..774678f92fa 100644 --- a/google-beta/services/edgecontainer/resource_edgecontainer_node_pool.go +++ b/google-beta/services/edgecontainer/resource_edgecontainer_node_pool.go @@ -116,6 +116,7 @@ func ResourceEdgecontainerNodePool() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -272,6 +273,18 @@ documented in more detail in [AIP-160](https://google.aip.dev/160).`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -444,6 +457,19 @@ func resourceEdgecontainerNodePoolRead(d *schema.ResourceData, meta interface{}) log.Printf("[DEBUG] Finished reading EdgecontainerNodePool %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading NodePool: %s", err) } @@ -487,6 +513,19 @@ func resourceEdgecontainerNodePoolRead(d *schema.ResourceData, meta interface{}) } func resourceEdgecontainerNodePoolUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceEdgecontainerNodePool().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceEdgecontainerNodePoolRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -630,6 +669,13 @@ func resourceEdgecontainerNodePoolUpdate(d *schema.ResourceData, meta interface{ } func resourceEdgecontainerNodePoolDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy EdgecontainerNodePool without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing NodePool %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/edgecontainer/resource_edgecontainer_node_pool_generated_meta.yaml b/google-beta/services/edgecontainer/resource_edgecontainer_node_pool_generated_meta.yaml index 17a5c6c3752..21552727af7 100644 --- a/google-beta/services/edgecontainer/resource_edgecontainer_node_pool_generated_meta.yaml +++ b/google-beta/services/edgecontainer/resource_edgecontainer_node_pool_generated_meta.yaml @@ -28,3 +28,5 @@ fields: - field: terraform_labels provider_only: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/edgecontainer/resource_edgecontainer_vpn_connection.go b/google-beta/services/edgecontainer/resource_edgecontainer_vpn_connection.go index c07a6cdd048..cde178e7ca6 100644 --- a/google-beta/services/edgecontainer/resource_edgecontainer_vpn_connection.go +++ b/google-beta/services/edgecontainer/resource_edgecontainer_vpn_connection.go @@ -116,6 +116,7 @@ func ResourceEdgecontainerVpnConnection() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -287,6 +288,18 @@ This is empty if NAT is not used.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -460,6 +473,19 @@ func resourceEdgecontainerVpnConnectionRead(d *schema.ResourceData, meta interfa log.Printf("[DEBUG] Finished reading EdgecontainerVpnConnection %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading VpnConnection: %s", err) } @@ -497,6 +523,19 @@ func resourceEdgecontainerVpnConnectionRead(d *schema.ResourceData, meta interfa } func resourceEdgecontainerVpnConnectionUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceEdgecontainerVpnConnection().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceEdgecontainerVpnConnectionRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -617,6 +656,13 @@ func resourceEdgecontainerVpnConnectionUpdate(d *schema.ResourceData, meta inter } func resourceEdgecontainerVpnConnectionDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy EdgecontainerVpnConnection without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing VpnConnection %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/edgecontainer/resource_edgecontainer_vpn_connection_generated_meta.yaml b/google-beta/services/edgecontainer/resource_edgecontainer_vpn_connection_generated_meta.yaml index ef903eb8bea..88f35d10937 100644 --- a/google-beta/services/edgecontainer/resource_edgecontainer_vpn_connection_generated_meta.yaml +++ b/google-beta/services/edgecontainer/resource_edgecontainer_vpn_connection_generated_meta.yaml @@ -28,3 +28,5 @@ fields: - api_field: updateTime - api_field: vpc - api_field: vpcProject.projectId + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/edgenetwork/resource_edgenetwork_interconnect_attachment.go b/google-beta/services/edgenetwork/resource_edgenetwork_interconnect_attachment.go index d4fec3e2213..c45bb1d6c01 100644 --- a/google-beta/services/edgenetwork/resource_edgenetwork_interconnect_attachment.go +++ b/google-beta/services/edgenetwork/resource_edgenetwork_interconnect_attachment.go @@ -116,6 +116,7 @@ func ResourceEdgenetworkInterconnectAttachment() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -247,6 +248,18 @@ fractional digits. Examples: '2014-10-02T15:01:23Z' and '2014-10-02T15:01:23.045 Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -419,6 +432,19 @@ func resourceEdgenetworkInterconnectAttachmentRead(d *schema.ResourceData, meta log.Printf("[DEBUG] Finished reading EdgenetworkInterconnectAttachment %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading InterconnectAttachment: %s", err) } @@ -462,11 +488,18 @@ func resourceEdgenetworkInterconnectAttachmentRead(d *schema.ResourceData, meta } func resourceEdgenetworkInterconnectAttachmentUpdate(d *schema.ResourceData, meta interface{}) error { - // Only the root field "labels", "terraform_labels", and virtual fields are mutable + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable return resourceEdgenetworkInterconnectAttachmentRead(d, meta) } func resourceEdgenetworkInterconnectAttachmentDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy EdgenetworkInterconnectAttachment without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing InterconnectAttachment %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/edgenetwork/resource_edgenetwork_interconnect_attachment_generated_meta.yaml b/google-beta/services/edgenetwork/resource_edgenetwork_interconnect_attachment_generated_meta.yaml index d645f8ee33f..bc0d4602be9 100644 --- a/google-beta/services/edgenetwork/resource_edgenetwork_interconnect_attachment_generated_meta.yaml +++ b/google-beta/services/edgenetwork/resource_edgenetwork_interconnect_attachment_generated_meta.yaml @@ -26,3 +26,5 @@ fields: - api_field: vlanId - field: zone provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/edgenetwork/resource_edgenetwork_network.go b/google-beta/services/edgenetwork/resource_edgenetwork_network.go index cea5d8cdf3e..88937269a91 100644 --- a/google-beta/services/edgenetwork/resource_edgenetwork_network.go +++ b/google-beta/services/edgenetwork/resource_edgenetwork_network.go @@ -116,6 +116,7 @@ func ResourceEdgenetworkNetwork() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -227,6 +228,18 @@ fractional digits. Examples: '2014-10-02T15:01:23Z' and '2014-10-02T15:01:23.045 Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -381,6 +394,19 @@ func resourceEdgenetworkNetworkRead(d *schema.ResourceData, meta interface{}) er log.Printf("[DEBUG] Finished reading EdgenetworkNetwork %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Network: %s", err) } @@ -424,11 +450,18 @@ func resourceEdgenetworkNetworkRead(d *schema.ResourceData, meta interface{}) er } func resourceEdgenetworkNetworkUpdate(d *schema.ResourceData, meta interface{}) error { - // Only the root field "labels", "terraform_labels", and virtual fields are mutable + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable return resourceEdgenetworkNetworkRead(d, meta) } func resourceEdgenetworkNetworkDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy EdgenetworkNetwork without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Network %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/edgenetwork/resource_edgenetwork_network_generated_meta.yaml b/google-beta/services/edgenetwork/resource_edgenetwork_network_generated_meta.yaml index da7055a6058..2cc16662c83 100644 --- a/google-beta/services/edgenetwork/resource_edgenetwork_network_generated_meta.yaml +++ b/google-beta/services/edgenetwork/resource_edgenetwork_network_generated_meta.yaml @@ -23,3 +23,5 @@ fields: - api_field: updateTime - field: zone provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/edgenetwork/resource_edgenetwork_subnet.go b/google-beta/services/edgenetwork/resource_edgenetwork_subnet.go index 6c6bfc24a10..6319c07152d 100644 --- a/google-beta/services/edgenetwork/resource_edgenetwork_subnet.go +++ b/google-beta/services/edgenetwork/resource_edgenetwork_subnet.go @@ -116,6 +116,7 @@ func ResourceEdgenetworkSubnet() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -258,6 +259,18 @@ fractional digits. Examples: '2014-10-02T15:01:23Z' and '2014-10-02T15:01:23.045 Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -430,6 +443,19 @@ func resourceEdgenetworkSubnetRead(d *schema.ResourceData, meta interface{}) err log.Printf("[DEBUG] Finished reading EdgenetworkSubnet %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Subnet: %s", err) } @@ -473,11 +499,18 @@ func resourceEdgenetworkSubnetRead(d *schema.ResourceData, meta interface{}) err } func resourceEdgenetworkSubnetUpdate(d *schema.ResourceData, meta interface{}) error { - // Only the root field "labels", "terraform_labels", and virtual fields are mutable + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable return resourceEdgenetworkSubnetRead(d, meta) } func resourceEdgenetworkSubnetDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy EdgenetworkSubnet without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Subnet %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/edgenetwork/resource_edgenetwork_subnet_generated_meta.yaml b/google-beta/services/edgenetwork/resource_edgenetwork_subnet_generated_meta.yaml index 445d9a19bdb..ab66fa25192 100644 --- a/google-beta/services/edgenetwork/resource_edgenetwork_subnet_generated_meta.yaml +++ b/google-beta/services/edgenetwork/resource_edgenetwork_subnet_generated_meta.yaml @@ -27,3 +27,5 @@ fields: - api_field: vlanId - field: zone provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/essentialcontacts/resource_essential_contacts_contact.go b/google-beta/services/essentialcontacts/resource_essential_contacts_contact.go index 32ea9dbeed9..12b0c04647e 100644 --- a/google-beta/services/essentialcontacts/resource_essential_contacts_contact.go +++ b/google-beta/services/essentialcontacts/resource_essential_contacts_contact.go @@ -159,6 +159,19 @@ func ResourceEssentialContactsContact() *schema.Resource { Computed: true, Description: `The identifier for the contact. Format: {resourceType}/{resource_id}/contacts/{contact_id}`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -282,6 +295,20 @@ func resourceEssentialContactsContactRead(d *schema.ResourceData, meta interface log.Printf("[DEBUG] Finished reading EssentialContactsContact %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceEssentialContactsContactFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -303,6 +330,19 @@ func resourceEssentialContactsContactRead(d *schema.ResourceData, meta interface } func resourceEssentialContactsContactUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceEssentialContactsContact().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceEssentialContactsContactRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -388,6 +428,13 @@ func resourceEssentialContactsContactUpdate(d *schema.ResourceData, meta interfa } func resourceEssentialContactsContactDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy EssentialContactsContact without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Contact %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/essentialcontacts/resource_essential_contacts_contact_generated_meta.yaml b/google-beta/services/essentialcontacts/resource_essential_contacts_contact_generated_meta.yaml index 6609edbdfba..daf72c5be24 100644 --- a/google-beta/services/essentialcontacts/resource_essential_contacts_contact_generated_meta.yaml +++ b/google-beta/services/essentialcontacts/resource_essential_contacts_contact_generated_meta.yaml @@ -17,3 +17,5 @@ fields: - api_field: notificationCategorySubscriptions - field: parent provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/eventarc/resource_eventarc_channel.go b/google-beta/services/eventarc/resource_eventarc_channel.go index e733209c249..79d2f6b81db 100644 --- a/google-beta/services/eventarc/resource_eventarc_channel.go +++ b/google-beta/services/eventarc/resource_eventarc_channel.go @@ -116,6 +116,7 @@ func ResourceEventarcChannel() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -225,6 +226,18 @@ Please refer to the field 'effective_labels' for all of the labels present on th Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -382,6 +395,19 @@ func resourceEventarcChannelRead(d *schema.ResourceData, meta interface{}) error log.Printf("[DEBUG] Finished reading EventarcChannel %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Channel: %s", err) } @@ -419,6 +445,19 @@ func resourceEventarcChannelRead(d *schema.ResourceData, meta interface{}) error } func resourceEventarcChannelUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceEventarcChannel().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceEventarcChannelRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -528,6 +567,13 @@ func resourceEventarcChannelUpdate(d *schema.ResourceData, meta interface{}) err } func resourceEventarcChannelDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy EventarcChannel without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Channel %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/eventarc/resource_eventarc_channel_generated_meta.yaml b/google-beta/services/eventarc/resource_eventarc_channel_generated_meta.yaml index 95c7a747e6f..27161d83b26 100644 --- a/google-beta/services/eventarc/resource_eventarc_channel_generated_meta.yaml +++ b/google-beta/services/eventarc/resource_eventarc_channel_generated_meta.yaml @@ -24,3 +24,5 @@ fields: field: third_party_provider - api_field: uid - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/eventarc/resource_eventarc_enrollment.go b/google-beta/services/eventarc/resource_eventarc_enrollment.go index d718dacccaf..d83733e3b9a 100644 --- a/google-beta/services/eventarc/resource_eventarc_enrollment.go +++ b/google-beta/services/eventarc/resource_eventarc_enrollment.go @@ -117,6 +117,7 @@ func ResourceEventarcEnrollment() *schema.Resource { tpgresource.SetLabelsDiff, tpgresource.SetAnnotationsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -253,6 +254,18 @@ string and guaranteed to remain unchanged until the resource is deleted.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -420,6 +433,19 @@ func resourceEventarcEnrollmentRead(d *schema.ResourceData, meta interface{}) er log.Printf("[DEBUG] Finished reading EventarcEnrollment %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Enrollment: %s", err) } @@ -457,6 +483,19 @@ func resourceEventarcEnrollmentRead(d *schema.ResourceData, meta interface{}) er } func resourceEventarcEnrollmentUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceEventarcEnrollment().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceEventarcEnrollmentRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -595,6 +634,13 @@ func resourceEventarcEnrollmentUpdate(d *schema.ResourceData, meta interface{}) } func resourceEventarcEnrollmentDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy EventarcEnrollment without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Enrollment %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/eventarc/resource_eventarc_enrollment_generated_meta.yaml b/google-beta/services/eventarc/resource_eventarc_enrollment_generated_meta.yaml index 27cd95bd968..fffcea98b14 100644 --- a/google-beta/services/eventarc/resource_eventarc_enrollment_generated_meta.yaml +++ b/google-beta/services/eventarc/resource_eventarc_enrollment_generated_meta.yaml @@ -28,3 +28,5 @@ fields: provider_only: true - api_field: uid - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/eventarc/resource_eventarc_google_api_source.go b/google-beta/services/eventarc/resource_eventarc_google_api_source.go index d2b5f6bdf73..8803d8d6395 100644 --- a/google-beta/services/eventarc/resource_eventarc_google_api_source.go +++ b/google-beta/services/eventarc/resource_eventarc_google_api_source.go @@ -117,6 +117,7 @@ func ResourceEventarcGoogleApiSource() *schema.Resource { tpgresource.SetLabelsDiff, tpgresource.SetAnnotationsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -269,6 +270,18 @@ string and guaranteed to remain unchanged until the resource is deleted.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -436,6 +449,19 @@ func resourceEventarcGoogleApiSourceRead(d *schema.ResourceData, meta interface{ log.Printf("[DEBUG] Finished reading EventarcGoogleApiSource %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading GoogleApiSource: %s", err) } @@ -473,6 +499,19 @@ func resourceEventarcGoogleApiSourceRead(d *schema.ResourceData, meta interface{ } func resourceEventarcGoogleApiSourceUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceEventarcGoogleApiSource().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceEventarcGoogleApiSourceRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -621,6 +660,13 @@ func resourceEventarcGoogleApiSourceUpdate(d *schema.ResourceData, meta interfac } func resourceEventarcGoogleApiSourceDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy EventarcGoogleApiSource without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing GoogleApiSource %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/eventarc/resource_eventarc_google_api_source_generated_meta.yaml b/google-beta/services/eventarc/resource_eventarc_google_api_source_generated_meta.yaml index e2c2663a754..26e1a8adc33 100644 --- a/google-beta/services/eventarc/resource_eventarc_google_api_source_generated_meta.yaml +++ b/google-beta/services/eventarc/resource_eventarc_google_api_source_generated_meta.yaml @@ -28,3 +28,5 @@ fields: provider_only: true - api_field: uid - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/eventarc/resource_eventarc_google_channel_config.go b/google-beta/services/eventarc/resource_eventarc_google_channel_config.go index ad78866bff1..623a37e09b3 100644 --- a/google-beta/services/eventarc/resource_eventarc_google_channel_config.go +++ b/google-beta/services/eventarc/resource_eventarc_google_channel_config.go @@ -326,6 +326,7 @@ func resourceEventarcGoogleChannelConfigRead(d *schema.ResourceData, meta interf } func resourceEventarcGoogleChannelConfigUpdate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/eventarc/resource_eventarc_message_bus.go b/google-beta/services/eventarc/resource_eventarc_message_bus.go index af7d21e9221..51a712761c0 100644 --- a/google-beta/services/eventarc/resource_eventarc_message_bus.go +++ b/google-beta/services/eventarc/resource_eventarc_message_bus.go @@ -117,6 +117,7 @@ func ResourceEventarcMessageBus() *schema.Resource { tpgresource.SetLabelsDiff, tpgresource.SetAnnotationsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -263,6 +264,18 @@ string and guaranteed to remain unchanged until the resource is deleted.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -424,6 +437,19 @@ func resourceEventarcMessageBusRead(d *schema.ResourceData, meta interface{}) er log.Printf("[DEBUG] Finished reading EventarcMessageBus %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading MessageBus: %s", err) } @@ -461,6 +487,19 @@ func resourceEventarcMessageBusRead(d *schema.ResourceData, meta interface{}) er } func resourceEventarcMessageBusUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceEventarcMessageBus().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceEventarcMessageBusRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -599,6 +638,13 @@ func resourceEventarcMessageBusUpdate(d *schema.ResourceData, meta interface{}) } func resourceEventarcMessageBusDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy EventarcMessageBus without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing MessageBus %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/eventarc/resource_eventarc_message_bus_generated_meta.yaml b/google-beta/services/eventarc/resource_eventarc_message_bus_generated_meta.yaml index 39e09cbf1a0..d51c92e8e90 100644 --- a/google-beta/services/eventarc/resource_eventarc_message_bus_generated_meta.yaml +++ b/google-beta/services/eventarc/resource_eventarc_message_bus_generated_meta.yaml @@ -27,3 +27,5 @@ fields: provider_only: true - api_field: uid - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/eventarc/resource_eventarc_pipeline.go b/google-beta/services/eventarc/resource_eventarc_pipeline.go index bfc3e026d0a..5688af6c9c4 100644 --- a/google-beta/services/eventarc/resource_eventarc_pipeline.go +++ b/google-beta/services/eventarc/resource_eventarc_pipeline.go @@ -117,6 +117,7 @@ func ResourceEventarcPipeline() *schema.Resource { tpgresource.SetAnnotationsDiff, tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -828,6 +829,18 @@ to nine fractional digits. Examples: "2014-10-02T15:01:23Z" and Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -1013,6 +1026,19 @@ func resourceEventarcPipelineRead(d *schema.ResourceData, meta interface{}) erro log.Printf("[DEBUG] Finished reading EventarcPipeline %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Pipeline: %s", err) } @@ -1050,6 +1076,19 @@ func resourceEventarcPipelineRead(d *schema.ResourceData, meta interface{}) erro } func resourceEventarcPipelineUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceEventarcPipeline().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceEventarcPipelineRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1228,6 +1267,13 @@ func resourceEventarcPipelineUpdate(d *schema.ResourceData, meta interface{}) er } func resourceEventarcPipelineDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy EventarcPipeline without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Pipeline %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/eventarc/resource_eventarc_pipeline_generated_meta.yaml b/google-beta/services/eventarc/resource_eventarc_pipeline_generated_meta.yaml index 24b8fca6773..afd6d18576d 100644 --- a/google-beta/services/eventarc/resource_eventarc_pipeline_generated_meta.yaml +++ b/google-beta/services/eventarc/resource_eventarc_pipeline_generated_meta.yaml @@ -47,3 +47,5 @@ fields: provider_only: true - api_field: uid - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/eventarc/resource_eventarc_trigger.go b/google-beta/services/eventarc/resource_eventarc_trigger.go index 7528b0cc63e..ca40b37f6a3 100644 --- a/google-beta/services/eventarc/resource_eventarc_trigger.go +++ b/google-beta/services/eventarc/resource_eventarc_trigger.go @@ -116,6 +116,7 @@ func ResourceEventarcTrigger() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Schema: map[string]*schema.Schema{ @@ -380,6 +381,18 @@ value is 1.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -568,6 +581,19 @@ func resourceEventarcTriggerRead(d *schema.ResourceData, meta interface{}) error log.Printf("[DEBUG] Finished reading EventarcTrigger %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Trigger: %s", err) } @@ -581,6 +607,19 @@ func resourceEventarcTriggerRead(d *schema.ResourceData, meta interface{}) error } func resourceEventarcTriggerUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceEventarcTrigger().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceEventarcTriggerRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -709,6 +748,13 @@ func resourceEventarcTriggerUpdate(d *schema.ResourceData, meta interface{}) err } func resourceEventarcTriggerDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy EventarcTrigger without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Trigger %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/eventarc/resource_eventarc_trigger_generated_meta.yaml b/google-beta/services/eventarc/resource_eventarc_trigger_generated_meta.yaml index 28c13b83d60..ebda752b842 100644 --- a/google-beta/services/eventarc/resource_eventarc_trigger_generated_meta.yaml +++ b/google-beta/services/eventarc/resource_eventarc_trigger_generated_meta.yaml @@ -47,3 +47,5 @@ fields: - api_field: transport.pubsub.topic - api_field: uid - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/filestore/resource_filestore_backup.go b/google-beta/services/filestore/resource_filestore_backup.go index 7dec47c8e91..0a66bc83f9e 100644 --- a/google-beta/services/filestore/resource_filestore_backup.go +++ b/google-beta/services/filestore/resource_filestore_backup.go @@ -116,6 +116,7 @@ func ResourceFilestoreBackup() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -251,6 +252,18 @@ The field is ignored (both PUT & PATCH) when empty.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -421,6 +434,19 @@ func resourceFilestoreBackupRead(d *schema.ResourceData, meta interface{}) error log.Printf("[DEBUG] Finished reading FilestoreBackup %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Backup: %s", err) } @@ -458,6 +484,19 @@ func resourceFilestoreBackupRead(d *schema.ResourceData, meta interface{}) error } func resourceFilestoreBackupUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceFilestoreBackup().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceFilestoreBackupRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -584,6 +623,13 @@ func resourceFilestoreBackupUpdate(d *schema.ResourceData, meta interface{}) err } func resourceFilestoreBackupDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy FilestoreBackup without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Backup %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/filestore/resource_filestore_backup_generated_meta.yaml b/google-beta/services/filestore/resource_filestore_backup_generated_meta.yaml index 719c7d9299c..656c6e81e19 100644 --- a/google-beta/services/filestore/resource_filestore_backup_generated_meta.yaml +++ b/google-beta/services/filestore/resource_filestore_backup_generated_meta.yaml @@ -27,3 +27,5 @@ fields: - api_field: tags - field: terraform_labels provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/filestore/resource_filestore_instance.go b/google-beta/services/filestore/resource_filestore_instance.go index 9ec6a46f018..f553289606c 100644 --- a/google-beta/services/filestore/resource_filestore_instance.go +++ b/google-beta/services/filestore/resource_filestore_instance.go @@ -152,6 +152,7 @@ func ResourceFilestoreInstance() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -658,6 +659,18 @@ simultaneous updates from overwriting each other.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -902,6 +915,18 @@ func resourceFilestoreInstanceRead(d *schema.ResourceData, meta interface{}) err return fmt.Errorf("Error setting desired_replica_state: %s", err) } } + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Instance: %s", err) } @@ -939,6 +964,19 @@ func resourceFilestoreInstanceRead(d *schema.ResourceData, meta interface{}) err } func resourceFilestoreInstanceUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceFilestoreInstance().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceFilestoreInstanceRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1139,6 +1177,13 @@ func resourceFilestoreInstanceUpdate(d *schema.ResourceData, meta interface{}) e } func resourceFilestoreInstanceDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy FilestoreInstance without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Instance %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/filestore/resource_filestore_instance_generated_meta.yaml b/google-beta/services/filestore/resource_filestore_instance_generated_meta.yaml index 6068f08faf4..be348777ce2 100644 --- a/google-beta/services/filestore/resource_filestore_instance_generated_meta.yaml +++ b/google-beta/services/filestore/resource_filestore_instance_generated_meta.yaml @@ -65,3 +65,5 @@ fields: - api_field: tier - field: zone provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/filestore/resource_filestore_snapshot.go b/google-beta/services/filestore/resource_filestore_snapshot.go index 262257a5b99..249bd91fb12 100644 --- a/google-beta/services/filestore/resource_filestore_snapshot.go +++ b/google-beta/services/filestore/resource_filestore_snapshot.go @@ -116,6 +116,7 @@ func ResourceFilestoreSnapshot() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -220,6 +221,18 @@ Please refer to the field 'effective_labels' for all of the labels present on th Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -377,6 +390,19 @@ func resourceFilestoreSnapshotRead(d *schema.ResourceData, meta interface{}) err log.Printf("[DEBUG] Finished reading FilestoreSnapshot %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Snapshot: %s", err) } @@ -420,6 +446,19 @@ func resourceFilestoreSnapshotRead(d *schema.ResourceData, meta interface{}) err } func resourceFilestoreSnapshotUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceFilestoreSnapshot().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceFilestoreSnapshotRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -541,6 +580,13 @@ func resourceFilestoreSnapshotUpdate(d *schema.ResourceData, meta interface{}) e } func resourceFilestoreSnapshotDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy FilestoreSnapshot without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Snapshot %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/filestore/resource_filestore_snapshot_generated_meta.yaml b/google-beta/services/filestore/resource_filestore_snapshot_generated_meta.yaml index 18fd4c1790d..6ba79248ce5 100644 --- a/google-beta/services/filestore/resource_filestore_snapshot_generated_meta.yaml +++ b/google-beta/services/filestore/resource_filestore_snapshot_generated_meta.yaml @@ -22,3 +22,5 @@ fields: - api_field: state - field: terraform_labels provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/firebase/resource_firebase_android_app.go b/google-beta/services/firebase/resource_firebase_android_app.go index 284fe196ec9..e20aa875078 100644 --- a/google-beta/services/firebase/resource_firebase_android_app.go +++ b/google-beta/services/firebase/resource_firebase_android_app.go @@ -115,6 +115,7 @@ func ResourceFirebaseAndroidApp() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -191,19 +192,23 @@ with update requests to ensure the client has an up-to-date value before proceed Description: `The fully qualified resource name of the AndroidApp, for example: projects/projectId/androidApps/appId`, }, - "deletion_policy": { + "project": { Type: schema.TypeString, Optional: true, - Description: `(Optional) Set to 'ABANDON' to allow the AndroidApp to be untracked from terraform state -rather than deleted upon 'terraform destroy'. This is useful because the AndroidApp may be -serving traffic. Set to 'DELETE' to delete the AndroidApp. Defaults to 'DELETE'.`, - Default: "DELETE", + Computed: true, + ForceNew: true, }, - "project": { + "deletion_policy": { Type: schema.TypeString, Optional: true, Computed: true, - ForceNew: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, }, }, UseJSONNumber: true, @@ -383,8 +388,15 @@ func resourceFirebaseAndroidAppRead(d *schema.ResourceData, meta interface{}) er // Explicitly set virtual fields to default values if unset if _, ok := d.GetOkExists("deletion_policy"); !ok { - if err := d.Set("deletion_policy", "DELETE"); err != nil { - return fmt.Errorf("Error setting deletion_policy: %s", err) + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } } } if err := d.Set("project", project); err != nil { @@ -418,6 +430,19 @@ func resourceFirebaseAndroidAppRead(d *schema.ResourceData, meta interface{}) er } func resourceFirebaseAndroidAppUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceFirebaseAndroidApp().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceFirebaseAndroidAppRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -544,6 +569,13 @@ func resourceFirebaseAndroidAppUpdate(d *schema.ResourceData, meta interface{}) } func resourceFirebaseAndroidAppDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy FirebaseAndroidApp without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing AndroidApp %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -628,11 +660,6 @@ func resourceFirebaseAndroidAppImport(d *schema.ResourceData, meta interface{}) } d.SetId(id) - // Explicitly set virtual fields to default values on import - if err := d.Set("deletion_policy", "DELETE"); err != nil { - return nil, fmt.Errorf("Error setting deletion_policy: %s", err) - } - return []*schema.ResourceData{d}, nil } diff --git a/google-beta/services/firebase/resource_firebase_android_app_generated_meta.yaml b/google-beta/services/firebase/resource_firebase_android_app_generated_meta.yaml index b4e1fa6c9c9..b84f92b8cf7 100644 --- a/google-beta/services/firebase/resource_firebase_android_app_generated_meta.yaml +++ b/google-beta/services/firebase/resource_firebase_android_app_generated_meta.yaml @@ -9,11 +9,11 @@ api_resource_type_kind: AndroidApp fields: - api_field: apiKeyId - api_field: appId - - field: deletion_policy - provider_only: true - api_field: displayName - api_field: etag - api_field: name - api_field: packageName - api_field: sha1Hashes - api_field: sha256Hashes + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/firebase/resource_firebase_apple_app.go b/google-beta/services/firebase/resource_firebase_apple_app.go index b324f5a6392..2f3ab3adab8 100644 --- a/google-beta/services/firebase/resource_firebase_apple_app.go +++ b/google-beta/services/firebase/resource_firebase_apple_app.go @@ -115,6 +115,7 @@ func ResourceFirebaseAppleApp() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -178,19 +179,23 @@ This identifier should be treated as an opaque token, as the data format is not Description: `The fully qualified resource name of the App, for example: projects/projectId/iosApps/appId`, }, - "deletion_policy": { + "project": { Type: schema.TypeString, Optional: true, - Description: `(Optional) Set to 'ABANDON' to allow the Apple to be untracked from terraform state -rather than deleted upon 'terraform destroy'. This is useful because the Apple may be -serving traffic. Set to 'DELETE' to delete the Apple. Defaults to 'DELETE'.`, - Default: "DELETE", + Computed: true, + ForceNew: true, }, - "project": { + "deletion_policy": { Type: schema.TypeString, Optional: true, Computed: true, - ForceNew: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, }, }, UseJSONNumber: true, @@ -364,8 +369,15 @@ func resourceFirebaseAppleAppRead(d *schema.ResourceData, meta interface{}) erro // Explicitly set virtual fields to default values if unset if _, ok := d.GetOkExists("deletion_policy"); !ok { - if err := d.Set("deletion_policy", "DELETE"); err != nil { - return fmt.Errorf("Error setting deletion_policy: %s", err) + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } } } if err := d.Set("project", project); err != nil { @@ -399,6 +411,19 @@ func resourceFirebaseAppleAppRead(d *schema.ResourceData, meta interface{}) erro } func resourceFirebaseAppleAppUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceFirebaseAppleApp().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceFirebaseAppleAppRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -515,6 +540,13 @@ func resourceFirebaseAppleAppUpdate(d *schema.ResourceData, meta interface{}) er } func resourceFirebaseAppleAppDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy FirebaseAppleApp without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing AppleApp %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -599,11 +631,6 @@ func resourceFirebaseAppleAppImport(d *schema.ResourceData, meta interface{}) ([ } d.SetId(id) - // Explicitly set virtual fields to default values on import - if err := d.Set("deletion_policy", "DELETE"); err != nil { - return nil, fmt.Errorf("Error setting deletion_policy: %s", err) - } - return []*schema.ResourceData{d}, nil } diff --git a/google-beta/services/firebase/resource_firebase_apple_app_generated_meta.yaml b/google-beta/services/firebase/resource_firebase_apple_app_generated_meta.yaml index a53a1916eb1..9fc58f7a45c 100644 --- a/google-beta/services/firebase/resource_firebase_apple_app_generated_meta.yaml +++ b/google-beta/services/firebase/resource_firebase_apple_app_generated_meta.yaml @@ -11,8 +11,8 @@ fields: - api_field: appId - api_field: appStoreId - api_field: bundleId - - field: deletion_policy - provider_only: true - api_field: displayName - api_field: name - api_field: teamId + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/firebase/resource_firebase_web_app.go b/google-beta/services/firebase/resource_firebase_web_app.go index 6da5783151e..d3a80bad109 100644 --- a/google-beta/services/firebase/resource_firebase_web_app.go +++ b/google-beta/services/firebase/resource_firebase_web_app.go @@ -115,6 +115,7 @@ func ResourceFirebaseWebApp() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -170,19 +171,23 @@ This identifier should be treated as an opaque token, as the data format is not Description: `The fully qualified resource name of the App, for example: projects/projectId/webApps/appId`, }, - "deletion_policy": { + "project": { Type: schema.TypeString, Optional: true, - Description: `Set to 'ABANDON' to allow the WebApp to be untracked from terraform state -rather than deleted upon 'terraform destroy'. This is useful becaue the WebApp may be -serving traffic. Set to 'DELETE' to delete the WebApp. Default to 'DELETE'`, - Default: "DELETE", + Computed: true, + ForceNew: true, }, - "project": { + "deletion_policy": { Type: schema.TypeString, Optional: true, Computed: true, - ForceNew: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, }, }, UseJSONNumber: true, @@ -338,8 +343,15 @@ func resourceFirebaseWebAppRead(d *schema.ResourceData, meta interface{}) error // Explicitly set virtual fields to default values if unset if _, ok := d.GetOkExists("deletion_policy"); !ok { - if err := d.Set("deletion_policy", "DELETE"); err != nil { - return fmt.Errorf("Error setting deletion_policy: %s", err) + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } } } if err := d.Set("project", project); err != nil { @@ -373,6 +385,19 @@ func resourceFirebaseWebAppRead(d *schema.ResourceData, meta interface{}) error } func resourceFirebaseWebAppUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceFirebaseWebApp().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceFirebaseWebAppRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -469,6 +494,13 @@ func resourceFirebaseWebAppUpdate(d *schema.ResourceData, meta interface{}) erro } func resourceFirebaseWebAppDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy FirebaseWebApp without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing WebApp %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -553,11 +585,6 @@ func resourceFirebaseWebAppImport(d *schema.ResourceData, meta interface{}) ([]* } d.SetId(id) - // Explicitly set virtual fields to default values on import - if err := d.Set("deletion_policy", "DELETE"); err != nil { - return nil, fmt.Errorf("Error setting deletion_policy: %s", err) - } - return []*schema.ResourceData{d}, nil } diff --git a/google-beta/services/firebase/resource_firebase_web_app_generated_meta.yaml b/google-beta/services/firebase/resource_firebase_web_app_generated_meta.yaml index 7aefe35b9d1..4f4046f6bfd 100644 --- a/google-beta/services/firebase/resource_firebase_web_app_generated_meta.yaml +++ b/google-beta/services/firebase/resource_firebase_web_app_generated_meta.yaml @@ -10,7 +10,7 @@ fields: - api_field: apiKeyId - api_field: appId - api_field: appUrls - - field: deletion_policy - provider_only: true - api_field: displayName - api_field: name + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/firebaseailogic/resource_firebase_ai_logic_config.go b/google-beta/services/firebaseailogic/resource_firebase_ai_logic_config.go index c60fbc8fc03..597abd49001 100644 --- a/google-beta/services/firebaseailogic/resource_firebase_ai_logic_config.go +++ b/google-beta/services/firebaseailogic/resource_firebase_ai_logic_config.go @@ -115,6 +115,7 @@ func ResourceFirebaseAILogicConfig() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -247,6 +248,18 @@ Format: projects/{project}/locations/{location}/config`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -381,6 +394,19 @@ func resourceFirebaseAILogicConfigRead(d *schema.ResourceData, meta interface{}) log.Printf("[DEBUG] Finished reading FirebaseAILogicConfig %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Config: %s", err) } @@ -412,6 +438,19 @@ func resourceFirebaseAILogicConfigRead(d *schema.ResourceData, meta interface{}) } func resourceFirebaseAILogicConfigUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceFirebaseAILogicConfig().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceFirebaseAILogicConfigRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -518,6 +557,13 @@ func resourceFirebaseAILogicConfigUpdate(d *schema.ResourceData, meta interface{ } func resourceFirebaseAILogicConfigDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy FirebaseAILogicConfig without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Config %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/firebaseailogic/resource_firebase_ai_logic_config_generated_meta.yaml b/google-beta/services/firebaseailogic/resource_firebase_ai_logic_config_generated_meta.yaml index c5469a9ee13..e6b1d699418 100644 --- a/google-beta/services/firebaseailogic/resource_firebase_ai_logic_config_generated_meta.yaml +++ b/google-beta/services/firebaseailogic/resource_firebase_ai_logic_config_generated_meta.yaml @@ -19,3 +19,5 @@ fields: - api_field: telemetryConfig.mode - api_field: telemetryConfig.samplingRate - api_field: trafficFilter.templateOnly + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/firebaseailogic/resource_firebase_ai_logic_prompt_template.go b/google-beta/services/firebaseailogic/resource_firebase_ai_logic_prompt_template.go index 5956cb32315..027e9fd377e 100644 --- a/google-beta/services/firebaseailogic/resource_firebase_ai_logic_prompt_template.go +++ b/google-beta/services/firebaseailogic/resource_firebase_ai_logic_prompt_template.go @@ -115,6 +115,7 @@ func ResourceFirebaseAILogicPromptTemplate() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -207,6 +208,18 @@ projects/{project}/locations/{location}/templates/{prompt_template}`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -346,6 +359,19 @@ func resourceFirebaseAILogicPromptTemplateRead(d *schema.ResourceData, meta inte log.Printf("[DEBUG] Finished reading FirebaseAILogicPromptTemplate %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading PromptTemplate: %s", err) } @@ -383,6 +409,19 @@ func resourceFirebaseAILogicPromptTemplateRead(d *schema.ResourceData, meta inte } func resourceFirebaseAILogicPromptTemplateUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceFirebaseAILogicPromptTemplate().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceFirebaseAILogicPromptTemplateRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -484,6 +523,13 @@ func resourceFirebaseAILogicPromptTemplateUpdate(d *schema.ResourceData, meta in } func resourceFirebaseAILogicPromptTemplateDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy FirebaseAILogicPromptTemplate without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing PromptTemplate %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/firebaseailogic/resource_firebase_ai_logic_prompt_template_generated_meta.yaml b/google-beta/services/firebaseailogic/resource_firebase_ai_logic_prompt_template_generated_meta.yaml index ad10e726075..e1361c68bcd 100644 --- a/google-beta/services/firebaseailogic/resource_firebase_ai_logic_prompt_template_generated_meta.yaml +++ b/google-beta/services/firebaseailogic/resource_firebase_ai_logic_prompt_template_generated_meta.yaml @@ -19,3 +19,5 @@ fields: - api_field: templateId - api_field: templateString - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/firebaseailogic/resource_firebase_ai_logic_prompt_template_lock.go b/google-beta/services/firebaseailogic/resource_firebase_ai_logic_prompt_template_lock.go index c5064bfda8f..10d60d986a4 100644 --- a/google-beta/services/firebaseailogic/resource_firebase_ai_logic_prompt_template_lock.go +++ b/google-beta/services/firebaseailogic/resource_firebase_ai_logic_prompt_template_lock.go @@ -100,6 +100,7 @@ func ResourceFirebaseAILogicPromptTemplateLock() *schema.Resource { return &schema.Resource{ Create: resourceFirebaseAILogicPromptTemplateLockCreate, Read: resourceFirebaseAILogicPromptTemplateLockRead, + Update: resourceFirebaseAILogicPromptTemplateLockUpdate, Delete: resourceFirebaseAILogicPromptTemplateLockDelete, Importer: &schema.ResourceImporter{ @@ -113,6 +114,7 @@ func ResourceFirebaseAILogicPromptTemplateLock() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -168,6 +170,18 @@ This is verified against the server-side PromptTemplate resource.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -301,6 +315,19 @@ func resourceFirebaseAILogicPromptTemplateLockRead(d *schema.ResourceData, meta // and d.Set("name", ...) after this block because those fields are defined // as output properties in the YAML and match the keys in 'res'. + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading PromptTemplateLock: %s", err) } @@ -337,7 +364,19 @@ func resourceFirebaseAILogicPromptTemplateLockRead(d *schema.ResourceData, meta return nil } +func resourceFirebaseAILogicPromptTemplateLockUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceFirebaseAILogicPromptTemplateLockRead(d, meta) +} + func resourceFirebaseAILogicPromptTemplateLockDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy FirebaseAILogicPromptTemplateLock without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing PromptTemplateLock %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/firebaseailogic/resource_firebase_ai_logic_prompt_template_lock_generated_meta.yaml b/google-beta/services/firebaseailogic/resource_firebase_ai_logic_prompt_template_lock_generated_meta.yaml index f337220b201..100ee933c70 100644 --- a/google-beta/services/firebaseailogic/resource_firebase_ai_logic_prompt_template_lock_generated_meta.yaml +++ b/google-beta/services/firebaseailogic/resource_firebase_ai_logic_prompt_template_lock_generated_meta.yaml @@ -13,3 +13,5 @@ fields: - api_field: name - field: template_id provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/firebaseappcheck/resource_firebase_app_check_app_attest_config.go b/google-beta/services/firebaseappcheck/resource_firebase_app_check_app_attest_config.go index 999a5622f32..c280f46b53d 100644 --- a/google-beta/services/firebaseappcheck/resource_firebase_app_check_app_attest_config.go +++ b/google-beta/services/firebaseappcheck/resource_firebase_app_check_app_attest_config.go @@ -317,6 +317,7 @@ func resourceFirebaseAppCheckAppAttestConfigRead(d *schema.ResourceData, meta in } func resourceFirebaseAppCheckAppAttestConfigUpdate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/firebaseappcheck/resource_firebase_app_check_debug_token.go b/google-beta/services/firebaseappcheck/resource_firebase_app_check_debug_token.go index 2057fdeaf40..90e27b0c493 100644 --- a/google-beta/services/firebaseappcheck/resource_firebase_app_check_debug_token.go +++ b/google-beta/services/firebaseappcheck/resource_firebase_app_check_debug_token.go @@ -115,6 +115,7 @@ func ResourceFirebaseAppCheckDebugToken() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -180,6 +181,18 @@ For security reasons, this field will never be populated in any response.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -319,6 +332,19 @@ func resourceFirebaseAppCheckDebugTokenRead(d *schema.ResourceData, meta interfa log.Printf("[DEBUG] Finished reading FirebaseAppCheckDebugToken %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading DebugToken: %s", err) } @@ -356,6 +382,19 @@ func resourceFirebaseAppCheckDebugTokenRead(d *schema.ResourceData, meta interfa } func resourceFirebaseAppCheckDebugTokenUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceFirebaseAppCheckDebugToken().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceFirebaseAppCheckDebugTokenRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -447,6 +486,13 @@ func resourceFirebaseAppCheckDebugTokenUpdate(d *schema.ResourceData, meta inter } func resourceFirebaseAppCheckDebugTokenDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy FirebaseAppCheckDebugToken without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing DebugToken %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/firebaseappcheck/resource_firebase_app_check_debug_token_generated_meta.yaml b/google-beta/services/firebaseappcheck/resource_firebase_app_check_debug_token_generated_meta.yaml index c6ec2e8a8f5..e64c35542a7 100644 --- a/google-beta/services/firebaseappcheck/resource_firebase_app_check_debug_token_generated_meta.yaml +++ b/google-beta/services/firebaseappcheck/resource_firebase_app_check_debug_token_generated_meta.yaml @@ -13,3 +13,5 @@ fields: field: debug_token_id - api_field: displayName - api_field: token + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/firebaseappcheck/resource_firebase_app_check_device_check_config.go b/google-beta/services/firebaseappcheck/resource_firebase_app_check_device_check_config.go index 0cc3dd4a6a1..5d4d6f80676 100644 --- a/google-beta/services/firebaseappcheck/resource_firebase_app_check_device_check_config.go +++ b/google-beta/services/firebaseappcheck/resource_firebase_app_check_device_check_config.go @@ -346,6 +346,7 @@ func resourceFirebaseAppCheckDeviceCheckConfigRead(d *schema.ResourceData, meta } func resourceFirebaseAppCheckDeviceCheckConfigUpdate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/firebaseappcheck/resource_firebase_app_check_play_integrity_config.go b/google-beta/services/firebaseappcheck/resource_firebase_app_check_play_integrity_config.go index 073d9e000b4..9c1e37af468 100644 --- a/google-beta/services/firebaseappcheck/resource_firebase_app_check_play_integrity_config.go +++ b/google-beta/services/firebaseappcheck/resource_firebase_app_check_play_integrity_config.go @@ -317,6 +317,7 @@ func resourceFirebaseAppCheckPlayIntegrityConfigRead(d *schema.ResourceData, met } func resourceFirebaseAppCheckPlayIntegrityConfigUpdate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/firebaseappcheck/resource_firebase_app_check_recaptcha_enterprise_config.go b/google-beta/services/firebaseappcheck/resource_firebase_app_check_recaptcha_enterprise_config.go index 4c227cb8878..13e75696d44 100644 --- a/google-beta/services/firebaseappcheck/resource_firebase_app_check_recaptcha_enterprise_config.go +++ b/google-beta/services/firebaseappcheck/resource_firebase_app_check_recaptcha_enterprise_config.go @@ -330,6 +330,7 @@ func resourceFirebaseAppCheckRecaptchaEnterpriseConfigRead(d *schema.ResourceDat } func resourceFirebaseAppCheckRecaptchaEnterpriseConfigUpdate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/firebaseappcheck/resource_firebase_app_check_recaptcha_v3_config.go b/google-beta/services/firebaseappcheck/resource_firebase_app_check_recaptcha_v3_config.go index 62f103c52c8..2ed43feb099 100644 --- a/google-beta/services/firebaseappcheck/resource_firebase_app_check_recaptcha_v3_config.go +++ b/google-beta/services/firebaseappcheck/resource_firebase_app_check_recaptcha_v3_config.go @@ -335,6 +335,7 @@ func resourceFirebaseAppCheckRecaptchaV3ConfigRead(d *schema.ResourceData, meta } func resourceFirebaseAppCheckRecaptchaV3ConfigUpdate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/firebaseappcheck/resource_firebase_app_check_resource_policy.go b/google-beta/services/firebaseappcheck/resource_firebase_app_check_resource_policy.go index 93f156ede11..eb544cc40c3 100644 --- a/google-beta/services/firebaseappcheck/resource_firebase_app_check_resource_policy.go +++ b/google-beta/services/firebaseappcheck/resource_firebase_app_check_resource_policy.go @@ -115,6 +115,7 @@ func ResourceFirebaseAppCheckResourcePolicy() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -215,6 +216,18 @@ clients in use. Possible values: ["UNENFORCED", "ENFORCED"]`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -354,6 +367,19 @@ func resourceFirebaseAppCheckResourcePolicyRead(d *schema.ResourceData, meta int log.Printf("[DEBUG] Finished reading FirebaseAppCheckResourcePolicy %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading ResourcePolicy: %s", err) } @@ -391,6 +417,19 @@ func resourceFirebaseAppCheckResourcePolicyRead(d *schema.ResourceData, meta int } func resourceFirebaseAppCheckResourcePolicyUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceFirebaseAppCheckResourcePolicy().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceFirebaseAppCheckResourcePolicyRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -492,6 +531,13 @@ func resourceFirebaseAppCheckResourcePolicyUpdate(d *schema.ResourceData, meta i } func resourceFirebaseAppCheckResourcePolicyDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy FirebaseAppCheckResourcePolicy without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing ResourcePolicy %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/firebaseappcheck/resource_firebase_app_check_resource_policy_generated_meta.yaml b/google-beta/services/firebaseappcheck/resource_firebase_app_check_resource_policy_generated_meta.yaml index f9daca460a4..ea322a8197e 100644 --- a/google-beta/services/firebaseappcheck/resource_firebase_app_check_resource_policy_generated_meta.yaml +++ b/google-beta/services/firebaseappcheck/resource_firebase_app_check_resource_policy_generated_meta.yaml @@ -15,3 +15,5 @@ fields: provider_only: true - api_field: targetResource - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/firebaseappcheck/resource_firebase_app_check_service_config.go b/google-beta/services/firebaseappcheck/resource_firebase_app_check_service_config.go index ba09c15915d..bd6e9bc193c 100644 --- a/google-beta/services/firebaseappcheck/resource_firebase_app_check_service_config.go +++ b/google-beta/services/firebaseappcheck/resource_firebase_app_check_service_config.go @@ -115,6 +115,7 @@ func ResourceFirebaseAppCheckServiceConfig() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -193,6 +194,18 @@ clients in use. Possible values: ["UNENFORCED", "ENFORCED"]`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -315,6 +328,19 @@ func resourceFirebaseAppCheckServiceConfigRead(d *schema.ResourceData, meta inte log.Printf("[DEBUG] Finished reading FirebaseAppCheckServiceConfig %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading ServiceConfig: %s", err) } @@ -346,6 +372,19 @@ func resourceFirebaseAppCheckServiceConfigRead(d *schema.ResourceData, meta inte } func resourceFirebaseAppCheckServiceConfigUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceFirebaseAppCheckServiceConfig().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceFirebaseAppCheckServiceConfigRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -432,6 +471,13 @@ func resourceFirebaseAppCheckServiceConfigUpdate(d *schema.ResourceData, meta in } func resourceFirebaseAppCheckServiceConfigDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy FirebaseAppCheckServiceConfig without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing ServiceConfig %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/firebaseappcheck/resource_firebase_app_check_service_config_generated_meta.yaml b/google-beta/services/firebaseappcheck/resource_firebase_app_check_service_config_generated_meta.yaml index eefb90b1d5d..bcf30efd623 100644 --- a/google-beta/services/firebaseappcheck/resource_firebase_app_check_service_config_generated_meta.yaml +++ b/google-beta/services/firebaseappcheck/resource_firebase_app_check_service_config_generated_meta.yaml @@ -11,3 +11,5 @@ fields: - api_field: name - field: service_id provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/firebaseapphosting/resource_firebase_app_hosting_backend.go b/google-beta/services/firebaseapphosting/resource_firebase_app_hosting_backend.go index 6ea75f211b4..082e54dfe2b 100644 --- a/google-beta/services/firebaseapphosting/resource_firebase_app_hosting_backend.go +++ b/google-beta/services/firebaseapphosting/resource_firebase_app_hosting_backend.go @@ -117,6 +117,7 @@ func ResourceFirebaseAppHostingBackend() *schema.Resource { tpgresource.SetAnnotationsDiff, tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -330,6 +331,18 @@ Format: Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -515,6 +528,19 @@ func resourceFirebaseAppHostingBackendRead(d *schema.ResourceData, meta interfac log.Printf("[DEBUG] Finished reading FirebaseAppHostingBackend %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Backend: %s", err) } @@ -552,6 +578,19 @@ func resourceFirebaseAppHostingBackendRead(d *schema.ResourceData, meta interfac } func resourceFirebaseAppHostingBackendUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceFirebaseAppHostingBackend().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceFirebaseAppHostingBackendRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -720,6 +759,13 @@ func resourceFirebaseAppHostingBackendUpdate(d *schema.ResourceData, meta interf } func resourceFirebaseAppHostingBackendDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy FirebaseAppHostingBackend without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Backend %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/firebaseapphosting/resource_firebase_app_hosting_backend_generated_meta.yaml b/google-beta/services/firebaseapphosting/resource_firebase_app_hosting_backend_generated_meta.yaml index 309ea8804ed..c2597dc01ea 100644 --- a/google-beta/services/firebaseapphosting/resource_firebase_app_hosting_backend_generated_meta.yaml +++ b/google-beta/services/firebaseapphosting/resource_firebase_app_hosting_backend_generated_meta.yaml @@ -35,3 +35,5 @@ fields: - api_field: uid - api_field: updateTime - api_field: uri + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/firebaseapphosting/resource_firebase_app_hosting_build.go b/google-beta/services/firebaseapphosting/resource_firebase_app_hosting_build.go index dbd78dee860..fd81e78e4fb 100644 --- a/google-beta/services/firebaseapphosting/resource_firebase_app_hosting_build.go +++ b/google-beta/services/firebaseapphosting/resource_firebase_app_hosting_build.go @@ -648,7 +648,7 @@ func resourceFirebaseAppHostingBuildRead(d *schema.ResourceData, meta interface{ } func resourceFirebaseAppHostingBuildUpdate(d *schema.ResourceData, meta interface{}) error { - // Only the root field "labels", "terraform_labels", and virtual fields are mutable + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable return resourceFirebaseAppHostingBuildRead(d, meta) } diff --git a/google-beta/services/firebaseapphosting/resource_firebase_app_hosting_default_domain.go b/google-beta/services/firebaseapphosting/resource_firebase_app_hosting_default_domain.go index a2eba5c7f20..294c849f960 100644 --- a/google-beta/services/firebaseapphosting/resource_firebase_app_hosting_default_domain.go +++ b/google-beta/services/firebaseapphosting/resource_firebase_app_hosting_default_domain.go @@ -387,6 +387,7 @@ func resourceFirebaseAppHostingDefaultDomainRead(d *schema.ResourceData, meta in } func resourceFirebaseAppHostingDefaultDomainUpdate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/firebaseapphosting/resource_firebase_app_hosting_domain.go b/google-beta/services/firebaseapphosting/resource_firebase_app_hosting_domain.go index af987d59919..65b41802dd5 100644 --- a/google-beta/services/firebaseapphosting/resource_firebase_app_hosting_domain.go +++ b/google-beta/services/firebaseapphosting/resource_firebase_app_hosting_domain.go @@ -115,6 +115,7 @@ func ResourceFirebaseAppHostingDomain() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -539,6 +540,18 @@ permanently deleted.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -712,6 +725,19 @@ func resourceFirebaseAppHostingDomainRead(d *schema.ResourceData, meta interface log.Printf("[DEBUG] Finished reading FirebaseAppHostingDomain %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Domain: %s", err) } @@ -755,6 +781,19 @@ func resourceFirebaseAppHostingDomainRead(d *schema.ResourceData, meta interface } func resourceFirebaseAppHostingDomainUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceFirebaseAppHostingDomain().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceFirebaseAppHostingDomainRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -856,6 +895,13 @@ func resourceFirebaseAppHostingDomainUpdate(d *schema.ResourceData, meta interfa } func resourceFirebaseAppHostingDomainDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy FirebaseAppHostingDomain without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Domain %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/firebaseapphosting/resource_firebase_app_hosting_domain_generated_meta.yaml b/google-beta/services/firebaseapphosting/resource_firebase_app_hosting_domain_generated_meta.yaml index b02dd736881..aa77db14863 100644 --- a/google-beta/services/firebaseapphosting/resource_firebase_app_hosting_domain_generated_meta.yaml +++ b/google-beta/services/firebaseapphosting/resource_firebase_app_hosting_domain_generated_meta.yaml @@ -52,3 +52,5 @@ fields: - api_field: serve.redirect.uri - api_field: uid - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/firebaseapphosting/resource_firebase_app_hosting_traffic.go b/google-beta/services/firebaseapphosting/resource_firebase_app_hosting_traffic.go index 6eaeca66684..0972677bfda 100644 --- a/google-beta/services/firebaseapphosting/resource_firebase_app_hosting_traffic.go +++ b/google-beta/services/firebaseapphosting/resource_firebase_app_hosting_traffic.go @@ -469,6 +469,7 @@ func resourceFirebaseAppHostingTrafficRead(d *schema.ResourceData, meta interfac } func resourceFirebaseAppHostingTrafficUpdate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/firebasedatabase/resource_firebase_database_instance.go b/google-beta/services/firebasedatabase/resource_firebase_database_instance.go index a5f143f24ef..ddfb253e7b2 100644 --- a/google-beta/services/firebasedatabase/resource_firebase_database_instance.go +++ b/google-beta/services/firebasedatabase/resource_firebase_database_instance.go @@ -157,6 +157,7 @@ func ResourceFirebaseDatabaseInstance() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -239,6 +240,18 @@ Learn more about using project identifiers in Google's [AIP 2510 standard](https Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -392,6 +405,18 @@ func resourceFirebaseDatabaseInstanceRead(d *schema.ResourceData, meta interface return fmt.Errorf("Error setting desired_state: %s", err) } } + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Instance: %s", err) } @@ -429,6 +454,19 @@ func resourceFirebaseDatabaseInstanceRead(d *schema.ResourceData, meta interface } func resourceFirebaseDatabaseInstanceUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceFirebaseDatabaseInstance().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceFirebaseDatabaseInstanceRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -525,6 +563,13 @@ func resourceFirebaseDatabaseInstanceUpdate(d *schema.ResourceData, meta interfa } func resourceFirebaseDatabaseInstanceDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy FirebaseDatabaseInstance without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Instance %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/firebasedatabase/resource_firebase_database_instance_generated_meta.yaml b/google-beta/services/firebasedatabase/resource_firebase_database_instance_generated_meta.yaml index 131964e9e5b..0fd6275c0c9 100644 --- a/google-beta/services/firebasedatabase/resource_firebase_database_instance_generated_meta.yaml +++ b/google-beta/services/firebasedatabase/resource_firebase_database_instance_generated_meta.yaml @@ -17,3 +17,5 @@ fields: provider_only: true - api_field: state - api_field: type + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/firebasedataconnect/resource_firebase_data_connect_service.go b/google-beta/services/firebasedataconnect/resource_firebase_data_connect_service.go index 9f165ca95b3..75204a6150a 100644 --- a/google-beta/services/firebasedataconnect/resource_firebase_data_connect_service.go +++ b/google-beta/services/firebasedataconnect/resource_firebase_data_connect_service.go @@ -117,6 +117,7 @@ func ResourceFirebaseDataConnectService() *schema.Resource { tpgresource.SetAnnotationsDiff, tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DEFAULT"), ), Identity: &schema.ResourceIdentity{ @@ -239,22 +240,18 @@ service.`, Computed: true, Description: `Output only. [Output only] Update time stamp.`, }, - "deletion_policy": { - Type: schema.TypeString, - Optional: true, - Description: `The deletion policy for the database. Setting the field to FORCE allows the -Service to be deleted even if a Schema or Connector is present. By default, -the Service deletion will only succeed when no Schema or Connectors are -present. -Possible values: DEFAULT, FORCE`, - Default: "DEFAULT", - }, "project": { Type: schema.TypeString, Optional: true, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `This field uses a custom implementation please refer to documentation under /hashicorp/terraform-provider-google-beta/website/docs/r/firebase_data_connect_service.html.markdown for specifics`, + }, }, UseJSONNumber: true, } @@ -412,8 +409,15 @@ func resourceFirebaseDataConnectServiceRead(d *schema.ResourceData, meta interfa // Explicitly set virtual fields to default values if unset if _, ok := d.GetOkExists("deletion_policy"); !ok { - if err := d.Set("deletion_policy", "DEFAULT"); err != nil { - return fmt.Errorf("Error setting deletion_policy: %s", err) + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DEFAULT"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } } } if err := d.Set("project", project); err != nil { @@ -453,6 +457,19 @@ func resourceFirebaseDataConnectServiceRead(d *schema.ResourceData, meta interfa } func resourceFirebaseDataConnectServiceUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceFirebaseDataConnectService().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceFirebaseDataConnectServiceRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -581,6 +598,13 @@ func resourceFirebaseDataConnectServiceUpdate(d *schema.ResourceData, meta inter } func resourceFirebaseDataConnectServiceDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy FirebaseDataConnectService without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Service %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -657,9 +681,6 @@ func resourceFirebaseDataConnectServiceImport(d *schema.ResourceData, meta inter d.SetId(id) // Explicitly set virtual fields to default values on import - if err := d.Set("deletion_policy", "DEFAULT"); err != nil { - return nil, fmt.Errorf("Error setting deletion_policy: %s", err) - } return []*schema.ResourceData{d}, nil } diff --git a/google-beta/services/firebasedataconnect/resource_firebase_data_connect_service_generated_meta.yaml b/google-beta/services/firebasedataconnect/resource_firebase_data_connect_service_generated_meta.yaml index 2a11d801bf6..84f46b7cdb6 100644 --- a/google-beta/services/firebasedataconnect/resource_firebase_data_connect_service_generated_meta.yaml +++ b/google-beta/services/firebasedataconnect/resource_firebase_data_connect_service_generated_meta.yaml @@ -10,8 +10,6 @@ autogen_status: true fields: - api_field: annotations - api_field: createTime - - field: deletion_policy - provider_only: true - api_field: displayName - field: effective_annotations provider_only: true @@ -29,3 +27,5 @@ fields: provider_only: true - api_field: uid - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/firebaseextensions/resource_firebase_extensions_instance.go b/google-beta/services/firebaseextensions/resource_firebase_extensions_instance.go index 2fb712466bd..3c6b6669b0e 100644 --- a/google-beta/services/firebaseextensions/resource_firebase_extensions_instance.go +++ b/google-beta/services/firebaseextensions/resource_firebase_extensions_instance.go @@ -115,6 +115,7 @@ func ResourceFirebaseExtensionsInstance() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -362,6 +363,18 @@ created for the operation of the Extension instance.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -500,6 +513,19 @@ func resourceFirebaseExtensionsInstanceRead(d *schema.ResourceData, meta interfa log.Printf("[DEBUG] Finished reading FirebaseExtensionsInstance %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Instance: %s", err) } @@ -531,6 +557,19 @@ func resourceFirebaseExtensionsInstanceRead(d *schema.ResourceData, meta interfa } func resourceFirebaseExtensionsInstanceUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceFirebaseExtensionsInstance().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceFirebaseExtensionsInstanceRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -639,6 +678,13 @@ func resourceFirebaseExtensionsInstanceUpdate(d *schema.ResourceData, meta inter } func resourceFirebaseExtensionsInstanceDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy FirebaseExtensionsInstance without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Instance %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/firebaseextensions/resource_firebase_extensions_instance_generated_meta.yaml b/google-beta/services/firebaseextensions/resource_firebase_extensions_instance_generated_meta.yaml index 39c4f55d923..b33f5a66dbd 100644 --- a/google-beta/services/firebaseextensions/resource_firebase_extensions_instance_generated_meta.yaml +++ b/google-beta/services/firebaseextensions/resource_firebase_extensions_instance_generated_meta.yaml @@ -33,3 +33,5 @@ fields: - api_field: serviceAccountEmail - api_field: state - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/firebasehosting/resource_firebase_hosting_channel.go b/google-beta/services/firebasehosting/resource_firebase_hosting_channel.go index fe023028fa7..05657838022 100644 --- a/google-beta/services/firebasehosting/resource_firebase_hosting_channel.go +++ b/google-beta/services/firebasehosting/resource_firebase_hosting_channel.go @@ -115,6 +115,7 @@ func ResourceFirebaseHostingChannel() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -202,6 +203,19 @@ sites/SITE_ID/channels/CHANNEL_ID`, and default labels configured on the provider.`, Elem: &schema.Schema{Type: schema.TypeString}, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -330,6 +344,20 @@ func resourceFirebaseHostingChannelRead(d *schema.ResourceData, meta interface{} log.Printf("[DEBUG] Finished reading FirebaseHostingChannel %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceFirebaseHostingChannelFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -357,6 +385,19 @@ func resourceFirebaseHostingChannelRead(d *schema.ResourceData, meta interface{} } func resourceFirebaseHostingChannelUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceFirebaseHostingChannel().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceFirebaseHostingChannelRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -457,6 +498,13 @@ func resourceFirebaseHostingChannelUpdate(d *schema.ResourceData, meta interface } func resourceFirebaseHostingChannelDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy FirebaseHostingChannel without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Channel %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/firebasehosting/resource_firebase_hosting_channel_generated_meta.yaml b/google-beta/services/firebasehosting/resource_firebase_hosting_channel_generated_meta.yaml index 451cb2d34b6..89d8d99e637 100644 --- a/google-beta/services/firebasehosting/resource_firebase_hosting_channel_generated_meta.yaml +++ b/google-beta/services/firebasehosting/resource_firebase_hosting_channel_generated_meta.yaml @@ -20,3 +20,5 @@ fields: - field: terraform_labels provider_only: true - api_field: ttl + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/firebasehosting/resource_firebase_hosting_custom_domain.go b/google-beta/services/firebasehosting/resource_firebase_hosting_custom_domain.go index 35035168b75..b0db3e34821 100644 --- a/google-beta/services/firebasehosting/resource_firebase_hosting_custom_domain.go +++ b/google-beta/services/firebasehosting/resource_firebase_hosting_custom_domain.go @@ -115,6 +115,7 @@ func ResourceFirebaseHostingCustomDomain() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -626,6 +627,18 @@ the 'CustomDomain' will be returned and stored in the Terraform state.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -786,6 +799,18 @@ func resourceFirebaseHostingCustomDomainRead(d *schema.ResourceData, meta interf return fmt.Errorf("Error setting wait_dns_verification: %s", err) } } + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading CustomDomain: %s", err) } @@ -823,6 +848,19 @@ func resourceFirebaseHostingCustomDomainRead(d *schema.ResourceData, meta interf } func resourceFirebaseHostingCustomDomainUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceFirebaseHostingCustomDomain().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceFirebaseHostingCustomDomainRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -941,6 +979,13 @@ func resourceFirebaseHostingCustomDomainUpdate(d *schema.ResourceData, meta inte } func resourceFirebaseHostingCustomDomainDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy FirebaseHostingCustomDomain without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing CustomDomain %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/firebasehosting/resource_firebase_hosting_custom_domain_generated_meta.yaml b/google-beta/services/firebasehosting/resource_firebase_hosting_custom_domain_generated_meta.yaml index a878f781efd..6011ecc08ad 100644 --- a/google-beta/services/firebasehosting/resource_firebase_hosting_custom_domain_generated_meta.yaml +++ b/google-beta/services/firebasehosting/resource_firebase_hosting_custom_domain_generated_meta.yaml @@ -56,3 +56,5 @@ fields: - api_field: updateTime - field: wait_dns_verification provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/firebasehosting/resource_firebase_hosting_site.go b/google-beta/services/firebasehosting/resource_firebase_hosting_site.go index a929119ea24..8b8100b4155 100644 --- a/google-beta/services/firebasehosting/resource_firebase_hosting_site.go +++ b/google-beta/services/firebasehosting/resource_firebase_hosting_site.go @@ -115,6 +115,7 @@ func ResourceFirebaseHostingSite() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -178,6 +179,18 @@ Learn more about using project identifiers in Google's Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -327,6 +340,19 @@ func resourceFirebaseHostingSiteRead(d *schema.ResourceData, meta interface{}) e log.Printf("[DEBUG] Finished reading FirebaseHostingSite %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Site: %s", err) } @@ -358,6 +384,19 @@ func resourceFirebaseHostingSiteRead(d *schema.ResourceData, meta interface{}) e } func resourceFirebaseHostingSiteUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceFirebaseHostingSite().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceFirebaseHostingSiteRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -444,6 +483,13 @@ func resourceFirebaseHostingSiteUpdate(d *schema.ResourceData, meta interface{}) } func resourceFirebaseHostingSiteDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy FirebaseHostingSite without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Site %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/firebasehosting/resource_firebase_hosting_site_generated_meta.yaml b/google-beta/services/firebasehosting/resource_firebase_hosting_site_generated_meta.yaml index 3f3503c4fc1..8ad55e81662 100644 --- a/google-beta/services/firebasehosting/resource_firebase_hosting_site_generated_meta.yaml +++ b/google-beta/services/firebasehosting/resource_firebase_hosting_site_generated_meta.yaml @@ -13,3 +13,5 @@ fields: - field: site_id provider_only: true - api_field: type + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/firebaseremoteconfig/resource_firebase_remote_config_remote_config.go b/google-beta/services/firebaseremoteconfig/resource_firebase_remote_config_remote_config.go index 29bd38cb143..f8a9f0e9098 100644 --- a/google-beta/services/firebaseremoteconfig/resource_firebase_remote_config_remote_config.go +++ b/google-beta/services/firebaseremoteconfig/resource_firebase_remote_config_remote_config.go @@ -601,6 +601,7 @@ func resourceFirebaseRemoteConfigRemoteConfigRead(d *schema.ResourceData, meta i } func resourceFirebaseRemoteConfigRemoteConfigUpdate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/firebaserules/resource_firebaserules_release.go b/google-beta/services/firebaserules/resource_firebaserules_release.go index b26abcc66b9..a8f9dede78d 100644 --- a/google-beta/services/firebaserules/resource_firebaserules_release.go +++ b/google-beta/services/firebaserules/resource_firebaserules_release.go @@ -36,6 +36,7 @@ func ResourceFirebaserulesRelease() *schema.Resource { return &schema.Resource{ Create: resourceFirebaserulesReleaseCreate, Read: resourceFirebaserulesReleaseRead, + Update: resourceFirebaserulesReleaseUpdate, Delete: resourceFirebaserulesReleaseDelete, Importer: &schema.ResourceImporter{ @@ -48,6 +49,7 @@ func ResourceFirebaserulesRelease() *schema.Resource { }, CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Schema: map[string]*schema.Schema{ @@ -92,6 +94,9 @@ func ResourceFirebaserulesRelease() *schema.Resource { Computed: true, Description: "Output only. Time the release was updated.", }, + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end }, } } @@ -200,10 +205,29 @@ func resourceFirebaserulesReleaseRead(d *schema.ResourceData, meta interface{}) return fmt.Errorf("error setting update_time in state: %s", err) } + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + return nil } +// UDP update start +func resourceFirebaserulesReleaseUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceFirebaserulesReleaseRead(d, meta) +} + +//UDP update end + func resourceFirebaserulesReleaseDelete(d *schema.ResourceData, meta interface{}) error { + + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { + return nil + } + config := meta.(*transport_tpg.Config) project, err := tpgresource.GetProject(d, config) if err != nil { diff --git a/google-beta/services/firebaserules/resource_firebaserules_release_meta.yaml b/google-beta/services/firebaserules/resource_firebaserules_release_meta.yaml index 6130f2ff337..6016a550efe 100644 --- a/google-beta/services/firebaserules/resource_firebaserules_release_meta.yaml +++ b/google-beta/services/firebaserules/resource_firebaserules_release_meta.yaml @@ -12,3 +12,5 @@ fields: - field: 'project' - api_field: 'rulesetName' - api_field: 'updateTime' + - field: 'deletion_policy' + provider_only: true diff --git a/google-beta/services/firebaserules/resource_firebaserules_ruleset.go b/google-beta/services/firebaserules/resource_firebaserules_ruleset.go index 90ef6234ce0..f97e8617df6 100644 --- a/google-beta/services/firebaserules/resource_firebaserules_ruleset.go +++ b/google-beta/services/firebaserules/resource_firebaserules_ruleset.go @@ -36,6 +36,7 @@ func ResourceFirebaserulesRuleset() *schema.Resource { return &schema.Resource{ Create: resourceFirebaserulesRulesetCreate, Read: resourceFirebaserulesRulesetRead, + Update: resourceFirebaserulesRulesetUpdate, Delete: resourceFirebaserulesRulesetDelete, Importer: &schema.ResourceImporter{ @@ -48,6 +49,7 @@ func ResourceFirebaserulesRuleset() *schema.Resource { }, CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Schema: map[string]*schema.Schema{ @@ -87,6 +89,9 @@ func ResourceFirebaserulesRuleset() *schema.Resource { Computed: true, Description: "Output only. Name of the `Ruleset`. The ruleset_id is auto generated by the service. Format: `projects/{project_id}/rulesets/{ruleset_id}`", }, + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end }, } } @@ -263,10 +268,29 @@ func resourceFirebaserulesRulesetRead(d *schema.ResourceData, meta interface{}) return fmt.Errorf("error setting name in state: %s", err) } + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + return nil } +// UDP update start +func resourceFirebaserulesRulesetUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceFirebaserulesRulesetRead(d, meta) +} + +//UDP update end + func resourceFirebaserulesRulesetDelete(d *schema.ResourceData, meta interface{}) error { + + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { + return nil + } + config := meta.(*transport_tpg.Config) project, err := tpgresource.GetProject(d, config) if err != nil { diff --git a/google-beta/services/firebaserules/resource_firebaserules_ruleset_meta.yaml b/google-beta/services/firebaserules/resource_firebaserules_ruleset_meta.yaml index 4df9f4d820d..9e831795454 100644 --- a/google-beta/services/firebaserules/resource_firebaserules_ruleset_meta.yaml +++ b/google-beta/services/firebaserules/resource_firebaserules_ruleset_meta.yaml @@ -14,3 +14,5 @@ fields: - api_field: 'source.files.fingerprint' - api_field: 'source.files.name' - api_field: 'source.language' + - field: 'deletion_policy' + provider_only: true diff --git a/google-beta/services/firebasestorage/resource_firebase_storage_bucket.go b/google-beta/services/firebasestorage/resource_firebase_storage_bucket.go index c7a951e18f2..585bdb4e3f7 100644 --- a/google-beta/services/firebasestorage/resource_firebase_storage_bucket.go +++ b/google-beta/services/firebasestorage/resource_firebase_storage_bucket.go @@ -100,6 +100,7 @@ func ResourceFirebaseStorageBucket() *schema.Resource { return &schema.Resource{ Create: resourceFirebaseStorageBucketCreate, Read: resourceFirebaseStorageBucketRead, + Update: resourceFirebaseStorageBucketUpdate, Delete: resourceFirebaseStorageBucketDelete, Importer: &schema.ResourceImporter{ @@ -113,6 +114,7 @@ func ResourceFirebaseStorageBucket() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -152,6 +154,18 @@ func ResourceFirebaseStorageBucket() *schema.Resource { Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -268,6 +282,19 @@ func resourceFirebaseStorageBucketRead(d *schema.ResourceData, meta interface{}) log.Printf("[DEBUG] Finished reading FirebaseStorageBucket %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Bucket: %s", err) } @@ -298,7 +325,19 @@ func resourceFirebaseStorageBucketRead(d *schema.ResourceData, meta interface{}) return nil } +func resourceFirebaseStorageBucketUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceFirebaseStorageBucketRead(d, meta) +} + func resourceFirebaseStorageBucketDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy FirebaseStorageBucket without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Bucket %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/firebasestorage/resource_firebase_storage_bucket_generated_meta.yaml b/google-beta/services/firebasestorage/resource_firebase_storage_bucket_generated_meta.yaml index 82419bcfc75..c8334eaec1c 100644 --- a/google-beta/services/firebasestorage/resource_firebase_storage_bucket_generated_meta.yaml +++ b/google-beta/services/firebasestorage/resource_firebase_storage_bucket_generated_meta.yaml @@ -10,3 +10,5 @@ fields: - field: bucket_id provider_only: true - api_field: name + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/firebasestorage/resource_firebase_storage_default_bucket.go b/google-beta/services/firebasestorage/resource_firebase_storage_default_bucket.go index 913725a33c8..58ebc5b48f1 100644 --- a/google-beta/services/firebasestorage/resource_firebase_storage_default_bucket.go +++ b/google-beta/services/firebasestorage/resource_firebase_storage_default_bucket.go @@ -100,6 +100,7 @@ func ResourceFirebaseStorageDefaultBucket() *schema.Resource { return &schema.Resource{ Create: resourceFirebaseStorageDefaultBucketCreate, Read: resourceFirebaseStorageDefaultBucketRead, + Update: resourceFirebaseStorageDefaultBucketUpdate, Delete: resourceFirebaseStorageDefaultBucketDelete, Importer: &schema.ResourceImporter{ @@ -113,6 +114,7 @@ func ResourceFirebaseStorageDefaultBucket() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -165,6 +167,18 @@ projects/PROJECT_IDENTIFIER/defaultBucket`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -282,6 +296,19 @@ func resourceFirebaseStorageDefaultBucketRead(d *schema.ResourceData, meta inter log.Printf("[DEBUG] Finished reading FirebaseStorageDefaultBucket %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading DefaultBucket: %s", err) } @@ -306,7 +333,19 @@ func resourceFirebaseStorageDefaultBucketRead(d *schema.ResourceData, meta inter return nil } +func resourceFirebaseStorageDefaultBucketUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceFirebaseStorageDefaultBucketRead(d, meta) +} + func resourceFirebaseStorageDefaultBucketDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy FirebaseStorageDefaultBucket without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing DefaultBucket %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/firebasestorage/resource_firebase_storage_default_bucket_generated_meta.yaml b/google-beta/services/firebasestorage/resource_firebase_storage_default_bucket_generated_meta.yaml index 0fa8e3fa6df..62c8c915d09 100644 --- a/google-beta/services/firebasestorage/resource_firebase_storage_default_bucket_generated_meta.yaml +++ b/google-beta/services/firebasestorage/resource_firebase_storage_default_bucket_generated_meta.yaml @@ -10,3 +10,5 @@ fields: - api_field: bucket.name - api_field: location - api_field: name + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/firestore/resource_firestore_backup_schedule.go b/google-beta/services/firestore/resource_firestore_backup_schedule.go index f1a9c654acd..1217446334d 100644 --- a/google-beta/services/firestore/resource_firestore_backup_schedule.go +++ b/google-beta/services/firestore/resource_firestore_backup_schedule.go @@ -115,6 +115,7 @@ func ResourceFirestoreBackupSchedule() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -197,6 +198,18 @@ You can set this to a value up to 14 weeks.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -342,6 +355,19 @@ func resourceFirestoreBackupScheduleRead(d *schema.ResourceData, meta interface{ log.Printf("[DEBUG] Finished reading FirestoreBackupSchedule %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading BackupSchedule: %s", err) } @@ -379,6 +405,19 @@ func resourceFirestoreBackupScheduleRead(d *schema.ResourceData, meta interface{ } func resourceFirestoreBackupScheduleUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceFirestoreBackupSchedule().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceFirestoreBackupScheduleRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -470,6 +509,13 @@ func resourceFirestoreBackupScheduleUpdate(d *schema.ResourceData, meta interfac } func resourceFirestoreBackupScheduleDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy FirestoreBackupSchedule without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing BackupSchedule %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/firestore/resource_firestore_backup_schedule_generated_meta.yaml b/google-beta/services/firestore/resource_firestore_backup_schedule_generated_meta.yaml index d66c0022173..6de75f70a1a 100644 --- a/google-beta/services/firestore/resource_firestore_backup_schedule_generated_meta.yaml +++ b/google-beta/services/firestore/resource_firestore_backup_schedule_generated_meta.yaml @@ -13,3 +13,5 @@ fields: - api_field: name - api_field: retention - api_field: weeklyRecurrence.day + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/firestore/resource_firestore_database.go b/google-beta/services/firestore/resource_firestore_database.go index bd9e1275bd4..60ae0cb6dc5 100644 --- a/google-beta/services/firestore/resource_firestore_database.go +++ b/google-beta/services/firestore/resource_firestore_database.go @@ -115,6 +115,7 @@ func ResourceFirestoreDatabase() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("ABANDON"), ), Identity: &schema.ResourceIdentity{ @@ -335,21 +336,23 @@ Any read or query can specify a readTime within this window, and will read the s If the PITR feature is enabled, the retention period is 7 days. Otherwise, the retention period is 1 hour. A duration in seconds with up to nine fractional digits, ending with 's'. Example: "3.5s".`, }, - "deletion_policy": { + "project": { Type: schema.TypeString, Optional: true, - Description: `Deletion behavior for this database. -If the deletion policy is 'ABANDON', the database will be removed from Terraform state but not deleted from Google Cloud upon destruction. -If the deletion policy is 'DELETE', the database will both be removed from Terraform state and deleted from Google Cloud upon destruction. -The default value is 'ABANDON'. -See also 'delete_protection'.`, - Default: "ABANDON", + Computed: true, + ForceNew: true, }, - "project": { + "deletion_policy": { Type: schema.TypeString, Optional: true, Computed: true, - ForceNew: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "ABANDON". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, }, }, UseJSONNumber: true, @@ -563,8 +566,15 @@ func resourceFirestoreDatabaseRead(d *schema.ResourceData, meta interface{}) err // Explicitly set virtual fields to default values if unset if _, ok := d.GetOkExists("deletion_policy"); !ok { - if err := d.Set("deletion_policy", "ABANDON"); err != nil { - return fmt.Errorf("Error setting deletion_policy: %s", err) + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "ABANDON"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } } } if err := d.Set("project", project); err != nil { @@ -598,6 +608,19 @@ func resourceFirestoreDatabaseRead(d *schema.ResourceData, meta interface{}) err } func resourceFirestoreDatabaseUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceFirestoreDatabase().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceFirestoreDatabaseRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -741,6 +764,13 @@ func resourceFirestoreDatabaseUpdate(d *schema.ResourceData, meta interface{}) e } func resourceFirestoreDatabaseDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy FirestoreDatabase without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Database %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -767,10 +797,6 @@ func resourceFirestoreDatabaseDelete(d *schema.ResourceData, meta interface{}) e } headers := make(http.Header) - if deletionPolicy := d.Get("deletion_policy"); deletionPolicy != "DELETE" { - log.Printf("[WARN] Firestore database %q deletion_policy is not set to 'DELETE', skipping deletion", d.Get("name").(string)) - return nil - } if deleteProtection := d.Get("delete_protection_state"); deleteProtection == "DELETE_PROTECTION_ENABLED" { return fmt.Errorf("Cannot delete Firestore database %s: Delete Protection is enabled. Set delete_protection_state to DELETE_PROTECTION_DISABLED for this resource and run \"terraform apply\" before attempting to delete it.", d.Get("name").(string)) } @@ -811,11 +837,6 @@ func resourceFirestoreDatabaseImport(d *schema.ResourceData, meta interface{}) ( } d.SetId(id) - // Explicitly set virtual fields to default values on import - if err := d.Set("deletion_policy", "ABANDON"); err != nil { - return nil, fmt.Errorf("Error setting deletion_policy: %s", err) - } - return []*schema.ResourceData{d}, nil } diff --git a/google-beta/services/firestore/resource_firestore_database_generated_meta.yaml b/google-beta/services/firestore/resource_firestore_database_generated_meta.yaml index 802d76d086f..2952ac00031 100644 --- a/google-beta/services/firestore/resource_firestore_database_generated_meta.yaml +++ b/google-beta/services/firestore/resource_firestore_database_generated_meta.yaml @@ -14,8 +14,6 @@ fields: - api_field: createTime - api_field: databaseEdition - api_field: deleteProtectionState - - field: deletion_policy - provider_only: true - api_field: earliestVersionTime - api_field: etag - api_field: firestoreDataAccessMode @@ -30,3 +28,5 @@ fields: - api_field: uid - api_field: updateTime - api_field: versionRetentionPeriod + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/firestore/resource_firestore_document.go b/google-beta/services/firestore/resource_firestore_document.go index 72fba0c469a..dbf24712888 100644 --- a/google-beta/services/firestore/resource_firestore_document.go +++ b/google-beta/services/firestore/resource_firestore_document.go @@ -115,6 +115,7 @@ func ResourceFirestoreDocument() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -186,6 +187,18 @@ func ResourceFirestoreDocument() *schema.Resource { Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -321,6 +334,19 @@ func resourceFirestoreDocumentRead(d *schema.ResourceData, meta interface{}) err return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Document: %s", err) } @@ -346,6 +372,19 @@ func resourceFirestoreDocumentRead(d *schema.ResourceData, meta interface{}) err } func resourceFirestoreDocumentUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceFirestoreDocument().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceFirestoreDocumentRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -412,6 +451,13 @@ func resourceFirestoreDocumentUpdate(d *schema.ResourceData, meta interface{}) e } func resourceFirestoreDocumentDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy FirestoreDocument without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Document %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/firestore/resource_firestore_document_generated_meta.yaml b/google-beta/services/firestore/resource_firestore_document_generated_meta.yaml index 9d5785ee7e9..e7acb3ff415 100644 --- a/google-beta/services/firestore/resource_firestore_document_generated_meta.yaml +++ b/google-beta/services/firestore/resource_firestore_document_generated_meta.yaml @@ -19,3 +19,5 @@ fields: - api_field: name - api_field: path - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/firestore/resource_firestore_field.go b/google-beta/services/firestore/resource_firestore_field.go index 12c925316e6..457c09b4eec 100644 --- a/google-beta/services/firestore/resource_firestore_field.go +++ b/google-beta/services/firestore/resource_firestore_field.go @@ -115,6 +115,7 @@ func ResourceFirestoreField() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -199,6 +200,18 @@ the field.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -385,6 +398,19 @@ func resourceFirestoreFieldRead(d *schema.ResourceData, meta interface{}) error log.Printf("[DEBUG] Finished reading FirestoreField %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Field: %s", err) } @@ -410,6 +436,19 @@ func resourceFirestoreFieldRead(d *schema.ResourceData, meta interface{}) error } func resourceFirestoreFieldUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceFirestoreField().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceFirestoreFieldRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -514,6 +553,13 @@ func resourceFirestoreFieldUpdate(d *schema.ResourceData, meta interface{}) erro } func resourceFirestoreFieldDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy FirestoreField without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Field %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/firestore/resource_firestore_field_generated_meta.yaml b/google-beta/services/firestore/resource_firestore_field_generated_meta.yaml index 7ded9f4fdb8..72f8aaa6f00 100644 --- a/google-beta/services/firestore/resource_firestore_field_generated_meta.yaml +++ b/google-beta/services/firestore/resource_firestore_field_generated_meta.yaml @@ -18,3 +18,5 @@ fields: - api_field: indexConfig.indexes.queryScope - api_field: name - api_field: ttlConfig.state + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/firestore/resource_firestore_index.go b/google-beta/services/firestore/resource_firestore_index.go index b9aeb77d2bc..bbe2d649a94 100644 --- a/google-beta/services/firestore/resource_firestore_index.go +++ b/google-beta/services/firestore/resource_firestore_index.go @@ -152,6 +152,7 @@ func ResourceFirestoreIndex() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -364,22 +365,24 @@ with the same dimension.`, Description: `Whether to skip waiting for the index to be created.`, Default: false, }, - "deletion_policy": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: verify.ValidateEnum([]string{"DELETE", "PREVENT", ""}), - Description: `Deletion behavior for this index. -If the deletion policy is 'PREVENT', the index cannot be deleted and a terraform destroy will fail. -If the deletion policy is 'DELETE', the index will both be removed from Terraform state and deleted from Google Cloud upon destruction. -The default value is 'DELETE'. Default value: "DELETE" Possible values: ["DELETE", "PREVENT"]`, - Default: "DELETE", - }, "project": { Type: schema.TypeString, Optional: true, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -582,8 +585,15 @@ func resourceFirestoreIndexRead(d *schema.ResourceData, meta interface{}) error } } if _, ok := d.GetOkExists("deletion_policy"); !ok { - if err := d.Set("deletion_policy", "DELETE"); err != nil { - return fmt.Errorf("Error setting deletion_policy: %s", err) + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } } } if err := d.Set("project", project); err != nil { @@ -611,11 +621,18 @@ func resourceFirestoreIndexRead(d *schema.ResourceData, meta interface{}) error } func resourceFirestoreIndexUpdate(d *schema.ResourceData, meta interface{}) error { - // Only the root field "labels", "terraform_labels", and virtual fields are mutable + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable return resourceFirestoreIndexRead(d, meta) } func resourceFirestoreIndexDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy FirestoreIndex without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Index %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -642,9 +659,6 @@ func resourceFirestoreIndexDelete(d *schema.ResourceData, meta interface{}) erro } headers := make(http.Header) - if d.Get("deletion_policy").(string) == "PREVENT" { - return fmt.Errorf("cannot destroy google_firestore_index resource with id : %q without setting deletion_policy=DELETE and running `terraform apply`", d.Id()) - } log.Printf("[DEBUG] Deleting Index %q", d.Id()) res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ diff --git a/google-beta/services/firestore/resource_firestore_index_generated_meta.yaml b/google-beta/services/firestore/resource_firestore_index_generated_meta.yaml index 69b4abaab78..3a8fd3f1feb 100644 --- a/google-beta/services/firestore/resource_firestore_index_generated_meta.yaml +++ b/google-beta/services/firestore/resource_firestore_index_generated_meta.yaml @@ -10,8 +10,6 @@ fields: - api_field: apiScope - api_field: collection - api_field: database - - field: deletion_policy - provider_only: true - api_field: density - api_field: fields.arrayConfig - api_field: fields.fieldPath @@ -27,3 +25,5 @@ fields: - field: skip_wait provider_only: true - api_field: unique + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/firestore/resource_firestore_user_creds.go b/google-beta/services/firestore/resource_firestore_user_creds.go index d45974281e4..5d12163fb87 100644 --- a/google-beta/services/firestore/resource_firestore_user_creds.go +++ b/google-beta/services/firestore/resource_firestore_user_creds.go @@ -100,6 +100,7 @@ func ResourceFirestoreUserCreds() *schema.Resource { return &schema.Resource{ Create: resourceFirestoreUserCredsCreate, Read: resourceFirestoreUserCredsRead, + Update: resourceFirestoreUserCredsUpdate, Delete: resourceFirestoreUserCredsDelete, Importer: &schema.ResourceImporter{ @@ -113,6 +114,7 @@ func ResourceFirestoreUserCreds() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -198,6 +200,18 @@ See https://cloud.google.com/iam/docs/principal-identifiers.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -334,6 +348,19 @@ func resourceFirestoreUserCredsRead(d *schema.ResourceData, meta interface{}) er log.Printf("[DEBUG] Finished reading FirestoreUserCreds %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading UserCreds: %s", err) } @@ -370,7 +397,19 @@ func resourceFirestoreUserCredsRead(d *schema.ResourceData, meta interface{}) er return nil } +func resourceFirestoreUserCredsUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceFirestoreUserCredsRead(d, meta) +} + func resourceFirestoreUserCredsDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy FirestoreUserCreds without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing UserCreds %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/firestore/resource_firestore_user_creds_generated_meta.yaml b/google-beta/services/firestore/resource_firestore_user_creds_generated_meta.yaml index 10a6bb9a1d2..8959104d172 100644 --- a/google-beta/services/firestore/resource_firestore_user_creds_generated_meta.yaml +++ b/google-beta/services/firestore/resource_firestore_user_creds_generated_meta.yaml @@ -15,3 +15,5 @@ fields: - api_field: securePassword - api_field: state - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/gemini/resource_gemini_code_repository_index.go b/google-beta/services/gemini/resource_gemini_code_repository_index.go index 49c59da5274..6f3ed948828 100644 --- a/google-beta/services/gemini/resource_gemini_code_repository_index.go +++ b/google-beta/services/gemini/resource_gemini_code_repository_index.go @@ -116,6 +116,7 @@ func ResourceGeminiCodeRepositoryIndex() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -216,6 +217,18 @@ Possible values are: 'STATE_UNSPECIFIED', 'CREATING', 'ACTIVE', 'DELETING', 'SUS Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -374,6 +387,18 @@ func resourceGeminiCodeRepositoryIndexRead(d *schema.ResourceData, meta interfac return fmt.Errorf("Error setting force_destroy: %s", err) } } + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading CodeRepositoryIndex: %s", err) } @@ -411,6 +436,19 @@ func resourceGeminiCodeRepositoryIndexRead(d *schema.ResourceData, meta interfac } func resourceGeminiCodeRepositoryIndexUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceGeminiCodeRepositoryIndex().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceGeminiCodeRepositoryIndexRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -517,6 +555,13 @@ func resourceGeminiCodeRepositoryIndexUpdate(d *schema.ResourceData, meta interf } func resourceGeminiCodeRepositoryIndexDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy GeminiCodeRepositoryIndex without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing CodeRepositoryIndex %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/gemini/resource_gemini_code_repository_index_generated_meta.yaml b/google-beta/services/gemini/resource_gemini_code_repository_index_generated_meta.yaml index e66f1341354..ffd52ca1c40 100644 --- a/google-beta/services/gemini/resource_gemini_code_repository_index_generated_meta.yaml +++ b/google-beta/services/gemini/resource_gemini_code_repository_index_generated_meta.yaml @@ -23,3 +23,5 @@ fields: - field: terraform_labels provider_only: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/gemini/resource_gemini_code_tools_setting.go b/google-beta/services/gemini/resource_gemini_code_tools_setting.go index 890754860f5..5a325450334 100644 --- a/google-beta/services/gemini/resource_gemini_code_tools_setting.go +++ b/google-beta/services/gemini/resource_gemini_code_tools_setting.go @@ -116,6 +116,7 @@ func ResourceGeminiCodeToolsSetting() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -247,6 +248,18 @@ Format:projects/{project}/locations/{location}/codeToolsSettings/{codeToolsSetti Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -387,6 +400,19 @@ func resourceGeminiCodeToolsSettingRead(d *schema.ResourceData, meta interface{} log.Printf("[DEBUG] Finished reading GeminiCodeToolsSetting %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading CodeToolsSetting: %s", err) } @@ -424,6 +450,19 @@ func resourceGeminiCodeToolsSettingRead(d *schema.ResourceData, meta interface{} } func resourceGeminiCodeToolsSettingUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceGeminiCodeToolsSetting().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceGeminiCodeToolsSettingRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -532,6 +571,13 @@ func resourceGeminiCodeToolsSettingUpdate(d *schema.ResourceData, meta interface } func resourceGeminiCodeToolsSettingDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy GeminiCodeToolsSetting without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing CodeToolsSetting %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/gemini/resource_gemini_code_tools_setting_binding.go b/google-beta/services/gemini/resource_gemini_code_tools_setting_binding.go index 65bc4b671ab..1c810e3c740 100644 --- a/google-beta/services/gemini/resource_gemini_code_tools_setting_binding.go +++ b/google-beta/services/gemini/resource_gemini_code_tools_setting_binding.go @@ -116,6 +116,7 @@ func ResourceGeminiCodeToolsSettingBinding() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -220,6 +221,18 @@ Format:projects/{project}/locations/{location}/codeToolsSettings/{setting}/setti Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -381,6 +394,19 @@ func resourceGeminiCodeToolsSettingBindingRead(d *schema.ResourceData, meta inte log.Printf("[DEBUG] Finished reading GeminiCodeToolsSettingBinding %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading CodeToolsSettingBinding: %s", err) } @@ -424,6 +450,19 @@ func resourceGeminiCodeToolsSettingBindingRead(d *schema.ResourceData, meta inte } func resourceGeminiCodeToolsSettingBindingUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceGeminiCodeToolsSettingBinding().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceGeminiCodeToolsSettingBindingRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -554,6 +593,13 @@ func resourceGeminiCodeToolsSettingBindingUpdate(d *schema.ResourceData, meta in } func resourceGeminiCodeToolsSettingBindingDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy GeminiCodeToolsSettingBinding without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing CodeToolsSettingBinding %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/gemini/resource_gemini_code_tools_setting_binding_generated_meta.yaml b/google-beta/services/gemini/resource_gemini_code_tools_setting_binding_generated_meta.yaml index ebbc69a2416..4759eb8da9a 100644 --- a/google-beta/services/gemini/resource_gemini_code_tools_setting_binding_generated_meta.yaml +++ b/google-beta/services/gemini/resource_gemini_code_tools_setting_binding_generated_meta.yaml @@ -24,3 +24,5 @@ fields: - field: terraform_labels provider_only: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/gemini/resource_gemini_code_tools_setting_generated_meta.yaml b/google-beta/services/gemini/resource_gemini_code_tools_setting_generated_meta.yaml index f36d1f64110..983bd0b72a1 100644 --- a/google-beta/services/gemini/resource_gemini_code_tools_setting_generated_meta.yaml +++ b/google-beta/services/gemini/resource_gemini_code_tools_setting_generated_meta.yaml @@ -26,3 +26,5 @@ fields: - field: terraform_labels provider_only: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/gemini/resource_gemini_data_sharing_with_google_setting.go b/google-beta/services/gemini/resource_gemini_data_sharing_with_google_setting.go index c3eb5db7abb..e61016768cd 100644 --- a/google-beta/services/gemini/resource_gemini_data_sharing_with_google_setting.go +++ b/google-beta/services/gemini/resource_gemini_data_sharing_with_google_setting.go @@ -116,6 +116,7 @@ func ResourceGeminiDataSharingWithGoogleSetting() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -208,6 +209,18 @@ Format:projects/{project}/locations/{location}/dataSharingWithGoogleSettings/{da Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -354,6 +367,19 @@ func resourceGeminiDataSharingWithGoogleSettingRead(d *schema.ResourceData, meta log.Printf("[DEBUG] Finished reading GeminiDataSharingWithGoogleSetting %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading DataSharingWithGoogleSetting: %s", err) } @@ -391,6 +417,19 @@ func resourceGeminiDataSharingWithGoogleSettingRead(d *schema.ResourceData, meta } func resourceGeminiDataSharingWithGoogleSettingUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceGeminiDataSharingWithGoogleSetting().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceGeminiDataSharingWithGoogleSettingRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -509,6 +548,13 @@ func resourceGeminiDataSharingWithGoogleSettingUpdate(d *schema.ResourceData, me } func resourceGeminiDataSharingWithGoogleSettingDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy GeminiDataSharingWithGoogleSetting without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing DataSharingWithGoogleSetting %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/gemini/resource_gemini_data_sharing_with_google_setting_binding.go b/google-beta/services/gemini/resource_gemini_data_sharing_with_google_setting_binding.go index 04c1c63113f..f11f8617b3c 100644 --- a/google-beta/services/gemini/resource_gemini_data_sharing_with_google_setting_binding.go +++ b/google-beta/services/gemini/resource_gemini_data_sharing_with_google_setting_binding.go @@ -116,6 +116,7 @@ func ResourceGeminiDataSharingWithGoogleSettingBinding() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -219,6 +220,18 @@ Format:projects/{project}/locations/{location}/dataSharingWithGoogleSettings/{se Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -380,6 +393,19 @@ func resourceGeminiDataSharingWithGoogleSettingBindingRead(d *schema.ResourceDat log.Printf("[DEBUG] Finished reading GeminiDataSharingWithGoogleSettingBinding %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading DataSharingWithGoogleSettingBinding: %s", err) } @@ -423,6 +449,19 @@ func resourceGeminiDataSharingWithGoogleSettingBindingRead(d *schema.ResourceDat } func resourceGeminiDataSharingWithGoogleSettingBindingUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceGeminiDataSharingWithGoogleSettingBinding().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceGeminiDataSharingWithGoogleSettingBindingRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -553,6 +592,13 @@ func resourceGeminiDataSharingWithGoogleSettingBindingUpdate(d *schema.ResourceD } func resourceGeminiDataSharingWithGoogleSettingBindingDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy GeminiDataSharingWithGoogleSettingBinding without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing DataSharingWithGoogleSettingBinding %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/gemini/resource_gemini_data_sharing_with_google_setting_binding_generated_meta.yaml b/google-beta/services/gemini/resource_gemini_data_sharing_with_google_setting_binding_generated_meta.yaml index e74b8e6dc38..cd1b1cccf32 100644 --- a/google-beta/services/gemini/resource_gemini_data_sharing_with_google_setting_binding_generated_meta.yaml +++ b/google-beta/services/gemini/resource_gemini_data_sharing_with_google_setting_binding_generated_meta.yaml @@ -26,3 +26,5 @@ fields: - field: terraform_labels provider_only: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/gemini/resource_gemini_data_sharing_with_google_setting_generated_meta.yaml b/google-beta/services/gemini/resource_gemini_data_sharing_with_google_setting_generated_meta.yaml index 93c65d63fd1..b4a8df5e133 100644 --- a/google-beta/services/gemini/resource_gemini_data_sharing_with_google_setting_generated_meta.yaml +++ b/google-beta/services/gemini/resource_gemini_data_sharing_with_google_setting_generated_meta.yaml @@ -22,3 +22,5 @@ fields: - field: terraform_labels provider_only: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/gemini/resource_gemini_gemini_gcp_enablement_setting.go b/google-beta/services/gemini/resource_gemini_gemini_gcp_enablement_setting.go index 97dd0f548a1..ded74b28868 100644 --- a/google-beta/services/gemini/resource_gemini_gemini_gcp_enablement_setting.go +++ b/google-beta/services/gemini/resource_gemini_gemini_gcp_enablement_setting.go @@ -116,6 +116,7 @@ func ResourceGeminiGeminiGcpEnablementSetting() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -217,6 +218,18 @@ Format:projects/{project}/locations/{location}/geminiGcpEnablementSettings/{gemi Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -369,6 +382,19 @@ func resourceGeminiGeminiGcpEnablementSettingRead(d *schema.ResourceData, meta i log.Printf("[DEBUG] Finished reading GeminiGeminiGcpEnablementSetting %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading GeminiGcpEnablementSetting: %s", err) } @@ -406,6 +432,19 @@ func resourceGeminiGeminiGcpEnablementSettingRead(d *schema.ResourceData, meta i } func resourceGeminiGeminiGcpEnablementSettingUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceGeminiGeminiGcpEnablementSetting().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceGeminiGeminiGcpEnablementSettingRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -534,6 +573,13 @@ func resourceGeminiGeminiGcpEnablementSettingUpdate(d *schema.ResourceData, meta } func resourceGeminiGeminiGcpEnablementSettingDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy GeminiGeminiGcpEnablementSetting without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing GeminiGcpEnablementSetting %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/gemini/resource_gemini_gemini_gcp_enablement_setting_binding.go b/google-beta/services/gemini/resource_gemini_gemini_gcp_enablement_setting_binding.go index 0556e81a004..c9118c62f29 100644 --- a/google-beta/services/gemini/resource_gemini_gemini_gcp_enablement_setting_binding.go +++ b/google-beta/services/gemini/resource_gemini_gemini_gcp_enablement_setting_binding.go @@ -116,6 +116,7 @@ func ResourceGeminiGeminiGcpEnablementSettingBinding() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -219,6 +220,18 @@ Format:projects/{project}/locations/{location}/geminiGcpEnablementSettings/{sett Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -380,6 +393,19 @@ func resourceGeminiGeminiGcpEnablementSettingBindingRead(d *schema.ResourceData, log.Printf("[DEBUG] Finished reading GeminiGeminiGcpEnablementSettingBinding %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading GeminiGcpEnablementSettingBinding: %s", err) } @@ -423,6 +449,19 @@ func resourceGeminiGeminiGcpEnablementSettingBindingRead(d *schema.ResourceData, } func resourceGeminiGeminiGcpEnablementSettingBindingUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceGeminiGeminiGcpEnablementSettingBinding().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceGeminiGeminiGcpEnablementSettingBindingRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -553,6 +592,13 @@ func resourceGeminiGeminiGcpEnablementSettingBindingUpdate(d *schema.ResourceDat } func resourceGeminiGeminiGcpEnablementSettingBindingDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy GeminiGeminiGcpEnablementSettingBinding without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing GeminiGcpEnablementSettingBinding %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/gemini/resource_gemini_gemini_gcp_enablement_setting_binding_generated_meta.yaml b/google-beta/services/gemini/resource_gemini_gemini_gcp_enablement_setting_binding_generated_meta.yaml index 221dee6e2d8..3eb687f4782 100644 --- a/google-beta/services/gemini/resource_gemini_gemini_gcp_enablement_setting_binding_generated_meta.yaml +++ b/google-beta/services/gemini/resource_gemini_gemini_gcp_enablement_setting_binding_generated_meta.yaml @@ -26,3 +26,5 @@ fields: - field: terraform_labels provider_only: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/gemini/resource_gemini_gemini_gcp_enablement_setting_generated_meta.yaml b/google-beta/services/gemini/resource_gemini_gemini_gcp_enablement_setting_generated_meta.yaml index 0c22b7ad19d..072729f4cb6 100644 --- a/google-beta/services/gemini/resource_gemini_gemini_gcp_enablement_setting_generated_meta.yaml +++ b/google-beta/services/gemini/resource_gemini_gemini_gcp_enablement_setting_generated_meta.yaml @@ -23,3 +23,5 @@ fields: provider_only: true - api_field: updateTime - api_field: webGroundingType + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/gemini/resource_gemini_logging_setting.go b/google-beta/services/gemini/resource_gemini_logging_setting.go index 8d336107d41..1abcb23687e 100644 --- a/google-beta/services/gemini/resource_gemini_logging_setting.go +++ b/google-beta/services/gemini/resource_gemini_logging_setting.go @@ -116,6 +116,7 @@ func ResourceGeminiLoggingSetting() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -208,6 +209,18 @@ Format:projects/{project}/locations/{location}/loggingsettings/{loggingsetting}` Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -354,6 +367,19 @@ func resourceGeminiLoggingSettingRead(d *schema.ResourceData, meta interface{}) log.Printf("[DEBUG] Finished reading GeminiLoggingSetting %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading LoggingSetting: %s", err) } @@ -391,6 +417,19 @@ func resourceGeminiLoggingSettingRead(d *schema.ResourceData, meta interface{}) } func resourceGeminiLoggingSettingUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceGeminiLoggingSetting().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceGeminiLoggingSettingRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -509,6 +548,13 @@ func resourceGeminiLoggingSettingUpdate(d *schema.ResourceData, meta interface{} } func resourceGeminiLoggingSettingDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy GeminiLoggingSetting without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing LoggingSetting %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/gemini/resource_gemini_logging_setting_binding.go b/google-beta/services/gemini/resource_gemini_logging_setting_binding.go index c128ba44deb..76c1e572834 100644 --- a/google-beta/services/gemini/resource_gemini_logging_setting_binding.go +++ b/google-beta/services/gemini/resource_gemini_logging_setting_binding.go @@ -116,6 +116,7 @@ func ResourceGeminiLoggingSettingBinding() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -220,6 +221,18 @@ Format:projects/{project}/locations/{location}/loggingSettings/{setting}/setting Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -381,6 +394,19 @@ func resourceGeminiLoggingSettingBindingRead(d *schema.ResourceData, meta interf log.Printf("[DEBUG] Finished reading GeminiLoggingSettingBinding %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading LoggingSettingBinding: %s", err) } @@ -424,6 +450,19 @@ func resourceGeminiLoggingSettingBindingRead(d *schema.ResourceData, meta interf } func resourceGeminiLoggingSettingBindingUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceGeminiLoggingSettingBinding().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceGeminiLoggingSettingBindingRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -554,6 +593,13 @@ func resourceGeminiLoggingSettingBindingUpdate(d *schema.ResourceData, meta inte } func resourceGeminiLoggingSettingBindingDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy GeminiLoggingSettingBinding without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing LoggingSettingBinding %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/gemini/resource_gemini_logging_setting_binding_generated_meta.yaml b/google-beta/services/gemini/resource_gemini_logging_setting_binding_generated_meta.yaml index 2328ecee407..cccc44129a6 100644 --- a/google-beta/services/gemini/resource_gemini_logging_setting_binding_generated_meta.yaml +++ b/google-beta/services/gemini/resource_gemini_logging_setting_binding_generated_meta.yaml @@ -26,3 +26,5 @@ fields: - field: terraform_labels provider_only: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/gemini/resource_gemini_logging_setting_generated_meta.yaml b/google-beta/services/gemini/resource_gemini_logging_setting_generated_meta.yaml index 0fefe3e7bf9..1473c43af3c 100644 --- a/google-beta/services/gemini/resource_gemini_logging_setting_generated_meta.yaml +++ b/google-beta/services/gemini/resource_gemini_logging_setting_generated_meta.yaml @@ -22,3 +22,5 @@ fields: - field: terraform_labels provider_only: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/gemini/resource_gemini_release_channel_setting.go b/google-beta/services/gemini/resource_gemini_release_channel_setting.go index 258373240a8..5406ee6d037 100644 --- a/google-beta/services/gemini/resource_gemini_release_channel_setting.go +++ b/google-beta/services/gemini/resource_gemini_release_channel_setting.go @@ -116,6 +116,7 @@ func ResourceGeminiReleaseChannelSetting() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -206,6 +207,18 @@ Format:projects/{project}/locations/{location}/releaseChannelSettings/{releaseCh Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -346,6 +359,19 @@ func resourceGeminiReleaseChannelSettingRead(d *schema.ResourceData, meta interf log.Printf("[DEBUG] Finished reading GeminiReleaseChannelSetting %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading ReleaseChannelSetting: %s", err) } @@ -383,6 +409,19 @@ func resourceGeminiReleaseChannelSettingRead(d *schema.ResourceData, meta interf } func resourceGeminiReleaseChannelSettingUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceGeminiReleaseChannelSetting().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceGeminiReleaseChannelSettingRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -491,6 +530,13 @@ func resourceGeminiReleaseChannelSettingUpdate(d *schema.ResourceData, meta inte } func resourceGeminiReleaseChannelSettingDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy GeminiReleaseChannelSetting without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing ReleaseChannelSetting %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/gemini/resource_gemini_release_channel_setting_binding.go b/google-beta/services/gemini/resource_gemini_release_channel_setting_binding.go index 538d6ac62a1..ae2943386cd 100644 --- a/google-beta/services/gemini/resource_gemini_release_channel_setting_binding.go +++ b/google-beta/services/gemini/resource_gemini_release_channel_setting_binding.go @@ -116,6 +116,7 @@ func ResourceGeminiReleaseChannelSettingBinding() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -220,6 +221,18 @@ Format:projects/{project}/locations/{location}/releaseChannelSettings/{setting}/ Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -381,6 +394,19 @@ func resourceGeminiReleaseChannelSettingBindingRead(d *schema.ResourceData, meta log.Printf("[DEBUG] Finished reading GeminiReleaseChannelSettingBinding %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading ReleaseChannelSettingBinding: %s", err) } @@ -424,6 +450,19 @@ func resourceGeminiReleaseChannelSettingBindingRead(d *schema.ResourceData, meta } func resourceGeminiReleaseChannelSettingBindingUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceGeminiReleaseChannelSettingBinding().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceGeminiReleaseChannelSettingBindingRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -554,6 +593,13 @@ func resourceGeminiReleaseChannelSettingBindingUpdate(d *schema.ResourceData, me } func resourceGeminiReleaseChannelSettingBindingDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy GeminiReleaseChannelSettingBinding without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing ReleaseChannelSettingBinding %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/gemini/resource_gemini_release_channel_setting_binding_generated_meta.yaml b/google-beta/services/gemini/resource_gemini_release_channel_setting_binding_generated_meta.yaml index 1d4c97016f4..48f4f065ac8 100644 --- a/google-beta/services/gemini/resource_gemini_release_channel_setting_binding_generated_meta.yaml +++ b/google-beta/services/gemini/resource_gemini_release_channel_setting_binding_generated_meta.yaml @@ -26,3 +26,5 @@ fields: - field: terraform_labels provider_only: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/gemini/resource_gemini_release_channel_setting_generated_meta.yaml b/google-beta/services/gemini/resource_gemini_release_channel_setting_generated_meta.yaml index e4399283c0a..6b4fd97a92b 100644 --- a/google-beta/services/gemini/resource_gemini_release_channel_setting_generated_meta.yaml +++ b/google-beta/services/gemini/resource_gemini_release_channel_setting_generated_meta.yaml @@ -21,3 +21,5 @@ fields: - field: terraform_labels provider_only: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/gemini/resource_gemini_repository_group.go b/google-beta/services/gemini/resource_gemini_repository_group.go index bd01c30889e..df24e1d19cc 100644 --- a/google-beta/services/gemini/resource_gemini_repository_group.go +++ b/google-beta/services/gemini/resource_gemini_repository_group.go @@ -116,6 +116,7 @@ func ResourceGeminiRepositoryGroup() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -228,6 +229,18 @@ Please refer to the field 'effective_labels' for all of the labels present on th Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -385,6 +398,19 @@ func resourceGeminiRepositoryGroupRead(d *schema.ResourceData, meta interface{}) log.Printf("[DEBUG] Finished reading GeminiRepositoryGroup %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading RepositoryGroup: %s", err) } @@ -428,6 +454,19 @@ func resourceGeminiRepositoryGroupRead(d *schema.ResourceData, meta interface{}) } func resourceGeminiRepositoryGroupUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceGeminiRepositoryGroup().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceGeminiRepositoryGroupRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -549,6 +588,13 @@ func resourceGeminiRepositoryGroupUpdate(d *schema.ResourceData, meta interface{ } func resourceGeminiRepositoryGroupDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy GeminiRepositoryGroup without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing RepositoryGroup %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/gemini/resource_gemini_repository_group_generated_meta.yaml b/google-beta/services/gemini/resource_gemini_repository_group_generated_meta.yaml index a9d27e89d07..a5f81fd72db 100644 --- a/google-beta/services/gemini/resource_gemini_repository_group_generated_meta.yaml +++ b/google-beta/services/gemini/resource_gemini_repository_group_generated_meta.yaml @@ -23,3 +23,5 @@ fields: - field: terraform_labels provider_only: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/gkebackup/resource_gke_backup_backup_channel.go b/google-beta/services/gkebackup/resource_gke_backup_backup_channel.go index 3347a1c0134..0a3fc43c87b 100644 --- a/google-beta/services/gkebackup/resource_gke_backup_backup_channel.go +++ b/google-beta/services/gkebackup/resource_gke_backup_backup_channel.go @@ -116,6 +116,7 @@ func ResourceGKEBackupBackupChannel() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -219,6 +220,18 @@ backupChannels.delete to ensure that their change will be applied to the same ve Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -374,6 +387,19 @@ func resourceGKEBackupBackupChannelRead(d *schema.ResourceData, meta interface{} log.Printf("[DEBUG] Finished reading GKEBackupBackupChannel %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading BackupChannel: %s", err) } @@ -411,6 +437,19 @@ func resourceGKEBackupBackupChannelRead(d *schema.ResourceData, meta interface{} } func resourceGKEBackupBackupChannelUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceGKEBackupBackupChannel().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceGKEBackupBackupChannelRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -519,6 +558,13 @@ func resourceGKEBackupBackupChannelUpdate(d *schema.ResourceData, meta interface } func resourceGKEBackupBackupChannelDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy GKEBackupBackupChannel without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing BackupChannel %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/gkebackup/resource_gke_backup_backup_channel_generated_meta.yaml b/google-beta/services/gkebackup/resource_gke_backup_backup_channel_generated_meta.yaml index 341d4c9babe..45150062362 100644 --- a/google-beta/services/gkebackup/resource_gke_backup_backup_channel_generated_meta.yaml +++ b/google-beta/services/gkebackup/resource_gke_backup_backup_channel_generated_meta.yaml @@ -20,3 +20,5 @@ fields: - field: terraform_labels provider_only: true - api_field: uid + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/gkebackup/resource_gke_backup_backup_plan.go b/google-beta/services/gkebackup/resource_gke_backup_backup_plan.go index 1d7ea875d62..7e0e0462f9d 100644 --- a/google-beta/services/gkebackup/resource_gke_backup_backup_plan.go +++ b/google-beta/services/gkebackup/resource_gke_backup_backup_plan.go @@ -116,6 +116,7 @@ func ResourceGKEBackupBackupPlan() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -573,6 +574,18 @@ backupPlans.delete to ensure that their change will be applied to the same versi Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -752,6 +765,19 @@ func resourceGKEBackupBackupPlanRead(d *schema.ResourceData, meta interface{}) e log.Printf("[DEBUG] Finished reading GKEBackupBackupPlan %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading BackupPlan: %s", err) } @@ -789,6 +815,19 @@ func resourceGKEBackupBackupPlanRead(d *schema.ResourceData, meta interface{}) e } func resourceGKEBackupBackupPlanUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceGKEBackupBackupPlan().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceGKEBackupBackupPlanRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -937,6 +976,13 @@ func resourceGKEBackupBackupPlanUpdate(d *schema.ResourceData, meta interface{}) } func resourceGKEBackupBackupPlanDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy GKEBackupBackupPlan without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing BackupPlan %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/gkebackup/resource_gke_backup_backup_plan_generated_meta.yaml b/google-beta/services/gkebackup/resource_gke_backup_backup_plan_generated_meta.yaml index eb0cc2a7363..56479f9e2a2 100644 --- a/google-beta/services/gkebackup/resource_gke_backup_backup_plan_generated_meta.yaml +++ b/google-beta/services/gkebackup/resource_gke_backup_backup_plan_generated_meta.yaml @@ -50,3 +50,5 @@ fields: - field: terraform_labels provider_only: true - api_field: uid + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/gkebackup/resource_gke_backup_restore_channel.go b/google-beta/services/gkebackup/resource_gke_backup_restore_channel.go index 288eee481b7..d400b42d38e 100644 --- a/google-beta/services/gkebackup/resource_gke_backup_restore_channel.go +++ b/google-beta/services/gkebackup/resource_gke_backup_restore_channel.go @@ -116,6 +116,7 @@ func ResourceGKEBackupRestoreChannel() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -219,6 +220,18 @@ restoreChannels.delete to ensure that their change will be applied to the same v Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -374,6 +387,19 @@ func resourceGKEBackupRestoreChannelRead(d *schema.ResourceData, meta interface{ log.Printf("[DEBUG] Finished reading GKEBackupRestoreChannel %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading RestoreChannel: %s", err) } @@ -411,6 +437,19 @@ func resourceGKEBackupRestoreChannelRead(d *schema.ResourceData, meta interface{ } func resourceGKEBackupRestoreChannelUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceGKEBackupRestoreChannel().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceGKEBackupRestoreChannelRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -519,6 +558,13 @@ func resourceGKEBackupRestoreChannelUpdate(d *schema.ResourceData, meta interfac } func resourceGKEBackupRestoreChannelDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy GKEBackupRestoreChannel without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing RestoreChannel %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/gkebackup/resource_gke_backup_restore_channel_generated_meta.yaml b/google-beta/services/gkebackup/resource_gke_backup_restore_channel_generated_meta.yaml index e6527fbfd0d..573a618c819 100644 --- a/google-beta/services/gkebackup/resource_gke_backup_restore_channel_generated_meta.yaml +++ b/google-beta/services/gkebackup/resource_gke_backup_restore_channel_generated_meta.yaml @@ -20,3 +20,5 @@ fields: - field: terraform_labels provider_only: true - api_field: uid + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/gkebackup/resource_gke_backup_restore_plan.go b/google-beta/services/gkebackup/resource_gke_backup_restore_plan.go index 85b060ad526..e69a54a98eb 100644 --- a/google-beta/services/gkebackup/resource_gke_backup_restore_plan.go +++ b/google-beta/services/gkebackup/resource_gke_backup_restore_plan.go @@ -116,6 +116,7 @@ func ResourceGKEBackupRestorePlan() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -633,6 +634,18 @@ Please refer to the field 'effective_labels' for all of the labels present on th Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -800,6 +813,19 @@ func resourceGKEBackupRestorePlanRead(d *schema.ResourceData, meta interface{}) log.Printf("[DEBUG] Finished reading GKEBackupRestorePlan %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading RestorePlan: %s", err) } @@ -837,6 +863,19 @@ func resourceGKEBackupRestorePlanRead(d *schema.ResourceData, meta interface{}) } func resourceGKEBackupRestorePlanUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceGKEBackupRestorePlan().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceGKEBackupRestorePlanRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -955,6 +994,13 @@ func resourceGKEBackupRestorePlanUpdate(d *schema.ResourceData, meta interface{} } func resourceGKEBackupRestorePlanDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy GKEBackupRestorePlan without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing RestorePlan %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/gkebackup/resource_gke_backup_restore_plan_generated_meta.yaml b/google-beta/services/gkebackup/resource_gke_backup_restore_plan_generated_meta.yaml index 7d2ccbbdf8d..a162c57b5d7 100644 --- a/google-beta/services/gkebackup/resource_gke_backup_restore_plan_generated_meta.yaml +++ b/google-beta/services/gkebackup/resource_gke_backup_restore_plan_generated_meta.yaml @@ -51,3 +51,5 @@ fields: - field: terraform_labels provider_only: true - api_field: uid + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/gkehub/resource_gke_hub_feature_membership.go b/google-beta/services/gkehub/resource_gke_hub_feature_membership.go index 35658e96da9..e76fc1056e6 100644 --- a/google-beta/services/gkehub/resource_gke_hub_feature_membership.go +++ b/google-beta/services/gkehub/resource_gke_hub_feature_membership.go @@ -111,6 +111,9 @@ func ResourceGkeHubFeatureMembership() *schema.Resource { DiffSuppressFunc: tpgresource.CompareSelfLinkOrResourceName, Description: "The project of the feature", }, + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end }, } } @@ -907,9 +910,18 @@ func resourceGkeHubFeatureMembershipRead(d *schema.ResourceData, meta interface{ return fmt.Errorf("error setting project in state: %s", err) } + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + return nil } func resourceGkeHubFeatureMembershipUpdate(d *schema.ResourceData, meta interface{}) error { + + if tpgresource.DeletionPolicyPreUpdate(d, ResourceGkeHubFeatureMembership) { + return ResourceGkeHubFeatureMembership().Read(d, meta) + } + config := meta.(*transport_tpg.Config) project, err := tpgresource.GetProject(d, config) if err != nil { @@ -967,6 +979,13 @@ func resourceGkeHubFeatureMembershipUpdate(d *schema.ResourceData, meta interfac } func resourceGkeHubFeatureMembershipDelete(d *schema.ResourceData, meta interface{}) error { + + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { + return nil + } + config := meta.(*transport_tpg.Config) project, err := tpgresource.GetProject(d, config) if err != nil { diff --git a/google-beta/services/gkehub/resource_gke_hub_feature_membership_meta.yaml b/google-beta/services/gkehub/resource_gke_hub_feature_membership_meta.yaml index b7f398bac7f..2b6b983882b 100644 --- a/google-beta/services/gkehub/resource_gke_hub_feature_membership_meta.yaml +++ b/google-beta/services/gkehub/resource_gke_hub_feature_membership_meta.yaml @@ -74,3 +74,5 @@ fields: - field: 'policycontroller.policy_controller_hub_config.referential_rules_enabled' - field: 'policycontroller.version' - field: 'project' + - field: 'deletion_policy' + provider_only: true diff --git a/google-beta/services/gkehub/resource_gke_hub_membership.go b/google-beta/services/gkehub/resource_gke_hub_membership.go index eab5389aec1..b2220f515ae 100644 --- a/google-beta/services/gkehub/resource_gke_hub_membership.go +++ b/google-beta/services/gkehub/resource_gke_hub_membership.go @@ -135,6 +135,7 @@ func ResourceGKEHubMembership() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -261,6 +262,18 @@ The default value is 'global'.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -410,6 +423,19 @@ func resourceGKEHubMembershipRead(d *schema.ResourceData, meta interface{}) erro log.Printf("[DEBUG] Finished reading GKEHubMembership %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Membership: %s", err) } @@ -447,6 +473,19 @@ func resourceGKEHubMembershipRead(d *schema.ResourceData, meta interface{}) erro } func resourceGKEHubMembershipUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceGKEHubMembership().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceGKEHubMembershipRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -555,6 +594,13 @@ func resourceGKEHubMembershipUpdate(d *schema.ResourceData, meta interface{}) er } func resourceGKEHubMembershipDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy GKEHubMembership without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Membership %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/gkehub/resource_gke_hub_membership_generated_meta.yaml b/google-beta/services/gkehub/resource_gke_hub_membership_generated_meta.yaml index 3f7c477a849..96d366ddb31 100644 --- a/google-beta/services/gkehub/resource_gke_hub_membership_generated_meta.yaml +++ b/google-beta/services/gkehub/resource_gke_hub_membership_generated_meta.yaml @@ -19,3 +19,5 @@ fields: - api_field: name - field: terraform_labels provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/gkehub2/resource_gke_hub_feature.go b/google-beta/services/gkehub2/resource_gke_hub_feature.go index 13e444681ca..d4ba55fa04c 100644 --- a/google-beta/services/gkehub2/resource_gke_hub_feature.go +++ b/google-beta/services/gkehub2/resource_gke_hub_feature.go @@ -116,6 +116,7 @@ func ResourceGKEHub2Feature() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -847,6 +848,18 @@ Please refer to the field 'effective_labels' for all of the labels present on th Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -1021,6 +1034,19 @@ func resourceGKEHub2FeatureRead(d *schema.ResourceData, meta interface{}) error log.Printf("[DEBUG] Finished reading GKEHub2Feature %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Feature: %s", err) } @@ -1058,6 +1084,19 @@ func resourceGKEHub2FeatureRead(d *schema.ResourceData, meta interface{}) error } func resourceGKEHub2FeatureUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceGKEHub2Feature().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceGKEHub2FeatureRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1176,6 +1215,13 @@ func resourceGKEHub2FeatureUpdate(d *schema.ResourceData, meta interface{}) erro } func resourceGKEHub2FeatureDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy GKEHub2Feature without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Feature %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/gkehub2/resource_gke_hub_feature_generated_meta.yaml b/google-beta/services/gkehub2/resource_gke_hub_feature_generated_meta.yaml index 973805b7f2d..fdb6c4932d8 100644 --- a/google-beta/services/gkehub2/resource_gke_hub_feature_generated_meta.yaml +++ b/google-beta/services/gkehub2/resource_gke_hub_feature_generated_meta.yaml @@ -91,3 +91,5 @@ fields: - field: terraform_labels provider_only: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/gkehub2/resource_gke_hub_fleet.go b/google-beta/services/gkehub2/resource_gke_hub_fleet.go index 70a336198d1..09b2ce5ecd3 100644 --- a/google-beta/services/gkehub2/resource_gke_hub_fleet.go +++ b/google-beta/services/gkehub2/resource_gke_hub_fleet.go @@ -115,6 +115,7 @@ func ResourceGKEHub2Fleet() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -245,6 +246,18 @@ resource with the same name is created, it gets a different uid.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -378,6 +391,19 @@ func resourceGKEHub2FleetRead(d *schema.ResourceData, meta interface{}) error { log.Printf("[DEBUG] Finished reading GKEHub2Fleet %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Fleet: %s", err) } @@ -403,6 +429,19 @@ func resourceGKEHub2FleetRead(d *schema.ResourceData, meta interface{}) error { } func resourceGKEHub2FleetUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceGKEHub2Fleet().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceGKEHub2FleetRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -501,6 +540,13 @@ func resourceGKEHub2FleetUpdate(d *schema.ResourceData, meta interface{}) error } func resourceGKEHub2FleetDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy GKEHub2Fleet without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Fleet %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/gkehub2/resource_gke_hub_fleet_generated_meta.yaml b/google-beta/services/gkehub2/resource_gke_hub_fleet_generated_meta.yaml index 5aa85204b3d..8f7d2e1de1a 100644 --- a/google-beta/services/gkehub2/resource_gke_hub_fleet_generated_meta.yaml +++ b/google-beta/services/gkehub2/resource_gke_hub_fleet_generated_meta.yaml @@ -17,3 +17,5 @@ fields: - api_field: state.code - api_field: uid - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/gkehub2/resource_gke_hub_membership_binding.go b/google-beta/services/gkehub2/resource_gke_hub_membership_binding.go index 8bf490e75b3..9da23a753d7 100644 --- a/google-beta/services/gkehub2/resource_gke_hub_membership_binding.go +++ b/google-beta/services/gkehub2/resource_gke_hub_membership_binding.go @@ -116,6 +116,7 @@ func ResourceGKEHub2MembershipBinding() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -239,6 +240,18 @@ Please refer to the field 'effective_labels' for all of the labels present on th Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -387,6 +400,19 @@ func resourceGKEHub2MembershipBindingRead(d *schema.ResourceData, meta interface log.Printf("[DEBUG] Finished reading GKEHub2MembershipBinding %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading MembershipBinding: %s", err) } @@ -430,6 +456,19 @@ func resourceGKEHub2MembershipBindingRead(d *schema.ResourceData, meta interface } func resourceGKEHub2MembershipBindingUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceGKEHub2MembershipBinding().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceGKEHub2MembershipBindingRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -543,6 +582,13 @@ func resourceGKEHub2MembershipBindingUpdate(d *schema.ResourceData, meta interfa } func resourceGKEHub2MembershipBindingDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy GKEHub2MembershipBinding without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing MembershipBinding %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/gkehub2/resource_gke_hub_membership_binding_generated_meta.yaml b/google-beta/services/gkehub2/resource_gke_hub_membership_binding_generated_meta.yaml index 24cea538b3c..1f4fd86e07a 100644 --- a/google-beta/services/gkehub2/resource_gke_hub_membership_binding_generated_meta.yaml +++ b/google-beta/services/gkehub2/resource_gke_hub_membership_binding_generated_meta.yaml @@ -25,3 +25,5 @@ fields: provider_only: true - api_field: uid - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/gkehub2/resource_gke_hub_membership_rbac_role_binding.go b/google-beta/services/gkehub2/resource_gke_hub_membership_rbac_role_binding.go index de0a98d0e4f..12d54c2c744 100644 --- a/google-beta/services/gkehub2/resource_gke_hub_membership_rbac_role_binding.go +++ b/google-beta/services/gkehub2/resource_gke_hub_membership_rbac_role_binding.go @@ -100,6 +100,7 @@ func ResourceGKEHub2MembershipRBACRoleBinding() *schema.Resource { return &schema.Resource{ Create: resourceGKEHub2MembershipRBACRoleBindingCreate, Read: resourceGKEHub2MembershipRBACRoleBindingRead, + Update: resourceGKEHub2MembershipRBACRoleBindingUpdate, Delete: resourceGKEHub2MembershipRBACRoleBindingDelete, Importer: &schema.ResourceImporter{ @@ -113,6 +114,7 @@ func ResourceGKEHub2MembershipRBACRoleBinding() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -233,6 +235,18 @@ user is the name of the user as seen by the kubernetes cluster, example Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -381,6 +395,19 @@ func resourceGKEHub2MembershipRBACRoleBindingRead(d *schema.ResourceData, meta i log.Printf("[DEBUG] Finished reading GKEHub2MembershipRBACRoleBinding %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading MembershipRBACRoleBinding: %s", err) } @@ -423,7 +450,19 @@ func resourceGKEHub2MembershipRBACRoleBindingRead(d *schema.ResourceData, meta i return nil } +func resourceGKEHub2MembershipRBACRoleBindingUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceGKEHub2MembershipRBACRoleBindingRead(d, meta) +} + func resourceGKEHub2MembershipRBACRoleBindingDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy GKEHub2MembershipRBACRoleBinding without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing MembershipRBACRoleBinding %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/gkehub2/resource_gke_hub_membership_rbac_role_binding_generated_meta.yaml b/google-beta/services/gkehub2/resource_gke_hub_membership_rbac_role_binding_generated_meta.yaml index 4cd69b1469b..56024f4e6ba 100644 --- a/google-beta/services/gkehub2/resource_gke_hub_membership_rbac_role_binding_generated_meta.yaml +++ b/google-beta/services/gkehub2/resource_gke_hub_membership_rbac_role_binding_generated_meta.yaml @@ -21,3 +21,5 @@ fields: - api_field: uid - api_field: updateTime - api_field: user + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/gkehub2/resource_gke_hub_namespace.go b/google-beta/services/gkehub2/resource_gke_hub_namespace.go index 18700c1bc2b..d92859552c8 100644 --- a/google-beta/services/gkehub2/resource_gke_hub_namespace.go +++ b/google-beta/services/gkehub2/resource_gke_hub_namespace.go @@ -116,6 +116,7 @@ func ResourceGKEHub2Namespace() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -239,6 +240,18 @@ a key. Keys and values must be Kubernetes-conformant.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -388,6 +401,19 @@ func resourceGKEHub2NamespaceRead(d *schema.ResourceData, meta interface{}) erro log.Printf("[DEBUG] Finished reading GKEHub2Namespace %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Namespace: %s", err) } @@ -425,6 +451,19 @@ func resourceGKEHub2NamespaceRead(d *schema.ResourceData, meta interface{}) erro } func resourceGKEHub2NamespaceUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceGKEHub2Namespace().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceGKEHub2NamespaceRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -533,6 +572,13 @@ func resourceGKEHub2NamespaceUpdate(d *schema.ResourceData, meta interface{}) er } func resourceGKEHub2NamespaceDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy GKEHub2Namespace without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Namespace %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/gkehub2/resource_gke_hub_namespace_generated_meta.yaml b/google-beta/services/gkehub2/resource_gke_hub_namespace_generated_meta.yaml index ef7b122b103..a100e2301a8 100644 --- a/google-beta/services/gkehub2/resource_gke_hub_namespace_generated_meta.yaml +++ b/google-beta/services/gkehub2/resource_gke_hub_namespace_generated_meta.yaml @@ -24,3 +24,5 @@ fields: provider_only: true - api_field: uid - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/gkehub2/resource_gke_hub_rollout_sequence.go b/google-beta/services/gkehub2/resource_gke_hub_rollout_sequence.go index a1c3481efa3..cdd35cc39d6 100644 --- a/google-beta/services/gkehub2/resource_gke_hub_rollout_sequence.go +++ b/google-beta/services/gkehub2/resource_gke_hub_rollout_sequence.go @@ -116,6 +116,7 @@ func ResourceGKEHub2RolloutSequence() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -303,6 +304,18 @@ Please refer to the field 'effective_labels' for all of the labels present on th Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -459,6 +472,19 @@ func resourceGKEHub2RolloutSequenceRead(d *schema.ResourceData, meta interface{} log.Printf("[DEBUG] Finished reading GKEHub2RolloutSequence %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading RolloutSequence: %s", err) } @@ -490,6 +516,19 @@ func resourceGKEHub2RolloutSequenceRead(d *schema.ResourceData, meta interface{} } func resourceGKEHub2RolloutSequenceUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceGKEHub2RolloutSequence().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceGKEHub2RolloutSequenceRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -623,6 +662,13 @@ func resourceGKEHub2RolloutSequenceUpdate(d *schema.ResourceData, meta interface } func resourceGKEHub2RolloutSequenceDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy GKEHub2RolloutSequence without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing RolloutSequence %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/gkehub2/resource_gke_hub_rollout_sequence_generated_meta.yaml b/google-beta/services/gkehub2/resource_gke_hub_rollout_sequence_generated_meta.yaml index bb9427f6e12..1272c45d639 100644 --- a/google-beta/services/gkehub2/resource_gke_hub_rollout_sequence_generated_meta.yaml +++ b/google-beta/services/gkehub2/resource_gke_hub_rollout_sequence_generated_meta.yaml @@ -26,3 +26,5 @@ fields: provider_only: true - api_field: uid - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/gkehub2/resource_gke_hub_scope.go b/google-beta/services/gkehub2/resource_gke_hub_scope.go index 0ec12ca4c84..a5a93614f7d 100644 --- a/google-beta/services/gkehub2/resource_gke_hub_scope.go +++ b/google-beta/services/gkehub2/resource_gke_hub_scope.go @@ -116,6 +116,7 @@ func ResourceGKEHub2Scope() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -222,6 +223,18 @@ share a key. Keys and values must be Kubernetes-conformant.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -360,6 +373,19 @@ func resourceGKEHub2ScopeRead(d *schema.ResourceData, meta interface{}) error { log.Printf("[DEBUG] Finished reading GKEHub2Scope %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Scope: %s", err) } @@ -391,6 +417,19 @@ func resourceGKEHub2ScopeRead(d *schema.ResourceData, meta interface{}) error { } func resourceGKEHub2ScopeUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceGKEHub2Scope().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceGKEHub2ScopeRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -494,6 +533,13 @@ func resourceGKEHub2ScopeUpdate(d *schema.ResourceData, meta interface{}) error } func resourceGKEHub2ScopeDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy GKEHub2Scope without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Scope %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/gkehub2/resource_gke_hub_scope_generated_meta.yaml b/google-beta/services/gkehub2/resource_gke_hub_scope_generated_meta.yaml index 038040f3e71..5a9a9cb8770 100644 --- a/google-beta/services/gkehub2/resource_gke_hub_scope_generated_meta.yaml +++ b/google-beta/services/gkehub2/resource_gke_hub_scope_generated_meta.yaml @@ -21,3 +21,5 @@ fields: provider_only: true - api_field: uid - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/gkehub2/resource_gke_hub_scope_rbac_role_binding.go b/google-beta/services/gkehub2/resource_gke_hub_scope_rbac_role_binding.go index 362c07e8f6e..7422f834a4d 100644 --- a/google-beta/services/gkehub2/resource_gke_hub_scope_rbac_role_binding.go +++ b/google-beta/services/gkehub2/resource_gke_hub_scope_rbac_role_binding.go @@ -116,6 +116,7 @@ func ResourceGKEHub2ScopeRBACRoleBinding() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -262,6 +263,18 @@ user is the name of the user as seen by the kubernetes cluster, example Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -417,6 +430,19 @@ func resourceGKEHub2ScopeRBACRoleBindingRead(d *schema.ResourceData, meta interf log.Printf("[DEBUG] Finished reading GKEHub2ScopeRBACRoleBinding %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading ScopeRBACRoleBinding: %s", err) } @@ -454,6 +480,19 @@ func resourceGKEHub2ScopeRBACRoleBindingRead(d *schema.ResourceData, meta interf } func resourceGKEHub2ScopeRBACRoleBindingUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceGKEHub2ScopeRBACRoleBinding().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceGKEHub2ScopeRBACRoleBindingRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -582,6 +621,13 @@ func resourceGKEHub2ScopeRBACRoleBindingUpdate(d *schema.ResourceData, meta inte } func resourceGKEHub2ScopeRBACRoleBindingDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy GKEHub2ScopeRBACRoleBinding without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing ScopeRBACRoleBinding %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/gkehub2/resource_gke_hub_scope_rbac_role_binding_generated_meta.yaml b/google-beta/services/gkehub2/resource_gke_hub_scope_rbac_role_binding_generated_meta.yaml index 59ba08ef58b..0f4f1102664 100644 --- a/google-beta/services/gkehub2/resource_gke_hub_scope_rbac_role_binding_generated_meta.yaml +++ b/google-beta/services/gkehub2/resource_gke_hub_scope_rbac_role_binding_generated_meta.yaml @@ -26,3 +26,5 @@ fields: - api_field: uid - api_field: updateTime - api_field: user + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/gkeonprem/resource_gkeonprem_bare_metal_admin_cluster.go b/google-beta/services/gkeonprem/resource_gkeonprem_bare_metal_admin_cluster.go index d8b41c54b7e..fcc37e2a785 100644 --- a/google-beta/services/gkeonprem/resource_gkeonprem_bare_metal_admin_cluster.go +++ b/google-beta/services/gkeonprem/resource_gkeonprem_bare_metal_admin_cluster.go @@ -1254,6 +1254,7 @@ func resourceGkeonpremBareMetalAdminClusterRead(d *schema.ResourceData, meta int } func resourceGkeonpremBareMetalAdminClusterUpdate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/gkeonprem/resource_gkeonprem_bare_metal_cluster.go b/google-beta/services/gkeonprem/resource_gkeonprem_bare_metal_cluster.go index a224defb784..773da441c84 100644 --- a/google-beta/services/gkeonprem/resource_gkeonprem_bare_metal_cluster.go +++ b/google-beta/services/gkeonprem/resource_gkeonprem_bare_metal_cluster.go @@ -116,6 +116,7 @@ func ResourceGkeonpremBareMetalCluster() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetAnnotationsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -1288,6 +1289,18 @@ indicate real problems requiring user intervention.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -1520,6 +1533,19 @@ func resourceGkeonpremBareMetalClusterRead(d *schema.ResourceData, meta interfac log.Printf("[DEBUG] Finished reading GkeonpremBareMetalCluster %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading BareMetalCluster: %s", err) } @@ -1557,6 +1583,19 @@ func resourceGkeonpremBareMetalClusterRead(d *schema.ResourceData, meta interfac } func resourceGkeonpremBareMetalClusterUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceGkeonpremBareMetalCluster().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceGkeonpremBareMetalClusterRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1805,6 +1844,13 @@ func resourceGkeonpremBareMetalClusterUpdate(d *schema.ResourceData, meta interf } func resourceGkeonpremBareMetalClusterDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy GkeonpremBareMetalCluster without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing BareMetalCluster %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/gkeonprem/resource_gkeonprem_bare_metal_cluster_generated_meta.yaml b/google-beta/services/gkeonprem/resource_gkeonprem_bare_metal_cluster_generated_meta.yaml index 8b7ec75af03..3167fbdf009 100644 --- a/google-beta/services/gkeonprem/resource_gkeonprem_bare_metal_cluster_generated_meta.yaml +++ b/google-beta/services/gkeonprem/resource_gkeonprem_bare_metal_cluster_generated_meta.yaml @@ -103,3 +103,5 @@ fields: - api_field: validationCheck.status.result.details - api_field: validationCheck.status.result.options - api_field: validationCheck.status.result.reason + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/gkeonprem/resource_gkeonprem_bare_metal_node_pool.go b/google-beta/services/gkeonprem/resource_gkeonprem_bare_metal_node_pool.go index f8cb821dbc5..e77ee242b84 100644 --- a/google-beta/services/gkeonprem/resource_gkeonprem_bare_metal_node_pool.go +++ b/google-beta/services/gkeonprem/resource_gkeonprem_bare_metal_node_pool.go @@ -116,6 +116,7 @@ func ResourceGkeonpremBareMetalNodePool() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetAnnotationsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -379,6 +380,18 @@ indicate real problems requiring user intervention.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -532,6 +545,19 @@ func resourceGkeonpremBareMetalNodePoolRead(d *schema.ResourceData, meta interfa log.Printf("[DEBUG] Finished reading GkeonpremBareMetalNodePool %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading BareMetalNodePool: %s", err) } @@ -575,6 +601,19 @@ func resourceGkeonpremBareMetalNodePoolRead(d *schema.ResourceData, meta interfa } func resourceGkeonpremBareMetalNodePoolUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceGkeonpremBareMetalNodePool().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceGkeonpremBareMetalNodePoolRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -698,6 +737,13 @@ func resourceGkeonpremBareMetalNodePoolUpdate(d *schema.ResourceData, meta inter } func resourceGkeonpremBareMetalNodePoolDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy GkeonpremBareMetalNodePool without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing BareMetalNodePool %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/gkeonprem/resource_gkeonprem_bare_metal_node_pool_generated_meta.yaml b/google-beta/services/gkeonprem/resource_gkeonprem_bare_metal_node_pool_generated_meta.yaml index 3eaadaa0a63..bbff9f355dd 100644 --- a/google-beta/services/gkeonprem/resource_gkeonprem_bare_metal_node_pool_generated_meta.yaml +++ b/google-beta/services/gkeonprem/resource_gkeonprem_bare_metal_node_pool_generated_meta.yaml @@ -37,3 +37,5 @@ fields: - api_field: status.errorMessage - api_field: uid - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/gkeonprem/resource_gkeonprem_vmware_admin_cluster.go b/google-beta/services/gkeonprem/resource_gkeonprem_vmware_admin_cluster.go index 26e8534fc1a..7a373252be6 100644 --- a/google-beta/services/gkeonprem/resource_gkeonprem_vmware_admin_cluster.go +++ b/google-beta/services/gkeonprem/resource_gkeonprem_vmware_admin_cluster.go @@ -1266,6 +1266,7 @@ func resourceGkeonpremVmwareAdminClusterRead(d *schema.ResourceData, meta interf } func resourceGkeonpremVmwareAdminClusterUpdate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/gkeonprem/resource_gkeonprem_vmware_cluster.go b/google-beta/services/gkeonprem/resource_gkeonprem_vmware_cluster.go index 0c3b2801a16..66cba37782e 100644 --- a/google-beta/services/gkeonprem/resource_gkeonprem_vmware_cluster.go +++ b/google-beta/services/gkeonprem/resource_gkeonprem_vmware_cluster.go @@ -116,6 +116,7 @@ func ResourceGkeonpremVmwareCluster() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetAnnotationsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -1004,6 +1005,18 @@ indicate real problems requiring user intervention.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -1242,6 +1255,19 @@ func resourceGkeonpremVmwareClusterRead(d *schema.ResourceData, meta interface{} log.Printf("[DEBUG] Finished reading GkeonpremVmwareCluster %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading VmwareCluster: %s", err) } @@ -1279,6 +1305,19 @@ func resourceGkeonpremVmwareClusterRead(d *schema.ResourceData, meta interface{} } func resourceGkeonpremVmwareClusterUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceGkeonpremVmwareCluster().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceGkeonpremVmwareClusterRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1537,6 +1576,13 @@ func resourceGkeonpremVmwareClusterUpdate(d *schema.ResourceData, meta interface } func resourceGkeonpremVmwareClusterDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy GkeonpremVmwareCluster without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing VmwareCluster %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/gkeonprem/resource_gkeonprem_vmware_cluster_generated_meta.yaml b/google-beta/services/gkeonprem/resource_gkeonprem_vmware_cluster_generated_meta.yaml index 08e8f903b5f..4d1f1d4f732 100644 --- a/google-beta/services/gkeonprem/resource_gkeonprem_vmware_cluster_generated_meta.yaml +++ b/google-beta/services/gkeonprem/resource_gkeonprem_vmware_cluster_generated_meta.yaml @@ -96,3 +96,5 @@ fields: - api_field: vcenter.resourcePool - api_field: vcenter.storagePolicyName - api_field: vmTrackingEnabled + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/gkeonprem/resource_gkeonprem_vmware_node_pool.go b/google-beta/services/gkeonprem/resource_gkeonprem_vmware_node_pool.go index 5dcc6e5d912..56e5655e4c9 100644 --- a/google-beta/services/gkeonprem/resource_gkeonprem_vmware_node_pool.go +++ b/google-beta/services/gkeonprem/resource_gkeonprem_vmware_node_pool.go @@ -116,6 +116,7 @@ func ResourceGkeonpremVmwareNodePool() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetAnnotationsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -445,6 +446,18 @@ indicate real problems requiring user intervention.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -610,6 +623,19 @@ func resourceGkeonpremVmwareNodePoolRead(d *schema.ResourceData, meta interface{ log.Printf("[DEBUG] Finished reading GkeonpremVmwareNodePool %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading VmwareNodePool: %s", err) } @@ -653,6 +679,19 @@ func resourceGkeonpremVmwareNodePoolRead(d *schema.ResourceData, meta interface{ } func resourceGkeonpremVmwareNodePoolUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceGkeonpremVmwareNodePool().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceGkeonpremVmwareNodePoolRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -796,6 +835,13 @@ func resourceGkeonpremVmwareNodePoolUpdate(d *schema.ResourceData, meta interfac } func resourceGkeonpremVmwareNodePoolDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy GkeonpremVmwareNodePool without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing VmwareNodePool %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/gkeonprem/resource_gkeonprem_vmware_node_pool_generated_meta.yaml b/google-beta/services/gkeonprem/resource_gkeonprem_vmware_node_pool_generated_meta.yaml index 0916655b8a4..293ae80f006 100644 --- a/google-beta/services/gkeonprem/resource_gkeonprem_vmware_node_pool_generated_meta.yaml +++ b/google-beta/services/gkeonprem/resource_gkeonprem_vmware_node_pool_generated_meta.yaml @@ -48,3 +48,5 @@ fields: - api_field: updateTime - field: vmware_cluster provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/healthcare/resource_healthcare_consent_store.go b/google-beta/services/healthcare/resource_healthcare_consent_store.go index d4911705cef..4797f704b45 100644 --- a/google-beta/services/healthcare/resource_healthcare_consent_store.go +++ b/google-beta/services/healthcare/resource_healthcare_consent_store.go @@ -115,6 +115,7 @@ func ResourceHealthcareConsentStore() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -198,6 +199,19 @@ Please refer to the field 'effective_labels' for all of the labels present on th and default labels configured on the provider.`, Elem: &schema.Schema{Type: schema.TypeString}, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -320,6 +334,20 @@ func resourceHealthcareConsentStoreRead(d *schema.ResourceData, meta interface{} log.Printf("[DEBUG] Finished reading HealthcareConsentStore %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceHealthcareConsentStoreFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -347,6 +375,19 @@ func resourceHealthcareConsentStoreRead(d *schema.ResourceData, meta interface{} } func resourceHealthcareConsentStoreUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceHealthcareConsentStore().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceHealthcareConsentStoreRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -447,6 +488,13 @@ func resourceHealthcareConsentStoreUpdate(d *schema.ResourceData, meta interface } func resourceHealthcareConsentStoreDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy HealthcareConsentStore without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing ConsentStore %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/healthcare/resource_healthcare_consent_store_generated_meta.yaml b/google-beta/services/healthcare/resource_healthcare_consent_store_generated_meta.yaml index 88ea15e8f66..b49783810ee 100644 --- a/google-beta/services/healthcare/resource_healthcare_consent_store_generated_meta.yaml +++ b/google-beta/services/healthcare/resource_healthcare_consent_store_generated_meta.yaml @@ -18,3 +18,5 @@ fields: provider_only: true - field: terraform_labels provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/healthcare/resource_healthcare_dataset.go b/google-beta/services/healthcare/resource_healthcare_dataset.go index 4d93061406e..b19aeb8fe14 100644 --- a/google-beta/services/healthcare/resource_healthcare_dataset.go +++ b/google-beta/services/healthcare/resource_healthcare_dataset.go @@ -115,6 +115,7 @@ func ResourceHealthcareDataset() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -193,6 +194,18 @@ projects/{projectId}/locations/{locationId}/keyRings/{keyRingId}/cryptoKeys/{key Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -346,6 +359,19 @@ func resourceHealthcareDatasetRead(d *schema.ResourceData, meta interface{}) err return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Dataset: %s", err) } @@ -383,6 +409,19 @@ func resourceHealthcareDatasetRead(d *schema.ResourceData, meta interface{}) err } func resourceHealthcareDatasetUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceHealthcareDataset().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceHealthcareDatasetRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -475,6 +514,13 @@ func resourceHealthcareDatasetUpdate(d *schema.ResourceData, meta interface{}) e } func resourceHealthcareDatasetDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy HealthcareDataset without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Dataset %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/healthcare/resource_healthcare_dataset_generated_meta.yaml b/google-beta/services/healthcare/resource_healthcare_dataset_generated_meta.yaml index a0287b28bb5..a02ce7608ec 100644 --- a/google-beta/services/healthcare/resource_healthcare_dataset_generated_meta.yaml +++ b/google-beta/services/healthcare/resource_healthcare_dataset_generated_meta.yaml @@ -13,3 +13,5 @@ fields: - api_field: name - api_field: selfLink - api_field: timeZone + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/healthcare/resource_healthcare_dicom_store.go b/google-beta/services/healthcare/resource_healthcare_dicom_store.go index d0826e9ba33..3810d15fedf 100644 --- a/google-beta/services/healthcare/resource_healthcare_dicom_store.go +++ b/google-beta/services/healthcare/resource_healthcare_dicom_store.go @@ -115,6 +115,7 @@ func ResourceHealthcareDicomStore() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -242,6 +243,19 @@ streamConfigs is an array, so you can specify multiple BigQuery destinations. Yo and default labels configured on the provider.`, Elem: &schema.Schema{Type: schema.TypeString}, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -382,6 +396,20 @@ func resourceHealthcareDicomStoreRead(d *schema.ResourceData, meta interface{}) return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceHealthcareDicomStoreFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -409,6 +437,19 @@ func resourceHealthcareDicomStoreRead(d *schema.ResourceData, meta interface{}) } func resourceHealthcareDicomStoreUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceHealthcareDicomStore().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceHealthcareDicomStoreRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -509,6 +550,13 @@ func resourceHealthcareDicomStoreUpdate(d *schema.ResourceData, meta interface{} } func resourceHealthcareDicomStoreDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy HealthcareDicomStore without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing DicomStore %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/healthcare/resource_healthcare_dicom_store_generated_meta.yaml b/google-beta/services/healthcare/resource_healthcare_dicom_store_generated_meta.yaml index dfa95353bd2..7e475aa3bbf 100644 --- a/google-beta/services/healthcare/resource_healthcare_dicom_store_generated_meta.yaml +++ b/google-beta/services/healthcare/resource_healthcare_dicom_store_generated_meta.yaml @@ -19,3 +19,5 @@ fields: - api_field: streamConfigs.bigqueryDestination.tableUri - field: terraform_labels provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/healthcare/resource_healthcare_fhir_store.go b/google-beta/services/healthcare/resource_healthcare_fhir_store.go index 41826bebbc6..f56cbf960e7 100644 --- a/google-beta/services/healthcare/resource_healthcare_fhir_store.go +++ b/google-beta/services/healthcare/resource_healthcare_fhir_store.go @@ -115,6 +115,7 @@ func ResourceHealthcareFhirStore() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -533,6 +534,19 @@ The Cloud Healthcare API does not currently enforce all of the rules in a Struct and default labels configured on the provider.`, Elem: &schema.Schema{Type: schema.TypeString}, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -739,6 +753,20 @@ func resourceHealthcareFhirStoreRead(d *schema.ResourceData, meta interface{}) e return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceHealthcareFhirStoreFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -766,6 +794,19 @@ func resourceHealthcareFhirStoreRead(d *schema.ResourceData, meta interface{}) e } func resourceHealthcareFhirStoreUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceHealthcareFhirStore().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceHealthcareFhirStoreRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -936,6 +977,13 @@ func resourceHealthcareFhirStoreUpdate(d *schema.ResourceData, meta interface{}) } func resourceHealthcareFhirStoreDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy HealthcareFhirStore without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing FhirStore %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/healthcare/resource_healthcare_fhir_store_generated_meta.yaml b/google-beta/services/healthcare/resource_healthcare_fhir_store_generated_meta.yaml index aa7dbab819d..ab42c38ecf9 100644 --- a/google-beta/services/healthcare/resource_healthcare_fhir_store_generated_meta.yaml +++ b/google-beta/services/healthcare/resource_healthcare_fhir_store_generated_meta.yaml @@ -44,3 +44,5 @@ fields: - api_field: validationConfig.disableRequiredFieldValidation - api_field: validationConfig.enabledImplementationGuides - api_field: version + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/healthcare/resource_healthcare_hl7_v2_store.go b/google-beta/services/healthcare/resource_healthcare_hl7_v2_store.go index 81db97cd139..3f50e52c799 100644 --- a/google-beta/services/healthcare/resource_healthcare_hl7_v2_store.go +++ b/google-beta/services/healthcare/resource_healthcare_hl7_v2_store.go @@ -115,6 +115,7 @@ func ResourceHealthcareHl7V2Store() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -300,6 +301,19 @@ A base64-encoded string.`, and default labels configured on the provider.`, Elem: &schema.Schema{Type: schema.TypeString}, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -452,6 +466,20 @@ func resourceHealthcareHl7V2StoreRead(d *schema.ResourceData, meta interface{}) return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceHealthcareHl7V2StoreFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -479,6 +507,19 @@ func resourceHealthcareHl7V2StoreRead(d *schema.ResourceData, meta interface{}) } func resourceHealthcareHl7V2StoreUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceHealthcareHl7V2Store().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceHealthcareHl7V2StoreRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -601,6 +642,13 @@ func resourceHealthcareHl7V2StoreUpdate(d *schema.ResourceData, meta interface{} } func resourceHealthcareHl7V2StoreDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy HealthcareHl7V2Store without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Hl7V2Store %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/healthcare/resource_healthcare_hl7_v2_store_generated_meta.yaml b/google-beta/services/healthcare/resource_healthcare_hl7_v2_store_generated_meta.yaml index a9f56d42bd6..b0e2c94d88d 100644 --- a/google-beta/services/healthcare/resource_healthcare_hl7_v2_store_generated_meta.yaml +++ b/google-beta/services/healthcare/resource_healthcare_hl7_v2_store_generated_meta.yaml @@ -25,3 +25,5 @@ fields: - api_field: selfLink - field: terraform_labels provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/healthcare/resource_healthcare_pipeline_job.go b/google-beta/services/healthcare/resource_healthcare_pipeline_job.go index db4db809758..aae9f67c968 100644 --- a/google-beta/services/healthcare/resource_healthcare_pipeline_job.go +++ b/google-beta/services/healthcare/resource_healthcare_pipeline_job.go @@ -115,6 +115,7 @@ func ResourceHealthcarePipelineJob() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -367,6 +368,19 @@ in the format of: project/{projectID}/locations/{locationID}/datasets/{datasetNa and default labels configured on the provider.`, Elem: &schema.Schema{Type: schema.TypeString}, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -529,6 +543,20 @@ func resourceHealthcarePipelineJobRead(d *schema.ResourceData, meta interface{}) return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceHealthcarePipelineJobFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -556,6 +584,19 @@ func resourceHealthcarePipelineJobRead(d *schema.ResourceData, meta interface{}) } func resourceHealthcarePipelineJobUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceHealthcarePipelineJob().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceHealthcarePipelineJobRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -693,6 +734,13 @@ func resourceHealthcarePipelineJobUpdate(d *schema.ResourceData, meta interface{ } func resourceHealthcarePipelineJobDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy HealthcarePipelineJob without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing PipelineJob %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/healthcare/resource_healthcare_pipeline_job_generated_meta.yaml b/google-beta/services/healthcare/resource_healthcare_pipeline_job_generated_meta.yaml index 5fa523950f7..c879bbb3c4a 100644 --- a/google-beta/services/healthcare/resource_healthcare_pipeline_job_generated_meta.yaml +++ b/google-beta/services/healthcare/resource_healthcare_pipeline_job_generated_meta.yaml @@ -32,3 +32,5 @@ fields: - api_field: selfLink - field: terraform_labels provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/healthcare/resource_healthcare_workspace.go b/google-beta/services/healthcare/resource_healthcare_workspace.go index eff74626868..65f10eefc86 100644 --- a/google-beta/services/healthcare/resource_healthcare_workspace.go +++ b/google-beta/services/healthcare/resource_healthcare_workspace.go @@ -115,6 +115,7 @@ func ResourceHealthcareWorkspace() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -192,6 +193,19 @@ Please refer to the field 'effective_labels' for all of the labels present on th and default labels configured on the provider.`, Elem: &schema.Schema{Type: schema.TypeString}, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -314,6 +328,20 @@ func resourceHealthcareWorkspaceRead(d *schema.ResourceData, meta interface{}) e log.Printf("[DEBUG] Finished reading HealthcareWorkspace %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceHealthcareWorkspaceFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -341,6 +369,19 @@ func resourceHealthcareWorkspaceRead(d *schema.ResourceData, meta interface{}) e } func resourceHealthcareWorkspaceUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceHealthcareWorkspace().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceHealthcareWorkspaceRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -431,6 +472,13 @@ func resourceHealthcareWorkspaceUpdate(d *schema.ResourceData, meta interface{}) } func resourceHealthcareWorkspaceDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy HealthcareWorkspace without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Workspace %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/healthcare/resource_healthcare_workspace_generated_meta.yaml b/google-beta/services/healthcare/resource_healthcare_workspace_generated_meta.yaml index 9010e5a4a8a..3a21a77d33a 100644 --- a/google-beta/services/healthcare/resource_healthcare_workspace_generated_meta.yaml +++ b/google-beta/services/healthcare/resource_healthcare_workspace_generated_meta.yaml @@ -16,3 +16,5 @@ fields: - api_field: settings.dataProjectIds - field: terraform_labels provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/hypercomputecluster/resource_hypercomputecluster_cluster.go b/google-beta/services/hypercomputecluster/resource_hypercomputecluster_cluster.go index c1e146fc42e..3b916f4d7d4 100644 --- a/google-beta/services/hypercomputecluster/resource_hypercomputecluster_cluster.go +++ b/google-beta/services/hypercomputecluster/resource_hypercomputecluster_cluster.go @@ -125,6 +125,7 @@ func ResourceHypercomputeclusterCluster() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -1059,6 +1060,18 @@ state.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -1226,6 +1239,19 @@ func resourceHypercomputeclusterClusterRead(d *schema.ResourceData, meta interfa log.Printf("[DEBUG] Finished reading HypercomputeclusterCluster %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Cluster: %s", err) } @@ -1263,6 +1289,19 @@ func resourceHypercomputeclusterClusterRead(d *schema.ResourceData, meta interfa } func resourceHypercomputeclusterClusterUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceHypercomputeclusterCluster().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceHypercomputeclusterClusterRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1411,6 +1450,13 @@ func resourceHypercomputeclusterClusterUpdate(d *schema.ResourceData, meta inter } func resourceHypercomputeclusterClusterDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy HypercomputeclusterCluster without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Cluster %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/hypercomputecluster/resource_hypercomputecluster_cluster_generated_meta.yaml b/google-beta/services/hypercomputecluster/resource_hypercomputecluster_cluster_generated_meta.yaml index 89fd3bf4314..c77082e3bfa 100644 --- a/google-beta/services/hypercomputecluster/resource_hypercomputecluster_cluster_generated_meta.yaml +++ b/google-beta/services/hypercomputecluster/resource_hypercomputecluster_cluster_generated_meta.yaml @@ -125,3 +125,5 @@ fields: - field: terraform_labels provider_only: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/iam2/resource_iam_access_boundary_policy.go b/google-beta/services/iam2/resource_iam_access_boundary_policy.go index 7a91783a57a..535f8957031 100644 --- a/google-beta/services/iam2/resource_iam_access_boundary_policy.go +++ b/google-beta/services/iam2/resource_iam_access_boundary_policy.go @@ -225,6 +225,19 @@ This can be used e.g. in UIs which allow to enter the expression.`, Computed: true, Description: `The hash of the resource. Used internally during updates.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -357,6 +370,20 @@ func resourceIAM2AccessBoundaryPolicyRead(d *schema.ResourceData, meta interface log.Printf("[DEBUG] Finished reading IAM2AccessBoundaryPolicy %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceIAM2AccessBoundaryPolicyFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -384,6 +411,19 @@ func resourceIAM2AccessBoundaryPolicyRead(d *schema.ResourceData, meta interface } func resourceIAM2AccessBoundaryPolicyUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceIAM2AccessBoundaryPolicy().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceIAM2AccessBoundaryPolicyRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -469,6 +509,13 @@ func resourceIAM2AccessBoundaryPolicyUpdate(d *schema.ResourceData, meta interfa } func resourceIAM2AccessBoundaryPolicyDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy IAM2AccessBoundaryPolicy without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing AccessBoundaryPolicy %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/iam2/resource_iam_access_boundary_policy_generated_meta.yaml b/google-beta/services/iam2/resource_iam_access_boundary_policy_generated_meta.yaml index 2fa932bb1a5..6cc234b23a3 100644 --- a/google-beta/services/iam2/resource_iam_access_boundary_policy_generated_meta.yaml +++ b/google-beta/services/iam2/resource_iam_access_boundary_policy_generated_meta.yaml @@ -20,3 +20,5 @@ fields: - api_field: rules.accessBoundaryRule.availablePermissions - api_field: rules.accessBoundaryRule.availableResource - api_field: rules.description + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/iam2/resource_iam_deny_policy.go b/google-beta/services/iam2/resource_iam_deny_policy.go index 5a54311b772..8dd49c8c519 100644 --- a/google-beta/services/iam2/resource_iam_deny_policy.go +++ b/google-beta/services/iam2/resource_iam_deny_policy.go @@ -248,6 +248,19 @@ For example, you could add a Google group to the deniedPrincipals, then exclude Computed: true, Description: `The hash of the resource. Used internally during updates.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -380,6 +393,20 @@ func resourceIAM2DenyPolicyRead(d *schema.ResourceData, meta interface{}) error log.Printf("[DEBUG] Finished reading IAM2DenyPolicy %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceIAM2DenyPolicyFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -407,6 +434,19 @@ func resourceIAM2DenyPolicyRead(d *schema.ResourceData, meta interface{}) error } func resourceIAM2DenyPolicyUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceIAM2DenyPolicy().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceIAM2DenyPolicyRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -492,6 +532,13 @@ func resourceIAM2DenyPolicyUpdate(d *schema.ResourceData, meta interface{}) erro } func resourceIAM2DenyPolicyDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy IAM2DenyPolicy without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing DenyPolicy %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/iam2/resource_iam_deny_policy_generated_meta.yaml b/google-beta/services/iam2/resource_iam_deny_policy_generated_meta.yaml index 616ac05660f..dc11eaf65e8 100644 --- a/google-beta/services/iam2/resource_iam_deny_policy_generated_meta.yaml +++ b/google-beta/services/iam2/resource_iam_deny_policy_generated_meta.yaml @@ -24,3 +24,5 @@ fields: - api_field: rules.denyRule.exceptionPermissions - api_field: rules.denyRule.exceptionPrincipals - api_field: rules.description + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/iam3/resource_iam_folders_policy_binding.go b/google-beta/services/iam3/resource_iam_folders_policy_binding.go index b0e200b2159..368b1f08507 100644 --- a/google-beta/services/iam3/resource_iam_folders_policy_binding.go +++ b/google-beta/services/iam3/resource_iam_folders_policy_binding.go @@ -115,6 +115,7 @@ func ResourceIAM3FoldersPolicyBinding() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetAnnotationsDiff, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -295,6 +296,19 @@ to the policy kind) - The input policy kind Possible values: POLICY_KIND_UNSP Computed: true, Description: `Output only. The time when the policy binding was most recently updated.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -451,6 +465,20 @@ func resourceIAM3FoldersPolicyBindingRead(d *schema.ResourceData, meta interface log.Printf("[DEBUG] Finished reading IAM3FoldersPolicyBinding %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceIAM3FoldersPolicyBindingFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -484,6 +512,18 @@ func resourceIAM3FoldersPolicyBindingRead(d *schema.ResourceData, meta interface } func resourceIAM3FoldersPolicyBindingUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceIAM3FoldersPolicyBinding().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceIAM3FoldersPolicyBindingRead(d, meta) + } var project string config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) @@ -607,6 +647,13 @@ func resourceIAM3FoldersPolicyBindingUpdate(d *schema.ResourceData, meta interfa } func resourceIAM3FoldersPolicyBindingDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy IAM3FoldersPolicyBinding without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing FoldersPolicyBinding %q from Terraform state without deletion", d.Id()) + return nil + } var project string config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) diff --git a/google-beta/services/iam3/resource_iam_folders_policy_binding_generated_meta.yaml b/google-beta/services/iam3/resource_iam_folders_policy_binding_generated_meta.yaml index 0124a45c1ae..7668041ec10 100644 --- a/google-beta/services/iam3/resource_iam_folders_policy_binding_generated_meta.yaml +++ b/google-beta/services/iam3/resource_iam_folders_policy_binding_generated_meta.yaml @@ -32,3 +32,5 @@ fields: - api_field: target.principalSet - api_field: uid - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/iam3/resource_iam_organizations_policy_binding.go b/google-beta/services/iam3/resource_iam_organizations_policy_binding.go index b78f31f02d8..678f7c946c3 100644 --- a/google-beta/services/iam3/resource_iam_organizations_policy_binding.go +++ b/google-beta/services/iam3/resource_iam_organizations_policy_binding.go @@ -115,6 +115,7 @@ func ResourceIAM3OrganizationsPolicyBinding() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetAnnotationsDiff, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -297,6 +298,19 @@ to the policy kind) - The input policy kind Possible values: POLICY_KIND_UNSP Computed: true, Description: `Output only. The time when the policy binding was most recently updated.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -453,6 +467,20 @@ func resourceIAM3OrganizationsPolicyBindingRead(d *schema.ResourceData, meta int log.Printf("[DEBUG] Finished reading IAM3OrganizationsPolicyBinding %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceIAM3OrganizationsPolicyBindingFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -486,6 +514,18 @@ func resourceIAM3OrganizationsPolicyBindingRead(d *schema.ResourceData, meta int } func resourceIAM3OrganizationsPolicyBindingUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceIAM3OrganizationsPolicyBinding().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceIAM3OrganizationsPolicyBindingRead(d, meta) + } var project string config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) @@ -609,6 +649,13 @@ func resourceIAM3OrganizationsPolicyBindingUpdate(d *schema.ResourceData, meta i } func resourceIAM3OrganizationsPolicyBindingDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy IAM3OrganizationsPolicyBinding without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing OrganizationsPolicyBinding %q from Terraform state without deletion", d.Id()) + return nil + } var project string config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) diff --git a/google-beta/services/iam3/resource_iam_organizations_policy_binding_generated_meta.yaml b/google-beta/services/iam3/resource_iam_organizations_policy_binding_generated_meta.yaml index a62b8b2cc29..050fd21a3ca 100644 --- a/google-beta/services/iam3/resource_iam_organizations_policy_binding_generated_meta.yaml +++ b/google-beta/services/iam3/resource_iam_organizations_policy_binding_generated_meta.yaml @@ -32,3 +32,5 @@ fields: - api_field: target.principalSet - api_field: uid - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/iam3/resource_iam_principal_access_boundary_policy.go b/google-beta/services/iam3/resource_iam_principal_access_boundary_policy.go index dddf2e50fdf..27bd4aaacdb 100644 --- a/google-beta/services/iam3/resource_iam_principal_access_boundary_policy.go +++ b/google-beta/services/iam3/resource_iam_principal_access_boundary_policy.go @@ -115,6 +115,7 @@ func ResourceIAM3PrincipalAccessBoundaryPolicy() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetAnnotationsDiff, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -263,6 +264,19 @@ won't get updated when new versions are released.`, Computed: true, Description: `Output only. The time when the principal access boundary policy was most recently updated.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -401,6 +415,20 @@ func resourceIAM3PrincipalAccessBoundaryPolicyRead(d *schema.ResourceData, meta log.Printf("[DEBUG] Finished reading IAM3PrincipalAccessBoundaryPolicy %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceIAM3PrincipalAccessBoundaryPolicyFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -434,6 +462,18 @@ func resourceIAM3PrincipalAccessBoundaryPolicyRead(d *schema.ResourceData, meta } func resourceIAM3PrincipalAccessBoundaryPolicyUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceIAM3PrincipalAccessBoundaryPolicy().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceIAM3PrincipalAccessBoundaryPolicyRead(d, meta) + } var project string config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) @@ -547,6 +587,13 @@ func resourceIAM3PrincipalAccessBoundaryPolicyUpdate(d *schema.ResourceData, met } func resourceIAM3PrincipalAccessBoundaryPolicyDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy IAM3PrincipalAccessBoundaryPolicy without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing PrincipalAccessBoundaryPolicy %q from Terraform state without deletion", d.Id()) + return nil + } var project string config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) diff --git a/google-beta/services/iam3/resource_iam_principal_access_boundary_policy_generated_meta.yaml b/google-beta/services/iam3/resource_iam_principal_access_boundary_policy_generated_meta.yaml index ede6e0ad29c..eda531bb0df 100644 --- a/google-beta/services/iam3/resource_iam_principal_access_boundary_policy_generated_meta.yaml +++ b/google-beta/services/iam3/resource_iam_principal_access_boundary_policy_generated_meta.yaml @@ -26,3 +26,5 @@ fields: provider_only: true - api_field: uid - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/iam3/resource_iam_projects_policy_binding.go b/google-beta/services/iam3/resource_iam_projects_policy_binding.go index d4a3648fc4d..18986d71062 100644 --- a/google-beta/services/iam3/resource_iam_projects_policy_binding.go +++ b/google-beta/services/iam3/resource_iam_projects_policy_binding.go @@ -116,6 +116,7 @@ func ResourceIAM3ProjectsPolicyBinding() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetAnnotationsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -299,6 +300,18 @@ to the policy kind) - The input policy kind Possible values: POLICY_KIND_UNSP Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -472,6 +485,19 @@ func resourceIAM3ProjectsPolicyBindingRead(d *schema.ResourceData, meta interfac log.Printf("[DEBUG] Finished reading IAM3ProjectsPolicyBinding %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading ProjectsPolicyBinding: %s", err) } @@ -509,6 +535,19 @@ func resourceIAM3ProjectsPolicyBindingRead(d *schema.ResourceData, meta interfac } func resourceIAM3ProjectsPolicyBindingUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceIAM3ProjectsPolicyBinding().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceIAM3ProjectsPolicyBindingRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -647,6 +686,13 @@ func resourceIAM3ProjectsPolicyBindingUpdate(d *schema.ResourceData, meta interf } func resourceIAM3ProjectsPolicyBindingDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy IAM3ProjectsPolicyBinding without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing ProjectsPolicyBinding %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/iam3/resource_iam_projects_policy_binding_generated_meta.yaml b/google-beta/services/iam3/resource_iam_projects_policy_binding_generated_meta.yaml index 4e011a661d7..55e61abafe2 100644 --- a/google-beta/services/iam3/resource_iam_projects_policy_binding_generated_meta.yaml +++ b/google-beta/services/iam3/resource_iam_projects_policy_binding_generated_meta.yaml @@ -30,3 +30,5 @@ fields: - api_field: target.principalSet - api_field: uid - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/iambeta/resource_iam_workload_identity_pool.go b/google-beta/services/iambeta/resource_iam_workload_identity_pool.go index 370d6bdb230..c00b65795fc 100644 --- a/google-beta/services/iambeta/resource_iam_workload_identity_pool.go +++ b/google-beta/services/iambeta/resource_iam_workload_identity_pool.go @@ -148,6 +148,7 @@ func ResourceIAMBetaWorkloadIdentityPool() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -394,6 +395,18 @@ can be created within 'SYSTEM_TRUST_DOMAIN' mode pools. All identities within a Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -645,6 +658,19 @@ func resourceIAMBetaWorkloadIdentityPoolRead(d *schema.ResourceData, meta interf return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading WorkloadIdentityPool: %s", err) } @@ -676,6 +702,19 @@ func resourceIAMBetaWorkloadIdentityPoolRead(d *schema.ResourceData, meta interf } func resourceIAMBetaWorkloadIdentityPoolUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceIAMBetaWorkloadIdentityPool().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceIAMBetaWorkloadIdentityPoolRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -868,6 +907,13 @@ func resourceIAMBetaWorkloadIdentityPoolUpdate(d *schema.ResourceData, meta inte } func resourceIAMBetaWorkloadIdentityPoolDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy IAMBetaWorkloadIdentityPool without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing WorkloadIdentityPool %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/iambeta/resource_iam_workload_identity_pool_generated_meta.yaml b/google-beta/services/iambeta/resource_iam_workload_identity_pool_generated_meta.yaml index 84aee154dbc..7aae7edcc26 100644 --- a/google-beta/services/iambeta/resource_iam_workload_identity_pool_generated_meta.yaml +++ b/google-beta/services/iambeta/resource_iam_workload_identity_pool_generated_meta.yaml @@ -27,3 +27,5 @@ fields: - api_field: state - field: workload_identity_pool_id provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/iambeta/resource_iam_workload_identity_pool_managed_identity.go b/google-beta/services/iambeta/resource_iam_workload_identity_pool_managed_identity.go index 65e66da90af..8ff64c20b66 100644 --- a/google-beta/services/iambeta/resource_iam_workload_identity_pool_managed_identity.go +++ b/google-beta/services/iambeta/resource_iam_workload_identity_pool_managed_identity.go @@ -160,6 +160,7 @@ func ResourceIAMBetaWorkloadIdentityPoolManagedIdentity() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -267,6 +268,18 @@ soft-deleted managed identity until it is permanently deleted.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -504,6 +517,19 @@ func resourceIAMBetaWorkloadIdentityPoolManagedIdentityRead(d *schema.ResourceDa return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading WorkloadIdentityPoolManagedIdentity: %s", err) } @@ -547,6 +573,19 @@ func resourceIAMBetaWorkloadIdentityPoolManagedIdentityRead(d *schema.ResourceDa } func resourceIAMBetaWorkloadIdentityPoolManagedIdentityUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceIAMBetaWorkloadIdentityPoolManagedIdentity().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceIAMBetaWorkloadIdentityPoolManagedIdentityRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -709,6 +748,13 @@ func resourceIAMBetaWorkloadIdentityPoolManagedIdentityUpdate(d *schema.Resource } func resourceIAMBetaWorkloadIdentityPoolManagedIdentityDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy IAMBetaWorkloadIdentityPoolManagedIdentity without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing WorkloadIdentityPoolManagedIdentity %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/iambeta/resource_iam_workload_identity_pool_managed_identity_generated_meta.yaml b/google-beta/services/iambeta/resource_iam_workload_identity_pool_managed_identity_generated_meta.yaml index cf7e4e731db..3cbe090594d 100644 --- a/google-beta/services/iambeta/resource_iam_workload_identity_pool_managed_identity_generated_meta.yaml +++ b/google-beta/services/iambeta/resource_iam_workload_identity_pool_managed_identity_generated_meta.yaml @@ -18,3 +18,5 @@ fields: provider_only: true - field: workload_identity_pool_namespace_id provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/iambeta/resource_iam_workload_identity_pool_namespace.go b/google-beta/services/iambeta/resource_iam_workload_identity_pool_namespace.go index 4060b91fb7d..028fe64e72e 100644 --- a/google-beta/services/iambeta/resource_iam_workload_identity_pool_namespace.go +++ b/google-beta/services/iambeta/resource_iam_workload_identity_pool_namespace.go @@ -160,6 +160,7 @@ func ResourceIAMBetaWorkloadIdentityPoolNamespace() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -258,6 +259,18 @@ until it is permanently deleted.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -413,6 +426,19 @@ func resourceIAMBetaWorkloadIdentityPoolNamespaceRead(d *schema.ResourceData, me return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading WorkloadIdentityPoolNamespace: %s", err) } @@ -450,6 +476,19 @@ func resourceIAMBetaWorkloadIdentityPoolNamespaceRead(d *schema.ResourceData, me } func resourceIAMBetaWorkloadIdentityPoolNamespaceUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceIAMBetaWorkloadIdentityPoolNamespace().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceIAMBetaWorkloadIdentityPoolNamespaceRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -558,6 +597,13 @@ func resourceIAMBetaWorkloadIdentityPoolNamespaceUpdate(d *schema.ResourceData, } func resourceIAMBetaWorkloadIdentityPoolNamespaceDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy IAMBetaWorkloadIdentityPoolNamespace without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing WorkloadIdentityPoolNamespace %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/iambeta/resource_iam_workload_identity_pool_namespace_generated_meta.yaml b/google-beta/services/iambeta/resource_iam_workload_identity_pool_namespace_generated_meta.yaml index 1bc3f5e2b3e..1411489710f 100644 --- a/google-beta/services/iambeta/resource_iam_workload_identity_pool_namespace_generated_meta.yaml +++ b/google-beta/services/iambeta/resource_iam_workload_identity_pool_namespace_generated_meta.yaml @@ -16,3 +16,5 @@ fields: provider_only: true - field: workload_identity_pool_namespace_id provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/iambeta/resource_iam_workload_identity_pool_provider.go b/google-beta/services/iambeta/resource_iam_workload_identity_pool_provider.go index 59d14e68a19..dc932e35164 100644 --- a/google-beta/services/iambeta/resource_iam_workload_identity_pool_provider.go +++ b/google-beta/services/iambeta/resource_iam_workload_identity_pool_provider.go @@ -161,6 +161,7 @@ func ResourceIAMBetaWorkloadIdentityPoolProvider() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -486,6 +487,18 @@ ca certificate(either root or intermediate cert).`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -683,6 +696,19 @@ func resourceIAMBetaWorkloadIdentityPoolProviderRead(d *schema.ResourceData, met return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading WorkloadIdentityPoolProvider: %s", err) } @@ -720,6 +746,19 @@ func resourceIAMBetaWorkloadIdentityPoolProviderRead(d *schema.ResourceData, met } func resourceIAMBetaWorkloadIdentityPoolProviderUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceIAMBetaWorkloadIdentityPoolProvider().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceIAMBetaWorkloadIdentityPoolProviderRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -900,6 +939,13 @@ func resourceIAMBetaWorkloadIdentityPoolProviderUpdate(d *schema.ResourceData, m } func resourceIAMBetaWorkloadIdentityPoolProviderDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy IAMBetaWorkloadIdentityPoolProvider without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing WorkloadIdentityPoolProvider %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/iambeta/resource_iam_workload_identity_pool_provider_generated_meta.yaml b/google-beta/services/iambeta/resource_iam_workload_identity_pool_provider_generated_meta.yaml index ef99ac656b9..509f2f9a91a 100644 --- a/google-beta/services/iambeta/resource_iam_workload_identity_pool_provider_generated_meta.yaml +++ b/google-beta/services/iambeta/resource_iam_workload_identity_pool_provider_generated_meta.yaml @@ -25,3 +25,5 @@ fields: provider_only: true - api_field: x509.trustStore.intermediateCas.pemCertificate - api_field: x509.trustStore.trustAnchors.pemCertificate + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/iamworkforcepool/resource_iam_oauth_client.go b/google-beta/services/iamworkforcepool/resource_iam_oauth_client.go index ac6051a9211..a7841304a31 100644 --- a/google-beta/services/iamworkforcepool/resource_iam_oauth_client.go +++ b/google-beta/services/iamworkforcepool/resource_iam_oauth_client.go @@ -115,6 +115,7 @@ func ResourceIAMWorkforcePoolOauthClient() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -258,6 +259,18 @@ DELETED`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -438,6 +451,19 @@ func resourceIAMWorkforcePoolOauthClientRead(d *schema.ResourceData, meta interf return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading OauthClient: %s", err) } @@ -475,6 +501,19 @@ func resourceIAMWorkforcePoolOauthClientRead(d *schema.ResourceData, meta interf } func resourceIAMWorkforcePoolOauthClientUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceIAMWorkforcePoolOauthClient().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceIAMWorkforcePoolOauthClientRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -620,6 +659,13 @@ func resourceIAMWorkforcePoolOauthClientUpdate(d *schema.ResourceData, meta inte } func resourceIAMWorkforcePoolOauthClientDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy IAMWorkforcePoolOauthClient without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing OauthClient %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/iamworkforcepool/resource_iam_oauth_client_credential.go b/google-beta/services/iamworkforcepool/resource_iam_oauth_client_credential.go index 9ae000143c8..1fa627511de 100644 --- a/google-beta/services/iamworkforcepool/resource_iam_oauth_client_credential.go +++ b/google-beta/services/iamworkforcepool/resource_iam_oauth_client_credential.go @@ -115,6 +115,7 @@ func ResourceIAMWorkforcePoolOauthClientCredential() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -204,6 +205,18 @@ Format: Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -359,6 +372,19 @@ func resourceIAMWorkforcePoolOauthClientCredentialRead(d *schema.ResourceData, m return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading OauthClientCredential: %s", err) } @@ -402,6 +428,19 @@ func resourceIAMWorkforcePoolOauthClientCredentialRead(d *schema.ResourceData, m } func resourceIAMWorkforcePoolOauthClientCredentialUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceIAMWorkforcePoolOauthClientCredential().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceIAMWorkforcePoolOauthClientCredentialRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -512,6 +551,13 @@ func resourceIAMWorkforcePoolOauthClientCredentialUpdate(d *schema.ResourceData, } func resourceIAMWorkforcePoolOauthClientCredentialDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy IAMWorkforcePoolOauthClientCredential without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing OauthClientCredential %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/iamworkforcepool/resource_iam_oauth_client_credential_generated_meta.yaml b/google-beta/services/iamworkforcepool/resource_iam_oauth_client_credential_generated_meta.yaml index 6c865b91f6e..4811fe9a8b5 100644 --- a/google-beta/services/iamworkforcepool/resource_iam_oauth_client_credential_generated_meta.yaml +++ b/google-beta/services/iamworkforcepool/resource_iam_oauth_client_credential_generated_meta.yaml @@ -17,3 +17,5 @@ fields: provider_only: true - field: oauthclient provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/iamworkforcepool/resource_iam_oauth_client_generated_meta.yaml b/google-beta/services/iamworkforcepool/resource_iam_oauth_client_generated_meta.yaml index a95ad4d6414..5b2dfe5ae76 100644 --- a/google-beta/services/iamworkforcepool/resource_iam_oauth_client_generated_meta.yaml +++ b/google-beta/services/iamworkforcepool/resource_iam_oauth_client_generated_meta.yaml @@ -22,3 +22,5 @@ fields: - field: oauth_client_id provider_only: true - api_field: state + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/iamworkforcepool/resource_iam_workforce_pool.go b/google-beta/services/iamworkforcepool/resource_iam_workforce_pool.go index e5830c3d917..ef8cbf4af00 100644 --- a/google-beta/services/iamworkforcepool/resource_iam_workforce_pool.go +++ b/google-beta/services/iamworkforcepool/resource_iam_workforce_pool.go @@ -255,6 +255,19 @@ Format: 'locations/{location}/workforcePools/{workforcePoolId}'`, existing tokens to access resources. If the pool is undeleted, existing tokens grant access again.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -417,6 +430,20 @@ func resourceIAMWorkforcePoolWorkforcePoolRead(d *schema.ResourceData, meta inte return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceIAMWorkforcePoolWorkforcePoolFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -444,6 +471,19 @@ func resourceIAMWorkforcePoolWorkforcePoolRead(d *schema.ResourceData, meta inte } func resourceIAMWorkforcePoolWorkforcePoolUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceIAMWorkforcePoolWorkforcePool().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceIAMWorkforcePoolWorkforcePoolRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -561,6 +601,13 @@ func resourceIAMWorkforcePoolWorkforcePoolUpdate(d *schema.ResourceData, meta in } func resourceIAMWorkforcePoolWorkforcePoolDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy IAMWorkforcePoolWorkforcePool without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing WorkforcePool %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/iamworkforcepool/resource_iam_workforce_pool_generated_meta.yaml b/google-beta/services/iamworkforcepool/resource_iam_workforce_pool_generated_meta.yaml index f4bb5202ebf..bb3e3a1e046 100644 --- a/google-beta/services/iamworkforcepool/resource_iam_workforce_pool_generated_meta.yaml +++ b/google-beta/services/iamworkforcepool/resource_iam_workforce_pool_generated_meta.yaml @@ -20,3 +20,5 @@ fields: - api_field: state - field: workforce_pool_id provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/iamworkforcepool/resource_iam_workforce_pool_provider.go b/google-beta/services/iamworkforcepool/resource_iam_workforce_pool_provider.go index 88a3ee362f2..91ead6370e0 100644 --- a/google-beta/services/iamworkforcepool/resource_iam_workforce_pool_provider.go +++ b/google-beta/services/iamworkforcepool/resource_iam_workforce_pool_provider.go @@ -653,6 +653,19 @@ Format: 'locations/{location}/workforcePools/{workforcePoolId}/providers/{provid deleted after approximately 30 days. You can restore a soft-deleted provider using [providers.undelete](https://cloud.google.com/iam/docs/reference/rest/v1/locations.workforcePools.providers/undelete#google.iam.admin.v1.WorkforcePools.UndeleteWorkforcePoolProvider).`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -897,6 +910,20 @@ func resourceIAMWorkforcePoolWorkforcePoolProviderRead(d *schema.ResourceData, m return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceIAMWorkforcePoolWorkforcePoolProviderFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -930,6 +957,19 @@ func resourceIAMWorkforcePoolWorkforcePoolProviderRead(d *schema.ResourceData, m } func resourceIAMWorkforcePoolWorkforcePoolProviderUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceIAMWorkforcePoolWorkforcePoolProvider().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceIAMWorkforcePoolWorkforcePoolProviderRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1164,6 +1204,13 @@ func resourceIAMWorkforcePoolWorkforcePoolProviderUpdate(d *schema.ResourceData, } func resourceIAMWorkforcePoolWorkforcePoolProviderDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy IAMWorkforcePoolWorkforcePoolProvider without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing WorkforcePoolProvider %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/iamworkforcepool/resource_iam_workforce_pool_provider_generated_meta.yaml b/google-beta/services/iamworkforcepool/resource_iam_workforce_pool_provider_generated_meta.yaml index d739dc57f55..df5c22f9e09 100644 --- a/google-beta/services/iamworkforcepool/resource_iam_workforce_pool_provider_generated_meta.yaml +++ b/google-beta/services/iamworkforcepool/resource_iam_workforce_pool_provider_generated_meta.yaml @@ -43,3 +43,5 @@ fields: - api_field: state - field: workforce_pool_id provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/iamworkforcepool/resource_iam_workforce_pool_provider_key.go b/google-beta/services/iamworkforcepool/resource_iam_workforce_pool_provider_key.go index 3312972601a..3fc8f6aa3af 100644 --- a/google-beta/services/iamworkforcepool/resource_iam_workforce_pool_provider_key.go +++ b/google-beta/services/iamworkforcepool/resource_iam_workforce_pool_provider_key.go @@ -119,6 +119,7 @@ func ResourceIAMWorkforcePoolWorkforcePoolProviderKey() *schema.Resource { return &schema.Resource{ Create: resourceIAMWorkforcePoolWorkforcePoolProviderKeyCreate, Read: resourceIAMWorkforcePoolWorkforcePoolProviderKeyRead, + Update: resourceIAMWorkforcePoolWorkforcePoolProviderKeyUpdate, Delete: resourceIAMWorkforcePoolWorkforcePoolProviderKeyDelete, Importer: &schema.ResourceImporter{ @@ -255,6 +256,19 @@ Format: 'locations/{location}/workforcePools/{workforcePoolId}/providers/{provid Computed: true, Description: `The state of the key.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -391,6 +405,20 @@ func resourceIAMWorkforcePoolWorkforcePoolProviderKeyRead(d *schema.ResourceData log.Printf("[DEBUG] Finished reading IAMWorkforcePoolWorkforcePoolProviderKey %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceIAMWorkforcePoolWorkforcePoolProviderKeyFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -429,7 +457,19 @@ func resourceIAMWorkforcePoolWorkforcePoolProviderKeyRead(d *schema.ResourceData return nil } +func resourceIAMWorkforcePoolWorkforcePoolProviderKeyUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceIAMWorkforcePoolWorkforcePoolProviderKeyRead(d, meta) +} + func resourceIAMWorkforcePoolWorkforcePoolProviderKeyDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy IAMWorkforcePoolWorkforcePoolProviderKey without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing WorkforcePoolProviderKey %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/iamworkforcepool/resource_iam_workforce_pool_provider_key_generated_meta.yaml b/google-beta/services/iamworkforcepool/resource_iam_workforce_pool_provider_key_generated_meta.yaml index 813d2084b70..af385f51437 100644 --- a/google-beta/services/iamworkforcepool/resource_iam_workforce_pool_provider_key_generated_meta.yaml +++ b/google-beta/services/iamworkforcepool/resource_iam_workforce_pool_provider_key_generated_meta.yaml @@ -24,3 +24,5 @@ fields: - api_field: use - field: workforce_pool_id provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/iamworkforcepool/resource_iam_workforce_pool_provider_scim_tenant.go b/google-beta/services/iamworkforcepool/resource_iam_workforce_pool_provider_scim_tenant.go index 44633c90e02..666e92d6266 100644 --- a/google-beta/services/iamworkforcepool/resource_iam_workforce_pool_provider_scim_tenant.go +++ b/google-beta/services/iamworkforcepool/resource_iam_workforce_pool_provider_scim_tenant.go @@ -221,6 +221,19 @@ this tenant will be attached to this service agent.`, * DELETED: The scim tenant is soft-deleted. Soft-deleted scim tenants are permanently deleted after approximately 30 days.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -370,6 +383,20 @@ func resourceIAMWorkforcePoolWorkforcePoolProviderScimTenantRead(d *schema.Resou return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceIAMWorkforcePoolWorkforcePoolProviderScimTenantFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -409,6 +436,19 @@ func resourceIAMWorkforcePoolWorkforcePoolProviderScimTenantRead(d *schema.Resou } func resourceIAMWorkforcePoolWorkforcePoolProviderScimTenantUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceIAMWorkforcePoolWorkforcePoolProviderScimTenant().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceIAMWorkforcePoolWorkforcePoolProviderScimTenantRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -523,6 +563,13 @@ func resourceIAMWorkforcePoolWorkforcePoolProviderScimTenantUpdate(d *schema.Res } func resourceIAMWorkforcePoolWorkforcePoolProviderScimTenantDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy IAMWorkforcePoolWorkforcePoolProviderScimTenant without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing WorkforcePoolProviderScimTenant %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/iamworkforcepool/resource_iam_workforce_pool_provider_scim_tenant_generated_meta.yaml b/google-beta/services/iamworkforcepool/resource_iam_workforce_pool_provider_scim_tenant_generated_meta.yaml index fc492605a02..cbc2d4d7b0e 100644 --- a/google-beta/services/iamworkforcepool/resource_iam_workforce_pool_provider_scim_tenant_generated_meta.yaml +++ b/google-beta/services/iamworkforcepool/resource_iam_workforce_pool_provider_scim_tenant_generated_meta.yaml @@ -25,3 +25,5 @@ fields: - api_field: state - field: workforce_pool_id provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/iamworkforcepool/resource_iam_workforce_pool_provider_scim_token.go b/google-beta/services/iamworkforcepool/resource_iam_workforce_pool_provider_scim_token.go index cfb5b2537c7..83a68c95fed 100644 --- a/google-beta/services/iamworkforcepool/resource_iam_workforce_pool_provider_scim_token.go +++ b/google-beta/services/iamworkforcepool/resource_iam_workforce_pool_provider_scim_token.go @@ -198,6 +198,19 @@ Format: 'locations/{location}/workforcePools/{workforce_pool}/providers/{workfor * ACTIVE: The token is active and may be used to provision users and groups. * DELETED: The token is soft-deleted. Soft-deleted tokens are permanently deleted after approximately 30 days.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -340,6 +353,20 @@ func resourceIAMWorkforcePoolWorkforcePoolProviderScimTokenRead(d *schema.Resour return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceIAMWorkforcePoolWorkforcePoolProviderScimTokenFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -385,6 +412,19 @@ func resourceIAMWorkforcePoolWorkforcePoolProviderScimTokenRead(d *schema.Resour } func resourceIAMWorkforcePoolWorkforcePoolProviderScimTokenUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceIAMWorkforcePoolWorkforcePoolProviderScimToken().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceIAMWorkforcePoolWorkforcePoolProviderScimTokenRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -484,6 +524,13 @@ func resourceIAMWorkforcePoolWorkforcePoolProviderScimTokenUpdate(d *schema.Reso } func resourceIAMWorkforcePoolWorkforcePoolProviderScimTokenDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy IAMWorkforcePoolWorkforcePoolProviderScimToken without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing WorkforcePoolProviderScimToken %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/iamworkforcepool/resource_iam_workforce_pool_provider_scim_token_generated_meta.yaml b/google-beta/services/iamworkforcepool/resource_iam_workforce_pool_provider_scim_token_generated_meta.yaml index ae6cb17512d..c0196be3b06 100644 --- a/google-beta/services/iamworkforcepool/resource_iam_workforce_pool_provider_scim_token_generated_meta.yaml +++ b/google-beta/services/iamworkforcepool/resource_iam_workforce_pool_provider_scim_token_generated_meta.yaml @@ -21,3 +21,5 @@ fields: - api_field: state - field: workforce_pool_id provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/iap/resource_iap_client.go b/google-beta/services/iap/resource_iap_client.go index 76b0338289a..8ed81d2e075 100644 --- a/google-beta/services/iap/resource_iap_client.go +++ b/google-beta/services/iap/resource_iap_client.go @@ -100,6 +100,7 @@ func ResourceIapClient() *schema.Resource { return &schema.Resource{ Create: resourceIapClientCreate, Read: resourceIapClientRead, + Update: resourceIapClientUpdate, Delete: resourceIapClientDelete, Importer: &schema.ResourceImporter{ @@ -158,6 +159,19 @@ is attached to. The format is Description: `Output only. Client secret of the OAuth client.`, Sensitive: true, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -276,6 +290,20 @@ func resourceIapClientRead(d *schema.ResourceData, meta interface{}) error { log.Printf("[DEBUG] Finished reading IapClient %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceIapClientFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -302,7 +330,19 @@ func resourceIapClientRead(d *schema.ResourceData, meta interface{}) error { return nil } +func resourceIapClientUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceIapClientRead(d, meta) +} + func resourceIapClientDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy IapClient without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Client %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/iap/resource_iap_client_generated_meta.yaml b/google-beta/services/iap/resource_iap_client_generated_meta.yaml index 05f0d7f8b5a..15d5c6b079d 100644 --- a/google-beta/services/iap/resource_iap_client_generated_meta.yaml +++ b/google-beta/services/iap/resource_iap_client_generated_meta.yaml @@ -13,3 +13,5 @@ fields: field: client_id - api_field: displayName - api_field: secret + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/iap/resource_iap_settings.go b/google-beta/services/iap/resource_iap_settings.go index af5be3a08c4..189dc31ba32 100644 --- a/google-beta/services/iap/resource_iap_settings.go +++ b/google-beta/services/iap/resource_iap_settings.go @@ -469,6 +469,19 @@ but will be ignored at runtime if invalid.`, }, }, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -586,6 +599,20 @@ func resourceIapSettingsRead(d *schema.ResourceData, meta interface{}) error { log.Printf("[DEBUG] Finished reading IapSettings %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceIapSettingsFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -607,6 +634,19 @@ func resourceIapSettingsRead(d *schema.ResourceData, meta interface{}) error { } func resourceIapSettingsUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceIapSettings().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceIapSettingsRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -673,6 +713,13 @@ func resourceIapSettingsUpdate(d *schema.ResourceData, meta interface{}) error { } func resourceIapSettingsDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy IapSettings without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Settings %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/iap/resource_iap_settings_generated_meta.yaml b/google-beta/services/iap/resource_iap_settings_generated_meta.yaml index 63246c8cfc7..0cb742864ac 100644 --- a/google-beta/services/iap/resource_iap_settings_generated_meta.yaml +++ b/google-beta/services/iap/resource_iap_settings_generated_meta.yaml @@ -34,3 +34,5 @@ fields: - api_field: applicationSettings.cookieDomain - api_field: applicationSettings.csmSettings.rctokenAud - api_field: name + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/iap/resource_iap_tunnel_dest_group.go b/google-beta/services/iap/resource_iap_tunnel_dest_group.go index 2c1c677d188..6c06998108f 100644 --- a/google-beta/services/iap/resource_iap_tunnel_dest_group.go +++ b/google-beta/services/iap/resource_iap_tunnel_dest_group.go @@ -115,6 +115,7 @@ func ResourceIapTunnelDestGroup() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -181,6 +182,18 @@ func ResourceIapTunnelDestGroup() *schema.Resource { Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -314,6 +327,19 @@ func resourceIapTunnelDestGroupRead(d *schema.ResourceData, meta interface{}) er log.Printf("[DEBUG] Finished reading IapTunnelDestGroup %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading TunnelDestGroup: %s", err) } @@ -351,6 +377,19 @@ func resourceIapTunnelDestGroupRead(d *schema.ResourceData, meta interface{}) er } func resourceIapTunnelDestGroupUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceIapTunnelDestGroup().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceIapTunnelDestGroupRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -433,6 +472,13 @@ func resourceIapTunnelDestGroupUpdate(d *schema.ResourceData, meta interface{}) } func resourceIapTunnelDestGroupDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy IapTunnelDestGroup without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing TunnelDestGroup %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/iap/resource_iap_tunnel_dest_group_generated_meta.yaml b/google-beta/services/iap/resource_iap_tunnel_dest_group_generated_meta.yaml index da8f0214e97..1b38f9c80e8 100644 --- a/google-beta/services/iap/resource_iap_tunnel_dest_group_generated_meta.yaml +++ b/google-beta/services/iap/resource_iap_tunnel_dest_group_generated_meta.yaml @@ -14,3 +14,5 @@ fields: - api_field: name - field: region provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/identityplatform/resource_identity_platform_config.go b/google-beta/services/identityplatform/resource_identity_platform_config.go index 45d4755649f..d86eca3b2dd 100644 --- a/google-beta/services/identityplatform/resource_identity_platform_config.go +++ b/google-beta/services/identityplatform/resource_identity_platform_config.go @@ -688,6 +688,7 @@ func resourceIdentityPlatformConfigRead(d *schema.ResourceData, meta interface{} } func resourceIdentityPlatformConfigUpdate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/identityplatform/resource_identity_platform_default_supported_idp_config.go b/google-beta/services/identityplatform/resource_identity_platform_default_supported_idp_config.go index 5374a404c64..960d18f4286 100644 --- a/google-beta/services/identityplatform/resource_identity_platform_default_supported_idp_config.go +++ b/google-beta/services/identityplatform/resource_identity_platform_default_supported_idp_config.go @@ -115,6 +115,7 @@ func ResourceIdentityPlatformDefaultSupportedIdpConfig() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -189,6 +190,18 @@ func ResourceIdentityPlatformDefaultSupportedIdpConfig() *schema.Resource { Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -323,6 +336,19 @@ func resourceIdentityPlatformDefaultSupportedIdpConfigRead(d *schema.ResourceDat log.Printf("[DEBUG] Finished reading IdentityPlatformDefaultSupportedIdpConfig %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading DefaultSupportedIdpConfig: %s", err) } @@ -354,6 +380,19 @@ func resourceIdentityPlatformDefaultSupportedIdpConfigRead(d *schema.ResourceDat } func resourceIdentityPlatformDefaultSupportedIdpConfigUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceIdentityPlatformDefaultSupportedIdpConfig().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceIdentityPlatformDefaultSupportedIdpConfigRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -460,6 +499,13 @@ func resourceIdentityPlatformDefaultSupportedIdpConfigUpdate(d *schema.ResourceD } func resourceIdentityPlatformDefaultSupportedIdpConfigDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy IdentityPlatformDefaultSupportedIdpConfig without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing DefaultSupportedIdpConfig %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/identityplatform/resource_identity_platform_default_supported_idp_config_generated_meta.yaml b/google-beta/services/identityplatform/resource_identity_platform_default_supported_idp_config_generated_meta.yaml index bc44a78be40..b0413f4c7b5 100644 --- a/google-beta/services/identityplatform/resource_identity_platform_default_supported_idp_config_generated_meta.yaml +++ b/google-beta/services/identityplatform/resource_identity_platform_default_supported_idp_config_generated_meta.yaml @@ -13,3 +13,5 @@ fields: - field: idp_id provider_only: true - api_field: name + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/identityplatform/resource_identity_platform_inbound_saml_config.go b/google-beta/services/identityplatform/resource_identity_platform_inbound_saml_config.go index 3b7045e4b03..d2d09207f4c 100644 --- a/google-beta/services/identityplatform/resource_identity_platform_inbound_saml_config.go +++ b/google-beta/services/identityplatform/resource_identity_platform_inbound_saml_config.go @@ -115,6 +115,7 @@ func ResourceIdentityPlatformInboundSamlConfig() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -235,6 +236,18 @@ and accept an authentication assertion issued by a SAML identity provider.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -381,6 +394,19 @@ func resourceIdentityPlatformInboundSamlConfigRead(d *schema.ResourceData, meta log.Printf("[DEBUG] Finished reading IdentityPlatformInboundSamlConfig %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading InboundSamlConfig: %s", err) } @@ -412,6 +438,19 @@ func resourceIdentityPlatformInboundSamlConfigRead(d *schema.ResourceData, meta } func resourceIdentityPlatformInboundSamlConfigUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceIdentityPlatformInboundSamlConfig().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceIdentityPlatformInboundSamlConfigRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -528,6 +567,13 @@ func resourceIdentityPlatformInboundSamlConfigUpdate(d *schema.ResourceData, met } func resourceIdentityPlatformInboundSamlConfigDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy IdentityPlatformInboundSamlConfig without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing InboundSamlConfig %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/identityplatform/resource_identity_platform_inbound_saml_config_generated_meta.yaml b/google-beta/services/identityplatform/resource_identity_platform_inbound_saml_config_generated_meta.yaml index cae4945e25d..166e27e675f 100644 --- a/google-beta/services/identityplatform/resource_identity_platform_inbound_saml_config_generated_meta.yaml +++ b/google-beta/services/identityplatform/resource_identity_platform_inbound_saml_config_generated_meta.yaml @@ -17,3 +17,5 @@ fields: - api_field: spConfig.callbackUri - api_field: spConfig.spCertificates.x509Certificate - api_field: spConfig.spEntityId + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/identityplatform/resource_identity_platform_oauth_idp_config.go b/google-beta/services/identityplatform/resource_identity_platform_oauth_idp_config.go index 8d97a07ff92..fe0f29fa2fb 100644 --- a/google-beta/services/identityplatform/resource_identity_platform_oauth_idp_config.go +++ b/google-beta/services/identityplatform/resource_identity_platform_oauth_idp_config.go @@ -115,6 +115,7 @@ func ResourceIdentityPlatformOauthIdpConfig() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -196,6 +197,18 @@ Setting both types to be simultaneously true ({code: true, idToken: true}) is no Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -354,6 +367,19 @@ func resourceIdentityPlatformOauthIdpConfigRead(d *schema.ResourceData, meta int log.Printf("[DEBUG] Finished reading IdentityPlatformOauthIdpConfig %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading OauthIdpConfig: %s", err) } @@ -385,6 +411,19 @@ func resourceIdentityPlatformOauthIdpConfigRead(d *schema.ResourceData, meta int } func resourceIdentityPlatformOauthIdpConfigUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceIdentityPlatformOauthIdpConfig().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceIdentityPlatformOauthIdpConfigRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -521,6 +560,13 @@ func resourceIdentityPlatformOauthIdpConfigUpdate(d *schema.ResourceData, meta i } func resourceIdentityPlatformOauthIdpConfigDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy IdentityPlatformOauthIdpConfig without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing OauthIdpConfig %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/identityplatform/resource_identity_platform_oauth_idp_config_generated_meta.yaml b/google-beta/services/identityplatform/resource_identity_platform_oauth_idp_config_generated_meta.yaml index 523b0fce467..88c17ecdba9 100644 --- a/google-beta/services/identityplatform/resource_identity_platform_oauth_idp_config_generated_meta.yaml +++ b/google-beta/services/identityplatform/resource_identity_platform_oauth_idp_config_generated_meta.yaml @@ -15,3 +15,5 @@ fields: - api_field: name - api_field: responseType.code - api_field: responseType.idToken + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/identityplatform/resource_identity_platform_tenant.go b/google-beta/services/identityplatform/resource_identity_platform_tenant.go index 0fc204f3f50..d7667129fdc 100644 --- a/google-beta/services/identityplatform/resource_identity_platform_tenant.go +++ b/google-beta/services/identityplatform/resource_identity_platform_tenant.go @@ -115,6 +115,7 @@ func ResourceIdentityPlatformTenant() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -200,6 +201,18 @@ are not able to manage its users.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -352,6 +365,19 @@ func resourceIdentityPlatformTenantRead(d *schema.ResourceData, meta interface{} log.Printf("[DEBUG] Finished reading IdentityPlatformTenant %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Tenant: %s", err) } @@ -383,6 +409,19 @@ func resourceIdentityPlatformTenantRead(d *schema.ResourceData, meta interface{} } func resourceIdentityPlatformTenantUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceIdentityPlatformTenant().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceIdentityPlatformTenantRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -509,6 +548,13 @@ func resourceIdentityPlatformTenantUpdate(d *schema.ResourceData, meta interface } func resourceIdentityPlatformTenantDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy IdentityPlatformTenant without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Tenant %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/identityplatform/resource_identity_platform_tenant_default_supported_idp_config.go b/google-beta/services/identityplatform/resource_identity_platform_tenant_default_supported_idp_config.go index 5b2c0e8d436..63f6e50ffa8 100644 --- a/google-beta/services/identityplatform/resource_identity_platform_tenant_default_supported_idp_config.go +++ b/google-beta/services/identityplatform/resource_identity_platform_tenant_default_supported_idp_config.go @@ -115,6 +115,7 @@ func ResourceIdentityPlatformTenantDefaultSupportedIdpConfig() *schema.Resource CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -199,6 +200,18 @@ func ResourceIdentityPlatformTenantDefaultSupportedIdpConfig() *schema.Resource Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -338,6 +351,19 @@ func resourceIdentityPlatformTenantDefaultSupportedIdpConfigRead(d *schema.Resou log.Printf("[DEBUG] Finished reading IdentityPlatformTenantDefaultSupportedIdpConfig %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading TenantDefaultSupportedIdpConfig: %s", err) } @@ -375,6 +401,19 @@ func resourceIdentityPlatformTenantDefaultSupportedIdpConfigRead(d *schema.Resou } func resourceIdentityPlatformTenantDefaultSupportedIdpConfigUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceIdentityPlatformTenantDefaultSupportedIdpConfig().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceIdentityPlatformTenantDefaultSupportedIdpConfigRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -486,6 +525,13 @@ func resourceIdentityPlatformTenantDefaultSupportedIdpConfigUpdate(d *schema.Res } func resourceIdentityPlatformTenantDefaultSupportedIdpConfigDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy IdentityPlatformTenantDefaultSupportedIdpConfig without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing TenantDefaultSupportedIdpConfig %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/identityplatform/resource_identity_platform_tenant_default_supported_idp_config_generated_meta.yaml b/google-beta/services/identityplatform/resource_identity_platform_tenant_default_supported_idp_config_generated_meta.yaml index e80bf237365..0f0d9377527 100644 --- a/google-beta/services/identityplatform/resource_identity_platform_tenant_default_supported_idp_config_generated_meta.yaml +++ b/google-beta/services/identityplatform/resource_identity_platform_tenant_default_supported_idp_config_generated_meta.yaml @@ -15,3 +15,5 @@ fields: - api_field: name - field: tenant provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/identityplatform/resource_identity_platform_tenant_generated_meta.yaml b/google-beta/services/identityplatform/resource_identity_platform_tenant_generated_meta.yaml index df36e0e45b2..ccf35ab3663 100644 --- a/google-beta/services/identityplatform/resource_identity_platform_tenant_generated_meta.yaml +++ b/google-beta/services/identityplatform/resource_identity_platform_tenant_generated_meta.yaml @@ -14,3 +14,5 @@ fields: - api_field: displayName - api_field: enableEmailLinkSignin - api_field: name + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/identityplatform/resource_identity_platform_tenant_inbound_saml_config.go b/google-beta/services/identityplatform/resource_identity_platform_tenant_inbound_saml_config.go index 81338f3c0b8..4f1f270817b 100644 --- a/google-beta/services/identityplatform/resource_identity_platform_tenant_inbound_saml_config.go +++ b/google-beta/services/identityplatform/resource_identity_platform_tenant_inbound_saml_config.go @@ -115,6 +115,7 @@ func ResourceIdentityPlatformTenantInboundSamlConfig() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -245,6 +246,18 @@ and accept an authentication assertion issued by a SAML identity provider.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -396,6 +409,19 @@ func resourceIdentityPlatformTenantInboundSamlConfigRead(d *schema.ResourceData, log.Printf("[DEBUG] Finished reading IdentityPlatformTenantInboundSamlConfig %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading TenantInboundSamlConfig: %s", err) } @@ -433,6 +459,19 @@ func resourceIdentityPlatformTenantInboundSamlConfigRead(d *schema.ResourceData, } func resourceIdentityPlatformTenantInboundSamlConfigUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceIdentityPlatformTenantInboundSamlConfig().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceIdentityPlatformTenantInboundSamlConfigRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -554,6 +593,13 @@ func resourceIdentityPlatformTenantInboundSamlConfigUpdate(d *schema.ResourceDat } func resourceIdentityPlatformTenantInboundSamlConfigDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy IdentityPlatformTenantInboundSamlConfig without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing TenantInboundSamlConfig %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/identityplatform/resource_identity_platform_tenant_inbound_saml_config_generated_meta.yaml b/google-beta/services/identityplatform/resource_identity_platform_tenant_inbound_saml_config_generated_meta.yaml index 4f96bf36ff1..7f237fcb2e0 100644 --- a/google-beta/services/identityplatform/resource_identity_platform_tenant_inbound_saml_config_generated_meta.yaml +++ b/google-beta/services/identityplatform/resource_identity_platform_tenant_inbound_saml_config_generated_meta.yaml @@ -19,3 +19,5 @@ fields: - api_field: spConfig.spEntityId - field: tenant provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/identityplatform/resource_identity_platform_tenant_oauth_idp_config.go b/google-beta/services/identityplatform/resource_identity_platform_tenant_oauth_idp_config.go index 89b55824d20..c2a722dd79e 100644 --- a/google-beta/services/identityplatform/resource_identity_platform_tenant_oauth_idp_config.go +++ b/google-beta/services/identityplatform/resource_identity_platform_tenant_oauth_idp_config.go @@ -115,6 +115,7 @@ func ResourceIdentityPlatformTenantOauthIdpConfig() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -184,6 +185,18 @@ func ResourceIdentityPlatformTenantOauthIdpConfig() *schema.Resource { Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -341,6 +354,19 @@ func resourceIdentityPlatformTenantOauthIdpConfigRead(d *schema.ResourceData, me log.Printf("[DEBUG] Finished reading IdentityPlatformTenantOauthIdpConfig %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading TenantOauthIdpConfig: %s", err) } @@ -378,6 +404,19 @@ func resourceIdentityPlatformTenantOauthIdpConfigRead(d *schema.ResourceData, me } func resourceIdentityPlatformTenantOauthIdpConfigUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceIdentityPlatformTenantOauthIdpConfig().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceIdentityPlatformTenantOauthIdpConfigRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -509,6 +548,13 @@ func resourceIdentityPlatformTenantOauthIdpConfigUpdate(d *schema.ResourceData, } func resourceIdentityPlatformTenantOauthIdpConfigDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy IdentityPlatformTenantOauthIdpConfig without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing TenantOauthIdpConfig %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/identityplatform/resource_identity_platform_tenant_oauth_idp_config_generated_meta.yaml b/google-beta/services/identityplatform/resource_identity_platform_tenant_oauth_idp_config_generated_meta.yaml index 2d53cdb85b3..118d5dbae95 100644 --- a/google-beta/services/identityplatform/resource_identity_platform_tenant_oauth_idp_config_generated_meta.yaml +++ b/google-beta/services/identityplatform/resource_identity_platform_tenant_oauth_idp_config_generated_meta.yaml @@ -15,3 +15,5 @@ fields: - api_field: name - field: tenant provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/integrationconnectors/resource_integration_connectors_connection.go b/google-beta/services/integrationconnectors/resource_integration_connectors_connection.go index aa7efd9eb6c..7bd95f327a4 100644 --- a/google-beta/services/integrationconnectors/resource_integration_connectors_connection.go +++ b/google-beta/services/integrationconnectors/resource_integration_connectors_connection.go @@ -135,6 +135,7 @@ func ResourceIntegrationConnectorsConnection() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -1211,6 +1212,18 @@ e.g. "projects/cloud-connectors-e2e-testing/locations/us-central1/namespaces/ist Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -1430,6 +1443,19 @@ func resourceIntegrationConnectorsConnectionRead(d *schema.ResourceData, meta in log.Printf("[DEBUG] Finished reading IntegrationConnectorsConnection %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Connection: %s", err) } @@ -1467,6 +1493,19 @@ func resourceIntegrationConnectorsConnectionRead(d *schema.ResourceData, meta in } func resourceIntegrationConnectorsConnectionUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceIntegrationConnectorsConnection().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceIntegrationConnectorsConnectionRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1698,6 +1737,13 @@ func resourceIntegrationConnectorsConnectionUpdate(d *schema.ResourceData, meta } func resourceIntegrationConnectorsConnectionDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy IntegrationConnectorsConnection without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Connection %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/integrationconnectors/resource_integration_connectors_connection_generated_meta.yaml b/google-beta/services/integrationconnectors/resource_integration_connectors_connection_generated_meta.yaml index f4bff54a517..b845f25babd 100644 --- a/google-beta/services/integrationconnectors/resource_integration_connectors_connection_generated_meta.yaml +++ b/google-beta/services/integrationconnectors/resource_integration_connectors_connection_generated_meta.yaml @@ -158,3 +158,5 @@ fields: - field: terraform_labels provider_only: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/integrationconnectors/resource_integration_connectors_endpoint_attachment.go b/google-beta/services/integrationconnectors/resource_integration_connectors_endpoint_attachment.go index 4bdf9beee77..e9a6b88a483 100644 --- a/google-beta/services/integrationconnectors/resource_integration_connectors_endpoint_attachment.go +++ b/google-beta/services/integrationconnectors/resource_integration_connectors_endpoint_attachment.go @@ -116,6 +116,7 @@ func ResourceIntegrationConnectorsEndpointAttachment() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -214,6 +215,18 @@ Please refer to the field 'effective_labels' for all of the labels present on th Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -369,6 +382,19 @@ func resourceIntegrationConnectorsEndpointAttachmentRead(d *schema.ResourceData, log.Printf("[DEBUG] Finished reading IntegrationConnectorsEndpointAttachment %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading EndpointAttachment: %s", err) } @@ -406,6 +432,19 @@ func resourceIntegrationConnectorsEndpointAttachmentRead(d *schema.ResourceData, } func resourceIntegrationConnectorsEndpointAttachmentUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceIntegrationConnectorsEndpointAttachment().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceIntegrationConnectorsEndpointAttachmentRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -524,6 +563,13 @@ func resourceIntegrationConnectorsEndpointAttachmentUpdate(d *schema.ResourceDat } func resourceIntegrationConnectorsEndpointAttachmentDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy IntegrationConnectorsEndpointAttachment without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing EndpointAttachment %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/integrationconnectors/resource_integration_connectors_endpoint_attachment_generated_meta.yaml b/google-beta/services/integrationconnectors/resource_integration_connectors_endpoint_attachment_generated_meta.yaml index c583494eae3..c18b8c104e5 100644 --- a/google-beta/services/integrationconnectors/resource_integration_connectors_endpoint_attachment_generated_meta.yaml +++ b/google-beta/services/integrationconnectors/resource_integration_connectors_endpoint_attachment_generated_meta.yaml @@ -22,3 +22,5 @@ fields: - field: terraform_labels provider_only: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/integrationconnectors/resource_integration_connectors_managed_zone.go b/google-beta/services/integrationconnectors/resource_integration_connectors_managed_zone.go index f7cb76082ac..5f3956bf2e2 100644 --- a/google-beta/services/integrationconnectors/resource_integration_connectors_managed_zone.go +++ b/google-beta/services/integrationconnectors/resource_integration_connectors_managed_zone.go @@ -116,6 +116,7 @@ func ResourceIntegrationConnectorsManagedZone() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -203,6 +204,18 @@ Please refer to the field 'effective_labels' for all of the labels present on th Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -359,6 +372,19 @@ func resourceIntegrationConnectorsManagedZoneRead(d *schema.ResourceData, meta i log.Printf("[DEBUG] Finished reading IntegrationConnectorsManagedZone %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading ManagedZone: %s", err) } @@ -390,6 +416,19 @@ func resourceIntegrationConnectorsManagedZoneRead(d *schema.ResourceData, meta i } func resourceIntegrationConnectorsManagedZoneUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceIntegrationConnectorsManagedZone().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceIntegrationConnectorsManagedZoneRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -523,6 +562,13 @@ func resourceIntegrationConnectorsManagedZoneUpdate(d *schema.ResourceData, meta } func resourceIntegrationConnectorsManagedZoneDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy IntegrationConnectorsManagedZone without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing ManagedZone %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/integrationconnectors/resource_integration_connectors_managed_zone_generated_meta.yaml b/google-beta/services/integrationconnectors/resource_integration_connectors_managed_zone_generated_meta.yaml index 9d4323177de..030d333140b 100644 --- a/google-beta/services/integrationconnectors/resource_integration_connectors_managed_zone_generated_meta.yaml +++ b/google-beta/services/integrationconnectors/resource_integration_connectors_managed_zone_generated_meta.yaml @@ -20,3 +20,5 @@ fields: - field: terraform_labels provider_only: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/integrations/resource_integrations_auth_config.go b/google-beta/services/integrations/resource_integrations_auth_config.go index 0ef860ae7bc..a464a22c12d 100644 --- a/google-beta/services/integrations/resource_integrations_auth_config.go +++ b/google-beta/services/integrations/resource_integrations_auth_config.go @@ -115,6 +115,7 @@ func ResourceIntegrationsAuthConfig() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -556,6 +557,18 @@ A timestamp in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to n Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -744,6 +757,19 @@ func resourceIntegrationsAuthConfigRead(d *schema.ResourceData, meta interface{} log.Printf("[DEBUG] Finished reading IntegrationsAuthConfig %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading AuthConfig: %s", err) } @@ -775,6 +801,19 @@ func resourceIntegrationsAuthConfigRead(d *schema.ResourceData, meta interface{} } func resourceIntegrationsAuthConfigUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceIntegrationsAuthConfig().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceIntegrationsAuthConfigRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -910,6 +949,13 @@ func resourceIntegrationsAuthConfigUpdate(d *schema.ResourceData, meta interface } func resourceIntegrationsAuthConfigDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy IntegrationsAuthConfig without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing AuthConfig %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/integrations/resource_integrations_auth_config_generated_meta.yaml b/google-beta/services/integrations/resource_integrations_auth_config_generated_meta.yaml index 8ae637ef7f2..617ea01aa3f 100644 --- a/google-beta/services/integrations/resource_integrations_auth_config_generated_meta.yaml +++ b/google-beta/services/integrations/resource_integrations_auth_config_generated_meta.yaml @@ -57,3 +57,5 @@ fields: - api_field: updateTime - api_field: validTime - api_field: visibility + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/integrations/resource_integrations_client.go b/google-beta/services/integrations/resource_integrations_client.go index f6d6819e090..52e43448018 100644 --- a/google-beta/services/integrations/resource_integrations_client.go +++ b/google-beta/services/integrations/resource_integrations_client.go @@ -100,6 +100,7 @@ func ResourceIntegrationsClient() *schema.Resource { return &schema.Resource{ Create: resourceIntegrationsClientCreate, Read: resourceIntegrationsClientRead, + Update: resourceIntegrationsClientUpdate, Delete: resourceIntegrationsClientDelete, Importer: &schema.ResourceImporter{ @@ -113,6 +114,7 @@ func ResourceIntegrationsClient() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -211,6 +213,18 @@ encrypted with GMEK.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -369,6 +383,19 @@ func resourceIntegrationsClientRead(d *schema.ResourceData, meta interface{}) er return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Client: %s", err) } @@ -399,7 +426,19 @@ func resourceIntegrationsClientRead(d *schema.ResourceData, meta interface{}) er return nil } +func resourceIntegrationsClientUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceIntegrationsClientRead(d, meta) +} + func resourceIntegrationsClientDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy IntegrationsClient without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Client %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/integrations/resource_integrations_client_generated_meta.yaml b/google-beta/services/integrations/resource_integrations_client_generated_meta.yaml index 3d8370ae2cf..f3e18a6fa91 100644 --- a/google-beta/services/integrations/resource_integrations_client_generated_meta.yaml +++ b/google-beta/services/integrations/resource_integrations_client_generated_meta.yaml @@ -16,3 +16,5 @@ fields: - field: location provider_only: true - api_field: runAsServiceAccount + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/kms/resource_kms_autokey_config.go b/google-beta/services/kms/resource_kms_autokey_config.go index ef2bc0f1eca..447a82d5d87 100644 --- a/google-beta/services/kms/resource_kms_autokey_config.go +++ b/google-beta/services/kms/resource_kms_autokey_config.go @@ -159,6 +159,19 @@ CryptoKey for any new KeyHandle the Developer creates. Should have the form Computed: true, Description: `The etag of the AutokeyConfig for optimistic concurrency control.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -278,6 +291,20 @@ func resourceKMSAutokeyConfigRead(d *schema.ResourceData, meta interface{}) erro log.Printf("[DEBUG] Finished reading KMSAutokeyConfig %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceKMSAutokeyConfigFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -299,6 +326,19 @@ func resourceKMSAutokeyConfigRead(d *schema.ResourceData, meta interface{}) erro } func resourceKMSAutokeyConfigUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceKMSAutokeyConfig().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceKMSAutokeyConfigRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -368,6 +408,13 @@ func resourceKMSAutokeyConfigUpdate(d *schema.ResourceData, meta interface{}) er } func resourceKMSAutokeyConfigDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy KMSAutokeyConfig without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing AutokeyConfig %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/kms/resource_kms_autokey_config_generated_meta.yaml b/google-beta/services/kms/resource_kms_autokey_config_generated_meta.yaml index 15619ca347a..3728ff55e4c 100644 --- a/google-beta/services/kms/resource_kms_autokey_config_generated_meta.yaml +++ b/google-beta/services/kms/resource_kms_autokey_config_generated_meta.yaml @@ -12,3 +12,5 @@ fields: provider_only: true - api_field: keyProject - api_field: keyProjectResolutionMode + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/kms/resource_kms_crypto_key.go b/google-beta/services/kms/resource_kms_crypto_key.go index f06f66e1018..fbe6e6c3369 100644 --- a/google-beta/services/kms/resource_kms_crypto_key.go +++ b/google-beta/services/kms/resource_kms_crypto_key.go @@ -124,6 +124,7 @@ func ResourceKMSCryptoKey() *schema.Resource { }, CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -305,6 +306,19 @@ Keys with purpose ENCRYPT_DECRYPT may have a primary. For other keys, this field and default labels configured on the provider.`, Elem: &schema.Schema{Type: schema.TypeString}, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -482,6 +496,20 @@ func resourceKMSCryptoKeyRead(d *schema.ResourceData, meta interface{}) error { return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceKMSCryptoKeyFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -509,6 +537,19 @@ func resourceKMSCryptoKeyRead(d *schema.ResourceData, meta interface{}) error { } func resourceKMSCryptoKeyUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceKMSCryptoKey().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceKMSCryptoKeyRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -628,6 +669,13 @@ func resourceKMSCryptoKeyUpdate(d *schema.ResourceData, meta interface{}) error } func resourceKMSCryptoKeyDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy KMSCryptoKey without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing CryptoKey %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/kms/resource_kms_crypto_key_generated_meta.yaml b/google-beta/services/kms/resource_kms_crypto_key_generated_meta.yaml index 816a03f2054..cf77ad79ded 100644 --- a/google-beta/services/kms/resource_kms_crypto_key_generated_meta.yaml +++ b/google-beta/services/kms/resource_kms_crypto_key_generated_meta.yaml @@ -28,3 +28,5 @@ fields: provider_only: true - api_field: versionTemplate.algorithm - api_field: versionTemplate.protectionLevel + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/kms/resource_kms_crypto_key_version.go b/google-beta/services/kms/resource_kms_crypto_key_version.go index eadf3d215b9..70fe181e870 100644 --- a/google-beta/services/kms/resource_kms_crypto_key_version.go +++ b/google-beta/services/kms/resource_kms_crypto_key_version.go @@ -259,6 +259,19 @@ Only provided for key versions with protectionLevel HSM.`, Computed: true, Description: `The ProtectionLevel describing how crypto operations are performed with this CryptoKeyVersion.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -376,6 +389,20 @@ func resourceKMSCryptoKeyVersionRead(d *schema.ResourceData, meta interface{}) e log.Printf("[DEBUG] Finished reading KMSCryptoKeyVersion %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceKMSCryptoKeyVersionFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -397,6 +424,19 @@ func resourceKMSCryptoKeyVersionRead(d *schema.ResourceData, meta interface{}) e } func resourceKMSCryptoKeyVersionUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceKMSCryptoKeyVersion().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceKMSCryptoKeyVersionRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -502,6 +542,13 @@ func resourceKMSCryptoKeyVersionUpdate(d *schema.ResourceData, meta interface{}) } func resourceKMSCryptoKeyVersionDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy KMSCryptoKeyVersion without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing CryptoKeyVersion %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/kms/resource_kms_crypto_key_version_generated_meta.yaml b/google-beta/services/kms/resource_kms_crypto_key_version_generated_meta.yaml index 23356784c18..1ce72b92a5d 100644 --- a/google-beta/services/kms/resource_kms_crypto_key_version_generated_meta.yaml +++ b/google-beta/services/kms/resource_kms_crypto_key_version_generated_meta.yaml @@ -23,3 +23,5 @@ fields: - api_field: name - api_field: protectionLevel - api_field: state + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/kms/resource_kms_ekm_connection.go b/google-beta/services/kms/resource_kms_ekm_connection.go index 6f1c894b588..aaa6b4a5277 100644 --- a/google-beta/services/kms/resource_kms_ekm_connection.go +++ b/google-beta/services/kms/resource_kms_ekm_connection.go @@ -459,6 +459,7 @@ func resourceKMSEkmConnectionRead(d *schema.ResourceData, meta interface{}) erro } func resourceKMSEkmConnectionUpdate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/kms/resource_kms_folder_kaj_policy_config.go b/google-beta/services/kms/resource_kms_folder_kaj_policy_config.go index bcd00f3a7c2..623fa6f06c1 100644 --- a/google-beta/services/kms/resource_kms_folder_kaj_policy_config.go +++ b/google-beta/services/kms/resource_kms_folder_kaj_policy_config.go @@ -289,6 +289,7 @@ func resourceKMSFolderKajPolicyConfigRead(d *schema.ResourceData, meta interface } func resourceKMSFolderKajPolicyConfigUpdate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/kms/resource_kms_key_ring_import_job.go b/google-beta/services/kms/resource_kms_key_ring_import_job.go index 03da585b41c..1a51f7acd1e 100644 --- a/google-beta/services/kms/resource_kms_key_ring_import_job.go +++ b/google-beta/services/kms/resource_kms_key_ring_import_job.go @@ -100,6 +100,7 @@ func ResourceKMSKeyRingImportJob() *schema.Resource { return &schema.Resource{ Create: resourceKMSKeyRingImportJobCreate, Read: resourceKMSKeyRingImportJobRead, + Update: resourceKMSKeyRingImportJobUpdate, Delete: resourceKMSKeyRingImportJobDelete, Importer: &schema.ResourceImporter{ @@ -209,6 +210,19 @@ for General Considerations and Textual Encoding of Subject Public Key Info.`, Computed: true, Description: `The current state of the ImportJob, indicating if it can be used.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -326,6 +340,20 @@ func resourceKMSKeyRingImportJobRead(d *schema.ResourceData, meta interface{}) e log.Printf("[DEBUG] Finished reading KMSKeyRingImportJob %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceKMSKeyRingImportJobFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -346,7 +374,19 @@ func resourceKMSKeyRingImportJobRead(d *schema.ResourceData, meta interface{}) e return nil } +func resourceKMSKeyRingImportJobUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceKMSKeyRingImportJobRead(d, meta) +} + func resourceKMSKeyRingImportJobDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy KMSKeyRingImportJob without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing KeyRingImportJob %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/kms/resource_kms_key_ring_import_job_generated_meta.yaml b/google-beta/services/kms/resource_kms_key_ring_import_job_generated_meta.yaml index e335c1804f3..83917720d85 100644 --- a/google-beta/services/kms/resource_kms_key_ring_import_job_generated_meta.yaml +++ b/google-beta/services/kms/resource_kms_key_ring_import_job_generated_meta.yaml @@ -21,3 +21,5 @@ fields: - api_field: protectionLevel - api_field: publicKey.pem - api_field: state + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/kms/resource_kms_organization_kaj_policy_config.go b/google-beta/services/kms/resource_kms_organization_kaj_policy_config.go index 0d33b767a65..58072969ab3 100644 --- a/google-beta/services/kms/resource_kms_organization_kaj_policy_config.go +++ b/google-beta/services/kms/resource_kms_organization_kaj_policy_config.go @@ -289,6 +289,7 @@ func resourceKMSOrganizationKajPolicyConfigRead(d *schema.ResourceData, meta int } func resourceKMSOrganizationKajPolicyConfigUpdate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/kms/resource_kms_project_autokey_config.go b/google-beta/services/kms/resource_kms_project_autokey_config.go index 51e6d56ac53..a6d401b7d39 100644 --- a/google-beta/services/kms/resource_kms_project_autokey_config.go +++ b/google-beta/services/kms/resource_kms_project_autokey_config.go @@ -115,6 +115,7 @@ func ResourceKMSProjectAutokeyConfig() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -150,6 +151,18 @@ func ResourceKMSProjectAutokeyConfig() *schema.Resource { Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -270,6 +283,19 @@ func resourceKMSProjectAutokeyConfigRead(d *schema.ResourceData, meta interface{ log.Printf("[DEBUG] Finished reading KMSProjectAutokeyConfig %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading ProjectAutokeyConfig: %s", err) } @@ -295,6 +321,19 @@ func resourceKMSProjectAutokeyConfigRead(d *schema.ResourceData, meta interface{ } func resourceKMSProjectAutokeyConfigUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceKMSProjectAutokeyConfig().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceKMSProjectAutokeyConfigRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -363,6 +402,13 @@ func resourceKMSProjectAutokeyConfigUpdate(d *schema.ResourceData, meta interfac } func resourceKMSProjectAutokeyConfigDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy KMSProjectAutokeyConfig without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing ProjectAutokeyConfig %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/kms/resource_kms_project_autokey_config_generated_meta.yaml b/google-beta/services/kms/resource_kms_project_autokey_config_generated_meta.yaml index 5fee24d5437..59410669667 100644 --- a/google-beta/services/kms/resource_kms_project_autokey_config_generated_meta.yaml +++ b/google-beta/services/kms/resource_kms_project_autokey_config_generated_meta.yaml @@ -9,3 +9,5 @@ api_resource_type_kind: ProjectAutokeyConfig fields: - api_field: etag - api_field: keyProjectResolutionMode + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/kms/resource_kms_project_kaj_policy_config.go b/google-beta/services/kms/resource_kms_project_kaj_policy_config.go index 7648ee21647..aecdd5f8950 100644 --- a/google-beta/services/kms/resource_kms_project_kaj_policy_config.go +++ b/google-beta/services/kms/resource_kms_project_kaj_policy_config.go @@ -309,6 +309,7 @@ func resourceKMSProjectKajPolicyConfigRead(d *schema.ResourceData, meta interfac } func resourceKMSProjectKajPolicyConfigUpdate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/logging/resource_logging_billing_account_bucket_config_meta.yaml b/google-beta/services/logging/resource_logging_billing_account_bucket_config_meta.yaml index 1211c1b1422..ea229ee0bc5 100644 --- a/google-beta/services/logging/resource_logging_billing_account_bucket_config_meta.yaml +++ b/google-beta/services/logging/resource_logging_billing_account_bucket_config_meta.yaml @@ -21,3 +21,6 @@ fields: - field: 'location' - api_field: 'name' - api_field: 'retentionDays' + - field: 'deletion_policy' + provider_only: true + \ No newline at end of file diff --git a/google-beta/services/logging/resource_logging_billing_account_sink.go b/google-beta/services/logging/resource_logging_billing_account_sink.go index 959274c916d..04f5cce3c78 100644 --- a/google-beta/services/logging/resource_logging_billing_account_sink.go +++ b/google-beta/services/logging/resource_logging_billing_account_sink.go @@ -19,6 +19,7 @@ package logging import ( "fmt" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-google-beta/google-beta/registry" "github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource" @@ -35,6 +36,9 @@ func ResourceLoggingBillingAccountSink() *schema.Resource { Importer: &schema.ResourceImporter{ State: resourceLoggingSinkImportState("billing_account"), }, + CustomizeDiff: customdiff.All( + tpgresource.DefaultProviderDeletionPolicy("DELETE"), + ), UseJSONNumber: true, } schm.Schema["billing_account"] = &schema.Schema{ @@ -81,10 +85,19 @@ func resourceLoggingBillingAccountSinkRead(d *schema.ResourceData, meta interfac return err } + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + return nil } func resourceLoggingBillingAccountSinkUpdate(d *schema.ResourceData, meta interface{}) error { + + if tpgresource.DeletionPolicyPreUpdate(d, ResourceLoggingBillingAccountSink) { + return ResourceLoggingBillingAccountSink().Read(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -104,6 +117,13 @@ func resourceLoggingBillingAccountSinkUpdate(d *schema.ResourceData, meta interf } func resourceLoggingBillingAccountSinkDelete(d *schema.ResourceData, meta interface{}) error { + + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { + return nil + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/logging/resource_logging_billing_account_sink_meta.yaml b/google-beta/services/logging/resource_logging_billing_account_sink_meta.yaml index 99455776efa..11371d082d4 100644 --- a/google-beta/services/logging/resource_logging_billing_account_sink_meta.yaml +++ b/google-beta/services/logging/resource_logging_billing_account_sink_meta.yaml @@ -20,3 +20,5 @@ fields: - api_field: 'filter' - api_field: 'name' - api_field: 'writerIdentity' + - field: 'deletion_policy' + provider_only: true diff --git a/google-beta/services/logging/resource_logging_bucket_config.go b/google-beta/services/logging/resource_logging_bucket_config.go index 1ea06753017..099d6b1dc23 100644 --- a/google-beta/services/logging/resource_logging_bucket_config.go +++ b/google-beta/services/logging/resource_logging_bucket_config.go @@ -128,6 +128,9 @@ For example: jsonPayload.request.status`, }, }, }, + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end } type loggingBucketConfigIDFunc func(d *schema.ResourceData, config *transport_tpg.Config) (string, error) @@ -146,6 +149,7 @@ func ResourceLoggingBucketConfig(parentType string, parentSpecificSchema map[str Schema: tpgresource.MergeSchemas(loggingBucketConfigSchema, parentSpecificSchema), UseJSONNumber: true, CustomizeDiff: customdiff.All( + tpgresource.DefaultProviderDeletionPolicy("DELETE"), tpgresource.DefaultProviderProject, ), } @@ -335,10 +339,29 @@ func resourceLoggingBucketConfigRead(d *schema.ResourceData, meta interface{}) e return fmt.Errorf("Error setting index_configs: %s", err) } + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + return nil } func resourceLoggingBucketConfigUpdate(d *schema.ResourceData, meta interface{}) error { + + //due to non standard resource function, Universal Deletion Policy pre-update code is included here in entirety + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range loggingBucketConfigSchema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceLoggingBucketConfigRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -392,6 +415,13 @@ func resourceLoggingBucketConfigUpdate(d *schema.ResourceData, meta interface{}) } func resourceLoggingBucketConfigDelete(d *schema.ResourceData, meta interface{}) error { + + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { + return nil + } + name := d.Get("bucket_id") for _, restrictedName := range []string{"_Required", "_Default"} { if name == restrictedName { diff --git a/google-beta/services/logging/resource_logging_folder_bucket_config_meta.yaml b/google-beta/services/logging/resource_logging_folder_bucket_config_meta.yaml index d8d91d750d3..7c733f060ca 100644 --- a/google-beta/services/logging/resource_logging_folder_bucket_config_meta.yaml +++ b/google-beta/services/logging/resource_logging_folder_bucket_config_meta.yaml @@ -21,3 +21,5 @@ fields: - field: 'location' - api_field: 'name' - api_field: 'retentionDays' + - field: 'deletion_policy' + provider_only: true diff --git a/google-beta/services/logging/resource_logging_folder_settings.go b/google-beta/services/logging/resource_logging_folder_settings.go index 8d39648c028..563bea0ce9b 100644 --- a/google-beta/services/logging/resource_logging_folder_settings.go +++ b/google-beta/services/logging/resource_logging_folder_settings.go @@ -306,6 +306,7 @@ func resourceLoggingFolderSettingsRead(d *schema.ResourceData, meta interface{}) } func resourceLoggingFolderSettingsUpdate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/logging/resource_logging_folder_sink.go b/google-beta/services/logging/resource_logging_folder_sink.go index ce42e65abf7..119575fb12d 100644 --- a/google-beta/services/logging/resource_logging_folder_sink.go +++ b/google-beta/services/logging/resource_logging_folder_sink.go @@ -20,6 +20,7 @@ import ( "fmt" "strings" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-google-beta/google-beta/registry" "github.com/hashicorp/terraform-provider-google-beta/google-beta/services/resourcemanager" @@ -34,6 +35,9 @@ func ResourceLoggingFolderSink() *schema.Resource { Delete: resourceLoggingFolderSinkDelete, Update: resourceLoggingFolderSinkUpdate, Schema: resourceLoggingSinkSchema(), + CustomizeDiff: customdiff.All( + tpgresource.DefaultProviderDeletionPolicy("DELETE"), + ), Importer: &schema.ResourceImporter{ State: resourceLoggingSinkImportState("folder"), }, @@ -110,10 +114,19 @@ func resourceLoggingFolderSinkRead(d *schema.ResourceData, meta interface{}) err return fmt.Errorf("Error setting intercept_children: %s", err) } + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + return nil } func resourceLoggingFolderSinkUpdate(d *schema.ResourceData, meta interface{}) error { + + if tpgresource.DeletionPolicyPreUpdate(d, ResourceLoggingFolderSink) { + return ResourceLoggingFolderSink().Read(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -133,6 +146,13 @@ func resourceLoggingFolderSinkUpdate(d *schema.ResourceData, meta interface{}) e } func resourceLoggingFolderSinkDelete(d *schema.ResourceData, meta interface{}) error { + + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { + return nil + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/logging/resource_logging_folder_sink_meta.yaml b/google-beta/services/logging/resource_logging_folder_sink_meta.yaml index 2a4d670ceeb..7ae43082df9 100644 --- a/google-beta/services/logging/resource_logging_folder_sink_meta.yaml +++ b/google-beta/services/logging/resource_logging_folder_sink_meta.yaml @@ -22,3 +22,5 @@ fields: - api_field: 'interceptChildren' - api_field: 'name' - api_field: 'writerIdentity' + - field: 'deletion_policy' + provider_only: true diff --git a/google-beta/services/logging/resource_logging_linked_dataset.go b/google-beta/services/logging/resource_logging_linked_dataset.go index cae55422cfa..a2f9e135ef9 100644 --- a/google-beta/services/logging/resource_logging_linked_dataset.go +++ b/google-beta/services/logging/resource_logging_linked_dataset.go @@ -100,6 +100,7 @@ func ResourceLoggingLinkedDataset() *schema.Resource { return &schema.Resource{ Create: resourceLoggingLinkedDatasetCreate, Read: resourceLoggingLinkedDatasetRead, + Update: resourceLoggingLinkedDatasetUpdate, Delete: resourceLoggingLinkedDatasetDelete, Importer: &schema.ResourceImporter{ @@ -211,6 +212,19 @@ and "2014-10-02T15:01:23.045123456Z".`, Description: `The resource name of the linked dataset. The name can have up to 100 characters. A valid link id (at the end of the link name) must only have alphanumeric characters and underscores within it.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -346,6 +360,20 @@ func resourceLoggingLinkedDatasetRead(d *schema.ResourceData, meta interface{}) log.Printf("[DEBUG] Finished reading LoggingLinkedDataset %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceLoggingLinkedDatasetFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -384,7 +412,19 @@ func resourceLoggingLinkedDatasetRead(d *schema.ResourceData, meta interface{}) return nil } +func resourceLoggingLinkedDatasetUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceLoggingLinkedDatasetRead(d, meta) +} + func resourceLoggingLinkedDatasetDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy LoggingLinkedDataset without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing LinkedDataset %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/logging/resource_logging_linked_dataset_generated_meta.yaml b/google-beta/services/logging/resource_logging_linked_dataset_generated_meta.yaml index 5f6477302ad..c20afd52af6 100644 --- a/google-beta/services/logging/resource_logging_linked_dataset_generated_meta.yaml +++ b/google-beta/services/logging/resource_logging_linked_dataset_generated_meta.yaml @@ -25,3 +25,5 @@ fields: - api_field: name - field: parent provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/logging/resource_logging_log_scope.go b/google-beta/services/logging/resource_logging_log_scope.go index 4bba1cf68f5..2ccc4e1fff7 100644 --- a/google-beta/services/logging/resource_logging_log_scope.go +++ b/google-beta/services/logging/resource_logging_log_scope.go @@ -182,6 +182,19 @@ func ResourceLoggingLogScope() *schema.Resource { Computed: true, Description: `Output only. The last update timestamp of the log scopes.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -314,6 +327,20 @@ func resourceLoggingLogScopeRead(d *schema.ResourceData, meta interface{}) error log.Printf("[DEBUG] Finished reading LoggingLogScope %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceLoggingLogScopeFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -347,6 +374,19 @@ func resourceLoggingLogScopeRead(d *schema.ResourceData, meta interface{}) error } func resourceLoggingLogScopeUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceLoggingLogScope().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceLoggingLogScopeRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -447,6 +487,13 @@ func resourceLoggingLogScopeUpdate(d *schema.ResourceData, meta interface{}) err } func resourceLoggingLogScopeDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy LoggingLogScope without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing LogScope %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/logging/resource_logging_log_scope_generated_meta.yaml b/google-beta/services/logging/resource_logging_log_scope_generated_meta.yaml index 7b3edea19bd..2befaa0a59e 100644 --- a/google-beta/services/logging/resource_logging_log_scope_generated_meta.yaml +++ b/google-beta/services/logging/resource_logging_log_scope_generated_meta.yaml @@ -16,3 +16,5 @@ fields: provider_only: true - api_field: resourceNames - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/logging/resource_logging_log_view.go b/google-beta/services/logging/resource_logging_log_view.go index 313fe1a535e..702a93ef732 100644 --- a/google-beta/services/logging/resource_logging_log_view.go +++ b/google-beta/services/logging/resource_logging_log_view.go @@ -190,6 +190,19 @@ func ResourceLoggingLogView() *schema.Resource { Computed: true, Description: `Output only. The last update timestamp of the view.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -332,6 +345,20 @@ func resourceLoggingLogViewRead(d *schema.ResourceData, meta interface{}) error log.Printf("[DEBUG] Finished reading LoggingLogView %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceLoggingLogViewFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -371,6 +398,19 @@ func resourceLoggingLogViewRead(d *schema.ResourceData, meta interface{}) error } func resourceLoggingLogViewUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceLoggingLogView().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceLoggingLogViewRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -476,6 +516,13 @@ func resourceLoggingLogViewUpdate(d *schema.ResourceData, meta interface{}) erro } func resourceLoggingLogViewDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy LoggingLogView without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing LogView %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/logging/resource_logging_log_view_generated_meta.yaml b/google-beta/services/logging/resource_logging_log_view_generated_meta.yaml index 6e9056859c0..c032eea8c8e 100644 --- a/google-beta/services/logging/resource_logging_log_view_generated_meta.yaml +++ b/google-beta/services/logging/resource_logging_log_view_generated_meta.yaml @@ -23,3 +23,5 @@ fields: - field: parent provider_only: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/logging/resource_logging_metric.go b/google-beta/services/logging/resource_logging_metric.go index 43be03c5c35..dbc29780211 100644 --- a/google-beta/services/logging/resource_logging_metric.go +++ b/google-beta/services/logging/resource_logging_metric.go @@ -115,6 +115,7 @@ func ResourceLoggingMetric() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -334,6 +335,18 @@ error to specify a regex that does not include exactly one capture group.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -537,6 +550,19 @@ func resourceLoggingMetricRead(d *schema.ResourceData, meta interface{}) error { log.Printf("[DEBUG] Finished reading LoggingMetric %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Metric: %s", err) } @@ -568,6 +594,19 @@ func resourceLoggingMetricRead(d *schema.ResourceData, meta interface{}) error { } func resourceLoggingMetricUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceLoggingMetric().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceLoggingMetricRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -694,6 +733,13 @@ func resourceLoggingMetricUpdate(d *schema.ResourceData, meta interface{}) error } func resourceLoggingMetricDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy LoggingMetric without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Metric %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/logging/resource_logging_metric_generated_meta.yaml b/google-beta/services/logging/resource_logging_metric_generated_meta.yaml index efb046f5063..83e22f36da7 100644 --- a/google-beta/services/logging/resource_logging_metric_generated_meta.yaml +++ b/google-beta/services/logging/resource_logging_metric_generated_meta.yaml @@ -30,3 +30,5 @@ fields: - api_field: metricDescriptor.valueType - api_field: name - api_field: valueExtractor + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/logging/resource_logging_organization_bucket_config_meta.yaml b/google-beta/services/logging/resource_logging_organization_bucket_config_meta.yaml index 8667dde986e..97e15038147 100644 --- a/google-beta/services/logging/resource_logging_organization_bucket_config_meta.yaml +++ b/google-beta/services/logging/resource_logging_organization_bucket_config_meta.yaml @@ -21,3 +21,5 @@ fields: - api_field: 'name' - field: 'organization' - api_field: 'retentionDays' + - field: 'deletion_policy' + provider_only: true diff --git a/google-beta/services/logging/resource_logging_organization_settings.go b/google-beta/services/logging/resource_logging_organization_settings.go index c26c9fc907e..d6186bf851e 100644 --- a/google-beta/services/logging/resource_logging_organization_settings.go +++ b/google-beta/services/logging/resource_logging_organization_settings.go @@ -306,6 +306,7 @@ func resourceLoggingOrganizationSettingsRead(d *schema.ResourceData, meta interf } func resourceLoggingOrganizationSettingsUpdate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/logging/resource_logging_organization_sink.go b/google-beta/services/logging/resource_logging_organization_sink.go index 795fcf852f5..6701c25c9e1 100644 --- a/google-beta/services/logging/resource_logging_organization_sink.go +++ b/google-beta/services/logging/resource_logging_organization_sink.go @@ -20,6 +20,7 @@ import ( "fmt" "strings" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-google-beta/google-beta/registry" "github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource" @@ -33,6 +34,9 @@ func ResourceLoggingOrganizationSink() *schema.Resource { Delete: resourceLoggingOrganizationSinkDelete, Update: resourceLoggingOrganizationSinkUpdate, Schema: resourceLoggingSinkSchema(), + CustomizeDiff: customdiff.All( + tpgresource.DefaultProviderDeletionPolicy("DELETE"), + ), Importer: &schema.ResourceImporter{ State: resourceLoggingSinkImportState("org_id"), }, @@ -109,10 +113,19 @@ func resourceLoggingOrganizationSinkRead(d *schema.ResourceData, meta interface{ return fmt.Errorf("Error setting intercept_children: %s", err) } + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + return nil } func resourceLoggingOrganizationSinkUpdate(d *schema.ResourceData, meta interface{}) error { + + if tpgresource.DeletionPolicyPreUpdate(d, ResourceLoggingOrganizationSink) { + return ResourceLoggingOrganizationSink().Read(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -132,6 +145,13 @@ func resourceLoggingOrganizationSinkUpdate(d *schema.ResourceData, meta interfac } func resourceLoggingOrganizationSinkDelete(d *schema.ResourceData, meta interface{}) error { + + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { + return nil + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/logging/resource_logging_organization_sink_meta.yaml b/google-beta/services/logging/resource_logging_organization_sink_meta.yaml index c751e7ccf9d..635287352af 100644 --- a/google-beta/services/logging/resource_logging_organization_sink_meta.yaml +++ b/google-beta/services/logging/resource_logging_organization_sink_meta.yaml @@ -22,3 +22,5 @@ fields: - api_field: 'name' - field: 'org_id' - api_field: 'writerIdentity' + - field: 'deletion_policy' + provider_only: true diff --git a/google-beta/services/logging/resource_logging_project_bucket_config.go b/google-beta/services/logging/resource_logging_project_bucket_config.go index 96d9b5ec9b5..21d1363912c 100644 --- a/google-beta/services/logging/resource_logging_project_bucket_config.go +++ b/google-beta/services/logging/resource_logging_project_bucket_config.go @@ -145,6 +145,9 @@ For example: jsonPayload.request.status`, }, }, }, + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end } func projectBucketConfigID(d *schema.ResourceData, config *transport_tpg.Config) (string, error) { diff --git a/google-beta/services/logging/resource_logging_project_bucket_config_meta.yaml b/google-beta/services/logging/resource_logging_project_bucket_config_meta.yaml index 982aef8e507..7403d543e2c 100644 --- a/google-beta/services/logging/resource_logging_project_bucket_config_meta.yaml +++ b/google-beta/services/logging/resource_logging_project_bucket_config_meta.yaml @@ -23,3 +23,6 @@ fields: - api_field: 'name' - field: 'project' - api_field: 'retentionDays' + - field: 'deletion_policy' + provider_only: true + \ No newline at end of file diff --git a/google-beta/services/logging/resource_logging_project_sink.go b/google-beta/services/logging/resource_logging_project_sink.go index ae03833a531..cbdf9e3528e 100644 --- a/google-beta/services/logging/resource_logging_project_sink.go +++ b/google-beta/services/logging/resource_logging_project_sink.go @@ -26,6 +26,7 @@ import ( "github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource" transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) @@ -33,12 +34,15 @@ const nonUniqueWriterAccount = "serviceAccount:cloud-logs@system.gserviceaccount func ResourceLoggingProjectSink() *schema.Resource { schm := &schema.Resource{ - Create: resourceLoggingProjectSinkAcquireOrCreate, - Read: resourceLoggingProjectSinkRead, - Delete: resourceLoggingProjectSinkDelete, - Update: resourceLoggingProjectSinkUpdate, - Schema: resourceLoggingSinkSchema(), - CustomizeDiff: resourceLoggingProjectSinkCustomizeDiff, + Create: resourceLoggingProjectSinkAcquireOrCreate, + Read: resourceLoggingProjectSinkRead, + Delete: resourceLoggingProjectSinkDelete, + Update: resourceLoggingProjectSinkUpdate, + Schema: resourceLoggingSinkSchema(), + CustomizeDiff: customdiff.All( + resourceLoggingProjectSinkCustomizeDiff, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), + ), Importer: &schema.ResourceImporter{ State: resourceLoggingSinkImportState("project"), }, @@ -187,10 +191,20 @@ func resourceLoggingProjectSinkRead(d *schema.ResourceData, meta interface{}) er return fmt.Errorf("Error setting unique_writer_identity: %s", err) } } + + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + return nil } func resourceLoggingProjectSinkUpdate(d *schema.ResourceData, meta interface{}) error { + + if tpgresource.DeletionPolicyPreUpdate(d, ResourceLoggingProjectSink) { + return ResourceLoggingProjectSink().Read(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -221,6 +235,13 @@ func resourceLoggingProjectSinkUpdate(d *schema.ResourceData, meta interface{}) } func resourceLoggingProjectSinkDelete(d *schema.ResourceData, meta interface{}) error { + + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { + return nil + } + name := d.Get("name") for _, restrictedName := range []string{"_Required", "_Default"} { if name == restrictedName { diff --git a/google-beta/services/logging/resource_logging_project_sink_meta.yaml b/google-beta/services/logging/resource_logging_project_sink_meta.yaml index 39a4e687f97..6ce97512beb 100644 --- a/google-beta/services/logging/resource_logging_project_sink_meta.yaml +++ b/google-beta/services/logging/resource_logging_project_sink_meta.yaml @@ -22,3 +22,5 @@ fields: - field: 'project' - field: 'unique_writer_identity' - api_field: 'writerIdentity' + - field: 'deletion_policy' + provider_only: true diff --git a/google-beta/services/logging/resource_logging_saved_query.go b/google-beta/services/logging/resource_logging_saved_query.go index 8c9f034245e..a3aca13b473 100644 --- a/google-beta/services/logging/resource_logging_saved_query.go +++ b/google-beta/services/logging/resource_logging_saved_query.go @@ -241,6 +241,19 @@ is used to match log entries.`, Computed: true, Description: `Output only. The last update timestamp of the saved query.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -380,6 +393,20 @@ func resourceLoggingSavedQueryRead(d *schema.ResourceData, meta interface{}) err log.Printf("[DEBUG] Finished reading LoggingSavedQuery %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceLoggingSavedQueryFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -413,6 +440,19 @@ func resourceLoggingSavedQueryRead(d *schema.ResourceData, meta interface{}) err } func resourceLoggingSavedQueryUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceLoggingSavedQuery().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceLoggingSavedQueryRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -538,6 +578,13 @@ func resourceLoggingSavedQueryUpdate(d *schema.ResourceData, meta interface{}) e } func resourceLoggingSavedQueryDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy LoggingSavedQuery without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing SavedQuery %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/logging/resource_logging_saved_query_generated_meta.yaml b/google-beta/services/logging/resource_logging_saved_query_generated_meta.yaml index b1077d9f619..5d3260c4f36 100644 --- a/google-beta/services/logging/resource_logging_saved_query_generated_meta.yaml +++ b/google-beta/services/logging/resource_logging_saved_query_generated_meta.yaml @@ -28,3 +28,5 @@ fields: provider_only: true - api_field: updateTime - api_field: visibility + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/logging/resource_logging_sink.go b/google-beta/services/logging/resource_logging_sink.go index 98a2077f307..31b360edf67 100644 --- a/google-beta/services/logging/resource_logging_sink.go +++ b/google-beta/services/logging/resource_logging_sink.go @@ -20,6 +20,8 @@ import ( "fmt" "strings" + "github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "google.golang.org/api/logging/v2" ) @@ -116,6 +118,10 @@ func resourceLoggingSinkSchema() map[string]*schema.Schema { }, }, }, + + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end } } diff --git a/google-beta/services/looker/resource_looker_instance.go b/google-beta/services/looker/resource_looker_instance.go index 680d8678b77..7601b24d9fb 100644 --- a/google-beta/services/looker/resource_looker_instance.go +++ b/google-beta/services/looker/resource_looker_instance.go @@ -115,6 +115,7 @@ func ResourceLookerInstance() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DEFAULT"), ), Identity: &schema.ResourceIdentity{ @@ -679,21 +680,18 @@ accurate to nanoseconds.`, Description: `The time the instance was updated in RFC3339 UTC "Zulu" format, accurate to nanoseconds.`, }, - "deletion_policy": { - Type: schema.TypeString, - Optional: true, - Description: `Policy to determine if the cluster should be deleted forcefully. -If setting deletion_policy = "FORCE", the Looker instance will be deleted regardless -of its nested resources. If set to "DEFAULT", Looker instances that still have -nested resources will return an error. Possible values: DEFAULT, FORCE`, - Default: "DEFAULT", - }, "project": { Type: schema.TypeString, Optional: true, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `This field uses a custom implementation please refer to documentation under /hashicorp/terraform-provider-google-beta/website/docs/r/looker_instance.html.markdown for specifics`, + }, }, UseJSONNumber: true, } @@ -943,8 +941,15 @@ func resourceLookerInstanceRead(d *schema.ResourceData, meta interface{}) error // Explicitly set virtual fields to default values if unset if _, ok := d.GetOkExists("deletion_policy"); !ok { - if err := d.Set("deletion_policy", "DEFAULT"); err != nil { - return fmt.Errorf("Error setting deletion_policy: %s", err) + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DEFAULT"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } } } if err := d.Set("project", project); err != nil { @@ -984,6 +989,19 @@ func resourceLookerInstanceRead(d *schema.ResourceData, meta interface{}) error } func resourceLookerInstanceUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceLookerInstance().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceLookerInstanceRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1255,6 +1273,13 @@ func resourceLookerInstanceUpdate(d *schema.ResourceData, meta interface{}) erro } func resourceLookerInstanceDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy LookerInstance without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Instance %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1333,9 +1358,6 @@ func resourceLookerInstanceImport(d *schema.ResourceData, meta interface{}) ([]* d.SetId(id) // Explicitly set virtual fields to default values on import - if err := d.Set("deletion_policy", "DEFAULT"); err != nil { - return nil, fmt.Errorf("Error setting deletion_policy: %s", err) - } return []*schema.ResourceData{d}, nil } diff --git a/google-beta/services/looker/resource_looker_instance_generated_meta.yaml b/google-beta/services/looker/resource_looker_instance_generated_meta.yaml index d9592572511..2da5bcb692b 100644 --- a/google-beta/services/looker/resource_looker_instance_generated_meta.yaml +++ b/google-beta/services/looker/resource_looker_instance_generated_meta.yaml @@ -15,8 +15,6 @@ fields: - api_field: createTime - api_field: customDomain.domain - api_field: customDomain.state - - field: deletion_policy - provider_only: true - api_field: denyMaintenancePeriod.endDate.day - api_field: denyMaintenancePeriod.endDate.month - api_field: denyMaintenancePeriod.endDate.year @@ -68,3 +66,5 @@ fields: - api_field: userMetadata.additionalDeveloperUserCount - api_field: userMetadata.additionalStandardUserCount - api_field: userMetadata.additionalViewerUserCount + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/lustre/resource_lustre_instance.go b/google-beta/services/lustre/resource_lustre_instance.go index 420a1f64ce1..ca65d775e94 100644 --- a/google-beta/services/lustre/resource_lustre_instance.go +++ b/google-beta/services/lustre/resource_lustre_instance.go @@ -116,6 +116,7 @@ func ResourceLustreInstance() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -628,6 +629,18 @@ squash uid.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -831,6 +844,19 @@ func resourceLustreInstanceRead(d *schema.ResourceData, meta interface{}) error log.Printf("[DEBUG] Finished reading LustreInstance %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Instance: %s", err) } @@ -868,6 +894,19 @@ func resourceLustreInstanceRead(d *schema.ResourceData, meta interface{}) error } func resourceLustreInstanceUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceLustreInstance().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceLustreInstanceRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1026,6 +1065,13 @@ func resourceLustreInstanceUpdate(d *schema.ResourceData, meta interface{}) erro } func resourceLustreInstanceDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy LustreInstance without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Instance %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/lustre/resource_lustre_instance_generated_meta.yaml b/google-beta/services/lustre/resource_lustre_instance_generated_meta.yaml index 3f49b3267c5..f98edab761b 100644 --- a/google-beta/services/lustre/resource_lustre_instance_generated_meta.yaml +++ b/google-beta/services/lustre/resource_lustre_instance_generated_meta.yaml @@ -56,3 +56,5 @@ fields: - api_field: upcomingMaintenanceSchedule.endTime - api_field: upcomingMaintenanceSchedule.startTime - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/managedkafka/resource_managed_kafka_acl.go b/google-beta/services/managedkafka/resource_managed_kafka_acl.go index c7e12e3dd26..65f9d119fd0 100644 --- a/google-beta/services/managedkafka/resource_managed_kafka_acl.go +++ b/google-beta/services/managedkafka/resource_managed_kafka_acl.go @@ -115,6 +115,7 @@ func ResourceManagedKafkaAcl() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -211,6 +212,18 @@ truncated due to repeated field limits.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -386,6 +399,19 @@ func resourceManagedKafkaAclRead(d *schema.ResourceData, meta interface{}) error log.Printf("[DEBUG] Finished reading ManagedKafkaAcl %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Acl: %s", err) } @@ -429,6 +455,19 @@ func resourceManagedKafkaAclRead(d *schema.ResourceData, meta interface{}) error } func resourceManagedKafkaAclUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceManagedKafkaAcl().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceManagedKafkaAclRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -539,6 +578,13 @@ func resourceManagedKafkaAclUpdate(d *schema.ResourceData, meta interface{}) err } func resourceManagedKafkaAclDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ManagedKafkaAcl without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Acl %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/managedkafka/resource_managed_kafka_acl_generated_meta.yaml b/google-beta/services/managedkafka/resource_managed_kafka_acl_generated_meta.yaml index bc8c4e4c7b3..145a839327e 100644 --- a/google-beta/services/managedkafka/resource_managed_kafka_acl_generated_meta.yaml +++ b/google-beta/services/managedkafka/resource_managed_kafka_acl_generated_meta.yaml @@ -22,3 +22,5 @@ fields: - api_field: patternType - api_field: resourceName - api_field: resourceType + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/managedkafka/resource_managed_kafka_cluster.go b/google-beta/services/managedkafka/resource_managed_kafka_cluster.go index efc735114c3..baa84dfa30b 100644 --- a/google-beta/services/managedkafka/resource_managed_kafka_cluster.go +++ b/google-beta/services/managedkafka/resource_managed_kafka_cluster.go @@ -116,6 +116,7 @@ func ResourceManagedKafkaCluster() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -335,6 +336,18 @@ Please refer to the field 'effective_labels' for all of the labels present on th Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -502,6 +515,19 @@ func resourceManagedKafkaClusterRead(d *schema.ResourceData, meta interface{}) e log.Printf("[DEBUG] Finished reading ManagedKafkaCluster %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Cluster: %s", err) } @@ -539,6 +565,19 @@ func resourceManagedKafkaClusterRead(d *schema.ResourceData, meta interface{}) e } func resourceManagedKafkaClusterUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceManagedKafkaCluster().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceManagedKafkaClusterRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -687,6 +726,13 @@ func resourceManagedKafkaClusterUpdate(d *schema.ResourceData, meta interface{}) } func resourceManagedKafkaClusterDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ManagedKafkaCluster without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Cluster %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/managedkafka/resource_managed_kafka_cluster_generated_meta.yaml b/google-beta/services/managedkafka/resource_managed_kafka_cluster_generated_meta.yaml index c0af10e393b..8d0ff473187 100644 --- a/google-beta/services/managedkafka/resource_managed_kafka_cluster_generated_meta.yaml +++ b/google-beta/services/managedkafka/resource_managed_kafka_cluster_generated_meta.yaml @@ -29,3 +29,5 @@ fields: - api_field: tlsConfig.sslPrincipalMappingRules - api_field: tlsConfig.trustConfig.casConfigs.caPool - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/managedkafka/resource_managed_kafka_connect_cluster.go b/google-beta/services/managedkafka/resource_managed_kafka_connect_cluster.go index 7c95162a1f9..dcf25f85d58 100644 --- a/google-beta/services/managedkafka/resource_managed_kafka_connect_cluster.go +++ b/google-beta/services/managedkafka/resource_managed_kafka_connect_cluster.go @@ -116,6 +116,7 @@ func ResourceManagedKafkaConnectCluster() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -279,6 +280,18 @@ Please refer to the field 'effective_labels' for all of the labels present on th Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -434,6 +447,19 @@ func resourceManagedKafkaConnectClusterRead(d *schema.ResourceData, meta interfa log.Printf("[DEBUG] Finished reading ManagedKafkaConnectCluster %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading ConnectCluster: %s", err) } @@ -471,6 +497,19 @@ func resourceManagedKafkaConnectClusterRead(d *schema.ResourceData, meta interfa } func resourceManagedKafkaConnectClusterUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceManagedKafkaConnectCluster().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceManagedKafkaConnectClusterRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -599,6 +638,13 @@ func resourceManagedKafkaConnectClusterUpdate(d *schema.ResourceData, meta inter } func resourceManagedKafkaConnectClusterDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ManagedKafkaConnectCluster without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing ConnectCluster %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/managedkafka/resource_managed_kafka_connect_cluster_generated_meta.yaml b/google-beta/services/managedkafka/resource_managed_kafka_connect_cluster_generated_meta.yaml index 362e6aa3baa..1044bc2f11d 100644 --- a/google-beta/services/managedkafka/resource_managed_kafka_connect_cluster_generated_meta.yaml +++ b/google-beta/services/managedkafka/resource_managed_kafka_connect_cluster_generated_meta.yaml @@ -26,3 +26,5 @@ fields: - field: terraform_labels provider_only: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/managedkafka/resource_managed_kafka_connector.go b/google-beta/services/managedkafka/resource_managed_kafka_connector.go index 5d858591682..0a08173fb78 100644 --- a/google-beta/services/managedkafka/resource_managed_kafka_connector.go +++ b/google-beta/services/managedkafka/resource_managed_kafka_connector.go @@ -115,6 +115,7 @@ func ResourceManagedKafkaConnector() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -207,6 +208,18 @@ A duration in seconds with up to nine fractional digits, terminated by 's'. Exam Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -345,6 +358,19 @@ func resourceManagedKafkaConnectorRead(d *schema.ResourceData, meta interface{}) log.Printf("[DEBUG] Finished reading ManagedKafkaConnector %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Connector: %s", err) } @@ -388,6 +414,19 @@ func resourceManagedKafkaConnectorRead(d *schema.ResourceData, meta interface{}) } func resourceManagedKafkaConnectorUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceManagedKafkaConnector().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceManagedKafkaConnectorRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -494,6 +533,13 @@ func resourceManagedKafkaConnectorUpdate(d *schema.ResourceData, meta interface{ } func resourceManagedKafkaConnectorDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ManagedKafkaConnector without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Connector %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/managedkafka/resource_managed_kafka_connector_generated_meta.yaml b/google-beta/services/managedkafka/resource_managed_kafka_connector_generated_meta.yaml index 3dabfc54b27..c44c7eb5f17 100644 --- a/google-beta/services/managedkafka/resource_managed_kafka_connector_generated_meta.yaml +++ b/google-beta/services/managedkafka/resource_managed_kafka_connector_generated_meta.yaml @@ -18,3 +18,5 @@ fields: - api_field: state - api_field: taskRestartPolicy.maximumBackoff - api_field: taskRestartPolicy.minimumBackoff + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/managedkafka/resource_managed_kafka_topic.go b/google-beta/services/managedkafka/resource_managed_kafka_topic.go index feac9d7d98e..4a3c1ccebd3 100644 --- a/google-beta/services/managedkafka/resource_managed_kafka_topic.go +++ b/google-beta/services/managedkafka/resource_managed_kafka_topic.go @@ -115,6 +115,7 @@ func ResourceManagedKafkaTopic() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -191,6 +192,18 @@ func ResourceManagedKafkaTopic() *schema.Resource { Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -340,6 +353,19 @@ func resourceManagedKafkaTopicRead(d *schema.ResourceData, meta interface{}) err log.Printf("[DEBUG] Finished reading ManagedKafkaTopic %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Topic: %s", err) } @@ -383,6 +409,19 @@ func resourceManagedKafkaTopicRead(d *schema.ResourceData, meta interface{}) err } func resourceManagedKafkaTopicUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceManagedKafkaTopic().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceManagedKafkaTopicRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -493,6 +532,13 @@ func resourceManagedKafkaTopicUpdate(d *schema.ResourceData, meta interface{}) e } func resourceManagedKafkaTopicDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ManagedKafkaTopic without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Topic %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/managedkafka/resource_managed_kafka_topic_generated_meta.yaml b/google-beta/services/managedkafka/resource_managed_kafka_topic_generated_meta.yaml index 45d8ba917cc..7f7dbc8dbc2 100644 --- a/google-beta/services/managedkafka/resource_managed_kafka_topic_generated_meta.yaml +++ b/google-beta/services/managedkafka/resource_managed_kafka_topic_generated_meta.yaml @@ -18,3 +18,5 @@ fields: - api_field: replicationFactor - field: topic_id provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/memcache/resource_memcache_instance.go b/google-beta/services/memcache/resource_memcache_instance.go index 4a41ca266bf..02e9160fc24 100644 --- a/google-beta/services/memcache/resource_memcache_instance.go +++ b/google-beta/services/memcache/resource_memcache_instance.go @@ -116,6 +116,7 @@ func ResourceMemcacheInstance() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -468,6 +469,18 @@ When the field is set to false, deleting the instance is allowed.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -660,6 +673,18 @@ func resourceMemcacheInstanceRead(d *schema.ResourceData, meta interface{}) erro log.Printf("[DEBUG] Finished reading MemcacheInstance %q: %#v", d.Id(), res) // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Instance: %s", err) } @@ -697,6 +722,19 @@ func resourceMemcacheInstanceRead(d *schema.ResourceData, meta interface{}) erro } func resourceMemcacheInstanceUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceMemcacheInstance().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceMemcacheInstanceRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -874,6 +912,13 @@ func resourceMemcacheInstanceUpdate(d *schema.ResourceData, meta interface{}) er } func resourceMemcacheInstanceDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy MemcacheInstance without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Instance %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/memcache/resource_memcache_instance_generated_meta.yaml b/google-beta/services/memcache/resource_memcache_instance_generated_meta.yaml index 128ef6d2249..10da105a94f 100644 --- a/google-beta/services/memcache/resource_memcache_instance_generated_meta.yaml +++ b/google-beta/services/memcache/resource_memcache_instance_generated_meta.yaml @@ -50,3 +50,5 @@ fields: - field: terraform_labels provider_only: true - api_field: zones + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/memorystore/resource_memorystore_instance.go b/google-beta/services/memorystore/resource_memorystore_instance.go index c76c65adf95..8afe6574087 100644 --- a/google-beta/services/memorystore/resource_memorystore_instance.go +++ b/google-beta/services/memorystore/resource_memorystore_instance.go @@ -130,6 +130,7 @@ func ResourceMemorystoreInstance() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -1096,6 +1097,18 @@ projects/{project_id}/global/networks/{network_id}.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -1371,6 +1384,18 @@ func resourceMemorystoreInstanceRead(d *schema.ResourceData, meta interface{}) e } // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Instance: %s", err) } @@ -1408,6 +1433,19 @@ func resourceMemorystoreInstanceRead(d *schema.ResourceData, meta interface{}) e } func resourceMemorystoreInstanceUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceMemorystoreInstance().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceMemorystoreInstanceRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1621,6 +1659,13 @@ func resourceMemorystoreInstanceUpdate(d *schema.ResourceData, meta interface{}) } func resourceMemorystoreInstanceDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy MemorystoreInstance without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Instance %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/memorystore/resource_memorystore_instance_desired_user_created_endpoints.go b/google-beta/services/memorystore/resource_memorystore_instance_desired_user_created_endpoints.go index 4cf08635f88..e232578771f 100644 --- a/google-beta/services/memorystore/resource_memorystore_instance_desired_user_created_endpoints.go +++ b/google-beta/services/memorystore/resource_memorystore_instance_desired_user_created_endpoints.go @@ -115,6 +115,7 @@ func ResourceMemorystoreInstanceDesiredUserCreatedEndpoints() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -238,6 +239,18 @@ service attachment.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -375,6 +388,19 @@ func resourceMemorystoreInstanceDesiredUserCreatedEndpointsRead(d *schema.Resour log.Printf("[DEBUG] Finished reading MemorystoreInstanceDesiredUserCreatedEndpoints %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading InstanceDesiredUserCreatedEndpoints: %s", err) } @@ -412,6 +438,19 @@ func resourceMemorystoreInstanceDesiredUserCreatedEndpointsRead(d *schema.Resour } func resourceMemorystoreInstanceDesiredUserCreatedEndpointsUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceMemorystoreInstanceDesiredUserCreatedEndpoints().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceMemorystoreInstanceDesiredUserCreatedEndpointsRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -510,6 +549,13 @@ func resourceMemorystoreInstanceDesiredUserCreatedEndpointsUpdate(d *schema.Reso } func resourceMemorystoreInstanceDesiredUserCreatedEndpointsDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy MemorystoreInstanceDesiredUserCreatedEndpoints without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing InstanceDesiredUserCreatedEndpoints %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/memorystore/resource_memorystore_instance_desired_user_created_endpoints_generated_meta.yaml b/google-beta/services/memorystore/resource_memorystore_instance_desired_user_created_endpoints_generated_meta.yaml index ce0cb3d2762..6807bceea47 100644 --- a/google-beta/services/memorystore/resource_memorystore_instance_desired_user_created_endpoints_generated_meta.yaml +++ b/google-beta/services/memorystore/resource_memorystore_instance_desired_user_created_endpoints_generated_meta.yaml @@ -27,3 +27,5 @@ fields: provider_only: true - field: region provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/memorystore/resource_memorystore_instance_generated_meta.yaml b/google-beta/services/memorystore/resource_memorystore_instance_generated_meta.yaml index 925b035dd53..52107dfb30c 100644 --- a/google-beta/services/memorystore/resource_memorystore_instance_generated_meta.yaml +++ b/google-beta/services/memorystore/resource_memorystore_instance_generated_meta.yaml @@ -105,3 +105,5 @@ fields: - api_field: updateTime - api_field: zoneDistributionConfig.mode - api_field: zoneDistributionConfig.zone + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/migrationcenter/resource_migration_center_group.go b/google-beta/services/migrationcenter/resource_migration_center_group.go index f478a0aeeb0..bf177dbbc87 100644 --- a/google-beta/services/migrationcenter/resource_migration_center_group.go +++ b/google-beta/services/migrationcenter/resource_migration_center_group.go @@ -116,6 +116,7 @@ func ResourceMigrationCenterGroup() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -207,6 +208,18 @@ Please refer to the field 'effective_labels' for all of the labels present on th Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -356,6 +369,19 @@ func resourceMigrationCenterGroupRead(d *schema.ResourceData, meta interface{}) log.Printf("[DEBUG] Finished reading MigrationCenterGroup %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Group: %s", err) } @@ -393,6 +419,19 @@ func resourceMigrationCenterGroupRead(d *schema.ResourceData, meta interface{}) } func resourceMigrationCenterGroupUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceMigrationCenterGroup().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceMigrationCenterGroupRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -511,6 +550,13 @@ func resourceMigrationCenterGroupUpdate(d *schema.ResourceData, meta interface{} } func resourceMigrationCenterGroupDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy MigrationCenterGroup without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Group %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/migrationcenter/resource_migration_center_group_generated_meta.yaml b/google-beta/services/migrationcenter/resource_migration_center_group_generated_meta.yaml index 0e0d1d7c976..d4b3303743e 100644 --- a/google-beta/services/migrationcenter/resource_migration_center_group_generated_meta.yaml +++ b/google-beta/services/migrationcenter/resource_migration_center_group_generated_meta.yaml @@ -22,3 +22,5 @@ fields: - field: terraform_labels provider_only: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/migrationcenter/resource_migration_center_preference_set.go b/google-beta/services/migrationcenter/resource_migration_center_preference_set.go index 64ad6ac3f31..10916fe6ed7 100644 --- a/google-beta/services/migrationcenter/resource_migration_center_preference_set.go +++ b/google-beta/services/migrationcenter/resource_migration_center_preference_set.go @@ -115,6 +115,7 @@ func ResourceMigrationCenterPreferenceSet() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -341,6 +342,18 @@ func ResourceMigrationCenterPreferenceSet() *schema.Resource { Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -490,6 +503,19 @@ func resourceMigrationCenterPreferenceSetRead(d *schema.ResourceData, meta inter log.Printf("[DEBUG] Finished reading MigrationCenterPreferenceSet %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading PreferenceSet: %s", err) } @@ -527,6 +553,19 @@ func resourceMigrationCenterPreferenceSetRead(d *schema.ResourceData, meta inter } func resourceMigrationCenterPreferenceSetUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceMigrationCenterPreferenceSet().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceMigrationCenterPreferenceSetRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -645,6 +684,13 @@ func resourceMigrationCenterPreferenceSetUpdate(d *schema.ResourceData, meta int } func resourceMigrationCenterPreferenceSetDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy MigrationCenterPreferenceSet without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing PreferenceSet %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/migrationcenter/resource_migration_center_preference_set_generated_meta.yaml b/google-beta/services/migrationcenter/resource_migration_center_preference_set_generated_meta.yaml index 630fb96114f..51abf1c9528 100644 --- a/google-beta/services/migrationcenter/resource_migration_center_preference_set_generated_meta.yaml +++ b/google-beta/services/migrationcenter/resource_migration_center_preference_set_generated_meta.yaml @@ -32,3 +32,5 @@ fields: - api_field: virtualMachinePreferences.vmwareEnginePreferences.cpuOvercommitRatio - api_field: virtualMachinePreferences.vmwareEnginePreferences.memoryOvercommitRatio - api_field: virtualMachinePreferences.vmwareEnginePreferences.storageDeduplicationCompressionRatio + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/mlengine/resource_ml_engine_model.go b/google-beta/services/mlengine/resource_ml_engine_model.go index eb316614d30..1895f04a467 100644 --- a/google-beta/services/mlengine/resource_ml_engine_model.go +++ b/google-beta/services/mlengine/resource_ml_engine_model.go @@ -125,6 +125,7 @@ func ResourceMLEngineModel() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), DeprecationMessage: "This resource is deprecated at the API level and will be removed in a future version of Terraform.", @@ -231,6 +232,18 @@ Currently only one region per model is supported`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -389,6 +402,19 @@ func resourceMLEngineModelRead(d *schema.ResourceData, meta interface{}) error { log.Printf("[DEBUG] Finished reading MLEngineModel %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Model: %s", err) } @@ -420,11 +446,18 @@ func resourceMLEngineModelRead(d *schema.ResourceData, meta interface{}) error { } func resourceMLEngineModelUpdate(d *schema.ResourceData, meta interface{}) error { - // Only the root field "labels", "terraform_labels", and virtual fields are mutable + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable return resourceMLEngineModelRead(d, meta) } func resourceMLEngineModelDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy MLEngineModel without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Model %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/mlengine/resource_ml_engine_model_generated_meta.yaml b/google-beta/services/mlengine/resource_ml_engine_model_generated_meta.yaml index cb7ecac16a3..300af75825c 100644 --- a/google-beta/services/mlengine/resource_ml_engine_model_generated_meta.yaml +++ b/google-beta/services/mlengine/resource_ml_engine_model_generated_meta.yaml @@ -18,3 +18,5 @@ fields: - api_field: regions - field: terraform_labels provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/modelarmor/resource_model_armor_template.go b/google-beta/services/modelarmor/resource_model_armor_template.go index c5b52d62e7a..ab129273055 100644 --- a/google-beta/services/modelarmor/resource_model_armor_template.go +++ b/google-beta/services/modelarmor/resource_model_armor_template.go @@ -116,6 +116,7 @@ func ResourceModelArmorTemplate() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -425,6 +426,18 @@ INSPECT_AND_BLOCK`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -564,6 +577,19 @@ func resourceModelArmorTemplateRead(d *schema.ResourceData, meta interface{}) er log.Printf("[DEBUG] Finished reading ModelArmorTemplate %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Template: %s", err) } @@ -601,6 +627,19 @@ func resourceModelArmorTemplateRead(d *schema.ResourceData, meta interface{}) er } func resourceModelArmorTemplateUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceModelArmorTemplate().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceModelArmorTemplateRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -712,6 +751,13 @@ func resourceModelArmorTemplateUpdate(d *schema.ResourceData, meta interface{}) } func resourceModelArmorTemplateDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ModelArmorTemplate without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Template %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/modelarmor/resource_model_armor_template_generated_meta.yaml b/google-beta/services/modelarmor/resource_model_armor_template_generated_meta.yaml index 1ef5eb01443..a9ddcc02d6c 100644 --- a/google-beta/services/modelarmor/resource_model_armor_template_generated_meta.yaml +++ b/google-beta/services/modelarmor/resource_model_armor_template_generated_meta.yaml @@ -37,3 +37,5 @@ fields: - field: terraform_labels provider_only: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/modelarmorglobal/resource_model_armor_floorsetting.go b/google-beta/services/modelarmorglobal/resource_model_armor_floorsetting.go index 048f47445ef..c0ec6523964 100644 --- a/google-beta/services/modelarmorglobal/resource_model_armor_floorsetting.go +++ b/google-beta/services/modelarmorglobal/resource_model_armor_floorsetting.go @@ -591,6 +591,7 @@ func resourceModelArmorGlobalFloorsettingRead(d *schema.ResourceData, meta inter } func resourceModelArmorGlobalFloorsettingUpdate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/monitoring/resource_monitoring_alert_policy.go b/google-beta/services/monitoring/resource_monitoring_alert_policy.go index bf61e42602b..2bc5d11e866 100644 --- a/google-beta/services/monitoring/resource_monitoring_alert_policy.go +++ b/google-beta/services/monitoring/resource_monitoring_alert_policy.go @@ -120,6 +120,7 @@ func ResourceMonitoringAlertPolicy() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -1301,6 +1302,18 @@ Its syntax is: projects/[PROJECT_ID]/alertPolicies/[ALERT_POLICY_ID]`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -1488,6 +1501,19 @@ func resourceMonitoringAlertPolicyRead(d *schema.ResourceData, meta interface{}) log.Printf("[DEBUG] Finished reading MonitoringAlertPolicy %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading AlertPolicy: %s", err) } @@ -1519,6 +1545,19 @@ func resourceMonitoringAlertPolicyRead(d *schema.ResourceData, meta interface{}) } func resourceMonitoringAlertPolicyUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceMonitoringAlertPolicy().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceMonitoringAlertPolicyRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1694,6 +1733,13 @@ func resourceMonitoringAlertPolicyUpdate(d *schema.ResourceData, meta interface{ } func resourceMonitoringAlertPolicyDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy MonitoringAlertPolicy without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing AlertPolicy %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/monitoring/resource_monitoring_alert_policy_generated_meta.yaml b/google-beta/services/monitoring/resource_monitoring_alert_policy_generated_meta.yaml index a9b462c921c..c540c0a0c56 100644 --- a/google-beta/services/monitoring/resource_monitoring_alert_policy_generated_meta.yaml +++ b/google-beta/services/monitoring/resource_monitoring_alert_policy_generated_meta.yaml @@ -79,3 +79,5 @@ fields: - api_field: notificationChannels - api_field: severity - api_field: userLabels + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/monitoring/resource_monitoring_custom_service.go b/google-beta/services/monitoring/resource_monitoring_custom_service.go index cc0da8e8974..018ef280e46 100644 --- a/google-beta/services/monitoring/resource_monitoring_custom_service.go +++ b/google-beta/services/monitoring/resource_monitoring_custom_service.go @@ -115,6 +115,7 @@ func ResourceMonitoringService() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -191,6 +192,18 @@ projects/[PROJECT_ID]/services/[SERVICE_ID].`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -344,6 +357,19 @@ func resourceMonitoringServiceRead(d *schema.ResourceData, meta interface{}) err log.Printf("[DEBUG] Finished reading MonitoringService %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Service: %s", err) } @@ -375,6 +401,19 @@ func resourceMonitoringServiceRead(d *schema.ResourceData, meta interface{}) err } func resourceMonitoringServiceUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceMonitoringService().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceMonitoringServiceRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -487,6 +526,13 @@ func resourceMonitoringServiceUpdate(d *schema.ResourceData, meta interface{}) e } func resourceMonitoringServiceDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy MonitoringService without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Service %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/monitoring/resource_monitoring_custom_service_generated_meta.yaml b/google-beta/services/monitoring/resource_monitoring_custom_service_generated_meta.yaml index e234e21bf35..c5b9bac792d 100644 --- a/google-beta/services/monitoring/resource_monitoring_custom_service_generated_meta.yaml +++ b/google-beta/services/monitoring/resource_monitoring_custom_service_generated_meta.yaml @@ -13,3 +13,5 @@ fields: field: service_id - api_field: telemetry.resourceName - api_field: userLabels + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/monitoring/resource_monitoring_dashboard.go b/google-beta/services/monitoring/resource_monitoring_dashboard.go index 09915c3d3a4..ede122f9be3 100644 --- a/google-beta/services/monitoring/resource_monitoring_dashboard.go +++ b/google-beta/services/monitoring/resource_monitoring_dashboard.go @@ -92,6 +92,7 @@ func ResourceMonitoringDashboard() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Schema: map[string]*schema.Schema{ @@ -113,6 +114,9 @@ func ResourceMonitoringDashboard() *schema.Resource { ForceNew: true, Description: `The ID of the project in which the resource belongs. If it is not provided, the provider project is used.`, }, + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end }, UseJSONNumber: true, } @@ -200,10 +204,19 @@ func resourceMonitoringDashboardRead(d *schema.ResourceData, meta interface{}) e return fmt.Errorf("Error reading Dashboard: %s", err) } + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + return nil } func resourceMonitoringDashboardUpdate(d *schema.ResourceData, meta interface{}) error { + + if tpgresource.DeletionPolicyPreUpdate(d, ResourceMonitoringDashboard) { + return ResourceMonitoringDashboard().Read(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -246,6 +259,13 @@ func resourceMonitoringDashboardUpdate(d *schema.ResourceData, meta interface{}) } func resourceMonitoringDashboardDelete(d *schema.ResourceData, meta interface{}) error { + + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { + return nil + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/monitoring/resource_monitoring_dashboard_meta.yaml b/google-beta/services/monitoring/resource_monitoring_dashboard_meta.yaml index eb4c23be8dc..9fcc29636cf 100644 --- a/google-beta/services/monitoring/resource_monitoring_dashboard_meta.yaml +++ b/google-beta/services/monitoring/resource_monitoring_dashboard_meta.yaml @@ -10,3 +10,5 @@ fields: api_field: '*' json: true - field: 'project' + - field: 'deletion_policy' + provider_only: true diff --git a/google-beta/services/monitoring/resource_monitoring_group.go b/google-beta/services/monitoring/resource_monitoring_group.go index 0636c831acf..2d51aa79d92 100644 --- a/google-beta/services/monitoring/resource_monitoring_group.go +++ b/google-beta/services/monitoring/resource_monitoring_group.go @@ -115,6 +115,7 @@ func ResourceMonitoringGroup() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -176,6 +177,18 @@ groups with no parent, parentName is the empty string, "".`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -331,6 +344,19 @@ func resourceMonitoringGroupRead(d *schema.ResourceData, meta interface{}) error log.Printf("[DEBUG] Finished reading MonitoringGroup %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Group: %s", err) } @@ -362,6 +388,19 @@ func resourceMonitoringGroupRead(d *schema.ResourceData, meta interface{}) error } func resourceMonitoringGroupUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceMonitoringGroup().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceMonitoringGroupRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -459,6 +498,13 @@ func resourceMonitoringGroupUpdate(d *schema.ResourceData, meta interface{}) err } func resourceMonitoringGroupDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy MonitoringGroup without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Group %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/monitoring/resource_monitoring_group_generated_meta.yaml b/google-beta/services/monitoring/resource_monitoring_group_generated_meta.yaml index 6eb9a6a080e..e44b9ebeb50 100644 --- a/google-beta/services/monitoring/resource_monitoring_group_generated_meta.yaml +++ b/google-beta/services/monitoring/resource_monitoring_group_generated_meta.yaml @@ -12,3 +12,5 @@ fields: - api_field: isCluster - api_field: name - api_field: parentName + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/monitoring/resource_monitoring_metric_descriptor.go b/google-beta/services/monitoring/resource_monitoring_metric_descriptor.go index 16da40178ad..07c0c9b7f6d 100644 --- a/google-beta/services/monitoring/resource_monitoring_metric_descriptor.go +++ b/google-beta/services/monitoring/resource_monitoring_metric_descriptor.go @@ -115,6 +115,7 @@ func ResourceMonitoringMetricDescriptor() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -248,6 +249,18 @@ More info can be found in the API documentation Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -497,6 +510,19 @@ func resourceMonitoringMetricDescriptorRead(d *schema.ResourceData, meta interfa log.Printf("[DEBUG] Finished reading MonitoringMetricDescriptor %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading MetricDescriptor: %s", err) } @@ -528,6 +554,19 @@ func resourceMonitoringMetricDescriptorRead(d *schema.ResourceData, meta interfa } func resourceMonitoringMetricDescriptorUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceMonitoringMetricDescriptor().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceMonitoringMetricDescriptorRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -653,6 +692,13 @@ func resourceMonitoringMetricDescriptorUpdate(d *schema.ResourceData, meta inter } func resourceMonitoringMetricDescriptorDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy MonitoringMetricDescriptor without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing MetricDescriptor %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/monitoring/resource_monitoring_metric_descriptor_generated_meta.yaml b/google-beta/services/monitoring/resource_monitoring_metric_descriptor_generated_meta.yaml index aff92ee7396..d877ac597c5 100644 --- a/google-beta/services/monitoring/resource_monitoring_metric_descriptor_generated_meta.yaml +++ b/google-beta/services/monitoring/resource_monitoring_metric_descriptor_generated_meta.yaml @@ -21,3 +21,5 @@ fields: - api_field: type - api_field: unit - api_field: valueType + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/monitoring/resource_monitoring_monitored_project.go b/google-beta/services/monitoring/resource_monitoring_monitored_project.go index 90a9aa12e5c..bf770f3bdad 100644 --- a/google-beta/services/monitoring/resource_monitoring_monitored_project.go +++ b/google-beta/services/monitoring/resource_monitoring_monitored_project.go @@ -133,6 +133,7 @@ func ResourceMonitoringMonitoredProject() *schema.Resource { return &schema.Resource{ Create: resourceMonitoringMonitoredProjectCreate, Read: resourceMonitoringMonitoredProjectRead, + Update: resourceMonitoringMonitoredProjectUpdate, Delete: resourceMonitoringMonitoredProjectDelete, Importer: &schema.ResourceImporter{ @@ -174,6 +175,19 @@ func ResourceMonitoringMonitoredProject() *schema.Resource { Computed: true, Description: `Output only. The time when this 'MonitoredProject' was created.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -307,6 +321,20 @@ func resourceMonitoringMonitoredProjectRead(d *schema.ResourceData, meta interfa return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceMonitoringMonitoredProjectFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -315,7 +343,19 @@ func resourceMonitoringMonitoredProjectRead(d *schema.ResourceData, meta interfa return nil } +func resourceMonitoringMonitoredProjectUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceMonitoringMonitoredProjectRead(d, meta) +} + func resourceMonitoringMonitoredProjectDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy MonitoringMonitoredProject without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing MonitoredProject %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/monitoring/resource_monitoring_monitored_project_generated_meta.yaml b/google-beta/services/monitoring/resource_monitoring_monitored_project_generated_meta.yaml index fb01b57555d..cec55f0c794 100644 --- a/google-beta/services/monitoring/resource_monitoring_monitored_project_generated_meta.yaml +++ b/google-beta/services/monitoring/resource_monitoring_monitored_project_generated_meta.yaml @@ -11,3 +11,5 @@ fields: - field: metrics_scope provider_only: true - api_field: name + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/monitoring/resource_monitoring_notification_channel.go b/google-beta/services/monitoring/resource_monitoring_notification_channel.go index af79f5ea348..765be3f4091 100644 --- a/google-beta/services/monitoring/resource_monitoring_notification_channel.go +++ b/google-beta/services/monitoring/resource_monitoring_notification_channel.go @@ -132,6 +132,7 @@ func ResourceMonitoringNotificationChannel() *schema.Resource { CustomizeDiff: customdiff.All( sensitiveLabelCustomizeDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -296,6 +297,18 @@ deleted in a delete operation.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -487,6 +500,18 @@ func resourceMonitoringNotificationChannelRead(d *schema.ResourceData, meta inte return fmt.Errorf("Error setting force_delete: %s", err) } } + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading NotificationChannel: %s", err) } @@ -512,6 +537,19 @@ func resourceMonitoringNotificationChannelRead(d *schema.ResourceData, meta inte } func resourceMonitoringNotificationChannelUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceMonitoringNotificationChannel().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceMonitoringNotificationChannelRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -627,6 +665,13 @@ func resourceMonitoringNotificationChannelUpdate(d *schema.ResourceData, meta in } func resourceMonitoringNotificationChannelDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy MonitoringNotificationChannel without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing NotificationChannel %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/monitoring/resource_monitoring_notification_channel_generated_meta.yaml b/google-beta/services/monitoring/resource_monitoring_notification_channel_generated_meta.yaml index 7cb52ae15e3..250dd776158 100644 --- a/google-beta/services/monitoring/resource_monitoring_notification_channel_generated_meta.yaml +++ b/google-beta/services/monitoring/resource_monitoring_notification_channel_generated_meta.yaml @@ -32,3 +32,5 @@ fields: - api_field: type - api_field: userLabels - api_field: verificationStatus + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/monitoring/resource_monitoring_service.go b/google-beta/services/monitoring/resource_monitoring_service.go index 026d2123fd3..82daddcc4fe 100644 --- a/google-beta/services/monitoring/resource_monitoring_service.go +++ b/google-beta/services/monitoring/resource_monitoring_service.go @@ -115,6 +115,7 @@ func ResourceMonitoringGenericService() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -215,6 +216,18 @@ https://cloud.google.com/apis/design/resource_names.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -351,6 +364,19 @@ func resourceMonitoringGenericServiceRead(d *schema.ResourceData, meta interface log.Printf("[DEBUG] Finished reading MonitoringGenericService %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading GenericService: %s", err) } @@ -382,6 +408,19 @@ func resourceMonitoringGenericServiceRead(d *schema.ResourceData, meta interface } func resourceMonitoringGenericServiceUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceMonitoringGenericService().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceMonitoringGenericServiceRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -479,6 +518,13 @@ func resourceMonitoringGenericServiceUpdate(d *schema.ResourceData, meta interfa } func resourceMonitoringGenericServiceDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy MonitoringGenericService without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing GenericService %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/monitoring/resource_monitoring_service_generated_meta.yaml b/google-beta/services/monitoring/resource_monitoring_service_generated_meta.yaml index 4aea653c3ed..b9d96489359 100644 --- a/google-beta/services/monitoring/resource_monitoring_service_generated_meta.yaml +++ b/google-beta/services/monitoring/resource_monitoring_service_generated_meta.yaml @@ -15,3 +15,5 @@ fields: provider_only: true - api_field: telemetry.resourceName - api_field: userLabels + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/monitoring/resource_monitoring_slo.go b/google-beta/services/monitoring/resource_monitoring_slo.go index eaa793da5d4..e1349777ced 100644 --- a/google-beta/services/monitoring/resource_monitoring_slo.go +++ b/google-beta/services/monitoring/resource_monitoring_slo.go @@ -130,6 +130,7 @@ func ResourceMonitoringSlo() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -825,6 +826,18 @@ projects/[PROJECT_ID_OR_NUMBER]/services/[SERVICE_ID]/serviceLevelObjectives/[SL Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -1001,6 +1014,19 @@ func resourceMonitoringSloRead(d *schema.ResourceData, meta interface{}) error { log.Printf("[DEBUG] Finished reading MonitoringSlo %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Slo: %s", err) } @@ -1032,6 +1058,19 @@ func resourceMonitoringSloRead(d *schema.ResourceData, meta interface{}) error { } func resourceMonitoringSloUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceMonitoringSlo().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceMonitoringSloRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1204,6 +1243,13 @@ func resourceMonitoringSloUpdate(d *schema.ResourceData, meta interface{}) error } func resourceMonitoringSloDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy MonitoringSlo without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Slo %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/monitoring/resource_monitoring_slo_generated_meta.yaml b/google-beta/services/monitoring/resource_monitoring_slo_generated_meta.yaml index 9b3dc9988ec..41a3d95f7ef 100644 --- a/google-beta/services/monitoring/resource_monitoring_slo_generated_meta.yaml +++ b/google-beta/services/monitoring/resource_monitoring_slo_generated_meta.yaml @@ -80,3 +80,5 @@ fields: field: windows_based_sli.metric_sum_in_range.time_series - api_field: serviceLevelIndicator.windowsBased.windowPeriod field: windows_based_sli.window_period + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/monitoring/resource_monitoring_uptime_check_config.go b/google-beta/services/monitoring/resource_monitoring_uptime_check_config.go index 55990e42c52..6dbd4f5bf76 100644 --- a/google-beta/services/monitoring/resource_monitoring_uptime_check_config.go +++ b/google-beta/services/monitoring/resource_monitoring_uptime_check_config.go @@ -128,6 +128,7 @@ func ResourceMonitoringUptimeCheckConfig() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -539,6 +540,18 @@ uptime checks: Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -753,6 +766,19 @@ func resourceMonitoringUptimeCheckConfigRead(d *schema.ResourceData, meta interf log.Printf("[DEBUG] Finished reading MonitoringUptimeCheckConfig %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading UptimeCheckConfig: %s", err) } @@ -784,6 +810,19 @@ func resourceMonitoringUptimeCheckConfigRead(d *schema.ResourceData, meta interf } func resourceMonitoringUptimeCheckConfigUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceMonitoringUptimeCheckConfig().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceMonitoringUptimeCheckConfigRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -963,6 +1002,13 @@ func resourceMonitoringUptimeCheckConfigUpdate(d *schema.ResourceData, meta inte } func resourceMonitoringUptimeCheckConfigDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy MonitoringUptimeCheckConfig without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing UptimeCheckConfig %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/monitoring/resource_monitoring_uptime_check_config_generated_meta.yaml b/google-beta/services/monitoring/resource_monitoring_uptime_check_config_generated_meta.yaml index 14b8263a7de..8967548d9e3 100644 --- a/google-beta/services/monitoring/resource_monitoring_uptime_check_config_generated_meta.yaml +++ b/google-beta/services/monitoring/resource_monitoring_uptime_check_config_generated_meta.yaml @@ -46,3 +46,5 @@ fields: - api_field: id field: uptime_check_id - api_field: userLabels + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/netapp/resource_netapp_active_directory.go b/google-beta/services/netapp/resource_netapp_active_directory.go index 7d66852acf0..f7cf085f3c1 100644 --- a/google-beta/services/netapp/resource_netapp_active_directory.go +++ b/google-beta/services/netapp/resource_netapp_active_directory.go @@ -116,6 +116,7 @@ func ResourceNetappActiveDirectory() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -300,6 +301,18 @@ Use when Active Directory domain controllers in multiple regions are configured. Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -539,6 +552,19 @@ func resourceNetappActiveDirectoryRead(d *schema.ResourceData, meta interface{}) log.Printf("[DEBUG] Finished reading NetappActiveDirectory %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading ActiveDirectory: %s", err) } @@ -576,6 +602,19 @@ func resourceNetappActiveDirectoryRead(d *schema.ResourceData, meta interface{}) } func resourceNetappActiveDirectoryUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceNetappActiveDirectory().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceNetappActiveDirectoryRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -844,6 +883,13 @@ func resourceNetappActiveDirectoryUpdate(d *schema.ResourceData, meta interface{ } func resourceNetappActiveDirectoryDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy NetappActiveDirectory without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing ActiveDirectory %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/netapp/resource_netapp_active_directory_generated_meta.yaml b/google-beta/services/netapp/resource_netapp_active_directory_generated_meta.yaml index ba993ee4c2b..33ee4c82542 100644 --- a/google-beta/services/netapp/resource_netapp_active_directory_generated_meta.yaml +++ b/google-beta/services/netapp/resource_netapp_active_directory_generated_meta.yaml @@ -36,3 +36,5 @@ fields: - field: terraform_labels provider_only: true - api_field: username + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/netapp/resource_netapp_backup.go b/google-beta/services/netapp/resource_netapp_backup.go index 6c66099813f..06ac5450841 100644 --- a/google-beta/services/netapp/resource_netapp_backup.go +++ b/google-beta/services/netapp/resource_netapp_backup.go @@ -116,6 +116,7 @@ func ResourceNetappBackup() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -249,6 +250,18 @@ Total size of all backups in a chain in bytes = baseline backup size + sum(incre Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -409,6 +422,19 @@ func resourceNetappBackupRead(d *schema.ResourceData, meta interface{}) error { log.Printf("[DEBUG] Finished reading NetappBackup %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Backup: %s", err) } @@ -452,6 +478,19 @@ func resourceNetappBackupRead(d *schema.ResourceData, meta interface{}) error { } func resourceNetappBackupUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceNetappBackup().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceNetappBackupRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -575,6 +614,13 @@ func resourceNetappBackupUpdate(d *schema.ResourceData, meta interface{}) error } func resourceNetappBackupDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy NetappBackup without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Backup %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/netapp/resource_netapp_backup_generated_meta.yaml b/google-beta/services/netapp/resource_netapp_backup_generated_meta.yaml index 6fe081635c1..9be9ab73f9c 100644 --- a/google-beta/services/netapp/resource_netapp_backup_generated_meta.yaml +++ b/google-beta/services/netapp/resource_netapp_backup_generated_meta.yaml @@ -30,3 +30,5 @@ fields: provider_only: true - api_field: volumeRegion - api_field: volumeUsageBytes + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/netapp/resource_netapp_backup_policy.go b/google-beta/services/netapp/resource_netapp_backup_policy.go index 2a0889754a0..e27e6ea09c9 100644 --- a/google-beta/services/netapp/resource_netapp_backup_policy.go +++ b/google-beta/services/netapp/resource_netapp_backup_policy.go @@ -116,6 +116,7 @@ func ResourceNetappBackupPolicy() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -225,6 +226,18 @@ Please refer to the field 'effective_labels' for all of the labels present on th Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -392,6 +405,19 @@ func resourceNetappBackupPolicyRead(d *schema.ResourceData, meta interface{}) er log.Printf("[DEBUG] Finished reading NetappBackupPolicy %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading BackupPolicy: %s", err) } @@ -429,6 +455,19 @@ func resourceNetappBackupPolicyRead(d *schema.ResourceData, meta interface{}) er } func resourceNetappBackupPolicyUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceNetappBackupPolicy().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceNetappBackupPolicyRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -577,6 +616,13 @@ func resourceNetappBackupPolicyUpdate(d *schema.ResourceData, meta interface{}) } func resourceNetappBackupPolicyDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy NetappBackupPolicy without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing BackupPolicy %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/netapp/resource_netapp_backup_policy_generated_meta.yaml b/google-beta/services/netapp/resource_netapp_backup_policy_generated_meta.yaml index a180aa3fc4b..8086338e59d 100644 --- a/google-beta/services/netapp/resource_netapp_backup_policy_generated_meta.yaml +++ b/google-beta/services/netapp/resource_netapp_backup_policy_generated_meta.yaml @@ -24,3 +24,5 @@ fields: - field: terraform_labels provider_only: true - api_field: weeklyBackupLimit + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/netapp/resource_netapp_backup_vault.go b/google-beta/services/netapp/resource_netapp_backup_vault.go index 82d5b70f012..47bcefd7060 100644 --- a/google-beta/services/netapp/resource_netapp_backup_vault.go +++ b/google-beta/services/netapp/resource_netapp_backup_vault.go @@ -116,6 +116,7 @@ func ResourceNetappBackupVault() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -279,6 +280,18 @@ Format: Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -446,6 +459,19 @@ func resourceNetappBackupVaultRead(d *schema.ResourceData, meta interface{}) err log.Printf("[DEBUG] Finished reading NetappBackupVault %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading BackupVault: %s", err) } @@ -483,6 +509,19 @@ func resourceNetappBackupVaultRead(d *schema.ResourceData, meta interface{}) err } func resourceNetappBackupVaultUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceNetappBackupVault().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceNetappBackupVaultRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -631,6 +670,13 @@ func resourceNetappBackupVaultUpdate(d *schema.ResourceData, meta interface{}) e } func resourceNetappBackupVaultDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy NetappBackupVault without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing BackupVault %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/netapp/resource_netapp_backup_vault_generated_meta.yaml b/google-beta/services/netapp/resource_netapp_backup_vault_generated_meta.yaml index 589d54f1491..f8aa523263f 100644 --- a/google-beta/services/netapp/resource_netapp_backup_vault_generated_meta.yaml +++ b/google-beta/services/netapp/resource_netapp_backup_vault_generated_meta.yaml @@ -32,3 +32,5 @@ fields: - api_field: state - field: terraform_labels provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/netapp/resource_netapp_host_group.go b/google-beta/services/netapp/resource_netapp_host_group.go index 55ef5c5e064..12ba60873c8 100644 --- a/google-beta/services/netapp/resource_netapp_host_group.go +++ b/google-beta/services/netapp/resource_netapp_host_group.go @@ -116,6 +116,7 @@ func ResourceNetappHostGroup() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -222,6 +223,18 @@ Please refer to the field 'effective_labels' for all of the labels present on th Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -389,6 +402,19 @@ func resourceNetappHostGroupRead(d *schema.ResourceData, meta interface{}) error log.Printf("[DEBUG] Finished reading NetappHostGroup %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading HostGroup: %s", err) } @@ -426,6 +452,19 @@ func resourceNetappHostGroupRead(d *schema.ResourceData, meta interface{}) error } func resourceNetappHostGroupUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceNetappHostGroup().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceNetappHostGroupRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -544,6 +583,13 @@ func resourceNetappHostGroupUpdate(d *schema.ResourceData, meta interface{}) err } func resourceNetappHostGroupDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy NetappHostGroup without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing HostGroup %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/netapp/resource_netapp_host_group_generated_meta.yaml b/google-beta/services/netapp/resource_netapp_host_group_generated_meta.yaml index 1768daa1507..2eea74880fb 100644 --- a/google-beta/services/netapp/resource_netapp_host_group_generated_meta.yaml +++ b/google-beta/services/netapp/resource_netapp_host_group_generated_meta.yaml @@ -21,3 +21,5 @@ fields: - field: terraform_labels provider_only: true - api_field: type + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/netapp/resource_netapp_kmsconfig.go b/google-beta/services/netapp/resource_netapp_kmsconfig.go index 6bc140031fd..5cb3955c00c 100644 --- a/google-beta/services/netapp/resource_netapp_kmsconfig.go +++ b/google-beta/services/netapp/resource_netapp_kmsconfig.go @@ -116,6 +116,7 @@ func ResourceNetappkmsconfig() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -205,6 +206,18 @@ To make the policy work, a CMEK policy check is required, which verifies key acc Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -372,6 +385,19 @@ func resourceNetappkmsconfigRead(d *schema.ResourceData, meta interface{}) error log.Printf("[DEBUG] Finished reading Netappkmsconfig %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading kmsconfig: %s", err) } @@ -409,6 +435,19 @@ func resourceNetappkmsconfigRead(d *schema.ResourceData, meta interface{}) error } func resourceNetappkmsconfigUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceNetappkmsconfig().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceNetappkmsconfigRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -527,6 +566,13 @@ func resourceNetappkmsconfigUpdate(d *schema.ResourceData, meta interface{}) err } func resourceNetappkmsconfigDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy Netappkmsconfig without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing kmsconfig %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/netapp/resource_netapp_kmsconfig_generated_meta.yaml b/google-beta/services/netapp/resource_netapp_kmsconfig_generated_meta.yaml index 17d743739d1..7b03b1b7914 100644 --- a/google-beta/services/netapp/resource_netapp_kmsconfig_generated_meta.yaml +++ b/google-beta/services/netapp/resource_netapp_kmsconfig_generated_meta.yaml @@ -20,3 +20,5 @@ fields: - api_field: serviceAccount - field: terraform_labels provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/netapp/resource_netapp_storage_pool.go b/google-beta/services/netapp/resource_netapp_storage_pool.go index 28844b9dcb6..efc678e145e 100644 --- a/google-beta/services/netapp/resource_netapp_storage_pool.go +++ b/google-beta/services/netapp/resource_netapp_storage_pool.go @@ -116,6 +116,7 @@ func ResourceNetappStoragePool() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -355,6 +356,18 @@ If you want to create a zonal Flex pool, specify a zone name for 'location' and Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -612,6 +625,19 @@ func resourceNetappStoragePoolRead(d *schema.ResourceData, meta interface{}) err log.Printf("[DEBUG] Finished reading NetappStoragePool %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading StoragePool: %s", err) } @@ -649,6 +675,19 @@ func resourceNetappStoragePoolRead(d *schema.ResourceData, meta interface{}) err } func resourceNetappStoragePoolUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceNetappStoragePool().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceNetappStoragePoolRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -922,6 +961,13 @@ func resourceNetappStoragePoolUpdate(d *schema.ResourceData, meta interface{}) e } func resourceNetappStoragePoolDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy NetappStoragePool without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing StoragePool %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/netapp/resource_netapp_storage_pool_generated_meta.yaml b/google-beta/services/netapp/resource_netapp_storage_pool_generated_meta.yaml index 3655128153d..1588190b7d4 100644 --- a/google-beta/services/netapp/resource_netapp_storage_pool_generated_meta.yaml +++ b/google-beta/services/netapp/resource_netapp_storage_pool_generated_meta.yaml @@ -42,3 +42,5 @@ fields: - api_field: volumeCapacityGib - api_field: volumeCount - api_field: zone + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/netapp/resource_netapp_volume.go b/google-beta/services/netapp/resource_netapp_volume.go index 2aa456daa14..a867830bb6d 100644 --- a/google-beta/services/netapp/resource_netapp_volume.go +++ b/google-beta/services/netapp/resource_netapp_volume.go @@ -159,6 +159,7 @@ func ResourceNetappVolume() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DEFAULT"), ), Identity: &schema.ResourceIdentity{ @@ -975,21 +976,18 @@ Format for SMB volumes: '\\\\netbios_prefix-four_random_hex_letters.domain_name\ Computed: true, Description: `Specifies the active zone for regional volume.`, }, - "deletion_policy": { - Type: schema.TypeString, - Optional: true, - Description: `Policy to determine if the volume should be deleted forcefully. -Volumes may have nested snapshot resources. Deleting such a volume will fail. -Setting this parameter to FORCE will delete volumes including nested snapshots. -Possible values: DEFAULT, FORCE.`, - Default: "DEFAULT", - }, "project": { Type: schema.TypeString, Optional: true, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `This field uses a custom implementation please refer to documentation under /hashicorp/terraform-provider-google-beta/website/docs/r/netapp_volume.html.markdown for specifics`, + }, }, UseJSONNumber: true, } @@ -1267,8 +1265,15 @@ func resourceNetappVolumeRead(d *schema.ResourceData, meta interface{}) error { // Explicitly set virtual fields to default values if unset if _, ok := d.GetOkExists("deletion_policy"); !ok { - if err := d.Set("deletion_policy", "DEFAULT"); err != nil { - return fmt.Errorf("Error setting deletion_policy: %s", err) + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DEFAULT"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } } } if err := d.Set("project", project); err != nil { @@ -1308,6 +1313,19 @@ func resourceNetappVolumeRead(d *schema.ResourceData, meta interface{}) error { } func resourceNetappVolumeUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceNetappVolume().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceNetappVolumeRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1757,6 +1775,13 @@ func resourceNetappVolumeUpdate(d *schema.ResourceData, meta interface{}) error } func resourceNetappVolumeDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy NetappVolume without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Volume %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1833,9 +1858,6 @@ func resourceNetappVolumeImport(d *schema.ResourceData, meta interface{}) ([]*sc d.SetId(id) // Explicitly set virtual fields to default values on import - if err := d.Set("deletion_policy", "DEFAULT"); err != nil { - return nil, fmt.Errorf("Error setting deletion_policy: %s", err) - } return []*schema.ResourceData{d}, nil } diff --git a/google-beta/services/netapp/resource_netapp_volume_generated_meta.yaml b/google-beta/services/netapp/resource_netapp_volume_generated_meta.yaml index 353357547db..ebae6da8674 100644 --- a/google-beta/services/netapp/resource_netapp_volume_generated_meta.yaml +++ b/google-beta/services/netapp/resource_netapp_volume_generated_meta.yaml @@ -30,8 +30,6 @@ fields: - api_field: capacityGib - api_field: coldTierSizeGib - api_field: createTime - - field: deletion_policy - provider_only: true - api_field: description - field: effective_labels provider_only: true @@ -116,3 +114,5 @@ fields: - api_field: unixPermissions - api_field: usedGib - api_field: zone + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/netapp/resource_netapp_volume_quota_rule.go b/google-beta/services/netapp/resource_netapp_volume_quota_rule.go index 4064fe46603..a54d6b6e296 100644 --- a/google-beta/services/netapp/resource_netapp_volume_quota_rule.go +++ b/google-beta/services/netapp/resource_netapp_volume_quota_rule.go @@ -116,6 +116,7 @@ func ResourceNetappVolumeQuotaRule() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -235,6 +236,18 @@ Leave empty for default quotas`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -401,6 +414,19 @@ func resourceNetappVolumeQuotaRuleRead(d *schema.ResourceData, meta interface{}) log.Printf("[DEBUG] Finished reading NetappVolumeQuotaRule %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading VolumeQuotaRule: %s", err) } @@ -444,6 +470,19 @@ func resourceNetappVolumeQuotaRuleRead(d *schema.ResourceData, meta interface{}) } func resourceNetappVolumeQuotaRuleUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceNetappVolumeQuotaRule().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceNetappVolumeQuotaRuleRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -587,6 +626,13 @@ func resourceNetappVolumeQuotaRuleUpdate(d *schema.ResourceData, meta interface{ } func resourceNetappVolumeQuotaRuleDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy NetappVolumeQuotaRule without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing VolumeQuotaRule %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/netapp/resource_netapp_volume_quota_rule_generated_meta.yaml b/google-beta/services/netapp/resource_netapp_volume_quota_rule_generated_meta.yaml index 86dad0d28a2..a451d39ece8 100644 --- a/google-beta/services/netapp/resource_netapp_volume_quota_rule_generated_meta.yaml +++ b/google-beta/services/netapp/resource_netapp_volume_quota_rule_generated_meta.yaml @@ -25,3 +25,5 @@ fields: - api_field: type - field: volume_name provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/netapp/resource_netapp_volume_replication.go b/google-beta/services/netapp/resource_netapp_volume_replication.go index 53bb59e2cbb..85008af31bd 100644 --- a/google-beta/services/netapp/resource_netapp_volume_replication.go +++ b/google-beta/services/netapp/resource_netapp_volume_replication.go @@ -168,6 +168,7 @@ func ResourceNetappVolumeReplication() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -518,6 +519,18 @@ create/stop/resume operations, set this parameter to true. Default is false.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -707,6 +720,18 @@ func resourceNetappVolumeReplicationRead(d *schema.ResourceData, meta interface{ return fmt.Errorf("Error setting wait_for_mirror: %s", err) } } + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading VolumeReplication: %s", err) } @@ -750,6 +775,19 @@ func resourceNetappVolumeReplicationRead(d *schema.ResourceData, meta interface{ } func resourceNetappVolumeReplicationUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceNetappVolumeReplication().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceNetappVolumeReplicationRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -972,6 +1010,13 @@ func resourceNetappVolumeReplicationUpdate(d *schema.ResourceData, meta interfac } func resourceNetappVolumeReplicationDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy NetappVolumeReplication without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing VolumeReplication %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/netapp/resource_netapp_volume_replication_generated_meta.yaml b/google-beta/services/netapp/resource_netapp_volume_replication_generated_meta.yaml index 4b8c3b891c2..ee70ef469a3 100644 --- a/google-beta/services/netapp/resource_netapp_volume_replication_generated_meta.yaml +++ b/google-beta/services/netapp/resource_netapp_volume_replication_generated_meta.yaml @@ -59,3 +59,5 @@ fields: provider_only: true - field: wait_for_mirror provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/netapp/resource_netapp_volume_snapshot.go b/google-beta/services/netapp/resource_netapp_volume_snapshot.go index e1a9c242a20..0d28949fae1 100644 --- a/google-beta/services/netapp/resource_netapp_volume_snapshot.go +++ b/google-beta/services/netapp/resource_netapp_volume_snapshot.go @@ -116,6 +116,7 @@ func ResourceNetappVolumeSnapshot() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -203,6 +204,18 @@ Please refer to the field 'effective_labels' for all of the labels present on th Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -351,6 +364,19 @@ func resourceNetappVolumeSnapshotRead(d *schema.ResourceData, meta interface{}) log.Printf("[DEBUG] Finished reading NetappVolumeSnapshot %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading VolumeSnapshot: %s", err) } @@ -394,6 +420,19 @@ func resourceNetappVolumeSnapshotRead(d *schema.ResourceData, meta interface{}) } func resourceNetappVolumeSnapshotUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceNetappVolumeSnapshot().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceNetappVolumeSnapshotRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -507,6 +546,13 @@ func resourceNetappVolumeSnapshotUpdate(d *schema.ResourceData, meta interface{} } func resourceNetappVolumeSnapshotDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy NetappVolumeSnapshot without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing VolumeSnapshot %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/netapp/resource_netapp_volume_snapshot_generated_meta.yaml b/google-beta/services/netapp/resource_netapp_volume_snapshot_generated_meta.yaml index e44092a96c9..57202a45405 100644 --- a/google-beta/services/netapp/resource_netapp_volume_snapshot_generated_meta.yaml +++ b/google-beta/services/netapp/resource_netapp_volume_snapshot_generated_meta.yaml @@ -20,3 +20,5 @@ fields: - api_field: usedBytes - field: volume_name provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/networkconnectivity/resource_network_connectivity_destination.go b/google-beta/services/networkconnectivity/resource_network_connectivity_destination.go index 9e673cf202d..a615cff5007 100644 --- a/google-beta/services/networkconnectivity/resource_network_connectivity_destination.go +++ b/google-beta/services/networkconnectivity/resource_network_connectivity_destination.go @@ -116,6 +116,7 @@ func ResourceNetworkConnectivityDestination() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -270,6 +271,18 @@ created, the new resource is assigned a different and unique ID.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -463,6 +476,19 @@ func resourceNetworkConnectivityDestinationRead(d *schema.ResourceData, meta int log.Printf("[DEBUG] Finished reading NetworkConnectivityDestination %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Destination: %s", err) } @@ -506,6 +532,19 @@ func resourceNetworkConnectivityDestinationRead(d *schema.ResourceData, meta int } func resourceNetworkConnectivityDestinationUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceNetworkConnectivityDestination().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceNetworkConnectivityDestinationRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -639,6 +678,13 @@ func resourceNetworkConnectivityDestinationUpdate(d *schema.ResourceData, meta i } func resourceNetworkConnectivityDestinationDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy NetworkConnectivityDestination without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Destination %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/networkconnectivity/resource_network_connectivity_destination_generated_meta.yaml b/google-beta/services/networkconnectivity/resource_network_connectivity_destination_generated_meta.yaml index af3273ca41e..56d3ea9d542 100644 --- a/google-beta/services/networkconnectivity/resource_network_connectivity_destination_generated_meta.yaml +++ b/google-beta/services/networkconnectivity/resource_network_connectivity_destination_generated_meta.yaml @@ -30,3 +30,5 @@ fields: provider_only: true - api_field: uid - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/networkconnectivity/resource_network_connectivity_gateway_advertised_route.go b/google-beta/services/networkconnectivity/resource_network_connectivity_gateway_advertised_route.go index 10b572cef95..99077ca59e6 100644 --- a/google-beta/services/networkconnectivity/resource_network_connectivity_gateway_advertised_route.go +++ b/google-beta/services/networkconnectivity/resource_network_connectivity_gateway_advertised_route.go @@ -116,6 +116,7 @@ func ResourceNetworkConnectivityGatewayAdvertisedRoute() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -240,6 +241,18 @@ If a gateway advertised route is deleted and another with the same name is creat Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -412,6 +425,19 @@ func resourceNetworkConnectivityGatewayAdvertisedRouteRead(d *schema.ResourceDat log.Printf("[DEBUG] Finished reading NetworkConnectivityGatewayAdvertisedRoute %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading GatewayAdvertisedRoute: %s", err) } @@ -455,6 +481,19 @@ func resourceNetworkConnectivityGatewayAdvertisedRouteRead(d *schema.ResourceDat } func resourceNetworkConnectivityGatewayAdvertisedRouteUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceNetworkConnectivityGatewayAdvertisedRoute().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceNetworkConnectivityGatewayAdvertisedRouteRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -568,6 +607,13 @@ func resourceNetworkConnectivityGatewayAdvertisedRouteUpdate(d *schema.ResourceD } func resourceNetworkConnectivityGatewayAdvertisedRouteDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy NetworkConnectivityGatewayAdvertisedRoute without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing GatewayAdvertisedRoute %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/networkconnectivity/resource_network_connectivity_gateway_advertised_route_generated_meta.yaml b/google-beta/services/networkconnectivity/resource_network_connectivity_gateway_advertised_route_generated_meta.yaml index aad5c15be26..f81bb5bcaff 100644 --- a/google-beta/services/networkconnectivity/resource_network_connectivity_gateway_advertised_route_generated_meta.yaml +++ b/google-beta/services/networkconnectivity/resource_network_connectivity_gateway_advertised_route_generated_meta.yaml @@ -25,3 +25,5 @@ fields: provider_only: true - api_field: uniqueId - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/networkconnectivity/resource_network_connectivity_group.go b/google-beta/services/networkconnectivity/resource_network_connectivity_group.go index 291240b33e7..32813f690d3 100644 --- a/google-beta/services/networkconnectivity/resource_network_connectivity_group.go +++ b/google-beta/services/networkconnectivity/resource_network_connectivity_group.go @@ -116,6 +116,7 @@ func ResourceNetworkConnectivityGroup() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -234,6 +235,18 @@ Please refer to the field 'effective_labels' for all of the labels present on th Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -389,6 +402,19 @@ func resourceNetworkConnectivityGroupRead(d *schema.ResourceData, meta interface log.Printf("[DEBUG] Finished reading NetworkConnectivityGroup %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Group: %s", err) } @@ -426,6 +452,19 @@ func resourceNetworkConnectivityGroupRead(d *schema.ResourceData, meta interface } func resourceNetworkConnectivityGroupUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceNetworkConnectivityGroup().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceNetworkConnectivityGroupRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -522,6 +561,13 @@ func resourceNetworkConnectivityGroupUpdate(d *schema.ResourceData, meta interfa } func resourceNetworkConnectivityGroupDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy NetworkConnectivityGroup without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Group %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/networkconnectivity/resource_network_connectivity_group_generated_meta.yaml b/google-beta/services/networkconnectivity/resource_network_connectivity_group_generated_meta.yaml index e6ac024f69b..24c0243bb5b 100644 --- a/google-beta/services/networkconnectivity/resource_network_connectivity_group_generated_meta.yaml +++ b/google-beta/services/networkconnectivity/resource_network_connectivity_group_generated_meta.yaml @@ -22,3 +22,5 @@ fields: provider_only: true - api_field: uid - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/networkconnectivity/resource_network_connectivity_hub.go b/google-beta/services/networkconnectivity/resource_network_connectivity_hub.go index 7b6a19eca97..7f3624ddc47 100644 --- a/google-beta/services/networkconnectivity/resource_network_connectivity_hub.go +++ b/google-beta/services/networkconnectivity/resource_network_connectivity_hub.go @@ -116,6 +116,7 @@ func ResourceNetworkConnectivityHub() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Schema: map[string]*schema.Schema{ @@ -217,6 +218,18 @@ Please refer to the field 'effective_labels' for all of the labels present on th Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -363,6 +376,19 @@ func resourceNetworkConnectivityHubRead(d *schema.ResourceData, meta interface{} log.Printf("[DEBUG] Finished reading NetworkConnectivityHub %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Hub: %s", err) } @@ -376,6 +402,19 @@ func resourceNetworkConnectivityHubRead(d *schema.ResourceData, meta interface{} } func resourceNetworkConnectivityHubUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceNetworkConnectivityHub().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceNetworkConnectivityHubRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -474,6 +513,13 @@ func resourceNetworkConnectivityHubUpdate(d *schema.ResourceData, meta interface } func resourceNetworkConnectivityHubDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy NetworkConnectivityHub without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Hub %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/networkconnectivity/resource_network_connectivity_hub_generated_meta.yaml b/google-beta/services/networkconnectivity/resource_network_connectivity_hub_generated_meta.yaml index ea1ee1b0a62..63805423c27 100644 --- a/google-beta/services/networkconnectivity/resource_network_connectivity_hub_generated_meta.yaml +++ b/google-beta/services/networkconnectivity/resource_network_connectivity_hub_generated_meta.yaml @@ -22,3 +22,5 @@ fields: provider_only: true - api_field: uniqueId - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/networkconnectivity/resource_network_connectivity_multicloud_data_transfer_config.go b/google-beta/services/networkconnectivity/resource_network_connectivity_multicloud_data_transfer_config.go index e66caf1ab47..a5e1414e8b1 100644 --- a/google-beta/services/networkconnectivity/resource_network_connectivity_multicloud_data_transfer_config.go +++ b/google-beta/services/networkconnectivity/resource_network_connectivity_multicloud_data_transfer_config.go @@ -116,6 +116,7 @@ func ResourceNetworkConnectivityMulticloudDataTransferConfig() *schema.Resource CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -233,6 +234,18 @@ created, the new resource is assigned a different and unique ID.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -420,6 +433,19 @@ func resourceNetworkConnectivityMulticloudDataTransferConfigRead(d *schema.Resou log.Printf("[DEBUG] Finished reading NetworkConnectivityMulticloudDataTransferConfig %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading MulticloudDataTransferConfig: %s", err) } @@ -457,6 +483,19 @@ func resourceNetworkConnectivityMulticloudDataTransferConfigRead(d *schema.Resou } func resourceNetworkConnectivityMulticloudDataTransferConfigUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceNetworkConnectivityMulticloudDataTransferConfig().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceNetworkConnectivityMulticloudDataTransferConfigRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -585,6 +624,13 @@ func resourceNetworkConnectivityMulticloudDataTransferConfigUpdate(d *schema.Res } func resourceNetworkConnectivityMulticloudDataTransferConfigDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy NetworkConnectivityMulticloudDataTransferConfig without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing MulticloudDataTransferConfig %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/networkconnectivity/resource_network_connectivity_multicloud_data_transfer_config_generated_meta.yaml b/google-beta/services/networkconnectivity/resource_network_connectivity_multicloud_data_transfer_config_generated_meta.yaml index 9e58c0881fe..1e6554693e5 100644 --- a/google-beta/services/networkconnectivity/resource_network_connectivity_multicloud_data_transfer_config_generated_meta.yaml +++ b/google-beta/services/networkconnectivity/resource_network_connectivity_multicloud_data_transfer_config_generated_meta.yaml @@ -29,3 +29,5 @@ fields: provider_only: true - api_field: uid - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/networkconnectivity/resource_network_connectivity_policy_based_route.go b/google-beta/services/networkconnectivity/resource_network_connectivity_policy_based_route.go index 6ead3647213..c7d5f400eb5 100644 --- a/google-beta/services/networkconnectivity/resource_network_connectivity_policy_based_route.go +++ b/google-beta/services/networkconnectivity/resource_network_connectivity_policy_based_route.go @@ -116,6 +116,7 @@ func ResourceNetworkConnectivityPolicyBasedRoute() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -326,6 +327,18 @@ Please refer to the field 'effective_labels' for all of the labels present on th Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -506,6 +519,19 @@ func resourceNetworkConnectivityPolicyBasedRouteRead(d *schema.ResourceData, met log.Printf("[DEBUG] Finished reading NetworkConnectivityPolicyBasedRoute %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading PolicyBasedRoute: %s", err) } @@ -537,11 +563,18 @@ func resourceNetworkConnectivityPolicyBasedRouteRead(d *schema.ResourceData, met } func resourceNetworkConnectivityPolicyBasedRouteUpdate(d *schema.ResourceData, meta interface{}) error { - // Only the root field "labels", "terraform_labels", and virtual fields are mutable + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable return resourceNetworkConnectivityPolicyBasedRouteRead(d, meta) } func resourceNetworkConnectivityPolicyBasedRouteDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy NetworkConnectivityPolicyBasedRoute without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing PolicyBasedRoute %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/networkconnectivity/resource_network_connectivity_policy_based_route_generated_meta.yaml b/google-beta/services/networkconnectivity/resource_network_connectivity_policy_based_route_generated_meta.yaml index f05a1a468b7..d66ec245463 100644 --- a/google-beta/services/networkconnectivity/resource_network_connectivity_policy_based_route_generated_meta.yaml +++ b/google-beta/services/networkconnectivity/resource_network_connectivity_policy_based_route_generated_meta.yaml @@ -31,3 +31,5 @@ fields: - api_field: warnings.code - api_field: warnings.data - api_field: warnings.warningMessage + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/networkconnectivity/resource_network_connectivity_regional_endpoint.go b/google-beta/services/networkconnectivity/resource_network_connectivity_regional_endpoint.go index 4f9e8be4109..d6216137457 100644 --- a/google-beta/services/networkconnectivity/resource_network_connectivity_regional_endpoint.go +++ b/google-beta/services/networkconnectivity/resource_network_connectivity_regional_endpoint.go @@ -116,6 +116,7 @@ func ResourceNetworkConnectivityRegionalEndpoint() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -241,6 +242,18 @@ Please refer to the field 'effective_labels' for all of the labels present on th Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -414,6 +427,19 @@ func resourceNetworkConnectivityRegionalEndpointRead(d *schema.ResourceData, met log.Printf("[DEBUG] Finished reading NetworkConnectivityRegionalEndpoint %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading RegionalEndpoint: %s", err) } @@ -451,11 +477,18 @@ func resourceNetworkConnectivityRegionalEndpointRead(d *schema.ResourceData, met } func resourceNetworkConnectivityRegionalEndpointUpdate(d *schema.ResourceData, meta interface{}) error { - // Only the root field "labels", "terraform_labels", and virtual fields are mutable + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable return resourceNetworkConnectivityRegionalEndpointRead(d, meta) } func resourceNetworkConnectivityRegionalEndpointDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy NetworkConnectivityRegionalEndpoint without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing RegionalEndpoint %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/networkconnectivity/resource_network_connectivity_regional_endpoint_generated_meta.yaml b/google-beta/services/networkconnectivity/resource_network_connectivity_regional_endpoint_generated_meta.yaml index dcebd16d675..e644e4c3c39 100644 --- a/google-beta/services/networkconnectivity/resource_network_connectivity_regional_endpoint_generated_meta.yaml +++ b/google-beta/services/networkconnectivity/resource_network_connectivity_regional_endpoint_generated_meta.yaml @@ -25,3 +25,5 @@ fields: - field: terraform_labels provider_only: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/networkconnectivity/resource_network_connectivity_spoke.go b/google-beta/services/networkconnectivity/resource_network_connectivity_spoke.go index 0ff823b23be..4428c94ccb5 100644 --- a/google-beta/services/networkconnectivity/resource_network_connectivity_spoke.go +++ b/google-beta/services/networkconnectivity/resource_network_connectivity_spoke.go @@ -116,6 +116,7 @@ func ResourceNetworkConnectivitySpoke() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -558,6 +559,18 @@ Please refer to the field 'effective_labels' for all of the labels present on th Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -755,6 +768,19 @@ func resourceNetworkConnectivitySpokeRead(d *schema.ResourceData, meta interface log.Printf("[DEBUG] Finished reading NetworkConnectivitySpoke %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Spoke: %s", err) } @@ -792,6 +818,19 @@ func resourceNetworkConnectivitySpokeRead(d *schema.ResourceData, meta interface } func resourceNetworkConnectivitySpokeUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceNetworkConnectivitySpoke().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceNetworkConnectivitySpokeRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -951,6 +990,13 @@ func resourceNetworkConnectivitySpokeUpdate(d *schema.ResourceData, meta interfa } func resourceNetworkConnectivitySpokeDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy NetworkConnectivitySpoke without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Spoke %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/networkconnectivity/resource_network_connectivity_spoke_generated_meta.yaml b/google-beta/services/networkconnectivity/resource_network_connectivity_spoke_generated_meta.yaml index 6e9a207b3f9..90173c40178 100644 --- a/google-beta/services/networkconnectivity/resource_network_connectivity_spoke_generated_meta.yaml +++ b/google-beta/services/networkconnectivity/resource_network_connectivity_spoke_generated_meta.yaml @@ -55,3 +55,5 @@ fields: provider_only: true - api_field: uniqueId - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/networkconnectivity/resource_network_connectivity_transport.go b/google-beta/services/networkconnectivity/resource_network_connectivity_transport.go index f0861d3d9ae..91b09a49dec 100644 --- a/google-beta/services/networkconnectivity/resource_network_connectivity_transport.go +++ b/google-beta/services/networkconnectivity/resource_network_connectivity_transport.go @@ -116,6 +116,7 @@ func ResourceNetworkConnectivityTransport() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -278,6 +279,18 @@ Please refer to the field 'effective_labels' for all of the labels present on th Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -499,6 +512,19 @@ func resourceNetworkConnectivityTransportRead(d *schema.ResourceData, meta inter log.Printf("[DEBUG] Finished reading NetworkConnectivityTransport %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Transport: %s", err) } @@ -536,6 +562,19 @@ func resourceNetworkConnectivityTransportRead(d *schema.ResourceData, meta inter } func resourceNetworkConnectivityTransportUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceNetworkConnectivityTransport().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceNetworkConnectivityTransportRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -660,6 +699,13 @@ func resourceNetworkConnectivityTransportUpdate(d *schema.ResourceData, meta int } func resourceNetworkConnectivityTransportDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy NetworkConnectivityTransport without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Transport %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/networkconnectivity/resource_network_connectivity_transport_generated_meta.yaml b/google-beta/services/networkconnectivity/resource_network_connectivity_transport_generated_meta.yaml index 2ec678de70a..1287d99f452 100644 --- a/google-beta/services/networkconnectivity/resource_network_connectivity_transport_generated_meta.yaml +++ b/google-beta/services/networkconnectivity/resource_network_connectivity_transport_generated_meta.yaml @@ -31,3 +31,5 @@ fields: - api_field: state - field: terraform_labels provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/networkconnectivityv1/resource_network_connectivity_internal_range.go b/google-beta/services/networkconnectivityv1/resource_network_connectivity_internal_range.go index c1202ed4544..f68b2a8e1f8 100644 --- a/google-beta/services/networkconnectivityv1/resource_network_connectivity_internal_range.go +++ b/google-beta/services/networkconnectivityv1/resource_network_connectivity_internal_range.go @@ -116,6 +116,7 @@ func ResourceNetworkConnectivityv1InternalRange() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -308,6 +309,18 @@ Other resources mark themselves as users while doing so by creating a reference Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -512,6 +525,19 @@ func resourceNetworkConnectivityv1InternalRangeRead(d *schema.ResourceData, meta log.Printf("[DEBUG] Finished reading NetworkConnectivityv1InternalRange %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading InternalRange: %s", err) } @@ -543,6 +569,19 @@ func resourceNetworkConnectivityv1InternalRangeRead(d *schema.ResourceData, meta } func resourceNetworkConnectivityv1InternalRangeUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceNetworkConnectivityv1InternalRange().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceNetworkConnectivityv1InternalRangeRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -726,6 +765,13 @@ func resourceNetworkConnectivityv1InternalRangeUpdate(d *schema.ResourceData, me } func resourceNetworkConnectivityv1InternalRangeDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy NetworkConnectivityv1InternalRange without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing InternalRange %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/networkconnectivityv1/resource_network_connectivity_internal_range_generated_meta.yaml b/google-beta/services/networkconnectivityv1/resource_network_connectivity_internal_range_generated_meta.yaml index e2063b66132..bd85167b55c 100644 --- a/google-beta/services/networkconnectivityv1/resource_network_connectivity_internal_range_generated_meta.yaml +++ b/google-beta/services/networkconnectivityv1/resource_network_connectivity_internal_range_generated_meta.yaml @@ -29,3 +29,5 @@ fields: provider_only: true - api_field: usage - api_field: users + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/networkconnectivityv1/resource_network_connectivity_service_connection_policy.go b/google-beta/services/networkconnectivityv1/resource_network_connectivity_service_connection_policy.go index ef9a0a0edef..9ff51e29a84 100644 --- a/google-beta/services/networkconnectivityv1/resource_network_connectivity_service_connection_policy.go +++ b/google-beta/services/networkconnectivityv1/resource_network_connectivity_service_connection_policy.go @@ -116,6 +116,7 @@ func ResourceNetworkConnectivityv1ServiceConnectionPolicy() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -371,6 +372,18 @@ facing or system internal. Possible values: ["CONNECTION_ERROR_TYPE_UNSPECIFIED" Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -538,6 +551,19 @@ func resourceNetworkConnectivityv1ServiceConnectionPolicyRead(d *schema.Resource log.Printf("[DEBUG] Finished reading NetworkConnectivityv1ServiceConnectionPolicy %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading ServiceConnectionPolicy: %s", err) } @@ -575,6 +601,19 @@ func resourceNetworkConnectivityv1ServiceConnectionPolicyRead(d *schema.Resource } func resourceNetworkConnectivityv1ServiceConnectionPolicyUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceNetworkConnectivityv1ServiceConnectionPolicy().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceNetworkConnectivityv1ServiceConnectionPolicyRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -708,6 +747,13 @@ func resourceNetworkConnectivityv1ServiceConnectionPolicyUpdate(d *schema.Resour } func resourceNetworkConnectivityv1ServiceConnectionPolicyDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy NetworkConnectivityv1ServiceConnectionPolicy without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing ServiceConnectionPolicy %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/networkconnectivityv1/resource_network_connectivity_service_connection_policy_generated_meta.yaml b/google-beta/services/networkconnectivityv1/resource_network_connectivity_service_connection_policy_generated_meta.yaml index 9900ef1cb75..16b49d3ea6c 100644 --- a/google-beta/services/networkconnectivityv1/resource_network_connectivity_service_connection_policy_generated_meta.yaml +++ b/google-beta/services/networkconnectivityv1/resource_network_connectivity_service_connection_policy_generated_meta.yaml @@ -40,3 +40,5 @@ fields: - field: terraform_labels provider_only: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/networkmanagement/data_source_network_management_connectivity_tests_test.go b/google-beta/services/networkmanagement/data_source_network_management_connectivity_tests_test.go index 99c79386522..3cbd76178e8 100644 --- a/google-beta/services/networkmanagement/data_source_network_management_connectivity_tests_test.go +++ b/google-beta/services/networkmanagement/data_source_network_management_connectivity_tests_test.go @@ -50,6 +50,7 @@ func TestAccNetworkManagementConnectivityTests_basic(t *testing.T) { "project": {}, "terraform_labels.%": {}, "terraform_labels.goog-terraform-provisioned": {}, + "deletion_policy": {}, }, ), ), @@ -65,6 +66,7 @@ func TestAccNetworkManagementConnectivityTests_basic(t *testing.T) { "project": {}, "terraform_labels.%": {}, "terraform_labels.goog-terraform-provisioned": {}, + "deletion_policy": {}, }, ), ), diff --git a/google-beta/services/networkmanagement/resource_network_management_connectivity_test_generated_meta.yaml b/google-beta/services/networkmanagement/resource_network_management_connectivity_test_generated_meta.yaml index ea176d9d7ee..0cdb7ccd3d0 100644 --- a/google-beta/services/networkmanagement/resource_network_management_connectivity_test_generated_meta.yaml +++ b/google-beta/services/networkmanagement/resource_network_management_connectivity_test_generated_meta.yaml @@ -40,3 +40,5 @@ fields: - api_field: source.projectId - field: terraform_labels provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/networkmanagement/resource_network_management_connectivity_test_resource.go b/google-beta/services/networkmanagement/resource_network_management_connectivity_test_resource.go index 4d65c3d3b32..652cb2550ef 100644 --- a/google-beta/services/networkmanagement/resource_network_management_connectivity_test_resource.go +++ b/google-beta/services/networkmanagement/resource_network_management_connectivity_test_resource.go @@ -116,6 +116,7 @@ func ResourceNetworkManagementConnectivityTest() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -405,6 +406,18 @@ Default value is false.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -585,6 +598,19 @@ func resourceNetworkManagementConnectivityTestRead(d *schema.ResourceData, meta log.Printf("[DEBUG] Finished reading NetworkManagementConnectivityTest %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading ConnectivityTest: %s", err) } @@ -616,6 +642,19 @@ func resourceNetworkManagementConnectivityTestRead(d *schema.ResourceData, meta } func resourceNetworkManagementConnectivityTestUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceNetworkManagementConnectivityTest().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceNetworkManagementConnectivityTestRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -799,6 +838,13 @@ func resourceNetworkManagementConnectivityTestUpdate(d *schema.ResourceData, met } func resourceNetworkManagementConnectivityTestDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy NetworkManagementConnectivityTest without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing ConnectivityTest %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/networkmanagement/resource_network_management_organization_vpc_flow_logs_config.go b/google-beta/services/networkmanagement/resource_network_management_organization_vpc_flow_logs_config.go index 4d62dca5930..97bafc9c6da 100644 --- a/google-beta/services/networkmanagement/resource_network_management_organization_vpc_flow_logs_config.go +++ b/google-beta/services/networkmanagement/resource_network_management_organization_vpc_flow_logs_config.go @@ -115,6 +115,7 @@ func ResourceNetworkManagementOrganizationVpcFlowLogsConfig() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -263,6 +264,19 @@ Possible values: ENABLED DISABLED`, Computed: true, Description: `Output only. The time the config was updated.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -437,6 +451,20 @@ func resourceNetworkManagementOrganizationVpcFlowLogsConfigRead(d *schema.Resour log.Printf("[DEBUG] Finished reading NetworkManagementOrganizationVpcFlowLogsConfig %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceNetworkManagementOrganizationVpcFlowLogsConfigFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -470,6 +498,18 @@ func resourceNetworkManagementOrganizationVpcFlowLogsConfigRead(d *schema.Resour } func resourceNetworkManagementOrganizationVpcFlowLogsConfigUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceNetworkManagementOrganizationVpcFlowLogsConfig().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceNetworkManagementOrganizationVpcFlowLogsConfigRead(d, meta) + } var project string config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) @@ -643,6 +683,13 @@ func resourceNetworkManagementOrganizationVpcFlowLogsConfigUpdate(d *schema.Reso } func resourceNetworkManagementOrganizationVpcFlowLogsConfigDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy NetworkManagementOrganizationVpcFlowLogsConfig without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing OrganizationVpcFlowLogsConfig %q from Terraform state without deletion", d.Id()) + return nil + } var project string config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) diff --git a/google-beta/services/networkmanagement/resource_network_management_organization_vpc_flow_logs_config_generated_meta.yaml b/google-beta/services/networkmanagement/resource_network_management_organization_vpc_flow_logs_config_generated_meta.yaml index fb275f349c8..f23e76bdb3d 100644 --- a/google-beta/services/networkmanagement/resource_network_management_organization_vpc_flow_logs_config_generated_meta.yaml +++ b/google-beta/services/networkmanagement/resource_network_management_organization_vpc_flow_logs_config_generated_meta.yaml @@ -29,3 +29,5 @@ fields: - api_field: updateTime - field: vpc_flow_logs_config_id provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/networkmanagement/resource_network_management_vpc_flow_logs_config.go b/google-beta/services/networkmanagement/resource_network_management_vpc_flow_logs_config.go index 8e44c73470d..4a508016f3b 100644 --- a/google-beta/services/networkmanagement/resource_network_management_vpc_flow_logs_config.go +++ b/google-beta/services/networkmanagement/resource_network_management_vpc_flow_logs_config.go @@ -116,6 +116,7 @@ func ResourceNetworkManagementVpcFlowLogsConfig() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -282,6 +283,18 @@ TARGET_RESOURCE_DOES_NOT_EXIST`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -485,6 +498,19 @@ func resourceNetworkManagementVpcFlowLogsConfigRead(d *schema.ResourceData, meta log.Printf("[DEBUG] Finished reading NetworkManagementVpcFlowLogsConfig %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading VpcFlowLogsConfig: %s", err) } @@ -522,6 +548,19 @@ func resourceNetworkManagementVpcFlowLogsConfigRead(d *schema.ResourceData, meta } func resourceNetworkManagementVpcFlowLogsConfigUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceNetworkManagementVpcFlowLogsConfig().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceNetworkManagementVpcFlowLogsConfigRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -730,6 +769,13 @@ func resourceNetworkManagementVpcFlowLogsConfigUpdate(d *schema.ResourceData, me } func resourceNetworkManagementVpcFlowLogsConfigDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy NetworkManagementVpcFlowLogsConfig without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing VpcFlowLogsConfig %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/networkmanagement/resource_network_management_vpc_flow_logs_config_generated_meta.yaml b/google-beta/services/networkmanagement/resource_network_management_vpc_flow_logs_config_generated_meta.yaml index ffd41a8d2c8..d2be4546233 100644 --- a/google-beta/services/networkmanagement/resource_network_management_vpc_flow_logs_config_generated_meta.yaml +++ b/google-beta/services/networkmanagement/resource_network_management_vpc_flow_logs_config_generated_meta.yaml @@ -31,3 +31,5 @@ fields: - field: vpc_flow_logs_config_id provider_only: true - api_field: vpnTunnel + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/networksecurity/resource_network_security_address_group.go b/google-beta/services/networksecurity/resource_network_security_address_group.go index 7722a123ded..9280dfe95a8 100644 --- a/google-beta/services/networksecurity/resource_network_security_address_group.go +++ b/google-beta/services/networksecurity/resource_network_security_address_group.go @@ -115,6 +115,7 @@ func ResourceNetworkSecurityAddressGroup() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -231,6 +232,19 @@ Examples: "2014-10-02T15:01:23Z" and "2014-10-02T15:01:23.045123456Z"`, A timestamp in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine fractional digits. Examples: "2014-10-02T15:01:23Z" and "2014-10-02T15:01:23.045123456Z".`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -387,6 +401,20 @@ func resourceNetworkSecurityAddressGroupRead(d *schema.ResourceData, meta interf log.Printf("[DEBUG] Finished reading NetworkSecurityAddressGroup %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceNetworkSecurityAddressGroupFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -420,6 +448,18 @@ func resourceNetworkSecurityAddressGroupRead(d *schema.ResourceData, meta interf } func resourceNetworkSecurityAddressGroupUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceNetworkSecurityAddressGroup().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceNetworkSecurityAddressGroupRead(d, meta) + } var project string config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) @@ -553,6 +593,13 @@ func resourceNetworkSecurityAddressGroupUpdate(d *schema.ResourceData, meta inte } func resourceNetworkSecurityAddressGroupDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy NetworkSecurityAddressGroup without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing AddressGroup %q from Terraform state without deletion", d.Id()) + return nil + } var project string config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) diff --git a/google-beta/services/networksecurity/resource_network_security_address_group_generated_meta.yaml b/google-beta/services/networksecurity/resource_network_security_address_group_generated_meta.yaml index 0a22fdc110f..079658a028f 100644 --- a/google-beta/services/networksecurity/resource_network_security_address_group_generated_meta.yaml +++ b/google-beta/services/networksecurity/resource_network_security_address_group_generated_meta.yaml @@ -25,3 +25,5 @@ fields: provider_only: true - api_field: type - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/networksecurity/resource_network_security_authorization_policy.go b/google-beta/services/networksecurity/resource_network_security_authorization_policy.go index e564fdbf81b..8fbced96a14 100644 --- a/google-beta/services/networksecurity/resource_network_security_authorization_policy.go +++ b/google-beta/services/networksecurity/resource_network_security_authorization_policy.go @@ -116,6 +116,7 @@ func ResourceNetworkSecurityAuthorizationPolicy() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -297,6 +298,18 @@ Authorization based on the principal name without certificate validation (config Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -452,6 +465,19 @@ func resourceNetworkSecurityAuthorizationPolicyRead(d *schema.ResourceData, meta log.Printf("[DEBUG] Finished reading NetworkSecurityAuthorizationPolicy %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading AuthorizationPolicy: %s", err) } @@ -489,6 +515,19 @@ func resourceNetworkSecurityAuthorizationPolicyRead(d *schema.ResourceData, meta } func resourceNetworkSecurityAuthorizationPolicyUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceNetworkSecurityAuthorizationPolicy().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceNetworkSecurityAuthorizationPolicyRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -617,6 +656,13 @@ func resourceNetworkSecurityAuthorizationPolicyUpdate(d *schema.ResourceData, me } func resourceNetworkSecurityAuthorizationPolicyDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy NetworkSecurityAuthorizationPolicy without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing AuthorizationPolicy %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/networksecurity/resource_network_security_authorization_policy_generated_meta.yaml b/google-beta/services/networksecurity/resource_network_security_authorization_policy_generated_meta.yaml index 264d010800a..c506dee8713 100644 --- a/google-beta/services/networksecurity/resource_network_security_authorization_policy_generated_meta.yaml +++ b/google-beta/services/networksecurity/resource_network_security_authorization_policy_generated_meta.yaml @@ -27,3 +27,5 @@ fields: - field: terraform_labels provider_only: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/networksecurity/resource_network_security_authz_policy.go b/google-beta/services/networksecurity/resource_network_security_authz_policy.go index 3f0dceb48c2..64559cc8143 100644 --- a/google-beta/services/networksecurity/resource_network_security_authz_policy.go +++ b/google-beta/services/networksecurity/resource_network_security_authz_policy.go @@ -116,6 +116,7 @@ func ResourceNetworkSecurityAuthzPolicy() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -1139,6 +1140,18 @@ RESPONSE_HEADERS, RESPONSE_BODY, RESPONSE_TRAILERS) with FULL_DUPLEX_STREAMED bo Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -1318,6 +1331,19 @@ func resourceNetworkSecurityAuthzPolicyRead(d *schema.ResourceData, meta interfa log.Printf("[DEBUG] Finished reading NetworkSecurityAuthzPolicy %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading AuthzPolicy: %s", err) } @@ -1355,6 +1381,19 @@ func resourceNetworkSecurityAuthzPolicyRead(d *schema.ResourceData, meta interfa } func resourceNetworkSecurityAuthzPolicyUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceNetworkSecurityAuthzPolicy().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceNetworkSecurityAuthzPolicyRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1513,6 +1552,13 @@ func resourceNetworkSecurityAuthzPolicyUpdate(d *schema.ResourceData, meta inter } func resourceNetworkSecurityAuthzPolicyDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy NetworkSecurityAuthzPolicy without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing AuthzPolicy %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/networksecurity/resource_network_security_authz_policy_generated_meta.yaml b/google-beta/services/networksecurity/resource_network_security_authz_policy_generated_meta.yaml index f9b7c4db907..e9ccc75e1df 100644 --- a/google-beta/services/networksecurity/resource_network_security_authz_policy_generated_meta.yaml +++ b/google-beta/services/networksecurity/resource_network_security_authz_policy_generated_meta.yaml @@ -104,3 +104,5 @@ fields: - field: terraform_labels provider_only: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/networksecurity/resource_network_security_backend_authentication_config.go b/google-beta/services/networksecurity/resource_network_security_backend_authentication_config.go index 80008291f89..32a5674ba03 100644 --- a/google-beta/services/networksecurity/resource_network_security_backend_authentication_config.go +++ b/google-beta/services/networksecurity/resource_network_security_backend_authentication_config.go @@ -116,6 +116,7 @@ func ResourceNetworkSecurityBackendAuthenticationConfig() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -222,6 +223,18 @@ Validation with these roots is only considered when the TlsSettings.sni field in Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -383,6 +396,19 @@ func resourceNetworkSecurityBackendAuthenticationConfigRead(d *schema.ResourceDa log.Printf("[DEBUG] Finished reading NetworkSecurityBackendAuthenticationConfig %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading BackendAuthenticationConfig: %s", err) } @@ -420,6 +446,19 @@ func resourceNetworkSecurityBackendAuthenticationConfigRead(d *schema.ResourceDa } func resourceNetworkSecurityBackendAuthenticationConfigUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceNetworkSecurityBackendAuthenticationConfig().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceNetworkSecurityBackendAuthenticationConfigRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -538,6 +577,13 @@ func resourceNetworkSecurityBackendAuthenticationConfigUpdate(d *schema.Resource } func resourceNetworkSecurityBackendAuthenticationConfigDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy NetworkSecurityBackendAuthenticationConfig without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing BackendAuthenticationConfig %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/networksecurity/resource_network_security_backend_authentication_config_generated_meta.yaml b/google-beta/services/networksecurity/resource_network_security_backend_authentication_config_generated_meta.yaml index 9f46c5c606d..aa3ec02df2e 100644 --- a/google-beta/services/networksecurity/resource_network_security_backend_authentication_config_generated_meta.yaml +++ b/google-beta/services/networksecurity/resource_network_security_backend_authentication_config_generated_meta.yaml @@ -22,3 +22,5 @@ fields: - api_field: trustConfig - api_field: updateTime - api_field: wellKnownRoots + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/networksecurity/resource_network_security_client_tls_policy.go b/google-beta/services/networksecurity/resource_network_security_client_tls_policy.go index cb87812f823..fb0928aa558 100644 --- a/google-beta/services/networksecurity/resource_network_security_client_tls_policy.go +++ b/google-beta/services/networksecurity/resource_network_security_client_tls_policy.go @@ -116,6 +116,7 @@ func ResourceNetworkSecurityClientTlsPolicy() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -286,6 +287,18 @@ The default value is 'global'.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -447,6 +460,19 @@ func resourceNetworkSecurityClientTlsPolicyRead(d *schema.ResourceData, meta int log.Printf("[DEBUG] Finished reading NetworkSecurityClientTlsPolicy %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading ClientTlsPolicy: %s", err) } @@ -484,6 +510,19 @@ func resourceNetworkSecurityClientTlsPolicyRead(d *schema.ResourceData, meta int } func resourceNetworkSecurityClientTlsPolicyUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceNetworkSecurityClientTlsPolicy().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceNetworkSecurityClientTlsPolicyRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -622,6 +661,13 @@ func resourceNetworkSecurityClientTlsPolicyUpdate(d *schema.ResourceData, meta i } func resourceNetworkSecurityClientTlsPolicyDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy NetworkSecurityClientTlsPolicy without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing ClientTlsPolicy %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/networksecurity/resource_network_security_client_tls_policy_generated_meta.yaml b/google-beta/services/networksecurity/resource_network_security_client_tls_policy_generated_meta.yaml index 89922961014..70385bf3f30 100644 --- a/google-beta/services/networksecurity/resource_network_security_client_tls_policy_generated_meta.yaml +++ b/google-beta/services/networksecurity/resource_network_security_client_tls_policy_generated_meta.yaml @@ -24,3 +24,5 @@ fields: - field: terraform_labels provider_only: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/networksecurity/resource_network_security_dns_threat_detector.go b/google-beta/services/networksecurity/resource_network_security_dns_threat_detector.go index d69aa69a438..4f0cda94eb4 100644 --- a/google-beta/services/networksecurity/resource_network_security_dns_threat_detector.go +++ b/google-beta/services/networksecurity/resource_network_security_dns_threat_detector.go @@ -116,6 +116,7 @@ func ResourceNetworkSecurityDnsThreatDetector() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -213,6 +214,18 @@ Examples: "2014-10-02T15:01:23Z" and "2014-10-02T15:01:23.045123456Z".`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -358,6 +371,19 @@ func resourceNetworkSecurityDnsThreatDetectorRead(d *schema.ResourceData, meta i log.Printf("[DEBUG] Finished reading NetworkSecurityDnsThreatDetector %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading DnsThreatDetector: %s", err) } @@ -395,6 +421,19 @@ func resourceNetworkSecurityDnsThreatDetectorRead(d *schema.ResourceData, meta i } func resourceNetworkSecurityDnsThreatDetectorUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceNetworkSecurityDnsThreatDetector().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceNetworkSecurityDnsThreatDetectorRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -496,6 +535,13 @@ func resourceNetworkSecurityDnsThreatDetectorUpdate(d *schema.ResourceData, meta } func resourceNetworkSecurityDnsThreatDetectorDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy NetworkSecurityDnsThreatDetector without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing DnsThreatDetector %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/networksecurity/resource_network_security_dns_threat_detector_generated_meta.yaml b/google-beta/services/networksecurity/resource_network_security_dns_threat_detector_generated_meta.yaml index 2b70683cc42..189d4ca23b0 100644 --- a/google-beta/services/networksecurity/resource_network_security_dns_threat_detector_generated_meta.yaml +++ b/google-beta/services/networksecurity/resource_network_security_dns_threat_detector_generated_meta.yaml @@ -20,3 +20,5 @@ fields: - api_field: provider field: threat_detector_provider - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/networksecurity/resource_network_security_firewall_endpoint.go b/google-beta/services/networksecurity/resource_network_security_firewall_endpoint.go index f7b8daab5cc..bc7f3b13de7 100644 --- a/google-beta/services/networksecurity/resource_network_security_firewall_endpoint.go +++ b/google-beta/services/networksecurity/resource_network_security_firewall_endpoint.go @@ -115,6 +115,7 @@ func ResourceNetworkSecurityFirewallEndpoint() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -244,6 +245,19 @@ fully configured. Format: projects/{project}/global/networks/{name}.`, Computed: true, Description: `Time the firewall endpoint was updated in UTC.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -382,6 +396,20 @@ func resourceNetworkSecurityFirewallEndpointRead(d *schema.ResourceData, meta in log.Printf("[DEBUG] Finished reading NetworkSecurityFirewallEndpoint %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceNetworkSecurityFirewallEndpointFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -415,6 +443,18 @@ func resourceNetworkSecurityFirewallEndpointRead(d *schema.ResourceData, meta in } func resourceNetworkSecurityFirewallEndpointUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceNetworkSecurityFirewallEndpoint().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceNetworkSecurityFirewallEndpointRead(d, meta) + } var project string config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) @@ -528,6 +568,13 @@ func resourceNetworkSecurityFirewallEndpointUpdate(d *schema.ResourceData, meta } func resourceNetworkSecurityFirewallEndpointDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy NetworkSecurityFirewallEndpoint without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing FirewallEndpoint %q from Terraform state without deletion", d.Id()) + return nil + } var project string config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) diff --git a/google-beta/services/networksecurity/resource_network_security_firewall_endpoint_association.go b/google-beta/services/networksecurity/resource_network_security_firewall_endpoint_association.go index b23078d47ab..c72062a5b46 100644 --- a/google-beta/services/networksecurity/resource_network_security_firewall_endpoint_association.go +++ b/google-beta/services/networksecurity/resource_network_security_firewall_endpoint_association.go @@ -115,6 +115,7 @@ func ResourceNetworkSecurityFirewallEndpointAssociation() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -232,6 +233,19 @@ Format: projects/{project_id}.`, Computed: true, Description: `Time the firewall endpoint was updated in UTC.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -382,6 +396,20 @@ func resourceNetworkSecurityFirewallEndpointAssociationRead(d *schema.ResourceDa log.Printf("[DEBUG] Finished reading NetworkSecurityFirewallEndpointAssociation %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceNetworkSecurityFirewallEndpointAssociationFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -415,6 +443,18 @@ func resourceNetworkSecurityFirewallEndpointAssociationRead(d *schema.ResourceDa } func resourceNetworkSecurityFirewallEndpointAssociationUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceNetworkSecurityFirewallEndpointAssociation().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceNetworkSecurityFirewallEndpointAssociationRead(d, meta) + } var project string config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) @@ -548,6 +588,13 @@ func resourceNetworkSecurityFirewallEndpointAssociationUpdate(d *schema.Resource } func resourceNetworkSecurityFirewallEndpointAssociationDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy NetworkSecurityFirewallEndpointAssociation without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing FirewallEndpointAssociation %q from Terraform state without deletion", d.Id()) + return nil + } var project string config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) diff --git a/google-beta/services/networksecurity/resource_network_security_firewall_endpoint_association_generated_meta.yaml b/google-beta/services/networksecurity/resource_network_security_firewall_endpoint_association_generated_meta.yaml index 860b6fa2928..b29e956100b 100644 --- a/google-beta/services/networksecurity/resource_network_security_firewall_endpoint_association_generated_meta.yaml +++ b/google-beta/services/networksecurity/resource_network_security_firewall_endpoint_association_generated_meta.yaml @@ -27,3 +27,5 @@ fields: provider_only: true - api_field: tlsInspectionPolicy - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/networksecurity/resource_network_security_firewall_endpoint_generated_meta.yaml b/google-beta/services/networksecurity/resource_network_security_firewall_endpoint_generated_meta.yaml index 3464b994395..93ce009009a 100644 --- a/google-beta/services/networksecurity/resource_network_security_firewall_endpoint_generated_meta.yaml +++ b/google-beta/services/networksecurity/resource_network_security_firewall_endpoint_generated_meta.yaml @@ -26,3 +26,5 @@ fields: - field: terraform_labels provider_only: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/networksecurity/resource_network_security_gateway_security_policy.go b/google-beta/services/networksecurity/resource_network_security_gateway_security_policy.go index 1a715f89bff..1421f7fd860 100644 --- a/google-beta/services/networksecurity/resource_network_security_gateway_security_policy.go +++ b/google-beta/services/networksecurity/resource_network_security_gateway_security_policy.go @@ -115,6 +115,7 @@ func ResourceNetworkSecurityGatewaySecurityPolicy() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -189,6 +190,18 @@ Examples: "2014-10-02T15:01:23Z" and "2014-10-02T15:01:23.045123456Z".`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -332,6 +345,19 @@ func resourceNetworkSecurityGatewaySecurityPolicyRead(d *schema.ResourceData, me log.Printf("[DEBUG] Finished reading NetworkSecurityGatewaySecurityPolicy %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading GatewaySecurityPolicy: %s", err) } @@ -369,6 +395,19 @@ func resourceNetworkSecurityGatewaySecurityPolicyRead(d *schema.ResourceData, me } func resourceNetworkSecurityGatewaySecurityPolicyUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceNetworkSecurityGatewaySecurityPolicy().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceNetworkSecurityGatewaySecurityPolicyRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -477,6 +516,13 @@ func resourceNetworkSecurityGatewaySecurityPolicyUpdate(d *schema.ResourceData, } func resourceNetworkSecurityGatewaySecurityPolicyDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy NetworkSecurityGatewaySecurityPolicy without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing GatewaySecurityPolicy %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/networksecurity/resource_network_security_gateway_security_policy_generated_meta.yaml b/google-beta/services/networksecurity/resource_network_security_gateway_security_policy_generated_meta.yaml index 829c7f348c6..466d7dbcb90 100644 --- a/google-beta/services/networksecurity/resource_network_security_gateway_security_policy_generated_meta.yaml +++ b/google-beta/services/networksecurity/resource_network_security_gateway_security_policy_generated_meta.yaml @@ -16,3 +16,5 @@ fields: - api_field: selfLink - api_field: tlsInspectionPolicy - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/networksecurity/resource_network_security_gateway_security_policy_rule.go b/google-beta/services/networksecurity/resource_network_security_gateway_security_policy_rule.go index 1f963354863..69cdb4aa5fc 100644 --- a/google-beta/services/networksecurity/resource_network_security_gateway_security_policy_rule.go +++ b/google-beta/services/networksecurity/resource_network_security_gateway_security_policy_rule.go @@ -115,6 +115,7 @@ func ResourceNetworkSecurityGatewaySecurityPolicyRule() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -226,6 +227,18 @@ Examples: "2014-10-02T15:01:23Z" and "2014-10-02T15:01:23.045123456Z".`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -411,6 +424,19 @@ func resourceNetworkSecurityGatewaySecurityPolicyRuleRead(d *schema.ResourceData log.Printf("[DEBUG] Finished reading NetworkSecurityGatewaySecurityPolicyRule %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading GatewaySecurityPolicyRule: %s", err) } @@ -454,6 +480,19 @@ func resourceNetworkSecurityGatewaySecurityPolicyRuleRead(d *schema.ResourceData } func resourceNetworkSecurityGatewaySecurityPolicyRuleUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceNetworkSecurityGatewaySecurityPolicyRule().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceNetworkSecurityGatewaySecurityPolicyRuleRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -624,6 +663,13 @@ func resourceNetworkSecurityGatewaySecurityPolicyRuleUpdate(d *schema.ResourceDa } func resourceNetworkSecurityGatewaySecurityPolicyRuleDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy NetworkSecurityGatewaySecurityPolicyRule without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing GatewaySecurityPolicyRule %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/networksecurity/resource_network_security_gateway_security_policy_rule_generated_meta.yaml b/google-beta/services/networksecurity/resource_network_security_gateway_security_policy_rule_generated_meta.yaml index d469443c4fc..1430ecdf080 100644 --- a/google-beta/services/networksecurity/resource_network_security_gateway_security_policy_rule_generated_meta.yaml +++ b/google-beta/services/networksecurity/resource_network_security_gateway_security_policy_rule_generated_meta.yaml @@ -23,3 +23,5 @@ fields: - api_field: sessionMatcher - api_field: tlsInspectionEnabled - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/networksecurity/resource_network_security_intercept_deployment.go b/google-beta/services/networksecurity/resource_network_security_intercept_deployment.go index 28792e329fd..31baaa34c27 100644 --- a/google-beta/services/networksecurity/resource_network_security_intercept_deployment.go +++ b/google-beta/services/networksecurity/resource_network_security_intercept_deployment.go @@ -116,6 +116,7 @@ func ResourceNetworkSecurityInterceptDeployment() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -245,6 +246,18 @@ See https://google.aip.dev/148#timestamps.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -400,6 +413,19 @@ func resourceNetworkSecurityInterceptDeploymentRead(d *schema.ResourceData, meta log.Printf("[DEBUG] Finished reading NetworkSecurityInterceptDeployment %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading InterceptDeployment: %s", err) } @@ -437,6 +463,19 @@ func resourceNetworkSecurityInterceptDeploymentRead(d *schema.ResourceData, meta } func resourceNetworkSecurityInterceptDeploymentUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceNetworkSecurityInterceptDeployment().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceNetworkSecurityInterceptDeploymentRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -545,6 +584,13 @@ func resourceNetworkSecurityInterceptDeploymentUpdate(d *schema.ResourceData, me } func resourceNetworkSecurityInterceptDeploymentDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy NetworkSecurityInterceptDeployment without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing InterceptDeployment %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/networksecurity/resource_network_security_intercept_deployment_generated_meta.yaml b/google-beta/services/networksecurity/resource_network_security_intercept_deployment_generated_meta.yaml index 0ef5292edc2..983fe7de008 100644 --- a/google-beta/services/networksecurity/resource_network_security_intercept_deployment_generated_meta.yaml +++ b/google-beta/services/networksecurity/resource_network_security_intercept_deployment_generated_meta.yaml @@ -24,3 +24,5 @@ fields: - field: terraform_labels provider_only: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/networksecurity/resource_network_security_intercept_deployment_group.go b/google-beta/services/networksecurity/resource_network_security_intercept_deployment_group.go index 659a4c6186a..da0e518fb39 100644 --- a/google-beta/services/networksecurity/resource_network_security_intercept_deployment_group.go +++ b/google-beta/services/networksecurity/resource_network_security_intercept_deployment_group.go @@ -116,6 +116,7 @@ func ResourceNetworkSecurityInterceptDeploymentGroup() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -258,6 +259,18 @@ See https://google.aip.dev/148#timestamps.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -428,6 +441,19 @@ func resourceNetworkSecurityInterceptDeploymentGroupRead(d *schema.ResourceData, log.Printf("[DEBUG] Finished reading NetworkSecurityInterceptDeploymentGroup %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading InterceptDeploymentGroup: %s", err) } @@ -465,6 +491,19 @@ func resourceNetworkSecurityInterceptDeploymentGroupRead(d *schema.ResourceData, } func resourceNetworkSecurityInterceptDeploymentGroupUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceNetworkSecurityInterceptDeploymentGroup().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceNetworkSecurityInterceptDeploymentGroupRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -573,6 +612,13 @@ func resourceNetworkSecurityInterceptDeploymentGroupUpdate(d *schema.ResourceDat } func resourceNetworkSecurityInterceptDeploymentGroupDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy NetworkSecurityInterceptDeploymentGroup without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing InterceptDeploymentGroup %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/networksecurity/resource_network_security_intercept_deployment_group_generated_meta.yaml b/google-beta/services/networksecurity/resource_network_security_intercept_deployment_group_generated_meta.yaml index 18237541862..66643f3fe80 100644 --- a/google-beta/services/networksecurity/resource_network_security_intercept_deployment_group_generated_meta.yaml +++ b/google-beta/services/networksecurity/resource_network_security_intercept_deployment_group_generated_meta.yaml @@ -26,3 +26,5 @@ fields: - field: terraform_labels provider_only: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/networksecurity/resource_network_security_intercept_endpoint_group.go b/google-beta/services/networksecurity/resource_network_security_intercept_endpoint_group.go index 22b1cbaed1a..a845d126934 100644 --- a/google-beta/services/networksecurity/resource_network_security_intercept_endpoint_group.go +++ b/google-beta/services/networksecurity/resource_network_security_intercept_endpoint_group.go @@ -116,6 +116,7 @@ func ResourceNetworkSecurityInterceptEndpointGroup() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -268,6 +269,18 @@ See https://google.aip.dev/148#timestamps.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -472,6 +485,19 @@ func resourceNetworkSecurityInterceptEndpointGroupRead(d *schema.ResourceData, m log.Printf("[DEBUG] Finished reading NetworkSecurityInterceptEndpointGroup %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading InterceptEndpointGroup: %s", err) } @@ -509,6 +535,19 @@ func resourceNetworkSecurityInterceptEndpointGroupRead(d *schema.ResourceData, m } func resourceNetworkSecurityInterceptEndpointGroupUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceNetworkSecurityInterceptEndpointGroup().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceNetworkSecurityInterceptEndpointGroupRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -617,6 +656,13 @@ func resourceNetworkSecurityInterceptEndpointGroupUpdate(d *schema.ResourceData, } func resourceNetworkSecurityInterceptEndpointGroupDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy NetworkSecurityInterceptEndpointGroup without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing InterceptEndpointGroup %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/networksecurity/resource_network_security_intercept_endpoint_group_association.go b/google-beta/services/networksecurity/resource_network_security_intercept_endpoint_group_association.go index a9d796ca584..dab9064dbfa 100644 --- a/google-beta/services/networksecurity/resource_network_security_intercept_endpoint_group_association.go +++ b/google-beta/services/networksecurity/resource_network_security_intercept_endpoint_group_association.go @@ -116,6 +116,7 @@ func ResourceNetworkSecurityInterceptEndpointGroupAssociation() *schema.Resource CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -274,6 +275,18 @@ See https://google.aip.dev/148#timestamps.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -444,6 +457,19 @@ func resourceNetworkSecurityInterceptEndpointGroupAssociationRead(d *schema.Reso log.Printf("[DEBUG] Finished reading NetworkSecurityInterceptEndpointGroupAssociation %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading InterceptEndpointGroupAssociation: %s", err) } @@ -481,6 +507,19 @@ func resourceNetworkSecurityInterceptEndpointGroupAssociationRead(d *schema.Reso } func resourceNetworkSecurityInterceptEndpointGroupAssociationUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceNetworkSecurityInterceptEndpointGroupAssociation().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceNetworkSecurityInterceptEndpointGroupAssociationRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -579,6 +618,13 @@ func resourceNetworkSecurityInterceptEndpointGroupAssociationUpdate(d *schema.Re } func resourceNetworkSecurityInterceptEndpointGroupAssociationDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy NetworkSecurityInterceptEndpointGroupAssociation without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing InterceptEndpointGroupAssociation %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/networksecurity/resource_network_security_intercept_endpoint_group_association_generated_meta.yaml b/google-beta/services/networksecurity/resource_network_security_intercept_endpoint_group_association_generated_meta.yaml index 7c84fa8620f..03ad4c34c8d 100644 --- a/google-beta/services/networksecurity/resource_network_security_intercept_endpoint_group_association_generated_meta.yaml +++ b/google-beta/services/networksecurity/resource_network_security_intercept_endpoint_group_association_generated_meta.yaml @@ -27,3 +27,5 @@ fields: - field: terraform_labels provider_only: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/networksecurity/resource_network_security_intercept_endpoint_group_generated_meta.yaml b/google-beta/services/networksecurity/resource_network_security_intercept_endpoint_group_generated_meta.yaml index 4e2aa98b3a8..5a147697ff4 100644 --- a/google-beta/services/networksecurity/resource_network_security_intercept_endpoint_group_generated_meta.yaml +++ b/google-beta/services/networksecurity/resource_network_security_intercept_endpoint_group_generated_meta.yaml @@ -29,3 +29,5 @@ fields: - field: terraform_labels provider_only: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/networksecurity/resource_network_security_mirroring_deployment.go b/google-beta/services/networksecurity/resource_network_security_mirroring_deployment.go index c4223c4e8f3..6c0f1b7d526 100644 --- a/google-beta/services/networksecurity/resource_network_security_mirroring_deployment.go +++ b/google-beta/services/networksecurity/resource_network_security_mirroring_deployment.go @@ -116,6 +116,7 @@ func ResourceNetworkSecurityMirroringDeployment() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -245,6 +246,18 @@ See https://google.aip.dev/148#timestamps.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -400,6 +413,19 @@ func resourceNetworkSecurityMirroringDeploymentRead(d *schema.ResourceData, meta log.Printf("[DEBUG] Finished reading NetworkSecurityMirroringDeployment %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading MirroringDeployment: %s", err) } @@ -437,6 +463,19 @@ func resourceNetworkSecurityMirroringDeploymentRead(d *schema.ResourceData, meta } func resourceNetworkSecurityMirroringDeploymentUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceNetworkSecurityMirroringDeployment().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceNetworkSecurityMirroringDeploymentRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -545,6 +584,13 @@ func resourceNetworkSecurityMirroringDeploymentUpdate(d *schema.ResourceData, me } func resourceNetworkSecurityMirroringDeploymentDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy NetworkSecurityMirroringDeployment without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing MirroringDeployment %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/networksecurity/resource_network_security_mirroring_deployment_generated_meta.yaml b/google-beta/services/networksecurity/resource_network_security_mirroring_deployment_generated_meta.yaml index 34a8277cc06..eba69fa3dfe 100644 --- a/google-beta/services/networksecurity/resource_network_security_mirroring_deployment_generated_meta.yaml +++ b/google-beta/services/networksecurity/resource_network_security_mirroring_deployment_generated_meta.yaml @@ -24,3 +24,5 @@ fields: - field: terraform_labels provider_only: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/networksecurity/resource_network_security_mirroring_deployment_group.go b/google-beta/services/networksecurity/resource_network_security_mirroring_deployment_group.go index 7ad2409ded7..de5a9dd91fa 100644 --- a/google-beta/services/networksecurity/resource_network_security_mirroring_deployment_group.go +++ b/google-beta/services/networksecurity/resource_network_security_mirroring_deployment_group.go @@ -116,6 +116,7 @@ func ResourceNetworkSecurityMirroringDeploymentGroup() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -258,6 +259,18 @@ See https://google.aip.dev/148#timestamps.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -428,6 +441,19 @@ func resourceNetworkSecurityMirroringDeploymentGroupRead(d *schema.ResourceData, log.Printf("[DEBUG] Finished reading NetworkSecurityMirroringDeploymentGroup %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading MirroringDeploymentGroup: %s", err) } @@ -465,6 +491,19 @@ func resourceNetworkSecurityMirroringDeploymentGroupRead(d *schema.ResourceData, } func resourceNetworkSecurityMirroringDeploymentGroupUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceNetworkSecurityMirroringDeploymentGroup().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceNetworkSecurityMirroringDeploymentGroupRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -573,6 +612,13 @@ func resourceNetworkSecurityMirroringDeploymentGroupUpdate(d *schema.ResourceDat } func resourceNetworkSecurityMirroringDeploymentGroupDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy NetworkSecurityMirroringDeploymentGroup without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing MirroringDeploymentGroup %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/networksecurity/resource_network_security_mirroring_deployment_group_generated_meta.yaml b/google-beta/services/networksecurity/resource_network_security_mirroring_deployment_group_generated_meta.yaml index 7b5168972b0..369ff090b1f 100644 --- a/google-beta/services/networksecurity/resource_network_security_mirroring_deployment_group_generated_meta.yaml +++ b/google-beta/services/networksecurity/resource_network_security_mirroring_deployment_group_generated_meta.yaml @@ -26,3 +26,5 @@ fields: - field: terraform_labels provider_only: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/networksecurity/resource_network_security_mirroring_endpoint.go b/google-beta/services/networksecurity/resource_network_security_mirroring_endpoint.go index 932e3da4681..3c18779e3fa 100644 --- a/google-beta/services/networksecurity/resource_network_security_mirroring_endpoint.go +++ b/google-beta/services/networksecurity/resource_network_security_mirroring_endpoint.go @@ -116,6 +116,7 @@ func ResourceNetworkSecurityMirroringEndpoint() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -237,6 +238,18 @@ See https://google.aip.dev/148#timestamps.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -386,6 +399,19 @@ func resourceNetworkSecurityMirroringEndpointRead(d *schema.ResourceData, meta i log.Printf("[DEBUG] Finished reading NetworkSecurityMirroringEndpoint %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading MirroringEndpoint: %s", err) } @@ -423,6 +449,19 @@ func resourceNetworkSecurityMirroringEndpointRead(d *schema.ResourceData, meta i } func resourceNetworkSecurityMirroringEndpointUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceNetworkSecurityMirroringEndpoint().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceNetworkSecurityMirroringEndpointRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -531,6 +570,13 @@ func resourceNetworkSecurityMirroringEndpointUpdate(d *schema.ResourceData, meta } func resourceNetworkSecurityMirroringEndpointDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy NetworkSecurityMirroringEndpoint without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing MirroringEndpoint %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/networksecurity/resource_network_security_mirroring_endpoint_generated_meta.yaml b/google-beta/services/networksecurity/resource_network_security_mirroring_endpoint_generated_meta.yaml index ae31ddcae27..c31da7d7e4c 100644 --- a/google-beta/services/networksecurity/resource_network_security_mirroring_endpoint_generated_meta.yaml +++ b/google-beta/services/networksecurity/resource_network_security_mirroring_endpoint_generated_meta.yaml @@ -23,3 +23,5 @@ fields: - field: terraform_labels provider_only: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/networksecurity/resource_network_security_mirroring_endpoint_group.go b/google-beta/services/networksecurity/resource_network_security_mirroring_endpoint_group.go index 6c6178d2b1a..bbc09e32daa 100644 --- a/google-beta/services/networksecurity/resource_network_security_mirroring_endpoint_group.go +++ b/google-beta/services/networksecurity/resource_network_security_mirroring_endpoint_group.go @@ -116,6 +116,7 @@ func ResourceNetworkSecurityMirroringEndpointGroup() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -278,6 +279,18 @@ See https://google.aip.dev/148#timestamps.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -515,6 +528,19 @@ func resourceNetworkSecurityMirroringEndpointGroupRead(d *schema.ResourceData, m log.Printf("[DEBUG] Finished reading NetworkSecurityMirroringEndpointGroup %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading MirroringEndpointGroup: %s", err) } @@ -552,6 +578,19 @@ func resourceNetworkSecurityMirroringEndpointGroupRead(d *schema.ResourceData, m } func resourceNetworkSecurityMirroringEndpointGroupUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceNetworkSecurityMirroringEndpointGroup().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceNetworkSecurityMirroringEndpointGroupRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -660,6 +699,13 @@ func resourceNetworkSecurityMirroringEndpointGroupUpdate(d *schema.ResourceData, } func resourceNetworkSecurityMirroringEndpointGroupDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy NetworkSecurityMirroringEndpointGroup without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing MirroringEndpointGroup %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/networksecurity/resource_network_security_mirroring_endpoint_group_association.go b/google-beta/services/networksecurity/resource_network_security_mirroring_endpoint_group_association.go index 1d1a2da5862..fb3b47974ec 100644 --- a/google-beta/services/networksecurity/resource_network_security_mirroring_endpoint_group_association.go +++ b/google-beta/services/networksecurity/resource_network_security_mirroring_endpoint_group_association.go @@ -116,6 +116,7 @@ func ResourceNetworkSecurityMirroringEndpointGroupAssociation() *schema.Resource CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -274,6 +275,18 @@ See https://google.aip.dev/148#timestamps.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -444,6 +457,19 @@ func resourceNetworkSecurityMirroringEndpointGroupAssociationRead(d *schema.Reso log.Printf("[DEBUG] Finished reading NetworkSecurityMirroringEndpointGroupAssociation %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading MirroringEndpointGroupAssociation: %s", err) } @@ -481,6 +507,19 @@ func resourceNetworkSecurityMirroringEndpointGroupAssociationRead(d *schema.Reso } func resourceNetworkSecurityMirroringEndpointGroupAssociationUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceNetworkSecurityMirroringEndpointGroupAssociation().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceNetworkSecurityMirroringEndpointGroupAssociationRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -579,6 +618,13 @@ func resourceNetworkSecurityMirroringEndpointGroupAssociationUpdate(d *schema.Re } func resourceNetworkSecurityMirroringEndpointGroupAssociationDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy NetworkSecurityMirroringEndpointGroupAssociation without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing MirroringEndpointGroupAssociation %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/networksecurity/resource_network_security_mirroring_endpoint_group_association_generated_meta.yaml b/google-beta/services/networksecurity/resource_network_security_mirroring_endpoint_group_association_generated_meta.yaml index 94cbb4431cc..4f8a7d5649e 100644 --- a/google-beta/services/networksecurity/resource_network_security_mirroring_endpoint_group_association_generated_meta.yaml +++ b/google-beta/services/networksecurity/resource_network_security_mirroring_endpoint_group_association_generated_meta.yaml @@ -27,3 +27,5 @@ fields: - field: terraform_labels provider_only: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/networksecurity/resource_network_security_mirroring_endpoint_group_generated_meta.yaml b/google-beta/services/networksecurity/resource_network_security_mirroring_endpoint_group_generated_meta.yaml index 91880bafd6c..b37cfb1a888 100644 --- a/google-beta/services/networksecurity/resource_network_security_mirroring_endpoint_group_generated_meta.yaml +++ b/google-beta/services/networksecurity/resource_network_security_mirroring_endpoint_group_generated_meta.yaml @@ -31,3 +31,5 @@ fields: provider_only: true - api_field: type - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/networksecurity/resource_network_security_sac_attachment.go b/google-beta/services/networksecurity/resource_network_security_sac_attachment.go index 530ff01e3a0..cc0c106a6ff 100644 --- a/google-beta/services/networksecurity/resource_network_security_sac_attachment.go +++ b/google-beta/services/networksecurity/resource_network_security_sac_attachment.go @@ -116,6 +116,7 @@ func ResourceNetworkSecuritySacAttachment() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -246,6 +247,18 @@ Please refer to the field 'effective_labels' for all of the labels present on th Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -419,6 +432,19 @@ func resourceNetworkSecuritySacAttachmentRead(d *schema.ResourceData, meta inter log.Printf("[DEBUG] Finished reading NetworkSecuritySacAttachment %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading SacAttachment: %s", err) } @@ -456,11 +482,18 @@ func resourceNetworkSecuritySacAttachmentRead(d *schema.ResourceData, meta inter } func resourceNetworkSecuritySacAttachmentUpdate(d *schema.ResourceData, meta interface{}) error { - // Only the root field "labels", "terraform_labels", and virtual fields are mutable + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable return resourceNetworkSecuritySacAttachmentRead(d, meta) } func resourceNetworkSecuritySacAttachmentDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy NetworkSecuritySacAttachment without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing SacAttachment %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/networksecurity/resource_network_security_sac_attachment_generated_meta.yaml b/google-beta/services/networksecurity/resource_network_security_sac_attachment_generated_meta.yaml index 3f515786d13..cfc8ce66d82 100644 --- a/google-beta/services/networksecurity/resource_network_security_sac_attachment_generated_meta.yaml +++ b/google-beta/services/networksecurity/resource_network_security_sac_attachment_generated_meta.yaml @@ -24,3 +24,5 @@ fields: provider_only: true - api_field: timeZone - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/networksecurity/resource_network_security_sac_realm.go b/google-beta/services/networksecurity/resource_network_security_sac_realm.go index eecb15281e6..fe853048c0a 100644 --- a/google-beta/services/networksecurity/resource_network_security_sac_realm.go +++ b/google-beta/services/networksecurity/resource_network_security_sac_realm.go @@ -116,6 +116,7 @@ func ResourceNetworkSecuritySacRealm() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -246,6 +247,18 @@ A secret ID, secret name, or secret URI can be specified, but it will be parsed Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -396,6 +409,19 @@ func resourceNetworkSecuritySacRealmRead(d *schema.ResourceData, meta interface{ log.Printf("[DEBUG] Finished reading NetworkSecuritySacRealm %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading SacRealm: %s", err) } @@ -427,11 +453,18 @@ func resourceNetworkSecuritySacRealmRead(d *schema.ResourceData, meta interface{ } func resourceNetworkSecuritySacRealmUpdate(d *schema.ResourceData, meta interface{}) error { - // Only the root field "labels", "terraform_labels", and virtual fields are mutable + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable return resourceNetworkSecuritySacRealmRead(d, meta) } func resourceNetworkSecuritySacRealmDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy NetworkSecuritySacRealm without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing SacRealm %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/networksecurity/resource_network_security_sac_realm_generated_meta.yaml b/google-beta/services/networksecurity/resource_network_security_sac_realm_generated_meta.yaml index 0d2b97a51b5..e0592a32fb1 100644 --- a/google-beta/services/networksecurity/resource_network_security_sac_realm_generated_meta.yaml +++ b/google-beta/services/networksecurity/resource_network_security_sac_realm_generated_meta.yaml @@ -22,3 +22,5 @@ fields: - field: terraform_labels provider_only: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/networksecurity/resource_network_security_security_profile.go b/google-beta/services/networksecurity/resource_network_security_security_profile.go index 910d3e73411..4eca0485eb5 100644 --- a/google-beta/services/networksecurity/resource_network_security_security_profile.go +++ b/google-beta/services/networksecurity/resource_network_security_security_profile.go @@ -115,6 +115,7 @@ func ResourceNetworkSecuritySecurityProfile() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -330,6 +331,19 @@ value before proceeding.`, Computed: true, Description: `Time the security profile was updated in UTC.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -582,6 +596,20 @@ func resourceNetworkSecuritySecurityProfileRead(d *schema.ResourceData, meta int log.Printf("[DEBUG] Finished reading NetworkSecuritySecurityProfile %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceNetworkSecuritySecurityProfileFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -615,6 +643,18 @@ func resourceNetworkSecuritySecurityProfileRead(d *schema.ResourceData, meta int } func resourceNetworkSecuritySecurityProfileUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceNetworkSecuritySecurityProfile().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceNetworkSecuritySecurityProfileRead(d, meta) + } var project string config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) @@ -758,6 +798,13 @@ func resourceNetworkSecuritySecurityProfileUpdate(d *schema.ResourceData, meta i } func resourceNetworkSecuritySecurityProfileDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy NetworkSecuritySecurityProfile without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing SecurityProfile %q from Terraform state without deletion", d.Id()) + return nil + } var project string config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) diff --git a/google-beta/services/networksecurity/resource_network_security_security_profile_generated_meta.yaml b/google-beta/services/networksecurity/resource_network_security_security_profile_generated_meta.yaml index d16d7280d4d..35a48fadbe0 100644 --- a/google-beta/services/networksecurity/resource_network_security_security_profile_generated_meta.yaml +++ b/google-beta/services/networksecurity/resource_network_security_security_profile_generated_meta.yaml @@ -38,3 +38,5 @@ fields: - api_field: urlFilteringProfile.urlFilters.filteringAction - api_field: urlFilteringProfile.urlFilters.priority - api_field: urlFilteringProfile.urlFilters.urls + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/networksecurity/resource_network_security_security_profile_group.go b/google-beta/services/networksecurity/resource_network_security_security_profile_group.go index b83dac36691..b0c0d9d1254 100644 --- a/google-beta/services/networksecurity/resource_network_security_security_profile_group.go +++ b/google-beta/services/networksecurity/resource_network_security_security_profile_group.go @@ -115,6 +115,7 @@ func ResourceNetworkSecuritySecurityProfileGroup() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -227,6 +228,19 @@ value before proceeding.`, Computed: true, Description: `Time the security profile group was updated in UTC.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -383,6 +397,20 @@ func resourceNetworkSecuritySecurityProfileGroupRead(d *schema.ResourceData, met log.Printf("[DEBUG] Finished reading NetworkSecuritySecurityProfileGroup %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceNetworkSecuritySecurityProfileGroupFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -416,6 +444,18 @@ func resourceNetworkSecuritySecurityProfileGroupRead(d *schema.ResourceData, met } func resourceNetworkSecuritySecurityProfileGroupUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceNetworkSecuritySecurityProfileGroup().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceNetworkSecuritySecurityProfileGroupRead(d, meta) + } var project string config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) @@ -559,6 +599,13 @@ func resourceNetworkSecuritySecurityProfileGroupUpdate(d *schema.ResourceData, m } func resourceNetworkSecuritySecurityProfileGroupDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy NetworkSecuritySecurityProfileGroup without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing SecurityProfileGroup %q from Terraform state without deletion", d.Id()) + return nil + } var project string config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) diff --git a/google-beta/services/networksecurity/resource_network_security_security_profile_group_generated_meta.yaml b/google-beta/services/networksecurity/resource_network_security_security_profile_group_generated_meta.yaml index 369fdf70e73..94fa4bd9c7c 100644 --- a/google-beta/services/networksecurity/resource_network_security_security_profile_group_generated_meta.yaml +++ b/google-beta/services/networksecurity/resource_network_security_security_profile_group_generated_meta.yaml @@ -26,3 +26,5 @@ fields: - api_field: threatPreventionProfile - api_field: updateTime - api_field: urlFilteringProfile + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/networksecurity/resource_network_security_server_tls_policy.go b/google-beta/services/networksecurity/resource_network_security_server_tls_policy.go index 5e05dc3a057..d6ddb7abc25 100644 --- a/google-beta/services/networksecurity/resource_network_security_server_tls_policy.go +++ b/google-beta/services/networksecurity/resource_network_security_server_tls_policy.go @@ -116,6 +116,7 @@ func ResourceNetworkSecurityServerTlsPolicy() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -318,6 +319,18 @@ Defines a mechanism to provision server identity (public and private keys). Cann Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -479,6 +492,19 @@ func resourceNetworkSecurityServerTlsPolicyRead(d *schema.ResourceData, meta int log.Printf("[DEBUG] Finished reading NetworkSecurityServerTlsPolicy %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading ServerTlsPolicy: %s", err) } @@ -516,6 +542,19 @@ func resourceNetworkSecurityServerTlsPolicyRead(d *schema.ResourceData, meta int } func resourceNetworkSecurityServerTlsPolicyUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceNetworkSecurityServerTlsPolicy().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceNetworkSecurityServerTlsPolicyRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -654,6 +693,13 @@ func resourceNetworkSecurityServerTlsPolicyUpdate(d *schema.ResourceData, meta i } func resourceNetworkSecurityServerTlsPolicyDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy NetworkSecurityServerTlsPolicy without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing ServerTlsPolicy %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/networksecurity/resource_network_security_server_tls_policy_generated_meta.yaml b/google-beta/services/networksecurity/resource_network_security_server_tls_policy_generated_meta.yaml index 524efaa3ca4..83c5ec6dd67 100644 --- a/google-beta/services/networksecurity/resource_network_security_server_tls_policy_generated_meta.yaml +++ b/google-beta/services/networksecurity/resource_network_security_server_tls_policy_generated_meta.yaml @@ -26,3 +26,5 @@ fields: - field: terraform_labels provider_only: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/networksecurity/resource_network_security_tls_inspection_policy.go b/google-beta/services/networksecurity/resource_network_security_tls_inspection_policy.go index 11b8c65a6af..fc743110e59 100644 --- a/google-beta/services/networksecurity/resource_network_security_tls_inspection_policy.go +++ b/google-beta/services/networksecurity/resource_network_security_tls_inspection_policy.go @@ -115,6 +115,7 @@ func ResourceNetworkSecurityTlsInspectionPolicy() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -210,6 +211,18 @@ func ResourceNetworkSecurityTlsInspectionPolicy() *schema.Resource { Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -383,6 +396,19 @@ func resourceNetworkSecurityTlsInspectionPolicyRead(d *schema.ResourceData, meta log.Printf("[DEBUG] Finished reading NetworkSecurityTlsInspectionPolicy %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading TlsInspectionPolicy: %s", err) } @@ -420,6 +446,19 @@ func resourceNetworkSecurityTlsInspectionPolicyRead(d *schema.ResourceData, meta } func resourceNetworkSecurityTlsInspectionPolicyUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceNetworkSecurityTlsInspectionPolicy().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceNetworkSecurityTlsInspectionPolicyRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -578,6 +617,13 @@ func resourceNetworkSecurityTlsInspectionPolicyUpdate(d *schema.ResourceData, me } func resourceNetworkSecurityTlsInspectionPolicyDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy NetworkSecurityTlsInspectionPolicy without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing TlsInspectionPolicy %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/networksecurity/resource_network_security_tls_inspection_policy_generated_meta.yaml b/google-beta/services/networksecurity/resource_network_security_tls_inspection_policy_generated_meta.yaml index 71d321e41a0..639af697e5e 100644 --- a/google-beta/services/networksecurity/resource_network_security_tls_inspection_policy_generated_meta.yaml +++ b/google-beta/services/networksecurity/resource_network_security_tls_inspection_policy_generated_meta.yaml @@ -20,3 +20,5 @@ fields: - api_field: tlsFeatureProfile - api_field: trustConfig - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/networksecurity/resource_network_security_ull_mirroring_collector.go b/google-beta/services/networksecurity/resource_network_security_ull_mirroring_collector.go index 94307d0186b..45a7dcf93dd 100644 --- a/google-beta/services/networksecurity/resource_network_security_ull_mirroring_collector.go +++ b/google-beta/services/networksecurity/resource_network_security_ull_mirroring_collector.go @@ -116,6 +116,7 @@ func ResourceNetworkSecurityUllMirroringCollector() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -234,6 +235,18 @@ See https://google.aip.dev/148#timestamps.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -383,6 +396,19 @@ func resourceNetworkSecurityUllMirroringCollectorRead(d *schema.ResourceData, me log.Printf("[DEBUG] Finished reading NetworkSecurityUllMirroringCollector %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading UllMirroringCollector: %s", err) } @@ -420,6 +446,19 @@ func resourceNetworkSecurityUllMirroringCollectorRead(d *schema.ResourceData, me } func resourceNetworkSecurityUllMirroringCollectorUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceNetworkSecurityUllMirroringCollector().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceNetworkSecurityUllMirroringCollectorRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -518,6 +557,13 @@ func resourceNetworkSecurityUllMirroringCollectorUpdate(d *schema.ResourceData, } func resourceNetworkSecurityUllMirroringCollectorDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy NetworkSecurityUllMirroringCollector without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing UllMirroringCollector %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/networksecurity/resource_network_security_ull_mirroring_collector_generated_meta.yaml b/google-beta/services/networksecurity/resource_network_security_ull_mirroring_collector_generated_meta.yaml index 1fcd9702328..cc47fba02ff 100644 --- a/google-beta/services/networksecurity/resource_network_security_ull_mirroring_collector_generated_meta.yaml +++ b/google-beta/services/networksecurity/resource_network_security_ull_mirroring_collector_generated_meta.yaml @@ -23,3 +23,5 @@ fields: - field: ull_mirroring_collector_id provider_only: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/networksecurity/resource_network_security_ull_mirroring_collector_rule.go b/google-beta/services/networksecurity/resource_network_security_ull_mirroring_collector_rule.go index 4b27fe29198..e992b4d4e8f 100644 --- a/google-beta/services/networksecurity/resource_network_security_ull_mirroring_collector_rule.go +++ b/google-beta/services/networksecurity/resource_network_security_ull_mirroring_collector_rule.go @@ -116,6 +116,7 @@ func ResourceNetworkSecurityUllMirroringCollectorRule() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -257,6 +258,18 @@ https://google.aip.dev/128.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -405,6 +418,19 @@ func resourceNetworkSecurityUllMirroringCollectorRuleRead(d *schema.ResourceData log.Printf("[DEBUG] Finished reading NetworkSecurityUllMirroringCollectorRule %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading UllMirroringCollectorRule: %s", err) } @@ -448,6 +474,19 @@ func resourceNetworkSecurityUllMirroringCollectorRuleRead(d *schema.ResourceData } func resourceNetworkSecurityUllMirroringCollectorRuleUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceNetworkSecurityUllMirroringCollectorRule().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceNetworkSecurityUllMirroringCollectorRuleRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -561,6 +600,13 @@ func resourceNetworkSecurityUllMirroringCollectorRuleUpdate(d *schema.ResourceDa } func resourceNetworkSecurityUllMirroringCollectorRuleDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy NetworkSecurityUllMirroringCollectorRule without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing UllMirroringCollectorRule %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/networksecurity/resource_network_security_ull_mirroring_collector_rule_generated_meta.yaml b/google-beta/services/networksecurity/resource_network_security_ull_mirroring_collector_rule_generated_meta.yaml index 64ad3038fc2..3886aeafee0 100644 --- a/google-beta/services/networksecurity/resource_network_security_ull_mirroring_collector_rule_generated_meta.yaml +++ b/google-beta/services/networksecurity/resource_network_security_ull_mirroring_collector_rule_generated_meta.yaml @@ -27,3 +27,5 @@ fields: - field: ull_mirroring_collector_rule_id provider_only: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/networksecurity/resource_network_security_ull_mirroring_engine.go b/google-beta/services/networksecurity/resource_network_security_ull_mirroring_engine.go index e79e2377950..0395814a2aa 100644 --- a/google-beta/services/networksecurity/resource_network_security_ull_mirroring_engine.go +++ b/google-beta/services/networksecurity/resource_network_security_ull_mirroring_engine.go @@ -116,6 +116,7 @@ func ResourceNetworkSecurityUllMirroringEngine() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -209,6 +210,18 @@ See https://google.aip.dev/148#timestamps.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -346,6 +359,19 @@ func resourceNetworkSecurityUllMirroringEngineRead(d *schema.ResourceData, meta log.Printf("[DEBUG] Finished reading NetworkSecurityUllMirroringEngine %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading UllMirroringEngine: %s", err) } @@ -383,6 +409,19 @@ func resourceNetworkSecurityUllMirroringEngineRead(d *schema.ResourceData, meta } func resourceNetworkSecurityUllMirroringEngineUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceNetworkSecurityUllMirroringEngine().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceNetworkSecurityUllMirroringEngineRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -481,6 +520,13 @@ func resourceNetworkSecurityUllMirroringEngineUpdate(d *schema.ResourceData, met } func resourceNetworkSecurityUllMirroringEngineDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy NetworkSecurityUllMirroringEngine without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing UllMirroringEngine %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/networksecurity/resource_network_security_ull_mirroring_engine_generated_meta.yaml b/google-beta/services/networksecurity/resource_network_security_ull_mirroring_engine_generated_meta.yaml index c1d874789bf..c4060006dab 100644 --- a/google-beta/services/networksecurity/resource_network_security_ull_mirroring_engine_generated_meta.yaml +++ b/google-beta/services/networksecurity/resource_network_security_ull_mirroring_engine_generated_meta.yaml @@ -20,3 +20,5 @@ fields: - field: ull_mirroring_engine_id provider_only: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/networksecurity/resource_network_security_url_lists.go b/google-beta/services/networksecurity/resource_network_security_url_lists.go index a6173644476..3493d100811 100644 --- a/google-beta/services/networksecurity/resource_network_security_url_lists.go +++ b/google-beta/services/networksecurity/resource_network_security_url_lists.go @@ -115,6 +115,7 @@ func ResourceNetworkSecurityUrlLists() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -185,6 +186,18 @@ Examples: '2014-10-02T15:01:23Z' and '2014-10-02T15:01:23.045123456Z'.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -328,6 +341,19 @@ func resourceNetworkSecurityUrlListsRead(d *schema.ResourceData, meta interface{ log.Printf("[DEBUG] Finished reading NetworkSecurityUrlLists %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading UrlLists: %s", err) } @@ -365,6 +391,19 @@ func resourceNetworkSecurityUrlListsRead(d *schema.ResourceData, meta interface{ } func resourceNetworkSecurityUrlListsUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceNetworkSecurityUrlLists().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceNetworkSecurityUrlListsRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -473,6 +512,13 @@ func resourceNetworkSecurityUrlListsUpdate(d *schema.ResourceData, meta interfac } func resourceNetworkSecurityUrlListsDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy NetworkSecurityUrlLists without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing UrlLists %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/networksecurity/resource_network_security_url_lists_generated_meta.yaml b/google-beta/services/networksecurity/resource_network_security_url_lists_generated_meta.yaml index 33eae87e680..093a35c1df1 100644 --- a/google-beta/services/networksecurity/resource_network_security_url_lists_generated_meta.yaml +++ b/google-beta/services/networksecurity/resource_network_security_url_lists_generated_meta.yaml @@ -15,3 +15,5 @@ fields: provider_only: true - api_field: updateTime - api_field: values + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/networkservices/resource_network_services_agent_gateway.go b/google-beta/services/networkservices/resource_network_services_agent_gateway.go index a43774fee3e..d62b9fb773c 100644 --- a/google-beta/services/networkservices/resource_network_services_agent_gateway.go +++ b/google-beta/services/networkservices/resource_network_services_agent_gateway.go @@ -116,6 +116,7 @@ func ResourceNetworkServicesAgentGateway() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -318,6 +319,18 @@ error.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -497,6 +510,19 @@ func resourceNetworkServicesAgentGatewayRead(d *schema.ResourceData, meta interf log.Printf("[DEBUG] Finished reading NetworkServicesAgentGateway %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading AgentGateway: %s", err) } @@ -534,6 +560,19 @@ func resourceNetworkServicesAgentGatewayRead(d *schema.ResourceData, meta interf } func resourceNetworkServicesAgentGatewayUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceNetworkServicesAgentGateway().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceNetworkServicesAgentGatewayRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -682,6 +721,13 @@ func resourceNetworkServicesAgentGatewayUpdate(d *schema.ResourceData, meta inte } func resourceNetworkServicesAgentGatewayDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy NetworkServicesAgentGateway without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing AgentGateway %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/networkservices/resource_network_services_agent_gateway_generated_meta.yaml b/google-beta/services/networkservices/resource_network_services_agent_gateway_generated_meta.yaml index 2bc3654d787..1d34c83566b 100644 --- a/google-beta/services/networkservices/resource_network_services_agent_gateway_generated_meta.yaml +++ b/google-beta/services/networkservices/resource_network_services_agent_gateway_generated_meta.yaml @@ -28,3 +28,5 @@ fields: - field: terraform_labels provider_only: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/networkservices/resource_network_services_authz_extension.go b/google-beta/services/networkservices/resource_network_services_authz_extension.go index bc983be634f..0f0f300c7dc 100644 --- a/google-beta/services/networkservices/resource_network_services_authz_extension.go +++ b/google-beta/services/networkservices/resource_network_services_authz_extension.go @@ -116,6 +116,7 @@ func ResourceNetworkServicesAuthzExtension() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -274,6 +275,18 @@ Supported values: Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -471,6 +484,19 @@ func resourceNetworkServicesAuthzExtensionRead(d *schema.ResourceData, meta inte log.Printf("[DEBUG] Finished reading NetworkServicesAuthzExtension %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading AuthzExtension: %s", err) } @@ -508,6 +534,19 @@ func resourceNetworkServicesAuthzExtensionRead(d *schema.ResourceData, meta inte } func resourceNetworkServicesAuthzExtensionUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceNetworkServicesAuthzExtension().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceNetworkServicesAuthzExtensionRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -706,6 +745,13 @@ func resourceNetworkServicesAuthzExtensionUpdate(d *schema.ResourceData, meta in } func resourceNetworkServicesAuthzExtensionDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy NetworkServicesAuthzExtension without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing AuthzExtension %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/networkservices/resource_network_services_authz_extension_generated_meta.yaml b/google-beta/services/networkservices/resource_network_services_authz_extension_generated_meta.yaml index f8aefa67708..19410f22723 100644 --- a/google-beta/services/networkservices/resource_network_services_authz_extension_generated_meta.yaml +++ b/google-beta/services/networkservices/resource_network_services_authz_extension_generated_meta.yaml @@ -26,3 +26,5 @@ fields: - api_field: timeout - api_field: updateTime - api_field: wireFormat + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/networkservices/resource_network_services_edge_cache_keyset.go b/google-beta/services/networkservices/resource_network_services_edge_cache_keyset.go index 753bd2ede9d..79d3d307c76 100644 --- a/google-beta/services/networkservices/resource_network_services_edge_cache_keyset.go +++ b/google-beta/services/networkservices/resource_network_services_edge_cache_keyset.go @@ -116,6 +116,7 @@ func ResourceNetworkServicesEdgeCacheKeyset() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -242,6 +243,18 @@ See RFC 2104, Section 3 for more details on these recommendations.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -394,6 +407,19 @@ func resourceNetworkServicesEdgeCacheKeysetRead(d *schema.ResourceData, meta int log.Printf("[DEBUG] Finished reading NetworkServicesEdgeCacheKeyset %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading EdgeCacheKeyset: %s", err) } @@ -425,6 +451,19 @@ func resourceNetworkServicesEdgeCacheKeysetRead(d *schema.ResourceData, meta int } func resourceNetworkServicesEdgeCacheKeysetUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceNetworkServicesEdgeCacheKeyset().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceNetworkServicesEdgeCacheKeysetRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -549,6 +588,13 @@ func resourceNetworkServicesEdgeCacheKeysetUpdate(d *schema.ResourceData, meta i } func resourceNetworkServicesEdgeCacheKeysetDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy NetworkServicesEdgeCacheKeyset without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing EdgeCacheKeyset %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/networkservices/resource_network_services_edge_cache_keyset_generated_meta.yaml b/google-beta/services/networkservices/resource_network_services_edge_cache_keyset_generated_meta.yaml index 4b6a347de91..4d1eb72afcf 100644 --- a/google-beta/services/networkservices/resource_network_services_edge_cache_keyset_generated_meta.yaml +++ b/google-beta/services/networkservices/resource_network_services_edge_cache_keyset_generated_meta.yaml @@ -22,3 +22,5 @@ fields: - field: terraform_labels provider_only: true - api_field: validationSharedKeys.secretVersion + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/networkservices/resource_network_services_edge_cache_origin.go b/google-beta/services/networkservices/resource_network_services_edge_cache_origin.go index bf16af1a433..fea9d1b9f9d 100644 --- a/google-beta/services/networkservices/resource_network_services_edge_cache_origin.go +++ b/google-beta/services/networkservices/resource_network_services_edge_cache_origin.go @@ -116,6 +116,7 @@ func ResourceNetworkServicesEdgeCacheOrigin() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -467,6 +468,18 @@ If the response headers have already been written to the connection, the respons Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -671,6 +684,19 @@ func resourceNetworkServicesEdgeCacheOriginRead(d *schema.ResourceData, meta int log.Printf("[DEBUG] Finished reading NetworkServicesEdgeCacheOrigin %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading EdgeCacheOrigin: %s", err) } @@ -702,6 +728,19 @@ func resourceNetworkServicesEdgeCacheOriginRead(d *schema.ResourceData, meta int } func resourceNetworkServicesEdgeCacheOriginUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceNetworkServicesEdgeCacheOrigin().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceNetworkServicesEdgeCacheOriginRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -915,6 +954,13 @@ func resourceNetworkServicesEdgeCacheOriginUpdate(d *schema.ResourceData, meta i } func resourceNetworkServicesEdgeCacheOriginDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy NetworkServicesEdgeCacheOrigin without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing EdgeCacheOrigin %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/networkservices/resource_network_services_edge_cache_origin_generated_meta.yaml b/google-beta/services/networkservices/resource_network_services_edge_cache_origin_generated_meta.yaml index 9314786711d..37ee914fa63 100644 --- a/google-beta/services/networkservices/resource_network_services_edge_cache_origin_generated_meta.yaml +++ b/google-beta/services/networkservices/resource_network_services_edge_cache_origin_generated_meta.yaml @@ -34,3 +34,5 @@ fields: - api_field: timeout.maxAttemptsTimeout - api_field: timeout.readTimeout - api_field: timeout.responseTimeout + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/networkservices/resource_network_services_edge_cache_service.go b/google-beta/services/networkservices/resource_network_services_edge_cache_service.go index c42ad192ef5..73077371876 100644 --- a/google-beta/services/networkservices/resource_network_services_edge_cache_service.go +++ b/google-beta/services/networkservices/resource_network_services_edge_cache_service.go @@ -116,6 +116,7 @@ func ResourceNetworkServicesEdgeCacheService() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -1133,6 +1134,18 @@ If not set, the EdgeCacheService has no SSL policy configured, and will default Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -1324,6 +1337,19 @@ func resourceNetworkServicesEdgeCacheServiceRead(d *schema.ResourceData, meta in log.Printf("[DEBUG] Finished reading NetworkServicesEdgeCacheService %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading EdgeCacheService: %s", err) } @@ -1355,6 +1381,19 @@ func resourceNetworkServicesEdgeCacheServiceRead(d *schema.ResourceData, meta in } func resourceNetworkServicesEdgeCacheServiceUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceNetworkServicesEdgeCacheService().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceNetworkServicesEdgeCacheServiceRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1543,6 +1582,13 @@ func resourceNetworkServicesEdgeCacheServiceUpdate(d *schema.ResourceData, meta } func resourceNetworkServicesEdgeCacheServiceDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy NetworkServicesEdgeCacheService without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing EdgeCacheService %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/networkservices/resource_network_services_edge_cache_service_generated_meta.yaml b/google-beta/services/networkservices/resource_network_services_edge_cache_service_generated_meta.yaml index 967a721b1ec..5dea0a11e80 100644 --- a/google-beta/services/networkservices/resource_network_services_edge_cache_service_generated_meta.yaml +++ b/google-beta/services/networkservices/resource_network_services_edge_cache_service_generated_meta.yaml @@ -165,3 +165,5 @@ fields: - api_field: sslPolicy - field: terraform_labels provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/networkservices/resource_network_services_endpoint_policy.go b/google-beta/services/networkservices/resource_network_services_endpoint_policy.go index be23f1681a3..147ef8de39d 100644 --- a/google-beta/services/networkservices/resource_network_services_endpoint_policy.go +++ b/google-beta/services/networkservices/resource_network_services_endpoint_policy.go @@ -116,6 +116,7 @@ func ResourceNetworkServicesEndpointPolicy() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -271,6 +272,18 @@ Please refer to the field 'effective_labels' for all of the labels present on th Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -445,6 +458,19 @@ func resourceNetworkServicesEndpointPolicyRead(d *schema.ResourceData, meta inte log.Printf("[DEBUG] Finished reading NetworkServicesEndpointPolicy %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading EndpointPolicy: %s", err) } @@ -476,6 +502,19 @@ func resourceNetworkServicesEndpointPolicyRead(d *schema.ResourceData, meta inte } func resourceNetworkServicesEndpointPolicyUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceNetworkServicesEndpointPolicy().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceNetworkServicesEndpointPolicyRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -639,6 +678,13 @@ func resourceNetworkServicesEndpointPolicyUpdate(d *schema.ResourceData, meta in } func resourceNetworkServicesEndpointPolicyDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy NetworkServicesEndpointPolicy without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing EndpointPolicy %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/networkservices/resource_network_services_endpoint_policy_generated_meta.yaml b/google-beta/services/networkservices/resource_network_services_endpoint_policy_generated_meta.yaml index 2bcd023cb2b..117926ed752 100644 --- a/google-beta/services/networkservices/resource_network_services_endpoint_policy_generated_meta.yaml +++ b/google-beta/services/networkservices/resource_network_services_endpoint_policy_generated_meta.yaml @@ -25,3 +25,5 @@ fields: - api_field: trafficPortSelector.ports - api_field: type - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/networkservices/resource_network_services_gateway.go b/google-beta/services/networkservices/resource_network_services_gateway.go index 7190ec87849..5108fd82a60 100644 --- a/google-beta/services/networkservices/resource_network_services_gateway.go +++ b/google-beta/services/networkservices/resource_network_services_gateway.go @@ -239,6 +239,7 @@ func ResourceNetworkServicesGateway() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -444,6 +445,18 @@ If there is no other gateway of type 'SECURE_WEB_GATEWAY' remaining for that reg Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -671,6 +684,18 @@ func resourceNetworkServicesGatewayRead(d *schema.ResourceData, meta interface{} return fmt.Errorf("Error setting delete_swg_autogen_router_on_destroy: %s", err) } } + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Gateway: %s", err) } @@ -708,6 +733,19 @@ func resourceNetworkServicesGatewayRead(d *schema.ResourceData, meta interface{} } func resourceNetworkServicesGatewayUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceNetworkServicesGateway().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceNetworkServicesGatewayRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -891,6 +929,13 @@ func resourceNetworkServicesGatewayUpdate(d *schema.ResourceData, meta interface } func resourceNetworkServicesGatewayDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy NetworkServicesGateway without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Gateway %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/networkservices/resource_network_services_gateway_generated_meta.yaml b/google-beta/services/networkservices/resource_network_services_gateway_generated_meta.yaml index 9208bdd8a3d..b6af14611aa 100644 --- a/google-beta/services/networkservices/resource_network_services_gateway_generated_meta.yaml +++ b/google-beta/services/networkservices/resource_network_services_gateway_generated_meta.yaml @@ -35,3 +35,5 @@ fields: provider_only: true - api_field: type - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/networkservices/resource_network_services_grpc_route.go b/google-beta/services/networkservices/resource_network_services_grpc_route.go index d1a6950faca..a2ad51adf20 100644 --- a/google-beta/services/networkservices/resource_network_services_grpc_route.go +++ b/google-beta/services/networkservices/resource_network_services_grpc_route.go @@ -125,6 +125,7 @@ func ResourceNetworkServicesGrpcRoute() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -415,6 +416,18 @@ Please refer to the field 'effective_labels' for all of the labels present on th Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -582,6 +595,19 @@ func resourceNetworkServicesGrpcRouteRead(d *schema.ResourceData, meta interface log.Printf("[DEBUG] Finished reading NetworkServicesGrpcRoute %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading GrpcRoute: %s", err) } @@ -619,6 +645,19 @@ func resourceNetworkServicesGrpcRouteRead(d *schema.ResourceData, meta interface } func resourceNetworkServicesGrpcRouteUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceNetworkServicesGrpcRoute().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceNetworkServicesGrpcRouteRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -767,6 +806,13 @@ func resourceNetworkServicesGrpcRouteUpdate(d *schema.ResourceData, meta interfa } func resourceNetworkServicesGrpcRouteDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy NetworkServicesGrpcRoute without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing GrpcRoute %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/networkservices/resource_network_services_grpc_route_generated_meta.yaml b/google-beta/services/networkservices/resource_network_services_grpc_route_generated_meta.yaml index caf542ae320..1243affb5ed 100644 --- a/google-beta/services/networkservices/resource_network_services_grpc_route_generated_meta.yaml +++ b/google-beta/services/networkservices/resource_network_services_grpc_route_generated_meta.yaml @@ -38,3 +38,5 @@ fields: - field: terraform_labels provider_only: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/networkservices/resource_network_services_http_route.go b/google-beta/services/networkservices/resource_network_services_http_route.go index b97104031b2..91e3e63a168 100644 --- a/google-beta/services/networkservices/resource_network_services_http_route.go +++ b/google-beta/services/networkservices/resource_network_services_http_route.go @@ -116,6 +116,7 @@ func ResourceNetworkServicesHttpRoute() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -702,6 +703,18 @@ The attached Mesh should be of a type SIDECAR.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -864,6 +877,19 @@ func resourceNetworkServicesHttpRouteRead(d *schema.ResourceData, meta interface log.Printf("[DEBUG] Finished reading NetworkServicesHttpRoute %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading HttpRoute: %s", err) } @@ -895,6 +921,19 @@ func resourceNetworkServicesHttpRouteRead(d *schema.ResourceData, meta interface } func resourceNetworkServicesHttpRouteUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceNetworkServicesHttpRoute().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceNetworkServicesHttpRouteRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1038,6 +1077,13 @@ func resourceNetworkServicesHttpRouteUpdate(d *schema.ResourceData, meta interfa } func resourceNetworkServicesHttpRouteDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy NetworkServicesHttpRoute without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing HttpRoute %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/networkservices/resource_network_services_http_route_generated_meta.yaml b/google-beta/services/networkservices/resource_network_services_http_route_generated_meta.yaml index 9390d426472..252998c825f 100644 --- a/google-beta/services/networkservices/resource_network_services_http_route_generated_meta.yaml +++ b/google-beta/services/networkservices/resource_network_services_http_route_generated_meta.yaml @@ -73,3 +73,5 @@ fields: - field: terraform_labels provider_only: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/networkservices/resource_network_services_lb_edge_extension.go b/google-beta/services/networkservices/resource_network_services_lb_edge_extension.go index 16a166a6251..b9410dfbe20 100644 --- a/google-beta/services/networkservices/resource_network_services_lb_edge_extension.go +++ b/google-beta/services/networkservices/resource_network_services_lb_edge_extension.go @@ -116,6 +116,7 @@ func ResourceNetworkServicesLbEdgeExtension() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -296,6 +297,18 @@ Please refer to the field 'effective_labels' for all of the labels present on th Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -457,6 +470,19 @@ func resourceNetworkServicesLbEdgeExtensionRead(d *schema.ResourceData, meta int log.Printf("[DEBUG] Finished reading NetworkServicesLbEdgeExtension %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading LbEdgeExtension: %s", err) } @@ -494,6 +520,19 @@ func resourceNetworkServicesLbEdgeExtensionRead(d *schema.ResourceData, meta int } func resourceNetworkServicesLbEdgeExtensionUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceNetworkServicesLbEdgeExtension().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceNetworkServicesLbEdgeExtensionRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -622,6 +661,13 @@ func resourceNetworkServicesLbEdgeExtensionUpdate(d *schema.ResourceData, meta i } func resourceNetworkServicesLbEdgeExtensionDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy NetworkServicesLbEdgeExtension without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing LbEdgeExtension %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/networkservices/resource_network_services_lb_edge_extension_generated_meta.yaml b/google-beta/services/networkservices/resource_network_services_lb_edge_extension_generated_meta.yaml index 86296be5822..6fdcb7eeb97 100644 --- a/google-beta/services/networkservices/resource_network_services_lb_edge_extension_generated_meta.yaml +++ b/google-beta/services/networkservices/resource_network_services_lb_edge_extension_generated_meta.yaml @@ -26,3 +26,5 @@ fields: provider_only: true - field: terraform_labels provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/networkservices/resource_network_services_lb_route_extension.go b/google-beta/services/networkservices/resource_network_services_lb_route_extension.go index 0849e10890c..ed20930e091 100644 --- a/google-beta/services/networkservices/resource_network_services_lb_route_extension.go +++ b/google-beta/services/networkservices/resource_network_services_lb_route_extension.go @@ -133,6 +133,7 @@ func ResourceNetworkServicesLbRouteExtension() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -361,6 +362,18 @@ Please refer to the field 'effective_labels' for all of the labels present on th Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -522,6 +535,19 @@ func resourceNetworkServicesLbRouteExtensionRead(d *schema.ResourceData, meta in log.Printf("[DEBUG] Finished reading NetworkServicesLbRouteExtension %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading LbRouteExtension: %s", err) } @@ -559,6 +585,19 @@ func resourceNetworkServicesLbRouteExtensionRead(d *schema.ResourceData, meta in } func resourceNetworkServicesLbRouteExtensionUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceNetworkServicesLbRouteExtension().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceNetworkServicesLbRouteExtensionRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -687,6 +726,13 @@ func resourceNetworkServicesLbRouteExtensionUpdate(d *schema.ResourceData, meta } func resourceNetworkServicesLbRouteExtensionDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy NetworkServicesLbRouteExtension without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing LbRouteExtension %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/networkservices/resource_network_services_lb_route_extension_generated_meta.yaml b/google-beta/services/networkservices/resource_network_services_lb_route_extension_generated_meta.yaml index b0adcec378d..73250308514 100644 --- a/google-beta/services/networkservices/resource_network_services_lb_route_extension_generated_meta.yaml +++ b/google-beta/services/networkservices/resource_network_services_lb_route_extension_generated_meta.yaml @@ -31,3 +31,5 @@ fields: provider_only: true - field: terraform_labels provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/networkservices/resource_network_services_lb_traffic_extension.go b/google-beta/services/networkservices/resource_network_services_lb_traffic_extension.go index 380448dd0a5..b0a0c221662 100644 --- a/google-beta/services/networkservices/resource_network_services_lb_traffic_extension.go +++ b/google-beta/services/networkservices/resource_network_services_lb_traffic_extension.go @@ -116,6 +116,7 @@ func ResourceNetworkServicesLbTrafficExtension() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -322,6 +323,18 @@ Please refer to the field 'effective_labels' for all of the labels present on th Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -483,6 +496,19 @@ func resourceNetworkServicesLbTrafficExtensionRead(d *schema.ResourceData, meta log.Printf("[DEBUG] Finished reading NetworkServicesLbTrafficExtension %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading LbTrafficExtension: %s", err) } @@ -520,6 +546,19 @@ func resourceNetworkServicesLbTrafficExtensionRead(d *schema.ResourceData, meta } func resourceNetworkServicesLbTrafficExtensionUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceNetworkServicesLbTrafficExtension().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceNetworkServicesLbTrafficExtensionRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -648,6 +687,13 @@ func resourceNetworkServicesLbTrafficExtensionUpdate(d *schema.ResourceData, met } func resourceNetworkServicesLbTrafficExtensionDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy NetworkServicesLbTrafficExtension without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing LbTrafficExtension %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/networkservices/resource_network_services_lb_traffic_extension_generated_meta.yaml b/google-beta/services/networkservices/resource_network_services_lb_traffic_extension_generated_meta.yaml index 970225ce98b..5bf7ebfdec1 100644 --- a/google-beta/services/networkservices/resource_network_services_lb_traffic_extension_generated_meta.yaml +++ b/google-beta/services/networkservices/resource_network_services_lb_traffic_extension_generated_meta.yaml @@ -29,3 +29,5 @@ fields: provider_only: true - field: terraform_labels provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/networkservices/resource_network_services_mesh.go b/google-beta/services/networkservices/resource_network_services_mesh.go index 6511a1924c2..6699d17f2fa 100644 --- a/google-beta/services/networkservices/resource_network_services_mesh.go +++ b/google-beta/services/networkservices/resource_network_services_mesh.go @@ -125,6 +125,7 @@ func ResourceNetworkServicesMesh() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -221,6 +222,18 @@ Please refer to the field 'effective_labels' for all of the labels present on th Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -370,6 +383,19 @@ func resourceNetworkServicesMeshRead(d *schema.ResourceData, meta interface{}) e log.Printf("[DEBUG] Finished reading NetworkServicesMesh %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Mesh: %s", err) } @@ -407,6 +433,19 @@ func resourceNetworkServicesMeshRead(d *schema.ResourceData, meta interface{}) e } func resourceNetworkServicesMeshUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceNetworkServicesMesh().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceNetworkServicesMeshRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -525,6 +564,13 @@ func resourceNetworkServicesMeshUpdate(d *schema.ResourceData, meta interface{}) } func resourceNetworkServicesMeshDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy NetworkServicesMesh without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Mesh %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/networkservices/resource_network_services_mesh_generated_meta.yaml b/google-beta/services/networkservices/resource_network_services_mesh_generated_meta.yaml index 1b38f4a4f99..f84fca0287a 100644 --- a/google-beta/services/networkservices/resource_network_services_mesh_generated_meta.yaml +++ b/google-beta/services/networkservices/resource_network_services_mesh_generated_meta.yaml @@ -21,3 +21,5 @@ fields: - field: terraform_labels provider_only: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/networkservices/resource_network_services_multicast_consumer_association.go b/google-beta/services/networkservices/resource_network_services_multicast_consumer_association.go index 91e79b86d9a..be8077832f1 100644 --- a/google-beta/services/networkservices/resource_network_services_multicast_consumer_association.go +++ b/google-beta/services/networkservices/resource_network_services_multicast_consumer_association.go @@ -116,6 +116,7 @@ func ResourceNetworkServicesMulticastConsumerAssociation() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -265,6 +266,18 @@ most recently updated.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -420,6 +433,19 @@ func resourceNetworkServicesMulticastConsumerAssociationRead(d *schema.ResourceD log.Printf("[DEBUG] Finished reading NetworkServicesMulticastConsumerAssociation %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading MulticastConsumerAssociation: %s", err) } @@ -457,6 +483,19 @@ func resourceNetworkServicesMulticastConsumerAssociationRead(d *schema.ResourceD } func resourceNetworkServicesMulticastConsumerAssociationUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceNetworkServicesMulticastConsumerAssociation().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceNetworkServicesMulticastConsumerAssociationRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -565,6 +604,13 @@ func resourceNetworkServicesMulticastConsumerAssociationUpdate(d *schema.Resourc } func resourceNetworkServicesMulticastConsumerAssociationDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy NetworkServicesMulticastConsumerAssociation without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing MulticastConsumerAssociation %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/networkservices/resource_network_services_multicast_consumer_association_generated_meta.yaml b/google-beta/services/networkservices/resource_network_services_multicast_consumer_association_generated_meta.yaml index f35bfeb075c..e71b087423a 100644 --- a/google-beta/services/networkservices/resource_network_services_multicast_consumer_association_generated_meta.yaml +++ b/google-beta/services/networkservices/resource_network_services_multicast_consumer_association_generated_meta.yaml @@ -26,3 +26,5 @@ fields: provider_only: true - api_field: uniqueId - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/networkservices/resource_network_services_multicast_domain.go b/google-beta/services/networkservices/resource_network_services_multicast_domain.go index fda17210867..e1f40f1d479 100644 --- a/google-beta/services/networkservices/resource_network_services_multicast_domain.go +++ b/google-beta/services/networkservices/resource_network_services_multicast_domain.go @@ -116,6 +116,7 @@ func ResourceNetworkServicesMulticastDomain() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -300,6 +301,18 @@ updated.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -467,6 +480,19 @@ func resourceNetworkServicesMulticastDomainRead(d *schema.ResourceData, meta int log.Printf("[DEBUG] Finished reading NetworkServicesMulticastDomain %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading MulticastDomain: %s", err) } @@ -504,6 +530,19 @@ func resourceNetworkServicesMulticastDomainRead(d *schema.ResourceData, meta int } func resourceNetworkServicesMulticastDomainUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceNetworkServicesMulticastDomain().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceNetworkServicesMulticastDomainRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -612,6 +651,13 @@ func resourceNetworkServicesMulticastDomainUpdate(d *schema.ResourceData, meta i } func resourceNetworkServicesMulticastDomainDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy NetworkServicesMulticastDomain without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing MulticastDomain %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/networkservices/resource_network_services_multicast_domain_activation.go b/google-beta/services/networkservices/resource_network_services_multicast_domain_activation.go index 811fa104f0b..4f7d8ddc20d 100644 --- a/google-beta/services/networkservices/resource_network_services_multicast_domain_activation.go +++ b/google-beta/services/networkservices/resource_network_services_multicast_domain_activation.go @@ -116,6 +116,7 @@ func ResourceNetworkServicesMulticastDomainActivation() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -307,6 +308,18 @@ recently updated.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -468,6 +481,19 @@ func resourceNetworkServicesMulticastDomainActivationRead(d *schema.ResourceData log.Printf("[DEBUG] Finished reading NetworkServicesMulticastDomainActivation %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading MulticastDomainActivation: %s", err) } @@ -505,6 +531,19 @@ func resourceNetworkServicesMulticastDomainActivationRead(d *schema.ResourceData } func resourceNetworkServicesMulticastDomainActivationUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceNetworkServicesMulticastDomainActivation().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceNetworkServicesMulticastDomainActivationRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -623,6 +662,13 @@ func resourceNetworkServicesMulticastDomainActivationUpdate(d *schema.ResourceDa } func resourceNetworkServicesMulticastDomainActivationDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy NetworkServicesMulticastDomainActivation without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing MulticastDomainActivation %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/networkservices/resource_network_services_multicast_domain_activation_generated_meta.yaml b/google-beta/services/networkservices/resource_network_services_multicast_domain_activation_generated_meta.yaml index d41937b1797..cf16c79871f 100644 --- a/google-beta/services/networkservices/resource_network_services_multicast_domain_activation_generated_meta.yaml +++ b/google-beta/services/networkservices/resource_network_services_multicast_domain_activation_generated_meta.yaml @@ -31,3 +31,5 @@ fields: - api_field: trafficSpec.maxPerGroupSubscribers - api_field: uniqueId - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/networkservices/resource_network_services_multicast_domain_generated_meta.yaml b/google-beta/services/networkservices/resource_network_services_multicast_domain_generated_meta.yaml index 6300cd84e80..992f1e880be 100644 --- a/google-beta/services/networkservices/resource_network_services_multicast_domain_generated_meta.yaml +++ b/google-beta/services/networkservices/resource_network_services_multicast_domain_generated_meta.yaml @@ -30,3 +30,5 @@ fields: - api_field: ullMulticastDomain.preconfiguredUllDomain - api_field: uniqueId - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/networkservices/resource_network_services_multicast_domain_group.go b/google-beta/services/networkservices/resource_network_services_multicast_domain_group.go index 6bc4ee75cf4..50e77419c1e 100644 --- a/google-beta/services/networkservices/resource_network_services_multicast_domain_group.go +++ b/google-beta/services/networkservices/resource_network_services_multicast_domain_group.go @@ -116,6 +116,7 @@ func ResourceNetworkServicesMulticastDomainGroup() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -247,6 +248,18 @@ recently updated.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -390,6 +403,19 @@ func resourceNetworkServicesMulticastDomainGroupRead(d *schema.ResourceData, met log.Printf("[DEBUG] Finished reading NetworkServicesMulticastDomainGroup %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading MulticastDomainGroup: %s", err) } @@ -427,6 +453,19 @@ func resourceNetworkServicesMulticastDomainGroupRead(d *schema.ResourceData, met } func resourceNetworkServicesMulticastDomainGroupUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceNetworkServicesMulticastDomainGroup().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceNetworkServicesMulticastDomainGroupRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -535,6 +574,13 @@ func resourceNetworkServicesMulticastDomainGroupUpdate(d *schema.ResourceData, m } func resourceNetworkServicesMulticastDomainGroupDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy NetworkServicesMulticastDomainGroup without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing MulticastDomainGroup %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/networkservices/resource_network_services_multicast_domain_group_generated_meta.yaml b/google-beta/services/networkservices/resource_network_services_multicast_domain_group_generated_meta.yaml index 1dd6dcd0643..2a4b7a99d04 100644 --- a/google-beta/services/networkservices/resource_network_services_multicast_domain_group_generated_meta.yaml +++ b/google-beta/services/networkservices/resource_network_services_multicast_domain_group_generated_meta.yaml @@ -24,3 +24,5 @@ fields: provider_only: true - api_field: uniqueId - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/networkservices/resource_network_services_multicast_group_consumer_activation.go b/google-beta/services/networkservices/resource_network_services_multicast_group_consumer_activation.go index 590794e2207..22f777bfad1 100644 --- a/google-beta/services/networkservices/resource_network_services_multicast_group_consumer_activation.go +++ b/google-beta/services/networkservices/resource_network_services_multicast_group_consumer_activation.go @@ -116,6 +116,7 @@ func ResourceNetworkServicesMulticastGroupConsumerActivation() *schema.Resource CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -272,6 +273,18 @@ was most recently updated.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -433,6 +446,19 @@ func resourceNetworkServicesMulticastGroupConsumerActivationRead(d *schema.Resou log.Printf("[DEBUG] Finished reading NetworkServicesMulticastGroupConsumerActivation %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading MulticastGroupConsumerActivation: %s", err) } @@ -470,6 +496,19 @@ func resourceNetworkServicesMulticastGroupConsumerActivationRead(d *schema.Resou } func resourceNetworkServicesMulticastGroupConsumerActivationUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceNetworkServicesMulticastGroupConsumerActivation().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceNetworkServicesMulticastGroupConsumerActivationRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -588,6 +627,13 @@ func resourceNetworkServicesMulticastGroupConsumerActivationUpdate(d *schema.Res } func resourceNetworkServicesMulticastGroupConsumerActivationDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy NetworkServicesMulticastGroupConsumerActivation without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing MulticastGroupConsumerActivation %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/networkservices/resource_network_services_multicast_group_consumer_activation_generated_meta.yaml b/google-beta/services/networkservices/resource_network_services_multicast_group_consumer_activation_generated_meta.yaml index cbe272688b7..2e96e5f123b 100644 --- a/google-beta/services/networkservices/resource_network_services_multicast_group_consumer_activation_generated_meta.yaml +++ b/google-beta/services/networkservices/resource_network_services_multicast_group_consumer_activation_generated_meta.yaml @@ -26,3 +26,5 @@ fields: provider_only: true - api_field: uniqueId - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/networkservices/resource_network_services_multicast_group_producer_activation.go b/google-beta/services/networkservices/resource_network_services_multicast_group_producer_activation.go index 9b548f2ef15..887977af2f9 100644 --- a/google-beta/services/networkservices/resource_network_services_multicast_group_producer_activation.go +++ b/google-beta/services/networkservices/resource_network_services_multicast_group_producer_activation.go @@ -116,6 +116,7 @@ func ResourceNetworkServicesMulticastGroupProducerActivation() *schema.Resource CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -256,6 +257,18 @@ was most recently updated.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -411,6 +424,19 @@ func resourceNetworkServicesMulticastGroupProducerActivationRead(d *schema.Resou log.Printf("[DEBUG] Finished reading NetworkServicesMulticastGroupProducerActivation %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading MulticastGroupProducerActivation: %s", err) } @@ -448,6 +474,19 @@ func resourceNetworkServicesMulticastGroupProducerActivationRead(d *schema.Resou } func resourceNetworkServicesMulticastGroupProducerActivationUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceNetworkServicesMulticastGroupProducerActivation().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceNetworkServicesMulticastGroupProducerActivationRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -556,6 +595,13 @@ func resourceNetworkServicesMulticastGroupProducerActivationUpdate(d *schema.Res } func resourceNetworkServicesMulticastGroupProducerActivationDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy NetworkServicesMulticastGroupProducerActivation without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing MulticastGroupProducerActivation %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/networkservices/resource_network_services_multicast_group_producer_activation_generated_meta.yaml b/google-beta/services/networkservices/resource_network_services_multicast_group_producer_activation_generated_meta.yaml index 9edf6a85f7c..7b471f75943 100644 --- a/google-beta/services/networkservices/resource_network_services_multicast_group_producer_activation_generated_meta.yaml +++ b/google-beta/services/networkservices/resource_network_services_multicast_group_producer_activation_generated_meta.yaml @@ -25,3 +25,5 @@ fields: provider_only: true - api_field: uniqueId - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/networkservices/resource_network_services_multicast_group_range.go b/google-beta/services/networkservices/resource_network_services_multicast_group_range.go index 462457051fb..0b18924c7f7 100644 --- a/google-beta/services/networkservices/resource_network_services_multicast_group_range.go +++ b/google-beta/services/networkservices/resource_network_services_multicast_group_range.go @@ -116,6 +116,7 @@ func ResourceNetworkServicesMulticastGroupRange() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -311,6 +312,18 @@ recently updated.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -490,6 +503,19 @@ func resourceNetworkServicesMulticastGroupRangeRead(d *schema.ResourceData, meta log.Printf("[DEBUG] Finished reading NetworkServicesMulticastGroupRange %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading MulticastGroupRange: %s", err) } @@ -527,6 +553,19 @@ func resourceNetworkServicesMulticastGroupRangeRead(d *schema.ResourceData, meta } func resourceNetworkServicesMulticastGroupRangeUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceNetworkServicesMulticastGroupRange().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceNetworkServicesMulticastGroupRangeRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -665,6 +704,13 @@ func resourceNetworkServicesMulticastGroupRangeUpdate(d *schema.ResourceData, me } func resourceNetworkServicesMulticastGroupRangeDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy NetworkServicesMulticastGroupRange without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing MulticastGroupRange %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/networkservices/resource_network_services_multicast_group_range_activation.go b/google-beta/services/networkservices/resource_network_services_multicast_group_range_activation.go index 103c411921e..a004d5c004b 100644 --- a/google-beta/services/networkservices/resource_network_services_multicast_group_range_activation.go +++ b/google-beta/services/networkservices/resource_network_services_multicast_group_range_activation.go @@ -116,6 +116,7 @@ func ResourceNetworkServicesMulticastGroupRangeActivation() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -286,6 +287,18 @@ most recently updated.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -447,6 +460,19 @@ func resourceNetworkServicesMulticastGroupRangeActivationRead(d *schema.Resource log.Printf("[DEBUG] Finished reading NetworkServicesMulticastGroupRangeActivation %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading MulticastGroupRangeActivation: %s", err) } @@ -484,6 +510,19 @@ func resourceNetworkServicesMulticastGroupRangeActivationRead(d *schema.Resource } func resourceNetworkServicesMulticastGroupRangeActivationUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceNetworkServicesMulticastGroupRangeActivation().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceNetworkServicesMulticastGroupRangeActivationRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -602,6 +641,13 @@ func resourceNetworkServicesMulticastGroupRangeActivationUpdate(d *schema.Resour } func resourceNetworkServicesMulticastGroupRangeActivationDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy NetworkServicesMulticastGroupRangeActivation without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing MulticastGroupRangeActivation %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/networkservices/resource_network_services_multicast_group_range_activation_generated_meta.yaml b/google-beta/services/networkservices/resource_network_services_multicast_group_range_activation_generated_meta.yaml index 385ecf1bda0..82af36fdbf6 100644 --- a/google-beta/services/networkservices/resource_network_services_multicast_group_range_activation_generated_meta.yaml +++ b/google-beta/services/networkservices/resource_network_services_multicast_group_range_activation_generated_meta.yaml @@ -28,3 +28,5 @@ fields: provider_only: true - api_field: uniqueId - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/networkservices/resource_network_services_multicast_group_range_generated_meta.yaml b/google-beta/services/networkservices/resource_network_services_multicast_group_range_generated_meta.yaml index 19b3c3d9453..142c62df567 100644 --- a/google-beta/services/networkservices/resource_network_services_multicast_group_range_generated_meta.yaml +++ b/google-beta/services/networkservices/resource_network_services_multicast_group_range_generated_meta.yaml @@ -30,3 +30,5 @@ fields: provider_only: true - api_field: uniqueId - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/networkservices/resource_network_services_multicast_producer_association.go b/google-beta/services/networkservices/resource_network_services_multicast_producer_association.go index b785ba3248f..7ba40eba46b 100644 --- a/google-beta/services/networkservices/resource_network_services_multicast_producer_association.go +++ b/google-beta/services/networkservices/resource_network_services_multicast_producer_association.go @@ -116,6 +116,7 @@ func ResourceNetworkServicesMulticastProducerAssociation() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -256,6 +257,18 @@ most recently updated.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -411,6 +424,19 @@ func resourceNetworkServicesMulticastProducerAssociationRead(d *schema.ResourceD log.Printf("[DEBUG] Finished reading NetworkServicesMulticastProducerAssociation %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading MulticastProducerAssociation: %s", err) } @@ -448,6 +474,19 @@ func resourceNetworkServicesMulticastProducerAssociationRead(d *schema.ResourceD } func resourceNetworkServicesMulticastProducerAssociationUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceNetworkServicesMulticastProducerAssociation().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceNetworkServicesMulticastProducerAssociationRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -556,6 +595,13 @@ func resourceNetworkServicesMulticastProducerAssociationUpdate(d *schema.Resourc } func resourceNetworkServicesMulticastProducerAssociationDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy NetworkServicesMulticastProducerAssociation without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing MulticastProducerAssociation %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/networkservices/resource_network_services_multicast_producer_association_generated_meta.yaml b/google-beta/services/networkservices/resource_network_services_multicast_producer_association_generated_meta.yaml index 1e5c170019d..1a40b496ae1 100644 --- a/google-beta/services/networkservices/resource_network_services_multicast_producer_association_generated_meta.yaml +++ b/google-beta/services/networkservices/resource_network_services_multicast_producer_association_generated_meta.yaml @@ -25,3 +25,5 @@ fields: provider_only: true - api_field: uniqueId - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/networkservices/resource_network_services_service_binding.go b/google-beta/services/networkservices/resource_network_services_service_binding.go index 1a21104b2e2..d7eb66b04c9 100644 --- a/google-beta/services/networkservices/resource_network_services_service_binding.go +++ b/google-beta/services/networkservices/resource_network_services_service_binding.go @@ -125,6 +125,7 @@ func ResourceNetworkServicesServiceBinding() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), DeprecationMessage: "Cloud Service Mesh's integration with Service Directory is going to be deprecated. [Learn more](https://docs.cloud.google.com/service-mesh/docs/service-routing/service-directory-integration-setup). Creating new service binding resources will be disabled.", @@ -207,6 +208,18 @@ Please refer to the field 'effective_labels' for all of the labels present on th Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -351,6 +364,19 @@ func resourceNetworkServicesServiceBindingRead(d *schema.ResourceData, meta inte log.Printf("[DEBUG] Finished reading NetworkServicesServiceBinding %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading ServiceBinding: %s", err) } @@ -382,11 +408,18 @@ func resourceNetworkServicesServiceBindingRead(d *schema.ResourceData, meta inte } func resourceNetworkServicesServiceBindingUpdate(d *schema.ResourceData, meta interface{}) error { - // Only the root field "labels", "terraform_labels", and virtual fields are mutable + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable return resourceNetworkServicesServiceBindingRead(d, meta) } func resourceNetworkServicesServiceBindingDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy NetworkServicesServiceBinding without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing ServiceBinding %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/networkservices/resource_network_services_service_binding_generated_meta.yaml b/google-beta/services/networkservices/resource_network_services_service_binding_generated_meta.yaml index 526862f9013..7224611121a 100644 --- a/google-beta/services/networkservices/resource_network_services_service_binding_generated_meta.yaml +++ b/google-beta/services/networkservices/resource_network_services_service_binding_generated_meta.yaml @@ -18,3 +18,5 @@ fields: - field: terraform_labels provider_only: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/networkservices/resource_network_services_service_lb_policies.go b/google-beta/services/networkservices/resource_network_services_service_lb_policies.go index f3df0e9cb2a..200a5e1a8a4 100644 --- a/google-beta/services/networkservices/resource_network_services_service_lb_policies.go +++ b/google-beta/services/networkservices/resource_network_services_service_lb_policies.go @@ -116,6 +116,7 @@ func ResourceNetworkServicesServiceLbPolicies() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -254,6 +255,18 @@ Please refer to the field 'effective_labels' for all of the labels present on th Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -421,6 +434,19 @@ func resourceNetworkServicesServiceLbPoliciesRead(d *schema.ResourceData, meta i log.Printf("[DEBUG] Finished reading NetworkServicesServiceLbPolicies %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading ServiceLbPolicies: %s", err) } @@ -458,6 +484,19 @@ func resourceNetworkServicesServiceLbPoliciesRead(d *schema.ResourceData, meta i } func resourceNetworkServicesServiceLbPoliciesUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceNetworkServicesServiceLbPolicies().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceNetworkServicesServiceLbPoliciesRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -606,6 +645,13 @@ func resourceNetworkServicesServiceLbPoliciesUpdate(d *schema.ResourceData, meta } func resourceNetworkServicesServiceLbPoliciesDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy NetworkServicesServiceLbPolicies without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing ServiceLbPolicies %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/networkservices/resource_network_services_service_lb_policies_generated_meta.yaml b/google-beta/services/networkservices/resource_network_services_service_lb_policies_generated_meta.yaml index 04846dc3744..e0c6adab7b4 100644 --- a/google-beta/services/networkservices/resource_network_services_service_lb_policies_generated_meta.yaml +++ b/google-beta/services/networkservices/resource_network_services_service_lb_policies_generated_meta.yaml @@ -24,3 +24,5 @@ fields: - field: terraform_labels provider_only: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/networkservices/resource_network_services_tcp_route.go b/google-beta/services/networkservices/resource_network_services_tcp_route.go index 65e4b786f51..d974d05fa00 100644 --- a/google-beta/services/networkservices/resource_network_services_tcp_route.go +++ b/google-beta/services/networkservices/resource_network_services_tcp_route.go @@ -116,6 +116,7 @@ func ResourceNetworkServicesTcpRoute() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -287,6 +288,18 @@ The attached Mesh should be of a type SIDECAR`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -443,6 +456,19 @@ func resourceNetworkServicesTcpRouteRead(d *schema.ResourceData, meta interface{ log.Printf("[DEBUG] Finished reading NetworkServicesTcpRoute %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading TcpRoute: %s", err) } @@ -474,6 +500,19 @@ func resourceNetworkServicesTcpRouteRead(d *schema.ResourceData, meta interface{ } func resourceNetworkServicesTcpRouteUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceNetworkServicesTcpRoute().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceNetworkServicesTcpRouteRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -607,6 +646,13 @@ func resourceNetworkServicesTcpRouteUpdate(d *schema.ResourceData, meta interfac } func resourceNetworkServicesTcpRouteDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy NetworkServicesTcpRoute without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing TcpRoute %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/networkservices/resource_network_services_tcp_route_generated_meta.yaml b/google-beta/services/networkservices/resource_network_services_tcp_route_generated_meta.yaml index 4209c638b29..d42e655ad87 100644 --- a/google-beta/services/networkservices/resource_network_services_tcp_route_generated_meta.yaml +++ b/google-beta/services/networkservices/resource_network_services_tcp_route_generated_meta.yaml @@ -26,3 +26,5 @@ fields: - field: terraform_labels provider_only: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/networkservices/resource_network_services_tls_route.go b/google-beta/services/networkservices/resource_network_services_tls_route.go index 01013930019..bb341d394bf 100644 --- a/google-beta/services/networkservices/resource_network_services_tls_route.go +++ b/google-beta/services/networkservices/resource_network_services_tls_route.go @@ -124,6 +124,7 @@ func ResourceNetworkServicesTlsRoute() *schema.Resource { }, CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -281,6 +282,18 @@ Each target proxy reference should match the pattern: projects/*/locations/globa Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -442,6 +455,19 @@ func resourceNetworkServicesTlsRouteRead(d *schema.ResourceData, meta interface{ log.Printf("[DEBUG] Finished reading NetworkServicesTlsRoute %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading TlsRoute: %s", err) } @@ -479,6 +505,19 @@ func resourceNetworkServicesTlsRouteRead(d *schema.ResourceData, meta interface{ } func resourceNetworkServicesTlsRouteUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceNetworkServicesTlsRoute().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceNetworkServicesTlsRouteRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -617,6 +656,13 @@ func resourceNetworkServicesTlsRouteUpdate(d *schema.ResourceData, meta interfac } func resourceNetworkServicesTlsRouteDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy NetworkServicesTlsRoute without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing TlsRoute %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/networkservices/resource_network_services_tls_route_generated_meta.yaml b/google-beta/services/networkservices/resource_network_services_tls_route_generated_meta.yaml index d145c2f4d27..ea4fff32030 100644 --- a/google-beta/services/networkservices/resource_network_services_tls_route_generated_meta.yaml +++ b/google-beta/services/networkservices/resource_network_services_tls_route_generated_meta.yaml @@ -22,3 +22,5 @@ fields: - api_field: selfLink - api_field: targetProxies - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/networkservices/resource_network_services_wasm_plugin.go b/google-beta/services/networkservices/resource_network_services_wasm_plugin.go index bebe49ab5c1..e22ded7f7ba 100644 --- a/google-beta/services/networkservices/resource_network_services_wasm_plugin.go +++ b/google-beta/services/networkservices/resource_network_services_wasm_plugin.go @@ -116,6 +116,7 @@ func ResourceNetworkServicesWasmPlugin() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -322,6 +323,18 @@ This field can be specified only if logging is enabled for this plugin.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -483,6 +496,19 @@ func resourceNetworkServicesWasmPluginRead(d *schema.ResourceData, meta interfac log.Printf("[DEBUG] Finished reading NetworkServicesWasmPlugin %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading WasmPlugin: %s", err) } @@ -520,6 +546,19 @@ func resourceNetworkServicesWasmPluginRead(d *schema.ResourceData, meta interfac } func resourceNetworkServicesWasmPluginUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceNetworkServicesWasmPlugin().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceNetworkServicesWasmPluginRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -658,6 +697,13 @@ func resourceNetworkServicesWasmPluginUpdate(d *schema.ResourceData, meta interf } func resourceNetworkServicesWasmPluginDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy NetworkServicesWasmPlugin without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing WasmPlugin %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/networkservices/resource_network_services_wasm_plugin_generated_meta.yaml b/google-beta/services/networkservices/resource_network_services_wasm_plugin_generated_meta.yaml index fd4ef29f50c..6daa0c9cdab 100644 --- a/google-beta/services/networkservices/resource_network_services_wasm_plugin_generated_meta.yaml +++ b/google-beta/services/networkservices/resource_network_services_wasm_plugin_generated_meta.yaml @@ -44,3 +44,5 @@ fields: field: versions.plugin_config_uri - api_field: versions.value.updateTime field: versions.update_time + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/notebooks/resource_notebooks_environment.go b/google-beta/services/notebooks/resource_notebooks_environment.go index 5d7eb9f52d9..471e916666d 100644 --- a/google-beta/services/notebooks/resource_notebooks_environment.go +++ b/google-beta/services/notebooks/resource_notebooks_environment.go @@ -115,6 +115,7 @@ func ResourceNotebooksEnvironment() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), DeprecationMessage: "`google_notebooks_environment` is deprecated and will be removed in a future major release. Use `google_workbench_instance` instead.", @@ -232,6 +233,18 @@ Format: projects/{project_id}`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -393,6 +406,19 @@ func resourceNotebooksEnvironmentRead(d *schema.ResourceData, meta interface{}) log.Printf("[DEBUG] Finished reading NotebooksEnvironment %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Environment: %s", err) } @@ -430,6 +456,19 @@ func resourceNotebooksEnvironmentRead(d *schema.ResourceData, meta interface{}) } func resourceNotebooksEnvironmentUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceNotebooksEnvironment().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceNotebooksEnvironmentRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -538,6 +577,13 @@ func resourceNotebooksEnvironmentUpdate(d *schema.ResourceData, meta interface{} } func resourceNotebooksEnvironmentDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy NotebooksEnvironment without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Environment %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/notebooks/resource_notebooks_environment_generated_meta.yaml b/google-beta/services/notebooks/resource_notebooks_environment_generated_meta.yaml index 844e6867954..0bd090ff044 100644 --- a/google-beta/services/notebooks/resource_notebooks_environment_generated_meta.yaml +++ b/google-beta/services/notebooks/resource_notebooks_environment_generated_meta.yaml @@ -20,3 +20,5 @@ fields: - api_field: vmImage.imageFamily - api_field: vmImage.imageName - api_field: vmImage.project + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/notebooks/resource_notebooks_instance.go b/google-beta/services/notebooks/resource_notebooks_instance.go index 477759b57c1..1f8033b1594 100644 --- a/google-beta/services/notebooks/resource_notebooks_instance.go +++ b/google-beta/services/notebooks/resource_notebooks_instance.go @@ -223,6 +223,7 @@ func ResourceNotebooksInstance() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), DeprecationMessage: "`google_notebooks_instance` is deprecated and will be removed in a future major release. Use `google_workbench_instance` instead.", @@ -657,6 +658,18 @@ the population of this value.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -970,6 +983,18 @@ func resourceNotebooksInstanceRead(d *schema.ResourceData, meta interface{}) err return fmt.Errorf("Error setting desired_state: %s", err) } } + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Instance: %s", err) } @@ -1007,6 +1032,19 @@ func resourceNotebooksInstanceRead(d *schema.ResourceData, meta interface{}) err } func resourceNotebooksInstanceUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceNotebooksInstance().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceNotebooksInstanceRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1171,6 +1209,13 @@ func resourceNotebooksInstanceUpdate(d *schema.ResourceData, meta interface{}) e } func resourceNotebooksInstanceDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy NotebooksInstance without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Instance %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/notebooks/resource_notebooks_instance_generated_meta.yaml b/google-beta/services/notebooks/resource_notebooks_instance_generated_meta.yaml index 37c12e75714..1badff78ccc 100644 --- a/google-beta/services/notebooks/resource_notebooks_instance_generated_meta.yaml +++ b/google-beta/services/notebooks/resource_notebooks_instance_generated_meta.yaml @@ -56,3 +56,5 @@ fields: - api_field: vmImage.imageFamily - api_field: vmImage.imageName - api_field: vmImage.project + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/notebooks/resource_notebooks_runtime.go b/google-beta/services/notebooks/resource_notebooks_runtime.go index 1b7e18e1940..65be819b29e 100644 --- a/google-beta/services/notebooks/resource_notebooks_runtime.go +++ b/google-beta/services/notebooks/resource_notebooks_runtime.go @@ -138,6 +138,7 @@ func ResourceNotebooksRuntime() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), DeprecationMessage: "`google_notebooks_runtime` is deprecated and will be removed in a future major release. Use `google_workbench_instance` instead.", @@ -747,6 +748,18 @@ sessions stats.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -902,6 +915,19 @@ func resourceNotebooksRuntimeRead(d *schema.ResourceData, meta interface{}) erro log.Printf("[DEBUG] Finished reading NotebooksRuntime %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Runtime: %s", err) } @@ -939,6 +965,19 @@ func resourceNotebooksRuntimeRead(d *schema.ResourceData, meta interface{}) erro } func resourceNotebooksRuntimeUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceNotebooksRuntime().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceNotebooksRuntimeRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1136,6 +1175,13 @@ func resourceNotebooksRuntimeUpdate(d *schema.ResourceData, meta interface{}) er } func resourceNotebooksRuntimeDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy NotebooksRuntime without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Runtime %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/notebooks/resource_notebooks_runtime_generated_meta.yaml b/google-beta/services/notebooks/resource_notebooks_runtime_generated_meta.yaml index 67420c9dc07..9627e7c8c24 100644 --- a/google-beta/services/notebooks/resource_notebooks_runtime_generated_meta.yaml +++ b/google-beta/services/notebooks/resource_notebooks_runtime_generated_meta.yaml @@ -70,3 +70,5 @@ fields: - api_field: virtualMachine.virtualMachineConfig.subnet - api_field: virtualMachine.virtualMachineConfig.tags - api_field: virtualMachine.virtualMachineConfig.zone + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/observability/resource_observability_project_settings.go b/google-beta/services/observability/resource_observability_project_settings.go index f7aae4fffa5..f239c429b55 100644 --- a/google-beta/services/observability/resource_observability_project_settings.go +++ b/google-beta/services/observability/resource_observability_project_settings.go @@ -352,6 +352,7 @@ func resourceObservabilityProjectSettingsRead(d *schema.ResourceData, meta inter } func resourceObservabilityProjectSettingsUpdate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/observability/resource_observability_trace_scope.go b/google-beta/services/observability/resource_observability_trace_scope.go index 5c32c3e7682..47d568d1262 100644 --- a/google-beta/services/observability/resource_observability_trace_scope.go +++ b/google-beta/services/observability/resource_observability_trace_scope.go @@ -115,6 +115,7 @@ func ResourceObservabilityTraceScope() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -197,6 +198,18 @@ projects/my-project/locations/global/traceScopes/my-trace-scope`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -330,6 +343,19 @@ func resourceObservabilityTraceScopeRead(d *schema.ResourceData, meta interface{ log.Printf("[DEBUG] Finished reading ObservabilityTraceScope %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading TraceScope: %s", err) } @@ -367,6 +393,19 @@ func resourceObservabilityTraceScopeRead(d *schema.ResourceData, meta interface{ } func resourceObservabilityTraceScopeUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceObservabilityTraceScope().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceObservabilityTraceScopeRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -468,6 +507,13 @@ func resourceObservabilityTraceScopeUpdate(d *schema.ResourceData, meta interfac } func resourceObservabilityTraceScopeDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ObservabilityTraceScope without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing TraceScope %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/observability/resource_observability_trace_scope_generated_meta.yaml b/google-beta/services/observability/resource_observability_trace_scope_generated_meta.yaml index b791347a73a..33ee546d348 100644 --- a/google-beta/services/observability/resource_observability_trace_scope_generated_meta.yaml +++ b/google-beta/services/observability/resource_observability_trace_scope_generated_meta.yaml @@ -16,3 +16,5 @@ fields: - field: trace_scope_id provider_only: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/oracledatabase/resource_oracle_database_autonomous_database.go b/google-beta/services/oracledatabase/resource_oracle_database_autonomous_database.go index 5b1d6e8f532..bc89a9f56b0 100644 --- a/google-beta/services/oracledatabase/resource_oracle_database_autonomous_database.go +++ b/google-beta/services/oracledatabase/resource_oracle_database_autonomous_database.go @@ -116,6 +116,7 @@ func ResourceOracleDatabaseAutonomousDatabase() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -1110,6 +1111,18 @@ projects/{project}/locations/{region}/autonomousDatabases/{autonomous_database}` Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -1307,6 +1320,18 @@ func resourceOracleDatabaseAutonomousDatabaseRead(d *schema.ResourceData, meta i return fmt.Errorf("Error setting deletion_protection: %s", err) } } + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading AutonomousDatabase: %s", err) } @@ -1344,11 +1369,18 @@ func resourceOracleDatabaseAutonomousDatabaseRead(d *schema.ResourceData, meta i } func resourceOracleDatabaseAutonomousDatabaseUpdate(d *schema.ResourceData, meta interface{}) error { - // Only the root field "labels", "terraform_labels", and virtual fields are mutable + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable return resourceOracleDatabaseAutonomousDatabaseRead(d, meta) } func resourceOracleDatabaseAutonomousDatabaseDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy OracleDatabaseAutonomousDatabase without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing AutonomousDatabase %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/oracledatabase/resource_oracle_database_autonomous_database_generated_meta.yaml b/google-beta/services/oracledatabase/resource_oracle_database_autonomous_database_generated_meta.yaml index 8dd59d60e4f..a10b47fa76e 100644 --- a/google-beta/services/oracledatabase/resource_oracle_database_autonomous_database_generated_meta.yaml +++ b/google-beta/services/oracledatabase/resource_oracle_database_autonomous_database_generated_meta.yaml @@ -125,3 +125,5 @@ fields: - api_field: sourceConfig.autonomousDatabase - field: terraform_labels provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/oracledatabase/resource_oracle_database_cloud_exadata_infrastructure.go b/google-beta/services/oracledatabase/resource_oracle_database_cloud_exadata_infrastructure.go index e5dee6a3ae9..1fa2e6e5b42 100644 --- a/google-beta/services/oracledatabase/resource_oracle_database_cloud_exadata_infrastructure.go +++ b/google-beta/services/oracledatabase/resource_oracle_database_cloud_exadata_infrastructure.go @@ -116,6 +116,7 @@ func ResourceOracleDatabaseCloudExadataInfrastructure() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -509,6 +510,18 @@ projects/{project}/locations/{region}/cloudExadataInfrastructures/{cloud_exadata Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -670,6 +683,18 @@ func resourceOracleDatabaseCloudExadataInfrastructureRead(d *schema.ResourceData return fmt.Errorf("Error setting deletion_protection: %s", err) } } + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading CloudExadataInfrastructure: %s", err) } @@ -707,11 +732,18 @@ func resourceOracleDatabaseCloudExadataInfrastructureRead(d *schema.ResourceData } func resourceOracleDatabaseCloudExadataInfrastructureUpdate(d *schema.ResourceData, meta interface{}) error { - // Only the root field "labels", "terraform_labels", and virtual fields are mutable + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable return resourceOracleDatabaseCloudExadataInfrastructureRead(d, meta) } func resourceOracleDatabaseCloudExadataInfrastructureDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy OracleDatabaseCloudExadataInfrastructure without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing CloudExadataInfrastructure %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/oracledatabase/resource_oracle_database_cloud_exadata_infrastructure_generated_meta.yaml b/google-beta/services/oracledatabase/resource_oracle_database_cloud_exadata_infrastructure_generated_meta.yaml index 104d0bac63a..c42043244c8 100644 --- a/google-beta/services/oracledatabase/resource_oracle_database_cloud_exadata_infrastructure_generated_meta.yaml +++ b/google-beta/services/oracledatabase/resource_oracle_database_cloud_exadata_infrastructure_generated_meta.yaml @@ -59,3 +59,5 @@ fields: - api_field: properties.totalStorageSizeGb - field: terraform_labels provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/oracledatabase/resource_oracle_database_cloud_vm_cluster.go b/google-beta/services/oracledatabase/resource_oracle_database_cloud_vm_cluster.go index 28df0b4c9f3..9930c78ca1b 100644 --- a/google-beta/services/oracledatabase/resource_oracle_database_cloud_vm_cluster.go +++ b/google-beta/services/oracledatabase/resource_oracle_database_cloud_vm_cluster.go @@ -116,6 +116,7 @@ func ResourceOracleDatabaseCloudVmCluster() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -542,6 +543,18 @@ projects/{project}/locations/{region}/cloudVmClusters/{cloud_vm_cluster}`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -739,6 +752,18 @@ func resourceOracleDatabaseCloudVmClusterRead(d *schema.ResourceData, meta inter return fmt.Errorf("Error setting deletion_protection: %s", err) } } + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading CloudVmCluster: %s", err) } @@ -776,11 +801,18 @@ func resourceOracleDatabaseCloudVmClusterRead(d *schema.ResourceData, meta inter } func resourceOracleDatabaseCloudVmClusterUpdate(d *schema.ResourceData, meta interface{}) error { - // Only the root field "labels", "terraform_labels", and virtual fields are mutable + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable return resourceOracleDatabaseCloudVmClusterRead(d, meta) } func resourceOracleDatabaseCloudVmClusterDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy OracleDatabaseCloudVmCluster without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing CloudVmCluster %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/oracledatabase/resource_oracle_database_cloud_vm_cluster_generated_meta.yaml b/google-beta/services/oracledatabase/resource_oracle_database_cloud_vm_cluster_generated_meta.yaml index 0aa86de41e9..72d177a577f 100644 --- a/google-beta/services/oracledatabase/resource_oracle_database_cloud_vm_cluster_generated_meta.yaml +++ b/google-beta/services/oracledatabase/resource_oracle_database_cloud_vm_cluster_generated_meta.yaml @@ -65,3 +65,5 @@ fields: - api_field: properties.timeZone.version - field: terraform_labels provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/oracledatabase/resource_oracle_database_db_system.go b/google-beta/services/oracledatabase/resource_oracle_database_db_system.go index 765c2e74204..4958584e727 100644 --- a/google-beta/services/oracledatabase/resource_oracle_database_db_system.go +++ b/google-beta/services/oracledatabase/resource_oracle_database_db_system.go @@ -116,6 +116,7 @@ func ResourceOracleDatabaseDbSystem() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -779,6 +780,18 @@ projects/{project}/locations/{region}/dbSystems/{db_system}`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -952,6 +965,18 @@ func resourceOracleDatabaseDbSystemRead(d *schema.ResourceData, meta interface{} return fmt.Errorf("Error setting deletion_protection: %s", err) } } + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading DbSystem: %s", err) } @@ -989,11 +1014,18 @@ func resourceOracleDatabaseDbSystemRead(d *schema.ResourceData, meta interface{} } func resourceOracleDatabaseDbSystemUpdate(d *schema.ResourceData, meta interface{}) error { - // Only the root field "labels", "terraform_labels", and virtual fields are mutable + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable return resourceOracleDatabaseDbSystemRead(d, meta) } func resourceOracleDatabaseDbSystemDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy OracleDatabaseDbSystem without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing DbSystem %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/oracledatabase/resource_oracle_database_db_system_generated_meta.yaml b/google-beta/services/oracledatabase/resource_oracle_database_db_system_generated_meta.yaml index baf63304be2..79ac3c51cb7 100644 --- a/google-beta/services/oracledatabase/resource_oracle_database_db_system_generated_meta.yaml +++ b/google-beta/services/oracledatabase/resource_oracle_database_db_system_generated_meta.yaml @@ -77,3 +77,5 @@ fields: - api_field: properties.timeZone.id - field: terraform_labels provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/oracledatabase/resource_oracle_database_exadb_vm_cluster.go b/google-beta/services/oracledatabase/resource_oracle_database_exadb_vm_cluster.go index c815721e9c6..66fdab7f497 100644 --- a/google-beta/services/oracledatabase/resource_oracle_database_exadb_vm_cluster.go +++ b/google-beta/services/oracledatabase/resource_oracle_database_exadb_vm_cluster.go @@ -116,6 +116,7 @@ func ResourceOracleDatabaseExadbVmCluster() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -451,6 +452,18 @@ projects/{project}/locations/{region}/exadbVmClusters/{exadb_vm_cluster}`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -624,6 +637,18 @@ func resourceOracleDatabaseExadbVmClusterRead(d *schema.ResourceData, meta inter return fmt.Errorf("Error setting deletion_protection: %s", err) } } + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading ExadbVmCluster: %s", err) } @@ -661,6 +686,19 @@ func resourceOracleDatabaseExadbVmClusterRead(d *schema.ResourceData, meta inter } func resourceOracleDatabaseExadbVmClusterUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceOracleDatabaseExadbVmCluster().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceOracleDatabaseExadbVmClusterRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -769,6 +807,13 @@ func resourceOracleDatabaseExadbVmClusterUpdate(d *schema.ResourceData, meta int } func resourceOracleDatabaseExadbVmClusterDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy OracleDatabaseExadbVmCluster without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing ExadbVmCluster %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/oracledatabase/resource_oracle_database_exadb_vm_cluster_generated_meta.yaml b/google-beta/services/oracledatabase/resource_oracle_database_exadb_vm_cluster_generated_meta.yaml index 8427f0974ea..c76eb361bc9 100644 --- a/google-beta/services/oracledatabase/resource_oracle_database_exadb_vm_cluster_generated_meta.yaml +++ b/google-beta/services/oracledatabase/resource_oracle_database_exadb_vm_cluster_generated_meta.yaml @@ -49,3 +49,5 @@ fields: - api_field: properties.vmFileSystemStorage.sizeInGbsPerNode - field: terraform_labels provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/oracledatabase/resource_oracle_database_exascale_db_storage_vault.go b/google-beta/services/oracledatabase/resource_oracle_database_exascale_db_storage_vault.go index bde3211b7de..3f2bcdc7fdf 100644 --- a/google-beta/services/oracledatabase/resource_oracle_database_exascale_db_storage_vault.go +++ b/google-beta/services/oracledatabase/resource_oracle_database_exascale_db_storage_vault.go @@ -116,6 +116,7 @@ func ResourceOracleDatabaseExascaleDbStorageVault() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -351,6 +352,18 @@ projects/{project}/locations/{location}/exascaleDbStorageVaults/{exascale_db_sto Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -512,6 +525,18 @@ func resourceOracleDatabaseExascaleDbStorageVaultRead(d *schema.ResourceData, me return fmt.Errorf("Error setting deletion_protection: %s", err) } } + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading ExascaleDbStorageVault: %s", err) } @@ -549,11 +574,18 @@ func resourceOracleDatabaseExascaleDbStorageVaultRead(d *schema.ResourceData, me } func resourceOracleDatabaseExascaleDbStorageVaultUpdate(d *schema.ResourceData, meta interface{}) error { - // Only the root field "labels", "terraform_labels", and virtual fields are mutable + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable return resourceOracleDatabaseExascaleDbStorageVaultRead(d, meta) } func resourceOracleDatabaseExascaleDbStorageVaultDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy OracleDatabaseExascaleDbStorageVault without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing ExascaleDbStorageVault %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/oracledatabase/resource_oracle_database_exascale_db_storage_vault_generated_meta.yaml b/google-beta/services/oracledatabase/resource_oracle_database_exascale_db_storage_vault_generated_meta.yaml index 1d3801e8c13..4baee3cd5fe 100644 --- a/google-beta/services/oracledatabase/resource_oracle_database_exascale_db_storage_vault_generated_meta.yaml +++ b/google-beta/services/oracledatabase/resource_oracle_database_exascale_db_storage_vault_generated_meta.yaml @@ -36,3 +36,5 @@ fields: - api_field: properties.vmClusterIds - field: terraform_labels provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/oracledatabase/resource_oracle_database_odb_network.go b/google-beta/services/oracledatabase/resource_oracle_database_odb_network.go index ffe22fbea37..8be9e7127f7 100644 --- a/google-beta/services/oracledatabase/resource_oracle_database_odb_network.go +++ b/google-beta/services/oracledatabase/resource_oracle_database_odb_network.go @@ -116,6 +116,7 @@ func ResourceOracleDatabaseOdbNetwork() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -234,6 +235,18 @@ FAILED`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -389,6 +402,18 @@ func resourceOracleDatabaseOdbNetworkRead(d *schema.ResourceData, meta interface return fmt.Errorf("Error setting deletion_protection: %s", err) } } + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading OdbNetwork: %s", err) } @@ -426,11 +451,18 @@ func resourceOracleDatabaseOdbNetworkRead(d *schema.ResourceData, meta interface } func resourceOracleDatabaseOdbNetworkUpdate(d *schema.ResourceData, meta interface{}) error { - // Only the root field "labels", "terraform_labels", and virtual fields are mutable + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable return resourceOracleDatabaseOdbNetworkRead(d, meta) } func resourceOracleDatabaseOdbNetworkDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy OracleDatabaseOdbNetwork without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing OdbNetwork %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/oracledatabase/resource_oracle_database_odb_network_generated_meta.yaml b/google-beta/services/oracledatabase/resource_oracle_database_odb_network_generated_meta.yaml index 01e151fcba6..4466a5cd68f 100644 --- a/google-beta/services/oracledatabase/resource_oracle_database_odb_network_generated_meta.yaml +++ b/google-beta/services/oracledatabase/resource_oracle_database_odb_network_generated_meta.yaml @@ -25,3 +25,5 @@ fields: - api_field: state - field: terraform_labels provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/oracledatabase/resource_oracle_database_odb_subnet.go b/google-beta/services/oracledatabase/resource_oracle_database_odb_subnet.go index cfcd9012230..a3324187249 100644 --- a/google-beta/services/oracledatabase/resource_oracle_database_odb_subnet.go +++ b/google-beta/services/oracledatabase/resource_oracle_database_odb_subnet.go @@ -116,6 +116,7 @@ func ResourceOracleDatabaseOdbSubnet() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -238,6 +239,18 @@ FAILED`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -398,6 +411,18 @@ func resourceOracleDatabaseOdbSubnetRead(d *schema.ResourceData, meta interface{ return fmt.Errorf("Error setting deletion_protection: %s", err) } } + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading OdbSubnet: %s", err) } @@ -441,11 +466,18 @@ func resourceOracleDatabaseOdbSubnetRead(d *schema.ResourceData, meta interface{ } func resourceOracleDatabaseOdbSubnetUpdate(d *schema.ResourceData, meta interface{}) error { - // Only the root field "labels", "terraform_labels", and virtual fields are mutable + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable return resourceOracleDatabaseOdbSubnetRead(d, meta) } func resourceOracleDatabaseOdbSubnetDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy OracleDatabaseOdbSubnet without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing OdbSubnet %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/oracledatabase/resource_oracle_database_odb_subnet_generated_meta.yaml b/google-beta/services/oracledatabase/resource_oracle_database_odb_subnet_generated_meta.yaml index 0e8157b623f..13f039742ae 100644 --- a/google-beta/services/oracledatabase/resource_oracle_database_odb_subnet_generated_meta.yaml +++ b/google-beta/services/oracledatabase/resource_oracle_database_odb_subnet_generated_meta.yaml @@ -26,3 +26,5 @@ fields: - api_field: state - field: terraform_labels provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/orgpolicy/resource_org_policy_custom_constraint.go b/google-beta/services/orgpolicy/resource_org_policy_custom_constraint.go index 0be6090271f..afbcda63136 100644 --- a/google-beta/services/orgpolicy/resource_org_policy_custom_constraint.go +++ b/google-beta/services/orgpolicy/resource_org_policy_custom_constraint.go @@ -190,6 +190,19 @@ func ResourceOrgPolicyCustomConstraint() *schema.Resource { Computed: true, Description: `Output only. The timestamp representing when the constraint was last updated.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -336,6 +349,20 @@ func resourceOrgPolicyCustomConstraintRead(d *schema.ResourceData, meta interfac log.Printf("[DEBUG] Finished reading OrgPolicyCustomConstraint %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceOrgPolicyCustomConstraintFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -363,6 +390,19 @@ func resourceOrgPolicyCustomConstraintRead(d *schema.ResourceData, meta interfac } func resourceOrgPolicyCustomConstraintUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceOrgPolicyCustomConstraint().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceOrgPolicyCustomConstraintRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -457,6 +497,13 @@ func resourceOrgPolicyCustomConstraintUpdate(d *schema.ResourceData, meta interf } func resourceOrgPolicyCustomConstraintDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy OrgPolicyCustomConstraint without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing CustomConstraint %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/orgpolicy/resource_org_policy_custom_constraint_generated_meta.yaml b/google-beta/services/orgpolicy/resource_org_policy_custom_constraint_generated_meta.yaml index 8f405a00921..7017c9aba7c 100644 --- a/google-beta/services/orgpolicy/resource_org_policy_custom_constraint_generated_meta.yaml +++ b/google-beta/services/orgpolicy/resource_org_policy_custom_constraint_generated_meta.yaml @@ -17,3 +17,5 @@ fields: provider_only: true - api_field: resourceTypes - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/orgpolicy/resource_org_policy_policy.go b/google-beta/services/orgpolicy/resource_org_policy_policy.go index 249d7570018..b17091f1da0 100644 --- a/google-beta/services/orgpolicy/resource_org_policy_policy.go +++ b/google-beta/services/orgpolicy/resource_org_policy_policy.go @@ -453,6 +453,19 @@ func ResourceOrgPolicyPolicy() *schema.Resource { Computed: true, Description: `Optional. An opaque tag indicating the current state of the policy, used for concurrency control. This 'etag' is computed by the server based on the value of other fields, and may be sent on update and delete requests to ensure the client has an up-to-date value before proceeding.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -589,6 +602,20 @@ func resourceOrgPolicyPolicyRead(d *schema.ResourceData, meta interface{}) error log.Printf("[DEBUG] Finished reading OrgPolicyPolicy %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceOrgPolicyPolicyFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -616,6 +643,19 @@ func resourceOrgPolicyPolicyRead(d *schema.ResourceData, meta interface{}) error } func resourceOrgPolicyPolicyUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceOrgPolicyPolicy().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceOrgPolicyPolicyRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -709,6 +749,13 @@ func resourceOrgPolicyPolicyUpdate(d *schema.ResourceData, meta interface{}) err } func resourceOrgPolicyPolicyDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy OrgPolicyPolicy without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Policy %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/orgpolicy/resource_org_policy_policy_generated_meta.yaml b/google-beta/services/orgpolicy/resource_org_policy_policy_generated_meta.yaml index 011986c6f0c..5eaec8d7fcf 100644 --- a/google-beta/services/orgpolicy/resource_org_policy_policy_generated_meta.yaml +++ b/google-beta/services/orgpolicy/resource_org_policy_policy_generated_meta.yaml @@ -45,3 +45,5 @@ fields: - api_field: spec.rules.values.allowedValues - api_field: spec.rules.values.deniedValues - api_field: spec.updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/osconfig/resource_os_config_guest_policies.go b/google-beta/services/osconfig/resource_os_config_guest_policies.go index d3ff6d84f40..d6de14d6260 100644 --- a/google-beta/services/osconfig/resource_os_config_guest_policies.go +++ b/google-beta/services/osconfig/resource_os_config_guest_policies.go @@ -115,6 +115,7 @@ func ResourceOSConfigGuestPolicies() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -964,6 +965,18 @@ Example: "2014-10-02T15:01:23.045123456Z".`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -1116,6 +1129,19 @@ func resourceOSConfigGuestPoliciesRead(d *schema.ResourceData, meta interface{}) log.Printf("[DEBUG] Finished reading OSConfigGuestPolicies %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading GuestPolicies: %s", err) } @@ -1147,6 +1173,19 @@ func resourceOSConfigGuestPoliciesRead(d *schema.ResourceData, meta interface{}) } func resourceOSConfigGuestPoliciesUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceOSConfigGuestPolicies().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceOSConfigGuestPoliciesRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1248,6 +1287,13 @@ func resourceOSConfigGuestPoliciesUpdate(d *schema.ResourceData, meta interface{ } func resourceOSConfigGuestPoliciesDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy OSConfigGuestPolicies without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing GuestPolicies %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/osconfig/resource_os_config_guest_policies_generated_meta.yaml b/google-beta/services/osconfig/resource_os_config_guest_policies_generated_meta.yaml index 345f8eca830..3a337097266 100644 --- a/google-beta/services/osconfig/resource_os_config_guest_policies_generated_meta.yaml +++ b/google-beta/services/osconfig/resource_os_config_guest_policies_generated_meta.yaml @@ -91,3 +91,5 @@ fields: - api_field: recipes.updateSteps.scriptRun.script - api_field: recipes.version - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/osconfig/resource_os_config_os_policy_assignment.go b/google-beta/services/osconfig/resource_os_config_os_policy_assignment.go index 1e3056a29fd..e5a95dccc9c 100644 --- a/google-beta/services/osconfig/resource_os_config_os_policy_assignment.go +++ b/google-beta/services/osconfig/resource_os_config_os_policy_assignment.go @@ -50,6 +50,7 @@ func ResourceOSConfigOSPolicyAssignment() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Schema: map[string]*schema.Schema{ @@ -1080,6 +1081,9 @@ For a given OS policy assignment, there is only one revision with a value of 'tr DiffSuppressFunc: tpgresource.CompareSelfLinkOrResourceName, Description: "The project for the resource", }, + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end }, UseJSONNumber: true, } @@ -1288,10 +1292,19 @@ func resourceOSConfigOSPolicyAssignmentRead(d *schema.ResourceData, meta interfa return fmt.Errorf("Error reading OSPolicyAssignment: %s", err) } + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + return nil } func resourceOSConfigOSPolicyAssignmentUpdate(d *schema.ResourceData, meta interface{}) error { + + if tpgresource.DeletionPolicyPreUpdate(d, ResourceOSConfigOSPolicyAssignment) { + return ResourceOSConfigOSPolicyAssignment().Read(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1402,6 +1415,13 @@ func resourceOSConfigOSPolicyAssignmentUpdate(d *schema.ResourceData, meta inter } func resourceOSConfigOSPolicyAssignmentDelete(d *schema.ResourceData, meta interface{}) error { + + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { + return nil + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/osconfig/resource_os_config_os_policy_assignment_meta.yaml b/google-beta/services/osconfig/resource_os_config_os_policy_assignment_meta.yaml index ed7fd7842ea..b1e068e10f1 100644 --- a/google-beta/services/osconfig/resource_os_config_os_policy_assignment_meta.yaml +++ b/google-beta/services/osconfig/resource_os_config_os_policy_assignment_meta.yaml @@ -111,3 +111,5 @@ fields: - api_field: 'rolloutState' - field: 'skip_await_rollout' - api_field: 'uid' + - field: 'deletion_policy' + provider_only: true diff --git a/google-beta/services/osconfig/resource_os_config_patch_deployment.go b/google-beta/services/osconfig/resource_os_config_patch_deployment.go index 016086ac858..c73e7943368 100644 --- a/google-beta/services/osconfig/resource_os_config_patch_deployment.go +++ b/google-beta/services/osconfig/resource_os_config_patch_deployment.go @@ -100,6 +100,7 @@ func ResourceOSConfigPatchDeployment() *schema.Resource { return &schema.Resource{ Create: resourceOSConfigPatchDeploymentCreate, Read: resourceOSConfigPatchDeploymentRead, + Update: resourceOSConfigPatchDeploymentUpdate, Delete: resourceOSConfigPatchDeploymentDelete, Importer: &schema.ResourceImporter{ @@ -113,6 +114,7 @@ func ResourceOSConfigPatchDeployment() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -1053,6 +1055,18 @@ A timestamp in RFC3339 UTC "Zulu" format, accurate to nanoseconds. Example: "201 Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -1234,6 +1248,19 @@ func resourceOSConfigPatchDeploymentRead(d *schema.ResourceData, meta interface{ return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading PatchDeployment: %s", err) } @@ -1264,7 +1291,19 @@ func resourceOSConfigPatchDeploymentRead(d *schema.ResourceData, meta interface{ return nil } +func resourceOSConfigPatchDeploymentUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceOSConfigPatchDeploymentRead(d, meta) +} + func resourceOSConfigPatchDeploymentDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy OSConfigPatchDeployment without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing PatchDeployment %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/osconfig/resource_os_config_patch_deployment_generated_meta.yaml b/google-beta/services/osconfig/resource_os_config_patch_deployment_generated_meta.yaml index 5313e3dd117..0e5af7080d0 100644 --- a/google-beta/services/osconfig/resource_os_config_patch_deployment_generated_meta.yaml +++ b/google-beta/services/osconfig/resource_os_config_patch_deployment_generated_meta.yaml @@ -84,3 +84,5 @@ fields: field: rollout.disruption_budget.percentage - api_field: rollout.mode - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/osconfigv2/resource_os_config_v2_policy_orchestrator.go b/google-beta/services/osconfigv2/resource_os_config_v2_policy_orchestrator.go index 99be26f9096..75abcffd3a0 100644 --- a/google-beta/services/osconfigv2/resource_os_config_v2_policy_orchestrator.go +++ b/google-beta/services/osconfigv2/resource_os_config_v2_policy_orchestrator.go @@ -116,6 +116,7 @@ func ResourceOSConfigV2PolicyOrchestrator() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -1764,6 +1765,18 @@ orchestrator.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -1926,6 +1939,19 @@ func resourceOSConfigV2PolicyOrchestratorRead(d *schema.ResourceData, meta inter log.Printf("[DEBUG] Finished reading OSConfigV2PolicyOrchestrator %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading PolicyOrchestrator: %s", err) } @@ -1957,6 +1983,19 @@ func resourceOSConfigV2PolicyOrchestratorRead(d *schema.ResourceData, meta inter } func resourceOSConfigV2PolicyOrchestratorUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceOSConfigV2PolicyOrchestrator().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceOSConfigV2PolicyOrchestratorRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -2100,6 +2139,13 @@ func resourceOSConfigV2PolicyOrchestratorUpdate(d *schema.ResourceData, meta int } func resourceOSConfigV2PolicyOrchestratorDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy OSConfigV2PolicyOrchestrator without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing PolicyOrchestrator %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/osconfigv2/resource_os_config_v2_policy_orchestrator_for_folder.go b/google-beta/services/osconfigv2/resource_os_config_v2_policy_orchestrator_for_folder.go index e227cfdef24..d5dd8743992 100644 --- a/google-beta/services/osconfigv2/resource_os_config_v2_policy_orchestrator_for_folder.go +++ b/google-beta/services/osconfigv2/resource_os_config_v2_policy_orchestrator_for_folder.go @@ -115,6 +115,7 @@ func ResourceOSConfigV2PolicyOrchestratorForFolder() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -1749,6 +1750,19 @@ orchestrator.`, Computed: true, Description: `Timestamp when the policy orchestrator resource was last modified.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -1900,6 +1914,20 @@ func resourceOSConfigV2PolicyOrchestratorForFolderRead(d *schema.ResourceData, m log.Printf("[DEBUG] Finished reading OSConfigV2PolicyOrchestratorForFolder %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceOSConfigV2PolicyOrchestratorForFolderFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -1927,6 +1955,18 @@ func resourceOSConfigV2PolicyOrchestratorForFolderRead(d *schema.ResourceData, m } func resourceOSConfigV2PolicyOrchestratorForFolderUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceOSConfigV2PolicyOrchestratorForFolder().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceOSConfigV2PolicyOrchestratorForFolderRead(d, meta) + } var project string config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) @@ -2065,6 +2105,13 @@ func resourceOSConfigV2PolicyOrchestratorForFolderUpdate(d *schema.ResourceData, } func resourceOSConfigV2PolicyOrchestratorForFolderDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy OSConfigV2PolicyOrchestratorForFolder without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing PolicyOrchestratorForFolder %q from Terraform state without deletion", d.Id()) + return nil + } var project string config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) diff --git a/google-beta/services/osconfigv2/resource_os_config_v2_policy_orchestrator_for_folder_generated_meta.yaml b/google-beta/services/osconfigv2/resource_os_config_v2_policy_orchestrator_for_folder_generated_meta.yaml index bb6058d4897..6d2ced5b307 100644 --- a/google-beta/services/osconfigv2/resource_os_config_v2_policy_orchestrator_for_folder_generated_meta.yaml +++ b/google-beta/services/osconfigv2/resource_os_config_v2_policy_orchestrator_for_folder_generated_meta.yaml @@ -155,3 +155,5 @@ fields: - field: terraform_labels provider_only: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/osconfigv2/resource_os_config_v2_policy_orchestrator_for_organization.go b/google-beta/services/osconfigv2/resource_os_config_v2_policy_orchestrator_for_organization.go index 2d6e4d2c1c0..882d7c9a219 100644 --- a/google-beta/services/osconfigv2/resource_os_config_v2_policy_orchestrator_for_organization.go +++ b/google-beta/services/osconfigv2/resource_os_config_v2_policy_orchestrator_for_organization.go @@ -115,6 +115,7 @@ func ResourceOSConfigV2PolicyOrchestratorForOrganization() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -1779,6 +1780,19 @@ orchestrator.`, Computed: true, Description: `Output only. Timestamp when the policy orchestrator resource was last modified.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -1930,6 +1944,20 @@ func resourceOSConfigV2PolicyOrchestratorForOrganizationRead(d *schema.ResourceD log.Printf("[DEBUG] Finished reading OSConfigV2PolicyOrchestratorForOrganization %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceOSConfigV2PolicyOrchestratorForOrganizationFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -1957,6 +1985,18 @@ func resourceOSConfigV2PolicyOrchestratorForOrganizationRead(d *schema.ResourceD } func resourceOSConfigV2PolicyOrchestratorForOrganizationUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceOSConfigV2PolicyOrchestratorForOrganization().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceOSConfigV2PolicyOrchestratorForOrganizationRead(d, meta) + } var project string config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) @@ -2095,6 +2135,13 @@ func resourceOSConfigV2PolicyOrchestratorForOrganizationUpdate(d *schema.Resourc } func resourceOSConfigV2PolicyOrchestratorForOrganizationDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy OSConfigV2PolicyOrchestratorForOrganization without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing PolicyOrchestratorForOrganization %q from Terraform state without deletion", d.Id()) + return nil + } var project string config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) diff --git a/google-beta/services/osconfigv2/resource_os_config_v2_policy_orchestrator_for_organization_generated_meta.yaml b/google-beta/services/osconfigv2/resource_os_config_v2_policy_orchestrator_for_organization_generated_meta.yaml index 5c195aef819..afdd2e2c9ec 100644 --- a/google-beta/services/osconfigv2/resource_os_config_v2_policy_orchestrator_for_organization_generated_meta.yaml +++ b/google-beta/services/osconfigv2/resource_os_config_v2_policy_orchestrator_for_organization_generated_meta.yaml @@ -155,3 +155,5 @@ fields: - field: terraform_labels provider_only: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/osconfigv2/resource_os_config_v2_policy_orchestrator_generated_meta.yaml b/google-beta/services/osconfigv2/resource_os_config_v2_policy_orchestrator_generated_meta.yaml index b9565fbfd03..2454e18d760 100644 --- a/google-beta/services/osconfigv2/resource_os_config_v2_policy_orchestrator_generated_meta.yaml +++ b/google-beta/services/osconfigv2/resource_os_config_v2_policy_orchestrator_generated_meta.yaml @@ -151,3 +151,5 @@ fields: - field: terraform_labels provider_only: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/oslogin/resource_os_login_ssh_public_key.go b/google-beta/services/oslogin/resource_os_login_ssh_public_key.go index 1dc60f0f3d1..628f7173224 100644 --- a/google-beta/services/oslogin/resource_os_login_ssh_public_key.go +++ b/google-beta/services/oslogin/resource_os_login_ssh_public_key.go @@ -161,6 +161,19 @@ func ResourceOSLoginSSHPublicKey() *schema.Resource { Computed: true, Description: `The SHA-256 fingerprint of the SSH public key.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -317,6 +330,20 @@ func resourceOSLoginSSHPublicKeyRead(d *schema.ResourceData, meta interface{}) e log.Printf("[DEBUG] Finished reading OSLoginSSHPublicKey %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceOSLoginSSHPublicKeyFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -344,6 +371,19 @@ func resourceOSLoginSSHPublicKeyRead(d *schema.ResourceData, meta interface{}) e } func resourceOSLoginSSHPublicKeyUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceOSLoginSSHPublicKey().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceOSLoginSSHPublicKeyRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -424,6 +464,13 @@ func resourceOSLoginSSHPublicKeyUpdate(d *schema.ResourceData, meta interface{}) } func resourceOSLoginSSHPublicKeyDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy OSLoginSSHPublicKey without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing SSHPublicKey %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/oslogin/resource_os_login_ssh_public_key_generated_meta.yaml b/google-beta/services/oslogin/resource_os_login_ssh_public_key_generated_meta.yaml index f3ac4e7eacb..a053dcbd4e6 100644 --- a/google-beta/services/oslogin/resource_os_login_ssh_public_key_generated_meta.yaml +++ b/google-beta/services/oslogin/resource_os_login_ssh_public_key_generated_meta.yaml @@ -14,3 +14,5 @@ fields: provider_only: true - field: user provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/parallelstore/resource_parallelstore_instance.go b/google-beta/services/parallelstore/resource_parallelstore_instance.go index 8c7cd274fe5..d78871e6f83 100644 --- a/google-beta/services/parallelstore/resource_parallelstore_instance.go +++ b/google-beta/services/parallelstore/resource_parallelstore_instance.go @@ -116,6 +116,7 @@ func ResourceParallelstoreInstance() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -318,6 +319,18 @@ and contains the value currently used by the service.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -497,6 +510,19 @@ func resourceParallelstoreInstanceRead(d *schema.ResourceData, meta interface{}) log.Printf("[DEBUG] Finished reading ParallelstoreInstance %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Instance: %s", err) } @@ -534,6 +560,19 @@ func resourceParallelstoreInstanceRead(d *schema.ResourceData, meta interface{}) } func resourceParallelstoreInstanceUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceParallelstoreInstance().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceParallelstoreInstanceRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -672,6 +711,13 @@ func resourceParallelstoreInstanceUpdate(d *schema.ResourceData, meta interface{ } func resourceParallelstoreInstanceDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ParallelstoreInstance without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Instance %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/parallelstore/resource_parallelstore_instance_generated_meta.yaml b/google-beta/services/parallelstore/resource_parallelstore_instance_generated_meta.yaml index 1bbc334cdfb..78eaebd2234 100644 --- a/google-beta/services/parallelstore/resource_parallelstore_instance_generated_meta.yaml +++ b/google-beta/services/parallelstore/resource_parallelstore_instance_generated_meta.yaml @@ -31,3 +31,5 @@ fields: - field: terraform_labels provider_only: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/parametermanager/data_source_parameter_manager_parameters_test.go b/google-beta/services/parametermanager/data_source_parameter_manager_parameters_test.go index 24b70d8773a..33bfca3368f 100644 --- a/google-beta/services/parametermanager/data_source_parameter_manager_parameters_test.go +++ b/google-beta/services/parametermanager/data_source_parameter_manager_parameters_test.go @@ -46,8 +46,9 @@ func TestAccDataSourceParameterManagerParameters_basic(t *testing.T) { "data.google_parameter_manager_parameters.parameters-datasource", "google_parameter_manager_parameter.parameters", map[string]struct{}{ - "id": {}, - "project": {}, + "id": {}, + "project": {}, + "deletion_policy": {}, }, ), ), @@ -103,8 +104,9 @@ func TestAccDataSourceParameterManagerParameters_filter(t *testing.T) { "google_parameter_manager_parameter.parameters-1", "google_parameter_manager_parameter.parameters-2", map[string]struct{}{ - "id": {}, - "project": {}, + "id": {}, + "project": {}, + "deletion_policy": {}, }, ), ), diff --git a/google-beta/services/parametermanager/resource_parameter_manager_parameter.go b/google-beta/services/parametermanager/resource_parameter_manager_parameter.go index 5931b066c27..ef831822f49 100644 --- a/google-beta/services/parametermanager/resource_parameter_manager_parameter.go +++ b/google-beta/services/parametermanager/resource_parameter_manager_parameter.go @@ -116,6 +116,7 @@ func ResourceParameterManagerParameter() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -239,6 +240,18 @@ new resource. Format: Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -373,6 +386,19 @@ func resourceParameterManagerParameterRead(d *schema.ResourceData, meta interfac log.Printf("[DEBUG] Finished reading ParameterManagerParameter %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Parameter: %s", err) } @@ -404,6 +430,19 @@ func resourceParameterManagerParameterRead(d *schema.ResourceData, meta interfac } func resourceParameterManagerParameterUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceParameterManagerParameter().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceParameterManagerParameterRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -500,6 +539,13 @@ func resourceParameterManagerParameterUpdate(d *schema.ResourceData, meta interf } func resourceParameterManagerParameterDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ParameterManagerParameter without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Parameter %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/parametermanager/resource_parameter_manager_parameter_generated_meta.yaml b/google-beta/services/parametermanager/resource_parameter_manager_parameter_generated_meta.yaml index b5424e3554a..2ca19e782f5 100644 --- a/google-beta/services/parametermanager/resource_parameter_manager_parameter_generated_meta.yaml +++ b/google-beta/services/parametermanager/resource_parameter_manager_parameter_generated_meta.yaml @@ -21,3 +21,5 @@ fields: - field: terraform_labels provider_only: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/parametermanager/resource_parameter_manager_parameter_version.go b/google-beta/services/parametermanager/resource_parameter_manager_parameter_version.go index 2c2e1deb713..7cd4d9a37cc 100644 --- a/google-beta/services/parametermanager/resource_parameter_manager_parameter_version.go +++ b/google-beta/services/parametermanager/resource_parameter_manager_parameter_version.go @@ -162,6 +162,19 @@ func ResourceParameterManagerParameterVersion() *schema.Resource { Computed: true, Description: `The time at which the Parameter Version was updated.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -262,6 +275,20 @@ func resourceParameterManagerParameterVersionRead(d *schema.ResourceData, meta i log.Printf("[DEBUG] Finished reading ParameterManagerParameterVersion %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceParameterManagerParameterVersionFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -271,6 +298,19 @@ func resourceParameterManagerParameterVersionRead(d *schema.ResourceData, meta i } func resourceParameterManagerParameterVersionUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceParameterManagerParameterVersion().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceParameterManagerParameterVersionRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -336,6 +376,13 @@ func resourceParameterManagerParameterVersionUpdate(d *schema.ResourceData, meta } func resourceParameterManagerParameterVersionDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ParameterManagerParameterVersion without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing ParameterVersion %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/parametermanager/resource_parameter_manager_parameter_version_generated_meta.yaml b/google-beta/services/parametermanager/resource_parameter_manager_parameter_version_generated_meta.yaml index 433dc6920b1..bfd3ca4265f 100644 --- a/google-beta/services/parametermanager/resource_parameter_manager_parameter_version_generated_meta.yaml +++ b/google-beta/services/parametermanager/resource_parameter_manager_parameter_version_generated_meta.yaml @@ -18,3 +18,5 @@ fields: - field: parameter_version_id provider_only: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/parametermanagerregional/data_source_parameter_manager_regional_parameters_test.go b/google-beta/services/parametermanagerregional/data_source_parameter_manager_regional_parameters_test.go index 7d2ca91975a..d8e995fd71e 100644 --- a/google-beta/services/parametermanagerregional/data_source_parameter_manager_regional_parameters_test.go +++ b/google-beta/services/parametermanagerregional/data_source_parameter_manager_regional_parameters_test.go @@ -46,8 +46,9 @@ func TestAccDataSourceParameterManagerRegionalRegionalParameters_basic(t *testin "data.google_parameter_manager_regional_parameters.regional-parameters-datasource", "google_parameter_manager_regional_parameter.regional-parameters", map[string]struct{}{ - "id": {}, - "project": {}, + "id": {}, + "project": {}, + "deletion_policy": {}, }, ), ), @@ -105,8 +106,9 @@ func TestAccDataSourceParameterManagerRegionalRegionalParameters_filter(t *testi "google_parameter_manager_regional_parameter.regional-parameters-1", "google_parameter_manager_regional_parameter.regional-parameters-2", map[string]struct{}{ - "id": {}, - "project": {}, + "id": {}, + "project": {}, + "deletion_policy": {}, }, ), ), diff --git a/google-beta/services/parametermanagerregional/resource_parameter_manager_regional_parameter.go b/google-beta/services/parametermanagerregional/resource_parameter_manager_regional_parameter.go index 0a885d592c8..4c2804ea302 100644 --- a/google-beta/services/parametermanagerregional/resource_parameter_manager_regional_parameter.go +++ b/google-beta/services/parametermanagerregional/resource_parameter_manager_regional_parameter.go @@ -116,6 +116,7 @@ func ResourceParameterManagerRegionalRegionalParameter() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -248,6 +249,18 @@ resource. Format: Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -387,6 +400,19 @@ func resourceParameterManagerRegionalRegionalParameterRead(d *schema.ResourceDat log.Printf("[DEBUG] Finished reading ParameterManagerRegionalRegionalParameter %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading RegionalParameter: %s", err) } @@ -424,6 +450,19 @@ func resourceParameterManagerRegionalRegionalParameterRead(d *schema.ResourceDat } func resourceParameterManagerRegionalRegionalParameterUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceParameterManagerRegionalRegionalParameter().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceParameterManagerRegionalRegionalParameterRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -525,6 +564,13 @@ func resourceParameterManagerRegionalRegionalParameterUpdate(d *schema.ResourceD } func resourceParameterManagerRegionalRegionalParameterDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ParameterManagerRegionalRegionalParameter without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing RegionalParameter %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/parametermanagerregional/resource_parameter_manager_regional_parameter_generated_meta.yaml b/google-beta/services/parametermanagerregional/resource_parameter_manager_regional_parameter_generated_meta.yaml index c4161ea96f3..05fe78edd25 100644 --- a/google-beta/services/parametermanagerregional/resource_parameter_manager_regional_parameter_generated_meta.yaml +++ b/google-beta/services/parametermanagerregional/resource_parameter_manager_regional_parameter_generated_meta.yaml @@ -23,3 +23,5 @@ fields: - field: terraform_labels provider_only: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/parametermanagerregional/resource_parameter_manager_regional_parameter_version.go b/google-beta/services/parametermanagerregional/resource_parameter_manager_regional_parameter_version.go index d66425b1094..3db24e57662 100644 --- a/google-beta/services/parametermanagerregional/resource_parameter_manager_regional_parameter_version.go +++ b/google-beta/services/parametermanagerregional/resource_parameter_manager_regional_parameter_version.go @@ -167,6 +167,19 @@ func ResourceParameterManagerRegionalRegionalParameterVersion() *schema.Resource Computed: true, Description: `The time at which the Regional Parameter Version was updated.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -284,6 +297,20 @@ func resourceParameterManagerRegionalRegionalParameterVersionRead(d *schema.Reso log.Printf("[DEBUG] Finished reading ParameterManagerRegionalRegionalParameterVersion %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceParameterManagerRegionalRegionalParameterVersionFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -293,6 +320,19 @@ func resourceParameterManagerRegionalRegionalParameterVersionRead(d *schema.Reso } func resourceParameterManagerRegionalRegionalParameterVersionUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceParameterManagerRegionalRegionalParameterVersion().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceParameterManagerRegionalRegionalParameterVersionRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -358,6 +398,13 @@ func resourceParameterManagerRegionalRegionalParameterVersionUpdate(d *schema.Re } func resourceParameterManagerRegionalRegionalParameterVersionDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ParameterManagerRegionalRegionalParameterVersion without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing RegionalParameterVersion %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/parametermanagerregional/resource_parameter_manager_regional_parameter_version_generated_meta.yaml b/google-beta/services/parametermanagerregional/resource_parameter_manager_regional_parameter_version_generated_meta.yaml index cf1c4184a13..5ffc5e92a92 100644 --- a/google-beta/services/parametermanagerregional/resource_parameter_manager_regional_parameter_version_generated_meta.yaml +++ b/google-beta/services/parametermanagerregional/resource_parameter_manager_regional_parameter_version_generated_meta.yaml @@ -20,3 +20,5 @@ fields: - field: parameter_version_id provider_only: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/privateca/resource_privateca_ca_pool.go b/google-beta/services/privateca/resource_privateca_ca_pool.go index 35c5bd9a578..d7602f61bb5 100644 --- a/google-beta/services/privateca/resource_privateca_ca_pool.go +++ b/google-beta/services/privateca/resource_privateca_ca_pool.go @@ -116,6 +116,7 @@ func ResourcePrivatecaCaPool() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -730,6 +731,18 @@ will be published in PEM. Possible values: ["PEM", "DER"]`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -891,6 +904,19 @@ func resourcePrivatecaCaPoolRead(d *schema.ResourceData, meta interface{}) error log.Printf("[DEBUG] Finished reading PrivatecaCaPool %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading CaPool: %s", err) } @@ -928,6 +954,19 @@ func resourcePrivatecaCaPoolRead(d *schema.ResourceData, meta interface{}) error } func resourcePrivatecaCaPoolUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourcePrivatecaCaPool().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourcePrivatecaCaPoolRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1056,6 +1095,13 @@ func resourcePrivatecaCaPoolUpdate(d *schema.ResourceData, meta interface{}) err } func resourcePrivatecaCaPoolDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy PrivatecaCaPool without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing CaPool %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/privateca/resource_privateca_ca_pool_generated_meta.yaml b/google-beta/services/privateca/resource_privateca_ca_pool_generated_meta.yaml index 4a97ab48064..f9c4f3a1687 100644 --- a/google-beta/services/privateca/resource_privateca_ca_pool_generated_meta.yaml +++ b/google-beta/services/privateca/resource_privateca_ca_pool_generated_meta.yaml @@ -70,3 +70,5 @@ fields: - field: terraform_labels provider_only: true - api_field: tier + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/privateca/resource_privateca_certificate.go b/google-beta/services/privateca/resource_privateca_certificate.go index 874aeab4150..00fe179e9f3 100644 --- a/google-beta/services/privateca/resource_privateca_certificate.go +++ b/google-beta/services/privateca/resource_privateca_certificate.go @@ -116,6 +116,7 @@ func ResourcePrivatecaCertificate() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -1385,6 +1386,18 @@ This is in RFC3339 text format.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -1548,6 +1561,19 @@ func resourcePrivatecaCertificateRead(d *schema.ResourceData, meta interface{}) log.Printf("[DEBUG] Finished reading PrivatecaCertificate %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Certificate: %s", err) } @@ -1591,6 +1617,19 @@ func resourcePrivatecaCertificateRead(d *schema.ResourceData, meta interface{}) } func resourcePrivatecaCertificateUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourcePrivatecaCertificate().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourcePrivatecaCertificateRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1687,6 +1726,13 @@ func resourcePrivatecaCertificateUpdate(d *schema.ResourceData, meta interface{} } func resourcePrivatecaCertificateDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy PrivatecaCertificate without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Certificate %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/privateca/resource_privateca_certificate_authority.go b/google-beta/services/privateca/resource_privateca_certificate_authority.go index 09fdcb219d3..254a870a6c5 100644 --- a/google-beta/services/privateca/resource_privateca_certificate_authority.go +++ b/google-beta/services/privateca/resource_privateca_certificate_authority.go @@ -134,6 +134,7 @@ func ResourcePrivatecaCertificateAuthority() *schema.Resource { resourcePrivateCaCACustomDiff, tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -969,6 +970,18 @@ Possible values: ENABLED, DISABLED, STAGED.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -1197,6 +1210,18 @@ func resourcePrivatecaCertificateAuthorityRead(d *schema.ResourceData, meta inte return fmt.Errorf("Error setting deletion_protection: %s", err) } } + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading CertificateAuthority: %s", err) } @@ -1240,6 +1265,19 @@ func resourcePrivatecaCertificateAuthorityRead(d *schema.ResourceData, meta inte } func resourcePrivatecaCertificateAuthorityUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourcePrivatecaCertificateAuthority().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourcePrivatecaCertificateAuthorityRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1421,6 +1459,13 @@ func resourcePrivatecaCertificateAuthorityUpdate(d *schema.ResourceData, meta in } func resourcePrivatecaCertificateAuthorityDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy PrivatecaCertificateAuthority without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing CertificateAuthority %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/privateca/resource_privateca_certificate_authority_generated_meta.yaml b/google-beta/services/privateca/resource_privateca_certificate_authority_generated_meta.yaml index 19093db66e6..6a2f5da3410 100644 --- a/google-beta/services/privateca/resource_privateca_certificate_authority_generated_meta.yaml +++ b/google-beta/services/privateca/resource_privateca_certificate_authority_generated_meta.yaml @@ -93,3 +93,5 @@ fields: - api_field: updateTime - api_field: userDefinedAccessUrls.aiaIssuingCertificateUrls - api_field: userDefinedAccessUrls.crlAccessUrls + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/privateca/resource_privateca_certificate_generated_meta.yaml b/google-beta/services/privateca/resource_privateca_certificate_generated_meta.yaml index ed922513d5d..f5014ad6c1e 100644 --- a/google-beta/services/privateca/resource_privateca_certificate_generated_meta.yaml +++ b/google-beta/services/privateca/resource_privateca_certificate_generated_meta.yaml @@ -139,3 +139,5 @@ fields: - field: terraform_labels provider_only: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/privateca/resource_privateca_certificate_template.go b/google-beta/services/privateca/resource_privateca_certificate_template.go index 19b23924295..276d346ba06 100644 --- a/google-beta/services/privateca/resource_privateca_certificate_template.go +++ b/google-beta/services/privateca/resource_privateca_certificate_template.go @@ -116,6 +116,7 @@ func ResourcePrivatecaCertificateTemplate() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -636,6 +637,18 @@ leading period (like '.example.com')`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -803,6 +816,19 @@ func resourcePrivatecaCertificateTemplateRead(d *schema.ResourceData, meta inter log.Printf("[DEBUG] Finished reading PrivatecaCertificateTemplate %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading CertificateTemplate: %s", err) } @@ -840,6 +866,19 @@ func resourcePrivatecaCertificateTemplateRead(d *schema.ResourceData, meta inter } func resourcePrivatecaCertificateTemplateUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourcePrivatecaCertificateTemplate().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourcePrivatecaCertificateTemplateRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -988,6 +1027,13 @@ func resourcePrivatecaCertificateTemplateUpdate(d *schema.ResourceData, meta int } func resourcePrivatecaCertificateTemplateDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy PrivatecaCertificateTemplate without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing CertificateTemplate %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/privateca/resource_privateca_certificate_template_generated_meta.yaml b/google-beta/services/privateca/resource_privateca_certificate_template_generated_meta.yaml index 3c12aa95faa..568e8aca984 100644 --- a/google-beta/services/privateca/resource_privateca_certificate_template_generated_meta.yaml +++ b/google-beta/services/privateca/resource_privateca_certificate_template_generated_meta.yaml @@ -64,3 +64,5 @@ fields: - field: terraform_labels provider_only: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/privilegedaccessmanager/resource_privileged_access_manager_entitlement.go b/google-beta/services/privilegedaccessmanager/resource_privileged_access_manager_entitlement.go index 56199cd9320..d2c4ae291d1 100644 --- a/google-beta/services/privilegedaccessmanager/resource_privileged_access_manager_entitlement.go +++ b/google-beta/services/privilegedaccessmanager/resource_privileged_access_manager_entitlement.go @@ -435,6 +435,19 @@ Formats: organizations/{organization-number}/locations/{region}/entitlements/{en Description: `Output only. Update time stamp. A timestamp in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine fractional digits. Examples: "2014-10-02T15:01:23Z" and "2014-10-02T15:01:23.045123456Z".`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -596,6 +609,20 @@ func resourcePrivilegedAccessManagerEntitlementRead(d *schema.ResourceData, meta log.Printf("[DEBUG] Finished reading PrivilegedAccessManagerEntitlement %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourcePrivilegedAccessManagerEntitlementFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -629,6 +656,19 @@ func resourcePrivilegedAccessManagerEntitlementRead(d *schema.ResourceData, meta } func resourcePrivilegedAccessManagerEntitlementUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourcePrivilegedAccessManagerEntitlement().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourcePrivilegedAccessManagerEntitlementRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -784,6 +824,13 @@ func resourcePrivilegedAccessManagerEntitlementUpdate(d *schema.ResourceData, me } func resourcePrivilegedAccessManagerEntitlementDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy PrivilegedAccessManagerEntitlement without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Entitlement %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/privilegedaccessmanager/resource_privileged_access_manager_entitlement_generated_meta.yaml b/google-beta/services/privilegedaccessmanager/resource_privileged_access_manager_entitlement_generated_meta.yaml index 35b107d3555..6f96028ca7f 100644 --- a/google-beta/services/privilegedaccessmanager/resource_privileged_access_manager_entitlement_generated_meta.yaml +++ b/google-beta/services/privilegedaccessmanager/resource_privileged_access_manager_entitlement_generated_meta.yaml @@ -38,3 +38,5 @@ fields: - api_field: requesterJustificationConfig.unstructured - api_field: state - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/privilegedaccessmanager/resource_privileged_access_manager_settings.go b/google-beta/services/privilegedaccessmanager/resource_privileged_access_manager_settings.go index 2e00bc609b9..570415dba3d 100644 --- a/google-beta/services/privilegedaccessmanager/resource_privileged_access_manager_settings.go +++ b/google-beta/services/privilegedaccessmanager/resource_privileged_access_manager_settings.go @@ -412,6 +412,7 @@ func resourcePrivilegedAccessManagerSettingsRead(d *schema.ResourceData, meta in } func resourcePrivilegedAccessManagerSettingsUpdate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/pubsub/resource_pubsub_schema.go b/google-beta/services/pubsub/resource_pubsub_schema.go index 446f6565177..4280af7ed5b 100644 --- a/google-beta/services/pubsub/resource_pubsub_schema.go +++ b/google-beta/services/pubsub/resource_pubsub_schema.go @@ -115,6 +115,7 @@ func ResourcePubsubSchema() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -168,6 +169,18 @@ error indicating that the limit has been reached require manually Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -343,6 +356,19 @@ func resourcePubsubSchemaRead(d *schema.ResourceData, meta interface{}) error { log.Printf("[DEBUG] Finished reading PubsubSchema %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Schema: %s", err) } @@ -374,6 +400,19 @@ func resourcePubsubSchemaRead(d *schema.ResourceData, meta interface{}) error { } func resourcePubsubSchemaUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourcePubsubSchema().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourcePubsubSchemaRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -462,6 +501,13 @@ func resourcePubsubSchemaUpdate(d *schema.ResourceData, meta interface{}) error } func resourcePubsubSchemaDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy PubsubSchema without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Schema %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/pubsub/resource_pubsub_schema_generated_meta.yaml b/google-beta/services/pubsub/resource_pubsub_schema_generated_meta.yaml index e55702252ad..f502860334e 100644 --- a/google-beta/services/pubsub/resource_pubsub_schema_generated_meta.yaml +++ b/google-beta/services/pubsub/resource_pubsub_schema_generated_meta.yaml @@ -10,3 +10,5 @@ fields: - api_field: definition - api_field: name - api_field: type + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/pubsub/resource_pubsub_subscription.go b/google-beta/services/pubsub/resource_pubsub_subscription.go index 416499df9a9..5393b5c2de3 100644 --- a/google-beta/services/pubsub/resource_pubsub_subscription.go +++ b/google-beta/services/pubsub/resource_pubsub_subscription.go @@ -150,6 +150,7 @@ func ResourcePubsubSubscription() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -767,6 +768,18 @@ resource.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -1036,6 +1049,19 @@ func resourcePubsubSubscriptionRead(d *schema.ResourceData, meta interface{}) er log.Printf("[DEBUG] Finished reading PubsubSubscription %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Subscription: %s", err) } @@ -1067,6 +1093,19 @@ func resourcePubsubSubscriptionRead(d *schema.ResourceData, meta interface{}) er } func resourcePubsubSubscriptionUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourcePubsubSubscription().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourcePubsubSubscriptionRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1277,6 +1316,13 @@ func resourcePubsubSubscriptionUpdate(d *schema.ResourceData, meta interface{}) } func resourcePubsubSubscriptionDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy PubsubSubscription without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Subscription %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/pubsub/resource_pubsub_subscription_generated_meta.yaml b/google-beta/services/pubsub/resource_pubsub_subscription_generated_meta.yaml index 14a9bf3ee07..1966d3c36ec 100644 --- a/google-beta/services/pubsub/resource_pubsub_subscription_generated_meta.yaml +++ b/google-beta/services/pubsub/resource_pubsub_subscription_generated_meta.yaml @@ -55,3 +55,5 @@ fields: - field: terraform_labels provider_only: true - api_field: topic + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/pubsub/resource_pubsub_topic.go b/google-beta/services/pubsub/resource_pubsub_topic.go index 041175e928c..f447e271d50 100644 --- a/google-beta/services/pubsub/resource_pubsub_topic.go +++ b/google-beta/services/pubsub/resource_pubsub_topic.go @@ -116,6 +116,7 @@ func ResourcePubsubTopic() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -643,6 +644,18 @@ resource.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -867,6 +880,19 @@ func resourcePubsubTopicRead(d *schema.ResourceData, meta interface{}) error { log.Printf("[DEBUG] Finished reading PubsubTopic %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Topic: %s", err) } @@ -898,6 +924,19 @@ func resourcePubsubTopicRead(d *schema.ResourceData, meta interface{}) error { } func resourcePubsubTopicUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourcePubsubTopic().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourcePubsubTopicRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1050,6 +1089,13 @@ func resourcePubsubTopicUpdate(d *schema.ResourceData, meta interface{}) error { } func resourcePubsubTopicDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy PubsubTopic without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Topic %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/pubsub/resource_pubsub_topic_generated_meta.yaml b/google-beta/services/pubsub/resource_pubsub_topic_generated_meta.yaml index c979aa30cec..5fea19a285a 100644 --- a/google-beta/services/pubsub/resource_pubsub_topic_generated_meta.yaml +++ b/google-beta/services/pubsub/resource_pubsub_topic_generated_meta.yaml @@ -53,3 +53,5 @@ fields: - api_field: tags - field: terraform_labels provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/pubsublite/resource_pubsub_lite_reservation.go b/google-beta/services/pubsublite/resource_pubsub_lite_reservation.go index 69639ceb53a..441c6309016 100644 --- a/google-beta/services/pubsublite/resource_pubsub_lite_reservation.go +++ b/google-beta/services/pubsublite/resource_pubsub_lite_reservation.go @@ -115,6 +115,7 @@ func ResourcePubsubLiteReservation() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), DeprecationMessage: "[Pubsub Lite is deprecated and will be turned down effective March 18, 2026](https://cloud.google.com/pubsub/lite/docs/release-notes#June_17_2024). The resource will be removed in a future major release, please use `google_pubsub_reservation` instead.", @@ -168,6 +169,18 @@ messages.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -295,6 +308,19 @@ func resourcePubsubLiteReservationRead(d *schema.ResourceData, meta interface{}) log.Printf("[DEBUG] Finished reading PubsubLiteReservation %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Reservation: %s", err) } @@ -332,6 +358,19 @@ func resourcePubsubLiteReservationRead(d *schema.ResourceData, meta interface{}) } func resourcePubsubLiteReservationUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourcePubsubLiteReservation().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourcePubsubLiteReservationRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -423,6 +462,13 @@ func resourcePubsubLiteReservationUpdate(d *schema.ResourceData, meta interface{ } func resourcePubsubLiteReservationDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy PubsubLiteReservation without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Reservation %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/pubsublite/resource_pubsub_lite_reservation_generated_meta.yaml b/google-beta/services/pubsublite/resource_pubsub_lite_reservation_generated_meta.yaml index ecfaf478ad0..5247b15394f 100644 --- a/google-beta/services/pubsublite/resource_pubsub_lite_reservation_generated_meta.yaml +++ b/google-beta/services/pubsublite/resource_pubsub_lite_reservation_generated_meta.yaml @@ -12,3 +12,5 @@ fields: - field: region provider_only: true - api_field: throughputCapacity + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/pubsublite/resource_pubsub_lite_subscription.go b/google-beta/services/pubsublite/resource_pubsub_lite_subscription.go index ea925d98785..63e5e8c8d3e 100644 --- a/google-beta/services/pubsublite/resource_pubsub_lite_subscription.go +++ b/google-beta/services/pubsublite/resource_pubsub_lite_subscription.go @@ -115,6 +115,7 @@ func ResourcePubsubLiteSubscription() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), DeprecationMessage: "[Pubsub Lite is deprecated and will be turned down effective March 18, 2026](https://cloud.google.com/pubsub/lite/docs/release-notes#June_17_2024). The resource will be removed in a future major release, please use `google_pubsub_subscription` instead.", @@ -189,6 +190,18 @@ func ResourcePubsubLiteSubscription() *schema.Resource { Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -327,6 +340,19 @@ func resourcePubsubLiteSubscriptionRead(d *schema.ResourceData, meta interface{} log.Printf("[DEBUG] Finished reading PubsubLiteSubscription %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Subscription: %s", err) } @@ -364,6 +390,19 @@ func resourcePubsubLiteSubscriptionRead(d *schema.ResourceData, meta interface{} } func resourcePubsubLiteSubscriptionUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourcePubsubLiteSubscription().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourcePubsubLiteSubscriptionRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -460,6 +499,13 @@ func resourcePubsubLiteSubscriptionUpdate(d *schema.ResourceData, meta interface } func resourcePubsubLiteSubscriptionDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy PubsubLiteSubscription without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Subscription %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/pubsublite/resource_pubsub_lite_subscription_generated_meta.yaml b/google-beta/services/pubsublite/resource_pubsub_lite_subscription_generated_meta.yaml index 08ee33e3a0e..984ec88fe86 100644 --- a/google-beta/services/pubsublite/resource_pubsub_lite_subscription_generated_meta.yaml +++ b/google-beta/services/pubsublite/resource_pubsub_lite_subscription_generated_meta.yaml @@ -15,3 +15,5 @@ fields: - api_field: topic - field: zone provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/pubsublite/resource_pubsub_lite_topic.go b/google-beta/services/pubsublite/resource_pubsub_lite_topic.go index d8d2954a738..78595f3eddc 100644 --- a/google-beta/services/pubsublite/resource_pubsub_lite_topic.go +++ b/google-beta/services/pubsublite/resource_pubsub_lite_topic.go @@ -115,6 +115,7 @@ func ResourcePubsubLiteTopic() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), DeprecationMessage: "[Pubsub Lite is deprecated and will be turned down effective March 18, 2026](https://cloud.google.com/pubsub/lite/docs/release-notes#June_17_2024). The resource will be removed in a future major release, please use `google_pubsub_topic` instead.", @@ -242,6 +243,18 @@ Example: "3.5s".`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -386,6 +399,19 @@ func resourcePubsubLiteTopicRead(d *schema.ResourceData, meta interface{}) error log.Printf("[DEBUG] Finished reading PubsubLiteTopic %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Topic: %s", err) } @@ -423,6 +449,19 @@ func resourcePubsubLiteTopicRead(d *schema.ResourceData, meta interface{}) error } func resourcePubsubLiteTopicUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourcePubsubLiteTopic().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourcePubsubLiteTopicRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -539,6 +578,13 @@ func resourcePubsubLiteTopicUpdate(d *schema.ResourceData, meta interface{}) err } func resourcePubsubLiteTopicDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy PubsubLiteTopic without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Topic %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/pubsublite/resource_pubsub_lite_topic_generated_meta.yaml b/google-beta/services/pubsublite/resource_pubsub_lite_topic_generated_meta.yaml index 941d9fe64a6..6c16b5e57ca 100644 --- a/google-beta/services/pubsublite/resource_pubsub_lite_topic_generated_meta.yaml +++ b/google-beta/services/pubsublite/resource_pubsub_lite_topic_generated_meta.yaml @@ -19,3 +19,5 @@ fields: - api_field: retentionConfig.period - field: zone provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/recaptchaenterprise/resource_recaptcha_enterprise_key.go b/google-beta/services/recaptchaenterprise/resource_recaptcha_enterprise_key.go index b0d72b6ba25..5d95f986402 100644 --- a/google-beta/services/recaptchaenterprise/resource_recaptcha_enterprise_key.go +++ b/google-beta/services/recaptchaenterprise/resource_recaptcha_enterprise_key.go @@ -52,6 +52,7 @@ func ResourceRecaptchaEnterpriseKey() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, tpgresource.SetLabelsDiff, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Schema: map[string]*schema.Schema{ @@ -145,6 +146,9 @@ func ResourceRecaptchaEnterpriseKey() *schema.Resource { Computed: true, Description: "The combination of labels configured directly on the resource and default labels configured on the provider.", }, + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end }, } } @@ -471,9 +475,18 @@ func resourceRecaptchaEnterpriseKeyRead(d *schema.ResourceData, meta interface{} return fmt.Errorf("error setting terraform_labels in state: %s", err) } + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + return nil } func resourceRecaptchaEnterpriseKeyUpdate(d *schema.ResourceData, meta interface{}) error { + + if tpgresource.DeletionPolicyPreUpdate(d, ResourceRecaptchaEnterpriseKey) { + return ResourceRecaptchaEnterpriseKey().Read(d, meta) + } + config := meta.(*transport_tpg.Config) project, err := tpgresource.GetProject(d, config) if err != nil { @@ -525,6 +538,13 @@ func resourceRecaptchaEnterpriseKeyUpdate(d *schema.ResourceData, meta interface } func resourceRecaptchaEnterpriseKeyDelete(d *schema.ResourceData, meta interface{}) error { + + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { + return nil + } + config := meta.(*transport_tpg.Config) project, err := tpgresource.GetProject(d, config) if err != nil { diff --git a/google-beta/services/recaptchaenterprise/resource_recaptcha_enterprise_key_meta.yaml b/google-beta/services/recaptchaenterprise/resource_recaptcha_enterprise_key_meta.yaml index bb37c904fa3..f1605bbe1c7 100644 --- a/google-beta/services/recaptchaenterprise/resource_recaptcha_enterprise_key_meta.yaml +++ b/google-beta/services/recaptchaenterprise/resource_recaptcha_enterprise_key_meta.yaml @@ -28,6 +28,8 @@ fields: - api_field: 'webSettings.allowedDomains' - api_field: 'webSettings.challengeSecurityPreference' - api_field: 'webSettings.integrationType' + - field: 'deletion_policy' + provider_only: true - api_field: 'webSettings.challengeSettings.defaultSettings.scoreThreshold' - field: 'web_settings.challenge_settings.action_settings.action' provider_only: true diff --git a/google-beta/services/redis/resource_redis_cluster.go b/google-beta/services/redis/resource_redis_cluster.go index dc7a9d532e7..fe900e10ba2 100644 --- a/google-beta/services/redis/resource_redis_cluster.go +++ b/google-beta/services/redis/resource_redis_cluster.go @@ -117,6 +117,7 @@ func ResourceRedisCluster() *schema.Resource { tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, tpgresource.DefaultProviderRegion, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -899,6 +900,18 @@ resolution and up to nine fractional digits.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -1167,6 +1180,19 @@ func resourceRedisClusterRead(d *schema.ResourceData, meta interface{}) error { return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Cluster: %s", err) } @@ -1212,6 +1238,19 @@ func resourceRedisClusterRead(d *schema.ResourceData, meta interface{}) error { } func resourceRedisClusterUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceRedisCluster().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceRedisClusterRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1455,6 +1494,13 @@ func resourceRedisClusterUpdate(d *schema.ResourceData, meta interface{}) error } func resourceRedisClusterDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy RedisCluster without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Cluster %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/redis/resource_redis_cluster_generated_meta.yaml b/google-beta/services/redis/resource_redis_cluster_generated_meta.yaml index 0ebcf9f2177..117874d2dd9 100644 --- a/google-beta/services/redis/resource_redis_cluster_generated_meta.yaml +++ b/google-beta/services/redis/resource_redis_cluster_generated_meta.yaml @@ -80,3 +80,5 @@ fields: - api_field: uid - api_field: zoneDistributionConfig.mode - api_field: zoneDistributionConfig.zone + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/redis/resource_redis_cluster_user_created_connections.go b/google-beta/services/redis/resource_redis_cluster_user_created_connections.go index 34166e0837a..fb592a71d5f 100644 --- a/google-beta/services/redis/resource_redis_cluster_user_created_connections.go +++ b/google-beta/services/redis/resource_redis_cluster_user_created_connections.go @@ -115,6 +115,7 @@ func ResourceRedisClusterUserCreatedConnections() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -238,6 +239,18 @@ service attachment.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -375,6 +388,19 @@ func resourceRedisClusterUserCreatedConnectionsRead(d *schema.ResourceData, meta log.Printf("[DEBUG] Finished reading RedisClusterUserCreatedConnections %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading ClusterUserCreatedConnections: %s", err) } @@ -412,6 +438,19 @@ func resourceRedisClusterUserCreatedConnectionsRead(d *schema.ResourceData, meta } func resourceRedisClusterUserCreatedConnectionsUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceRedisClusterUserCreatedConnections().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceRedisClusterUserCreatedConnectionsRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -510,6 +549,13 @@ func resourceRedisClusterUserCreatedConnectionsUpdate(d *schema.ResourceData, me } func resourceRedisClusterUserCreatedConnectionsDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy RedisClusterUserCreatedConnections without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing ClusterUserCreatedConnections %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/redis/resource_redis_cluster_user_created_connections_generated_meta.yaml b/google-beta/services/redis/resource_redis_cluster_user_created_connections_generated_meta.yaml index 8d7d980a712..e91ccf8f9a5 100644 --- a/google-beta/services/redis/resource_redis_cluster_user_created_connections_generated_meta.yaml +++ b/google-beta/services/redis/resource_redis_cluster_user_created_connections_generated_meta.yaml @@ -19,3 +19,5 @@ fields: provider_only: true - field: region provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/redis/resource_redis_instance.go b/google-beta/services/redis/resource_redis_instance.go index f6ba1383d7c..1a3a4059e64 100644 --- a/google-beta/services/redis/resource_redis_instance.go +++ b/google-beta/services/redis/resource_redis_instance.go @@ -155,6 +155,7 @@ func ResourceRedisInstance() *schema.Resource { customdiff.ForceNewIfChange("redis_version", isRedisVersionDecreasing), tpgresource.DefaultProviderProject, tpgresource.SetLabelsDiff, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -680,6 +681,18 @@ When the field is set to false, deleting the instance is allowed.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -955,6 +968,18 @@ func resourceRedisInstanceRead(d *schema.ResourceData, meta interface{}) error { } // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Instance: %s", err) } @@ -1000,6 +1025,19 @@ func resourceRedisInstanceRead(d *schema.ResourceData, meta interface{}) error { } func resourceRedisInstanceUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceRedisInstance().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceRedisInstanceRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1252,6 +1290,13 @@ func resourceRedisInstanceUpdate(d *schema.ResourceData, meta interface{}) error } func resourceRedisInstanceDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy RedisInstance without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Instance %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/redis/resource_redis_instance_generated_meta.yaml b/google-beta/services/redis/resource_redis_instance_generated_meta.yaml index 2051d75369d..2e8e08c3199 100644 --- a/google-beta/services/redis/resource_redis_instance_generated_meta.yaml +++ b/google-beta/services/redis/resource_redis_instance_generated_meta.yaml @@ -66,3 +66,5 @@ fields: provider_only: true - api_field: tier - api_field: transitEncryptionMode + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/resourcemanager/data_source_google_folder.go b/google-beta/services/resourcemanager/data_source_google_folder.go index 7b357b4ae21..972f880bca5 100644 --- a/google-beta/services/resourcemanager/data_source_google_folder.go +++ b/google-beta/services/resourcemanager/data_source_google_folder.go @@ -80,6 +80,10 @@ func DataSourceGoogleFolder() *schema.Resource { Type: schema.TypeString, Computed: true, }, + "deletion_policy": { + Type: schema.TypeString, + Computed: true, + }, }, } } diff --git a/google-beta/services/resourcemanager/list_google_service_account.go b/google-beta/services/resourcemanager/list_google_service_account.go index 916e0329ee8..a3e265bba19 100644 --- a/google-beta/services/resourcemanager/list_google_service_account.go +++ b/google-beta/services/resourcemanager/list_google_service_account.go @@ -107,7 +107,7 @@ func flattenGoogleServiceAccountListItem(res map[string]interface{}, d *schema.R return err } d.SetId(sa.Name) - return populateResourceData(d, &sa) + return populateResourceData(d, &sa, config) } func ListServiceAccounts(config *transport_tpg.Config, project string, callback func(rd *schema.ResourceData) error) error { diff --git a/google-beta/services/resourcemanager/resource_google_billing_subaccount.go b/google-beta/services/resourcemanager/resource_google_billing_subaccount.go index 31b8c9db973..c19a10cc855 100644 --- a/google-beta/services/resourcemanager/resource_google_billing_subaccount.go +++ b/google-beta/services/resourcemanager/resource_google_billing_subaccount.go @@ -21,8 +21,8 @@ import ( "strings" "time" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-provider-google-beta/google-beta/registry" cloudbilling_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/services/cloudbilling" @@ -42,6 +42,10 @@ func ResourceBillingSubaccount() *schema.Resource { State: schema.ImportStatePassthrough, }, + CustomizeDiff: customdiff.All( + tpgresource.DefaultProviderDeletionPolicy(""), + ), + Schema: map[string]*schema.Schema{ "display_name": { Type: schema.TypeString, @@ -53,12 +57,9 @@ func ResourceBillingSubaccount() *schema.Resource { ForceNew: true, DiffSuppressFunc: tpgresource.CompareSelfLinkOrResourceName, }, - "deletion_policy": { - Type: schema.TypeString, - Optional: true, - Default: "", - ValidateFunc: validation.StringInSlice([]string{"RENAME_ON_DESTROY", ""}, false), - }, + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry(""), + //UDP schema end "billing_account_id": { Type: schema.TypeString, Computed: true, @@ -131,10 +132,19 @@ func resourceBillingSubaccountRead(d *schema.ResourceData, meta interface{}) err return fmt.Errorf("Error setting billing_account_id: %s", err) } + if err := tpgresource.DeletionPolicyReadDefault(d, config, ""); err != nil { + return err + } + return nil } func resourceBillingSubaccountUpdate(d *schema.ResourceData, meta interface{}) error { + + if tpgresource.DeletionPolicyPreUpdate(d, ResourceBillingSubaccount) { + return ResourceBillingSubaccount().Read(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -154,6 +164,13 @@ func resourceBillingSubaccountUpdate(d *schema.ResourceData, meta interface{}) e } func resourceBillingSubaccountDelete(d *schema.ResourceData, meta interface{}) error { + + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { + return nil + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/resourcemanager/resource_google_billing_subaccount_meta.yaml b/google-beta/services/resourcemanager/resource_google_billing_subaccount_meta.yaml index 436a56e2c60..13ccbe578df 100644 --- a/google-beta/services/resourcemanager/resource_google_billing_subaccount_meta.yaml +++ b/google-beta/services/resourcemanager/resource_google_billing_subaccount_meta.yaml @@ -8,7 +8,9 @@ api_resource_type_kind: 'BillingAccount' fields: - field: 'billing_account_id' - field: 'deletion_policy' + provider_only: true - api_field: 'displayName' - api_field: 'masterBillingAccount' - api_field: 'name' - api_field: 'open' + diff --git a/google-beta/services/resourcemanager/resource_google_folder.go b/google-beta/services/resourcemanager/resource_google_folder.go index 4bd2b5f774a..5290678ca05 100644 --- a/google-beta/services/resourcemanager/resource_google_folder.go +++ b/google-beta/services/resourcemanager/resource_google_folder.go @@ -22,6 +22,7 @@ import ( "strings" "time" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-google-beta/google-beta/registry" @@ -43,6 +44,10 @@ func ResourceGoogleFolder() *schema.Resource { State: resourceGoogleFolderImportState, }, + CustomizeDiff: customdiff.All( + tpgresource.DefaultProviderDeletionPolicy("DELETE"), + ), + Timeouts: &schema.ResourceTimeout{ Create: schema.DefaultTimeout(4 * time.Minute), Update: schema.DefaultTimeout(4 * time.Minute), @@ -109,6 +114,9 @@ func ResourceGoogleFolder() *schema.Resource { Computed: true, Description: `The Management Project associated with the folder's configured capabilities.`, }, + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end }, UseJSONNumber: true, } @@ -217,6 +225,10 @@ func resourceGoogleFolderRead(d *schema.ResourceData, meta interface{}) error { return fmt.Errorf("Error setting management_project: %s", err) } + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + return nil } @@ -227,7 +239,7 @@ func resourceGoogleFolderUpdate(d *schema.ResourceData, meta interface{}) error return err } - clientSideFields := map[string]bool{"deletion_protection": true} + clientSideFields := map[string]bool{"deletion_protection": true, "deletion_policy": true} clientSideOnly := true for field := range ResourceGoogleFolder().Schema { if d.HasChange(field) && !clientSideFields[field] { @@ -290,6 +302,13 @@ func resourceGoogleFolderUpdate(d *schema.ResourceData, meta interface{}) error } func resourceGoogleFolderDelete(d *schema.ResourceData, meta interface{}) error { + + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { + return nil + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/resourcemanager/resource_google_folder_meta.yaml b/google-beta/services/resourcemanager/resource_google_folder_meta.yaml index a0f359c1b74..fdd9565a7c0 100644 --- a/google-beta/services/resourcemanager/resource_google_folder_meta.yaml +++ b/google-beta/services/resourcemanager/resource_google_folder_meta.yaml @@ -16,3 +16,5 @@ fields: - api_field: 'name' - api_field: 'parent' - api_field: 'tags' + - field: 'deletion_policy' + provider_only: true diff --git a/google-beta/services/resourcemanager/resource_google_folder_organization_policy.go b/google-beta/services/resourcemanager/resource_google_folder_organization_policy.go index 58b84131363..202b0651d47 100644 --- a/google-beta/services/resourcemanager/resource_google_folder_organization_policy.go +++ b/google-beta/services/resourcemanager/resource_google_folder_organization_policy.go @@ -20,6 +20,7 @@ import ( "fmt" "time" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-google-beta/google-beta/registry" rmClient "github.com/hashicorp/terraform-provider-google-beta/google-beta/services/resourcemanager/client" @@ -46,6 +47,10 @@ func ResourceGoogleFolderOrganizationPolicy() *schema.Resource { Delete: schema.DefaultTimeout(4 * time.Minute), }, + CustomizeDiff: customdiff.All( + tpgresource.DefaultProviderDeletionPolicy("DELETE"), + ), + Schema: tpgresource.MergeSchemas( schemaOrganizationPolicy, map[string]*schema.Schema{ @@ -55,6 +60,9 @@ func ResourceGoogleFolderOrganizationPolicy() *schema.Resource { ForceNew: true, Description: `The resource name of the folder to set the policy for. Its format is folders/{folder_id}.`, }, + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end }, ), UseJSONNumber: true, @@ -141,10 +149,19 @@ func resourceGoogleFolderOrganizationPolicyRead(d *schema.ResourceData, meta int return fmt.Errorf("Error setting update_time: %s", err) } + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + return nil } func resourceGoogleFolderOrganizationPolicyUpdate(d *schema.ResourceData, meta interface{}) error { + + if tpgresource.DeletionPolicyPreUpdate(d, ResourceGoogleFolderOrganizationPolicy) { + return ResourceGoogleFolderOrganizationPolicy().Read(d, meta) + } + if isOrganizationPolicyUnset(d) { return resourceGoogleFolderOrganizationPolicyDelete(d, meta) } @@ -157,6 +174,13 @@ func resourceGoogleFolderOrganizationPolicyUpdate(d *schema.ResourceData, meta i } func resourceGoogleFolderOrganizationPolicyDelete(d *schema.ResourceData, meta interface{}) error { + + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { + return nil + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/resourcemanager/resource_google_folder_organization_policy_meta.yaml b/google-beta/services/resourcemanager/resource_google_folder_organization_policy_meta.yaml index 6a06787f341..fccbda8b232 100644 --- a/google-beta/services/resourcemanager/resource_google_folder_organization_policy_meta.yaml +++ b/google-beta/services/resourcemanager/resource_google_folder_organization_policy_meta.yaml @@ -19,3 +19,5 @@ fields: - field: 'restore_policy.default' - api_field: 'updateTime' - field: 'version' + - field: 'deletion_policy' + provider_only: true diff --git a/google-beta/services/resourcemanager/resource_google_organization_iam_custom_role.go b/google-beta/services/resourcemanager/resource_google_organization_iam_custom_role.go index 9fdcc417640..5334dca8ae3 100644 --- a/google-beta/services/resourcemanager/resource_google_organization_iam_custom_role.go +++ b/google-beta/services/resourcemanager/resource_google_organization_iam_custom_role.go @@ -19,6 +19,7 @@ package resourcemanager import ( "fmt" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-provider-google-beta/google-beta/registry" @@ -49,6 +50,10 @@ func ResourceGoogleOrganizationIamCustomRole() *schema.Resource { State: schema.ImportStatePassthrough, }, + CustomizeDiff: customdiff.All( + tpgresource.DefaultProviderDeletionPolicy("DELETE"), + ), + Schema: map[string]*schema.Schema{ "role_id": { Type: schema.TypeString, @@ -98,6 +103,9 @@ func ResourceGoogleOrganizationIamCustomRole() *schema.Resource { Computed: true, Description: `The name of the role in the format organizations/{{org_id}}/roles/{{role_id}}. Like id, this field can be used as a reference in other resources such as IAM role bindings.`, }, + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end }, UseJSONNumber: true, } @@ -196,10 +204,19 @@ func resourceGoogleOrganizationIamCustomRoleRead(d *schema.ResourceData, meta in return fmt.Errorf("Error setting deleted: %s", err) } + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + return nil } func resourceGoogleOrganizationIamCustomRoleUpdate(d *schema.ResourceData, meta interface{}) error { + + if tpgresource.DeletionPolicyPreUpdate(d, ResourceGoogleOrganizationIamCustomRole) { + return ResourceGoogleOrganizationIamCustomRole().Read(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -240,6 +257,13 @@ func resourceGoogleOrganizationIamCustomRoleUpdate(d *schema.ResourceData, meta } func resourceGoogleOrganizationIamCustomRoleDelete(d *schema.ResourceData, meta interface{}) error { + + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { + return nil + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/resourcemanager/resource_google_organization_iam_custom_role_meta.yaml b/google-beta/services/resourcemanager/resource_google_organization_iam_custom_role_meta.yaml index 20dd62fc1c0..24de3fd7d63 100644 --- a/google-beta/services/resourcemanager/resource_google_organization_iam_custom_role_meta.yaml +++ b/google-beta/services/resourcemanager/resource_google_organization_iam_custom_role_meta.yaml @@ -14,3 +14,5 @@ fields: - field: 'role_id' - api_field: 'stage' - api_field: 'title' + - field: 'deletion_policy' + provider_only: true diff --git a/google-beta/services/resourcemanager/resource_google_organization_policy.go b/google-beta/services/resourcemanager/resource_google_organization_policy.go index 9c8bd881cff..1a71298994b 100644 --- a/google-beta/services/resourcemanager/resource_google_organization_policy.go +++ b/google-beta/services/resourcemanager/resource_google_organization_policy.go @@ -21,6 +21,7 @@ import ( "strings" "time" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-google-beta/google-beta/registry" @@ -181,6 +182,10 @@ func ResourceGoogleOrganizationPolicy() *schema.Resource { Delete: schema.DefaultTimeout(4 * time.Minute), }, + CustomizeDiff: customdiff.All( + tpgresource.DefaultProviderDeletionPolicy("DELETE"), + ), + Schema: tpgresource.MergeSchemas( schemaOrganizationPolicy, map[string]*schema.Schema{ @@ -189,6 +194,9 @@ func ResourceGoogleOrganizationPolicy() *schema.Resource { Required: true, ForceNew: true, }, + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end }), UseJSONNumber: true, } @@ -251,10 +259,19 @@ func resourceGoogleOrganizationPolicyRead(d *schema.ResourceData, meta interface return fmt.Errorf("Error setting restore_policy: %s", err) } + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + return nil } func resourceGoogleOrganizationPolicyUpdate(d *schema.ResourceData, meta interface{}) error { + + if tpgresource.DeletionPolicyPreUpdate(d, ResourceGoogleOrganizationPolicy) { + return ResourceGoogleOrganizationPolicy().Read(d, meta) + } + if isOrganizationPolicyUnset(d) { return resourceGoogleOrganizationPolicyDelete(d, meta) } @@ -267,6 +284,13 @@ func resourceGoogleOrganizationPolicyUpdate(d *schema.ResourceData, meta interfa } func resourceGoogleOrganizationPolicyDelete(d *schema.ResourceData, meta interface{}) error { + + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { + return nil + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/resourcemanager/resource_google_organization_policy_meta.yaml b/google-beta/services/resourcemanager/resource_google_organization_policy_meta.yaml index bb3a047901b..81aef42e5e0 100644 --- a/google-beta/services/resourcemanager/resource_google_organization_policy_meta.yaml +++ b/google-beta/services/resourcemanager/resource_google_organization_policy_meta.yaml @@ -19,3 +19,5 @@ fields: - field: 'restore_policy.default' - api_field: 'updateTime' - field: 'version' + - field: 'deletion_policy' + provider_only: true diff --git a/google-beta/services/resourcemanager/resource_google_project.go b/google-beta/services/resourcemanager/resource_google_project.go index baff3e31cd8..1ff082a817e 100644 --- a/google-beta/services/resourcemanager/resource_google_project.go +++ b/google-beta/services/resourcemanager/resource_google_project.go @@ -62,6 +62,7 @@ func ResourceGoogleProject() *schema.Resource { Delete: resourceGoogleProjectDelete, CustomizeDiff: customdiff.All( + tpgresource.DefaultProviderDeletionPolicy("PREVENT"), tpgresource.SetLabelsDiff, ), @@ -88,8 +89,8 @@ func ResourceGoogleProject() *schema.Resource { }, "deletion_policy": { Type: schema.TypeString, + Computed: true, Optional: true, - Default: "PREVENT", Description: `The deletion policy for the Project. Setting PREVENT will protect the project against any destroy actions caused by a terraform apply or terraform destroy. Setting ABANDON allows the resource to be abandoned rather than deleted. Possible values are: "PREVENT", "ABANDON", "DELETE"`, ValidateFunc: validation.StringInSlice([]string{"PREVENT", "ABANDON", "DELETE"}, false), @@ -339,11 +340,11 @@ func resourceGoogleProjectRead(d *schema.ResourceData, meta interface{}) error { return nil } // Explicitly set client-side fields to default values if unset - if _, ok := d.GetOkExists("deletion_policy"); !ok { - if err := d.Set("deletion_policy", "PREVENT"); err != nil { - return fmt.Errorf("Error setting deletion_policy: %s", err) - } + + if err := tpgresource.DeletionPolicyReadDefault(d, config, "PREVENT"); err != nil { + return err } + if err := d.Set("project_id", pid); err != nil { return fmt.Errorf("Error setting project_id: %s", err) } diff --git a/google-beta/services/resourcemanager/resource_google_project_iam_custom_role.go b/google-beta/services/resourcemanager/resource_google_project_iam_custom_role.go index 475e0ba67c0..d718b23682b 100644 --- a/google-beta/services/resourcemanager/resource_google_project_iam_custom_role.go +++ b/google-beta/services/resourcemanager/resource_google_project_iam_custom_role.go @@ -44,6 +44,7 @@ func ResourceGoogleProjectIamCustomRole() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Schema: map[string]*schema.Schema{ @@ -96,6 +97,9 @@ func ResourceGoogleProjectIamCustomRole() *schema.Resource { Computed: true, Description: `The name of the role in the format projects/{{project}}/roles/{{role_id}}. Like id, this field can be used as a reference in other resources such as IAM role bindings.`, }, + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end }, UseJSONNumber: true, } @@ -196,10 +200,19 @@ func resourceGoogleProjectIamCustomRoleRead(d *schema.ResourceData, meta interfa return fmt.Errorf("Error setting project: %s", err) } + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + return nil } func resourceGoogleProjectIamCustomRoleUpdate(d *schema.ResourceData, meta interface{}) error { + + if tpgresource.DeletionPolicyPreUpdate(d, ResourceGoogleProjectIamCustomRole) { + return ResourceGoogleProjectIamCustomRole().Read(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -239,6 +252,13 @@ func resourceGoogleProjectIamCustomRoleUpdate(d *schema.ResourceData, meta inter } func resourceGoogleProjectIamCustomRoleDelete(d *schema.ResourceData, meta interface{}) error { + + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { + return nil + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/resourcemanager/resource_google_project_iam_custom_role_meta.yaml b/google-beta/services/resourcemanager/resource_google_project_iam_custom_role_meta.yaml index 75c54995f8f..10a80c138d4 100644 --- a/google-beta/services/resourcemanager/resource_google_project_iam_custom_role_meta.yaml +++ b/google-beta/services/resourcemanager/resource_google_project_iam_custom_role_meta.yaml @@ -14,3 +14,5 @@ fields: - field: 'role_id' - api_field: 'stage' - api_field: 'title' + - field: 'deletion_policy' + provider_only: true diff --git a/google-beta/services/resourcemanager/resource_google_project_organization_policy.go b/google-beta/services/resourcemanager/resource_google_project_organization_policy.go index 78ccf22f241..9f8ed5ae115 100644 --- a/google-beta/services/resourcemanager/resource_google_project_organization_policy.go +++ b/google-beta/services/resourcemanager/resource_google_project_organization_policy.go @@ -20,6 +20,7 @@ import ( "fmt" "time" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-google-beta/google-beta/registry" rmClient "github.com/hashicorp/terraform-provider-google-beta/google-beta/services/resourcemanager/client" @@ -46,6 +47,10 @@ func ResourceGoogleProjectOrganizationPolicy() *schema.Resource { Delete: schema.DefaultTimeout(4 * time.Minute), }, + CustomizeDiff: customdiff.All( + tpgresource.DefaultProviderDeletionPolicy("DELETE"), + ), + Schema: tpgresource.MergeSchemas( schemaOrganizationPolicy, map[string]*schema.Schema{ @@ -55,6 +60,9 @@ func ResourceGoogleProjectOrganizationPolicy() *schema.Resource { ForceNew: true, Description: `The project ID.`, }, + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end }, ), UseJSONNumber: true, @@ -138,10 +146,19 @@ func resourceGoogleProjectOrganizationPolicyRead(d *schema.ResourceData, meta in return fmt.Errorf("Error setting update_time: %s", err) } + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + return nil } func resourceGoogleProjectOrganizationPolicyUpdate(d *schema.ResourceData, meta interface{}) error { + + if tpgresource.DeletionPolicyPreUpdate(d, ResourceGoogleProjectOrganizationPolicy) { + return ResourceGoogleProjectOrganizationPolicy().Read(d, meta) + } + if isOrganizationPolicyUnset(d) { return resourceGoogleProjectOrganizationPolicyDelete(d, meta) } @@ -154,6 +171,13 @@ func resourceGoogleProjectOrganizationPolicyUpdate(d *schema.ResourceData, meta } func resourceGoogleProjectOrganizationPolicyDelete(d *schema.ResourceData, meta interface{}) error { + + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { + return nil + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/resourcemanager/resource_google_project_organization_policy_meta.yaml b/google-beta/services/resourcemanager/resource_google_project_organization_policy_meta.yaml index 693d56f083e..ef60612ce03 100644 --- a/google-beta/services/resourcemanager/resource_google_project_organization_policy_meta.yaml +++ b/google-beta/services/resourcemanager/resource_google_project_organization_policy_meta.yaml @@ -19,3 +19,5 @@ fields: - field: 'restore_policy.default' - api_field: 'updateTime' - field: 'version' + - field: 'deletion_policy' + provider_only: true diff --git a/google-beta/services/resourcemanager/resource_google_project_service.go b/google-beta/services/resourcemanager/resource_google_project_service.go index 87ef9bc3775..fd897187fe6 100644 --- a/google-beta/services/resourcemanager/resource_google_project_service.go +++ b/google-beta/services/resourcemanager/resource_google_project_service.go @@ -109,6 +109,7 @@ func ResourceGoogleProjectService() *schema.Resource { }, CustomizeDiff: customdiff.All( + tpgresource.DefaultProviderDeletionPolicy("DELETE"), tpgresource.DefaultProviderProject, ), @@ -140,6 +141,9 @@ func ResourceGoogleProjectService() *schema.Resource { Type: schema.TypeBool, Optional: true, }, + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end }, UseJSONNumber: true, } @@ -251,12 +255,23 @@ func resourceGoogleProjectServiceRead(d *schema.ResourceData, meta interface{}) return nil } + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + log.Printf("[DEBUG] service %s not in enabled services for project %s, removing from state", srv, project) d.SetId("") return nil } func resourceGoogleProjectServiceDelete(d *schema.ResourceData, meta interface{}) error { + + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { + return nil + } + config := meta.(*transport_tpg.Config) if disable := d.Get("disable_on_destroy"); !(disable.(bool)) { diff --git a/google-beta/services/resourcemanager/resource_google_project_service_meta.yaml b/google-beta/services/resourcemanager/resource_google_project_service_meta.yaml index a05a81d9665..8d239748361 100644 --- a/google-beta/services/resourcemanager/resource_google_project_service_meta.yaml +++ b/google-beta/services/resourcemanager/resource_google_project_service_meta.yaml @@ -13,3 +13,5 @@ fields: - field: 'disable_on_destroy' - field: 'project' - field: 'service' + - field: 'deletion_policy' + provider_only: true diff --git a/google-beta/services/resourcemanager/resource_google_service_account.go b/google-beta/services/resourcemanager/resource_google_service_account.go index 964fe382181..1afcb9d6e66 100644 --- a/google-beta/services/resourcemanager/resource_google_service_account.go +++ b/google-beta/services/resourcemanager/resource_google_service_account.go @@ -51,6 +51,7 @@ func ResourceGoogleServiceAccount() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, resourceServiceAccountCustomDiff, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -127,6 +128,9 @@ func ResourceGoogleServiceAccount() *schema.Resource { Computed: false, Description: `If set to true, skip service account creation if a service account with the same email already exists.`, }, + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end }, UseJSONNumber: true, } @@ -173,7 +177,7 @@ func resourceGoogleServiceAccountCreate(d *schema.ResourceData, meta interface{} } d.SetId(sa.Name) - return populateResourceData(d, sa) + return populateResourceData(d, sa, config) }, Timeout: d.Timeout(schema.TimeoutCreate), ErrorRetryPredicates: []transport_tpg.RetryErrorPredicateFunc{ @@ -188,7 +192,7 @@ func resourceGoogleServiceAccountCreate(d *schema.ResourceData, meta interface{} } d.SetId(sa.Name) - populateResourceData(d, sa) + populateResourceData(d, sa, config) // We poll until the resource is found due to eventual consistency issue // on part of the api https://cloud.google.com/iam/docs/overview#consistency. @@ -243,10 +247,10 @@ func resourceGoogleServiceAccountRead(d *schema.ResourceData, meta interface{}) return transport_tpg.HandleNotFoundError(err, d, fmt.Sprintf("Service Account %q", d.Id())) } - return populateResourceData(d, sa) + return populateResourceData(d, sa, config) } -func populateResourceData(d *schema.ResourceData, sa *iam.ServiceAccount) error { +func populateResourceData(d *schema.ResourceData, sa *iam.ServiceAccount, config *transport_tpg.Config) error { if err := d.Set("email", sa.Email); err != nil { return fmt.Errorf("Error setting email: %s", err) } @@ -275,6 +279,10 @@ func populateResourceData(d *schema.ResourceData, sa *iam.ServiceAccount) error return fmt.Errorf("Error setting member: %s", err) } + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + return tpgresource.SetResourceIdentityAttributes(d, map[string]interface{}{ "email": sa.Email, "project": sa.ProjectId, @@ -282,6 +290,13 @@ func populateResourceData(d *schema.ResourceData, sa *iam.ServiceAccount) error } func resourceGoogleServiceAccountDelete(d *schema.ResourceData, meta interface{}) error { + + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { + return nil + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -301,6 +316,11 @@ func resourceGoogleServiceAccountDelete(d *schema.ResourceData, meta interface{} } func resourceGoogleServiceAccountUpdate(d *schema.ResourceData, meta interface{}) error { + + if tpgresource.DeletionPolicyPreUpdate(d, ResourceGoogleServiceAccount) { + return ResourceGoogleServiceAccount().Read(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/resourcemanager/resource_google_service_account_key.go b/google-beta/services/resourcemanager/resource_google_service_account_key.go index e0e109d4a32..e9fbe4afa2a 100644 --- a/google-beta/services/resourcemanager/resource_google_service_account_key.go +++ b/google-beta/services/resourcemanager/resource_google_service_account_key.go @@ -26,6 +26,7 @@ import ( "github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource" transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "google.golang.org/api/iam/v1" @@ -35,7 +36,13 @@ func ResourceGoogleServiceAccountKey() *schema.Resource { return &schema.Resource{ Create: resourceGoogleServiceAccountKeyCreate, Read: resourceGoogleServiceAccountKeyRead, + Update: resourceGoogleServiceAccountKeyUpdate, Delete: resourceGoogleServiceAccountKeyDelete, + + CustomizeDiff: customdiff.All( + tpgresource.DefaultProviderDeletionPolicy("DELETE"), + ), + Schema: map[string]*schema.Schema{ // Required "service_account_id": { @@ -109,6 +116,9 @@ func ResourceGoogleServiceAccountKey() *schema.Resource { Computed: true, Description: `The key can be used before this timestamp. A timestamp in RFC3339 UTC "Zulu" format, accurate to nanoseconds. Example: "2014-10-02T15:01:23.045123456Z".`, }, + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end }, UseJSONNumber: true, } @@ -207,10 +217,30 @@ func resourceGoogleServiceAccountKeyRead(d *schema.ResourceData, meta interface{ if err := d.Set("public_key", sak.PublicKeyData); err != nil { return fmt.Errorf("Error setting public_key: %s", err) } + + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + return nil } +// UDP update start +func resourceGoogleServiceAccountKeyUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceGoogleServiceAccountKeyRead(d, meta) +} + +//UDP update end + func resourceGoogleServiceAccountKeyDelete(d *schema.ResourceData, meta interface{}) error { + + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { + return nil + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/resourcemanager/resource_google_service_account_key_meta.yaml b/google-beta/services/resourcemanager/resource_google_service_account_key_meta.yaml index 4e5a42915ee..9a20fec89ff 100644 --- a/google-beta/services/resourcemanager/resource_google_service_account_key_meta.yaml +++ b/google-beta/services/resourcemanager/resource_google_service_account_key_meta.yaml @@ -17,3 +17,5 @@ fields: - field: 'service_account_id' - field: 'valid_after' - field: 'valid_before' + - field: 'deletion_policy' + provider_only: true diff --git a/google-beta/services/resourcemanager/resource_google_service_account_meta.yaml b/google-beta/services/resourcemanager/resource_google_service_account_meta.yaml index 148a780213b..1d92df4f610 100644 --- a/google-beta/services/resourcemanager/resource_google_service_account_meta.yaml +++ b/google-beta/services/resourcemanager/resource_google_service_account_meta.yaml @@ -18,3 +18,5 @@ fields: - api_field: 'name' - field: 'project' - api_field: 'uniqueId' + - field: 'deletion_policy' + provider_only: true diff --git a/google-beta/services/resourcemanager/resource_resource_manager_lien.go b/google-beta/services/resourcemanager/resource_resource_manager_lien.go index ed40ae8b2b6..b9fb45a784d 100644 --- a/google-beta/services/resourcemanager/resource_resource_manager_lien.go +++ b/google-beta/services/resourcemanager/resource_resource_manager_lien.go @@ -106,6 +106,7 @@ func ResourceResourceManagerLien() *schema.Resource { return &schema.Resource{ Create: resourceResourceManagerLienCreate, Read: resourceResourceManagerLienRead, + Update: resourceResourceManagerLienUpdate, Delete: resourceResourceManagerLienDelete, Importer: &schema.ResourceImporter{ @@ -184,6 +185,19 @@ e.g. ['resourcemanager.projects.delete']`, Computed: true, Description: `A system-generated unique identifier for this Lien.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -342,6 +356,20 @@ func resourceResourceManagerLienRead(d *schema.ResourceData, meta interface{}) e return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceResourceManagerLienFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -368,7 +396,19 @@ func resourceResourceManagerLienRead(d *schema.ResourceData, meta interface{}) e return nil } +func resourceResourceManagerLienUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceResourceManagerLienRead(d, meta) +} + func resourceResourceManagerLienDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ResourceManagerLien without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Lien %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/resourcemanager/resource_resource_manager_lien_generated_meta.yaml b/google-beta/services/resourcemanager/resource_resource_manager_lien_generated_meta.yaml index c1bb214277e..e1de4e9b408 100644 --- a/google-beta/services/resourcemanager/resource_resource_manager_lien_generated_meta.yaml +++ b/google-beta/services/resourcemanager/resource_resource_manager_lien_generated_meta.yaml @@ -13,3 +13,5 @@ fields: - api_field: parent - api_field: reason - api_field: restrictions + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/resourcemanagerv3/resource_resource_manager_capability.go b/google-beta/services/resourcemanagerv3/resource_resource_manager_capability.go index 212e47ce61b..8621e84b997 100644 --- a/google-beta/services/resourcemanagerv3/resource_resource_manager_capability.go +++ b/google-beta/services/resourcemanagerv3/resource_resource_manager_capability.go @@ -295,6 +295,7 @@ func resourceResourceManagerV3CapabilityRead(d *schema.ResourceData, meta interf } func resourceResourceManagerV3CapabilityUpdate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/runtimeconfig/resource_runtimeconfig_config.go b/google-beta/services/runtimeconfig/resource_runtimeconfig_config.go index 37ded84c7e4..4a8abc1cea3 100644 --- a/google-beta/services/runtimeconfig/resource_runtimeconfig_config.go +++ b/google-beta/services/runtimeconfig/resource_runtimeconfig_config.go @@ -45,6 +45,7 @@ func ResourceRuntimeconfigConfig() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Schema: map[string]*schema.Schema{ @@ -69,6 +70,9 @@ func ResourceRuntimeconfigConfig() *schema.Resource { ForceNew: true, Description: `The ID of the project in which the resource belongs. If it is not provided, the provider project is used.`, }, + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end }, UseJSONNumber: true, } @@ -144,10 +148,19 @@ func resourceRuntimeconfigConfigRead(d *schema.ResourceData, meta interface{}) e return fmt.Errorf("Error setting project: %s", err) } + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + return nil } func resourceRuntimeconfigConfigUpdate(d *schema.ResourceData, meta interface{}) error { + + if tpgresource.DeletionPolicyPreUpdate(d, ResourceRuntimeconfigConfig) { + return ResourceRuntimeconfigConfig().Read(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -173,6 +186,13 @@ func resourceRuntimeconfigConfigUpdate(d *schema.ResourceData, meta interface{}) } func resourceRuntimeconfigConfigDelete(d *schema.ResourceData, meta interface{}) error { + + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { + return nil + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/runtimeconfig/resource_runtimeconfig_config_meta.yaml b/google-beta/services/runtimeconfig/resource_runtimeconfig_config_meta.yaml index 0e5cf237a66..a5c6645d3a1 100644 --- a/google-beta/services/runtimeconfig/resource_runtimeconfig_config_meta.yaml +++ b/google-beta/services/runtimeconfig/resource_runtimeconfig_config_meta.yaml @@ -9,3 +9,5 @@ fields: - api_field: 'description' - api_field: 'name' - field: 'project' + - field: 'deletion_policy' + provider_only: true diff --git a/google-beta/services/runtimeconfig/resource_runtimeconfig_variable.go b/google-beta/services/runtimeconfig/resource_runtimeconfig_variable.go index 187e435b41b..402aa63023f 100644 --- a/google-beta/services/runtimeconfig/resource_runtimeconfig_variable.go +++ b/google-beta/services/runtimeconfig/resource_runtimeconfig_variable.go @@ -42,6 +42,7 @@ func ResourceRuntimeconfigVariable() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Schema: map[string]*schema.Schema{ @@ -86,6 +87,10 @@ func ResourceRuntimeconfigVariable() *schema.Resource { Computed: true, Description: `The timestamp in RFC3339 UTC "Zulu" format, accurate to nanoseconds, representing when the variable was last updated. Example: "2016-10-09T12:33:37.578138407Z".`, }, + + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end }, UseJSONNumber: true, } @@ -130,10 +135,19 @@ func resourceRuntimeconfigVariableRead(d *schema.ResourceData, meta interface{}) return err } + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + return setRuntimeConfigVariableToResourceData(d, *createdVariable) } func resourceRuntimeconfigVariableUpdate(d *schema.ResourceData, meta interface{}) error { + + if tpgresource.DeletionPolicyPreUpdate(d, ResourceRuntimeconfigVariable) { + return ResourceRuntimeconfigVariable().Read(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -162,6 +176,13 @@ func resourceRuntimeconfigVariableUpdate(d *schema.ResourceData, meta interface{ } func resourceRuntimeconfigVariableDelete(d *schema.ResourceData, meta interface{}) error { + + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { + return nil + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/runtimeconfig/resource_runtimeconfig_variable_meta.yaml b/google-beta/services/runtimeconfig/resource_runtimeconfig_variable_meta.yaml index 414af9b2966..186e6a95fa7 100644 --- a/google-beta/services/runtimeconfig/resource_runtimeconfig_variable_meta.yaml +++ b/google-beta/services/runtimeconfig/resource_runtimeconfig_variable_meta.yaml @@ -12,3 +12,5 @@ fields: - api_field: 'text' - api_field: 'updateTime' - api_field: 'value' + - field: 'deletion_policy' + provider_only: true diff --git a/google-beta/services/saasruntime/resource_saas_runtime_release.go b/google-beta/services/saasruntime/resource_saas_runtime_release.go index d62cb3a28e1..fb62b160bbd 100644 --- a/google-beta/services/saasruntime/resource_saas_runtime_release.go +++ b/google-beta/services/saasruntime/resource_saas_runtime_release.go @@ -117,6 +117,7 @@ func ResourceSaasRuntimeRelease() *schema.Resource { tpgresource.SetAnnotationsDiff, tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -381,6 +382,18 @@ Changes to a resource made by the service should refresh this value.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -538,6 +551,19 @@ func resourceSaasRuntimeReleaseRead(d *schema.ResourceData, meta interface{}) er log.Printf("[DEBUG] Finished reading SaasRuntimeRelease %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Release: %s", err) } @@ -575,6 +601,19 @@ func resourceSaasRuntimeReleaseRead(d *schema.ResourceData, meta interface{}) er } func resourceSaasRuntimeReleaseUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceSaasRuntimeRelease().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceSaasRuntimeReleaseRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -706,6 +745,13 @@ func resourceSaasRuntimeReleaseUpdate(d *schema.ResourceData, meta interface{}) } func resourceSaasRuntimeReleaseDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy SaasRuntimeRelease without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Release %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/saasruntime/resource_saas_runtime_release_generated_meta.yaml b/google-beta/services/saasruntime/resource_saas_runtime_release_generated_meta.yaml index 17e46237b3d..bb67f8e50ef 100644 --- a/google-beta/services/saasruntime/resource_saas_runtime_release_generated_meta.yaml +++ b/google-beta/services/saasruntime/resource_saas_runtime_release_generated_meta.yaml @@ -39,3 +39,5 @@ fields: - api_field: uid - api_field: unitKind - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/saasruntime/resource_saas_runtime_rollout_kind.go b/google-beta/services/saasruntime/resource_saas_runtime_rollout_kind.go index cfa51df48f6..56b78ce306b 100644 --- a/google-beta/services/saasruntime/resource_saas_runtime_rollout_kind.go +++ b/google-beta/services/saasruntime/resource_saas_runtime_rollout_kind.go @@ -117,6 +117,7 @@ func ResourceSaasRuntimeRolloutKind() *schema.Resource { tpgresource.SetAnnotationsDiff, tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -292,6 +293,18 @@ Changes to a resource made by the service should refresh this value.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -455,6 +468,19 @@ func resourceSaasRuntimeRolloutKindRead(d *schema.ResourceData, meta interface{} log.Printf("[DEBUG] Finished reading SaasRuntimeRolloutKind %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading RolloutKind: %s", err) } @@ -492,6 +518,19 @@ func resourceSaasRuntimeRolloutKindRead(d *schema.ResourceData, meta interface{} } func resourceSaasRuntimeRolloutKindUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceSaasRuntimeRolloutKind().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceSaasRuntimeRolloutKindRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -633,6 +672,13 @@ func resourceSaasRuntimeRolloutKindUpdate(d *schema.ResourceData, meta interface } func resourceSaasRuntimeRolloutKindDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy SaasRuntimeRolloutKind without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing RolloutKind %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/saasruntime/resource_saas_runtime_rollout_kind_generated_meta.yaml b/google-beta/services/saasruntime/resource_saas_runtime_rollout_kind_generated_meta.yaml index 518d073b2ed..3e30ec12c53 100644 --- a/google-beta/services/saasruntime/resource_saas_runtime_rollout_kind_generated_meta.yaml +++ b/google-beta/services/saasruntime/resource_saas_runtime_rollout_kind_generated_meta.yaml @@ -30,3 +30,5 @@ fields: - api_field: unitKind - api_field: updateTime - api_field: updateUnitKindStrategy + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/saasruntime/resource_saas_runtime_saas.go b/google-beta/services/saasruntime/resource_saas_runtime_saas.go index 9e3a76627a2..4142c5f1a07 100644 --- a/google-beta/services/saasruntime/resource_saas_runtime_saas.go +++ b/google-beta/services/saasruntime/resource_saas_runtime_saas.go @@ -117,6 +117,7 @@ func ResourceSaasRuntimeSaas() *schema.Resource { tpgresource.SetAnnotationsDiff, tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -254,6 +255,18 @@ Changes to a resource made by the service should refresh this value.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -393,6 +406,19 @@ func resourceSaasRuntimeSaasRead(d *schema.ResourceData, meta interface{}) error log.Printf("[DEBUG] Finished reading SaasRuntimeSaas %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Saas: %s", err) } @@ -430,6 +456,19 @@ func resourceSaasRuntimeSaasRead(d *schema.ResourceData, meta interface{}) error } func resourceSaasRuntimeSaasUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceSaasRuntimeSaas().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceSaasRuntimeSaasRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -541,6 +580,13 @@ func resourceSaasRuntimeSaasUpdate(d *schema.ResourceData, meta interface{}) err } func resourceSaasRuntimeSaasDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy SaasRuntimeSaas without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Saas %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/saasruntime/resource_saas_runtime_saas_generated_meta.yaml b/google-beta/services/saasruntime/resource_saas_runtime_saas_generated_meta.yaml index 4733c82f288..eb4c37271d5 100644 --- a/google-beta/services/saasruntime/resource_saas_runtime_saas_generated_meta.yaml +++ b/google-beta/services/saasruntime/resource_saas_runtime_saas_generated_meta.yaml @@ -26,3 +26,5 @@ fields: provider_only: true - api_field: uid - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/saasruntime/resource_saas_runtime_tenant.go b/google-beta/services/saasruntime/resource_saas_runtime_tenant.go index 314c9a6aa17..1460b60b596 100644 --- a/google-beta/services/saasruntime/resource_saas_runtime_tenant.go +++ b/google-beta/services/saasruntime/resource_saas_runtime_tenant.go @@ -117,6 +117,7 @@ func ResourceSaasRuntimeTenant() *schema.Resource { tpgresource.SetAnnotationsDiff, tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -250,6 +251,18 @@ Changes to a resource made by the service should refresh this value.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -395,6 +408,19 @@ func resourceSaasRuntimeTenantRead(d *schema.ResourceData, meta interface{}) err log.Printf("[DEBUG] Finished reading SaasRuntimeTenant %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Tenant: %s", err) } @@ -432,6 +458,19 @@ func resourceSaasRuntimeTenantRead(d *schema.ResourceData, meta interface{}) err } func resourceSaasRuntimeTenantUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceSaasRuntimeTenant().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceSaasRuntimeTenantRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -533,6 +572,13 @@ func resourceSaasRuntimeTenantUpdate(d *schema.ResourceData, meta interface{}) e } func resourceSaasRuntimeTenantDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy SaasRuntimeTenant without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Tenant %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/saasruntime/resource_saas_runtime_tenant_generated_meta.yaml b/google-beta/services/saasruntime/resource_saas_runtime_tenant_generated_meta.yaml index b5f1b8e08ef..f25c3bc1146 100644 --- a/google-beta/services/saasruntime/resource_saas_runtime_tenant_generated_meta.yaml +++ b/google-beta/services/saasruntime/resource_saas_runtime_tenant_generated_meta.yaml @@ -26,3 +26,5 @@ fields: provider_only: true - api_field: uid - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/saasruntime/resource_saas_runtime_unit.go b/google-beta/services/saasruntime/resource_saas_runtime_unit.go index ddff5d61676..a9e56132b6e 100644 --- a/google-beta/services/saasruntime/resource_saas_runtime_unit.go +++ b/google-beta/services/saasruntime/resource_saas_runtime_unit.go @@ -117,6 +117,7 @@ func ResourceSaasRuntimeUnit() *schema.Resource { tpgresource.SetAnnotationsDiff, tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -477,6 +478,18 @@ Changes to a resource made by the service should refresh this value.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -634,6 +647,19 @@ func resourceSaasRuntimeUnitRead(d *schema.ResourceData, meta interface{}) error log.Printf("[DEBUG] Finished reading SaasRuntimeUnit %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Unit: %s", err) } @@ -671,6 +697,19 @@ func resourceSaasRuntimeUnitRead(d *schema.ResourceData, meta interface{}) error } func resourceSaasRuntimeUnitUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceSaasRuntimeUnit().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceSaasRuntimeUnitRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -802,6 +841,13 @@ func resourceSaasRuntimeUnitUpdate(d *schema.ResourceData, meta interface{}) err } func resourceSaasRuntimeUnitDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy SaasRuntimeUnit without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Unit %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/saasruntime/resource_saas_runtime_unit_generated_meta.yaml b/google-beta/services/saasruntime/resource_saas_runtime_unit_generated_meta.yaml index 1a05d32605a..b1eb5c877f5 100644 --- a/google-beta/services/saasruntime/resource_saas_runtime_unit_generated_meta.yaml +++ b/google-beta/services/saasruntime/resource_saas_runtime_unit_generated_meta.yaml @@ -50,3 +50,5 @@ fields: provider_only: true - api_field: unitKind - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/saasruntime/resource_saas_runtime_unit_kind.go b/google-beta/services/saasruntime/resource_saas_runtime_unit_kind.go index 03841248b96..b5c9185f529 100644 --- a/google-beta/services/saasruntime/resource_saas_runtime_unit_kind.go +++ b/google-beta/services/saasruntime/resource_saas_runtime_unit_kind.go @@ -117,6 +117,7 @@ func ResourceSaasRuntimeUnitKind() *schema.Resource { tpgresource.SetAnnotationsDiff, tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -398,6 +399,18 @@ Changes to a resource made by the service should refresh this value.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -561,6 +574,19 @@ func resourceSaasRuntimeUnitKindRead(d *schema.ResourceData, meta interface{}) e log.Printf("[DEBUG] Finished reading SaasRuntimeUnitKind %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading UnitKind: %s", err) } @@ -598,6 +624,19 @@ func resourceSaasRuntimeUnitKindRead(d *schema.ResourceData, meta interface{}) e } func resourceSaasRuntimeUnitKindUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceSaasRuntimeUnitKind().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceSaasRuntimeUnitKindRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -729,6 +768,13 @@ func resourceSaasRuntimeUnitKindUpdate(d *schema.ResourceData, meta interface{}) } func resourceSaasRuntimeUnitKindDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy SaasRuntimeUnitKind without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing UnitKind %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/saasruntime/resource_saas_runtime_unit_kind_generated_meta.yaml b/google-beta/services/saasruntime/resource_saas_runtime_unit_kind_generated_meta.yaml index 430c4052ec2..2a80cc37f64 100644 --- a/google-beta/services/saasruntime/resource_saas_runtime_unit_kind_generated_meta.yaml +++ b/google-beta/services/saasruntime/resource_saas_runtime_unit_kind_generated_meta.yaml @@ -41,3 +41,5 @@ fields: - field: unit_kind_id provider_only: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/saasruntime/resource_saas_runtime_unit_operation.go b/google-beta/services/saasruntime/resource_saas_runtime_unit_operation.go index 9d62e7c4291..f7fd0e75c36 100644 --- a/google-beta/services/saasruntime/resource_saas_runtime_unit_operation.go +++ b/google-beta/services/saasruntime/resource_saas_runtime_unit_operation.go @@ -117,6 +117,7 @@ func ResourceSaasRuntimeUnitOperation() *schema.Resource { tpgresource.SetAnnotationsDiff, tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -443,6 +444,18 @@ before completing the apply.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -666,6 +679,18 @@ func resourceSaasRuntimeUnitOperationRead(d *schema.ResourceData, meta interface return fmt.Errorf("Error setting wait_for_completion: %s", err) } } + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading UnitOperation: %s", err) } @@ -703,11 +728,18 @@ func resourceSaasRuntimeUnitOperationRead(d *schema.ResourceData, meta interface } func resourceSaasRuntimeUnitOperationUpdate(d *schema.ResourceData, meta interface{}) error { - // Only the root field "labels", "terraform_labels", and virtual fields are mutable + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable return resourceSaasRuntimeUnitOperationRead(d, meta) } func resourceSaasRuntimeUnitOperationDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy SaasRuntimeUnitOperation without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing UnitOperation %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/saasruntime/resource_saas_runtime_unit_operation_generated_meta.yaml b/google-beta/services/saasruntime/resource_saas_runtime_unit_operation_generated_meta.yaml index db3b8297d46..c1a84b408a6 100644 --- a/google-beta/services/saasruntime/resource_saas_runtime_unit_operation_generated_meta.yaml +++ b/google-beta/services/saasruntime/resource_saas_runtime_unit_operation_generated_meta.yaml @@ -45,3 +45,5 @@ fields: - api_field: upgrade.release - field: wait_for_completion provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/secretmanager/data_source_secret_manager_secrets_test.go b/google-beta/services/secretmanager/data_source_secret_manager_secrets_test.go index e940383d198..2184625a2b9 100644 --- a/google-beta/services/secretmanager/data_source_secret_manager_secrets_test.go +++ b/google-beta/services/secretmanager/data_source_secret_manager_secrets_test.go @@ -46,8 +46,9 @@ func TestAccDataSourceSecretManagerSecrets_basic(t *testing.T) { "data.google_secret_manager_secrets.foo", "google_secret_manager_secret.foo", map[string]struct{}{ - "id": {}, - "project": {}, + "id": {}, + "project": {}, + "deletion_policy": {}, }, ), ), @@ -112,8 +113,9 @@ func TestAccDataSourceSecretManagerSecrets_filter(t *testing.T) { "google_secret_manager_secret.foo", "google_secret_manager_secret.bar", map[string]struct{}{ - "id": {}, - "project": {}, + "id": {}, + "project": {}, + "deletion_policy": {}, }, ), ), diff --git a/google-beta/services/secretmanager/resource_secret_manager_secret.go b/google-beta/services/secretmanager/resource_secret_manager_secret.go index c64b65f0efc..1919f1f95e6 100644 --- a/google-beta/services/secretmanager/resource_secret_manager_secret.go +++ b/google-beta/services/secretmanager/resource_secret_manager_secret.go @@ -144,6 +144,7 @@ func ResourceSecretManagerSecret() *schema.Resource { tpgresource.SetLabelsDiff, tpgresource.SetAnnotationsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -431,6 +432,18 @@ or 'terraform destroy' that would delete the secret will fail.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -613,6 +626,18 @@ func resourceSecretManagerSecretRead(d *schema.ResourceData, meta interface{}) e return fmt.Errorf("Error setting deletion_protection: %s", err) } } + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Secret: %s", err) } @@ -644,6 +669,19 @@ func resourceSecretManagerSecretRead(d *schema.ResourceData, meta interface{}) e } func resourceSecretManagerSecretUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceSecretManagerSecret().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceSecretManagerSecretRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -823,6 +861,13 @@ func resourceSecretManagerSecretUpdate(d *schema.ResourceData, meta interface{}) } func resourceSecretManagerSecretDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy SecretManagerSecret without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Secret %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/secretmanager/resource_secret_manager_secret_generated_meta.yaml b/google-beta/services/secretmanager/resource_secret_manager_secret_generated_meta.yaml index 1b16e2c9478..08a9fe2a7ee 100644 --- a/google-beta/services/secretmanager/resource_secret_manager_secret_generated_meta.yaml +++ b/google-beta/services/secretmanager/resource_secret_manager_secret_generated_meta.yaml @@ -35,3 +35,5 @@ fields: - api_field: ttl - api_field: versionAliases - api_field: versionDestroyTtl + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/secretmanager/resource_secret_manager_secret_version.go b/google-beta/services/secretmanager/resource_secret_manager_secret_version.go index 9097943e28f..e53d8ffdfb1 100644 --- a/google-beta/services/secretmanager/resource_secret_manager_secret_version.go +++ b/google-beta/services/secretmanager/resource_secret_manager_secret_version.go @@ -214,23 +214,19 @@ the provider project is used`, Computed: true, Description: `The version of the Secret.`, }, - "deletion_policy": { - Type: schema.TypeString, - Optional: true, - Description: `The deletion policy for the secret version. Setting 'ABANDON' allows the resource -to be abandoned rather than deleted. Setting 'DISABLE' allows the resource to be -disabled rather than deleted. Default is 'DELETE'. Possible values are: - * DELETE - * DISABLE - * ABANDON`, - Default: "DELETE", - }, "is_secret_data_base64": { Type: schema.TypeBool, Optional: true, ForceNew: true, Description: `If set to 'true', the secret data is expected to be base64-encoded string and would be sent as is.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `This field uses a custom implementation please refer to documentation under /hashicorp/terraform-provider-google-beta/website/docs/r/secret_manager_secret_version.html.markdown for specifics`, + }, }, UseJSONNumber: true, } @@ -405,8 +401,15 @@ func resourceSecretManagerSecretVersionRead(d *schema.ResourceData, meta interfa // Explicitly set virtual fields to default values if unset if _, ok := d.GetOkExists("deletion_policy"); !ok { - if err := d.Set("deletion_policy", "DELETE"); err != nil { - return fmt.Errorf("Error setting deletion_policy: %s", err) + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } } } @@ -419,6 +422,19 @@ func resourceSecretManagerSecretVersionRead(d *schema.ResourceData, meta interfa } func resourceSecretManagerSecretVersionUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceSecretManagerSecretVersion().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceSecretManagerSecretVersionRead(d, meta) + } + config := meta.(*transport_tpg.Config) err := setEnabled(d.Get("enabled"), d, config) if err != nil { @@ -429,6 +445,13 @@ func resourceSecretManagerSecretVersionUpdate(d *schema.ResourceData, meta inter } func resourceSecretManagerSecretVersionDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy SecretManagerSecretVersion without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing SecretVersion %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -451,10 +474,7 @@ func resourceSecretManagerSecretVersionDelete(d *schema.ResourceData, meta inter headers := make(http.Header) deletionPolicy := d.Get("deletion_policy") - - if deletionPolicy == "ABANDON" { - return nil - } else if deletionPolicy == "DISABLE" { + if deletionPolicy == "DISABLE" { url, err = tpgresource.ReplaceVars(d, config, "{{SecretManagerBasePath}}{{name}}:disable") if err != nil { return err diff --git a/google-beta/services/secretmanager/resource_secret_manager_secret_version_generated_meta.yaml b/google-beta/services/secretmanager/resource_secret_manager_secret_version_generated_meta.yaml index a52e94fd5c3..28be2471bdc 100644 --- a/google-beta/services/secretmanager/resource_secret_manager_secret_version_generated_meta.yaml +++ b/google-beta/services/secretmanager/resource_secret_manager_secret_version_generated_meta.yaml @@ -12,8 +12,6 @@ api_variant_patterns: - projects/{project}/secrets/{secret}/versions/{version} fields: - api_field: createTime - - field: deletion_policy - provider_only: true - api_field: destroyTime - api_field: state field: enabled @@ -31,3 +29,5 @@ fields: - field: secret_data_wo_version provider_only: true - api_field: version + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/secretmanagerregional/data_source_secret_manager_regional_secrets_test.go b/google-beta/services/secretmanagerregional/data_source_secret_manager_regional_secrets_test.go index 2465845d31d..b7821754d87 100644 --- a/google-beta/services/secretmanagerregional/data_source_secret_manager_regional_secrets_test.go +++ b/google-beta/services/secretmanagerregional/data_source_secret_manager_regional_secrets_test.go @@ -47,8 +47,9 @@ func TestAccDataSourceSecretManagerRegionalRegionalSecrets_basic(t *testing.T) { "data.google_secret_manager_regional_secrets.foo", "google_secret_manager_regional_secret.foo", map[string]struct{}{ - "id": {}, - "project": {}, + "id": {}, + "project": {}, + "deletion_policy": {}, }, ), ), @@ -105,8 +106,9 @@ func TestAccDataSourceSecretManagerRegionalRegionalSecrets_filter(t *testing.T) "google_secret_manager_regional_secret.foo", "google_secret_manager_regional_secret.bar", map[string]struct{}{ - "id": {}, - "project": {}, + "id": {}, + "project": {}, + "deletion_policy": {}, }, ), ), diff --git a/google-beta/services/secretmanagerregional/resource_secret_manager_regional_secret.go b/google-beta/services/secretmanagerregional/resource_secret_manager_regional_secret.go index 6efbd30d7b2..5c4efed8f1f 100644 --- a/google-beta/services/secretmanagerregional/resource_secret_manager_regional_secret.go +++ b/google-beta/services/secretmanagerregional/resource_secret_manager_regional_secret.go @@ -117,6 +117,7 @@ func ResourceSecretManagerRegionalRegionalSecret() *schema.Resource { tpgresource.SetLabelsDiff, tpgresource.SetAnnotationsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -351,6 +352,18 @@ or 'terraform destroy' that would delete the federation will fail.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -538,6 +551,18 @@ func resourceSecretManagerRegionalRegionalSecretRead(d *schema.ResourceData, met return fmt.Errorf("Error setting deletion_protection: %s", err) } } + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading RegionalSecret: %s", err) } @@ -575,6 +600,19 @@ func resourceSecretManagerRegionalRegionalSecretRead(d *schema.ResourceData, met } func resourceSecretManagerRegionalRegionalSecretUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceSecretManagerRegionalRegionalSecret().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceSecretManagerRegionalRegionalSecretRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -750,6 +788,13 @@ func resourceSecretManagerRegionalRegionalSecretUpdate(d *schema.ResourceData, m } func resourceSecretManagerRegionalRegionalSecretDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy SecretManagerRegionalRegionalSecret without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing RegionalSecret %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/secretmanagerregional/resource_secret_manager_regional_secret_generated_meta.yaml b/google-beta/services/secretmanagerregional/resource_secret_manager_regional_secret_generated_meta.yaml index 2c9a330bbdc..e20b6c533ad 100644 --- a/google-beta/services/secretmanagerregional/resource_secret_manager_regional_secret_generated_meta.yaml +++ b/google-beta/services/secretmanagerregional/resource_secret_manager_regional_secret_generated_meta.yaml @@ -32,3 +32,5 @@ fields: - api_field: ttl - api_field: versionAliases - api_field: versionDestroyTtl + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/secretmanagerregional/resource_secret_manager_regional_secret_version.go b/google-beta/services/secretmanagerregional/resource_secret_manager_regional_secret_version.go index 91cfb33f0fc..2548a665680 100644 --- a/google-beta/services/secretmanagerregional/resource_secret_manager_regional_secret_version.go +++ b/google-beta/services/secretmanagerregional/resource_secret_manager_regional_secret_version.go @@ -209,23 +209,19 @@ func ResourceSecretManagerRegionalRegionalSecretVersion() *schema.Resource { Computed: true, Description: `The version of the Regional Secret.`, }, - "deletion_policy": { - Type: schema.TypeString, - Optional: true, - Description: `The deletion policy for the regional secret version. Setting 'ABANDON' allows the resource -to be abandoned rather than deleted. Setting 'DISABLE' allows the resource to be -disabled rather than deleted. Default is 'DELETE'. Possible values are: - * DELETE - * DISABLE - * ABANDON`, - Default: "DELETE", - }, "is_secret_data_base64": { Type: schema.TypeBool, Optional: true, ForceNew: true, Description: `If set to 'true', the secret data is expected to be base64-encoded string and would be sent as is.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `This field uses a custom implementation please refer to documentation under /hashicorp/terraform-provider-google-beta/website/docs/r/secret_manager_regional_regional_secret_version.html.markdown for specifics`, + }, }, UseJSONNumber: true, } @@ -402,8 +398,15 @@ func resourceSecretManagerRegionalRegionalSecretVersionRead(d *schema.ResourceDa // Explicitly set virtual fields to default values if unset if _, ok := d.GetOkExists("deletion_policy"); !ok { - if err := d.Set("deletion_policy", "DELETE"); err != nil { - return fmt.Errorf("Error setting deletion_policy: %s", err) + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } } } @@ -416,6 +419,19 @@ func resourceSecretManagerRegionalRegionalSecretVersionRead(d *schema.ResourceDa } func resourceSecretManagerRegionalRegionalSecretVersionUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceSecretManagerRegionalRegionalSecretVersion().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceSecretManagerRegionalRegionalSecretVersionRead(d, meta) + } + config := meta.(*transport_tpg.Config) err := setEnabled(d.Get("enabled"), d, config) if err != nil { @@ -426,6 +442,13 @@ func resourceSecretManagerRegionalRegionalSecretVersionUpdate(d *schema.Resource } func resourceSecretManagerRegionalRegionalSecretVersionDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy SecretManagerRegionalRegionalSecretVersion without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing RegionalSecretVersion %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -449,9 +472,7 @@ func resourceSecretManagerRegionalRegionalSecretVersionDelete(d *schema.Resource headers := make(http.Header) deletionPolicy := d.Get("deletion_policy") - if deletionPolicy == "ABANDON" { - return nil - } else if deletionPolicy == "DISABLE" { + if deletionPolicy == "DISABLE" { url, err = tpgresource.ReplaceVars(d, config, "{{SecretManagerRegionalBasePath}}{{name}}:disable") if err != nil { return err diff --git a/google-beta/services/secretmanagerregional/resource_secret_manager_regional_secret_version_generated_meta.yaml b/google-beta/services/secretmanagerregional/resource_secret_manager_regional_secret_version_generated_meta.yaml index b2bedf8668f..2c1c1886189 100644 --- a/google-beta/services/secretmanagerregional/resource_secret_manager_regional_secret_version_generated_meta.yaml +++ b/google-beta/services/secretmanagerregional/resource_secret_manager_regional_secret_version_generated_meta.yaml @@ -11,8 +11,6 @@ cai_asset_name_formats: fields: - api_field: createTime - api_field: customerManagedEncryption.kmsKeyVersionName - - field: deletion_policy - provider_only: true - api_field: destroyTime - api_field: state field: enabled @@ -26,3 +24,5 @@ fields: - api_field: payload.data field: secret_data - api_field: version + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/securesourcemanager/resource_secure_source_manager_branch_rule.go b/google-beta/services/securesourcemanager/resource_secure_source_manager_branch_rule.go index 1f670643593..2a3e4065a55 100644 --- a/google-beta/services/securesourcemanager/resource_secure_source_manager_branch_rule.go +++ b/google-beta/services/securesourcemanager/resource_secure_source_manager_branch_rule.go @@ -115,6 +115,7 @@ func ResourceSecureSourceManagerBranchRule() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -226,6 +227,18 @@ func ResourceSecureSourceManagerBranchRule() *schema.Resource { Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -410,6 +423,19 @@ func resourceSecureSourceManagerBranchRuleRead(d *schema.ResourceData, meta inte log.Printf("[DEBUG] Finished reading SecureSourceManagerBranchRule %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading BranchRule: %s", err) } @@ -453,6 +479,19 @@ func resourceSecureSourceManagerBranchRuleRead(d *schema.ResourceData, meta inte } func resourceSecureSourceManagerBranchRuleUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceSecureSourceManagerBranchRule().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceSecureSourceManagerBranchRuleRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -619,6 +658,13 @@ func resourceSecureSourceManagerBranchRuleUpdate(d *schema.ResourceData, meta in } func resourceSecureSourceManagerBranchRuleDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy SecureSourceManagerBranchRule without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing BranchRule %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/securesourcemanager/resource_secure_source_manager_branch_rule_generated_meta.yaml b/google-beta/services/securesourcemanager/resource_secure_source_manager_branch_rule_generated_meta.yaml index 9f0b1b3403b..6c27e0c737c 100644 --- a/google-beta/services/securesourcemanager/resource_secure_source_manager_branch_rule_generated_meta.yaml +++ b/google-beta/services/securesourcemanager/resource_secure_source_manager_branch_rule_generated_meta.yaml @@ -25,3 +25,5 @@ fields: - api_field: requirePullRequest - api_field: uid - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/securesourcemanager/resource_secure_source_manager_hook.go b/google-beta/services/securesourcemanager/resource_secure_source_manager_hook.go index 2c0039a781a..1c09b9446f1 100644 --- a/google-beta/services/securesourcemanager/resource_secure_source_manager_hook.go +++ b/google-beta/services/securesourcemanager/resource_secure_source_manager_hook.go @@ -115,6 +115,7 @@ func ResourceSecureSourceManagerHook() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -233,6 +234,18 @@ See https://pkg.go.dev/github.com/gobwas/glob documentation.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -399,6 +412,19 @@ func resourceSecureSourceManagerHookRead(d *schema.ResourceData, meta interface{ log.Printf("[DEBUG] Finished reading SecureSourceManagerHook %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Hook: %s", err) } @@ -442,6 +468,19 @@ func resourceSecureSourceManagerHookRead(d *schema.ResourceData, meta interface{ } func resourceSecureSourceManagerHookUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceSecureSourceManagerHook().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceSecureSourceManagerHookRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -578,6 +617,13 @@ func resourceSecureSourceManagerHookUpdate(d *schema.ResourceData, meta interfac } func resourceSecureSourceManagerHookDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy SecureSourceManagerHook without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Hook %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/securesourcemanager/resource_secure_source_manager_hook_generated_meta.yaml b/google-beta/services/securesourcemanager/resource_secure_source_manager_hook_generated_meta.yaml index c3a35816686..87b297b785f 100644 --- a/google-beta/services/securesourcemanager/resource_secure_source_manager_hook_generated_meta.yaml +++ b/google-beta/services/securesourcemanager/resource_secure_source_manager_hook_generated_meta.yaml @@ -22,3 +22,5 @@ fields: - api_field: targetUri - api_field: uid - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/securesourcemanager/resource_secure_source_manager_instance.go b/google-beta/services/securesourcemanager/resource_secure_source_manager_instance.go index ebf2d48aa29..775f3fea740 100644 --- a/google-beta/services/securesourcemanager/resource_secure_source_manager_instance.go +++ b/google-beta/services/securesourcemanager/resource_secure_source_manager_instance.go @@ -116,6 +116,7 @@ func ResourceSecureSourceManagerInstance() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("PREVENT"), ), Identity: &schema.ResourceIdentity{ @@ -324,24 +325,23 @@ If unset, defaults to the Google OIDC IdP.`, Computed: true, Description: `Time the Instance was updated in UTC.`, }, - "deletion_policy": { + "project": { Type: schema.TypeString, Optional: true, - Description: `The deletion policy for the instance. Setting 'ABANDON' allows the resource -to be abandoned, rather than deleted. Setting 'DELETE' deletes the resource -and all its contents. Setting 'PREVENT' prevents the resource from accidental -deletion by erroring out during plan. -Default is 'PREVENT'. Possible values are: - * DELETE - * PREVENT - * ABANDON`, - Default: "PREVENT", + Computed: true, + ForceNew: true, }, - "project": { + "deletion_policy": { Type: schema.TypeString, Optional: true, Computed: true, - ForceNew: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "PREVENT". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, }, }, UseJSONNumber: true, @@ -500,8 +500,15 @@ func resourceSecureSourceManagerInstanceRead(d *schema.ResourceData, meta interf // Explicitly set virtual fields to default values if unset if _, ok := d.GetOkExists("deletion_policy"); !ok { - if err := d.Set("deletion_policy", "PREVENT"); err != nil { - return fmt.Errorf("Error setting deletion_policy: %s", err) + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "PREVENT"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } } } if err := d.Set("project", project); err != nil { @@ -541,11 +548,18 @@ func resourceSecureSourceManagerInstanceRead(d *schema.ResourceData, meta interf } func resourceSecureSourceManagerInstanceUpdate(d *schema.ResourceData, meta interface{}) error { - // Only the root field "labels", "terraform_labels", and virtual fields are mutable + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable return resourceSecureSourceManagerInstanceRead(d, meta) } func resourceSecureSourceManagerInstanceDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy SecureSourceManagerInstance without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Instance %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -625,11 +639,6 @@ func resourceSecureSourceManagerInstanceImport(d *schema.ResourceData, meta inte } d.SetId(id) - // Explicitly set virtual fields to default values on import - if err := d.Set("deletion_policy", "PREVENT"); err != nil { - return nil, fmt.Errorf("Error setting deletion_policy: %s", err) - } - return []*schema.ResourceData{d}, nil } diff --git a/google-beta/services/securesourcemanager/resource_secure_source_manager_instance_generated_meta.yaml b/google-beta/services/securesourcemanager/resource_secure_source_manager_instance_generated_meta.yaml index 00f3eb6f15b..2957d9c2050 100644 --- a/google-beta/services/securesourcemanager/resource_secure_source_manager_instance_generated_meta.yaml +++ b/google-beta/services/securesourcemanager/resource_secure_source_manager_instance_generated_meta.yaml @@ -8,8 +8,6 @@ api_version: v1 api_resource_type_kind: Instance fields: - api_field: createTime - - field: deletion_policy - provider_only: true - field: effective_labels provider_only: true - api_field: hostConfig.api @@ -37,3 +35,5 @@ fields: provider_only: true - api_field: updateTime - api_field: workforceIdentityFederationConfig.enabled + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/securesourcemanager/resource_secure_source_manager_repository.go b/google-beta/services/securesourcemanager/resource_secure_source_manager_repository.go index 8fc936b8fe2..5a38e993a2d 100644 --- a/google-beta/services/securesourcemanager/resource_secure_source_manager_repository.go +++ b/google-beta/services/securesourcemanager/resource_secure_source_manager_repository.go @@ -115,6 +115,7 @@ func ResourceSecureSourceManagerRepository() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("PREVENT"), ), Identity: &schema.ResourceIdentity{ @@ -250,24 +251,23 @@ Valid values can be viewed at https://cloud.google.com/secure-source-manager/doc }, }, }, - "deletion_policy": { + "project": { Type: schema.TypeString, Optional: true, - Description: `The deletion policy for the repository. Setting 'ABANDON' allows the resource -to be abandoned, rather than deleted. Setting 'DELETE' deletes the resource -and all its contents. Setting 'PREVENT' prevents the resource from accidental deletion -by erroring out during plan. -Default is 'PREVENT'. Possible values are: - * DELETE - * PREVENT - * ABANDON`, - Default: "PREVENT", + Computed: true, + ForceNew: true, }, - "project": { + "deletion_policy": { Type: schema.TypeString, Optional: true, Computed: true, - ForceNew: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "PREVENT". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, }, }, UseJSONNumber: true, @@ -420,8 +420,15 @@ func resourceSecureSourceManagerRepositoryRead(d *schema.ResourceData, meta inte // Explicitly set virtual fields to default values if unset if _, ok := d.GetOkExists("deletion_policy"); !ok { - if err := d.Set("deletion_policy", "PREVENT"); err != nil { - return fmt.Errorf("Error setting deletion_policy: %s", err) + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "PREVENT"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } } } if err := d.Set("project", project); err != nil { @@ -461,6 +468,19 @@ func resourceSecureSourceManagerRepositoryRead(d *schema.ResourceData, meta inte } func resourceSecureSourceManagerRepositoryUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceSecureSourceManagerRepository().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceSecureSourceManagerRepositoryRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -559,6 +579,13 @@ func resourceSecureSourceManagerRepositoryUpdate(d *schema.ResourceData, meta in } func resourceSecureSourceManagerRepositoryDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy SecureSourceManagerRepository without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Repository %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -585,13 +612,6 @@ func resourceSecureSourceManagerRepositoryDelete(d *schema.ResourceData, meta in } headers := make(http.Header) - deletionPolicy := d.Get("deletion_policy") - - if deletionPolicy == "ABANDON" { - return nil - } else if deletionPolicy == "PREVENT" { - return fmt.Errorf(`cannot destroy resource without setting deletion_policy="DELETE"`) - } log.Printf("[DEBUG] Deleting Repository %q", d.Id()) res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ @@ -638,11 +658,6 @@ func resourceSecureSourceManagerRepositoryImport(d *schema.ResourceData, meta in } d.SetId(id) - // Explicitly set virtual fields to default values on import - if err := d.Set("deletion_policy", "PREVENT"); err != nil { - return nil, fmt.Errorf("Error setting deletion_policy: %s", err) - } - return []*schema.ResourceData{d}, nil } diff --git a/google-beta/services/securesourcemanager/resource_secure_source_manager_repository_generated_meta.yaml b/google-beta/services/securesourcemanager/resource_secure_source_manager_repository_generated_meta.yaml index 1fbbd1d4239..75a96624cb4 100644 --- a/google-beta/services/securesourcemanager/resource_secure_source_manager_repository_generated_meta.yaml +++ b/google-beta/services/securesourcemanager/resource_secure_source_manager_repository_generated_meta.yaml @@ -8,8 +8,6 @@ api_version: v1 api_resource_type_kind: Repository fields: - api_field: createTime - - field: deletion_policy - provider_only: true - api_field: description - api_field: initialConfig.defaultBranch - api_field: initialConfig.gitignores @@ -26,3 +24,5 @@ fields: - api_field: uris.api - api_field: uris.gitHttps - api_field: uris.html + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/securitycenter/resource_scc_event_threat_detection_custom_module.go b/google-beta/services/securitycenter/resource_scc_event_threat_detection_custom_module.go index e2ceb006f91..ba0fd6e0d49 100644 --- a/google-beta/services/securitycenter/resource_scc_event_threat_detection_custom_module.go +++ b/google-beta/services/securitycenter/resource_scc_event_threat_detection_custom_module.go @@ -183,6 +183,19 @@ Its format is "organizations/{organization}/eventThreatDetectionSettings/customM A timestamp in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine fractional digits. Examples: "2014-10-02T15:01:23Z" and "2014-10-02T15:01:23.045123456Z".`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -324,6 +337,20 @@ func resourceSecurityCenterEventThreatDetectionCustomModuleRead(d *schema.Resour log.Printf("[DEBUG] Finished reading SecurityCenterEventThreatDetectionCustomModule %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceSecurityCenterEventThreatDetectionCustomModuleFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -351,6 +378,19 @@ func resourceSecurityCenterEventThreatDetectionCustomModuleRead(d *schema.Resour } func resourceSecurityCenterEventThreatDetectionCustomModuleUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceSecurityCenterEventThreatDetectionCustomModule().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceSecurityCenterEventThreatDetectionCustomModuleRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -458,6 +498,13 @@ func resourceSecurityCenterEventThreatDetectionCustomModuleUpdate(d *schema.Reso } func resourceSecurityCenterEventThreatDetectionCustomModuleDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy SecurityCenterEventThreatDetectionCustomModule without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing EventThreatDetectionCustomModule %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/securitycenter/resource_scc_event_threat_detection_custom_module_generated_meta.yaml b/google-beta/services/securitycenter/resource_scc_event_threat_detection_custom_module_generated_meta.yaml index 42cdd43406d..5136f4a78f5 100644 --- a/google-beta/services/securitycenter/resource_scc_event_threat_detection_custom_module_generated_meta.yaml +++ b/google-beta/services/securitycenter/resource_scc_event_threat_detection_custom_module_generated_meta.yaml @@ -19,3 +19,5 @@ fields: provider_only: true - api_field: type - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/securitycenter/resource_scc_folder_custom_module.go b/google-beta/services/securitycenter/resource_scc_folder_custom_module.go index 8ce5a6e2303..682efd11d3a 100644 --- a/google-beta/services/securitycenter/resource_scc_folder_custom_module.go +++ b/google-beta/services/securitycenter/resource_scc_folder_custom_module.go @@ -323,6 +323,19 @@ The id {customModule} is server-generated and is not user settable. It will be a A timestamp in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine fractional digits. Examples: "2014-10-02T15:01:23Z" and "2014-10-02T15:01:23.045123456Z".`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -458,6 +471,20 @@ func resourceSecurityCenterFolderCustomModuleRead(d *schema.ResourceData, meta i log.Printf("[DEBUG] Finished reading SecurityCenterFolderCustomModule %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceSecurityCenterFolderCustomModuleFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -485,6 +512,19 @@ func resourceSecurityCenterFolderCustomModuleRead(d *schema.ResourceData, meta i } func resourceSecurityCenterFolderCustomModuleUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceSecurityCenterFolderCustomModule().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceSecurityCenterFolderCustomModuleRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -582,6 +622,13 @@ func resourceSecurityCenterFolderCustomModuleUpdate(d *schema.ResourceData, meta } func resourceSecurityCenterFolderCustomModuleDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy SecurityCenterFolderCustomModule without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing FolderCustomModule %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/securitycenter/resource_scc_folder_custom_module_generated_meta.yaml b/google-beta/services/securitycenter/resource_scc_folder_custom_module_generated_meta.yaml index e748be6d82b..6690572d1f7 100644 --- a/google-beta/services/securitycenter/resource_scc_folder_custom_module_generated_meta.yaml +++ b/google-beta/services/securitycenter/resource_scc_folder_custom_module_generated_meta.yaml @@ -30,3 +30,5 @@ fields: - api_field: lastEditor - api_field: name - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/securitycenter/resource_scc_folder_notification_config.go b/google-beta/services/securitycenter/resource_scc_folder_notification_config.go index ab18d5f40f7..3b7bf67fe2b 100644 --- a/google-beta/services/securitycenter/resource_scc_folder_notification_config.go +++ b/google-beta/services/securitycenter/resource_scc_folder_notification_config.go @@ -208,6 +208,19 @@ for information on how to write a filter.`, Description: `The service account that needs "pubsub.topics.publish" permission to publish to the Pub/Sub topic.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -330,6 +343,20 @@ func resourceSecurityCenterFolderNotificationConfigRead(d *schema.ResourceData, log.Printf("[DEBUG] Finished reading SecurityCenterFolderNotificationConfig %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceSecurityCenterFolderNotificationConfigFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -357,6 +384,19 @@ func resourceSecurityCenterFolderNotificationConfigRead(d *schema.ResourceData, } func resourceSecurityCenterFolderNotificationConfigUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceSecurityCenterFolderNotificationConfig().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceSecurityCenterFolderNotificationConfigRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -457,6 +497,13 @@ func resourceSecurityCenterFolderNotificationConfigUpdate(d *schema.ResourceData } func resourceSecurityCenterFolderNotificationConfigDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy SecurityCenterFolderNotificationConfig without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing FolderNotificationConfig %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/securitycenter/resource_scc_folder_notification_config_generated_meta.yaml b/google-beta/services/securitycenter/resource_scc_folder_notification_config_generated_meta.yaml index 50fe149bfcc..ca57ff34abe 100644 --- a/google-beta/services/securitycenter/resource_scc_folder_notification_config_generated_meta.yaml +++ b/google-beta/services/securitycenter/resource_scc_folder_notification_config_generated_meta.yaml @@ -18,3 +18,5 @@ fields: - api_field: pubsubTopic - api_field: serviceAccount - api_field: streamingConfig.filter + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/securitycenter/resource_scc_folder_scc_big_query_export.go b/google-beta/services/securitycenter/resource_scc_folder_scc_big_query_export.go index c382a2fd953..5bc6abdeeab 100644 --- a/google-beta/services/securitycenter/resource_scc_folder_scc_big_query_export.go +++ b/google-beta/services/securitycenter/resource_scc_folder_scc_big_query_export.go @@ -219,6 +219,19 @@ This field is provided in responses, and is ignored when provided in create requ A timestamp in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine fractional digits. Examples: "2014-10-02T15:01:23Z" and "2014-10-02T15:01:23.045123456Z".`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -341,6 +354,20 @@ func resourceSecurityCenterFolderSccBigQueryExportRead(d *schema.ResourceData, m log.Printf("[DEBUG] Finished reading SecurityCenterFolderSccBigQueryExport %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceSecurityCenterFolderSccBigQueryExportFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -368,6 +395,19 @@ func resourceSecurityCenterFolderSccBigQueryExportRead(d *schema.ResourceData, m } func resourceSecurityCenterFolderSccBigQueryExportUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceSecurityCenterFolderSccBigQueryExport().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceSecurityCenterFolderSccBigQueryExportRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -468,6 +508,13 @@ func resourceSecurityCenterFolderSccBigQueryExportUpdate(d *schema.ResourceData, } func resourceSecurityCenterFolderSccBigQueryExportDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy SecurityCenterFolderSccBigQueryExport without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing FolderSccBigQueryExport %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/securitycenter/resource_scc_folder_scc_big_query_export_generated_meta.yaml b/google-beta/services/securitycenter/resource_scc_folder_scc_big_query_export_generated_meta.yaml index d1b9c0d48a3..b83e9972f6a 100644 --- a/google-beta/services/securitycenter/resource_scc_folder_scc_big_query_export_generated_meta.yaml +++ b/google-beta/services/securitycenter/resource_scc_folder_scc_big_query_export_generated_meta.yaml @@ -21,3 +21,5 @@ fields: - api_field: name - api_field: principal - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/securitycenter/resource_scc_mute_config.go b/google-beta/services/securitycenter/resource_scc_mute_config.go index 2e71440ade6..11b05f68d67 100644 --- a/google-beta/services/securitycenter/resource_scc_mute_config.go +++ b/google-beta/services/securitycenter/resource_scc_mute_config.go @@ -201,6 +201,19 @@ or projects/{project}/muteConfigs/{configId}`, updated. This field is set by the server and will be ignored if provided on config creation or update.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -330,6 +343,20 @@ func resourceSecurityCenterMuteConfigRead(d *schema.ResourceData, meta interface log.Printf("[DEBUG] Finished reading SecurityCenterMuteConfig %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceSecurityCenterMuteConfigFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -351,6 +378,19 @@ func resourceSecurityCenterMuteConfigRead(d *schema.ResourceData, meta interface } func resourceSecurityCenterMuteConfigUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceSecurityCenterMuteConfig().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceSecurityCenterMuteConfigRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -456,6 +496,13 @@ func resourceSecurityCenterMuteConfigUpdate(d *schema.ResourceData, meta interfa } func resourceSecurityCenterMuteConfigDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy SecurityCenterMuteConfig without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing MuteConfig %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/securitycenter/resource_scc_mute_config_generated_meta.yaml b/google-beta/services/securitycenter/resource_scc_mute_config_generated_meta.yaml index e075b2ae235..9b4e3363f1c 100644 --- a/google-beta/services/securitycenter/resource_scc_mute_config_generated_meta.yaml +++ b/google-beta/services/securitycenter/resource_scc_mute_config_generated_meta.yaml @@ -23,3 +23,5 @@ fields: provider_only: true - api_field: type - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/securitycenter/resource_scc_notification_config.go b/google-beta/services/securitycenter/resource_scc_notification_config.go index 5cbbacdfb4b..e022f59c021 100644 --- a/google-beta/services/securitycenter/resource_scc_notification_config.go +++ b/google-beta/services/securitycenter/resource_scc_notification_config.go @@ -190,6 +190,19 @@ for information on how to write a filter.`, Description: `The service account that needs "pubsub.topics.publish" permission to publish to the Pub/Sub topic.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -302,6 +315,20 @@ func resourceSecurityCenterNotificationConfigRead(d *schema.ResourceData, meta i log.Printf("[DEBUG] Finished reading SecurityCenterNotificationConfig %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceSecurityCenterNotificationConfigFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -311,6 +338,19 @@ func resourceSecurityCenterNotificationConfigRead(d *schema.ResourceData, meta i } func resourceSecurityCenterNotificationConfigUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceSecurityCenterNotificationConfig().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceSecurityCenterNotificationConfigRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -396,6 +436,13 @@ func resourceSecurityCenterNotificationConfigUpdate(d *schema.ResourceData, meta } func resourceSecurityCenterNotificationConfigDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy SecurityCenterNotificationConfig without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing NotificationConfig %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/securitycenter/resource_scc_notification_config_generated_meta.yaml b/google-beta/services/securitycenter/resource_scc_notification_config_generated_meta.yaml index c7e82ed03c7..79a8fdb7a72 100644 --- a/google-beta/services/securitycenter/resource_scc_notification_config_generated_meta.yaml +++ b/google-beta/services/securitycenter/resource_scc_notification_config_generated_meta.yaml @@ -18,3 +18,5 @@ fields: - api_field: pubsubTopic - api_field: serviceAccount - api_field: streamingConfig.filter + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/securitycenter/resource_scc_organization_custom_module.go b/google-beta/services/securitycenter/resource_scc_organization_custom_module.go index 5a7784e80b5..8a717a7cd2b 100644 --- a/google-beta/services/securitycenter/resource_scc_organization_custom_module.go +++ b/google-beta/services/securitycenter/resource_scc_organization_custom_module.go @@ -323,6 +323,19 @@ The id {customModule} is server-generated and is not user settable. It will be a A timestamp in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine fractional digits. Examples: "2014-10-02T15:01:23Z" and "2014-10-02T15:01:23.045123456Z".`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -458,6 +471,20 @@ func resourceSecurityCenterOrganizationCustomModuleRead(d *schema.ResourceData, log.Printf("[DEBUG] Finished reading SecurityCenterOrganizationCustomModule %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceSecurityCenterOrganizationCustomModuleFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -485,6 +512,19 @@ func resourceSecurityCenterOrganizationCustomModuleRead(d *schema.ResourceData, } func resourceSecurityCenterOrganizationCustomModuleUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceSecurityCenterOrganizationCustomModule().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceSecurityCenterOrganizationCustomModuleRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -582,6 +622,13 @@ func resourceSecurityCenterOrganizationCustomModuleUpdate(d *schema.ResourceData } func resourceSecurityCenterOrganizationCustomModuleDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy SecurityCenterOrganizationCustomModule without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing OrganizationCustomModule %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/securitycenter/resource_scc_organization_custom_module_generated_meta.yaml b/google-beta/services/securitycenter/resource_scc_organization_custom_module_generated_meta.yaml index b943c97dccd..81ec1adcdb5 100644 --- a/google-beta/services/securitycenter/resource_scc_organization_custom_module_generated_meta.yaml +++ b/google-beta/services/securitycenter/resource_scc_organization_custom_module_generated_meta.yaml @@ -30,3 +30,5 @@ fields: - field: organization provider_only: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/securitycenter/resource_scc_organization_scc_big_query_export.go b/google-beta/services/securitycenter/resource_scc_organization_scc_big_query_export.go index 9d2fefa4b68..d24457f193a 100644 --- a/google-beta/services/securitycenter/resource_scc_organization_scc_big_query_export.go +++ b/google-beta/services/securitycenter/resource_scc_organization_scc_big_query_export.go @@ -220,6 +220,19 @@ This field is provided in responses, and is ignored when provided in create requ A timestamp in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine fractional digits. Examples: "2014-10-02T15:01:23Z" and "2014-10-02T15:01:23.045123456Z".`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -342,6 +355,20 @@ func resourceSecurityCenterOrganizationSccBigQueryExportRead(d *schema.ResourceD log.Printf("[DEBUG] Finished reading SecurityCenterOrganizationSccBigQueryExport %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceSecurityCenterOrganizationSccBigQueryExportFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -369,6 +396,19 @@ func resourceSecurityCenterOrganizationSccBigQueryExportRead(d *schema.ResourceD } func resourceSecurityCenterOrganizationSccBigQueryExportUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceSecurityCenterOrganizationSccBigQueryExport().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceSecurityCenterOrganizationSccBigQueryExportRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -469,6 +509,13 @@ func resourceSecurityCenterOrganizationSccBigQueryExportUpdate(d *schema.Resourc } func resourceSecurityCenterOrganizationSccBigQueryExportDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy SecurityCenterOrganizationSccBigQueryExport without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing OrganizationSccBigQueryExport %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/securitycenter/resource_scc_organization_scc_big_query_export_generated_meta.yaml b/google-beta/services/securitycenter/resource_scc_organization_scc_big_query_export_generated_meta.yaml index 7fae62348c6..6e04e50b85e 100644 --- a/google-beta/services/securitycenter/resource_scc_organization_scc_big_query_export_generated_meta.yaml +++ b/google-beta/services/securitycenter/resource_scc_organization_scc_big_query_export_generated_meta.yaml @@ -21,3 +21,5 @@ fields: provider_only: true - api_field: principal - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/securitycenter/resource_scc_project_custom_module.go b/google-beta/services/securitycenter/resource_scc_project_custom_module.go index 323ba420f97..3ce177b251b 100644 --- a/google-beta/services/securitycenter/resource_scc_project_custom_module.go +++ b/google-beta/services/securitycenter/resource_scc_project_custom_module.go @@ -115,6 +115,7 @@ func ResourceSecurityCenterProjectCustomModule() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -327,6 +328,18 @@ up to nine fractional digits. Examples: "2014-10-02T15:01:23Z" and "2014-10-02T1 Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -474,6 +487,19 @@ func resourceSecurityCenterProjectCustomModuleRead(d *schema.ResourceData, meta log.Printf("[DEBUG] Finished reading SecurityCenterProjectCustomModule %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading ProjectCustomModule: %s", err) } @@ -505,6 +531,19 @@ func resourceSecurityCenterProjectCustomModuleRead(d *schema.ResourceData, meta } func resourceSecurityCenterProjectCustomModuleUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceSecurityCenterProjectCustomModule().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceSecurityCenterProjectCustomModuleRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -608,6 +647,13 @@ func resourceSecurityCenterProjectCustomModuleUpdate(d *schema.ResourceData, met } func resourceSecurityCenterProjectCustomModuleDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy SecurityCenterProjectCustomModule without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing ProjectCustomModule %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/securitycenter/resource_scc_project_custom_module_generated_meta.yaml b/google-beta/services/securitycenter/resource_scc_project_custom_module_generated_meta.yaml index ceadd2befec..7813831ba08 100644 --- a/google-beta/services/securitycenter/resource_scc_project_custom_module_generated_meta.yaml +++ b/google-beta/services/securitycenter/resource_scc_project_custom_module_generated_meta.yaml @@ -28,3 +28,5 @@ fields: - api_field: lastEditor - api_field: name - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/securitycenter/resource_scc_project_notification_config.go b/google-beta/services/securitycenter/resource_scc_project_notification_config.go index 4cb7b91762d..a0ca4b8ff7c 100644 --- a/google-beta/services/securitycenter/resource_scc_project_notification_config.go +++ b/google-beta/services/securitycenter/resource_scc_project_notification_config.go @@ -115,6 +115,7 @@ func ResourceSecurityCenterProjectNotificationConfig() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Schema: map[string]*schema.Schema{ @@ -193,6 +194,18 @@ publish to the Pub/Sub topic.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -317,6 +330,19 @@ func resourceSecurityCenterProjectNotificationConfigRead(d *schema.ResourceData, log.Printf("[DEBUG] Finished reading SecurityCenterProjectNotificationConfig %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading ProjectNotificationConfig: %s", err) } @@ -330,6 +356,19 @@ func resourceSecurityCenterProjectNotificationConfigRead(d *schema.ResourceData, } func resourceSecurityCenterProjectNotificationConfigUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceSecurityCenterProjectNotificationConfig().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceSecurityCenterProjectNotificationConfigRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -421,6 +460,13 @@ func resourceSecurityCenterProjectNotificationConfigUpdate(d *schema.ResourceDat } func resourceSecurityCenterProjectNotificationConfigDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy SecurityCenterProjectNotificationConfig without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing ProjectNotificationConfig %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/securitycenter/resource_scc_project_notification_config_generated_meta.yaml b/google-beta/services/securitycenter/resource_scc_project_notification_config_generated_meta.yaml index 1b5ad929b3e..30411bbcf1c 100644 --- a/google-beta/services/securitycenter/resource_scc_project_notification_config_generated_meta.yaml +++ b/google-beta/services/securitycenter/resource_scc_project_notification_config_generated_meta.yaml @@ -16,3 +16,5 @@ fields: - api_field: pubsubTopic - api_field: serviceAccount - api_field: streamingConfig.filter + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/securitycenter/resource_scc_project_scc_big_query_export.go b/google-beta/services/securitycenter/resource_scc_project_scc_big_query_export.go index c3308e1a03d..f9c53e8e854 100644 --- a/google-beta/services/securitycenter/resource_scc_project_scc_big_query_export.go +++ b/google-beta/services/securitycenter/resource_scc_project_scc_big_query_export.go @@ -115,6 +115,7 @@ func ResourceSecurityCenterProjectSccBigQueryExport() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -223,6 +224,18 @@ Examples: "2014-10-02T15:01:23Z" and "2014-10-02T15:01:23.045123456Z".`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -357,6 +370,19 @@ func resourceSecurityCenterProjectSccBigQueryExportRead(d *schema.ResourceData, log.Printf("[DEBUG] Finished reading SecurityCenterProjectSccBigQueryExport %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading ProjectSccBigQueryExport: %s", err) } @@ -388,6 +414,19 @@ func resourceSecurityCenterProjectSccBigQueryExportRead(d *schema.ResourceData, } func resourceSecurityCenterProjectSccBigQueryExportUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceSecurityCenterProjectSccBigQueryExport().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceSecurityCenterProjectSccBigQueryExportRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -494,6 +533,13 @@ func resourceSecurityCenterProjectSccBigQueryExportUpdate(d *schema.ResourceData } func resourceSecurityCenterProjectSccBigQueryExportDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy SecurityCenterProjectSccBigQueryExport without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing ProjectSccBigQueryExport %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/securitycenter/resource_scc_project_scc_big_query_export_generated_meta.yaml b/google-beta/services/securitycenter/resource_scc_project_scc_big_query_export_generated_meta.yaml index 04921b6d4b3..c1465cb8f38 100644 --- a/google-beta/services/securitycenter/resource_scc_project_scc_big_query_export_generated_meta.yaml +++ b/google-beta/services/securitycenter/resource_scc_project_scc_big_query_export_generated_meta.yaml @@ -19,3 +19,5 @@ fields: - api_field: name - api_field: principal - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/securitycenter/resource_scc_source.go b/google-beta/services/securitycenter/resource_scc_source.go index 6753d269d94..18f6d2f5bbb 100644 --- a/google-beta/services/securitycenter/resource_scc_source.go +++ b/google-beta/services/securitycenter/resource_scc_source.go @@ -311,6 +311,7 @@ func resourceSecurityCenterSourceRead(d *schema.ResourceData, meta interface{}) } func resourceSecurityCenterSourceUpdate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/securitycentermanagement/resource_scc_management_folder_security_health_analytics_custom_module.go b/google-beta/services/securitycentermanagement/resource_scc_management_folder_security_health_analytics_custom_module.go index 01a7f4b7f9b..3161d5518de 100644 --- a/google-beta/services/securitycentermanagement/resource_scc_management_folder_security_health_analytics_custom_module.go +++ b/google-beta/services/securitycentermanagement/resource_scc_management_folder_security_health_analytics_custom_module.go @@ -334,6 +334,19 @@ The id {securityHealthAnalyticsCustomModule} is server-generated and is not user A timestamp in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine fractional digits. Examples: "2014-10-02T15:01:23Z" and "2014-10-02T15:01:23.045123456Z".`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -474,6 +487,20 @@ func resourceSecurityCenterManagementFolderSecurityHealthAnalyticsCustomModuleRe log.Printf("[DEBUG] Finished reading SecurityCenterManagementFolderSecurityHealthAnalyticsCustomModule %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceSecurityCenterManagementFolderSecurityHealthAnalyticsCustomModuleFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -507,6 +534,19 @@ func resourceSecurityCenterManagementFolderSecurityHealthAnalyticsCustomModuleRe } func resourceSecurityCenterManagementFolderSecurityHealthAnalyticsCustomModuleUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceSecurityCenterManagementFolderSecurityHealthAnalyticsCustomModule().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceSecurityCenterManagementFolderSecurityHealthAnalyticsCustomModuleRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -609,6 +649,13 @@ func resourceSecurityCenterManagementFolderSecurityHealthAnalyticsCustomModuleUp } func resourceSecurityCenterManagementFolderSecurityHealthAnalyticsCustomModuleDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy SecurityCenterManagementFolderSecurityHealthAnalyticsCustomModule without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing FolderSecurityHealthAnalyticsCustomModule %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/securitycentermanagement/resource_scc_management_folder_security_health_analytics_custom_module_generated_meta.yaml b/google-beta/services/securitycentermanagement/resource_scc_management_folder_security_health_analytics_custom_module_generated_meta.yaml index 14678b4a065..cbbae2224b2 100644 --- a/google-beta/services/securitycentermanagement/resource_scc_management_folder_security_health_analytics_custom_module_generated_meta.yaml +++ b/google-beta/services/securitycentermanagement/resource_scc_management_folder_security_health_analytics_custom_module_generated_meta.yaml @@ -32,3 +32,5 @@ fields: provider_only: true - api_field: name - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/securitycentermanagement/resource_scc_management_organization_event_threat_detection_custom_module.go b/google-beta/services/securitycentermanagement/resource_scc_management_organization_event_threat_detection_custom_module.go index 03bccb80dd8..0502eb2acbe 100644 --- a/google-beta/services/securitycentermanagement/resource_scc_management_organization_event_threat_detection_custom_module.go +++ b/google-beta/services/securitycentermanagement/resource_scc_management_organization_event_threat_detection_custom_module.go @@ -194,6 +194,19 @@ Its format is "organizations/{organization}/locations/{location}/eventThreatDete A timestamp in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine fractional digits. Examples: "2014-10-02T15:01:23Z" and "2014-10-02T15:01:23.045123456Z".`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -340,6 +353,20 @@ func resourceSecurityCenterManagementOrganizationEventThreatDetectionCustomModul log.Printf("[DEBUG] Finished reading SecurityCenterManagementOrganizationEventThreatDetectionCustomModule %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceSecurityCenterManagementOrganizationEventThreatDetectionCustomModuleFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -373,6 +400,19 @@ func resourceSecurityCenterManagementOrganizationEventThreatDetectionCustomModul } func resourceSecurityCenterManagementOrganizationEventThreatDetectionCustomModuleUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceSecurityCenterManagementOrganizationEventThreatDetectionCustomModule().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceSecurityCenterManagementOrganizationEventThreatDetectionCustomModuleRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -485,6 +525,13 @@ func resourceSecurityCenterManagementOrganizationEventThreatDetectionCustomModul } func resourceSecurityCenterManagementOrganizationEventThreatDetectionCustomModuleDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy SecurityCenterManagementOrganizationEventThreatDetectionCustomModule without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing OrganizationEventThreatDetectionCustomModule %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/securitycentermanagement/resource_scc_management_organization_event_threat_detection_custom_module_generated_meta.yaml b/google-beta/services/securitycentermanagement/resource_scc_management_organization_event_threat_detection_custom_module_generated_meta.yaml index 9710ddc0e2e..358dcff8489 100644 --- a/google-beta/services/securitycentermanagement/resource_scc_management_organization_event_threat_detection_custom_module_generated_meta.yaml +++ b/google-beta/services/securitycentermanagement/resource_scc_management_organization_event_threat_detection_custom_module_generated_meta.yaml @@ -21,3 +21,5 @@ fields: provider_only: true - api_field: type - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/securitycentermanagement/resource_scc_management_organization_security_health_analytics_custom_module.go b/google-beta/services/securitycentermanagement/resource_scc_management_organization_security_health_analytics_custom_module.go index dadd9285811..d401a36ea9d 100644 --- a/google-beta/services/securitycentermanagement/resource_scc_management_organization_security_health_analytics_custom_module.go +++ b/google-beta/services/securitycentermanagement/resource_scc_management_organization_security_health_analytics_custom_module.go @@ -334,6 +334,19 @@ The id {securityHealthAnalyticsCustomModule} is server-generated and is not user A timestamp in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine fractional digits. Examples: "2014-10-02T15:01:23Z" and "2014-10-02T15:01:23.045123456Z".`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -474,6 +487,20 @@ func resourceSecurityCenterManagementOrganizationSecurityHealthAnalyticsCustomMo log.Printf("[DEBUG] Finished reading SecurityCenterManagementOrganizationSecurityHealthAnalyticsCustomModule %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceSecurityCenterManagementOrganizationSecurityHealthAnalyticsCustomModuleFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -507,6 +534,19 @@ func resourceSecurityCenterManagementOrganizationSecurityHealthAnalyticsCustomMo } func resourceSecurityCenterManagementOrganizationSecurityHealthAnalyticsCustomModuleUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceSecurityCenterManagementOrganizationSecurityHealthAnalyticsCustomModule().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceSecurityCenterManagementOrganizationSecurityHealthAnalyticsCustomModuleRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -609,6 +649,13 @@ func resourceSecurityCenterManagementOrganizationSecurityHealthAnalyticsCustomMo } func resourceSecurityCenterManagementOrganizationSecurityHealthAnalyticsCustomModuleDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy SecurityCenterManagementOrganizationSecurityHealthAnalyticsCustomModule without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing OrganizationSecurityHealthAnalyticsCustomModule %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/securitycentermanagement/resource_scc_management_organization_security_health_analytics_custom_module_generated_meta.yaml b/google-beta/services/securitycentermanagement/resource_scc_management_organization_security_health_analytics_custom_module_generated_meta.yaml index ddb8f130155..ec2e424cb36 100644 --- a/google-beta/services/securitycentermanagement/resource_scc_management_organization_security_health_analytics_custom_module_generated_meta.yaml +++ b/google-beta/services/securitycentermanagement/resource_scc_management_organization_security_health_analytics_custom_module_generated_meta.yaml @@ -32,3 +32,5 @@ fields: - field: organization provider_only: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/securitycentermanagement/resource_scc_management_project_security_health_analytics_custom_module.go b/google-beta/services/securitycentermanagement/resource_scc_management_project_security_health_analytics_custom_module.go index f8f89ab46e3..3e7c64608c2 100644 --- a/google-beta/services/securitycentermanagement/resource_scc_management_project_security_health_analytics_custom_module.go +++ b/google-beta/services/securitycentermanagement/resource_scc_management_project_security_health_analytics_custom_module.go @@ -115,6 +115,7 @@ func ResourceSecurityCenterManagementProjectSecurityHealthAnalyticsCustomModule( CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -338,6 +339,18 @@ up to nine fractional digits. Examples: "2014-10-02T15:01:23Z" and "2014-10-02T1 Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -490,6 +503,19 @@ func resourceSecurityCenterManagementProjectSecurityHealthAnalyticsCustomModuleR log.Printf("[DEBUG] Finished reading SecurityCenterManagementProjectSecurityHealthAnalyticsCustomModule %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading ProjectSecurityHealthAnalyticsCustomModule: %s", err) } @@ -527,6 +553,19 @@ func resourceSecurityCenterManagementProjectSecurityHealthAnalyticsCustomModuleR } func resourceSecurityCenterManagementProjectSecurityHealthAnalyticsCustomModuleUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceSecurityCenterManagementProjectSecurityHealthAnalyticsCustomModule().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceSecurityCenterManagementProjectSecurityHealthAnalyticsCustomModuleRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -635,6 +674,13 @@ func resourceSecurityCenterManagementProjectSecurityHealthAnalyticsCustomModuleU } func resourceSecurityCenterManagementProjectSecurityHealthAnalyticsCustomModuleDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy SecurityCenterManagementProjectSecurityHealthAnalyticsCustomModule without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing ProjectSecurityHealthAnalyticsCustomModule %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/securitycentermanagement/resource_scc_management_project_security_health_analytics_custom_module_generated_meta.yaml b/google-beta/services/securitycentermanagement/resource_scc_management_project_security_health_analytics_custom_module_generated_meta.yaml index e1ec95ee996..ec5584a7b5c 100644 --- a/google-beta/services/securitycentermanagement/resource_scc_management_project_security_health_analytics_custom_module_generated_meta.yaml +++ b/google-beta/services/securitycentermanagement/resource_scc_management_project_security_health_analytics_custom_module_generated_meta.yaml @@ -30,3 +30,5 @@ fields: provider_only: true - api_field: name - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/securitycenterv2/resource_scc_v2_folder_mute_config.go b/google-beta/services/securitycenterv2/resource_scc_v2_folder_mute_config.go index 2589f3ce159..2d2a51e9853 100644 --- a/google-beta/services/securitycenterv2/resource_scc_v2_folder_mute_config.go +++ b/google-beta/services/securitycenterv2/resource_scc_v2_folder_mute_config.go @@ -204,6 +204,19 @@ or projects/{project}/locations/global/muteConfigs/{configId}`, updated. This field is set by the server and will be ignored if provided on config creation or update.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -331,6 +344,20 @@ func resourceSecurityCenterV2FolderMuteConfigRead(d *schema.ResourceData, meta i log.Printf("[DEBUG] Finished reading SecurityCenterV2FolderMuteConfig %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceSecurityCenterV2FolderMuteConfigFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -364,6 +391,19 @@ func resourceSecurityCenterV2FolderMuteConfigRead(d *schema.ResourceData, meta i } func resourceSecurityCenterV2FolderMuteConfigUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceSecurityCenterV2FolderMuteConfig().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceSecurityCenterV2FolderMuteConfigRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -469,6 +509,13 @@ func resourceSecurityCenterV2FolderMuteConfigUpdate(d *schema.ResourceData, meta } func resourceSecurityCenterV2FolderMuteConfigDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy SecurityCenterV2FolderMuteConfig without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing FolderMuteConfig %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/securitycenterv2/resource_scc_v2_folder_mute_config_generated_meta.yaml b/google-beta/services/securitycenterv2/resource_scc_v2_folder_mute_config_generated_meta.yaml index eef5acc8c97..3296eb5f9da 100644 --- a/google-beta/services/securitycenterv2/resource_scc_v2_folder_mute_config_generated_meta.yaml +++ b/google-beta/services/securitycenterv2/resource_scc_v2_folder_mute_config_generated_meta.yaml @@ -22,3 +22,5 @@ fields: - api_field: name - api_field: type - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/securitycenterv2/resource_scc_v2_folder_notification_config.go b/google-beta/services/securitycenterv2/resource_scc_v2_folder_notification_config.go index b20b87045e5..879511a54a0 100644 --- a/google-beta/services/securitycenterv2/resource_scc_v2_folder_notification_config.go +++ b/google-beta/services/securitycenterv2/resource_scc_v2_folder_notification_config.go @@ -219,6 +219,19 @@ for information on how to write a filter.`, Description: `The service account that needs "pubsub.topics.publish" permission to publish to the Pub/Sub topic.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -346,6 +359,20 @@ func resourceSecurityCenterV2FolderNotificationConfigRead(d *schema.ResourceData log.Printf("[DEBUG] Finished reading SecurityCenterV2FolderNotificationConfig %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceSecurityCenterV2FolderNotificationConfigFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -379,6 +406,19 @@ func resourceSecurityCenterV2FolderNotificationConfigRead(d *schema.ResourceData } func resourceSecurityCenterV2FolderNotificationConfigUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceSecurityCenterV2FolderNotificationConfig().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceSecurityCenterV2FolderNotificationConfigRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -484,6 +524,13 @@ func resourceSecurityCenterV2FolderNotificationConfigUpdate(d *schema.ResourceDa } func resourceSecurityCenterV2FolderNotificationConfigDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy SecurityCenterV2FolderNotificationConfig without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing FolderNotificationConfig %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/securitycenterv2/resource_scc_v2_folder_notification_config_generated_meta.yaml b/google-beta/services/securitycenterv2/resource_scc_v2_folder_notification_config_generated_meta.yaml index d3f754b06e0..b03053412fa 100644 --- a/google-beta/services/securitycenterv2/resource_scc_v2_folder_notification_config_generated_meta.yaml +++ b/google-beta/services/securitycenterv2/resource_scc_v2_folder_notification_config_generated_meta.yaml @@ -20,3 +20,5 @@ fields: - api_field: pubsubTopic - api_field: serviceAccount - api_field: streamingConfig.filter + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/securitycenterv2/resource_scc_v2_folder_scc_big_query_export.go b/google-beta/services/securitycenterv2/resource_scc_v2_folder_scc_big_query_export.go index e04b7acbab3..09df830d4a1 100644 --- a/google-beta/services/securitycenterv2/resource_scc_v2_folder_scc_big_query_export.go +++ b/google-beta/services/securitycenterv2/resource_scc_v2_folder_scc_big_query_export.go @@ -233,6 +233,19 @@ This field is provided in responses, and is ignored when provided in create requ A timestamp in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine fractional digits. Examples: "2014-10-02T15:01:23Z" and "2014-10-02T15:01:23.045123456Z".`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -360,6 +373,20 @@ func resourceSecurityCenterV2FolderSccBigQueryExportRead(d *schema.ResourceData, log.Printf("[DEBUG] Finished reading SecurityCenterV2FolderSccBigQueryExport %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceSecurityCenterV2FolderSccBigQueryExportFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -393,6 +420,19 @@ func resourceSecurityCenterV2FolderSccBigQueryExportRead(d *schema.ResourceData, } func resourceSecurityCenterV2FolderSccBigQueryExportUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceSecurityCenterV2FolderSccBigQueryExport().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceSecurityCenterV2FolderSccBigQueryExportRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -498,6 +538,13 @@ func resourceSecurityCenterV2FolderSccBigQueryExportUpdate(d *schema.ResourceDat } func resourceSecurityCenterV2FolderSccBigQueryExportDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy SecurityCenterV2FolderSccBigQueryExport without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing FolderSccBigQueryExport %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/securitycenterv2/resource_scc_v2_folder_scc_big_query_export_generated_meta.yaml b/google-beta/services/securitycenterv2/resource_scc_v2_folder_scc_big_query_export_generated_meta.yaml index acf5e5914ad..be51add612d 100644 --- a/google-beta/services/securitycenterv2/resource_scc_v2_folder_scc_big_query_export_generated_meta.yaml +++ b/google-beta/services/securitycenterv2/resource_scc_v2_folder_scc_big_query_export_generated_meta.yaml @@ -23,3 +23,5 @@ fields: - api_field: name - api_field: principal - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/securitycenterv2/resource_scc_v2_organization_mute_config.go b/google-beta/services/securitycenterv2/resource_scc_v2_organization_mute_config.go index ff038edce91..10ca3789fac 100644 --- a/google-beta/services/securitycenterv2/resource_scc_v2_organization_mute_config.go +++ b/google-beta/services/securitycenterv2/resource_scc_v2_organization_mute_config.go @@ -204,6 +204,19 @@ or projects/{project}/locations/global/muteConfigs/{configId}`, updated. This field is set by the server and will be ignored if provided on config creation or update.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -331,6 +344,20 @@ func resourceSecurityCenterV2OrganizationMuteConfigRead(d *schema.ResourceData, log.Printf("[DEBUG] Finished reading SecurityCenterV2OrganizationMuteConfig %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceSecurityCenterV2OrganizationMuteConfigFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -364,6 +391,19 @@ func resourceSecurityCenterV2OrganizationMuteConfigRead(d *schema.ResourceData, } func resourceSecurityCenterV2OrganizationMuteConfigUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceSecurityCenterV2OrganizationMuteConfig().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceSecurityCenterV2OrganizationMuteConfigRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -469,6 +509,13 @@ func resourceSecurityCenterV2OrganizationMuteConfigUpdate(d *schema.ResourceData } func resourceSecurityCenterV2OrganizationMuteConfigDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy SecurityCenterV2OrganizationMuteConfig without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing OrganizationMuteConfig %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/securitycenterv2/resource_scc_v2_organization_mute_config_generated_meta.yaml b/google-beta/services/securitycenterv2/resource_scc_v2_organization_mute_config_generated_meta.yaml index dd08f8d5e1b..8950c6422ec 100644 --- a/google-beta/services/securitycenterv2/resource_scc_v2_organization_mute_config_generated_meta.yaml +++ b/google-beta/services/securitycenterv2/resource_scc_v2_organization_mute_config_generated_meta.yaml @@ -22,3 +22,5 @@ fields: provider_only: true - api_field: type - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/securitycenterv2/resource_scc_v2_organization_notification_config.go b/google-beta/services/securitycenterv2/resource_scc_v2_organization_notification_config.go index 494f11fe5cd..fa656d2120e 100644 --- a/google-beta/services/securitycenterv2/resource_scc_v2_organization_notification_config.go +++ b/google-beta/services/securitycenterv2/resource_scc_v2_organization_notification_config.go @@ -212,6 +212,19 @@ for information on how to write a filter.`, Description: `The service account that needs "pubsub.topics.publish" permission to publish to the Pub/Sub topic.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -335,6 +348,20 @@ func resourceSecurityCenterV2OrganizationNotificationConfigRead(d *schema.Resour log.Printf("[DEBUG] Finished reading SecurityCenterV2OrganizationNotificationConfig %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceSecurityCenterV2OrganizationNotificationConfigFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -356,6 +383,19 @@ func resourceSecurityCenterV2OrganizationNotificationConfigRead(d *schema.Resour } func resourceSecurityCenterV2OrganizationNotificationConfigUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceSecurityCenterV2OrganizationNotificationConfig().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceSecurityCenterV2OrganizationNotificationConfigRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -451,6 +491,13 @@ func resourceSecurityCenterV2OrganizationNotificationConfigUpdate(d *schema.Reso } func resourceSecurityCenterV2OrganizationNotificationConfigDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy SecurityCenterV2OrganizationNotificationConfig without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing OrganizationNotificationConfig %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/securitycenterv2/resource_scc_v2_organization_notification_config_generated_meta.yaml b/google-beta/services/securitycenterv2/resource_scc_v2_organization_notification_config_generated_meta.yaml index f25837cafda..8ffc9789102 100644 --- a/google-beta/services/securitycenterv2/resource_scc_v2_organization_notification_config_generated_meta.yaml +++ b/google-beta/services/securitycenterv2/resource_scc_v2_organization_notification_config_generated_meta.yaml @@ -22,3 +22,5 @@ fields: - api_field: pubsubTopic - api_field: serviceAccount - api_field: streamingConfig.filter + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/securitycenterv2/resource_scc_v2_organization_scc_big_query_export.go b/google-beta/services/securitycenterv2/resource_scc_v2_organization_scc_big_query_export.go index a5513b05b81..19dd8fec4d6 100644 --- a/google-beta/services/securitycenterv2/resource_scc_v2_organization_scc_big_query_export.go +++ b/google-beta/services/securitycenterv2/resource_scc_v2_organization_scc_big_query_export.go @@ -231,6 +231,19 @@ This field is set by the server and will be ignored if provided on export creati A timestamp in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine fractional digits. Examples: "2014-10-02T15:01:23Z" and "2014-10-02T15:01:23.045123456Z".`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -364,6 +377,20 @@ func resourceSecurityCenterV2OrganizationSccBigQueryExportRead(d *schema.Resourc log.Printf("[DEBUG] Finished reading SecurityCenterV2OrganizationSccBigQueryExport %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceSecurityCenterV2OrganizationSccBigQueryExportFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -397,6 +424,19 @@ func resourceSecurityCenterV2OrganizationSccBigQueryExportRead(d *schema.Resourc } func resourceSecurityCenterV2OrganizationSccBigQueryExportUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceSecurityCenterV2OrganizationSccBigQueryExport().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceSecurityCenterV2OrganizationSccBigQueryExportRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -512,6 +552,13 @@ func resourceSecurityCenterV2OrganizationSccBigQueryExportUpdate(d *schema.Resou } func resourceSecurityCenterV2OrganizationSccBigQueryExportDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy SecurityCenterV2OrganizationSccBigQueryExport without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing OrganizationSccBigQueryExport %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/securitycenterv2/resource_scc_v2_organization_scc_big_query_export_generated_meta.yaml b/google-beta/services/securitycenterv2/resource_scc_v2_organization_scc_big_query_export_generated_meta.yaml index 26848c20171..0bb14b4f01a 100644 --- a/google-beta/services/securitycenterv2/resource_scc_v2_organization_scc_big_query_export_generated_meta.yaml +++ b/google-beta/services/securitycenterv2/resource_scc_v2_organization_scc_big_query_export_generated_meta.yaml @@ -23,3 +23,5 @@ fields: provider_only: true - api_field: principal - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/securitycenterv2/resource_scc_v2_organization_scc_big_query_exports.go b/google-beta/services/securitycenterv2/resource_scc_v2_organization_scc_big_query_exports.go index 4cd99106901..a47f2dda285 100644 --- a/google-beta/services/securitycenterv2/resource_scc_v2_organization_scc_big_query_exports.go +++ b/google-beta/services/securitycenterv2/resource_scc_v2_organization_scc_big_query_exports.go @@ -233,6 +233,19 @@ This field is set by the server and will be ignored if provided on export creati A timestamp in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine fractional digits. Examples: "2014-10-02T15:01:23Z" and "2014-10-02T15:01:23.045123456Z".`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -366,6 +379,20 @@ func resourceSecurityCenterV2OrganizationSccBigQueryExportsRead(d *schema.Resour log.Printf("[DEBUG] Finished reading SecurityCenterV2OrganizationSccBigQueryExports %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceSecurityCenterV2OrganizationSccBigQueryExportsFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -399,6 +426,19 @@ func resourceSecurityCenterV2OrganizationSccBigQueryExportsRead(d *schema.Resour } func resourceSecurityCenterV2OrganizationSccBigQueryExportsUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceSecurityCenterV2OrganizationSccBigQueryExports().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceSecurityCenterV2OrganizationSccBigQueryExportsRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -514,6 +554,13 @@ func resourceSecurityCenterV2OrganizationSccBigQueryExportsUpdate(d *schema.Reso } func resourceSecurityCenterV2OrganizationSccBigQueryExportsDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy SecurityCenterV2OrganizationSccBigQueryExports without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing OrganizationSccBigQueryExports %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/securitycenterv2/resource_scc_v2_organization_scc_big_query_exports_generated_meta.yaml b/google-beta/services/securitycenterv2/resource_scc_v2_organization_scc_big_query_exports_generated_meta.yaml index dc27a659867..006d16ee376 100644 --- a/google-beta/services/securitycenterv2/resource_scc_v2_organization_scc_big_query_exports_generated_meta.yaml +++ b/google-beta/services/securitycenterv2/resource_scc_v2_organization_scc_big_query_exports_generated_meta.yaml @@ -23,3 +23,5 @@ fields: provider_only: true - api_field: principal - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/securitycenterv2/resource_scc_v2_organization_source.go b/google-beta/services/securitycenterv2/resource_scc_v2_organization_source.go index 95b8ee75d08..76337b136d1 100644 --- a/google-beta/services/securitycenterv2/resource_scc_v2_organization_source.go +++ b/google-beta/services/securitycenterv2/resource_scc_v2_organization_source.go @@ -311,6 +311,7 @@ func resourceSecurityCenterV2OrganizationSourceRead(d *schema.ResourceData, meta } func resourceSecurityCenterV2OrganizationSourceUpdate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/securitycenterv2/resource_scc_v2_project_mute_config.go b/google-beta/services/securitycenterv2/resource_scc_v2_project_mute_config.go index a3abac53b5d..ff207452a82 100644 --- a/google-beta/services/securitycenterv2/resource_scc_v2_project_mute_config.go +++ b/google-beta/services/securitycenterv2/resource_scc_v2_project_mute_config.go @@ -115,6 +115,7 @@ func ResourceSecurityCenterV2ProjectMuteConfig() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -207,6 +208,18 @@ provided on config creation or update.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -346,6 +359,19 @@ func resourceSecurityCenterV2ProjectMuteConfigRead(d *schema.ResourceData, meta log.Printf("[DEBUG] Finished reading SecurityCenterV2ProjectMuteConfig %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading ProjectMuteConfig: %s", err) } @@ -383,6 +409,19 @@ func resourceSecurityCenterV2ProjectMuteConfigRead(d *schema.ResourceData, meta } func resourceSecurityCenterV2ProjectMuteConfigUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceSecurityCenterV2ProjectMuteConfig().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceSecurityCenterV2ProjectMuteConfigRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -494,6 +533,13 @@ func resourceSecurityCenterV2ProjectMuteConfigUpdate(d *schema.ResourceData, met } func resourceSecurityCenterV2ProjectMuteConfigDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy SecurityCenterV2ProjectMuteConfig without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing ProjectMuteConfig %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/securitycenterv2/resource_scc_v2_project_mute_config_generated_meta.yaml b/google-beta/services/securitycenterv2/resource_scc_v2_project_mute_config_generated_meta.yaml index e34c999935d..b412a9c5b0b 100644 --- a/google-beta/services/securitycenterv2/resource_scc_v2_project_mute_config_generated_meta.yaml +++ b/google-beta/services/securitycenterv2/resource_scc_v2_project_mute_config_generated_meta.yaml @@ -20,3 +20,5 @@ fields: - api_field: name - api_field: type - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/securitycenterv2/resource_scc_v2_project_notification_config.go b/google-beta/services/securitycenterv2/resource_scc_v2_project_notification_config.go index 663e74af87c..7047157765b 100644 --- a/google-beta/services/securitycenterv2/resource_scc_v2_project_notification_config.go +++ b/google-beta/services/securitycenterv2/resource_scc_v2_project_notification_config.go @@ -115,6 +115,7 @@ func ResourceSecurityCenterV2ProjectNotificationConfig() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Schema: map[string]*schema.Schema{ @@ -200,6 +201,18 @@ publish to the Pub/Sub topic.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -324,6 +337,19 @@ func resourceSecurityCenterV2ProjectNotificationConfigRead(d *schema.ResourceDat log.Printf("[DEBUG] Finished reading SecurityCenterV2ProjectNotificationConfig %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading ProjectNotificationConfig: %s", err) } @@ -337,6 +363,19 @@ func resourceSecurityCenterV2ProjectNotificationConfigRead(d *schema.ResourceDat } func resourceSecurityCenterV2ProjectNotificationConfigUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceSecurityCenterV2ProjectNotificationConfig().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceSecurityCenterV2ProjectNotificationConfigRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -428,6 +467,13 @@ func resourceSecurityCenterV2ProjectNotificationConfigUpdate(d *schema.ResourceD } func resourceSecurityCenterV2ProjectNotificationConfigDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy SecurityCenterV2ProjectNotificationConfig without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing ProjectNotificationConfig %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/securitycenterv2/resource_scc_v2_project_notification_config_generated_meta.yaml b/google-beta/services/securitycenterv2/resource_scc_v2_project_notification_config_generated_meta.yaml index 7988454d44e..c9648f2c701 100644 --- a/google-beta/services/securitycenterv2/resource_scc_v2_project_notification_config_generated_meta.yaml +++ b/google-beta/services/securitycenterv2/resource_scc_v2_project_notification_config_generated_meta.yaml @@ -18,3 +18,5 @@ fields: - api_field: pubsubTopic - api_field: serviceAccount - api_field: streamingConfig.filter + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/securitycenterv2/resource_scc_v2_project_scc_big_query_export.go b/google-beta/services/securitycenterv2/resource_scc_v2_project_scc_big_query_export.go index f60cdfdf532..af14689230a 100644 --- a/google-beta/services/securitycenterv2/resource_scc_v2_project_scc_big_query_export.go +++ b/google-beta/services/securitycenterv2/resource_scc_v2_project_scc_big_query_export.go @@ -115,6 +115,7 @@ func ResourceSecurityCenterV2ProjectSccBigQueryExport() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -234,6 +235,18 @@ Examples: "2014-10-02T15:01:23Z" and "2014-10-02T15:01:23.045123456Z".`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -373,6 +386,19 @@ func resourceSecurityCenterV2ProjectSccBigQueryExportRead(d *schema.ResourceData log.Printf("[DEBUG] Finished reading SecurityCenterV2ProjectSccBigQueryExport %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading ProjectSccBigQueryExport: %s", err) } @@ -410,6 +436,19 @@ func resourceSecurityCenterV2ProjectSccBigQueryExportRead(d *schema.ResourceData } func resourceSecurityCenterV2ProjectSccBigQueryExportUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceSecurityCenterV2ProjectSccBigQueryExport().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceSecurityCenterV2ProjectSccBigQueryExportRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -521,6 +560,13 @@ func resourceSecurityCenterV2ProjectSccBigQueryExportUpdate(d *schema.ResourceDa } func resourceSecurityCenterV2ProjectSccBigQueryExportDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy SecurityCenterV2ProjectSccBigQueryExport without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing ProjectSccBigQueryExport %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/securitycenterv2/resource_scc_v2_project_scc_big_query_export_generated_meta.yaml b/google-beta/services/securitycenterv2/resource_scc_v2_project_scc_big_query_export_generated_meta.yaml index 0d07993c8d7..43a254a0f70 100644 --- a/google-beta/services/securitycenterv2/resource_scc_v2_project_scc_big_query_export_generated_meta.yaml +++ b/google-beta/services/securitycenterv2/resource_scc_v2_project_scc_big_query_export_generated_meta.yaml @@ -21,3 +21,5 @@ fields: - api_field: name - api_field: principal - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/securityposture/resource_securityposture_posture.go b/google-beta/services/securityposture/resource_securityposture_posture.go index 5b5eab139c0..5d499b395d1 100644 --- a/google-beta/services/securityposture/resource_securityposture_posture.go +++ b/google-beta/services/securityposture/resource_securityposture_posture.go @@ -126,6 +126,7 @@ func ResourceSecurityposturePosture() *schema.Resource { CustomizeDiff: customdiff.All( revisionIdCustomizeDiff, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -714,6 +715,19 @@ with other field updates. Possible values: ["DEPRECATED", "DRAFT", "ACTIVE"]`, Computed: true, Description: `Time the Posture was updated in UTC.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -857,6 +871,20 @@ func resourceSecurityposturePostureRead(d *schema.ResourceData, meta interface{} log.Printf("[DEBUG] Finished reading SecurityposturePosture %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceSecurityposturePostureFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -890,6 +918,19 @@ func resourceSecurityposturePostureRead(d *schema.ResourceData, meta interface{} } func resourceSecurityposturePostureUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceSecurityposturePosture().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceSecurityposturePostureRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1012,6 +1053,13 @@ func resourceSecurityposturePostureUpdate(d *schema.ResourceData, meta interface } func resourceSecurityposturePostureDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy SecurityposturePosture without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Posture %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/securityposture/resource_securityposture_posture_deployment.go b/google-beta/services/securityposture/resource_securityposture_posture_deployment.go index 8f7616a99d6..382c9404f37 100644 --- a/google-beta/services/securityposture/resource_securityposture_posture_deployment.go +++ b/google-beta/services/securityposture/resource_securityposture_posture_deployment.go @@ -233,6 +233,19 @@ ACTIVE, CREATE_FAILED, UPDATE_FAILED, DELETE_FAILED.`, Computed: true, Description: `Time the posture deployment was updated in UTC.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -376,6 +389,20 @@ func resourceSecurityposturePostureDeploymentRead(d *schema.ResourceData, meta i log.Printf("[DEBUG] Finished reading SecurityposturePostureDeployment %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceSecurityposturePostureDeploymentFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -409,6 +436,19 @@ func resourceSecurityposturePostureDeploymentRead(d *schema.ResourceData, meta i } func resourceSecurityposturePostureDeploymentUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceSecurityposturePostureDeployment().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceSecurityposturePostureDeploymentRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -521,6 +561,13 @@ func resourceSecurityposturePostureDeploymentUpdate(d *schema.ResourceData, meta } func resourceSecurityposturePostureDeploymentDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy SecurityposturePostureDeployment without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing PostureDeployment %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/securityposture/resource_securityposture_posture_deployment_generated_meta.yaml b/google-beta/services/securityposture/resource_securityposture_posture_deployment_generated_meta.yaml index ace3ea73d71..48a6d017eae 100644 --- a/google-beta/services/securityposture/resource_securityposture_posture_deployment_generated_meta.yaml +++ b/google-beta/services/securityposture/resource_securityposture_posture_deployment_generated_meta.yaml @@ -30,3 +30,5 @@ fields: - api_field: state - api_field: targetResource - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/securityposture/resource_securityposture_posture_generated_meta.yaml b/google-beta/services/securityposture/resource_securityposture_posture_generated_meta.yaml index 0d496c01e33..1e33437c041 100644 --- a/google-beta/services/securityposture/resource_securityposture_posture_generated_meta.yaml +++ b/google-beta/services/securityposture/resource_securityposture_posture_generated_meta.yaml @@ -71,3 +71,5 @@ fields: - api_field: revisionId - api_field: state - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/securityscanner/resource_security_scanner_scan_config.go b/google-beta/services/securityscanner/resource_security_scanner_scan_config.go index 3c9af32d889..0ad3302d276 100644 --- a/google-beta/services/securityscanner/resource_security_scanner_scan_config.go +++ b/google-beta/services/securityscanner/resource_security_scanner_scan_config.go @@ -115,6 +115,7 @@ func ResourceSecurityScannerScanConfig() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -288,6 +289,18 @@ which means the scan will be scheduled to start immediately.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -464,6 +477,19 @@ func resourceSecurityScannerScanConfigRead(d *schema.ResourceData, meta interfac log.Printf("[DEBUG] Finished reading SecurityScannerScanConfig %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading ScanConfig: %s", err) } @@ -495,6 +521,19 @@ func resourceSecurityScannerScanConfigRead(d *schema.ResourceData, meta interfac } func resourceSecurityScannerScanConfigUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceSecurityScannerScanConfig().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceSecurityScannerScanConfigRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -661,6 +700,13 @@ func resourceSecurityScannerScanConfigUpdate(d *schema.ResourceData, meta interf } func resourceSecurityScannerScanConfigDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy SecurityScannerScanConfig without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing ScanConfig %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/securityscanner/resource_security_scanner_scan_config_generated_meta.yaml b/google-beta/services/securityscanner/resource_security_scanner_scan_config_generated_meta.yaml index 351663f92eb..b47ae0dd7d9 100644 --- a/google-beta/services/securityscanner/resource_security_scanner_scan_config_generated_meta.yaml +++ b/google-beta/services/securityscanner/resource_security_scanner_scan_config_generated_meta.yaml @@ -22,3 +22,5 @@ fields: - api_field: startingUrls - api_field: targetPlatforms - api_field: userAgent + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/servicedirectory/resource_service_directory_endpoint.go b/google-beta/services/servicedirectory/resource_service_directory_endpoint.go index 5cc3f650ea3..38c1ace862e 100644 --- a/google-beta/services/servicedirectory/resource_service_directory_endpoint.go +++ b/google-beta/services/servicedirectory/resource_service_directory_endpoint.go @@ -162,6 +162,19 @@ range of [0, 65535]. If unspecified, the default is 0.`, Description: `The resource name for the endpoint in the format 'projects/*/locations/*/namespaces/*/services/*/endpoints/*'.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -297,6 +310,20 @@ func resourceServiceDirectoryEndpointRead(d *schema.ResourceData, meta interface return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceServiceDirectoryEndpointFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -306,6 +333,19 @@ func resourceServiceDirectoryEndpointRead(d *schema.ResourceData, meta interface } func resourceServiceDirectoryEndpointUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceServiceDirectoryEndpoint().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceServiceDirectoryEndpointRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -393,6 +433,13 @@ func resourceServiceDirectoryEndpointUpdate(d *schema.ResourceData, meta interfa } func resourceServiceDirectoryEndpointDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ServiceDirectoryEndpoint without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Endpoint %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/servicedirectory/resource_service_directory_endpoint_generated_meta.yaml b/google-beta/services/servicedirectory/resource_service_directory_endpoint_generated_meta.yaml index 9d7ecc350a1..f0adfaf31e8 100644 --- a/google-beta/services/servicedirectory/resource_service_directory_endpoint_generated_meta.yaml +++ b/google-beta/services/servicedirectory/resource_service_directory_endpoint_generated_meta.yaml @@ -16,3 +16,5 @@ fields: - api_field: port - field: service provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/servicedirectory/resource_service_directory_namespace.go b/google-beta/services/servicedirectory/resource_service_directory_namespace.go index 4c6f10e1380..accad66106c 100644 --- a/google-beta/services/servicedirectory/resource_service_directory_namespace.go +++ b/google-beta/services/servicedirectory/resource_service_directory_namespace.go @@ -116,6 +116,7 @@ func ResourceServiceDirectoryNamespace() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Schema: map[string]*schema.Schema{ @@ -170,6 +171,18 @@ in the format 'projects/*/locations/*/namespaces/*'.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -282,6 +295,19 @@ func resourceServiceDirectoryNamespaceRead(d *schema.ResourceData, meta interfac log.Printf("[DEBUG] Finished reading ServiceDirectoryNamespace %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Namespace: %s", err) } @@ -295,6 +321,19 @@ func resourceServiceDirectoryNamespaceRead(d *schema.ResourceData, meta interfac } func resourceServiceDirectoryNamespaceUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceServiceDirectoryNamespace().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceServiceDirectoryNamespaceRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -366,6 +405,13 @@ func resourceServiceDirectoryNamespaceUpdate(d *schema.ResourceData, meta interf } func resourceServiceDirectoryNamespaceDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ServiceDirectoryNamespace without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Namespace %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/servicedirectory/resource_service_directory_namespace_generated_meta.yaml b/google-beta/services/servicedirectory/resource_service_directory_namespace_generated_meta.yaml index 9227e4bc641..3d3816d1784 100644 --- a/google-beta/services/servicedirectory/resource_service_directory_namespace_generated_meta.yaml +++ b/google-beta/services/servicedirectory/resource_service_directory_namespace_generated_meta.yaml @@ -17,3 +17,5 @@ fields: provider_only: true - field: terraform_labels provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/servicedirectory/resource_service_directory_service.go b/google-beta/services/servicedirectory/resource_service_directory_service.go index 9b9e3d09e9d..099176a9013 100644 --- a/google-beta/services/servicedirectory/resource_service_directory_service.go +++ b/google-beta/services/servicedirectory/resource_service_directory_service.go @@ -142,6 +142,19 @@ Metadata that goes beyond any these limits will be rejected.`, Description: `The resource name for the service in the format 'projects/*/locations/*/namespaces/*/services/*'.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -259,6 +272,20 @@ func resourceServiceDirectoryServiceRead(d *schema.ResourceData, meta interface{ return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceServiceDirectoryServiceFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -268,6 +295,19 @@ func resourceServiceDirectoryServiceRead(d *schema.ResourceData, meta interface{ } func resourceServiceDirectoryServiceUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceServiceDirectoryService().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceServiceDirectoryServiceRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -335,6 +375,13 @@ func resourceServiceDirectoryServiceUpdate(d *schema.ResourceData, meta interfac } func resourceServiceDirectoryServiceDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ServiceDirectoryService without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Service %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/servicedirectory/resource_service_directory_service_generated_meta.yaml b/google-beta/services/servicedirectory/resource_service_directory_service_generated_meta.yaml index 21d5e3cc89e..ff1a64b6707 100644 --- a/google-beta/services/servicedirectory/resource_service_directory_service_generated_meta.yaml +++ b/google-beta/services/servicedirectory/resource_service_directory_service_generated_meta.yaml @@ -13,3 +13,5 @@ fields: provider_only: true - field: service_id provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/servicemanagement/resource_endpoints_service.go b/google-beta/services/servicemanagement/resource_endpoints_service.go index cf5acf3c59c..828cec8a7e2 100644 --- a/google-beta/services/servicemanagement/resource_endpoints_service.go +++ b/google-beta/services/servicemanagement/resource_endpoints_service.go @@ -28,6 +28,7 @@ import ( "strings" "time" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-google-beta/google-beta/registry" "github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource" @@ -164,8 +165,14 @@ func ResourceEndpointsService() *schema.Resource { }, }, }, + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end }, - CustomizeDiff: predictServiceId, + CustomizeDiff: customdiff.All( + tpgresource.DefaultProviderDeletionPolicy("DELETE"), + predictServiceId, + ), UseJSONNumber: true, } } @@ -300,6 +307,11 @@ func expandEndpointServiceConfigSource(d *schema.ResourceData, meta interface{}) } func resourceEndpointsServiceUpdate(d *schema.ResourceData, meta interface{}) error { + + if tpgresource.DeletionPolicyPreUpdate(d, ResourceEndpointsService) { + return ResourceEndpointsService().Read(d, meta) + } + // This update is not quite standard for a terraform resource. Instead of // using the go client library to send an HTTP request to update something // serverside, we have to push a new configuration, wait for it to be @@ -370,6 +382,13 @@ func resourceEndpointsServiceUpdate(d *schema.ResourceData, meta interface{}) er } func resourceEndpointsServiceDelete(d *schema.ResourceData, meta interface{}) error { + + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { + return nil + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -414,6 +433,10 @@ func resourceEndpointsServiceRead(d *schema.ResourceData, meta interface{}) erro return fmt.Errorf("Error setting endpoints: %s", err) } + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + return nil } diff --git a/google-beta/services/servicemanagement/resource_endpoints_service_meta.yaml b/google-beta/services/servicemanagement/resource_endpoints_service_meta.yaml index 561ed1145b5..dcab542636e 100644 --- a/google-beta/services/servicemanagement/resource_endpoints_service_meta.yaml +++ b/google-beta/services/servicemanagement/resource_endpoints_service_meta.yaml @@ -22,3 +22,5 @@ fields: - field: 'project' - field: 'protoc_output_base64' - api_field: 'serviceName' + - field: 'deletion_policy' + provider_only: true diff --git a/google-beta/services/servicenetworking/data_source_google_service_networking_peered_dns_domain.go b/google-beta/services/servicenetworking/data_source_google_service_networking_peered_dns_domain.go index 0c3e127adff..9250ffd4fee 100644 --- a/google-beta/services/servicenetworking/data_source_google_service_networking_peered_dns_domain.go +++ b/google-beta/services/servicenetworking/data_source_google_service_networking_peered_dns_domain.go @@ -17,6 +17,8 @@ package servicenetworking import ( + "github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-google-beta/google-beta/registry" ) @@ -49,6 +51,9 @@ func DataSourceGoogleServiceNetworkingPeeredDNSDomain() *schema.Resource { Type: schema.TypeString, Computed: true, }, + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end }, } } diff --git a/google-beta/services/servicenetworking/resource_google_service_networking_peered_dns_domain.go b/google-beta/services/servicenetworking/resource_google_service_networking_peered_dns_domain.go index e6e494be368..bea737ed5fe 100644 --- a/google-beta/services/servicenetworking/resource_google_service_networking_peered_dns_domain.go +++ b/google-beta/services/servicenetworking/resource_google_service_networking_peered_dns_domain.go @@ -37,6 +37,7 @@ func ResourceGoogleServiceNetworkingPeeredDNSDomain() *schema.Resource { return &schema.Resource{ Create: resourceGoogleServiceNetworkingPeeredDNSDomainCreate, Read: resourceGoogleServiceNetworkingPeeredDNSDomainRead, + Update: resourceGoogleServiceNetworkingPeeredDNSDomainUpdate, Delete: resourceGoogleServiceNetworkingPeeredDNSDomainDelete, Importer: &schema.ResourceImporter{ @@ -51,6 +52,7 @@ func ResourceGoogleServiceNetworkingPeeredDNSDomain() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Schema: map[string]*schema.Schema{ @@ -90,6 +92,9 @@ func ResourceGoogleServiceNetworkingPeeredDNSDomain() *schema.Resource { Type: schema.TypeString, Computed: true, }, + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end }, UseJSONNumber: true, } @@ -230,10 +235,29 @@ func resourceGoogleServiceNetworkingPeeredDNSDomainRead(d *schema.ResourceData, return fmt.Errorf("Error setting parent: %s", err) } + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + return nil } +// UDP update start +func resourceGoogleServiceNetworkingPeeredDNSDomainUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceGoogleServiceNetworkingPeeredDNSDomainRead(d, meta) +} + +//UDP update end + func resourceGoogleServiceNetworkingPeeredDNSDomainDelete(d *schema.ResourceData, meta interface{}) error { + + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { + return nil + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/servicenetworking/resource_google_service_networking_peered_dns_domain_meta.yaml b/google-beta/services/servicenetworking/resource_google_service_networking_peered_dns_domain_meta.yaml index 9d58a039d3a..4cbaa0c4516 100644 --- a/google-beta/services/servicenetworking/resource_google_service_networking_peered_dns_domain_meta.yaml +++ b/google-beta/services/servicenetworking/resource_google_service_networking_peered_dns_domain_meta.yaml @@ -12,3 +12,5 @@ fields: - field: 'parent' - field: 'project' - field: 'service' + - field: 'deletion_policy' + provider_only: true diff --git a/google-beta/services/servicenetworking/resource_service_networking_connection.go b/google-beta/services/servicenetworking/resource_service_networking_connection.go index e4add40c145..0529ba5d7ff 100644 --- a/google-beta/services/servicenetworking/resource_service_networking_connection.go +++ b/google-beta/services/servicenetworking/resource_service_networking_connection.go @@ -32,8 +32,8 @@ import ( transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport" "github.com/hashicorp/errwrap" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "google.golang.org/api/servicenetworking/v1" ) @@ -53,6 +53,9 @@ func ResourceServiceNetworkingConnection() *schema.Resource { Importer: &schema.ResourceImporter{ State: resourceServiceNetworkingConnectionImportState, }, + CustomizeDiff: customdiff.All( + tpgresource.DefaultProviderDeletionPolicy("DELETE"), + ), Timeouts: &schema.ResourceTimeout{ Create: schema.DefaultTimeout(10 * time.Minute), @@ -87,12 +90,9 @@ func ResourceServiceNetworkingConnection() *schema.Resource { DiffSuppressFunc: stringListDiffSuppress, Description: `Named IP address range(s) of PEERING type reserved for this service provider. Note that invoking this method with a different range when connection is already established will not reallocate already provisioned service producer subnetworks.`, }, - "deletion_policy": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: validation.StringInSlice([]string{"ABANDON", ""}, false), - Description: `When set to ABANDON, terraform will abandon management of the resource instead of deleting it. Prevents terraform apply failures with CloudSQL. Note: The resource will still exist.`, - }, + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end "peering": { Type: schema.TypeString, Computed: true, @@ -255,10 +255,19 @@ func resourceServiceNetworkingConnectionRead(d *schema.ResourceData, meta interf return fmt.Errorf("Error setting reserved_peering_ranges: %s", err) } + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + return nil } func resourceServiceNetworkingConnectionUpdate(d *schema.ResourceData, meta interface{}) error { + + if tpgresource.DeletionPolicyPreUpdate(d, ResourceServiceNetworkingConnection) { + return ResourceServiceNetworkingConnection().Read(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -316,8 +325,9 @@ func resourceServiceNetworkingConnectionUpdate(d *schema.ResourceData, meta inte func resourceServiceNetworkingConnectionDelete(d *schema.ResourceData, meta interface{}) error { config := meta.(*transport_tpg.Config) - if deletionPolicy := d.Get("deletion_policy"); deletionPolicy == "ABANDON" { - log.Printf("[WARN] The service networking connection has been abandoned") + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { return nil } diff --git a/google-beta/services/servicenetworking/resource_service_networking_connection_meta.yaml b/google-beta/services/servicenetworking/resource_service_networking_connection_meta.yaml index ad66ed83c4a..7c300295c48 100644 --- a/google-beta/services/servicenetworking/resource_service_networking_connection_meta.yaml +++ b/google-beta/services/servicenetworking/resource_service_networking_connection_meta.yaml @@ -7,6 +7,7 @@ api_version: 'v1' api_resource_type_kind: 'Connection' fields: - field: 'deletion_policy' + provider_only: true - api_field: 'network' - api_field: 'peering' - api_field: 'reservedPeeringRanges' diff --git a/google-beta/services/servicenetworking/resource_service_networking_vpc_service_controls.go b/google-beta/services/servicenetworking/resource_service_networking_vpc_service_controls.go index 09a09811671..1d2b3458d82 100644 --- a/google-beta/services/servicenetworking/resource_service_networking_vpc_service_controls.go +++ b/google-beta/services/servicenetworking/resource_service_networking_vpc_service_controls.go @@ -333,6 +333,7 @@ func resourceServiceNetworkingVPCServiceControlsRead(d *schema.ResourceData, met } func resourceServiceNetworkingVPCServiceControlsUpdate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*transport_tpg.Config) return resourceServiceNetworkingVPCServiceControlsSet(d, meta, config) } diff --git a/google-beta/services/serviceusage/resource_service_usage_consumer_quota_override.go b/google-beta/services/serviceusage/resource_service_usage_consumer_quota_override.go index 9791a611fd5..22ffdc5b96b 100644 --- a/google-beta/services/serviceusage/resource_service_usage_consumer_quota_override.go +++ b/google-beta/services/serviceusage/resource_service_usage_consumer_quota_override.go @@ -115,6 +115,7 @@ func ResourceServiceUsageConsumerQuotaOverride() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -200,6 +201,18 @@ If 'force' is 'true', that safety check is ignored.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -389,6 +402,19 @@ func resourceServiceUsageConsumerQuotaOverrideRead(d *schema.ResourceData, meta return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading ConsumerQuotaOverride: %s", err) } @@ -438,6 +464,19 @@ func resourceServiceUsageConsumerQuotaOverrideRead(d *schema.ResourceData, meta } func resourceServiceUsageConsumerQuotaOverrideUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceServiceUsageConsumerQuotaOverride().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceServiceUsageConsumerQuotaOverrideRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -532,6 +571,13 @@ func resourceServiceUsageConsumerQuotaOverrideUpdate(d *schema.ResourceData, met } func resourceServiceUsageConsumerQuotaOverrideDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy ServiceUsageConsumerQuotaOverride without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing ConsumerQuotaOverride %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/serviceusage/resource_service_usage_consumer_quota_override_generated_meta.yaml b/google-beta/services/serviceusage/resource_service_usage_consumer_quota_override_generated_meta.yaml index ce1d847c1dd..86b8fad3104 100644 --- a/google-beta/services/serviceusage/resource_service_usage_consumer_quota_override_generated_meta.yaml +++ b/google-beta/services/serviceusage/resource_service_usage_consumer_quota_override_generated_meta.yaml @@ -18,3 +18,5 @@ fields: - api_field: overrideValue - field: service provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/siteverification/resource_site_verification_owner.go b/google-beta/services/siteverification/resource_site_verification_owner.go index 7501d7ac82f..4aa1c187869 100644 --- a/google-beta/services/siteverification/resource_site_verification_owner.go +++ b/google-beta/services/siteverification/resource_site_verification_owner.go @@ -32,6 +32,7 @@ func ResourceSiteVerificationOwner() *schema.Resource { return &schema.Resource{ Create: resourceSiteVerificationOwnerCreate, Read: resourceSiteVerificationOwnerRead, + Update: resourceSiteVerificationOwnerUpdate, Delete: resourceSiteVerificationOwnerDelete, Importer: &schema.ResourceImporter{ @@ -57,6 +58,9 @@ func ResourceSiteVerificationOwner() *schema.Resource { DiffSuppressFunc: tpgresource.CompareSelfLinkOrResourceName, Description: `The id of the Web Resource to add this owner to, in the form "webResource/".`, }, + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end }, UseJSONNumber: true, } @@ -196,10 +200,29 @@ func resourceSiteVerificationOwnerRead(d *schema.ResourceData, meta interface{}) return nil } + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + return nil } +// UDP update start +func resourceSiteVerificationOwnerUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceSiteVerificationOwnerRead(d, meta) +} + +//UDP update end + func resourceSiteVerificationOwnerDelete(d *schema.ResourceData, meta interface{}) error { + + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { + return nil + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/siteverification/resource_site_verification_owner_meta.yaml b/google-beta/services/siteverification/resource_site_verification_owner_meta.yaml index a545baa0482..48b66da6095 100644 --- a/google-beta/services/siteverification/resource_site_verification_owner_meta.yaml +++ b/google-beta/services/siteverification/resource_site_verification_owner_meta.yaml @@ -8,3 +8,5 @@ api_resource_type_kind: 'WebResource' fields: - field: 'email' - field: 'web_resource_id' + - field: 'deletion_policy' + provider_only: true diff --git a/google-beta/services/siteverification/resource_site_verification_web_resource.go b/google-beta/services/siteverification/resource_site_verification_web_resource.go index 106215b93b0..ab6b69e3627 100644 --- a/google-beta/services/siteverification/resource_site_verification_web_resource.go +++ b/google-beta/services/siteverification/resource_site_verification_web_resource.go @@ -100,6 +100,7 @@ func ResourceSiteVerificationWebResource() *schema.Resource { return &schema.Resource{ Create: resourceSiteVerificationWebResourceCreate, Read: resourceSiteVerificationWebResourceRead, + Update: resourceSiteVerificationWebResourceUpdate, Delete: resourceSiteVerificationWebResourceDelete, Importer: &schema.ResourceImporter{ @@ -174,6 +175,19 @@ for example verified owners of the containing domain—are not included in this Computed: true, Description: `The string used to identify this web resource.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -295,6 +309,20 @@ func resourceSiteVerificationWebResourceRead(d *schema.ResourceData, meta interf log.Printf("[DEBUG] Finished reading SiteVerificationWebResource %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceSiteVerificationWebResourceFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -315,7 +343,19 @@ func resourceSiteVerificationWebResourceRead(d *schema.ResourceData, meta interf return nil } +func resourceSiteVerificationWebResourceUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceSiteVerificationWebResourceRead(d, meta) +} + func resourceSiteVerificationWebResourceDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy SiteVerificationWebResource without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing WebResource %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/siteverification/resource_site_verification_web_resource_generated_meta.yaml b/google-beta/services/siteverification/resource_site_verification_web_resource_generated_meta.yaml index 7ad9bc9458c..cd8ae066d7d 100644 --- a/google-beta/services/siteverification/resource_site_verification_web_resource_generated_meta.yaml +++ b/google-beta/services/siteverification/resource_site_verification_web_resource_generated_meta.yaml @@ -14,3 +14,5 @@ fields: provider_only: true - api_field: id field: web_resource_id + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/sourcerepo/resource_sourcerepo_repository.go b/google-beta/services/sourcerepo/resource_sourcerepo_repository.go index 520a9ff6177..c3596ffdc37 100644 --- a/google-beta/services/sourcerepo/resource_sourcerepo_repository.go +++ b/google-beta/services/sourcerepo/resource_sourcerepo_repository.go @@ -176,6 +176,7 @@ func ResourceSourceRepoRepository() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -259,6 +260,18 @@ If unspecified, it defaults to the compute engine default service account.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -407,6 +420,19 @@ func resourceSourceRepoRepositoryRead(d *schema.ResourceData, meta interface{}) log.Printf("[DEBUG] Finished reading SourceRepoRepository %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Repository: %s", err) } @@ -438,6 +464,19 @@ func resourceSourceRepoRepositoryRead(d *schema.ResourceData, meta interface{}) } func resourceSourceRepoRepositoryUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceSourceRepoRepository().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceSourceRepoRepositoryRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -529,6 +568,13 @@ func resourceSourceRepoRepositoryUpdate(d *schema.ResourceData, meta interface{} } func resourceSourceRepoRepositoryDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy SourceRepoRepository without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Repository %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/sourcerepo/resource_sourcerepo_repository_generated_meta.yaml b/google-beta/services/sourcerepo/resource_sourcerepo_repository_generated_meta.yaml index 3715d0af636..a3db2cab1f4 100644 --- a/google-beta/services/sourcerepo/resource_sourcerepo_repository_generated_meta.yaml +++ b/google-beta/services/sourcerepo/resource_sourcerepo_repository_generated_meta.yaml @@ -16,3 +16,5 @@ fields: field: pubsub_configs.service_account_email - api_field: size - api_field: url + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/spanner/resource_spanner_backup_schedule.go b/google-beta/services/spanner/resource_spanner_backup_schedule.go index 0de9aa06b70..a2361f7add4 100644 --- a/google-beta/services/spanner/resource_spanner_backup_schedule.go +++ b/google-beta/services/spanner/resource_spanner_backup_schedule.go @@ -115,6 +115,7 @@ func ResourceSpannerBackupSchedule() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -273,6 +274,18 @@ database at the version time. Allowed frequencies are 12 hour, 1 day, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -452,6 +465,19 @@ func resourceSpannerBackupScheduleRead(d *schema.ResourceData, meta interface{}) return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading BackupSchedule: %s", err) } @@ -495,6 +521,19 @@ func resourceSpannerBackupScheduleRead(d *schema.ResourceData, meta interface{}) } func resourceSpannerBackupScheduleUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceSpannerBackupSchedule().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceSpannerBackupScheduleRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -633,6 +672,13 @@ func resourceSpannerBackupScheduleUpdate(d *schema.ResourceData, meta interface{ } func resourceSpannerBackupScheduleDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy SpannerBackupSchedule without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing BackupSchedule %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/spanner/resource_spanner_backup_schedule_generated_meta.yaml b/google-beta/services/spanner/resource_spanner_backup_schedule_generated_meta.yaml index 956536beb67..06be3c30a53 100644 --- a/google-beta/services/spanner/resource_spanner_backup_schedule_generated_meta.yaml +++ b/google-beta/services/spanner/resource_spanner_backup_schedule_generated_meta.yaml @@ -19,3 +19,5 @@ fields: - api_field: name - api_field: retentionDuration - api_field: spec.cronSpec.text + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/spanner/resource_spanner_database.go b/google-beta/services/spanner/resource_spanner_database.go index 45c7082a1f2..8088a77df46 100644 --- a/google-beta/services/spanner/resource_spanner_database.go +++ b/google-beta/services/spanner/resource_spanner_database.go @@ -192,6 +192,7 @@ func ResourceSpannerDatabase() *schema.Resource { resourceSpannerDBDdlCustomDiff, resourceSpannerEncryptionConfigCustomDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -340,6 +341,18 @@ from the tz database. Default value is "America/Los_angeles".`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -651,6 +664,18 @@ func resourceSpannerDatabaseRead(d *schema.ResourceData, meta interface{}) error return fmt.Errorf("Error setting deletion_protection: %s", err) } } + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Database: %s", err) } @@ -688,6 +713,19 @@ func resourceSpannerDatabaseRead(d *schema.ResourceData, meta interface{}) error } func resourceSpannerDatabaseUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceSpannerDatabase().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceSpannerDatabaseRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -885,6 +923,13 @@ func resourceSpannerDatabaseUpdate(d *schema.ResourceData, meta interface{}) err } func resourceSpannerDatabaseDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy SpannerDatabase without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Database %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/spanner/resource_spanner_database_generated_meta.yaml b/google-beta/services/spanner/resource_spanner_database_generated_meta.yaml index ad6057176aa..85b26d223f2 100644 --- a/google-beta/services/spanner/resource_spanner_database_generated_meta.yaml +++ b/google-beta/services/spanner/resource_spanner_database_generated_meta.yaml @@ -23,3 +23,5 @@ fields: - api_field: name - api_field: state - api_field: versionRetentionPeriod + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/spanner/resource_spanner_instance.go b/google-beta/services/spanner/resource_spanner_instance.go index 7c8c9eb7348..5c7c696cd2c 100644 --- a/google-beta/services/spanner/resource_spanner_instance.go +++ b/google-beta/services/spanner/resource_spanner_instance.go @@ -173,6 +173,7 @@ func ResourceSpannerInstance() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -507,6 +508,18 @@ This must be set to true if you created a backup manually in the console.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -746,6 +759,18 @@ func resourceSpannerInstanceRead(d *schema.ResourceData, meta interface{}) error return fmt.Errorf("Error setting force_destroy: %s", err) } } + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Instance: %s", err) } @@ -777,6 +802,19 @@ func resourceSpannerInstanceRead(d *schema.ResourceData, meta interface{}) error } func resourceSpannerInstanceUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceSpannerInstance().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceSpannerInstanceRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -911,6 +949,13 @@ func resourceSpannerInstanceUpdate(d *schema.ResourceData, meta interface{}) err } func resourceSpannerInstanceDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy SpannerInstance without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Instance %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/spanner/resource_spanner_instance_config.go b/google-beta/services/spanner/resource_spanner_instance_config.go index c8366320b72..721b807357f 100644 --- a/google-beta/services/spanner/resource_spanner_instance_config.go +++ b/google-beta/services/spanner/resource_spanner_instance_config.go @@ -160,6 +160,7 @@ func ResourceSpannerInstanceConfig() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -247,6 +248,18 @@ form projects//instanceConfigs/[a-z][-a-z0-9]*`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -475,6 +488,19 @@ func resourceSpannerInstanceConfigRead(d *schema.ResourceData, meta interface{}) return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading InstanceConfig: %s", err) } @@ -506,6 +532,19 @@ func resourceSpannerInstanceConfigRead(d *schema.ResourceData, meta interface{}) } func resourceSpannerInstanceConfigUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceSpannerInstanceConfig().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceSpannerInstanceConfigRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -614,6 +653,13 @@ func resourceSpannerInstanceConfigUpdate(d *schema.ResourceData, meta interface{ } func resourceSpannerInstanceConfigDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy SpannerInstanceConfig without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing InstanceConfig %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/spanner/resource_spanner_instance_config_generated_meta.yaml b/google-beta/services/spanner/resource_spanner_instance_config_generated_meta.yaml index 737fe5e4c59..cc9330ccecd 100644 --- a/google-beta/services/spanner/resource_spanner_instance_config_generated_meta.yaml +++ b/google-beta/services/spanner/resource_spanner_instance_config_generated_meta.yaml @@ -19,3 +19,5 @@ fields: - api_field: replicas.type - field: terraform_labels provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/spanner/resource_spanner_instance_generated_meta.yaml b/google-beta/services/spanner/resource_spanner_instance_generated_meta.yaml index 48dd50484f9..d8ef3bd68f1 100644 --- a/google-beta/services/spanner/resource_spanner_instance_generated_meta.yaml +++ b/google-beta/services/spanner/resource_spanner_instance_generated_meta.yaml @@ -42,3 +42,5 @@ fields: - api_field: state - field: terraform_labels provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/spanner/resource_spanner_instance_partition.go b/google-beta/services/spanner/resource_spanner_instance_partition.go index 57abcf80b22..21f0c3a0dd9 100644 --- a/google-beta/services/spanner/resource_spanner_instance_partition.go +++ b/google-beta/services/spanner/resource_spanner_instance_partition.go @@ -115,6 +115,7 @@ func ResourceSpannerInstancePartition() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -304,6 +305,18 @@ READY: The instance partition has been allocated resources and is ready for use. Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -476,6 +489,19 @@ func resourceSpannerInstancePartitionRead(d *schema.ResourceData, meta interface log.Printf("[DEBUG] Finished reading SpannerInstancePartition %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading InstancePartition: %s", err) } @@ -513,6 +539,19 @@ func resourceSpannerInstancePartitionRead(d *schema.ResourceData, meta interface } func resourceSpannerInstancePartitionUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceSpannerInstancePartition().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceSpannerInstancePartitionRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -678,6 +717,13 @@ func resourceSpannerInstancePartitionUpdate(d *schema.ResourceData, meta interfa } func resourceSpannerInstancePartitionDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy SpannerInstancePartition without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing InstancePartition %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/spanner/resource_spanner_instance_partition_generated_meta.yaml b/google-beta/services/spanner/resource_spanner_instance_partition_generated_meta.yaml index eb5b3fe4a26..dd79de8e908 100644 --- a/google-beta/services/spanner/resource_spanner_instance_partition_generated_meta.yaml +++ b/google-beta/services/spanner/resource_spanner_instance_partition_generated_meta.yaml @@ -22,3 +22,5 @@ fields: - api_field: nodeCount - api_field: processingUnits - api_field: state + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/sql/data_source_sql_database_instances_test.go b/google-beta/services/sql/data_source_sql_database_instances_test.go index eb577c0dff7..70900dc4d32 100644 --- a/google-beta/services/sql/data_source_sql_database_instances_test.go +++ b/google-beta/services/sql/data_source_sql_database_instances_test.go @@ -49,6 +49,7 @@ func TestAccDataSourceSqlDatabaseInstances_basic(t *testing.T) { map[string]struct{}{ "deletion_protection": {}, "id": {}, + "deletion_policy": {}, }, ), ), @@ -79,6 +80,7 @@ func TestAccDataSourceSqlDatabaseInstances_databaseVersionFilter(t *testing.T) { map[string]struct{}{ "deletion_protection": {}, "id": {}, + "deletion_policy": {}, }, ), ), @@ -109,6 +111,7 @@ func TestAccDataSourceSqlDatabaseInstances_regionFilter(t *testing.T) { map[string]struct{}{ "deletion_protection": {}, "id": {}, + "deletion_policy": {}, }, ), ), @@ -140,6 +143,7 @@ func TestAccDataSourceSqlDatabaseInstances_tierFilter(t *testing.T) { "deletion_protection": {}, "id": {}, "settings.0.version": {}, + "deletion_policy": {}, }, ), ), diff --git a/google-beta/services/sql/resource_sql_database.go b/google-beta/services/sql/resource_sql_database.go index a6753156453..f91b08ea8d6 100644 --- a/google-beta/services/sql/resource_sql_database.go +++ b/google-beta/services/sql/resource_sql_database.go @@ -115,6 +115,7 @@ func ResourceSQLDatabase() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -176,15 +177,6 @@ and Postgres' [Collation Support](https://www.postgresql.org/docs/9.6/static/col for more details and supported values. Postgres databases only support a value of 'en_US.UTF8' at creation time.`, }, - "deletion_policy": { - Type: schema.TypeString, - Optional: true, - Description: `The deletion policy for the database. Setting ABANDON allows the resource -to be abandoned rather than deleted. This is useful for Postgres, where databases cannot be -deleted from the API if there are users other than cloudsqlsuperuser with access. Possible -values are: "ABANDON", "DELETE". Defaults to "DELETE".`, - Default: "DELETE", - }, "project": { Type: schema.TypeString, Optional: true, @@ -195,6 +187,18 @@ values are: "ABANDON", "DELETE". Defaults to "DELETE".`, Type: schema.TypeString, Computed: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -390,8 +394,15 @@ func resourceSQLDatabaseRead(d *schema.ResourceData, meta interface{}) error { // Explicitly set virtual fields to default values if unset if _, ok := d.GetOkExists("deletion_policy"); !ok { - if err := d.Set("deletion_policy", "DELETE"); err != nil { - return fmt.Errorf("Error setting deletion_policy: %s", err) + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } } } if err := d.Set("project", project); err != nil { @@ -431,6 +442,19 @@ func resourceSQLDatabaseRead(d *schema.ResourceData, meta interface{}) error { } func resourceSQLDatabaseUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceSQLDatabase().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceSQLDatabaseRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -540,6 +564,13 @@ func resourceSQLDatabaseUpdate(d *schema.ResourceData, meta interface{}) error { } func resourceSQLDatabaseDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy SQLDatabase without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Database %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -573,11 +604,6 @@ func resourceSQLDatabaseDelete(d *schema.ResourceData, meta interface{}) error { } headers := make(http.Header) - if deletionPolicy := d.Get("deletion_policy"); deletionPolicy == "ABANDON" { - // Allows for database to be abandoned without deletion to avoid deletion failing - // for Postgres databases in some circumstances due to existing SQL users - return nil - } log.Printf("[DEBUG] Deleting Database %q", d.Id()) res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ @@ -624,11 +650,6 @@ func resourceSQLDatabaseImport(d *schema.ResourceData, meta interface{}) ([]*sch } d.SetId(id) - // Explicitly set virtual fields to default values on import - if err := d.Set("deletion_policy", "DELETE"); err != nil { - return nil, fmt.Errorf("Error setting deletion_policy: %s", err) - } - return []*schema.ResourceData{d}, nil } diff --git a/google-beta/services/sql/resource_sql_database_generated_meta.yaml b/google-beta/services/sql/resource_sql_database_generated_meta.yaml index 868ffab0228..bf2303969ad 100644 --- a/google-beta/services/sql/resource_sql_database_generated_meta.yaml +++ b/google-beta/services/sql/resource_sql_database_generated_meta.yaml @@ -9,8 +9,8 @@ api_resource_type_kind: Database fields: - api_field: charset - api_field: collation - - field: deletion_policy - provider_only: true - api_field: instance - api_field: name - api_field: selfLink + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/sql/resource_sql_database_instance.go b/google-beta/services/sql/resource_sql_database_instance.go index 7514df62004..bb9c24d909f 100644 --- a/google-beta/services/sql/resource_sql_database_instance.go +++ b/google-beta/services/sql/resource_sql_database_instance.go @@ -249,6 +249,7 @@ func ResourceSqlDatabaseInstance() *schema.Resource { pitrSupportDbCustomizeDiff, nodeCountCustomDiff, autoUpgradeEnabledCustomizeDiff, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Schema: map[string]*schema.Schema{ @@ -1504,6 +1505,9 @@ API (for read pools, effective_availability_type may differ from availability_ty }, }, }, + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end }, UseJSONNumber: true, } @@ -2427,6 +2431,10 @@ func resourceSqlDatabaseInstanceRead(d *schema.ResourceData, meta interface{}) e } d.SetId(instance.Name) + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + return nil } @@ -2439,6 +2447,11 @@ const ( ) func resourceSqlDatabaseInstanceUpdate(d *schema.ResourceData, meta interface{}) error { + + if tpgresource.DeletionPolicyPreUpdate(d, ResourceSqlDatabaseInstance) { + return ResourceSqlDatabaseInstance().Read(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -2932,6 +2945,13 @@ func serverCertificateRotationModeDiffSuppress(_, oldMode, newMode string, _ *sc } func resourceSqlDatabaseInstanceDelete(d *schema.ResourceData, meta interface{}) error { + + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { + return nil + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/sql/resource_sql_database_instance_meta.yaml b/google-beta/services/sql/resource_sql_database_instance_meta.yaml index ea5ed56fed6..8ed24c4e3b9 100644 --- a/google-beta/services/sql/resource_sql_database_instance_meta.yaml +++ b/google-beta/services/sql/resource_sql_database_instance_meta.yaml @@ -200,3 +200,5 @@ fields: - api_field: 'settings.userLabels' - api_field: 'settings.settingsVersion' field: 'settings.version' + - field: 'deletion_policy' + provider_only: true diff --git a/google-beta/services/sql/resource_sql_source_representation_instance.go b/google-beta/services/sql/resource_sql_source_representation_instance.go index fb84f11cc37..daf4d5299c1 100644 --- a/google-beta/services/sql/resource_sql_source_representation_instance.go +++ b/google-beta/services/sql/resource_sql_source_representation_instance.go @@ -100,6 +100,7 @@ func ResourceSQLSourceRepresentationInstance() *schema.Resource { return &schema.Resource{ Create: resourceSQLSourceRepresentationInstanceCreate, Read: resourceSQLSourceRepresentationInstanceRead, + Update: resourceSQLSourceRepresentationInstanceUpdate, Delete: resourceSQLSourceRepresentationInstanceDelete, Importer: &schema.ResourceImporter{ @@ -113,6 +114,7 @@ func ResourceSQLSourceRepresentationInstance() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -214,6 +216,18 @@ If it is not provided, the provider region is used.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -381,6 +395,19 @@ func resourceSQLSourceRepresentationInstanceRead(d *schema.ResourceData, meta in return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading SourceRepresentationInstance: %s", err) } @@ -411,7 +438,19 @@ func resourceSQLSourceRepresentationInstanceRead(d *schema.ResourceData, meta in return nil } +func resourceSQLSourceRepresentationInstanceUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceSQLSourceRepresentationInstanceRead(d, meta) +} + func resourceSQLSourceRepresentationInstanceDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy SQLSourceRepresentationInstance without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing SourceRepresentationInstance %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/sql/resource_sql_source_representation_instance_generated_meta.yaml b/google-beta/services/sql/resource_sql_source_representation_instance_generated_meta.yaml index a202eb1234f..69e9ef9b0c6 100644 --- a/google-beta/services/sql/resource_sql_source_representation_instance_generated_meta.yaml +++ b/google-beta/services/sql/resource_sql_source_representation_instance_generated_meta.yaml @@ -26,3 +26,5 @@ fields: - api_field: region - api_field: onPremisesConfiguration.username field: username + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/sql/resource_sql_ssl_cert.go b/google-beta/services/sql/resource_sql_ssl_cert.go index 6de1bbea2c5..4787a3b9eea 100644 --- a/google-beta/services/sql/resource_sql_ssl_cert.go +++ b/google-beta/services/sql/resource_sql_ssl_cert.go @@ -34,6 +34,7 @@ func ResourceSqlSslCert() *schema.Resource { return &schema.Resource{ Create: resourceSqlSslCertCreate, Read: resourceSqlSslCertRead, + Update: resourceSqlSslCertUpdate, Delete: resourceSqlSslCertDelete, SchemaVersion: 1, @@ -45,6 +46,7 @@ func ResourceSqlSslCert() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Schema: map[string]*schema.Schema{ @@ -114,6 +116,9 @@ func ResourceSqlSslCert() *schema.Resource { Computed: true, Description: `The SHA1 Fingerprint of the certificate.`, }, + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end }, UseJSONNumber: true, } @@ -223,10 +228,30 @@ func resourceSqlSslCertRead(d *schema.ResourceData, meta interface{}) error { } d.SetId(fmt.Sprintf("projects/%s/instances/%s/sslCerts/%s", project, instance, fingerprint)) + + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + return nil } +// UDP update start +func resourceSqlSslCertUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceSqlSslCertRead(d, meta) +} + +//UDP update end + func resourceSqlSslCertDelete(d *schema.ResourceData, meta interface{}) error { + + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { + return nil + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/sql/resource_sql_ssl_cert_meta.yaml b/google-beta/services/sql/resource_sql_ssl_cert_meta.yaml index 7f6b3d39515..42e9b3a0b99 100644 --- a/google-beta/services/sql/resource_sql_ssl_cert_meta.yaml +++ b/google-beta/services/sql/resource_sql_ssl_cert_meta.yaml @@ -16,3 +16,5 @@ fields: - field: 'project' - field: 'server_ca_cert' - api_field: 'sha1Fingerprint' + - field: 'deletion_policy' + provider_only: true diff --git a/google-beta/services/sql/resource_sql_user.go b/google-beta/services/sql/resource_sql_user.go index c200b9f23e7..31e3db5b1e5 100644 --- a/google-beta/services/sql/resource_sql_user.go +++ b/google-beta/services/sql/resource_sql_user.go @@ -30,7 +30,6 @@ import ( "github.com/hashicorp/errwrap" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" sqladmin "google.golang.org/api/sqladmin/v1beta4" ) @@ -77,6 +76,7 @@ func ResourceSqlUser() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), SchemaVersion: 1, @@ -216,14 +216,9 @@ func ResourceSqlUser() *schema.Resource { Description: `The ID of the project in which the resource belongs. If it is not provided, the provider project is used.`, }, - "deletion_policy": { - Type: schema.TypeString, - Optional: true, - Description: `The deletion policy for the user. Setting ABANDON allows the resource - to be abandoned rather than deleted. This is useful for Postgres, where users cannot be deleted from the API if they - have been granted SQL roles. Possible values are: "ABANDON".`, - ValidateFunc: validation.StringInSlice([]string{"ABANDON", ""}, false), - }, + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end "database_roles": { Type: schema.TypeList, Optional: true, @@ -464,6 +459,11 @@ func resourceSqlUserRead(d *schema.ResourceData, meta interface{}) error { } d.SetId(fmt.Sprintf("%s/%s/%s", user.Name, user.Host, user.Instance)) + + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + return nil } @@ -507,6 +507,11 @@ func flattenPasswordStatus(status *sqladmin.PasswordStatus) interface{} { } func resourceSqlUserUpdate(d *schema.ResourceData, meta interface{}) error { + + if tpgresource.DeletionPolicyPreUpdate(d, ResourceSqlUser) { + return ResourceSqlUser().Read(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -590,9 +595,9 @@ func resourceSqlUserUpdate(d *schema.ResourceData, meta interface{}) error { func resourceSqlUserDelete(d *schema.ResourceData, meta interface{}) error { config := meta.(*transport_tpg.Config) - if deletionPolicy := d.Get("deletion_policy"); deletionPolicy == "ABANDON" { - // Allows for user to be abandoned without deletion to avoid deletion failing - // for Postgres users in some circumstances due to existing SQL roles + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { return nil } diff --git a/google-beta/services/sql/resource_sql_user_meta.yaml b/google-beta/services/sql/resource_sql_user_meta.yaml index e65afe8c1d4..56f74b7c6bd 100644 --- a/google-beta/services/sql/resource_sql_user_meta.yaml +++ b/google-beta/services/sql/resource_sql_user_meta.yaml @@ -7,6 +7,7 @@ api_version: 'v1beta4' api_resource_type_kind: 'User' fields: - field: 'deletion_policy' + provider_only: true - api_field: 'host' - api_field: 'instance' - api_field: 'name' diff --git a/google-beta/services/storage/resource_storage_anywhere_cache.go b/google-beta/services/storage/resource_storage_anywhere_cache.go index 86983f30b17..53dd4ee80b8 100644 --- a/google-beta/services/storage/resource_storage_anywhere_cache.go +++ b/google-beta/services/storage/resource_storage_anywhere_cache.go @@ -189,6 +189,19 @@ func ResourceStorageAnywhereCache() *schema.Resource { Computed: true, Description: `The modification time of the cache instance metadata in RFC 3339 format.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -356,6 +369,20 @@ func resourceStorageAnywhereCacheRead(d *schema.ResourceData, meta interface{}) log.Printf("[DEBUG] Finished reading StorageAnywhereCache %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceStorageAnywhereCacheFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -383,6 +410,19 @@ func resourceStorageAnywhereCacheRead(d *schema.ResourceData, meta interface{}) } func resourceStorageAnywhereCacheUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceStorageAnywhereCache().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceStorageAnywhereCacheRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -471,6 +511,13 @@ func resourceStorageAnywhereCacheUpdate(d *schema.ResourceData, meta interface{} } func resourceStorageAnywhereCacheDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy StorageAnywhereCache without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing AnywhereCache %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/storage/resource_storage_anywhere_cache_generated_meta.yaml b/google-beta/services/storage/resource_storage_anywhere_cache_generated_meta.yaml index 7104a6e5d32..17402536250 100644 --- a/google-beta/services/storage/resource_storage_anywhere_cache_generated_meta.yaml +++ b/google-beta/services/storage/resource_storage_anywhere_cache_generated_meta.yaml @@ -18,3 +18,5 @@ fields: - api_field: ttl - api_field: updateTime - api_field: zone + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/storage/resource_storage_bucket.go b/google-beta/services/storage/resource_storage_bucket.go index 319961d7e3e..f603551bc39 100644 --- a/google-beta/services/storage/resource_storage_bucket.go +++ b/google-beta/services/storage/resource_storage_bucket.go @@ -80,6 +80,7 @@ func ResourceStorageBucket() *schema.Resource { CustomizeDiff: customdiff.All( customdiff.ForceNewIfChange("retention_policy.0.is_locked", isPolicyLocked), tpgresource.SetLabelsDiff, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Timeouts: &schema.ResourceTimeout{ @@ -711,6 +712,9 @@ func ResourceStorageBucket() *schema.Resource { return false }, }, + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end }, UseJSONNumber: true, } @@ -1023,6 +1027,11 @@ func resourceStorageBucketCreate(d *schema.ResourceData, meta interface{}) error } func resourceStorageBucketUpdate(d *schema.ResourceData, meta interface{}) error { + + if tpgresource.DeletionPolicyPreUpdate(d, ResourceStorageBucket) { + return ResourceStorageBucket().Read(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1224,6 +1233,13 @@ func resourceStorageBucketRead(d *schema.ResourceData, meta interface{}) error { } func resourceStorageBucketDelete(d *schema.ResourceData, meta interface{}) error { + + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { + return nil + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -2523,6 +2539,10 @@ func setStorageBucket(d *schema.ResourceData, config *transport_tpg.Config, res return fmt.Errorf("Error setting ip_filter: %s", err) } + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + d.SetId(res.Id) return nil } diff --git a/google-beta/services/storage/resource_storage_bucket_access_control.go b/google-beta/services/storage/resource_storage_bucket_access_control.go index 6d1c653d957..be7244e9c2d 100644 --- a/google-beta/services/storage/resource_storage_bucket_access_control.go +++ b/google-beta/services/storage/resource_storage_bucket_access_control.go @@ -176,6 +176,19 @@ Examples: Computed: true, Description: `The email address associated with the entity.`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -305,6 +318,20 @@ func resourceStorageBucketAccessControlRead(d *schema.ResourceData, meta interfa log.Printf("[DEBUG] Finished reading StorageBucketAccessControl %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceStorageBucketAccessControlFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -332,6 +359,19 @@ func resourceStorageBucketAccessControlRead(d *schema.ResourceData, meta interfa } func resourceStorageBucketAccessControlUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceStorageBucketAccessControl().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceStorageBucketAccessControlRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -416,6 +456,13 @@ func resourceStorageBucketAccessControlUpdate(d *schema.ResourceData, meta inter } func resourceStorageBucketAccessControlDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy StorageBucketAccessControl without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing BucketAccessControl %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/storage/resource_storage_bucket_access_control_generated_meta.yaml b/google-beta/services/storage/resource_storage_bucket_access_control_generated_meta.yaml index 9c2c2182598..929886bfd2d 100644 --- a/google-beta/services/storage/resource_storage_bucket_access_control_generated_meta.yaml +++ b/google-beta/services/storage/resource_storage_bucket_access_control_generated_meta.yaml @@ -12,3 +12,5 @@ fields: - api_field: email - api_field: entity - api_field: role + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/storage/resource_storage_bucket_acl.go b/google-beta/services/storage/resource_storage_bucket_acl.go index eec151961ad..511ab2bf392 100644 --- a/google-beta/services/storage/resource_storage_bucket_acl.go +++ b/google-beta/services/storage/resource_storage_bucket_acl.go @@ -27,6 +27,7 @@ import ( "github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource" transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "google.golang.org/api/storage/v1" @@ -34,11 +35,14 @@ import ( func ResourceStorageBucketAcl() *schema.Resource { return &schema.Resource{ - Create: resourceStorageBucketAclCreate, - Read: resourceStorageBucketAclRead, - Update: resourceStorageBucketAclUpdate, - Delete: resourceStorageBucketAclDelete, - CustomizeDiff: resourceStorageRoleEntityCustomizeDiff, + Create: resourceStorageBucketAclCreate, + Read: resourceStorageBucketAclRead, + Update: resourceStorageBucketAclUpdate, + Delete: resourceStorageBucketAclDelete, + CustomizeDiff: customdiff.All( + resourceStorageRoleEntityCustomizeDiff, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), + ), Schema: map[string]*schema.Schema{ "bucket": { @@ -70,6 +74,9 @@ func ResourceStorageBucketAcl() *schema.Resource { ConflictsWith: []string{"predefined_acl"}, Description: `List of role/entity pairs in the form ROLE:entity. See GCS Bucket ACL documentation for more details. Must be set if predefined_acl is not.`, }, + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end }, UseJSONNumber: true, } @@ -291,10 +298,19 @@ func resourceStorageBucketAclRead(d *schema.ResourceData, meta interface{}) erro } } + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + return nil } func resourceStorageBucketAclUpdate(d *schema.ResourceData, meta interface{}) error { + + if tpgresource.DeletionPolicyPreUpdate(d, ResourceStorageBucketAcl) { + return ResourceStorageBucketAcl().Read(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -391,6 +407,13 @@ func resourceStorageBucketAclUpdate(d *schema.ResourceData, meta interface{}) er } func resourceStorageBucketAclDelete(d *schema.ResourceData, meta interface{}) error { + + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { + return nil + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/storage/resource_storage_bucket_acl_meta.yaml b/google-beta/services/storage/resource_storage_bucket_acl_meta.yaml index d2e67bc0367..e3f4073059d 100644 --- a/google-beta/services/storage/resource_storage_bucket_acl_meta.yaml +++ b/google-beta/services/storage/resource_storage_bucket_acl_meta.yaml @@ -10,3 +10,5 @@ fields: - field: 'default_acl' - field: 'predefined_acl' - field: 'role_entity' + - field: 'deletion_policy' + provider_only: true diff --git a/google-beta/services/storage/resource_storage_bucket_meta.yaml b/google-beta/services/storage/resource_storage_bucket_meta.yaml index bd62f7b7db3..47f99ba3a3e 100644 --- a/google-beta/services/storage/resource_storage_bucket_meta.yaml +++ b/google-beta/services/storage/resource_storage_bucket_meta.yaml @@ -100,3 +100,5 @@ fields: - api_field: 'versioning.enabled' - api_field: 'website.mainPageSuffix' - api_field: 'website.notFoundPage' + - field: 'deletion_policy' + provider_only: true diff --git a/google-beta/services/storage/resource_storage_bucket_object.go b/google-beta/services/storage/resource_storage_bucket_object.go index eecff13471a..531da00737a 100644 --- a/google-beta/services/storage/resource_storage_bucket_object.go +++ b/google-beta/services/storage/resource_storage_bucket_object.go @@ -32,7 +32,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "crypto/sha256" "encoding/base64" @@ -52,6 +51,7 @@ func ResourceStorageBucketObject() *schema.Resource { CustomizeDiff: customdiff.All( resourceStorageBucketObjectCustomizeDiff, validateContexts, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Timeouts: &schema.ResourceTimeout{ @@ -368,12 +368,9 @@ func ResourceStorageBucketObject() *schema.Resource { Description: `A url reference to download this object.`, }, - "deletion_policy": { - Type: schema.TypeString, - Optional: true, - Description: `The deletion policy for the object. Setting ABANDON allows the resource to be abandoned rather than deleted when removed from your Terraform configuration.`, - ValidateFunc: validation.StringInSlice([]string{"ABANDON"}, false), - }, + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end }, UseJSONNumber: true, } @@ -481,6 +478,11 @@ func resourceStorageBucketObjectCreate(d *schema.ResourceData, meta interface{}) } func resourceStorageBucketObjectUpdate(d *schema.ResourceData, meta interface{}) error { + + if tpgresource.DeletionPolicyPreUpdate(d, ResourceStorageBucketObject) { + return ResourceStorageBucketObject().Read(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -638,12 +640,23 @@ func resourceStorageBucketObjectRead(d *schema.ResourceData, meta interface{}) e return fmt.Errorf("Error reading Contexts: %s", err) } + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + d.SetId(objectGetID(res)) return nil } func resourceStorageBucketObjectDelete(d *schema.ResourceData, meta interface{}) error { + + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { + return nil + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/storage/resource_storage_default_object_access_control.go b/google-beta/services/storage/resource_storage_default_object_access_control.go index b6a820f5054..5a09e7e4127 100644 --- a/google-beta/services/storage/resource_storage_default_object_access_control.go +++ b/google-beta/services/storage/resource_storage_default_object_access_control.go @@ -203,6 +203,19 @@ func ResourceStorageDefaultObjectAccessControl() *schema.Resource { }, }, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -338,6 +351,20 @@ func resourceStorageDefaultObjectAccessControlRead(d *schema.ResourceData, meta log.Printf("[DEBUG] Finished reading StorageDefaultObjectAccessControl %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceStorageDefaultObjectAccessControlFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -365,6 +392,19 @@ func resourceStorageDefaultObjectAccessControlRead(d *schema.ResourceData, meta } func resourceStorageDefaultObjectAccessControlUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceStorageDefaultObjectAccessControl().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceStorageDefaultObjectAccessControlRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -455,6 +495,13 @@ func resourceStorageDefaultObjectAccessControlUpdate(d *schema.ResourceData, met } func resourceStorageDefaultObjectAccessControlDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy StorageDefaultObjectAccessControl without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing DefaultObjectAccessControl %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/storage/resource_storage_default_object_access_control_generated_meta.yaml b/google-beta/services/storage/resource_storage_default_object_access_control_generated_meta.yaml index ee6c08af37e..ed29e18b3de 100644 --- a/google-beta/services/storage/resource_storage_default_object_access_control_generated_meta.yaml +++ b/google-beta/services/storage/resource_storage_default_object_access_control_generated_meta.yaml @@ -17,3 +17,5 @@ fields: - api_field: projectTeam.projectNumber - api_field: projectTeam.team - api_field: role + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/storage/resource_storage_default_object_acl.go b/google-beta/services/storage/resource_storage_default_object_acl.go index be86bcb598b..ffeb7aaef07 100644 --- a/google-beta/services/storage/resource_storage_default_object_acl.go +++ b/google-beta/services/storage/resource_storage_default_object_acl.go @@ -19,6 +19,7 @@ package storage import ( "fmt" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-google-beta/google-beta/registry" "github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource" @@ -33,6 +34,10 @@ func ResourceStorageDefaultObjectAcl() *schema.Resource { Update: resourceStorageDefaultObjectAclCreateUpdate, Delete: resourceStorageDefaultObjectAclDelete, + CustomizeDiff: customdiff.All( + tpgresource.DefaultProviderDeletionPolicy("DELETE"), + ), + Schema: map[string]*schema.Schema{ "bucket": { Type: schema.TypeString, @@ -49,12 +54,21 @@ func ResourceStorageDefaultObjectAcl() *schema.Resource { ValidateFunc: validateRoleEntityPair, }, }, + + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end }, UseJSONNumber: true, } } func resourceStorageDefaultObjectAclCreateUpdate(d *schema.ResourceData, meta interface{}) error { + + if tpgresource.DeletionPolicyPreUpdate(d, ResourceStorageDefaultObjectAcl) { + return ResourceStorageDefaultObjectAcl().Read(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -125,11 +139,22 @@ func resourceStorageDefaultObjectAclRead(d *schema.ResourceData, meta interface{ return err } + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + d.SetId(bucket) return nil } func resourceStorageDefaultObjectAclDelete(d *schema.ResourceData, meta interface{}) error { + + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { + return nil + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/storage/resource_storage_default_object_acl_meta.yaml b/google-beta/services/storage/resource_storage_default_object_acl_meta.yaml index 5ef8330a193..5736469e9af 100644 --- a/google-beta/services/storage/resource_storage_default_object_acl_meta.yaml +++ b/google-beta/services/storage/resource_storage_default_object_acl_meta.yaml @@ -8,3 +8,5 @@ api_resource_type_kind: 'ObjectAccessControl' fields: - field: 'bucket' - field: 'role_entity' + - field: 'deletion_policy' + provider_only: true diff --git a/google-beta/services/storage/resource_storage_folder.go b/google-beta/services/storage/resource_storage_folder.go index 910e3e54b5e..5b3a17734b4 100644 --- a/google-beta/services/storage/resource_storage_folder.go +++ b/google-beta/services/storage/resource_storage_folder.go @@ -183,6 +183,18 @@ trailing '/'. For example, 'example_dir/example_dir2/', 'example@#/', 'a-b/d-f/' Type: schema.TypeString, Computed: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -299,6 +311,18 @@ func resourceStorageFolderRead(d *schema.ResourceData, meta interface{}) error { return fmt.Errorf("Error setting force_destroy: %s", err) } } + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } err = ResourceStorageFolderFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { @@ -327,6 +351,19 @@ func resourceStorageFolderRead(d *schema.ResourceData, meta interface{}) error { } func resourceStorageFolderUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceStorageFolder().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceStorageFolderRead(d, meta) + } + config := meta.(*transport_tpg.Config) _ = config // we can only get here if force_destroy was updated @@ -359,6 +396,13 @@ func resourceStorageFolderUpdate(d *schema.ResourceData, meta interface{}) error } func resourceStorageFolderDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy StorageFolder without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Folder %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/storage/resource_storage_folder_generated_meta.yaml b/google-beta/services/storage/resource_storage_folder_generated_meta.yaml index 659968603d9..c4d8d6be8dd 100644 --- a/google-beta/services/storage/resource_storage_folder_generated_meta.yaml +++ b/google-beta/services/storage/resource_storage_folder_generated_meta.yaml @@ -16,3 +16,5 @@ fields: - api_field: name - api_field: updateTime - api_field: selfLink + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/storage/resource_storage_hmac_key.go b/google-beta/services/storage/resource_storage_hmac_key.go index df596ce8ae4..f48601bd5f4 100644 --- a/google-beta/services/storage/resource_storage_hmac_key.go +++ b/google-beta/services/storage/resource_storage_hmac_key.go @@ -115,6 +115,7 @@ func ResourceStorageHmacKey() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -177,6 +178,18 @@ func ResourceStorageHmacKey() *schema.Resource { Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -405,6 +418,19 @@ func resourceStorageHmacKeyRead(d *schema.ResourceData, meta interface{}) error return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading HmacKey: %s", err) } @@ -436,6 +462,19 @@ func resourceStorageHmacKeyRead(d *schema.ResourceData, meta interface{}) error } func resourceStorageHmacKeyUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceStorageHmacKey().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceStorageHmacKeyRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -536,6 +575,13 @@ func resourceStorageHmacKeyUpdate(d *schema.ResourceData, meta interface{}) erro } func resourceStorageHmacKeyDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy StorageHmacKey without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing HmacKey %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/storage/resource_storage_hmac_key_generated_meta.yaml b/google-beta/services/storage/resource_storage_hmac_key_generated_meta.yaml index ca33e730dd6..d9a547751e0 100644 --- a/google-beta/services/storage/resource_storage_hmac_key_generated_meta.yaml +++ b/google-beta/services/storage/resource_storage_hmac_key_generated_meta.yaml @@ -13,3 +13,5 @@ fields: - api_field: state - api_field: timeCreated - api_field: updated + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/storage/resource_storage_managed_folder.go b/google-beta/services/storage/resource_storage_managed_folder.go index 3b3fc2f78d9..77c582ad876 100644 --- a/google-beta/services/storage/resource_storage_managed_folder.go +++ b/google-beta/services/storage/resource_storage_managed_folder.go @@ -177,6 +177,18 @@ same name.`, Type: schema.TypeString, Computed: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -299,6 +311,18 @@ func resourceStorageManagedFolderRead(d *schema.ResourceData, meta interface{}) return fmt.Errorf("Error setting force_destroy: %s", err) } } + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } err = ResourceStorageManagedFolderFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { @@ -327,6 +351,19 @@ func resourceStorageManagedFolderRead(d *schema.ResourceData, meta interface{}) } func resourceStorageManagedFolderUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceStorageManagedFolder().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceStorageManagedFolderRead(d, meta) + } + config := meta.(*transport_tpg.Config) _ = config @@ -360,6 +397,13 @@ func resourceStorageManagedFolderUpdate(d *schema.ResourceData, meta interface{} } func resourceStorageManagedFolderDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy StorageManagedFolder without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing ManagedFolder %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/storage/resource_storage_managed_folder_generated_meta.yaml b/google-beta/services/storage/resource_storage_managed_folder_generated_meta.yaml index 90ebc3da256..af7d4670a74 100644 --- a/google-beta/services/storage/resource_storage_managed_folder_generated_meta.yaml +++ b/google-beta/services/storage/resource_storage_managed_folder_generated_meta.yaml @@ -15,3 +15,5 @@ fields: - api_field: name - api_field: updateTime - api_field: selfLink + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/storage/resource_storage_object_access_control.go b/google-beta/services/storage/resource_storage_object_access_control.go index e204a13939f..b85e4220b40 100644 --- a/google-beta/services/storage/resource_storage_object_access_control.go +++ b/google-beta/services/storage/resource_storage_object_access_control.go @@ -207,6 +207,19 @@ func ResourceStorageObjectAccessControl() *schema.Resource { }, }, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -347,6 +360,20 @@ func resourceStorageObjectAccessControlRead(d *schema.ResourceData, meta interfa log.Printf("[DEBUG] Finished reading StorageObjectAccessControl %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceStorageObjectAccessControlFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -380,6 +407,19 @@ func resourceStorageObjectAccessControlRead(d *schema.ResourceData, meta interfa } func resourceStorageObjectAccessControlUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceStorageObjectAccessControl().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceStorageObjectAccessControlRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -475,6 +515,13 @@ func resourceStorageObjectAccessControlUpdate(d *schema.ResourceData, meta inter } func resourceStorageObjectAccessControlDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy StorageObjectAccessControl without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing ObjectAccessControl %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/storage/resource_storage_object_access_control_generated_meta.yaml b/google-beta/services/storage/resource_storage_object_access_control_generated_meta.yaml index 7226c77a2a6..8614ad2caca 100644 --- a/google-beta/services/storage/resource_storage_object_access_control_generated_meta.yaml +++ b/google-beta/services/storage/resource_storage_object_access_control_generated_meta.yaml @@ -17,3 +17,5 @@ fields: - api_field: projectTeam.projectNumber - api_field: projectTeam.team - api_field: role + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/storage/resource_storage_object_acl.go b/google-beta/services/storage/resource_storage_object_acl.go index 9d1448f76b8..ea81651b538 100644 --- a/google-beta/services/storage/resource_storage_object_acl.go +++ b/google-beta/services/storage/resource_storage_object_acl.go @@ -25,6 +25,7 @@ import ( "github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource" transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "google.golang.org/api/storage/v1" @@ -32,11 +33,14 @@ import ( func ResourceStorageObjectAcl() *schema.Resource { return &schema.Resource{ - Create: resourceStorageObjectAclCreate, - Read: resourceStorageObjectAclRead, - Update: resourceStorageObjectAclUpdate, - Delete: resourceStorageObjectAclDelete, - CustomizeDiff: resourceStorageObjectAclDiff, + Create: resourceStorageObjectAclCreate, + Read: resourceStorageObjectAclRead, + Update: resourceStorageObjectAclUpdate, + Delete: resourceStorageObjectAclDelete, + CustomizeDiff: customdiff.All( + resourceStorageObjectAclDiff, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), + ), Schema: map[string]*schema.Schema{ "bucket": { @@ -68,6 +72,10 @@ func ResourceStorageObjectAcl() *schema.Resource { }, ConflictsWith: []string{"predefined_acl"}, }, + + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end }, UseJSONNumber: true, } @@ -214,11 +222,20 @@ func resourceStorageObjectAclRead(d *schema.ResourceData, meta interface{}) erro return err } + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + d.SetId(getObjectAclId(object)) return nil } func resourceStorageObjectAclUpdate(d *schema.ResourceData, meta interface{}) error { + + if tpgresource.DeletionPolicyPreUpdate(d, ResourceStorageObjectAcl) { + return ResourceStorageObjectAcl().Read(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -277,6 +294,13 @@ func resourceStorageObjectAclUpdate(d *schema.ResourceData, meta interface{}) er } func resourceStorageObjectAclDelete(d *schema.ResourceData, meta interface{}) error { + + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { + return nil + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/storage/resource_storage_object_acl_meta.yaml b/google-beta/services/storage/resource_storage_object_acl_meta.yaml index c7ad77cf205..c3df252ea4a 100644 --- a/google-beta/services/storage/resource_storage_object_acl_meta.yaml +++ b/google-beta/services/storage/resource_storage_object_acl_meta.yaml @@ -10,3 +10,5 @@ fields: - field: 'object' - field: 'predefined_acl' - field: 'role_entity' + - field: 'deletion_policy' + provider_only: true diff --git a/google-beta/services/storagebatchoperations/resource_storage_batch_operations_job.go b/google-beta/services/storagebatchoperations/resource_storage_batch_operations_job.go index 0468958756c..11ba2e65186 100644 --- a/google-beta/services/storagebatchoperations/resource_storage_batch_operations_job.go +++ b/google-beta/services/storagebatchoperations/resource_storage_batch_operations_job.go @@ -115,6 +115,7 @@ func ResourceStorageBatchOperationsJob() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -374,6 +375,18 @@ func ResourceStorageBatchOperationsJob() *schema.Resource { Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -536,6 +549,18 @@ func resourceStorageBatchOperationsJobRead(d *schema.ResourceData, meta interfac return fmt.Errorf("Error setting delete_protection: %s", err) } } + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Job: %s", err) } @@ -567,6 +592,19 @@ func resourceStorageBatchOperationsJobRead(d *schema.ResourceData, meta interfac } func resourceStorageBatchOperationsJobUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceStorageBatchOperationsJob().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceStorageBatchOperationsJobRead(d, meta) + } + config := meta.(*transport_tpg.Config) _ = config // we can only get here if delete_protection was updated @@ -581,6 +619,13 @@ func resourceStorageBatchOperationsJobUpdate(d *schema.ResourceData, meta interf } func resourceStorageBatchOperationsJobDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy StorageBatchOperationsJob without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Job %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/storagebatchoperations/resource_storage_batch_operations_job_generated_meta.yaml b/google-beta/services/storagebatchoperations/resource_storage_batch_operations_job_generated_meta.yaml index bf70fda616e..b757fbd365a 100644 --- a/google-beta/services/storagebatchoperations/resource_storage_batch_operations_job_generated_meta.yaml +++ b/google-beta/services/storagebatchoperations/resource_storage_batch_operations_job_generated_meta.yaml @@ -30,3 +30,5 @@ fields: - api_field: scheduleTime - api_field: state - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/storagecontrol/resource_storage_control_folder_intelligence_config.go b/google-beta/services/storagecontrol/resource_storage_control_folder_intelligence_config.go index 1b93a688ad4..9513d25cbda 100644 --- a/google-beta/services/storagecontrol/resource_storage_control_folder_intelligence_config.go +++ b/google-beta/services/storagecontrol/resource_storage_control_folder_intelligence_config.go @@ -423,6 +423,7 @@ func resourceStorageControlFolderIntelligenceConfigRead(d *schema.ResourceData, } func resourceStorageControlFolderIntelligenceConfigUpdate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/storagecontrol/resource_storage_control_organization_intelligence_config.go b/google-beta/services/storagecontrol/resource_storage_control_organization_intelligence_config.go index 13cfd48c316..8a0d4b35b45 100644 --- a/google-beta/services/storagecontrol/resource_storage_control_organization_intelligence_config.go +++ b/google-beta/services/storagecontrol/resource_storage_control_organization_intelligence_config.go @@ -423,6 +423,7 @@ func resourceStorageControlOrganizationIntelligenceConfigRead(d *schema.Resource } func resourceStorageControlOrganizationIntelligenceConfigUpdate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/storagecontrol/resource_storage_control_project_intelligence_config.go b/google-beta/services/storagecontrol/resource_storage_control_project_intelligence_config.go index bc1e015e8fd..40ea7f66d9f 100644 --- a/google-beta/services/storagecontrol/resource_storage_control_project_intelligence_config.go +++ b/google-beta/services/storagecontrol/resource_storage_control_project_intelligence_config.go @@ -520,6 +520,7 @@ func resourceStorageControlProjectIntelligenceConfigRead(d *schema.ResourceData, } func resourceStorageControlProjectIntelligenceConfigUpdate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/storageinsights/resource_storage_insights_dataset_config.go b/google-beta/services/storageinsights/resource_storage_insights_dataset_config.go index c4dbbef7183..ac10577311d 100644 --- a/google-beta/services/storageinsights/resource_storage_insights_dataset_config.go +++ b/google-beta/services/storageinsights/resource_storage_insights_dataset_config.go @@ -115,6 +115,7 @@ func ResourceStorageInsightsDatasetConfig() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -412,6 +413,18 @@ so users must set this field to false to unlink the dataset and destroy the data Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -661,6 +674,18 @@ func resourceStorageInsightsDatasetConfigRead(d *schema.ResourceData, meta inter return fmt.Errorf("Error setting link_dataset: %s", err) } } + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading DatasetConfig: %s", err) } @@ -698,6 +723,19 @@ func resourceStorageInsightsDatasetConfigRead(d *schema.ResourceData, meta inter } func resourceStorageInsightsDatasetConfigUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceStorageInsightsDatasetConfig().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceStorageInsightsDatasetConfigRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -960,6 +998,13 @@ func resourceStorageInsightsDatasetConfigUpdate(d *schema.ResourceData, meta int } func resourceStorageInsightsDatasetConfigDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy StorageInsightsDatasetConfig without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing DatasetConfig %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/storageinsights/resource_storage_insights_dataset_config_generated_meta.yaml b/google-beta/services/storageinsights/resource_storage_insights_dataset_config_generated_meta.yaml index 60f403697bd..8e163583745 100644 --- a/google-beta/services/storageinsights/resource_storage_insights_dataset_config_generated_meta.yaml +++ b/google-beta/services/storageinsights/resource_storage_insights_dataset_config_generated_meta.yaml @@ -36,3 +36,5 @@ fields: - api_field: sourceProjects.projectNumbers - api_field: uid - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/storageinsights/resource_storage_insights_report_config.go b/google-beta/services/storageinsights/resource_storage_insights_report_config.go index 8379453873b..df14591b4d0 100644 --- a/google-beta/services/storageinsights/resource_storage_insights_report_config.go +++ b/google-beta/services/storageinsights/resource_storage_insights_report_config.go @@ -115,6 +115,7 @@ func ResourceStorageInsightsReportConfig() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -326,6 +327,18 @@ must be in the same location.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -489,6 +502,18 @@ func resourceStorageInsightsReportConfigRead(d *schema.ResourceData, meta interf return fmt.Errorf("Error setting force_destroy: %s", err) } } + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading ReportConfig: %s", err) } @@ -526,6 +551,19 @@ func resourceStorageInsightsReportConfigRead(d *schema.ResourceData, meta interf } func resourceStorageInsightsReportConfigUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceStorageInsightsReportConfig().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceStorageInsightsReportConfigRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -659,6 +697,13 @@ func resourceStorageInsightsReportConfigUpdate(d *schema.ResourceData, meta inte } func resourceStorageInsightsReportConfigDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy StorageInsightsReportConfig without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing ReportConfig %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/storageinsights/resource_storage_insights_report_config_generated_meta.yaml b/google-beta/services/storageinsights/resource_storage_insights_report_config_generated_meta.yaml index bc2ce4a91d4..6c79fc0c907 100644 --- a/google-beta/services/storageinsights/resource_storage_insights_report_config_generated_meta.yaml +++ b/google-beta/services/storageinsights/resource_storage_insights_report_config_generated_meta.yaml @@ -28,3 +28,5 @@ fields: - api_field: objectMetadataReportOptions.storageDestinationOptions.destinationPath - api_field: objectMetadataReportOptions.storageFilters.bucket - api_field: parquetOptions + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/storagetransfer/resource_storage_transfer_agent_pool.go b/google-beta/services/storagetransfer/resource_storage_transfer_agent_pool.go index db86356622e..24ddffb2803 100644 --- a/google-beta/services/storagetransfer/resource_storage_transfer_agent_pool.go +++ b/google-beta/services/storagetransfer/resource_storage_transfer_agent_pool.go @@ -136,6 +136,7 @@ func ResourceStorageTransferAgentPool() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -204,6 +205,18 @@ As expressed by the regular expression: ^(?!goog)[a-z]([a-z0-9-._~]*[a-z0-9])?$. Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -336,6 +349,19 @@ func resourceStorageTransferAgentPoolRead(d *schema.ResourceData, meta interface log.Printf("[DEBUG] Finished reading StorageTransferAgentPool %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading AgentPool: %s", err) } @@ -367,6 +393,19 @@ func resourceStorageTransferAgentPoolRead(d *schema.ResourceData, meta interface } func resourceStorageTransferAgentPoolUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceStorageTransferAgentPool().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceStorageTransferAgentPoolRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -466,6 +505,13 @@ func resourceStorageTransferAgentPoolUpdate(d *schema.ResourceData, meta interfa } func resourceStorageTransferAgentPoolDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy StorageTransferAgentPool without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing AgentPool %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/storagetransfer/resource_storage_transfer_agent_pool_generated_meta.yaml b/google-beta/services/storagetransfer/resource_storage_transfer_agent_pool_generated_meta.yaml index 194d05074a9..f9b0bd798da 100644 --- a/google-beta/services/storagetransfer/resource_storage_transfer_agent_pool_generated_meta.yaml +++ b/google-beta/services/storagetransfer/resource_storage_transfer_agent_pool_generated_meta.yaml @@ -12,3 +12,5 @@ fields: - field: name provider_only: true - api_field: state + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/storagetransfer/resource_storage_transfer_job.go b/google-beta/services/storagetransfer/resource_storage_transfer_job.go index ba08d0a96e7..41975b858b6 100644 --- a/google-beta/services/storagetransfer/resource_storage_transfer_job.go +++ b/google-beta/services/storagetransfer/resource_storage_transfer_job.go @@ -138,6 +138,7 @@ func ResourceStorageTransferJob() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Schema: map[string]*schema.Schema{ @@ -458,6 +459,9 @@ func ResourceStorageTransferJob() *schema.Resource { Computed: true, Description: `When the Transfer Job was deleted.`, }, + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end }, UseJSONNumber: true, } @@ -1147,10 +1151,19 @@ func resourceStorageTransferJobRead(d *schema.ResourceData, meta interface{}) er return err } + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + return nil } func resourceStorageTransferJobUpdate(d *schema.ResourceData, meta interface{}) error { + + if tpgresource.DeletionPolicyPreUpdate(d, ResourceStorageTransferJob) { + return ResourceStorageTransferJob().Read(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1264,6 +1277,13 @@ func resourceStorageTransferJobUpdate(d *schema.ResourceData, meta interface{}) } func resourceStorageTransferJobDelete(d *schema.ResourceData, meta interface{}) error { + + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { + return nil + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/storagetransfer/resource_storage_transfer_job_meta.yaml b/google-beta/services/storagetransfer/resource_storage_transfer_job_meta.yaml index 3a679877830..c8d9d57c17c 100644 --- a/google-beta/services/storagetransfer/resource_storage_transfer_job_meta.yaml +++ b/google-beta/services/storagetransfer/resource_storage_transfer_job_meta.yaml @@ -111,3 +111,5 @@ fields: - api_field: 'transferSpec.transferOptions.metadataOptions.uid' - api_field: 'transferSpec.transferOptions.overwriteObjectsAlreadyExistingInSink' - api_field: 'transferSpec.transferOptions.overwriteWhen' + - field: 'deletion_policy' + provider_only: true diff --git a/google-beta/services/tags/resource_tags_location_tag_binding.go b/google-beta/services/tags/resource_tags_location_tag_binding.go index b0f93a2c5a2..b75ccd8abd4 100644 --- a/google-beta/services/tags/resource_tags_location_tag_binding.go +++ b/google-beta/services/tags/resource_tags_location_tag_binding.go @@ -29,6 +29,7 @@ import ( transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport" "google.golang.org/api/googleapi" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) @@ -36,6 +37,7 @@ func ResourceTagsLocationTagBinding() *schema.Resource { return &schema.Resource{ Create: resourceTagsLocationTagBindingCreate, Read: resourceTagsLocationTagBindingRead, + Update: resourceTagsLocationTagBindingUpdate, Delete: resourceTagsLocationTagBindingDelete, Importer: &schema.ResourceImporter{ @@ -47,6 +49,10 @@ func ResourceTagsLocationTagBinding() *schema.Resource { Delete: schema.DefaultTimeout(20 * time.Minute), }, + CustomizeDiff: customdiff.All( + tpgresource.DefaultProviderDeletionPolicy("DELETE"), + ), + Schema: map[string]*schema.Schema{ "parent": { Type: schema.TypeString, @@ -73,6 +79,9 @@ Examples: US, EU, asia-northeast1. The default value is US.`, Computed: true, Description: `The generated id for the TagBinding. This is a string of the form 'tagBindings/{full-resource-name}/{tag-value-name}' or 'tagBindings/{full-resource-name}/{tag-key-name}'`, }, + //UDP schema start + "deletion_policy": tpgresource.DeletionPolicySchemaEntry("DELETE"), + //UDP schema end }, UseJSONNumber: true, } @@ -289,10 +298,29 @@ func resourceTagsLocationTagBindingRead(d *schema.ResourceData, meta interface{} log.Printf("[DEBUG] Read: Existing tag_value in state: %s.", d.Get("tag_value").(string)) } + if err := tpgresource.DeletionPolicyReadDefault(d, config, "DELETE"); err != nil { + return err + } + return nil } +// UDP update start +func resourceTagsLocationTagBindingUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceTagsLocationTagBindingRead(d, meta) +} + +//UDP update end + func resourceTagsLocationTagBindingDelete(d *schema.ResourceData, meta interface{}) error { + + if ok, err := tpgresource.DeletionPolicyPreDelete(d); err != nil { + return err + } else if ok { + return nil + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/tags/resource_tags_location_tag_binding_meta.yaml b/google-beta/services/tags/resource_tags_location_tag_binding_meta.yaml index 0236b9583a8..608df4a8980 100644 --- a/google-beta/services/tags/resource_tags_location_tag_binding_meta.yaml +++ b/google-beta/services/tags/resource_tags_location_tag_binding_meta.yaml @@ -12,3 +12,5 @@ fields: - api_field: 'name' - api_field: 'parent' - api_field: 'tagValue' + - field: 'deletion_policy' + provider_only: true diff --git a/google-beta/services/tags/resource_tags_tag_binding.go b/google-beta/services/tags/resource_tags_tag_binding.go index 384e018f8e2..500f826b6a7 100644 --- a/google-beta/services/tags/resource_tags_tag_binding.go +++ b/google-beta/services/tags/resource_tags_tag_binding.go @@ -100,6 +100,7 @@ func ResourceTagsTagBinding() *schema.Resource { return &schema.Resource{ Create: resourceTagsTagBindingCreate, Read: resourceTagsTagBindingRead, + Update: resourceTagsTagBindingUpdate, Delete: resourceTagsTagBindingDelete, Importer: &schema.ResourceImporter{ @@ -144,6 +145,19 @@ func ResourceTagsTagBinding() *schema.Resource { Computed: true, Description: `The generated id for the TagBinding. This is a string of the form 'tagBindings/{full-resource-name}/{tag-value-name}' or 'tagBindings/{full-resource-name}/{tag-key-name}'`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -359,6 +373,20 @@ func resourceTagsTagBindingRead(d *schema.ResourceData, meta interface{}) error log.Printf("[DEBUG] Read: Existing tag_value in state: %s.", d.Get("tag_value").(string)) } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceTagsTagBindingFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -379,7 +407,19 @@ func resourceTagsTagBindingRead(d *schema.ResourceData, meta interface{}) error return nil } +func resourceTagsTagBindingUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceTagsTagBindingRead(d, meta) +} + func resourceTagsTagBindingDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy TagsTagBinding without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing TagBinding %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/tags/resource_tags_tag_binding_generated_meta.yaml b/google-beta/services/tags/resource_tags_tag_binding_generated_meta.yaml index 41a79c6d2f7..bef520ac2fa 100644 --- a/google-beta/services/tags/resource_tags_tag_binding_generated_meta.yaml +++ b/google-beta/services/tags/resource_tags_tag_binding_generated_meta.yaml @@ -10,3 +10,5 @@ fields: - api_field: name - api_field: parent - api_field: tagValue + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/tags/resource_tags_tag_key.go b/google-beta/services/tags/resource_tags_tag_key.go index 9b8ff7cc7a7..263b254074d 100644 --- a/google-beta/services/tags/resource_tags_tag_key.go +++ b/google-beta/services/tags/resource_tags_tag_key.go @@ -199,6 +199,19 @@ A timestamp in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to n A timestamp in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine fractional digits. Examples: "2014-10-02T15:01:23Z" and "2014-10-02T15:01:23.045123456Z".`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -365,6 +378,20 @@ func resourceTagsTagKeyRead(d *schema.ResourceData, meta interface{}) error { log.Printf("[DEBUG] Finished reading TagsTagKey %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceTagsTagKeyFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -386,6 +413,19 @@ func resourceTagsTagKeyRead(d *schema.ResourceData, meta interface{}) error { } func resourceTagsTagKeyUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceTagsTagKey().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceTagsTagKeyRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -485,6 +525,13 @@ func resourceTagsTagKeyUpdate(d *schema.ResourceData, meta interface{}) error { } func resourceTagsTagKeyDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy TagsTagKey without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing TagKey %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/tags/resource_tags_tag_key_generated_meta.yaml b/google-beta/services/tags/resource_tags_tag_key_generated_meta.yaml index 04c1bbc0bfd..a8f49ad68e6 100644 --- a/google-beta/services/tags/resource_tags_tag_key_generated_meta.yaml +++ b/google-beta/services/tags/resource_tags_tag_key_generated_meta.yaml @@ -17,3 +17,5 @@ fields: - api_field: purposeData - api_field: shortName - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/tags/resource_tags_tag_value.go b/google-beta/services/tags/resource_tags_tag_value.go index 1595b3c092a..08cc6804438 100644 --- a/google-beta/services/tags/resource_tags_tag_value.go +++ b/google-beta/services/tags/resource_tags_tag_value.go @@ -173,6 +173,19 @@ A timestamp in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to n Description: `Output only. Update time. A timestamp in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine fractional digits. Examples: "2014-10-02T15:01:23Z" and "2014-10-02T15:01:23.045123456Z".`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -321,6 +334,20 @@ func resourceTagsTagValueRead(d *schema.ResourceData, meta interface{}) error { log.Printf("[DEBUG] Finished reading TagsTagValue %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceTagsTagValueFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -342,6 +369,19 @@ func resourceTagsTagValueRead(d *schema.ResourceData, meta interface{}) error { } func resourceTagsTagValueUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceTagsTagValue().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceTagsTagValueRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -431,6 +471,13 @@ func resourceTagsTagValueUpdate(d *schema.ResourceData, meta interface{}) error } func resourceTagsTagValueDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy TagsTagValue without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing TagValue %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/tags/resource_tags_tag_value_generated_meta.yaml b/google-beta/services/tags/resource_tags_tag_value_generated_meta.yaml index 2bcd81246f9..e5254fd90ef 100644 --- a/google-beta/services/tags/resource_tags_tag_value_generated_meta.yaml +++ b/google-beta/services/tags/resource_tags_tag_value_generated_meta.yaml @@ -14,3 +14,5 @@ fields: - api_field: parent - api_field: shortName - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/tpuv2/resource_tpu_v2_queued_resource.go b/google-beta/services/tpuv2/resource_tpu_v2_queued_resource.go index 8f07835a1fd..13a4ff1a175 100644 --- a/google-beta/services/tpuv2/resource_tpu_v2_queued_resource.go +++ b/google-beta/services/tpuv2/resource_tpu_v2_queued_resource.go @@ -100,6 +100,7 @@ func ResourceTpuV2QueuedResource() *schema.Resource { return &schema.Resource{ Create: resourceTpuV2QueuedResourceCreate, Read: resourceTpuV2QueuedResourceRead, + Update: resourceTpuV2QueuedResourceUpdate, Delete: resourceTpuV2QueuedResourceDelete, Importer: &schema.ResourceImporter{ @@ -113,6 +114,7 @@ func ResourceTpuV2QueuedResource() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -270,6 +272,18 @@ Engine subnetwork. If none is provided, "default" will be used.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -413,6 +427,19 @@ func resourceTpuV2QueuedResourceRead(d *schema.ResourceData, meta interface{}) e log.Printf("[DEBUG] Finished reading TpuV2QueuedResource %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading QueuedResource: %s", err) } @@ -449,7 +476,19 @@ func resourceTpuV2QueuedResourceRead(d *schema.ResourceData, meta interface{}) e return nil } +func resourceTpuV2QueuedResourceUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceTpuV2QueuedResourceRead(d, meta) +} + func resourceTpuV2QueuedResourceDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy TpuV2QueuedResource without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing QueuedResource %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/tpuv2/resource_tpu_v2_queued_resource_generated_meta.yaml b/google-beta/services/tpuv2/resource_tpu_v2_queued_resource_generated_meta.yaml index 06e274c5cc4..c7f4191b62a 100644 --- a/google-beta/services/tpuv2/resource_tpu_v2_queued_resource_generated_meta.yaml +++ b/google-beta/services/tpuv2/resource_tpu_v2_queued_resource_generated_meta.yaml @@ -20,3 +20,5 @@ fields: - api_field: tpu.nodeSpec.parent - field: zone provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/tpuv2/resource_tpu_v2_vm.go b/google-beta/services/tpuv2/resource_tpu_v2_vm.go index 1634736e387..4b3f0b7f0aa 100644 --- a/google-beta/services/tpuv2/resource_tpu_v2_vm.go +++ b/google-beta/services/tpuv2/resource_tpu_v2_vm.go @@ -163,6 +163,7 @@ func ResourceTpuV2Vm() *schema.Resource { acceleratorTypeCustomizeDiff, tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -593,6 +594,18 @@ runtime clients of the node reach out to the 0th entry in this map first.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -814,6 +827,19 @@ func resourceTpuV2VmRead(d *schema.ResourceData, meta interface{}) error { log.Printf("[DEBUG] Finished reading TpuV2Vm %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Vm: %s", err) } @@ -851,6 +877,19 @@ func resourceTpuV2VmRead(d *schema.ResourceData, meta interface{}) error { } func resourceTpuV2VmUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceTpuV2Vm().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceTpuV2VmRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -989,6 +1028,13 @@ func resourceTpuV2VmUpdate(d *schema.ResourceData, meta interface{}) error { } func resourceTpuV2VmDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy TpuV2Vm without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Vm %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/tpuv2/resource_tpu_v2_vm_generated_meta.yaml b/google-beta/services/tpuv2/resource_tpu_v2_vm_generated_meta.yaml index 6a071b1a66f..156a92138e4 100644 --- a/google-beta/services/tpuv2/resource_tpu_v2_vm_generated_meta.yaml +++ b/google-beta/services/tpuv2/resource_tpu_v2_vm_generated_meta.yaml @@ -54,3 +54,5 @@ fields: provider_only: true - field: zone provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/transcoder/resource_transcoder_job.go b/google-beta/services/transcoder/resource_transcoder_job.go index 5d32161e863..0777209d2b1 100644 --- a/google-beta/services/transcoder/resource_transcoder_job.go +++ b/google-beta/services/transcoder/resource_transcoder_job.go @@ -116,6 +116,7 @@ func ResourceTranscoderJob() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -870,6 +871,18 @@ The default is preset/web-hd, which is the only supported preset.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -1010,6 +1023,19 @@ func resourceTranscoderJobRead(d *schema.ResourceData, meta interface{}) error { log.Printf("[DEBUG] Finished reading TranscoderJob %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Job: %s", err) } @@ -1041,11 +1067,18 @@ func resourceTranscoderJobRead(d *schema.ResourceData, meta interface{}) error { } func resourceTranscoderJobUpdate(d *schema.ResourceData, meta interface{}) error { - // Only the root field "labels", "terraform_labels", and virtual fields are mutable + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable return resourceTranscoderJobRead(d, meta) } func resourceTranscoderJobDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy TranscoderJob without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Job %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/transcoder/resource_transcoder_job_generated_meta.yaml b/google-beta/services/transcoder/resource_transcoder_job_generated_meta.yaml index ef9f437fc7d..110488c2387 100644 --- a/google-beta/services/transcoder/resource_transcoder_job_generated_meta.yaml +++ b/google-beta/services/transcoder/resource_transcoder_job_generated_meta.yaml @@ -73,3 +73,5 @@ fields: - api_field: templateId - field: terraform_labels provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/transcoder/resource_transcoder_job_template.go b/google-beta/services/transcoder/resource_transcoder_job_template.go index 92d3d03e463..e178626a625 100644 --- a/google-beta/services/transcoder/resource_transcoder_job_template.go +++ b/google-beta/services/transcoder/resource_transcoder_job_template.go @@ -116,6 +116,7 @@ func ResourceTranscoderJobTemplate() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -852,6 +853,18 @@ Please refer to the field 'effective_labels' for all of the labels present on th Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -985,6 +998,19 @@ func resourceTranscoderJobTemplateRead(d *schema.ResourceData, meta interface{}) log.Printf("[DEBUG] Finished reading TranscoderJobTemplate %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading JobTemplate: %s", err) } @@ -1022,11 +1048,18 @@ func resourceTranscoderJobTemplateRead(d *schema.ResourceData, meta interface{}) } func resourceTranscoderJobTemplateUpdate(d *schema.ResourceData, meta interface{}) error { - // Only the root field "labels", "terraform_labels", and virtual fields are mutable + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable return resourceTranscoderJobTemplateRead(d, meta) } func resourceTranscoderJobTemplateDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy TranscoderJobTemplate without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing JobTemplate %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/transcoder/resource_transcoder_job_template_generated_meta.yaml b/google-beta/services/transcoder/resource_transcoder_job_template_generated_meta.yaml index 84d3da2a1cd..10a13377b6a 100644 --- a/google-beta/services/transcoder/resource_transcoder_job_template_generated_meta.yaml +++ b/google-beta/services/transcoder/resource_transcoder_job_template_generated_meta.yaml @@ -70,3 +70,5 @@ fields: - api_field: name - field: terraform_labels provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/vectorsearch/resource_vector_search_collection.go b/google-beta/services/vectorsearch/resource_vector_search_collection.go index de3d01150aa..a6d3d066e50 100644 --- a/google-beta/services/vectorsearch/resource_vector_search_collection.go +++ b/google-beta/services/vectorsearch/resource_vector_search_collection.go @@ -116,6 +116,7 @@ func ResourceVectorSearchCollection() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -322,6 +323,18 @@ contain one or more references to fields in the DataObject, e.g.: Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -489,6 +502,19 @@ func resourceVectorSearchCollectionRead(d *schema.ResourceData, meta interface{} log.Printf("[DEBUG] Finished reading VectorSearchCollection %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Collection: %s", err) } @@ -526,6 +552,19 @@ func resourceVectorSearchCollectionRead(d *schema.ResourceData, meta interface{} } func resourceVectorSearchCollectionUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceVectorSearchCollection().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceVectorSearchCollectionRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -664,6 +703,13 @@ func resourceVectorSearchCollectionUpdate(d *schema.ResourceData, meta interface } func resourceVectorSearchCollectionDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy VectorSearchCollection without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Collection %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/vectorsearch/resource_vector_search_collection_generated_meta.yaml b/google-beta/services/vectorsearch/resource_vector_search_collection_generated_meta.yaml index 9b537ea6beb..5bbe368ad2e 100644 --- a/google-beta/services/vectorsearch/resource_vector_search_collection_generated_meta.yaml +++ b/google-beta/services/vectorsearch/resource_vector_search_collection_generated_meta.yaml @@ -37,3 +37,5 @@ fields: field: vector_schema.dense_vector.vertex_embedding_config.text_template - api_field: vectorSchema.value.sparseVector field: vector_schema.sparse_vector + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/vertexai/resource_vertex_ai_cache_config.go b/google-beta/services/vertexai/resource_vertex_ai_cache_config.go index b47de3550c3..edc33e4834b 100644 --- a/google-beta/services/vertexai/resource_vertex_ai_cache_config.go +++ b/google-beta/services/vertexai/resource_vertex_ai_cache_config.go @@ -301,6 +301,7 @@ func resourceVertexAICacheConfigRead(d *schema.ResourceData, meta interface{}) e } func resourceVertexAICacheConfigUpdate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/vertexai/resource_vertex_ai_dataset.go b/google-beta/services/vertexai/resource_vertex_ai_dataset.go index dfa80274e64..655b6a40eca 100644 --- a/google-beta/services/vertexai/resource_vertex_ai_dataset.go +++ b/google-beta/services/vertexai/resource_vertex_ai_dataset.go @@ -112,6 +112,7 @@ func ResourceVertexAIDataset() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -218,6 +219,18 @@ Please refer to the field 'effective_labels' for all of the labels present on th Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -387,6 +400,19 @@ func resourceVertexAIDatasetRead(d *schema.ResourceData, meta interface{}) error log.Printf("[DEBUG] Finished reading VertexAIDataset %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Dataset: %s", err) } @@ -424,6 +450,19 @@ func resourceVertexAIDatasetRead(d *schema.ResourceData, meta interface{}) error } func resourceVertexAIDatasetUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceVertexAIDataset().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceVertexAIDatasetRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -525,6 +564,13 @@ func resourceVertexAIDatasetUpdate(d *schema.ResourceData, meta interface{}) err } func resourceVertexAIDatasetDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy VertexAIDataset without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Dataset %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/vertexai/resource_vertex_ai_dataset_generated_meta.yaml b/google-beta/services/vertexai/resource_vertex_ai_dataset_generated_meta.yaml index a4affbb6a2b..a849e93de73 100644 --- a/google-beta/services/vertexai/resource_vertex_ai_dataset_generated_meta.yaml +++ b/google-beta/services/vertexai/resource_vertex_ai_dataset_generated_meta.yaml @@ -22,3 +22,5 @@ fields: - field: terraform_labels provider_only: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/vertexai/resource_vertex_ai_deployment_resource_pool.go b/google-beta/services/vertexai/resource_vertex_ai_deployment_resource_pool.go index f79efc6d880..d9835d80382 100644 --- a/google-beta/services/vertexai/resource_vertex_ai_deployment_resource_pool.go +++ b/google-beta/services/vertexai/resource_vertex_ai_deployment_resource_pool.go @@ -100,6 +100,7 @@ func ResourceVertexAIDeploymentResourcePool() *schema.Resource { return &schema.Resource{ Create: resourceVertexAIDeploymentResourcePoolCreate, Read: resourceVertexAIDeploymentResourcePoolRead, + Update: resourceVertexAIDeploymentResourcePoolUpdate, Delete: resourceVertexAIDeploymentResourcePoolDelete, Importer: &schema.ResourceImporter{ @@ -113,6 +114,7 @@ func ResourceVertexAIDeploymentResourcePool() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -236,6 +238,18 @@ func ResourceVertexAIDeploymentResourcePool() *schema.Resource { Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -384,6 +398,19 @@ func resourceVertexAIDeploymentResourcePoolRead(d *schema.ResourceData, meta int log.Printf("[DEBUG] Finished reading VertexAIDeploymentResourcePool %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading DeploymentResourcePool: %s", err) } @@ -420,7 +447,19 @@ func resourceVertexAIDeploymentResourcePoolRead(d *schema.ResourceData, meta int return nil } +func resourceVertexAIDeploymentResourcePoolUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceVertexAIDeploymentResourcePoolRead(d, meta) +} + func resourceVertexAIDeploymentResourcePoolDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy VertexAIDeploymentResourcePool without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing DeploymentResourcePool %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/vertexai/resource_vertex_ai_deployment_resource_pool_generated_meta.yaml b/google-beta/services/vertexai/resource_vertex_ai_deployment_resource_pool_generated_meta.yaml index a9ebb34e64d..bd17b6db295 100644 --- a/google-beta/services/vertexai/resource_vertex_ai_deployment_resource_pool_generated_meta.yaml +++ b/google-beta/services/vertexai/resource_vertex_ai_deployment_resource_pool_generated_meta.yaml @@ -18,3 +18,5 @@ fields: - api_field: name - field: region provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/vertexai/resource_vertex_ai_endpoint.go b/google-beta/services/vertexai/resource_vertex_ai_endpoint.go index 5457bc32f4e..aa1a2635363 100644 --- a/google-beta/services/vertexai/resource_vertex_ai_endpoint.go +++ b/google-beta/services/vertexai/resource_vertex_ai_endpoint.go @@ -116,6 +116,7 @@ func ResourceVertexAIEndpoint() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -535,6 +536,18 @@ the 'deployModel' [example](https://cloud.google.com/vertex-ai/docs/general/depl Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -720,6 +733,19 @@ func resourceVertexAIEndpointRead(d *schema.ResourceData, meta interface{}) erro log.Printf("[DEBUG] Finished reading VertexAIEndpoint %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Endpoint: %s", err) } @@ -757,6 +783,19 @@ func resourceVertexAIEndpointRead(d *schema.ResourceData, meta interface{}) erro } func resourceVertexAIEndpointUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceVertexAIEndpoint().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceVertexAIEndpointRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -908,6 +947,13 @@ func resourceVertexAIEndpointUpdate(d *schema.ResourceData, meta interface{}) er } func resourceVertexAIEndpointDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy VertexAIEndpoint without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Endpoint %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/vertexai/resource_vertex_ai_endpoint_generated_meta.yaml b/google-beta/services/vertexai/resource_vertex_ai_endpoint_generated_meta.yaml index aa224eb2c01..d9be72b3cbd 100644 --- a/google-beta/services/vertexai/resource_vertex_ai_endpoint_generated_meta.yaml +++ b/google-beta/services/vertexai/resource_vertex_ai_endpoint_generated_meta.yaml @@ -66,3 +66,5 @@ fields: - api_field: trafficSplit json: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/vertexai/resource_vertex_ai_endpoint_with_model_garden_deployment.go b/google-beta/services/vertexai/resource_vertex_ai_endpoint_with_model_garden_deployment.go index d49dacb1f77..49ad1443673 100644 --- a/google-beta/services/vertexai/resource_vertex_ai_endpoint_with_model_garden_deployment.go +++ b/google-beta/services/vertexai/resource_vertex_ai_endpoint_with_model_garden_deployment.go @@ -100,6 +100,7 @@ func ResourceVertexAIEndpointWithModelGardenDeployment() *schema.Resource { return &schema.Resource{ Create: resourceVertexAIEndpointWithModelGardenDeploymentCreate, Read: resourceVertexAIEndpointWithModelGardenDeploymentRead, + Update: resourceVertexAIEndpointWithModelGardenDeploymentUpdate, Delete: resourceVertexAIEndpointWithModelGardenDeploymentDelete, Timeouts: &schema.ResourceTimeout{ @@ -109,6 +110,7 @@ func ResourceVertexAIEndpointWithModelGardenDeployment() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Schema: map[string]*schema.Schema{ @@ -1448,6 +1450,18 @@ https://cloud.google.com/vertex-ai/docs/reference/rest/v1/projects.locations.end Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -1709,7 +1723,19 @@ func resourceVertexAIEndpointWithModelGardenDeploymentRead(d *schema.ResourceDat return nil } +func resourceVertexAIEndpointWithModelGardenDeploymentUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceVertexAIEndpointWithModelGardenDeploymentRead(d, meta) +} + func resourceVertexAIEndpointWithModelGardenDeploymentDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy VertexAIEndpointWithModelGardenDeployment without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing EndpointWithModelGardenDeployment %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/vertexai/resource_vertex_ai_endpoint_with_model_garden_deployment_generated_meta.yaml b/google-beta/services/vertexai/resource_vertex_ai_endpoint_with_model_garden_deployment_generated_meta.yaml index c1df2a96a0b..29d9db1a140 100644 --- a/google-beta/services/vertexai/resource_vertex_ai_endpoint_with_model_garden_deployment_generated_meta.yaml +++ b/google-beta/services/vertexai/resource_vertex_ai_endpoint_with_model_garden_deployment_generated_meta.yaml @@ -106,3 +106,5 @@ fields: - api_field: modelConfig.huggingFaceCacheEnabled - api_field: modelConfig.modelDisplayName - api_field: publisherModelName + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/vertexai/resource_vertex_ai_feature_group.go b/google-beta/services/vertexai/resource_vertex_ai_feature_group.go index bfeeff94a05..3690d33f8bb 100644 --- a/google-beta/services/vertexai/resource_vertex_ai_feature_group.go +++ b/google-beta/services/vertexai/resource_vertex_ai_feature_group.go @@ -116,6 +116,7 @@ func ResourceVertexAIFeatureGroup() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -236,6 +237,18 @@ Please refer to the field 'effective_labels' for all of the labels present on th Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -391,6 +404,19 @@ func resourceVertexAIFeatureGroupRead(d *schema.ResourceData, meta interface{}) log.Printf("[DEBUG] Finished reading VertexAIFeatureGroup %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading FeatureGroup: %s", err) } @@ -428,6 +454,19 @@ func resourceVertexAIFeatureGroupRead(d *schema.ResourceData, meta interface{}) } func resourceVertexAIFeatureGroupUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceVertexAIFeatureGroup().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceVertexAIFeatureGroupRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -556,6 +595,13 @@ func resourceVertexAIFeatureGroupUpdate(d *schema.ResourceData, meta interface{} } func resourceVertexAIFeatureGroupDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy VertexAIFeatureGroup without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing FeatureGroup %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/vertexai/resource_vertex_ai_feature_group_feature.go b/google-beta/services/vertexai/resource_vertex_ai_feature_group_feature.go index 5d203357c9a..a2186595cc8 100644 --- a/google-beta/services/vertexai/resource_vertex_ai_feature_group_feature.go +++ b/google-beta/services/vertexai/resource_vertex_ai_feature_group_feature.go @@ -116,6 +116,7 @@ func ResourceVertexAIFeatureGroupFeature() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -213,6 +214,18 @@ Please refer to the field 'effective_labels' for all of the labels present on th Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -367,6 +380,19 @@ func resourceVertexAIFeatureGroupFeatureRead(d *schema.ResourceData, meta interf log.Printf("[DEBUG] Finished reading VertexAIFeatureGroupFeature %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading FeatureGroupFeature: %s", err) } @@ -410,6 +436,19 @@ func resourceVertexAIFeatureGroupFeatureRead(d *schema.ResourceData, meta interf } func resourceVertexAIFeatureGroupFeatureUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceVertexAIFeatureGroupFeature().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceVertexAIFeatureGroupFeatureRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -533,6 +572,13 @@ func resourceVertexAIFeatureGroupFeatureUpdate(d *schema.ResourceData, meta inte } func resourceVertexAIFeatureGroupFeatureDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy VertexAIFeatureGroupFeature without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing FeatureGroupFeature %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/vertexai/resource_vertex_ai_feature_group_feature_generated_meta.yaml b/google-beta/services/vertexai/resource_vertex_ai_feature_group_feature_generated_meta.yaml index d9f2e1e7db4..2a970c372b5 100644 --- a/google-beta/services/vertexai/resource_vertex_ai_feature_group_feature_generated_meta.yaml +++ b/google-beta/services/vertexai/resource_vertex_ai_feature_group_feature_generated_meta.yaml @@ -24,3 +24,5 @@ fields: provider_only: true - api_field: updateTime - api_field: versionColumnName + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/vertexai/resource_vertex_ai_feature_group_generated_meta.yaml b/google-beta/services/vertexai/resource_vertex_ai_feature_group_generated_meta.yaml index e45e5bc52c1..72ddf7532b2 100644 --- a/google-beta/services/vertexai/resource_vertex_ai_feature_group_generated_meta.yaml +++ b/google-beta/services/vertexai/resource_vertex_ai_feature_group_generated_meta.yaml @@ -21,3 +21,5 @@ fields: - field: terraform_labels provider_only: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/vertexai/resource_vertex_ai_feature_online_store.go b/google-beta/services/vertexai/resource_vertex_ai_feature_online_store.go index 4d164835f4e..5a8e82fa0e1 100644 --- a/google-beta/services/vertexai/resource_vertex_ai_feature_online_store.go +++ b/google-beta/services/vertexai/resource_vertex_ai_feature_online_store.go @@ -116,6 +116,7 @@ func ResourceVertexAIFeatureOnlineStore() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -346,6 +347,18 @@ Please refer to the field 'effective_labels' for all of the labels present on th Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -519,6 +532,18 @@ func resourceVertexAIFeatureOnlineStoreRead(d *schema.ResourceData, meta interfa return fmt.Errorf("Error setting force_destroy: %s", err) } } + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading FeatureOnlineStore: %s", err) } @@ -556,6 +581,19 @@ func resourceVertexAIFeatureOnlineStoreRead(d *schema.ResourceData, meta interfa } func resourceVertexAIFeatureOnlineStoreUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceVertexAIFeatureOnlineStore().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceVertexAIFeatureOnlineStoreRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -704,6 +742,13 @@ func resourceVertexAIFeatureOnlineStoreUpdate(d *schema.ResourceData, meta inter } func resourceVertexAIFeatureOnlineStoreDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy VertexAIFeatureOnlineStore without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing FeatureOnlineStore %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/vertexai/resource_vertex_ai_feature_online_store_featureview.go b/google-beta/services/vertexai/resource_vertex_ai_feature_online_store_featureview.go index c4f4de37560..6e00f90c745 100644 --- a/google-beta/services/vertexai/resource_vertex_ai_feature_online_store_featureview.go +++ b/google-beta/services/vertexai/resource_vertex_ai_feature_online_store_featureview.go @@ -116,6 +116,7 @@ func ResourceVertexAIFeatureOnlineStoreFeatureview() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -360,6 +361,18 @@ For details on allowed values, see the [API documentation](https://cloud.google. Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -526,6 +539,19 @@ func resourceVertexAIFeatureOnlineStoreFeatureviewRead(d *schema.ResourceData, m log.Printf("[DEBUG] Finished reading VertexAIFeatureOnlineStoreFeatureview %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading FeatureOnlineStoreFeatureview: %s", err) } @@ -569,6 +595,19 @@ func resourceVertexAIFeatureOnlineStoreFeatureviewRead(d *schema.ResourceData, m } func resourceVertexAIFeatureOnlineStoreFeatureviewUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceVertexAIFeatureOnlineStoreFeatureview().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceVertexAIFeatureOnlineStoreFeatureviewRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -695,6 +734,13 @@ func resourceVertexAIFeatureOnlineStoreFeatureviewUpdate(d *schema.ResourceData, } func resourceVertexAIFeatureOnlineStoreFeatureviewDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy VertexAIFeatureOnlineStoreFeatureview without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing FeatureOnlineStoreFeatureview %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/vertexai/resource_vertex_ai_feature_online_store_featureview_generated_meta.yaml b/google-beta/services/vertexai/resource_vertex_ai_feature_online_store_featureview_generated_meta.yaml index 08ce6b5ee1a..60e2a1f3d3c 100644 --- a/google-beta/services/vertexai/resource_vertex_ai_feature_online_store_featureview_generated_meta.yaml +++ b/google-beta/services/vertexai/resource_vertex_ai_feature_online_store_featureview_generated_meta.yaml @@ -34,3 +34,5 @@ fields: - api_field: vectorSearchConfig.embeddingDimension - api_field: vectorSearchConfig.filterColumns - api_field: vectorSearchConfig.treeAhConfig.leafNodeEmbeddingCount + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/vertexai/resource_vertex_ai_feature_online_store_generated_meta.yaml b/google-beta/services/vertexai/resource_vertex_ai_feature_online_store_generated_meta.yaml index 494ef144775..2ff5716ede0 100644 --- a/google-beta/services/vertexai/resource_vertex_ai_feature_online_store_generated_meta.yaml +++ b/google-beta/services/vertexai/resource_vertex_ai_feature_online_store_generated_meta.yaml @@ -34,3 +34,5 @@ fields: - field: terraform_labels provider_only: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/vertexai/resource_vertex_ai_featurestore.go b/google-beta/services/vertexai/resource_vertex_ai_featurestore.go index a1a9c627ffa..939889bf669 100644 --- a/google-beta/services/vertexai/resource_vertex_ai_featurestore.go +++ b/google-beta/services/vertexai/resource_vertex_ai_featurestore.go @@ -116,6 +116,7 @@ func ResourceVertexAIFeaturestore() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -263,6 +264,18 @@ Please refer to the field 'effective_labels' for all of the labels present on th Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -424,6 +437,18 @@ func resourceVertexAIFeaturestoreRead(d *schema.ResourceData, meta interface{}) return fmt.Errorf("Error setting force_destroy: %s", err) } } + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Featurestore: %s", err) } @@ -461,6 +486,19 @@ func resourceVertexAIFeaturestoreRead(d *schema.ResourceData, meta interface{}) } func resourceVertexAIFeaturestoreUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceVertexAIFeaturestore().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceVertexAIFeaturestoreRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -589,6 +627,13 @@ func resourceVertexAIFeaturestoreUpdate(d *schema.ResourceData, meta interface{} } func resourceVertexAIFeaturestoreDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy VertexAIFeaturestore without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Featurestore %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/vertexai/resource_vertex_ai_featurestore_entitytype.go b/google-beta/services/vertexai/resource_vertex_ai_featurestore_entitytype.go index 0f274c7fd41..4527cece8c1 100644 --- a/google-beta/services/vertexai/resource_vertex_ai_featurestore_entitytype.go +++ b/google-beta/services/vertexai/resource_vertex_ai_featurestore_entitytype.go @@ -115,6 +115,7 @@ func ResourceVertexAIFeaturestoreEntitytype() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -309,6 +310,19 @@ If both FeaturestoreMonitoringConfig.SnapshotAnalysis.monitoring_interval_days a Computed: true, Description: "The region of the EntityType.", }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -462,6 +476,20 @@ func resourceVertexAIFeaturestoreEntitytypeRead(d *schema.ResourceData, meta int log.Printf("[DEBUG] Finished reading VertexAIFeaturestoreEntitytype %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceVertexAIFeaturestoreEntitytypeFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -489,6 +517,19 @@ func resourceVertexAIFeaturestoreEntitytypeRead(d *schema.ResourceData, meta int } func resourceVertexAIFeaturestoreEntitytypeUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceVertexAIFeaturestoreEntitytype().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceVertexAIFeaturestoreEntitytypeRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -604,6 +645,13 @@ func resourceVertexAIFeaturestoreEntitytypeUpdate(d *schema.ResourceData, meta i } func resourceVertexAIFeaturestoreEntitytypeDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy VertexAIFeaturestoreEntitytype without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing FeaturestoreEntitytype %q from Terraform state without deletion", d.Id()) + return nil + } var project string config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) diff --git a/google-beta/services/vertexai/resource_vertex_ai_featurestore_entitytype_feature.go b/google-beta/services/vertexai/resource_vertex_ai_featurestore_entitytype_feature.go index 3544ce50ed3..32434e4eee6 100644 --- a/google-beta/services/vertexai/resource_vertex_ai_featurestore_entitytype_feature.go +++ b/google-beta/services/vertexai/resource_vertex_ai_featurestore_entitytype_feature.go @@ -115,6 +115,7 @@ func ResourceVertexAIFeaturestoreEntitytypeFeature() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -203,6 +204,19 @@ Please refer to the field 'effective_labels' for all of the labels present on th Computed: true, Description: "The region of the feature", }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -350,6 +364,20 @@ func resourceVertexAIFeaturestoreEntitytypeFeatureRead(d *schema.ResourceData, m log.Printf("[DEBUG] Finished reading VertexAIFeaturestoreEntitytypeFeature %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceVertexAIFeaturestoreEntitytypeFeatureFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -377,6 +405,19 @@ func resourceVertexAIFeaturestoreEntitytypeFeatureRead(d *schema.ResourceData, m } func resourceVertexAIFeaturestoreEntitytypeFeatureUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceVertexAIFeaturestoreEntitytypeFeature().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceVertexAIFeaturestoreEntitytypeFeatureRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -472,6 +513,13 @@ func resourceVertexAIFeaturestoreEntitytypeFeatureUpdate(d *schema.ResourceData, } func resourceVertexAIFeaturestoreEntitytypeFeatureDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy VertexAIFeaturestoreEntitytypeFeature without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing FeaturestoreEntitytypeFeature %q from Terraform state without deletion", d.Id()) + return nil + } var project string config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) diff --git a/google-beta/services/vertexai/resource_vertex_ai_featurestore_entitytype_feature_generated_meta.yaml b/google-beta/services/vertexai/resource_vertex_ai_featurestore_entitytype_feature_generated_meta.yaml index f816f3bc2d3..d91f43aa9b8 100644 --- a/google-beta/services/vertexai/resource_vertex_ai_featurestore_entitytype_feature_generated_meta.yaml +++ b/google-beta/services/vertexai/resource_vertex_ai_featurestore_entitytype_feature_generated_meta.yaml @@ -23,3 +23,5 @@ fields: provider_only: true - api_field: updateTime - api_field: valueType + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/vertexai/resource_vertex_ai_featurestore_entitytype_generated_meta.yaml b/google-beta/services/vertexai/resource_vertex_ai_featurestore_entitytype_generated_meta.yaml index 433e81ecf4a..7433c303ac4 100644 --- a/google-beta/services/vertexai/resource_vertex_ai_featurestore_entitytype_generated_meta.yaml +++ b/google-beta/services/vertexai/resource_vertex_ai_featurestore_entitytype_generated_meta.yaml @@ -29,3 +29,5 @@ fields: - field: terraform_labels provider_only: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/vertexai/resource_vertex_ai_featurestore_generated_meta.yaml b/google-beta/services/vertexai/resource_vertex_ai_featurestore_generated_meta.yaml index 153c67fa9d5..ab955d355df 100644 --- a/google-beta/services/vertexai/resource_vertex_ai_featurestore_generated_meta.yaml +++ b/google-beta/services/vertexai/resource_vertex_ai_featurestore_generated_meta.yaml @@ -26,3 +26,5 @@ fields: - field: terraform_labels provider_only: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/vertexai/resource_vertex_ai_index.go b/google-beta/services/vertexai/resource_vertex_ai_index.go index 870141abac6..7909ea83ce4 100644 --- a/google-beta/services/vertexai/resource_vertex_ai_index.go +++ b/google-beta/services/vertexai/resource_vertex_ai_index.go @@ -116,6 +116,7 @@ func ResourceVertexAIIndex() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -403,6 +404,18 @@ Please refer to the field 'effective_labels' for all of the labels present on th Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -584,6 +597,19 @@ func resourceVertexAIIndexRead(d *schema.ResourceData, meta interface{}) error { log.Printf("[DEBUG] Finished reading VertexAIIndex %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Index: %s", err) } @@ -621,6 +647,19 @@ func resourceVertexAIIndexRead(d *schema.ResourceData, meta interface{}) error { } func resourceVertexAIIndexUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceVertexAIIndex().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceVertexAIIndexRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -768,6 +807,13 @@ func resourceVertexAIIndexUpdate(d *schema.ResourceData, meta interface{}) error } func resourceVertexAIIndexDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy VertexAIIndex without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Index %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/vertexai/resource_vertex_ai_index_endpoint.go b/google-beta/services/vertexai/resource_vertex_ai_index_endpoint.go index 8a612f4ef95..77946cb7680 100644 --- a/google-beta/services/vertexai/resource_vertex_ai_index_endpoint.go +++ b/google-beta/services/vertexai/resource_vertex_ai_index_endpoint.go @@ -116,6 +116,7 @@ func ResourceVertexAIIndexEndpoint() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -291,6 +292,18 @@ Where '{project}' is a project number, as in '12345', and '{network}' is network Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -478,6 +491,19 @@ func resourceVertexAIIndexEndpointRead(d *schema.ResourceData, meta interface{}) log.Printf("[DEBUG] Finished reading VertexAIIndexEndpoint %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading IndexEndpoint: %s", err) } @@ -515,6 +541,19 @@ func resourceVertexAIIndexEndpointRead(d *schema.ResourceData, meta interface{}) } func resourceVertexAIIndexEndpointUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceVertexAIIndexEndpoint().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceVertexAIIndexEndpointRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -626,6 +665,13 @@ func resourceVertexAIIndexEndpointUpdate(d *schema.ResourceData, meta interface{ } func resourceVertexAIIndexEndpointDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy VertexAIIndexEndpoint without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing IndexEndpoint %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/vertexai/resource_vertex_ai_index_endpoint_deployed_index.go b/google-beta/services/vertexai/resource_vertex_ai_index_endpoint_deployed_index.go index 17c44481508..e1226157a1f 100644 --- a/google-beta/services/vertexai/resource_vertex_ai_index_endpoint_deployed_index.go +++ b/google-beta/services/vertexai/resource_vertex_ai_index_endpoint_deployed_index.go @@ -355,6 +355,19 @@ A timestamp in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to n }, }, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -525,6 +538,20 @@ func resourceVertexAIIndexEndpointDeployedIndexRead(d *schema.ResourceData, meta return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceVertexAIIndexEndpointDeployedIndexFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -534,6 +561,18 @@ func resourceVertexAIIndexEndpointDeployedIndexRead(d *schema.ResourceData, meta } func resourceVertexAIIndexEndpointDeployedIndexUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceVertexAIIndexEndpointDeployedIndex().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceVertexAIIndexEndpointDeployedIndexRead(d, meta) + } var project string config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) @@ -646,6 +685,13 @@ func resourceVertexAIIndexEndpointDeployedIndexUpdate(d *schema.ResourceData, me } func resourceVertexAIIndexEndpointDeployedIndexDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy VertexAIIndexEndpointDeployedIndex without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing IndexEndpointDeployedIndex %q from Terraform state without deletion", d.Id()) + return nil + } var project string config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) diff --git a/google-beta/services/vertexai/resource_vertex_ai_index_endpoint_deployed_index_generated_meta.yaml b/google-beta/services/vertexai/resource_vertex_ai_index_endpoint_deployed_index_generated_meta.yaml index 1b48d21a17f..26b548f2184 100644 --- a/google-beta/services/vertexai/resource_vertex_ai_index_endpoint_deployed_index_generated_meta.yaml +++ b/google-beta/services/vertexai/resource_vertex_ai_index_endpoint_deployed_index_generated_meta.yaml @@ -32,3 +32,5 @@ fields: - field: region provider_only: true - api_field: reservedIpRanges + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/vertexai/resource_vertex_ai_index_endpoint_generated_meta.yaml b/google-beta/services/vertexai/resource_vertex_ai_index_endpoint_generated_meta.yaml index a0c329cfca5..bf1b9e7399d 100644 --- a/google-beta/services/vertexai/resource_vertex_ai_index_endpoint_generated_meta.yaml +++ b/google-beta/services/vertexai/resource_vertex_ai_index_endpoint_generated_meta.yaml @@ -28,3 +28,5 @@ fields: - field: terraform_labels provider_only: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/vertexai/resource_vertex_ai_index_generated_meta.yaml b/google-beta/services/vertexai/resource_vertex_ai_index_generated_meta.yaml index 81b3e470dbe..ac34fbf52af 100644 --- a/google-beta/services/vertexai/resource_vertex_ai_index_generated_meta.yaml +++ b/google-beta/services/vertexai/resource_vertex_ai_index_generated_meta.yaml @@ -37,3 +37,5 @@ fields: - field: terraform_labels provider_only: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/vertexai/resource_vertex_ai_metadata_store.go b/google-beta/services/vertexai/resource_vertex_ai_metadata_store.go index 4b587580ed4..bffcc89ea70 100644 --- a/google-beta/services/vertexai/resource_vertex_ai_metadata_store.go +++ b/google-beta/services/vertexai/resource_vertex_ai_metadata_store.go @@ -100,6 +100,7 @@ func ResourceVertexAIMetadataStore() *schema.Resource { return &schema.Resource{ Create: resourceVertexAIMetadataStoreCreate, Read: resourceVertexAIMetadataStoreRead, + Update: resourceVertexAIMetadataStoreUpdate, Delete: resourceVertexAIMetadataStoreDelete, Importer: &schema.ResourceImporter{ @@ -113,6 +114,7 @@ func ResourceVertexAIMetadataStore() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -206,6 +208,18 @@ Has the form: projects/my-project/locations/my-region/keyRings/my-kr/cryptoKeys/ Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -349,6 +363,19 @@ func resourceVertexAIMetadataStoreRead(d *schema.ResourceData, meta interface{}) log.Printf("[DEBUG] Finished reading VertexAIMetadataStore %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading MetadataStore: %s", err) } @@ -385,7 +412,19 @@ func resourceVertexAIMetadataStoreRead(d *schema.ResourceData, meta interface{}) return nil } +func resourceVertexAIMetadataStoreUpdate(d *schema.ResourceData, meta interface{}) error { + // Only the root field "deletion_policy", "labels", "terraform_labels", and virtual fields are mutable + return resourceVertexAIMetadataStoreRead(d, meta) +} + func resourceVertexAIMetadataStoreDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy VertexAIMetadataStore without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing MetadataStore %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/vertexai/resource_vertex_ai_metadata_store_generated_meta.yaml b/google-beta/services/vertexai/resource_vertex_ai_metadata_store_generated_meta.yaml index 9a956098445..70072c884ee 100644 --- a/google-beta/services/vertexai/resource_vertex_ai_metadata_store_generated_meta.yaml +++ b/google-beta/services/vertexai/resource_vertex_ai_metadata_store_generated_meta.yaml @@ -16,3 +16,5 @@ fields: provider_only: true - api_field: state.diskUtilizationBytes - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/vertexai/resource_vertex_ai_rag_engine_config.go b/google-beta/services/vertexai/resource_vertex_ai_rag_engine_config.go index 5b501d1ede0..accf0e06cfc 100644 --- a/google-beta/services/vertexai/resource_vertex_ai_rag_engine_config.go +++ b/google-beta/services/vertexai/resource_vertex_ai_rag_engine_config.go @@ -115,6 +115,7 @@ func ResourceVertexAIRagEngineConfig() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -197,6 +198,18 @@ NOTE: Once deleted the data cannot be recovered. To start using RAG Engine again Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -329,6 +342,19 @@ func resourceVertexAIRagEngineConfigRead(d *schema.ResourceData, meta interface{ log.Printf("[DEBUG] Finished reading VertexAIRagEngineConfig %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading RagEngineConfig: %s", err) } @@ -360,6 +386,19 @@ func resourceVertexAIRagEngineConfigRead(d *schema.ResourceData, meta interface{ } func resourceVertexAIRagEngineConfigUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceVertexAIRagEngineConfig().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceVertexAIRagEngineConfigRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -439,6 +478,13 @@ func resourceVertexAIRagEngineConfigUpdate(d *schema.ResourceData, meta interfac } func resourceVertexAIRagEngineConfigDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy VertexAIRagEngineConfig without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing RagEngineConfig %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/vertexai/resource_vertex_ai_rag_engine_config_generated_meta.yaml b/google-beta/services/vertexai/resource_vertex_ai_rag_engine_config_generated_meta.yaml index 918348a13a1..383b884a4d1 100644 --- a/google-beta/services/vertexai/resource_vertex_ai_rag_engine_config_generated_meta.yaml +++ b/google-beta/services/vertexai/resource_vertex_ai_rag_engine_config_generated_meta.yaml @@ -13,3 +13,5 @@ fields: - api_field: ragManagedDbConfig.unprovisioned - field: region provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/vertexai/resource_vertex_ai_reasoning_engine.go b/google-beta/services/vertexai/resource_vertex_ai_reasoning_engine.go index 14724532cf8..a80ab440876 100644 --- a/google-beta/services/vertexai/resource_vertex_ai_reasoning_engine.go +++ b/google-beta/services/vertexai/resource_vertex_ai_reasoning_engine.go @@ -116,6 +116,7 @@ func ResourceVertexAIReasoningEngine() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -667,18 +668,18 @@ projects/{project}/locations/{location}/reasoningEngines/{reasoningEngine}`, Description: `The timestamp of when the Index was last updated in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine fractional digits.`, }, - "deletion_policy": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: verify.ValidateEnum([]string{"FORCE", ""}), - Description: `Optional. The deletion policy for the reasoning engine. Setting this to FORCE allows the reasoning engine to be deleted regardless of child undeleted resources. Possible values: ["FORCE"]`, - }, "project": { Type: schema.TypeString, Optional: true, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `This field uses a custom implementation please refer to documentation under /hashicorp/terraform-provider-google-beta/website/docs/r/vertex_ai_reasoning_engine.html.markdown for specifics`, + }, }, UseJSONNumber: true, } @@ -923,6 +924,18 @@ func resourceVertexAIReasoningEngineRead(d *schema.ResourceData, meta interface{ log.Printf("[DEBUG] Finished reading VertexAIReasoningEngine %q: %#v", d.Id(), res) // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading ReasoningEngine: %s", err) } @@ -960,6 +973,19 @@ func resourceVertexAIReasoningEngineRead(d *schema.ResourceData, meta interface{ } func resourceVertexAIReasoningEngineUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceVertexAIReasoningEngine().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceVertexAIReasoningEngineRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1100,6 +1126,13 @@ func resourceVertexAIReasoningEngineUpdate(d *schema.ResourceData, meta interfac } func resourceVertexAIReasoningEngineDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy VertexAIReasoningEngine without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing ReasoningEngine %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/vertexai/resource_vertex_ai_reasoning_engine_generated_meta.yaml b/google-beta/services/vertexai/resource_vertex_ai_reasoning_engine_generated_meta.yaml index 48bd9514695..22b68ec83df 100644 --- a/google-beta/services/vertexai/resource_vertex_ai_reasoning_engine_generated_meta.yaml +++ b/google-beta/services/vertexai/resource_vertex_ai_reasoning_engine_generated_meta.yaml @@ -16,8 +16,6 @@ fields: - api_field: contextSpec.memoryBankConfig.ttlConfig.granularTtlConfig.generateUpdatedTtl - api_field: contextSpec.memoryBankConfig.ttlConfig.memoryRevisionDefaultTtl - api_field: createTime - - field: deletion_policy - provider_only: true - api_field: description - api_field: displayName - field: effective_labels @@ -63,3 +61,5 @@ fields: - field: terraform_labels provider_only: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/vertexai/resource_vertex_ai_tensorboard.go b/google-beta/services/vertexai/resource_vertex_ai_tensorboard.go index c2b87b9a8c6..2bffd46d13d 100644 --- a/google-beta/services/vertexai/resource_vertex_ai_tensorboard.go +++ b/google-beta/services/vertexai/resource_vertex_ai_tensorboard.go @@ -116,6 +116,7 @@ func ResourceVertexAITensorboard() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -231,6 +232,18 @@ Please refer to the field 'effective_labels' for all of the labels present on th Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -400,6 +413,19 @@ func resourceVertexAITensorboardRead(d *schema.ResourceData, meta interface{}) e log.Printf("[DEBUG] Finished reading VertexAITensorboard %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Tensorboard: %s", err) } @@ -437,6 +463,19 @@ func resourceVertexAITensorboardRead(d *schema.ResourceData, meta interface{}) e } func resourceVertexAITensorboardUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceVertexAITensorboard().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceVertexAITensorboardRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -555,6 +594,13 @@ func resourceVertexAITensorboardUpdate(d *schema.ResourceData, meta interface{}) } func resourceVertexAITensorboardDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy VertexAITensorboard without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Tensorboard %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/vertexai/resource_vertex_ai_tensorboard_generated_meta.yaml b/google-beta/services/vertexai/resource_vertex_ai_tensorboard_generated_meta.yaml index 32c5803d64b..fb4e7e3310c 100644 --- a/google-beta/services/vertexai/resource_vertex_ai_tensorboard_generated_meta.yaml +++ b/google-beta/services/vertexai/resource_vertex_ai_tensorboard_generated_meta.yaml @@ -22,3 +22,5 @@ fields: - field: terraform_labels provider_only: true - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/vmwareengine/resource_vmwareengine_cluster.go b/google-beta/services/vmwareengine/resource_vmwareengine_cluster.go index 1c32e30f23c..fcad61a482e 100644 --- a/google-beta/services/vmwareengine/resource_vmwareengine_cluster.go +++ b/google-beta/services/vmwareengine/resource_vmwareengine_cluster.go @@ -602,6 +602,19 @@ There can only be one management cluster in a private cloud and it has to be the A timestamp in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine fractional digits. Examples: "2014-10-02T15:01:23Z" and "2014-10-02T15:01:23.045123456Z".`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -751,6 +764,20 @@ func resourceVmwareengineClusterRead(d *schema.ResourceData, meta interface{}) e log.Printf("[DEBUG] Finished reading VmwareengineCluster %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceVmwareengineClusterFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -778,6 +805,18 @@ func resourceVmwareengineClusterRead(d *schema.ResourceData, meta interface{}) e } func resourceVmwareengineClusterUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceVmwareengineCluster().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceVmwareengineClusterRead(d, meta) + } var project string config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) @@ -913,6 +952,13 @@ func resourceVmwareengineClusterUpdate(d *schema.ResourceData, meta interface{}) } func resourceVmwareengineClusterDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy VmwareengineCluster without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Cluster %q from Terraform state without deletion", d.Id()) + return nil + } var project string config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) diff --git a/google-beta/services/vmwareengine/resource_vmwareengine_cluster_generated_meta.yaml b/google-beta/services/vmwareengine/resource_vmwareengine_cluster_generated_meta.yaml index c143d9759a1..568ba2d5b4b 100644 --- a/google-beta/services/vmwareengine/resource_vmwareengine_cluster_generated_meta.yaml +++ b/google-beta/services/vmwareengine/resource_vmwareengine_cluster_generated_meta.yaml @@ -53,3 +53,5 @@ fields: - api_field: state - api_field: uid - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/vmwareengine/resource_vmwareengine_datastore.go b/google-beta/services/vmwareengine/resource_vmwareengine_datastore.go index 27c0363d6a9..4d6d84e1d6b 100644 --- a/google-beta/services/vmwareengine/resource_vmwareengine_datastore.go +++ b/google-beta/services/vmwareengine/resource_vmwareengine_datastore.go @@ -115,6 +115,7 @@ func ResourceVmwareengineDatastore() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -275,6 +276,18 @@ SOFT_DELETED`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -418,6 +431,19 @@ func resourceVmwareengineDatastoreRead(d *schema.ResourceData, meta interface{}) log.Printf("[DEBUG] Finished reading VmwareengineDatastore %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Datastore: %s", err) } @@ -455,6 +481,19 @@ func resourceVmwareengineDatastoreRead(d *schema.ResourceData, meta interface{}) } func resourceVmwareengineDatastoreUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceVmwareengineDatastore().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceVmwareengineDatastoreRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -563,6 +602,13 @@ func resourceVmwareengineDatastoreUpdate(d *schema.ResourceData, meta interface{ } func resourceVmwareengineDatastoreDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy VmwareengineDatastore without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Datastore %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/vmwareengine/resource_vmwareengine_datastore_generated_meta.yaml b/google-beta/services/vmwareengine/resource_vmwareengine_datastore_generated_meta.yaml index 57e5f6747c4..178f4fd8017 100644 --- a/google-beta/services/vmwareengine/resource_vmwareengine_datastore_generated_meta.yaml +++ b/google-beta/services/vmwareengine/resource_vmwareengine_datastore_generated_meta.yaml @@ -23,3 +23,5 @@ fields: - api_field: state - api_field: uid - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/vmwareengine/resource_vmwareengine_external_access_rule.go b/google-beta/services/vmwareengine/resource_vmwareengine_external_access_rule.go index 8eb8b6959dd..b6f0b66f64e 100644 --- a/google-beta/services/vmwareengine/resource_vmwareengine_external_access_rule.go +++ b/google-beta/services/vmwareengine/resource_vmwareengine_external_access_rule.go @@ -248,6 +248,19 @@ up to nine fractional digits. Examples: "2014-10-02T15:01:23Z" and "2014-10-02T1 A timestamp in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine fractional digits. Examples: "2014-10-02T15:01:23Z" and "2014-10-02T15:01:23.045123456Z".`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -411,6 +424,20 @@ func resourceVmwareengineExternalAccessRuleRead(d *schema.ResourceData, meta int log.Printf("[DEBUG] Finished reading VmwareengineExternalAccessRule %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceVmwareengineExternalAccessRuleFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -438,6 +465,18 @@ func resourceVmwareengineExternalAccessRuleRead(d *schema.ResourceData, meta int } func resourceVmwareengineExternalAccessRuleUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceVmwareengineExternalAccessRule().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceVmwareengineExternalAccessRuleRead(d, meta) + } var project string config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) @@ -596,6 +635,13 @@ func resourceVmwareengineExternalAccessRuleUpdate(d *schema.ResourceData, meta i } func resourceVmwareengineExternalAccessRuleDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy VmwareengineExternalAccessRule without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing ExternalAccessRule %q from Terraform state without deletion", d.Id()) + return nil + } var project string config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) diff --git a/google-beta/services/vmwareengine/resource_vmwareengine_external_access_rule_generated_meta.yaml b/google-beta/services/vmwareengine/resource_vmwareengine_external_access_rule_generated_meta.yaml index 4182e0c0a10..2f1c7d0bba2 100644 --- a/google-beta/services/vmwareengine/resource_vmwareengine_external_access_rule_generated_meta.yaml +++ b/google-beta/services/vmwareengine/resource_vmwareengine_external_access_rule_generated_meta.yaml @@ -25,3 +25,5 @@ fields: - api_field: state - api_field: uid - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/vmwareengine/resource_vmwareengine_external_address.go b/google-beta/services/vmwareengine/resource_vmwareengine_external_address.go index 0e1dfb837d0..dff1646a797 100644 --- a/google-beta/services/vmwareengine/resource_vmwareengine_external_address.go +++ b/google-beta/services/vmwareengine/resource_vmwareengine_external_address.go @@ -186,6 +186,19 @@ up to nine fractional digits. Examples: "2014-10-02T15:01:23Z" and "2014-10-02T1 A timestamp in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine fractional digits. Examples: "2014-10-02T15:01:23Z" and "2014-10-02T15:01:23.045123456Z".`, }, + + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -315,6 +328,20 @@ func resourceVmwareengineExternalAddressRead(d *schema.ResourceData, meta interf log.Printf("[DEBUG] Finished reading VmwareengineExternalAddress %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + err = ResourceVmwareengineExternalAddressFlatten(d, meta, res, config, userAgent, billingProject, url, headers) if err != nil { return err @@ -342,6 +369,18 @@ func resourceVmwareengineExternalAddressRead(d *schema.ResourceData, meta interf } func resourceVmwareengineExternalAddressUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceVmwareengineExternalAddress().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceVmwareengineExternalAddressRead(d, meta) + } var project string config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) @@ -441,6 +480,13 @@ func resourceVmwareengineExternalAddressUpdate(d *schema.ResourceData, meta inte } func resourceVmwareengineExternalAddressDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy VmwareengineExternalAddress without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing ExternalAddress %q from Terraform state without deletion", d.Id()) + return nil + } var project string config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) diff --git a/google-beta/services/vmwareengine/resource_vmwareengine_external_address_generated_meta.yaml b/google-beta/services/vmwareengine/resource_vmwareengine_external_address_generated_meta.yaml index d06eabcaca5..d084c49cb1a 100644 --- a/google-beta/services/vmwareengine/resource_vmwareengine_external_address_generated_meta.yaml +++ b/google-beta/services/vmwareengine/resource_vmwareengine_external_address_generated_meta.yaml @@ -18,3 +18,5 @@ fields: - api_field: state - api_field: uid - api_field: updateTime + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/vmwareengine/resource_vmwareengine_network.go b/google-beta/services/vmwareengine/resource_vmwareengine_network.go index 82aaf63902e..ccdaaff4d21 100644 --- a/google-beta/services/vmwareengine/resource_vmwareengine_network.go +++ b/google-beta/services/vmwareengine/resource_vmwareengine_network.go @@ -115,6 +115,7 @@ func ResourceVmwareengineNetwork() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -222,6 +223,18 @@ For example: projects/123123/global/networks/my-network`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -365,6 +378,19 @@ func resourceVmwareengineNetworkRead(d *schema.ResourceData, meta interface{}) e log.Printf("[DEBUG] Finished reading VmwareengineNetwork %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Network: %s", err) } @@ -402,6 +428,19 @@ func resourceVmwareengineNetworkRead(d *schema.ResourceData, meta interface{}) e } func resourceVmwareengineNetworkUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceVmwareengineNetwork().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceVmwareengineNetworkRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -500,6 +539,13 @@ func resourceVmwareengineNetworkUpdate(d *schema.ResourceData, meta interface{}) } func resourceVmwareengineNetworkDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy VmwareengineNetwork without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Network %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/vmwareengine/resource_vmwareengine_network_generated_meta.yaml b/google-beta/services/vmwareengine/resource_vmwareengine_network_generated_meta.yaml index 8e97932f89c..7ff012464dd 100644 --- a/google-beta/services/vmwareengine/resource_vmwareengine_network_generated_meta.yaml +++ b/google-beta/services/vmwareengine/resource_vmwareengine_network_generated_meta.yaml @@ -20,3 +20,5 @@ fields: - api_field: updateTime - api_field: vpcNetworks.network - api_field: vpcNetworks.type + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/vmwareengine/resource_vmwareengine_network_peering.go b/google-beta/services/vmwareengine/resource_vmwareengine_network_peering.go index 199071219f7..2aac808524d 100644 --- a/google-beta/services/vmwareengine/resource_vmwareengine_network_peering.go +++ b/google-beta/services/vmwareengine/resource_vmwareengine_network_peering.go @@ -122,6 +122,7 @@ func ResourceVmwareengineNetworkPeering() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -242,6 +243,18 @@ projects/{project_number}/locations/{location}/vmwareEngineNetworks/{vmwareEngin Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -416,6 +429,19 @@ func resourceVmwareengineNetworkPeeringRead(d *schema.ResourceData, meta interfa log.Printf("[DEBUG] Finished reading VmwareengineNetworkPeering %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading NetworkPeering: %s", err) } @@ -447,6 +473,19 @@ func resourceVmwareengineNetworkPeeringRead(d *schema.ResourceData, meta interfa } func resourceVmwareengineNetworkPeeringUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceVmwareengineNetworkPeering().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceVmwareengineNetworkPeeringRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -568,6 +607,13 @@ func resourceVmwareengineNetworkPeeringUpdate(d *schema.ResourceData, meta inter } func resourceVmwareengineNetworkPeeringDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy VmwareengineNetworkPeering without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing NetworkPeering %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/vmwareengine/resource_vmwareengine_network_peering_generated_meta.yaml b/google-beta/services/vmwareengine/resource_vmwareengine_network_peering_generated_meta.yaml index 2c41071a33a..0d7af266733 100644 --- a/google-beta/services/vmwareengine/resource_vmwareengine_network_peering_generated_meta.yaml +++ b/google-beta/services/vmwareengine/resource_vmwareengine_network_peering_generated_meta.yaml @@ -23,3 +23,5 @@ fields: - api_field: updateTime - api_field: vmwareEngineNetwork - api_field: vmwareEngineNetworkCanonical + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/vmwareengine/resource_vmwareengine_network_policy.go b/google-beta/services/vmwareengine/resource_vmwareengine_network_policy.go index 993f621235d..109ee9f25af 100644 --- a/google-beta/services/vmwareengine/resource_vmwareengine_network_policy.go +++ b/google-beta/services/vmwareengine/resource_vmwareengine_network_policy.go @@ -115,6 +115,7 @@ func ResourceVmwareengineNetworkPolicy() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -249,6 +250,18 @@ projects/{project_number}/locations/{location}/vmwareEngineNetworks/{vmwareEngin Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -410,6 +423,19 @@ func resourceVmwareengineNetworkPolicyRead(d *schema.ResourceData, meta interfac log.Printf("[DEBUG] Finished reading VmwareengineNetworkPolicy %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading NetworkPolicy: %s", err) } @@ -447,6 +473,19 @@ func resourceVmwareengineNetworkPolicyRead(d *schema.ResourceData, meta interfac } func resourceVmwareengineNetworkPolicyUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceVmwareengineNetworkPolicy().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceVmwareengineNetworkPolicyRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -549,6 +588,13 @@ func resourceVmwareengineNetworkPolicyUpdate(d *schema.ResourceData, meta interf } func resourceVmwareengineNetworkPolicyDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy VmwareengineNetworkPolicy without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing NetworkPolicy %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/vmwareengine/resource_vmwareengine_network_policy_generated_meta.yaml b/google-beta/services/vmwareengine/resource_vmwareengine_network_policy_generated_meta.yaml index d9f26da5913..314cb9d1dc7 100644 --- a/google-beta/services/vmwareengine/resource_vmwareengine_network_policy_generated_meta.yaml +++ b/google-beta/services/vmwareengine/resource_vmwareengine_network_policy_generated_meta.yaml @@ -22,3 +22,5 @@ fields: - api_field: updateTime - api_field: vmwareEngineNetwork - api_field: vmwareEngineNetworkCanonical + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/vmwareengine/resource_vmwareengine_private_cloud.go b/google-beta/services/vmwareengine/resource_vmwareengine_private_cloud.go index fbfcccb75af..48f2d258302 100644 --- a/google-beta/services/vmwareengine/resource_vmwareengine_private_cloud.go +++ b/google-beta/services/vmwareengine/resource_vmwareengine_private_cloud.go @@ -195,6 +195,7 @@ func ResourceVmwareenginePrivateCloud() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -630,6 +631,18 @@ Examples: "2014-10-02T15:01:23Z" and "2014-10-02T15:01:23.045123456Z".`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -870,6 +883,18 @@ func resourceVmwareenginePrivateCloudRead(d *schema.ResourceData, meta interface } // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading PrivateCloud: %s", err) } @@ -907,6 +932,19 @@ func resourceVmwareenginePrivateCloudRead(d *schema.ResourceData, meta interface } func resourceVmwareenginePrivateCloudUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceVmwareenginePrivateCloud().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceVmwareenginePrivateCloudRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1059,6 +1097,13 @@ func resourceVmwareenginePrivateCloudUpdate(d *schema.ResourceData, meta interfa } func resourceVmwareenginePrivateCloudDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy VmwareenginePrivateCloud without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing PrivateCloud %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/vmwareengine/resource_vmwareengine_private_cloud_generated_meta.yaml b/google-beta/services/vmwareengine/resource_vmwareengine_private_cloud_generated_meta.yaml index 73ba7f5ef70..18273fe0348 100644 --- a/google-beta/services/vmwareengine/resource_vmwareengine_private_cloud_generated_meta.yaml +++ b/google-beta/services/vmwareengine/resource_vmwareengine_private_cloud_generated_meta.yaml @@ -70,3 +70,5 @@ fields: - api_field: vcenter.internalIp - api_field: vcenter.state - api_field: vcenter.version + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/vpcaccess/resource_vpc_access_connector.go b/google-beta/services/vpcaccess/resource_vpc_access_connector.go index 803c9f7c0dd..b6c3a58bb6c 100644 --- a/google-beta/services/vpcaccess/resource_vpc_access_connector.go +++ b/google-beta/services/vpcaccess/resource_vpc_access_connector.go @@ -126,6 +126,7 @@ func ResourceVPCAccessConnector() *schema.Resource { customdiff.ForceNewIfChange("min_instances", isInstanceShrinkage), customdiff.ForceNewIfChange("max_instances", isInstanceShrinkage), tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -275,6 +276,18 @@ https://compute.googleapis.com/compute/v1/projects/{project}/regions/{region}/su Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -482,6 +495,19 @@ func resourceVPCAccessConnectorRead(d *schema.ResourceData, meta interface{}) er return nil } + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Connector: %s", err) } @@ -519,6 +545,19 @@ func resourceVPCAccessConnectorRead(d *schema.ResourceData, meta interface{}) er } func resourceVPCAccessConnectorUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceVPCAccessConnector().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceVPCAccessConnectorRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -657,6 +696,13 @@ func resourceVPCAccessConnectorUpdate(d *schema.ResourceData, meta interface{}) } func resourceVPCAccessConnectorDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy VPCAccessConnector without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Connector %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/vpcaccess/resource_vpc_access_connector_generated_meta.yaml b/google-beta/services/vpcaccess/resource_vpc_access_connector_generated_meta.yaml index 857db3ea921..51de67d87a3 100644 --- a/google-beta/services/vpcaccess/resource_vpc_access_connector_generated_meta.yaml +++ b/google-beta/services/vpcaccess/resource_vpc_access_connector_generated_meta.yaml @@ -22,3 +22,5 @@ fields: - api_field: state - api_field: subnet.name - api_field: subnet.projectId + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/workbench/resource_workbench_instance.go b/google-beta/services/workbench/resource_workbench_instance.go index 8cf7e104d0c..4625e2600c2 100644 --- a/google-beta/services/workbench/resource_workbench_instance.go +++ b/google-beta/services/workbench/resource_workbench_instance.go @@ -442,6 +442,7 @@ func ResourceWorkbenchInstance() *schema.Resource { workbenchMetadataCustomizeDiff, tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -1049,6 +1050,18 @@ The milliseconds portion (".SSS") is optional.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -1238,6 +1251,18 @@ func resourceWorkbenchInstanceRead(d *schema.ResourceData, meta interface{}) err return fmt.Errorf("Error setting desired_state: %s", err) } } + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Instance: %s", err) } @@ -1275,6 +1300,19 @@ func resourceWorkbenchInstanceRead(d *schema.ResourceData, meta interface{}) err } func resourceWorkbenchInstanceUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceWorkbenchInstance().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceWorkbenchInstanceRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1541,6 +1579,13 @@ func resourceWorkbenchInstanceUpdate(d *schema.ResourceData, meta interface{}) e } func resourceWorkbenchInstanceDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy WorkbenchInstance without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Instance %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/workbench/resource_workbench_instance_generated_meta.yaml b/google-beta/services/workbench/resource_workbench_instance_generated_meta.yaml index 3f247b25721..35d8d11b7cc 100644 --- a/google-beta/services/workbench/resource_workbench_instance_generated_meta.yaml +++ b/google-beta/services/workbench/resource_workbench_instance_generated_meta.yaml @@ -73,3 +73,5 @@ fields: - api_field: upgradeHistory.targetVersion - api_field: upgradeHistory.version - api_field: upgradeHistory.vmImage + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/workflows/resource_workflows_workflow.go b/google-beta/services/workflows/resource_workflows_workflow.go index ed23d7e463d..b40a3282026 100644 --- a/google-beta/services/workflows/resource_workflows_workflow.go +++ b/google-beta/services/workflows/resource_workflows_workflow.go @@ -121,6 +121,7 @@ func ResourceWorkflowsWorkflow() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.SetLabelsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -289,6 +290,18 @@ When the field is set to false, deleting the workflow is allowed.`, Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -508,6 +521,18 @@ func resourceWorkflowsWorkflowRead(d *schema.ResourceData, meta interface{}) err return fmt.Errorf("Error setting deletion_protection: %s", err) } } + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Workflow: %s", err) } @@ -545,6 +570,19 @@ func resourceWorkflowsWorkflowRead(d *schema.ResourceData, meta interface{}) err } func resourceWorkflowsWorkflowUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceWorkflowsWorkflow().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceWorkflowsWorkflowRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -718,6 +756,13 @@ func resourceWorkflowsWorkflowUpdate(d *schema.ResourceData, meta interface{}) e } func resourceWorkflowsWorkflowDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy WorkflowsWorkflow without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Workflow %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/workflows/resource_workflows_workflow_generated_meta.yaml b/google-beta/services/workflows/resource_workflows_workflow_generated_meta.yaml index e518cc1d8da..0776e24a537 100644 --- a/google-beta/services/workflows/resource_workflows_workflow_generated_meta.yaml +++ b/google-beta/services/workflows/resource_workflows_workflow_generated_meta.yaml @@ -29,3 +29,5 @@ fields: provider_only: true - api_field: updateTime - api_field: userEnvVars + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/workstations/resource_workstations_workstation.go b/google-beta/services/workstations/resource_workstations_workstation.go index f4b28488cec..90bf3499caa 100644 --- a/google-beta/services/workstations/resource_workstations_workstation.go +++ b/google-beta/services/workstations/resource_workstations_workstation.go @@ -117,6 +117,7 @@ func ResourceWorkstationsWorkstation() *schema.Resource { tpgresource.SetLabelsDiff, tpgresource.SetAnnotationsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -263,6 +264,18 @@ To send traffic to a different port, clients may prefix the host with the destin Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -434,6 +447,19 @@ func resourceWorkstationsWorkstationRead(d *schema.ResourceData, meta interface{ log.Printf("[DEBUG] Finished reading WorkstationsWorkstation %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading Workstation: %s", err) } @@ -483,6 +509,19 @@ func resourceWorkstationsWorkstationRead(d *schema.ResourceData, meta interface{ } func resourceWorkstationsWorkstationUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceWorkstationsWorkstation().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceWorkstationsWorkstationRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -621,6 +660,13 @@ func resourceWorkstationsWorkstationUpdate(d *schema.ResourceData, meta interfac } func resourceWorkstationsWorkstationDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy WorkstationsWorkstation without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing Workstation %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/workstations/resource_workstations_workstation_cluster.go b/google-beta/services/workstations/resource_workstations_workstation_cluster.go index ca6e3b7f3f8..c014254a2e9 100644 --- a/google-beta/services/workstations/resource_workstations_workstation_cluster.go +++ b/google-beta/services/workstations/resource_workstations_workstation_cluster.go @@ -117,6 +117,7 @@ func ResourceWorkstationsWorkstationCluster() *schema.Resource { tpgresource.SetLabelsDiff, tpgresource.SetAnnotationsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -343,6 +344,18 @@ May be sent on update and delete requests to ensure that the client has an up-to Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -528,6 +541,19 @@ func resourceWorkstationsWorkstationClusterRead(d *schema.ResourceData, meta int log.Printf("[DEBUG] Finished reading WorkstationsWorkstationCluster %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading WorkstationCluster: %s", err) } @@ -565,6 +591,19 @@ func resourceWorkstationsWorkstationClusterRead(d *schema.ResourceData, meta int } func resourceWorkstationsWorkstationClusterUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceWorkstationsWorkstationCluster().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceWorkstationsWorkstationClusterRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -713,6 +752,13 @@ func resourceWorkstationsWorkstationClusterUpdate(d *schema.ResourceData, meta i } func resourceWorkstationsWorkstationClusterDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy WorkstationsWorkstationCluster without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing WorkstationCluster %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/workstations/resource_workstations_workstation_cluster_generated_meta.yaml b/google-beta/services/workstations/resource_workstations_workstation_cluster_generated_meta.yaml index 3ed5526f2dd..6c6f71c3b7e 100644 --- a/google-beta/services/workstations/resource_workstations_workstation_cluster_generated_meta.yaml +++ b/google-beta/services/workstations/resource_workstations_workstation_cluster_generated_meta.yaml @@ -37,3 +37,5 @@ fields: - api_field: uid - field: workstation_cluster_id provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/workstations/resource_workstations_workstation_config.go b/google-beta/services/workstations/resource_workstations_workstation_config.go index 4ba4431f9fb..27ee903fcd6 100644 --- a/google-beta/services/workstations/resource_workstations_workstation_config.go +++ b/google-beta/services/workstations/resource_workstations_workstation_config.go @@ -117,6 +117,7 @@ func ResourceWorkstationsWorkstationConfig() *schema.Resource { tpgresource.SetLabelsDiff, tpgresource.SetAnnotationsDiff, tpgresource.DefaultProviderProject, + tpgresource.DefaultProviderDeletionPolicy("DELETE"), ), Identity: &schema.ResourceIdentity{ @@ -783,6 +784,18 @@ May be sent on update and delete requests to ensure that the client has an up-to Computed: true, ForceNew: true, }, + "deletion_policy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "DELETE". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, + }, }, UseJSONNumber: true, } @@ -1021,6 +1034,19 @@ func resourceWorkstationsWorkstationConfigRead(d *schema.ResourceData, meta inte log.Printf("[DEBUG] Finished reading WorkstationsWorkstationConfig %q: %#v", d.Id(), res) + // Explicitly set virtual fields to default values if unset + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", "DELETE"); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading WorkstationConfig: %s", err) } @@ -1064,6 +1090,19 @@ func resourceWorkstationsWorkstationConfigRead(d *schema.ResourceData, meta inte } func resourceWorkstationsWorkstationConfigUpdate(d *schema.ResourceData, meta interface{}) error { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range ResourceWorkstationsWorkstationConfig().Schema { + if d.HasChange(field) && !clientSideFields[field] { + clientSideOnly = false + break + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return resourceWorkstationsWorkstationConfigRead(d, meta) + } + config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { @@ -1325,6 +1364,13 @@ func resourceWorkstationsWorkstationConfigUpdate(d *schema.ResourceData, meta in } func resourceWorkstationsWorkstationConfigDelete(d *schema.ResourceData, meta interface{}) error { + if d.Get("deletion_policy").(string) == "PREVENT" { + return fmt.Errorf("cannot destroy WorkstationsWorkstationConfig without setting deletion_policy=\"DELETE\" and running `terraform apply`") + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing WorkstationConfig %q from Terraform state without deletion", d.Id()) + return nil + } config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { diff --git a/google-beta/services/workstations/resource_workstations_workstation_config_generated_meta.yaml b/google-beta/services/workstations/resource_workstations_workstation_config_generated_meta.yaml index af136c6139f..3b96ee9519e 100644 --- a/google-beta/services/workstations/resource_workstations_workstation_config_generated_meta.yaml +++ b/google-beta/services/workstations/resource_workstations_workstation_config_generated_meta.yaml @@ -86,3 +86,5 @@ fields: provider_only: true - field: workstation_config_id provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/services/workstations/resource_workstations_workstation_generated_meta.yaml b/google-beta/services/workstations/resource_workstations_workstation_generated_meta.yaml index ccd96f72a02..c276c9b6342 100644 --- a/google-beta/services/workstations/resource_workstations_workstation_generated_meta.yaml +++ b/google-beta/services/workstations/resource_workstations_workstation_generated_meta.yaml @@ -31,3 +31,5 @@ fields: provider_only: true - field: workstation_id provider_only: true + - field: deletion_policy + provider_only: true diff --git a/google-beta/tpgresource/utils.go b/google-beta/tpgresource/utils.go index 2e5736be952..dcdcdc62d03 100644 --- a/google-beta/tpgresource/utils.go +++ b/google-beta/tpgresource/utils.go @@ -170,6 +170,88 @@ func GetZoneFromDiff(d *schema.ResourceDiff, config *transport_tpg.Config) (stri return "", fmt.Errorf("%s: required field is not set", "zone") } +// getDeletionPolicyFromDiff reads the "deletion_policy" field from the given diff and falls +// back to the provider's value if not given. If the provider's value is not +// given, an error is returned. +func GetDeletionPolicyFromDiff(d *schema.ResourceDiff, config *transport_tpg.Config, resourceDefault string) (string, error) { + //if IsNull() value, then the value has not been manually configured + if d.GetRawConfig().GetAttr("deletion_policy").IsNull() { + if config.DeletionPolicy != "" { + log.Printf("[DEBUG] `deletion_policy` detected as not set within resource configuration. Falling back to configured provider default, %s", config.DeletionPolicy) + return config.DeletionPolicy, nil + } + //return the provided resource default as the final backup + log.Printf("[DEBUG] `deletion_policy` detected as not set within resource or provider configuration. Falling back to resource default, %s", resourceDefault) + return resourceDefault, nil + } + //if not null, then use/maintain usage of manually configured value + // + //this has to happen after a check for the null is made, + //as "GetOk" will always return a value once the resource is set, preventing changes + res, ok := d.GetOk("deletion_policy") + if ok { + return res.(string), nil + } + return "", fmt.Errorf("An error has occured during %s configuration. Please report this issue to the provider developers.", "`deletion_policy`") +} + +func DeletionPolicySchemaEntry(resourceDefault string) *schema.Schema { + return &schema.Schema{ + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: fmt.Sprintf(`Whether Terraform will be prevented from destroying the instance. Defaults to "%s". +When a 'terraform destroy' or 'terraform apply' would delete the instance, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is allowed. +`, resourceDefault), + } +} + +func DeletionPolicyReadDefault(d *schema.ResourceData, config *transport_tpg.Config, resourceDefault string) error { + if _, ok := d.GetOkExists("deletion_policy"); !ok { + //prioritize config's value if present + if config.DeletionPolicy != "" { + if err := d.Set("deletion_policy", config.DeletionPolicy); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } else { + if err := d.Set("deletion_policy", resourceDefault); err != nil { + return fmt.Errorf("Error setting deletion_policy: %s", err) + } + } + } + return nil +} + +func DeletionPolicyPreUpdate(d *schema.ResourceData, resourceSchema func() *schema.Resource) bool { + clientSideFields := map[string]bool{"deletion_policy": true} + clientSideOnly := true + for field := range resourceSchema().Schema { + if d.HasChange(field) && !clientSideFields[field] { + return false + } + } + if clientSideOnly { + log.Print("[DEBUG] Only client-side changes detected. Cancelling update operation.") + return true + } + return false +} + +func DeletionPolicyPreDelete(d *schema.ResourceData) (bool, error) { + if d.Get("deletion_policy").(string) == "PREVENT" { + return true, fmt.Errorf("cannot destroy %q without setting deletion_policy=\"DELETE\" and running `terraform apply`", d.Id()) + } + if d.Get("deletion_policy").(string) == "ABANDON" { + log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing %q from Terraform state without deletion", d.Id()) + return true, nil + } + return false, nil +} + func GetRouterLockName(region string, router string) string { return fmt.Sprintf("router/%s/%s", region, router) } @@ -917,6 +999,20 @@ func DefaultProviderZone(_ context.Context, diff *schema.ResourceDiff, meta inte return nil } +func DefaultProviderDeletionPolicy(resourceDefault string) schema.CustomizeDiffFunc { + return func(_ context.Context, diff *schema.ResourceDiff, meta interface{}) error { + config := meta.(*transport_tpg.Config) + if dpolicy := diff.Get("deletion_policy"); dpolicy != nil { + dpolicy, err := GetDeletionPolicyFromDiff(diff, config, resourceDefault) + err = diff.SetNew("deletion_policy", dpolicy) + if err != nil { + return err + } + } + return nil + } +} + // id.UniqueId() returns a timestamp + incremental hash // This function truncates the timestamp to provide a prefix + 9 using // YYmmdd + last 3 digits of the incremental hash diff --git a/google-beta/transport/config.go b/google-beta/transport/config.go index 92f1fdc24c9..497c031aff1 100644 --- a/google-beta/transport/config.go +++ b/google-beta/transport/config.go @@ -215,6 +215,8 @@ type Config struct { DefaultLabels map[string]string AddTerraformAttributionLabel bool TerraformAttributionLabelAdditionStrategy string + DeletionPolicy string + // PollInterval is passed to retry.StateChangeConf in common_operation.go // It controls the interval at which we poll for successful operations PollInterval time.Duration diff --git a/website/docs/r/access_context_manager_access_level.html.markdown b/website/docs/r/access_context_manager_access_level.html.markdown index 15d51b7cf09..a13473b63f0 100644 --- a/website/docs/r/access_context_manager_access_level.html.markdown +++ b/website/docs/r/access_context_manager_access_level.html.markdown @@ -105,6 +105,12 @@ The following arguments are supported: See CEL spec at: https://github.com/google/cel-spec. Structure is [documented below](#nested_custom). +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `basic` block supports: diff --git a/website/docs/r/access_context_manager_access_level_condition.html.markdown b/website/docs/r/access_context_manager_access_level_condition.html.markdown index 06fb2ff31cd..b9d76cbf131 100644 --- a/website/docs/r/access_context_manager_access_level_condition.html.markdown +++ b/website/docs/r/access_context_manager_access_level_condition.html.markdown @@ -166,6 +166,12 @@ The following arguments are supported: The request must originate from one of the provided VPC networks in Google Cloud. Cannot specify this field together with `ip_subnetworks`. Structure is [documented below](#nested_vpc_network_sources). +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `device_policy` block supports: diff --git a/website/docs/r/access_context_manager_access_levels.html.markdown b/website/docs/r/access_context_manager_access_levels.html.markdown index a665f6f4e82..71a9e97a084 100644 --- a/website/docs/r/access_context_manager_access_levels.html.markdown +++ b/website/docs/r/access_context_manager_access_levels.html.markdown @@ -107,6 +107,12 @@ The following arguments are supported: The desired Access Levels that should replace all existing Access Levels in the Access Policy. Structure is [documented below](#nested_access_levels). +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `access_levels` block supports: diff --git a/website/docs/r/access_context_manager_access_policy.html.markdown b/website/docs/r/access_context_manager_access_policy.html.markdown index 5eb3fc77824..2a6e5f1bcf2 100644 --- a/website/docs/r/access_context_manager_access_policy.html.markdown +++ b/website/docs/r/access_context_manager_access_policy.html.markdown @@ -89,6 +89,12 @@ The following arguments are supported: Folder or project on which this policy is applicable. Format: 'folders/{{folder_id}}' or 'projects/{{project_number}}' +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/access_context_manager_authorized_orgs_desc.html.markdown b/website/docs/r/access_context_manager_authorized_orgs_desc.html.markdown index 588638031ee..0bac36421b9 100644 --- a/website/docs/r/access_context_manager_authorized_orgs_desc.html.markdown +++ b/website/docs/r/access_context_manager_authorized_orgs_desc.html.markdown @@ -117,6 +117,12 @@ The following arguments are supported: A granular control type for authorization levels. Valid value is "AUTHORIZATION_TYPE_TRUST". Possible values are: `AUTHORIZATION_TYPE_TRUST`. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/access_context_manager_egress_policy.html.markdown b/website/docs/r/access_context_manager_egress_policy.html.markdown index aa1ea295fa1..b27b059e325 100644 --- a/website/docs/r/access_context_manager_egress_policy.html.markdown +++ b/website/docs/r/access_context_manager_egress_policy.html.markdown @@ -42,6 +42,12 @@ The following arguments are supported: The name of the Service Perimeter to add this resource to. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/access_context_manager_gcp_user_access_binding.html.markdown b/website/docs/r/access_context_manager_gcp_user_access_binding.html.markdown index 34df11586fa..f90dda016f8 100644 --- a/website/docs/r/access_context_manager_gcp_user_access_binding.html.markdown +++ b/website/docs/r/access_context_manager_gcp_user_access_binding.html.markdown @@ -109,6 +109,12 @@ The following arguments are supported: Optional. A list of scoped access settings that set this binding's restrictions on a subset of applications. Structure is [documented below](#nested_scoped_access_settings). +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `session_settings` block supports: diff --git a/website/docs/r/access_context_manager_ingress_policy.html.markdown b/website/docs/r/access_context_manager_ingress_policy.html.markdown index ad6e16654f2..ced476f00a6 100644 --- a/website/docs/r/access_context_manager_ingress_policy.html.markdown +++ b/website/docs/r/access_context_manager_ingress_policy.html.markdown @@ -42,6 +42,12 @@ The following arguments are supported: The name of the Service Perimeter to add this resource to. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/access_context_manager_service_perimeter.html.markdown b/website/docs/r/access_context_manager_service_perimeter.html.markdown index 92e58f194f5..97926a0d9fc 100644 --- a/website/docs/r/access_context_manager_service_perimeter.html.markdown +++ b/website/docs/r/access_context_manager_service_perimeter.html.markdown @@ -350,6 +350,12 @@ The following arguments are supported: between currently enforced and suggested restrictions. useExplicitDryRunSpec must bet set to True if any of the fields in the spec are set to non-default values. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `status` block supports: diff --git a/website/docs/r/access_context_manager_service_perimeter_dry_run_egress_policy.html.markdown b/website/docs/r/access_context_manager_service_perimeter_dry_run_egress_policy.html.markdown index 87017dffdd9..80a11998eb5 100644 --- a/website/docs/r/access_context_manager_service_perimeter_dry_run_egress_policy.html.markdown +++ b/website/docs/r/access_context_manager_service_perimeter_dry_run_egress_policy.html.markdown @@ -151,6 +151,12 @@ The following arguments are supported: (Optional) Human readable title. Must be unique within the perimeter. Does not affect behavior. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `egress_from` block supports: diff --git a/website/docs/r/access_context_manager_service_perimeter_dry_run_ingress_policy.html.markdown b/website/docs/r/access_context_manager_service_perimeter_dry_run_ingress_policy.html.markdown index 4cd590ed027..89901166be3 100644 --- a/website/docs/r/access_context_manager_service_perimeter_dry_run_ingress_policy.html.markdown +++ b/website/docs/r/access_context_manager_service_perimeter_dry_run_ingress_policy.html.markdown @@ -159,6 +159,12 @@ The following arguments are supported: (Optional) Human readable title. Must be unique within the perimeter. Does not affect behavior. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `ingress_from` block supports: diff --git a/website/docs/r/access_context_manager_service_perimeter_dry_run_resource.html.markdown b/website/docs/r/access_context_manager_service_perimeter_dry_run_resource.html.markdown index 0532f09daf2..5a8b25d39cb 100644 --- a/website/docs/r/access_context_manager_service_perimeter_dry_run_resource.html.markdown +++ b/website/docs/r/access_context_manager_service_perimeter_dry_run_resource.html.markdown @@ -88,6 +88,12 @@ The following arguments are supported: The name of the Service Perimeter to add this resource to. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/access_context_manager_service_perimeter_egress_policy.html.markdown b/website/docs/r/access_context_manager_service_perimeter_egress_policy.html.markdown index 8efd418ae32..ee4379ed33d 100644 --- a/website/docs/r/access_context_manager_service_perimeter_egress_policy.html.markdown +++ b/website/docs/r/access_context_manager_service_perimeter_egress_policy.html.markdown @@ -151,6 +151,12 @@ The following arguments are supported: (Optional) Human readable title. Must be unique within the perimeter. Does not affect behavior. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `egress_from` block supports: diff --git a/website/docs/r/access_context_manager_service_perimeter_ingress_policy.html.markdown b/website/docs/r/access_context_manager_service_perimeter_ingress_policy.html.markdown index 74e38aa3972..913c7166595 100644 --- a/website/docs/r/access_context_manager_service_perimeter_ingress_policy.html.markdown +++ b/website/docs/r/access_context_manager_service_perimeter_ingress_policy.html.markdown @@ -159,6 +159,12 @@ The following arguments are supported: (Optional) Human readable title. Must be unique within the perimeter. Does not affect behavior. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `ingress_from` block supports: diff --git a/website/docs/r/access_context_manager_service_perimeter_resource.html.markdown b/website/docs/r/access_context_manager_service_perimeter_resource.html.markdown index 3a0575b86c5..64d8c6abbb3 100644 --- a/website/docs/r/access_context_manager_service_perimeter_resource.html.markdown +++ b/website/docs/r/access_context_manager_service_perimeter_resource.html.markdown @@ -88,6 +88,12 @@ The following arguments are supported: The name of the Service Perimeter to add this resource to. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/access_context_manager_service_perimeters.html.markdown b/website/docs/r/access_context_manager_service_perimeters.html.markdown index 4f21b7e2d81..3bce30bf8a3 100644 --- a/website/docs/r/access_context_manager_service_perimeters.html.markdown +++ b/website/docs/r/access_context_manager_service_perimeters.html.markdown @@ -100,6 +100,12 @@ The following arguments are supported: The desired Service Perimeters that should replace all existing Service Perimeters in the Access Policy. Structure is [documented below](#nested_service_perimeters). +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `service_perimeters` block supports: diff --git a/website/docs/r/active_directory_domain.html.markdown b/website/docs/r/active_directory_domain.html.markdown index 117879d0071..31f1256ba2b 100644 --- a/website/docs/r/active_directory_domain.html.markdown +++ b/website/docs/r/active_directory_domain.html.markdown @@ -82,6 +82,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. * `deletion_protection` - (Optional) Whether Terraform will be prevented from destroying the domain. Defaults to true. When a`terraform destroy` or `terraform apply` would delete the domain, the command will fail if this field is not set to false in Terraform state. diff --git a/website/docs/r/active_directory_domain_trust.html.markdown b/website/docs/r/active_directory_domain_trust.html.markdown index fa0aa6c850e..3469c5bb337 100644 --- a/website/docs/r/active_directory_domain_trust.html.markdown +++ b/website/docs/r/active_directory_domain_trust.html.markdown @@ -90,6 +90,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/active_directory_peering.html.markdown b/website/docs/r/active_directory_peering.html.markdown index 718f421dc3d..f1fcd5e7b2b 100644 --- a/website/docs/r/active_directory_peering.html.markdown +++ b/website/docs/r/active_directory_peering.html.markdown @@ -117,6 +117,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/alloydb_backup.html.markdown b/website/docs/r/alloydb_backup.html.markdown index a8529d4aff6..7009ec84952 100644 --- a/website/docs/r/alloydb_backup.html.markdown +++ b/website/docs/r/alloydb_backup.html.markdown @@ -186,6 +186,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `encryption_config` block supports: diff --git a/website/docs/r/alloydb_cluster.html.markdown b/website/docs/r/alloydb_cluster.html.markdown index 41ff31ce415..3dc388e540e 100644 --- a/website/docs/r/alloydb_cluster.html.markdown +++ b/website/docs/r/alloydb_cluster.html.markdown @@ -490,7 +490,14 @@ The following arguments are supported: * `deletion_policy` - (Optional) Policy to determine if the cluster should be deleted forcefully. Deleting a cluster forcefully, deletes the cluster and all its associated instances within the cluster. Deleting a Secondary cluster with a secondary instance REQUIRES setting deletion_policy = "FORCE" otherwise an error is returned. This is needed as there is no support to delete just the secondary instance, and the only way to delete secondary instance is to delete the associated secondary cluster forcefully which also deletes the secondary instance. -Possible values: DEFAULT, FORCE + +When a 'terraform destroy' or 'terraform apply' would delete the resource, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", the command will behave as if set to "DEFAULT". + +Possible values: DEFAULT, FORCE, PREVENT, ABANDON, DELETE * `deletion_protection` - (Optional) Whether Terraform will be prevented from destroying the cluster. When the field is set to true or unset in Terraform state, a `terraform apply` diff --git a/website/docs/r/alloydb_instance.html.markdown b/website/docs/r/alloydb_instance.html.markdown index 084203b0af9..b38b78ff5a5 100644 --- a/website/docs/r/alloydb_instance.html.markdown +++ b/website/docs/r/alloydb_instance.html.markdown @@ -284,6 +284,12 @@ The following arguments are supported: Configuration for Managed Connection Pool. Structure is [documented below](#nested_connection_pool_config). +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `query_insights_config` block supports: diff --git a/website/docs/r/alloydb_user.html.markdown b/website/docs/r/alloydb_user.html.markdown index 9aa69825cf3..dc5a34fcbb0 100644 --- a/website/docs/r/alloydb_user.html.markdown +++ b/website/docs/r/alloydb_user.html.markdown @@ -188,6 +188,12 @@ The following arguments are supported: (Optional) Triggers update of `password_wo` write-only. Increment this value when an update to `password_wo` is needed. For more info see [updating write-only arguments](/docs/providers/google/guides/using_write_only_arguments.html#updating-write-only-arguments) +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/api_gateway_api.html.markdown b/website/docs/r/api_gateway_api.html.markdown index 793a0425c95..b528a6f3d1f 100644 --- a/website/docs/r/api_gateway_api.html.markdown +++ b/website/docs/r/api_gateway_api.html.markdown @@ -76,6 +76,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/api_gateway_api_config.html.markdown b/website/docs/r/api_gateway_api_config.html.markdown index 77abf0183fa..7d453f63a51 100644 --- a/website/docs/r/api_gateway_api_config.html.markdown +++ b/website/docs/r/api_gateway_api_config.html.markdown @@ -165,6 +165,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. * `api_config_id_prefix` - (Optional) Creates a unique name beginning with the specified prefix. If this and api_config_id are unspecified, a random value is chosen for the name. diff --git a/website/docs/r/api_gateway_gateway.html.markdown b/website/docs/r/api_gateway_gateway.html.markdown index a3c72212151..804e0c12909 100644 --- a/website/docs/r/api_gateway_gateway.html.markdown +++ b/website/docs/r/api_gateway_gateway.html.markdown @@ -103,6 +103,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/apigee_addons_config.html.markdown b/website/docs/r/apigee_addons_config.html.markdown index 2028a32670c..a5883406c92 100644 --- a/website/docs/r/apigee_addons_config.html.markdown +++ b/website/docs/r/apigee_addons_config.html.markdown @@ -138,6 +138,12 @@ The following arguments are supported: Addon configurations of the Apigee organization. Structure is [documented below](#nested_addons_config). +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `addons_config` block supports: diff --git a/website/docs/r/apigee_api.html.markdown b/website/docs/r/apigee_api.html.markdown index 2ff1e20cef0..3ab9bdd2a23 100644 --- a/website/docs/r/apigee_api.html.markdown +++ b/website/docs/r/apigee_api.html.markdown @@ -67,6 +67,14 @@ The following arguments are supported: (Required) Path to the config zip bundle. +* `deletion_policy` - + (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. + - - - ## Attributes Reference diff --git a/website/docs/r/apigee_api_deployment.html.markdown b/website/docs/r/apigee_api_deployment.html.markdown index f982627ff31..e37940a1852 100644 --- a/website/docs/r/apigee_api_deployment.html.markdown +++ b/website/docs/r/apigee_api_deployment.html.markdown @@ -96,6 +96,12 @@ The following arguments are supported: The revision of the API proxy to be deployed. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/apigee_api_product.html.markdown b/website/docs/r/apigee_api_product.html.markdown index 791f3d1a660..22d56b85591 100644 --- a/website/docs/r/apigee_api_product.html.markdown +++ b/website/docs/r/apigee_api_product.html.markdown @@ -465,6 +465,12 @@ The following arguments are supported: (Optional) Optional. The resource ID of the parent Space. If not set, the parent resource will be the Organization. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `attributes` block supports: diff --git a/website/docs/r/apigee_app_group.html.markdown b/website/docs/r/apigee_app_group.html.markdown index 92dc880f0c0..6af0f050b8f 100644 --- a/website/docs/r/apigee_app_group.html.markdown +++ b/website/docs/r/apigee_app_group.html.markdown @@ -176,6 +176,12 @@ The following arguments are supported: A list of attributes Structure is [documented below](#nested_attributes). +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `attributes` block supports: diff --git a/website/docs/r/apigee_control_plane_access.html.markdown b/website/docs/r/apigee_control_plane_access.html.markdown index ef17d21b591..312bf929949 100644 --- a/website/docs/r/apigee_control_plane_access.html.markdown +++ b/website/docs/r/apigee_control_plane_access.html.markdown @@ -100,6 +100,12 @@ The following arguments are supported: The `service-account-name` is formatted like an email address. For example: serviceAccount@my_project_id.iam.gserviceaccount.com You might specify multiple service accounts, for example, if you have multiple environments and wish to assign a unique service account to each one. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/apigee_developer.html.markdown b/website/docs/r/apigee_developer.html.markdown index a2f51d5aaba..b608d029716 100644 --- a/website/docs/r/apigee_developer.html.markdown +++ b/website/docs/r/apigee_developer.html.markdown @@ -169,6 +169,12 @@ The following arguments are supported: Developer attributes (name/value pairs). The custom attribute limit is 18. Structure is [documented below](#nested_attributes). +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `attributes` block supports: diff --git a/website/docs/r/apigee_developer_app.html.markdown b/website/docs/r/apigee_developer_app.html.markdown index 2d2a9c48ab2..6be70e64712 100644 --- a/website/docs/r/apigee_developer_app.html.markdown +++ b/website/docs/r/apigee_developer_app.html.markdown @@ -245,6 +245,12 @@ The following arguments are supported: Developer attributes (name/value pairs). The custom attribute limit is 18. Structure is [documented below](#nested_attributes). +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `attributes` block supports: diff --git a/website/docs/r/apigee_dns_zone.html.markdown b/website/docs/r/apigee_dns_zone.html.markdown index bb166211c7e..c5cc46a51f2 100644 --- a/website/docs/r/apigee_dns_zone.html.markdown +++ b/website/docs/r/apigee_dns_zone.html.markdown @@ -87,6 +87,12 @@ The following arguments are supported: ID of the dns zone. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `peering_config` block supports: diff --git a/website/docs/r/apigee_endpoint_attachment.html.markdown b/website/docs/r/apigee_endpoint_attachment.html.markdown index ed48001e2dd..70ef3228aab 100644 --- a/website/docs/r/apigee_endpoint_attachment.html.markdown +++ b/website/docs/r/apigee_endpoint_attachment.html.markdown @@ -53,6 +53,12 @@ The following arguments are supported: ID of the endpoint attachment. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/apigee_env_keystore.html.markdown b/website/docs/r/apigee_env_keystore.html.markdown index 70cf06e5fc6..ecfbaf80f69 100644 --- a/website/docs/r/apigee_env_keystore.html.markdown +++ b/website/docs/r/apigee_env_keystore.html.markdown @@ -46,6 +46,12 @@ The following arguments are supported: The name of the newly created keystore. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/apigee_env_references.html.markdown b/website/docs/r/apigee_env_references.html.markdown index 4e770233dde..67087eaee24 100644 --- a/website/docs/r/apigee_env_references.html.markdown +++ b/website/docs/r/apigee_env_references.html.markdown @@ -58,6 +58,12 @@ The following arguments are supported: (Optional) Optional. A human-readable description of this reference. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/apigee_envgroup.html.markdown b/website/docs/r/apigee_envgroup.html.markdown index a366af553c0..888acc1b85c 100644 --- a/website/docs/r/apigee_envgroup.html.markdown +++ b/website/docs/r/apigee_envgroup.html.markdown @@ -87,6 +87,12 @@ The following arguments are supported: (Optional) Hostnames of the environment group. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/apigee_envgroup_attachment.html.markdown b/website/docs/r/apigee_envgroup_attachment.html.markdown index 7aa2929d61c..df2da689f43 100644 --- a/website/docs/r/apigee_envgroup_attachment.html.markdown +++ b/website/docs/r/apigee_envgroup_attachment.html.markdown @@ -123,6 +123,12 @@ The following arguments are supported: in the format `organizations/{{org_name}}/envgroups/{{envgroup_name}}`. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/apigee_environment.html.markdown b/website/docs/r/apigee_environment.html.markdown index e2c7281ae81..149e19bb597 100644 --- a/website/docs/r/apigee_environment.html.markdown +++ b/website/docs/r/apigee_environment.html.markdown @@ -142,6 +142,12 @@ The following arguments are supported: The algorithm to resolve IP. This will affect Analytics, API Security, and other features that use the client ip. To remove a client ip resolution config, update the field to an empty value. Example: '{ "clientIpResolutionConfig" = {} }' For more information, see: https://cloud.google.com/apigee/docs/api-platform/system-administration/client-ip-resolution Structure is [documented below](#nested_client_ip_resolution_config). +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `node_config` block supports: diff --git a/website/docs/r/apigee_environment_addons_config.html.markdown b/website/docs/r/apigee_environment_addons_config.html.markdown index d3bcb3b6f5a..2a51451ea12 100644 --- a/website/docs/r/apigee_environment_addons_config.html.markdown +++ b/website/docs/r/apigee_environment_addons_config.html.markdown @@ -70,6 +70,12 @@ The following arguments are supported: (Optional) Flag to enable/disable Analytics. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/apigee_environment_api_revision_deployment.html.markdown b/website/docs/r/apigee_environment_api_revision_deployment.html.markdown index c4121e09244..768573cc3ce 100644 --- a/website/docs/r/apigee_environment_api_revision_deployment.html.markdown +++ b/website/docs/r/apigee_environment_api_revision_deployment.html.markdown @@ -78,6 +78,12 @@ The following arguments are supported: (Optional) Optional service account the deployed proxy runs as. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/apigee_environment_keyvaluemaps.html.markdown b/website/docs/r/apigee_environment_keyvaluemaps.html.markdown index 83d782c6221..5cabe13f52c 100644 --- a/website/docs/r/apigee_environment_keyvaluemaps.html.markdown +++ b/website/docs/r/apigee_environment_keyvaluemaps.html.markdown @@ -106,6 +106,12 @@ The following arguments are supported: in the format `organizations/{{org_name}}/environments/{{env_name}}`. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/apigee_environment_keyvaluemaps_entries.html.markdown b/website/docs/r/apigee_environment_keyvaluemaps_entries.html.markdown index 52afa657e5f..97bd69a9c15 100644 --- a/website/docs/r/apigee_environment_keyvaluemaps_entries.html.markdown +++ b/website/docs/r/apigee_environment_keyvaluemaps_entries.html.markdown @@ -123,6 +123,12 @@ The following arguments are supported: in the format `organizations/{{org_name}}/environments/{{env_name}}/keyvaluemaps/{{keyvaluemap_name}}`. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/apigee_flowhook.html.markdown b/website/docs/r/apigee_flowhook.html.markdown index 839cb30ad55..ef1c82ddb81 100644 --- a/website/docs/r/apigee_flowhook.html.markdown +++ b/website/docs/r/apigee_flowhook.html.markdown @@ -58,6 +58,14 @@ The following arguments are supported: (Optional) Flag that specifies whether execution should continue if the flow hook throws an exception. Set to true to continue execution. Set to false to stop execution if the flow hook throws an exception. Defaults to true. +* `deletion_policy` - + (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. + ## Attributes Reference diff --git a/website/docs/r/apigee_instance.html.markdown b/website/docs/r/apigee_instance.html.markdown index 4e1826fc0dd..1b9eaa87775 100644 --- a/website/docs/r/apigee_instance.html.markdown +++ b/website/docs/r/apigee_instance.html.markdown @@ -278,6 +278,12 @@ The following arguments are supported: Apigee customers can enable access logging to ship the access logs to their own project's cloud logging. Structure is [documented below](#nested_access_logging_config). +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `access_logging_config` block supports: diff --git a/website/docs/r/apigee_instance_attachment.html.markdown b/website/docs/r/apigee_instance_attachment.html.markdown index cf1c8956c8f..edb90fc02c8 100644 --- a/website/docs/r/apigee_instance_attachment.html.markdown +++ b/website/docs/r/apigee_instance_attachment.html.markdown @@ -123,6 +123,12 @@ The following arguments are supported: in the format `organizations/{{org_name}}/instances/{{instance_name}}`. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/apigee_keystores_aliases_pkcs12.html.markdown b/website/docs/r/apigee_keystores_aliases_pkcs12.html.markdown index 9d47080f258..a12aab594bb 100644 --- a/website/docs/r/apigee_keystores_aliases_pkcs12.html.markdown +++ b/website/docs/r/apigee_keystores_aliases_pkcs12.html.markdown @@ -53,6 +53,14 @@ The following arguments are supported: (Required) PKCS12 file content +* `deletion_policy` - + (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. + - - - * `password` - diff --git a/website/docs/r/apigee_keystores_aliases_self_signed_cert.html.markdown b/website/docs/r/apigee_keystores_aliases_self_signed_cert.html.markdown index b22f99a9312..96aa2afca9f 100644 --- a/website/docs/r/apigee_keystores_aliases_self_signed_cert.html.markdown +++ b/website/docs/r/apigee_keystores_aliases_self_signed_cert.html.markdown @@ -172,6 +172,12 @@ The following arguments are supported: (Optional) Validity duration of certificate, in days. Accepts positive non-zero value. Defaults to 365. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `subject` block supports: diff --git a/website/docs/r/apigee_nat_address.html.markdown b/website/docs/r/apigee_nat_address.html.markdown index 101f7c166c4..ba39f6bbf07 100644 --- a/website/docs/r/apigee_nat_address.html.markdown +++ b/website/docs/r/apigee_nat_address.html.markdown @@ -209,6 +209,12 @@ The following arguments are supported: (Optional) Flag that specifies whether the reserved NAT address should be activate. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/apigee_organization.html.markdown b/website/docs/r/apigee_organization.html.markdown index 5d9b71790fe..39ce84e4b59 100644 --- a/website/docs/r/apigee_organization.html.markdown +++ b/website/docs/r/apigee_organization.html.markdown @@ -287,6 +287,12 @@ The following arguments are supported: Default value is `DELETION_RETENTION_UNSPECIFIED`. Possible values are: `DELETION_RETENTION_UNSPECIFIED`, `MINIMUM`. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `properties` block supports: diff --git a/website/docs/r/apigee_security_action.html.markdown b/website/docs/r/apigee_security_action.html.markdown index 2a71e0955f7..a187a4e0032 100644 --- a/website/docs/r/apigee_security_action.html.markdown +++ b/website/docs/r/apigee_security_action.html.markdown @@ -176,6 +176,12 @@ The following arguments are supported: The TTL for this SecurityAction. A duration in seconds with up to nine fractional digits, ending with 's'. Example: "3.5s". +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `condition_config` block supports: diff --git a/website/docs/r/apigee_security_feedback.html.markdown b/website/docs/r/apigee_security_feedback.html.markdown index e8c6267aa50..c7d5a75ce5a 100644 --- a/website/docs/r/apigee_security_feedback.html.markdown +++ b/website/docs/r/apigee_security_feedback.html.markdown @@ -130,6 +130,12 @@ The following arguments are supported: (Optional) Optional text the user can provide for additional, unstructured context. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `feedback_contexts` block supports: diff --git a/website/docs/r/apigee_security_monitoring_condition.html.markdown b/website/docs/r/apigee_security_monitoring_condition.html.markdown index a06dd58ae43..b29e06f9fc6 100644 --- a/website/docs/r/apigee_security_monitoring_condition.html.markdown +++ b/website/docs/r/apigee_security_monitoring_condition.html.markdown @@ -116,6 +116,12 @@ The following arguments are supported: (Optional) A nested object resource. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/apigee_security_profile_v2.html.markdown b/website/docs/r/apigee_security_profile_v2.html.markdown index f7f9841d65c..4603d5f57f3 100644 --- a/website/docs/r/apigee_security_profile_v2.html.markdown +++ b/website/docs/r/apigee_security_profile_v2.html.markdown @@ -116,6 +116,12 @@ The following arguments are supported: (Optional) Description of the security profile. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `profile_assessment_configs` block supports: diff --git a/website/docs/r/apigee_sharedflow.html.markdown b/website/docs/r/apigee_sharedflow.html.markdown index 210d7dd3066..3eae3134925 100644 --- a/website/docs/r/apigee_sharedflow.html.markdown +++ b/website/docs/r/apigee_sharedflow.html.markdown @@ -140,6 +140,14 @@ The following arguments are supported: (Required) Path to the config zip bundle. +* `deletion_policy` - + (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. + - - - diff --git a/website/docs/r/apigee_sharedflow_deployment.html.markdown b/website/docs/r/apigee_sharedflow_deployment.html.markdown index 4b9359c6682..606f3e10759 100644 --- a/website/docs/r/apigee_sharedflow_deployment.html.markdown +++ b/website/docs/r/apigee_sharedflow_deployment.html.markdown @@ -50,6 +50,13 @@ The following arguments are supported: (Required) Revision of the Sharedflow to be deployed. +* `deletion_policy` - + (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. - - - diff --git a/website/docs/r/apigee_space.html.markdown b/website/docs/r/apigee_space.html.markdown index 39377031143..cc8f3a582ed 100644 --- a/website/docs/r/apigee_space.html.markdown +++ b/website/docs/r/apigee_space.html.markdown @@ -86,6 +86,12 @@ The following arguments are supported: Space ID of the Apigee Space. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/apigee_sync_authorization.html.markdown b/website/docs/r/apigee_sync_authorization.html.markdown index 0c01d7c5940..8f06bde7069 100644 --- a/website/docs/r/apigee_sync_authorization.html.markdown +++ b/website/docs/r/apigee_sync_authorization.html.markdown @@ -92,6 +92,12 @@ The following arguments are supported: Name of the Apigee organization. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/apigee_target_server.html.markdown b/website/docs/r/apigee_target_server.html.markdown index f47f4c89103..44c8a042c8d 100644 --- a/website/docs/r/apigee_target_server.html.markdown +++ b/website/docs/r/apigee_target_server.html.markdown @@ -149,6 +149,12 @@ The following arguments are supported: Immutable. The protocol used by this TargetServer. Possible values are: `HTTP`, `HTTP2`, `GRPC_TARGET`, `GRPC`, `EXTERNAL_CALLOUT`. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `s_sl_info` block supports: diff --git a/website/docs/r/apihub_api_hub_instance.html.markdown b/website/docs/r/apihub_api_hub_instance.html.markdown index 1cf89844fc7..162979bb536 100644 --- a/website/docs/r/apihub_api_hub_instance.html.markdown +++ b/website/docs/r/apihub_api_hub_instance.html.markdown @@ -97,6 +97,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `config` block supports: diff --git a/website/docs/r/apihub_curation.html.markdown b/website/docs/r/apihub_curation.html.markdown index 8ce69c8aaea..adb52d40780 100644 --- a/website/docs/r/apihub_curation.html.markdown +++ b/website/docs/r/apihub_curation.html.markdown @@ -88,6 +88,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `endpoint` block supports: diff --git a/website/docs/r/apihub_host_project_registration.html.markdown b/website/docs/r/apihub_host_project_registration.html.markdown index 3b738eb215d..c5c6934b4ba 100644 --- a/website/docs/r/apihub_host_project_registration.html.markdown +++ b/website/docs/r/apihub_host_project_registration.html.markdown @@ -88,6 +88,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/apihub_plugin.html.markdown b/website/docs/r/apihub_plugin.html.markdown index 885dceaf074..03fcfce3332 100644 --- a/website/docs/r/apihub_plugin.html.markdown +++ b/website/docs/r/apihub_plugin.html.markdown @@ -161,6 +161,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `actions_config` block supports: diff --git a/website/docs/r/apihub_plugin_instance.html.markdown b/website/docs/r/apihub_plugin_instance.html.markdown index 18ca9010cd5..8c7e7e58ee7 100644 --- a/website/docs/r/apihub_plugin_instance.html.markdown +++ b/website/docs/r/apihub_plugin_instance.html.markdown @@ -87,6 +87,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `actions` block supports: diff --git a/website/docs/r/apikeys_key.html.markdown b/website/docs/r/apikeys_key.html.markdown index 48d1517cfd3..b23b5838442 100644 --- a/website/docs/r/apikeys_key.html.markdown +++ b/website/docs/r/apikeys_key.html.markdown @@ -169,6 +169,13 @@ The following arguments are supported: * `service_account_email` - (Optional) The email of the service account the key is bound to. If this field is specified, the key is a service account bound key and auth enabled. See [Documentation](https://cloud.google.com/docs/authentication/api-keys?#api-keys-bound-sa) for more details. + +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. diff --git a/website/docs/r/app_engine_application_url_dispatch_rules.html.markdown b/website/docs/r/app_engine_application_url_dispatch_rules.html.markdown index 671f3f9a0bc..0e6aae55a9a 100644 --- a/website/docs/r/app_engine_application_url_dispatch_rules.html.markdown +++ b/website/docs/r/app_engine_application_url_dispatch_rules.html.markdown @@ -99,6 +99,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `dispatch_rules` block supports: diff --git a/website/docs/r/app_engine_domain_mapping.html.markdown b/website/docs/r/app_engine_domain_mapping.html.markdown index 5e055395810..7ac3ecb27f5 100644 --- a/website/docs/r/app_engine_domain_mapping.html.markdown +++ b/website/docs/r/app_engine_domain_mapping.html.markdown @@ -73,6 +73,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `ssl_settings` block supports: diff --git a/website/docs/r/app_engine_firewall_rule.html.markdown b/website/docs/r/app_engine_firewall_rule.html.markdown index 76f910eadef..1e44edfb404 100644 --- a/website/docs/r/app_engine_firewall_rule.html.markdown +++ b/website/docs/r/app_engine_firewall_rule.html.markdown @@ -87,6 +87,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/app_engine_flexible_app_version.html.markdown b/website/docs/r/app_engine_flexible_app_version.html.markdown index d21450c7756..c74e6c0e660 100644 --- a/website/docs/r/app_engine_flexible_app_version.html.markdown +++ b/website/docs/r/app_engine_flexible_app_version.html.markdown @@ -294,6 +294,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. * `noop_on_destroy` - (Optional) If set to `true`, the application version will not be deleted. * `delete_service_on_destroy` - (Optional) If set to `true`, the service will be deleted if it is the last version. diff --git a/website/docs/r/app_engine_service_network_settings.html.markdown b/website/docs/r/app_engine_service_network_settings.html.markdown index 6a7715d545a..96290bc7ef6 100644 --- a/website/docs/r/app_engine_service_network_settings.html.markdown +++ b/website/docs/r/app_engine_service_network_settings.html.markdown @@ -93,6 +93,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `network_settings` block supports: diff --git a/website/docs/r/app_engine_service_split_traffic.html.markdown b/website/docs/r/app_engine_service_split_traffic.html.markdown index c84da8351b0..0030e60843e 100644 --- a/website/docs/r/app_engine_service_split_traffic.html.markdown +++ b/website/docs/r/app_engine_service_split_traffic.html.markdown @@ -117,6 +117,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `split` block supports: diff --git a/website/docs/r/app_engine_standard_app_version.html.markdown b/website/docs/r/app_engine_standard_app_version.html.markdown index 202a3164e65..40b76ccd2f1 100644 --- a/website/docs/r/app_engine_standard_app_version.html.markdown +++ b/website/docs/r/app_engine_standard_app_version.html.markdown @@ -227,6 +227,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. * `noop_on_destroy` - (Optional) If set to `true`, the application version will not be deleted. * `delete_service_on_destroy` - (Optional) If set to `true`, the service will be deleted if it is the last version. diff --git a/website/docs/r/apphub_application.html.markdown b/website/docs/r/apphub_application.html.markdown index 67a9b4a36b2..c606b112ced 100644 --- a/website/docs/r/apphub_application.html.markdown +++ b/website/docs/r/apphub_application.html.markdown @@ -134,6 +134,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `scope` block supports: diff --git a/website/docs/r/apphub_boundary.html.markdown b/website/docs/r/apphub_boundary.html.markdown index f9b4a6513eb..42779b373ff 100644 --- a/website/docs/r/apphub_boundary.html.markdown +++ b/website/docs/r/apphub_boundary.html.markdown @@ -59,6 +59,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/apphub_service.html.markdown b/website/docs/r/apphub_service.html.markdown index 2749af38e35..a8c15cbd37a 100644 --- a/website/docs/r/apphub_service.html.markdown +++ b/website/docs/r/apphub_service.html.markdown @@ -314,6 +314,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `attributes` block supports: diff --git a/website/docs/r/apphub_service_project_attachment.html.markdown b/website/docs/r/apphub_service_project_attachment.html.markdown index bcc14f7514f..2663feb7cf4 100644 --- a/website/docs/r/apphub_service_project_attachment.html.markdown +++ b/website/docs/r/apphub_service_project_attachment.html.markdown @@ -90,6 +90,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/apphub_workload.html.markdown b/website/docs/r/apphub_workload.html.markdown index b5dee498c06..5bffe22ba5e 100644 --- a/website/docs/r/apphub_workload.html.markdown +++ b/website/docs/r/apphub_workload.html.markdown @@ -349,6 +349,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `attributes` block supports: diff --git a/website/docs/r/artifact_registry_repository.html.markdown b/website/docs/r/artifact_registry_repository.html.markdown index 8c7f06e5a49..03b4062350f 100644 --- a/website/docs/r/artifact_registry_repository.html.markdown +++ b/website/docs/r/artifact_registry_repository.html.markdown @@ -776,6 +776,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `docker_config` block supports: diff --git a/website/docs/r/artifact_registry_rule.html.markdown b/website/docs/r/artifact_registry_rule.html.markdown index addd6b51047..5b838fda4c3 100644 --- a/website/docs/r/artifact_registry_rule.html.markdown +++ b/website/docs/r/artifact_registry_rule.html.markdown @@ -140,6 +140,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `condition` block supports: diff --git a/website/docs/r/artifact_registry_vpcsc_config.html.markdown b/website/docs/r/artifact_registry_vpcsc_config.html.markdown index 29904097cf0..3dc8a088e32 100644 --- a/website/docs/r/artifact_registry_vpcsc_config.html.markdown +++ b/website/docs/r/artifact_registry_vpcsc_config.html.markdown @@ -63,6 +63,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/assured_workloads_workload.html.markdown b/website/docs/r/assured_workloads_workload.html.markdown index 2ba69170c1c..cb3b123c356 100644 --- a/website/docs/r/assured_workloads_workload.html.markdown +++ b/website/docs/r/assured_workloads_workload.html.markdown @@ -214,6 +214,13 @@ Please refer to the field `effective_labels` for all of the labels present on th * `workload_options` - (Optional) Optional. Used to specify certain options for a workload during workload creation - currently only supporting KAT Optionality for Regional Controls workloads. + +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. diff --git a/website/docs/r/backup_dr_backup_plan.html.markdown b/website/docs/r/backup_dr_backup_plan.html.markdown index ea58fa14df0..52f4d81144e 100644 --- a/website/docs/r/backup_dr_backup_plan.html.markdown +++ b/website/docs/r/backup_dr_backup_plan.html.markdown @@ -217,6 +217,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `backup_rules` block supports: diff --git a/website/docs/r/backup_dr_backup_plan_association.html.markdown b/website/docs/r/backup_dr_backup_plan_association.html.markdown index 9437acfe860..62956085032 100644 --- a/website/docs/r/backup_dr_backup_plan_association.html.markdown +++ b/website/docs/r/backup_dr_backup_plan_association.html.markdown @@ -197,6 +197,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/backup_dr_backup_vault.html.markdown b/website/docs/r/backup_dr_backup_vault.html.markdown index ec158a16b69..91608bcd58c 100644 --- a/website/docs/r/backup_dr_backup_vault.html.markdown +++ b/website/docs/r/backup_dr_backup_vault.html.markdown @@ -170,6 +170,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `encryption_config` block supports: diff --git a/website/docs/r/backup_dr_management_server.html.markdown b/website/docs/r/backup_dr_management_server.html.markdown index 1aa457fe93a..0b040fcb974 100644 --- a/website/docs/r/backup_dr_management_server.html.markdown +++ b/website/docs/r/backup_dr_management_server.html.markdown @@ -88,6 +88,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `networks` block supports: diff --git a/website/docs/r/backup_dr_restore_workload.html.markdown b/website/docs/r/backup_dr_restore_workload.html.markdown index 75fba2d131c..dd99dc47053 100644 --- a/website/docs/r/backup_dr_restore_workload.html.markdown +++ b/website/docs/r/backup_dr_restore_workload.html.markdown @@ -298,6 +298,12 @@ The following arguments are supported: Optional. If true (default), running terraform destroy will delete the live resource in GCP. If false, only the restore record is removed from the state, leaving the resource active. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `compute_instance_target_environment` block supports: diff --git a/website/docs/r/backup_dr_service_config.html.markdown b/website/docs/r/backup_dr_service_config.html.markdown index a1314e84f37..09779cc775c 100644 --- a/website/docs/r/backup_dr_service_config.html.markdown +++ b/website/docs/r/backup_dr_service_config.html.markdown @@ -55,6 +55,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/beyondcorp_app_connection.html.markdown b/website/docs/r/beyondcorp_app_connection.html.markdown index 45fed5475f5..41d826eaed2 100644 --- a/website/docs/r/beyondcorp_app_connection.html.markdown +++ b/website/docs/r/beyondcorp_app_connection.html.markdown @@ -161,6 +161,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `application_endpoint` block supports: diff --git a/website/docs/r/beyondcorp_app_connector.html.markdown b/website/docs/r/beyondcorp_app_connector.html.markdown index 339de13871e..24a20bc425b 100644 --- a/website/docs/r/beyondcorp_app_connector.html.markdown +++ b/website/docs/r/beyondcorp_app_connector.html.markdown @@ -120,6 +120,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `principal_info` block supports: diff --git a/website/docs/r/beyondcorp_app_gateway.html.markdown b/website/docs/r/beyondcorp_app_gateway.html.markdown index 7619225d4f7..cb136dd6e07 100644 --- a/website/docs/r/beyondcorp_app_gateway.html.markdown +++ b/website/docs/r/beyondcorp_app_gateway.html.markdown @@ -110,6 +110,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/beyondcorp_security_gateway.html.markdown b/website/docs/r/beyondcorp_security_gateway.html.markdown index e2b2f7248d6..85ca90e0a54 100644 --- a/website/docs/r/beyondcorp_security_gateway.html.markdown +++ b/website/docs/r/beyondcorp_security_gateway.html.markdown @@ -146,6 +146,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `hubs` block supports: diff --git a/website/docs/r/beyondcorp_security_gateway_application.html.markdown b/website/docs/r/beyondcorp_security_gateway_application.html.markdown index 6a9fe6d0949..78b4be4c794 100644 --- a/website/docs/r/beyondcorp_security_gateway_application.html.markdown +++ b/website/docs/r/beyondcorp_security_gateway_application.html.markdown @@ -218,6 +218,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `endpoint_matchers` block supports: diff --git a/website/docs/r/biglake_catalog.html.markdown b/website/docs/r/biglake_catalog.html.markdown index 1c79eccb763..45c5fccd969 100644 --- a/website/docs/r/biglake_catalog.html.markdown +++ b/website/docs/r/biglake_catalog.html.markdown @@ -63,6 +63,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/biglake_database.html.markdown b/website/docs/r/biglake_database.html.markdown index 445dff4fbf0..ce2f17f536d 100644 --- a/website/docs/r/biglake_database.html.markdown +++ b/website/docs/r/biglake_database.html.markdown @@ -93,6 +93,12 @@ The following arguments are supported: The name of the database. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `hive_options` block supports: diff --git a/website/docs/r/biglake_iceberg_catalog.html.markdown b/website/docs/r/biglake_iceberg_catalog.html.markdown index cdb3054ae43..806c5876e7e 100644 --- a/website/docs/r/biglake_iceberg_catalog.html.markdown +++ b/website/docs/r/biglake_iceberg_catalog.html.markdown @@ -117,6 +117,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/biglake_iceberg_namespace.html.markdown b/website/docs/r/biglake_iceberg_namespace.html.markdown index 2afb4fa1589..7b43f3141ee 100644 --- a/website/docs/r/biglake_iceberg_namespace.html.markdown +++ b/website/docs/r/biglake_iceberg_namespace.html.markdown @@ -71,6 +71,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/biglake_iceberg_table.html.markdown b/website/docs/r/biglake_iceberg_table.html.markdown index 10ac44964d4..3738f672404 100644 --- a/website/docs/r/biglake_iceberg_table.html.markdown +++ b/website/docs/r/biglake_iceberg_table.html.markdown @@ -167,6 +167,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `schema` block supports: diff --git a/website/docs/r/biglake_table.html.markdown b/website/docs/r/biglake_table.html.markdown index 371f3a98214..919e3a70c3a 100644 --- a/website/docs/r/biglake_table.html.markdown +++ b/website/docs/r/biglake_table.html.markdown @@ -127,6 +127,12 @@ The following arguments are supported: (Optional) The id of the parent database. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `hive_options` block supports: diff --git a/website/docs/r/bigquery_analytics_hub_data_exchange.html.markdown b/website/docs/r/bigquery_analytics_hub_data_exchange.html.markdown index 8d370ac205f..5b748afda96 100644 --- a/website/docs/r/bigquery_analytics_hub_data_exchange.html.markdown +++ b/website/docs/r/bigquery_analytics_hub_data_exchange.html.markdown @@ -152,6 +152,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `sharing_environment_config` block supports: diff --git a/website/docs/r/bigquery_analytics_hub_data_exchange_subscription.html.markdown b/website/docs/r/bigquery_analytics_hub_data_exchange_subscription.html.markdown index 74cd9816ddc..0350de994ed 100644 --- a/website/docs/r/bigquery_analytics_hub_data_exchange_subscription.html.markdown +++ b/website/docs/r/bigquery_analytics_hub_data_exchange_subscription.html.markdown @@ -179,6 +179,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. * `refresh_policy` - (Optional) Controls when the subscription is automatically refreshed by the provider. * `ON_READ`: Default value if not specified. The subscription will be refreshed every time Terraform performs a read operation (e.g., `terraform plan`, `terraform apply`, `terraform refresh`). This ensures the state is always up-to-date. * `ON_STALE`: The subscription will only be refreshed when its reported `state` (an output-only field from the API) is `STATE_STALE` during a Terraform read operation. diff --git a/website/docs/r/bigquery_analytics_hub_listing.html.markdown b/website/docs/r/bigquery_analytics_hub_listing.html.markdown index 3192d9a51c2..4eaa50d95f3 100644 --- a/website/docs/r/bigquery_analytics_hub_listing.html.markdown +++ b/website/docs/r/bigquery_analytics_hub_listing.html.markdown @@ -496,6 +496,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. * `delete_commercial` - (Optional) If the listing is commercial then this field must be set to true, otherwise a failure is thrown. This acts as a safety guard to avoid deleting commercial listings accidentally. diff --git a/website/docs/r/bigquery_analytics_hub_listing_subscription.html.markdown b/website/docs/r/bigquery_analytics_hub_listing_subscription.html.markdown index b9fc2e6ba4a..6906f78b2cc 100644 --- a/website/docs/r/bigquery_analytics_hub_listing_subscription.html.markdown +++ b/website/docs/r/bigquery_analytics_hub_listing_subscription.html.markdown @@ -149,6 +149,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `destination_dataset` block supports: diff --git a/website/docs/r/bigquery_bi_reservation.html.markdown b/website/docs/r/bigquery_bi_reservation.html.markdown index 083e2d93597..364cd677c40 100644 --- a/website/docs/r/bigquery_bi_reservation.html.markdown +++ b/website/docs/r/bigquery_bi_reservation.html.markdown @@ -67,6 +67,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `preferred_tables` block supports: diff --git a/website/docs/r/bigquery_capacity_commitment.html.markdown b/website/docs/r/bigquery_capacity_commitment.html.markdown index cf13888e976..6814fc73363 100644 --- a/website/docs/r/bigquery_capacity_commitment.html.markdown +++ b/website/docs/r/bigquery_capacity_commitment.html.markdown @@ -87,6 +87,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/bigquery_connection.html.markdown b/website/docs/r/bigquery_connection.html.markdown index 88868b7210f..e465eaff861 100644 --- a/website/docs/r/bigquery_connection.html.markdown +++ b/website/docs/r/bigquery_connection.html.markdown @@ -486,6 +486,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `cloud_sql` block supports: diff --git a/website/docs/r/bigquery_data_transfer_config.html.markdown b/website/docs/r/bigquery_data_transfer_config.html.markdown index 7f0f9ddff90..0b61c0e843d 100644 --- a/website/docs/r/bigquery_data_transfer_config.html.markdown +++ b/website/docs/r/bigquery_data_transfer_config.html.markdown @@ -247,6 +247,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `schedule_options` block supports: diff --git a/website/docs/r/bigquery_datapolicy_data_policy.html.markdown b/website/docs/r/bigquery_datapolicy_data_policy.html.markdown index 4b5d939b21e..94fa340cbb6 100644 --- a/website/docs/r/bigquery_datapolicy_data_policy.html.markdown +++ b/website/docs/r/bigquery_datapolicy_data_policy.html.markdown @@ -143,6 +143,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `data_masking_policy` block supports: diff --git a/website/docs/r/bigquery_datapolicyv2_data_policy.html.markdown b/website/docs/r/bigquery_datapolicyv2_data_policy.html.markdown index 9a4c494630c..daa2d562e13 100644 --- a/website/docs/r/bigquery_datapolicyv2_data_policy.html.markdown +++ b/website/docs/r/bigquery_datapolicyv2_data_policy.html.markdown @@ -157,6 +157,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `data_masking_policy` block supports: diff --git a/website/docs/r/bigquery_dataset.html.markdown b/website/docs/r/bigquery_dataset.html.markdown index be67d6faa1d..34d7c146077 100644 --- a/website/docs/r/bigquery_dataset.html.markdown +++ b/website/docs/r/bigquery_dataset.html.markdown @@ -377,6 +377,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. * `delete_contents_on_destroy` - (Optional) If set to `true`, delete all the tables in the dataset when destroying the resource; otherwise, destroying the resource will fail if tables are present. diff --git a/website/docs/r/bigquery_dataset_access.html.markdown b/website/docs/r/bigquery_dataset_access.html.markdown index 64da837e2de..63067a82978 100644 --- a/website/docs/r/bigquery_dataset_access.html.markdown +++ b/website/docs/r/bigquery_dataset_access.html.markdown @@ -236,6 +236,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `view` block supports: diff --git a/website/docs/r/bigquery_job.html.markdown b/website/docs/r/bigquery_job.html.markdown index afcea27a518..2c0d0f9b0f7 100644 --- a/website/docs/r/bigquery_job.html.markdown +++ b/website/docs/r/bigquery_job.html.markdown @@ -546,6 +546,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `query` block supports: diff --git a/website/docs/r/bigquery_reservation.html.markdown b/website/docs/r/bigquery_reservation.html.markdown index 32bbac65ed6..73a5602537d 100644 --- a/website/docs/r/bigquery_reservation.html.markdown +++ b/website/docs/r/bigquery_reservation.html.markdown @@ -178,6 +178,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `autoscale` block supports: diff --git a/website/docs/r/bigquery_reservation_assignment.html.markdown b/website/docs/r/bigquery_reservation_assignment.html.markdown index c8241b644ec..b9cdbedae91 100644 --- a/website/docs/r/bigquery_reservation_assignment.html.markdown +++ b/website/docs/r/bigquery_reservation_assignment.html.markdown @@ -74,6 +74,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/bigquery_reservation_group.html.markdown b/website/docs/r/bigquery_reservation_group.html.markdown index 160c603a49b..bec62cffc21 100644 --- a/website/docs/r/bigquery_reservation_group.html.markdown +++ b/website/docs/r/bigquery_reservation_group.html.markdown @@ -61,6 +61,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/bigquery_routine.html.markdown b/website/docs/r/bigquery_routine.html.markdown index af909764962..522703622a8 100644 --- a/website/docs/r/bigquery_routine.html.markdown +++ b/website/docs/r/bigquery_routine.html.markdown @@ -444,6 +444,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `arguments` block supports: diff --git a/website/docs/r/bigquery_row_access_policy.html.markdown b/website/docs/r/bigquery_row_access_policy.html.markdown index f6da9a546ce..4a1bdb6757b 100644 --- a/website/docs/r/bigquery_row_access_policy.html.markdown +++ b/website/docs/r/bigquery_row_access_policy.html.markdown @@ -126,6 +126,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/bigquery_table.html.markdown b/website/docs/r/bigquery_table.html.markdown index da8f88a0728..4d6dfc2db29 100644 --- a/website/docs/r/bigquery_table.html.markdown +++ b/website/docs/r/bigquery_table.html.markdown @@ -142,6 +142,14 @@ The following arguments are supported: * `effective_labels` - All of labels (key/value pairs) present on the resource in GCP, including the labels configured through Terraform, other clients and services. +* `deletion_policy` - + (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. + * `schema` - (Optional) A JSON schema for the table. ~>**NOTE:** Because this field expects a JSON string, any changes to the diff --git a/website/docs/r/bigtable_app_profile.html.markdown b/website/docs/r/bigtable_app_profile.html.markdown index 54ba1786ec4..eb3c76a65fd 100644 --- a/website/docs/r/bigtable_app_profile.html.markdown +++ b/website/docs/r/bigtable_app_profile.html.markdown @@ -234,6 +234,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `single_cluster_routing` block supports: diff --git a/website/docs/r/bigtable_authorized_view.html.markdown b/website/docs/r/bigtable_authorized_view.html.markdown index 514d3e16d55..af859b2ce73 100644 --- a/website/docs/r/bigtable_authorized_view.html.markdown +++ b/website/docs/r/bigtable_authorized_view.html.markdown @@ -112,6 +112,13 @@ The following arguments are supported: If not provided, currently deletion protection will be set to UNPROTECTED as it is the API default value. Note this field configs the deletion protection provided by the API in the backend, and should not be confused with Terraform-side deletion protection. * `subset_view` - (Optional) An AuthorizedView permitting access to an explicit subset of a Table. Structure is documented below. + +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ----- diff --git a/website/docs/r/bigtable_gc_policy.html.markdown b/website/docs/r/bigtable_gc_policy.html.markdown index 0472de8aacc..acbb78e92fe 100644 --- a/website/docs/r/bigtable_gc_policy.html.markdown +++ b/website/docs/r/bigtable_gc_policy.html.markdown @@ -175,10 +175,15 @@ The following arguments are supported: * `gc_rules` - (Optional) Serialized JSON object to represent a more complex GC policy. Conflicts with `mode`, `max_age` and `max_version`. Conflicts with `mode`, `max_age` and `max_version`. -* `deletion_policy` - (Optional) The deletion policy for the GC policy. - Setting ABANDON allows the resource to be abandoned rather than deleted. This is useful for GC policy as it cannot be deleted in a replicated instance. - - Possible values are: `ABANDON`. +* `deletion_policy` - (Optional) The deletion policy for the GC policy. Setting ABANDON allows the resource + to be abandoned rather than deleted. This is useful for GC policy as it cannot be deleted + in a replicated instance. + + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "DELETE" or "", deleting the resource is allowed. + + Possible values: PREVENT, ABANDON, DELETE. * `ignore_warnings` - (Optional) Boolean for whether to allow ignoring warnings when updating the gc policy. Setting this to `true` allows relaxing the gc policy for replicated clusters by up to 90 days, but keep in mind this may increase how long clusters are inconsistent. Make sure diff --git a/website/docs/r/bigtable_instance.html.markdown b/website/docs/r/bigtable_instance.html.markdown index 1a2c2099d50..f0b34f785f1 100644 --- a/website/docs/r/bigtable_instance.html.markdown +++ b/website/docs/r/bigtable_instance.html.markdown @@ -128,6 +128,14 @@ to default to the backend value. See [structure below](#nested_cluster). * `effective_labels` - All of labels (key/value pairs) present on the resource in GCP, including the labels configured through Terraform, other clients and services. +* `deletion_policy` - + (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. + * `tags` - (Optional) A set of key/value label pairs to assign to the resource. Tags must follow the requirements at [create and manage tags](https://docs.cloud.google.com/resource-manager/docs/tags/tags-creating-and-managing). ----- diff --git a/website/docs/r/bigtable_logical_view.html.markdown b/website/docs/r/bigtable_logical_view.html.markdown index a70830a57d6..f0b7657d56d 100644 --- a/website/docs/r/bigtable_logical_view.html.markdown +++ b/website/docs/r/bigtable_logical_view.html.markdown @@ -98,6 +98,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/bigtable_materialized_view.html.markdown b/website/docs/r/bigtable_materialized_view.html.markdown index fed4e4e3763..37dff6fcc77 100644 --- a/website/docs/r/bigtable_materialized_view.html.markdown +++ b/website/docs/r/bigtable_materialized_view.html.markdown @@ -99,6 +99,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/bigtable_schema_bundle.html.markdown b/website/docs/r/bigtable_schema_bundle.html.markdown index 8ff59b6d9ca..f3c7b8d7766 100644 --- a/website/docs/r/bigtable_schema_bundle.html.markdown +++ b/website/docs/r/bigtable_schema_bundle.html.markdown @@ -101,6 +101,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `proto_schema` block supports: diff --git a/website/docs/r/bigtable_table.html.markdown b/website/docs/r/bigtable_table.html.markdown index eb93b2b75ca..c656ca33e2d 100644 --- a/website/docs/r/bigtable_table.html.markdown +++ b/website/docs/r/bigtable_table.html.markdown @@ -115,6 +115,13 @@ to delete/recreate the entire `google_bigtable_table` resource. * `change_stream_retention` - (Optional) Duration to retain change stream data for the table. Set to 0 to disable. Must be between 1 and 7 days. * `automated_backup_policy` - (Optional) Defines an automated backup policy for a table, specified by Retention Period and Frequency. To _create_ a table with automated backup disabled, either omit the automated_backup_policy argument, or set both Retention Period and Frequency properties to "0". To disable automated backup on an _existing_ table that has automated backup enabled, set _both_ Retention Period and Frequency properties to "0". When updating an existing table, to modify the Retention Period or Frequency properties of the resource's automated backup policy, set the respective property to a non-zero value. If the automated_backup_policy argument is not provided in the configuration on update, the resource's automated backup policy will _not_ be modified. + +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ----- diff --git a/website/docs/r/billing_budget.html.markdown b/website/docs/r/billing_budget.html.markdown index e24d4355c54..051f08590c8 100644 --- a/website/docs/r/billing_budget.html.markdown +++ b/website/docs/r/billing_budget.html.markdown @@ -306,6 +306,12 @@ The following arguments are supported: IAM permissions determine who has full access to the budget's data. Possible values are: `OWNERSHIP_SCOPE_UNSPECIFIED`, `ALL_USERS`, `BILLING_ACCOUNT`. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `amount` block supports: diff --git a/website/docs/r/billing_project_info.html.markdown b/website/docs/r/billing_project_info.html.markdown index d9bb87fa826..e60c91713d4 100644 --- a/website/docs/r/billing_project_info.html.markdown +++ b/website/docs/r/billing_project_info.html.markdown @@ -65,6 +65,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/binary_authorization_attestor.html.markdown b/website/docs/r/binary_authorization_attestor.html.markdown index fb620f84e98..5233167e533 100644 --- a/website/docs/r/binary_authorization_attestor.html.markdown +++ b/website/docs/r/binary_authorization_attestor.html.markdown @@ -149,6 +149,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `attestation_authority_note` block supports: diff --git a/website/docs/r/binary_authorization_policy.html.markdown b/website/docs/r/binary_authorization_policy.html.markdown index 7ea674866eb..8a98198039c 100644 --- a/website/docs/r/binary_authorization_policy.html.markdown +++ b/website/docs/r/binary_authorization_policy.html.markdown @@ -145,6 +145,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `default_admission_rule` block supports: diff --git a/website/docs/r/blockchain_node_engine_blockchain_nodes.html.markdown b/website/docs/r/blockchain_node_engine_blockchain_nodes.html.markdown index 9546c187c2f..3233e152766 100644 --- a/website/docs/r/blockchain_node_engine_blockchain_nodes.html.markdown +++ b/website/docs/r/blockchain_node_engine_blockchain_nodes.html.markdown @@ -158,6 +158,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `ethereum_details` block supports: diff --git a/website/docs/r/certificate_manager_certificate.html.markdown b/website/docs/r/certificate_manager_certificate.html.markdown index 82fe323034d..246774b2968 100644 --- a/website/docs/r/certificate_manager_certificate.html.markdown +++ b/website/docs/r/certificate_manager_certificate.html.markdown @@ -421,6 +421,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `self_managed` block supports: diff --git a/website/docs/r/certificate_manager_certificate_issuance_config.html.markdown b/website/docs/r/certificate_manager_certificate_issuance_config.html.markdown index 2a5c221fe9e..e7342d918c4 100644 --- a/website/docs/r/certificate_manager_certificate_issuance_config.html.markdown +++ b/website/docs/r/certificate_manager_certificate_issuance_config.html.markdown @@ -153,6 +153,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `certificate_authority_config` block supports: diff --git a/website/docs/r/certificate_manager_certificate_map.html.markdown b/website/docs/r/certificate_manager_certificate_map.html.markdown index 4a9c3c9fc59..b7d3938baac 100644 --- a/website/docs/r/certificate_manager_certificate_map.html.markdown +++ b/website/docs/r/certificate_manager_certificate_map.html.markdown @@ -71,6 +71,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/certificate_manager_certificate_map_entry.html.markdown b/website/docs/r/certificate_manager_certificate_map_entry.html.markdown index 62ca0eb01f7..a69b12ab9e2 100644 --- a/website/docs/r/certificate_manager_certificate_map_entry.html.markdown +++ b/website/docs/r/certificate_manager_certificate_map_entry.html.markdown @@ -135,6 +135,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/certificate_manager_dns_authorization.html.markdown b/website/docs/r/certificate_manager_dns_authorization.html.markdown index 2bee591ac81..55eba32b8d1 100644 --- a/website/docs/r/certificate_manager_dns_authorization.html.markdown +++ b/website/docs/r/certificate_manager_dns_authorization.html.markdown @@ -116,6 +116,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/certificate_manager_trust_config.html.markdown b/website/docs/r/certificate_manager_trust_config.html.markdown index 450c8d37307..8b668e9b391 100644 --- a/website/docs/r/certificate_manager_trust_config.html.markdown +++ b/website/docs/r/certificate_manager_trust_config.html.markdown @@ -128,6 +128,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `trust_stores` block supports: diff --git a/website/docs/r/ces_agent.html.markdown b/website/docs/r/ces_agent.html.markdown index 1f748aa91d6..ab335dbbaec 100644 --- a/website/docs/r/ces_agent.html.markdown +++ b/website/docs/r/ces_agent.html.markdown @@ -441,6 +441,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `after_agent_callbacks` block supports: diff --git a/website/docs/r/ces_app.html.markdown b/website/docs/r/ces_app.html.markdown index b81153f0c73..c5329ed7964 100644 --- a/website/docs/r/ces_app.html.markdown +++ b/website/docs/r/ces_app.html.markdown @@ -489,6 +489,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `audio_processing_config` block supports: diff --git a/website/docs/r/ces_app_root_agent_association.html.markdown b/website/docs/r/ces_app_root_agent_association.html.markdown index b4943d353c7..bbe99240a17 100644 --- a/website/docs/r/ces_app_root_agent_association.html.markdown +++ b/website/docs/r/ces_app_root_agent_association.html.markdown @@ -105,6 +105,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/ces_app_version.html.markdown b/website/docs/r/ces_app_version.html.markdown index 12a7dc45224..b8007f63b93 100644 --- a/website/docs/r/ces_app_version.html.markdown +++ b/website/docs/r/ces_app_version.html.markdown @@ -82,6 +82,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/ces_deployment.html.markdown b/website/docs/r/ces_deployment.html.markdown index 709de02e7fb..e46d016e8bf 100644 --- a/website/docs/r/ces_deployment.html.markdown +++ b/website/docs/r/ces_deployment.html.markdown @@ -97,6 +97,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `channel_profile` block supports: diff --git a/website/docs/r/ces_evaluation.html.markdown b/website/docs/r/ces_evaluation.html.markdown index 16748ef81d0..edca7059584 100644 --- a/website/docs/r/ces_evaluation.html.markdown +++ b/website/docs/r/ces_evaluation.html.markdown @@ -720,6 +720,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `golden` block supports: diff --git a/website/docs/r/ces_example.html.markdown b/website/docs/r/ces_example.html.markdown index 32134e59c72..82268b53457 100644 --- a/website/docs/r/ces_example.html.markdown +++ b/website/docs/r/ces_example.html.markdown @@ -241,6 +241,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `messages` block supports: diff --git a/website/docs/r/ces_guardrail.html.markdown b/website/docs/r/ces_guardrail.html.markdown index 42b498f03a6..76f1f05e27e 100644 --- a/website/docs/r/ces_guardrail.html.markdown +++ b/website/docs/r/ces_guardrail.html.markdown @@ -358,6 +358,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `action` block supports: diff --git a/website/docs/r/ces_tool.html.markdown b/website/docs/r/ces_tool.html.markdown index 7f2e255fd68..ab6546c322b 100644 --- a/website/docs/r/ces_tool.html.markdown +++ b/website/docs/r/ces_tool.html.markdown @@ -358,6 +358,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `client_function` block supports: diff --git a/website/docs/r/ces_toolset.html.markdown b/website/docs/r/ces_toolset.html.markdown index 6fb5ce7a49e..7d97ef66599 100644 --- a/website/docs/r/ces_toolset.html.markdown +++ b/website/docs/r/ces_toolset.html.markdown @@ -643,6 +643,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `open_api_toolset` block supports: diff --git a/website/docs/r/chronicle_dashboard_chart.html.markdown b/website/docs/r/chronicle_dashboard_chart.html.markdown index 0df0e81ecee..4954c6cdceb 100644 --- a/website/docs/r/chronicle_dashboard_chart.html.markdown +++ b/website/docs/r/chronicle_dashboard_chart.html.markdown @@ -346,6 +346,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `dashboard_chart` block supports: diff --git a/website/docs/r/chronicle_data_access_label.html.markdown b/website/docs/r/chronicle_data_access_label.html.markdown index 59bf0a61832..efe0e3147b6 100644 --- a/website/docs/r/chronicle_data_access_label.html.markdown +++ b/website/docs/r/chronicle_data_access_label.html.markdown @@ -75,6 +75,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/chronicle_data_access_scope.html.markdown b/website/docs/r/chronicle_data_access_scope.html.markdown index de8e5f680f0..1e7a38290ad 100644 --- a/website/docs/r/chronicle_data_access_scope.html.markdown +++ b/website/docs/r/chronicle_data_access_scope.html.markdown @@ -191,6 +191,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `allowed_data_access_labels` block supports: diff --git a/website/docs/r/chronicle_data_table.html.markdown b/website/docs/r/chronicle_data_table.html.markdown index f524e0b5b1b..66f9e46c565 100644 --- a/website/docs/r/chronicle_data_table.html.markdown +++ b/website/docs/r/chronicle_data_table.html.markdown @@ -165,7 +165,14 @@ The following arguments are supported: * `deletion_policy` - (Optional) The policy governing the deletion of the data table. If set to `FORCE`, allows the deletion of the data table even if it contains rows. If set to `DEFAULT`,or if the field is omitted, the data table must be empty before it can be deleted. -Possible values: DEFAULT, FORCE + +When a 'terraform destroy' or 'terraform apply' would delete the resource, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", the command will behave as if set to "DEFAULT". + +Possible values: DEFAULT, FORCE, PREVENT, ABANDON, DELETE diff --git a/website/docs/r/chronicle_data_table_row.html.markdown b/website/docs/r/chronicle_data_table_row.html.markdown index 2a6bd1fcbca..416e82bfe44 100644 --- a/website/docs/r/chronicle_data_table_row.html.markdown +++ b/website/docs/r/chronicle_data_table_row.html.markdown @@ -115,6 +115,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/chronicle_feed.html.markdown b/website/docs/r/chronicle_feed.html.markdown index 4ef4dc70d1c..aac73f1c5c9 100644 --- a/website/docs/r/chronicle_feed.html.markdown +++ b/website/docs/r/chronicle_feed.html.markdown @@ -215,6 +215,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. * `secret` - (Optional) Output only. The secret generated for the feed. This is only available when the feed source type is HTTPS_PUSH_AMAZON_KINESIS_FIREHOSE. * `feed_service_account` - (Optional) Output only. The service account used by Chronicle to ingest data from Cloud Storage. This is only available when the feed source type is GOOGLE_CLOUD_STORAGE_EVENT_DRIVEN or GOOGLE_CLOUD_STORAGE. diff --git a/website/docs/r/chronicle_native_dashboard.html.markdown b/website/docs/r/chronicle_native_dashboard.html.markdown index 225f8b92bc2..2b8fd184919 100644 --- a/website/docs/r/chronicle_native_dashboard.html.markdown +++ b/website/docs/r/chronicle_native_dashboard.html.markdown @@ -111,6 +111,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `charts` block supports: diff --git a/website/docs/r/chronicle_reference_list.html.markdown b/website/docs/r/chronicle_reference_list.html.markdown index 7152b350c2a..6951fed9a18 100644 --- a/website/docs/r/chronicle_reference_list.html.markdown +++ b/website/docs/r/chronicle_reference_list.html.markdown @@ -114,6 +114,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `entries` block supports: diff --git a/website/docs/r/chronicle_retrohunt.html.markdown b/website/docs/r/chronicle_retrohunt.html.markdown index 4fdf957a718..3e05241e23f 100644 --- a/website/docs/r/chronicle_retrohunt.html.markdown +++ b/website/docs/r/chronicle_retrohunt.html.markdown @@ -88,6 +88,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `process_interval` block supports: diff --git a/website/docs/r/chronicle_rule.html.markdown b/website/docs/r/chronicle_rule.html.markdown index ea5a4c60143..ef961e2cacc 100644 --- a/website/docs/r/chronicle_rule.html.markdown +++ b/website/docs/r/chronicle_rule.html.markdown @@ -124,9 +124,16 @@ The following arguments are supported: If deletion_policy = "FORCE", any retrohunts and any detections associated with the rule will also be deleted. If deletion_policy = "DEFAULT", the call will only succeed if the rule has no associated retrohunts, including completed retrohunts, and no -associated detections. Regardless of this field's value, the rule -deployment associated with this rule will also be deleted. -Possible values: DEFAULT, FORCE +associated detections. Regardless of being set to "FORCE" the rule +deployment associated with this rule will also be deleted if deletion is successful. + +When a 'terraform destroy' or 'terraform apply' would delete the resource, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", the command will behave as if set to "DEFAULT". + +Possible values: DEFAULT, FORCE, PREVENT, ABANDON, DELETE diff --git a/website/docs/r/chronicle_rule_deployment.html.markdown b/website/docs/r/chronicle_rule_deployment.html.markdown index c7d19c28059..eeccf173fa0 100644 --- a/website/docs/r/chronicle_rule_deployment.html.markdown +++ b/website/docs/r/chronicle_rule_deployment.html.markdown @@ -142,6 +142,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/chronicle_watchlist.html.markdown b/website/docs/r/chronicle_watchlist.html.markdown index c12e2bdc936..97b3f59cb47 100644 --- a/website/docs/r/chronicle_watchlist.html.markdown +++ b/website/docs/r/chronicle_watchlist.html.markdown @@ -122,6 +122,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `entity_population_mechanism` block supports: diff --git a/website/docs/r/cloud_asset_folder_feed.html.markdown b/website/docs/r/cloud_asset_folder_feed.html.markdown index 82bf356f916..2e735437f7c 100644 --- a/website/docs/r/cloud_asset_folder_feed.html.markdown +++ b/website/docs/r/cloud_asset_folder_feed.html.markdown @@ -137,6 +137,12 @@ The following arguments are supported: condition are optional. Structure is [documented below](#nested_condition). +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `feed_output_config` block supports: diff --git a/website/docs/r/cloud_asset_organization_feed.html.markdown b/website/docs/r/cloud_asset_organization_feed.html.markdown index 953698347a7..bdc84019bf4 100644 --- a/website/docs/r/cloud_asset_organization_feed.html.markdown +++ b/website/docs/r/cloud_asset_organization_feed.html.markdown @@ -130,6 +130,12 @@ The following arguments are supported: condition are optional. Structure is [documented below](#nested_condition). +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `feed_output_config` block supports: diff --git a/website/docs/r/cloud_asset_project_feed.html.markdown b/website/docs/r/cloud_asset_project_feed.html.markdown index eb21972b76c..239e022a537 100644 --- a/website/docs/r/cloud_asset_project_feed.html.markdown +++ b/website/docs/r/cloud_asset_project_feed.html.markdown @@ -128,6 +128,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `feed_output_config` block supports: diff --git a/website/docs/r/cloud_identity_group.html.markdown b/website/docs/r/cloud_identity_group.html.markdown index 48c0e1d9139..67343b6df21 100644 --- a/website/docs/r/cloud_identity_group.html.markdown +++ b/website/docs/r/cloud_identity_group.html.markdown @@ -100,6 +100,12 @@ The following arguments are supported: Default value is `EMPTY`. Possible values are: `INITIAL_GROUP_CONFIG_UNSPECIFIED`, `WITH_INITIAL_OWNER`, `EMPTY`. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `group_key` block supports: diff --git a/website/docs/r/cloud_identity_group_membership.html.markdown b/website/docs/r/cloud_identity_group_membership.html.markdown index 323923e2959..8f3fc73a829 100644 --- a/website/docs/r/cloud_identity_group_membership.html.markdown +++ b/website/docs/r/cloud_identity_group_membership.html.markdown @@ -141,6 +141,12 @@ The following arguments are supported: EntityKey of the member. Structure is [documented below](#nested_preferred_member_key). +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. * `create_ignore_already_exists` - (Optional) If set to true, skip group member creation if a membership with the same name already exists. Defaults to false. diff --git a/website/docs/r/cloud_identity_policy.html.markdown b/website/docs/r/cloud_identity_policy.html.markdown index fe69a1c8f89..25bd1eae59e 100644 --- a/website/docs/r/cloud_identity_policy.html.markdown +++ b/website/docs/r/cloud_identity_policy.html.markdown @@ -75,6 +75,12 @@ The following arguments are supported: Structure is [documented below](#nested_setting). +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `policy_query` block supports: diff --git a/website/docs/r/cloud_ids_endpoint.html.markdown b/website/docs/r/cloud_ids_endpoint.html.markdown index b48ea0d1d28..fea535ab7de 100644 --- a/website/docs/r/cloud_ids_endpoint.html.markdown +++ b/website/docs/r/cloud_ids_endpoint.html.markdown @@ -91,6 +91,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/cloud_quotas_quota_adjuster_settings.html.markdown b/website/docs/r/cloud_quotas_quota_adjuster_settings.html.markdown index ed27c6b6e4b..bff0ff7ddd2 100644 --- a/website/docs/r/cloud_quotas_quota_adjuster_settings.html.markdown +++ b/website/docs/r/cloud_quotas_quota_adjuster_settings.html.markdown @@ -58,6 +58,12 @@ The following arguments are supported: The parent of the quota preference. Allowed parent format is "projects/[project-id / number]". +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/cloud_quotas_quota_preference.html.markdown b/website/docs/r/cloud_quotas_quota_preference.html.markdown index 6ddcba12084..57103c5bf73 100644 --- a/website/docs/r/cloud_quotas_quota_preference.html.markdown +++ b/website/docs/r/cloud_quotas_quota_preference.html.markdown @@ -96,6 +96,12 @@ The following arguments are supported: Default value is `QUOTA_SAFETY_CHECK_UNSPECIFIED`. Possible values are: `QUOTA_SAFETY_CHECK_UNSPECIFIED`, `QUOTA_DECREASE_BELOW_USAGE`, `QUOTA_DECREASE_PERCENTAGE_TOO_HIGH`. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `quota_config` block supports: diff --git a/website/docs/r/cloud_run_domain_mapping.html.markdown b/website/docs/r/cloud_run_domain_mapping.html.markdown index 0174d12a48d..d962b5d860f 100644 --- a/website/docs/r/cloud_run_domain_mapping.html.markdown +++ b/website/docs/r/cloud_run_domain_mapping.html.markdown @@ -93,6 +93,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `spec` block supports: diff --git a/website/docs/r/cloud_run_service.html.markdown b/website/docs/r/cloud_run_service.html.markdown index e4c44c5c104..249a4f5dd8d 100644 --- a/website/docs/r/cloud_run_service.html.markdown +++ b/website/docs/r/cloud_run_service.html.markdown @@ -391,6 +391,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. * `autogenerate_revision_name` - (Optional) If set to `true`, the revision name (template.metadata.name) will be omitted and autogenerated by Cloud Run. This cannot be set to `true` while `template.metadata.name` is also set. diff --git a/website/docs/r/cloud_run_v2_job.html.markdown b/website/docs/r/cloud_run_v2_job.html.markdown index 110627c6657..fac33accdc5 100644 --- a/website/docs/r/cloud_run_v2_job.html.markdown +++ b/website/docs/r/cloud_run_v2_job.html.markdown @@ -534,6 +534,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. * `deletion_protection` - (Optional) Whether Terraform will be prevented from destroying the job. Defaults to true. When a`terraform destroy` or `terraform apply` would delete the job, the command will fail if this field is not set to false in Terraform state. diff --git a/website/docs/r/cloud_run_v2_service.html.markdown b/website/docs/r/cloud_run_v2_service.html.markdown index 927a3558747..82b21caf573 100644 --- a/website/docs/r/cloud_run_v2_service.html.markdown +++ b/website/docs/r/cloud_run_v2_service.html.markdown @@ -847,6 +847,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. * `deletion_protection` - (Optional) Whether Terraform will be prevented from destroying the service. Defaults to true. When a`terraform destroy` or `terraform apply` would delete the service, the command will fail if this field is not set to false in Terraform state. diff --git a/website/docs/r/cloud_run_v2_worker_pool.html.markdown b/website/docs/r/cloud_run_v2_worker_pool.html.markdown index a342c6295d4..c3dcde55e3a 100644 --- a/website/docs/r/cloud_run_v2_worker_pool.html.markdown +++ b/website/docs/r/cloud_run_v2_worker_pool.html.markdown @@ -644,6 +644,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. * `deletion_protection` - (Optional) Whether Terraform will be prevented from destroying the service. Defaults to true. When a`terraform destroy` or `terraform apply` would delete the service, the command will fail if this field is not set to false in Terraform state. diff --git a/website/docs/r/cloud_scheduler_job.html.markdown b/website/docs/r/cloud_scheduler_job.html.markdown index 42870118621..9afc4e3d47d 100644 --- a/website/docs/r/cloud_scheduler_job.html.markdown +++ b/website/docs/r/cloud_scheduler_job.html.markdown @@ -282,6 +282,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `retry_config` block supports: diff --git a/website/docs/r/cloud_security_compliance_cloud_control.html.markdown b/website/docs/r/cloud_security_compliance_cloud_control.html.markdown index 0835486c829..a28a58e8305 100644 --- a/website/docs/r/cloud_security_compliance_cloud_control.html.markdown +++ b/website/docs/r/cloud_security_compliance_cloud_control.html.markdown @@ -249,6 +249,12 @@ The following arguments are supported: (Optional) cloud providers supported +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `parameter_spec` block supports: diff --git a/website/docs/r/cloud_security_compliance_framework.html.markdown b/website/docs/r/cloud_security_compliance_framework.html.markdown index 566bd1a6f0c..d69a69fc0df 100644 --- a/website/docs/r/cloud_security_compliance_framework.html.markdown +++ b/website/docs/r/cloud_security_compliance_framework.html.markdown @@ -128,6 +128,12 @@ The following arguments are supported: (Optional) Display name of the framework. The maximum length is 200 characters. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `cloud_control_details` block supports: diff --git a/website/docs/r/cloud_security_compliance_framework_deployment.html.markdown b/website/docs/r/cloud_security_compliance_framework_deployment.html.markdown index 16de07ee4ba..da7cc600cb3 100644 --- a/website/docs/r/cloud_security_compliance_framework_deployment.html.markdown +++ b/website/docs/r/cloud_security_compliance_framework_deployment.html.markdown @@ -362,6 +362,12 @@ The following arguments are supported: (Optional) User provided description of the Framework deployment +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `cloud_control_metadata` block supports: diff --git a/website/docs/r/cloud_tasks_queue.html.markdown b/website/docs/r/cloud_tasks_queue.html.markdown index 8fb4b290afa..4219ca989fa 100644 --- a/website/docs/r/cloud_tasks_queue.html.markdown +++ b/website/docs/r/cloud_tasks_queue.html.markdown @@ -228,6 +228,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. * `desired_state` - (Optional) The desired state of the queue. Use this to pause and resume the queue. * RUNNING: The queue is running. Tasks can be dispatched. diff --git a/website/docs/r/cloudbuild_bitbucket_server_config.html.markdown b/website/docs/r/cloudbuild_bitbucket_server_config.html.markdown index f660548b931..d27531cd0da 100644 --- a/website/docs/r/cloudbuild_bitbucket_server_config.html.markdown +++ b/website/docs/r/cloudbuild_bitbucket_server_config.html.markdown @@ -182,6 +182,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `secrets` block supports: diff --git a/website/docs/r/cloudbuild_trigger.html.markdown b/website/docs/r/cloudbuild_trigger.html.markdown index 4ead392aa67..f632b8c6b99 100644 --- a/website/docs/r/cloudbuild_trigger.html.markdown +++ b/website/docs/r/cloudbuild_trigger.html.markdown @@ -939,6 +939,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `git_file_source` block supports: diff --git a/website/docs/r/cloudbuild_worker_pool.html.markdown b/website/docs/r/cloudbuild_worker_pool.html.markdown index 8cb61a4c548..82d904e0202 100644 --- a/website/docs/r/cloudbuild_worker_pool.html.markdown +++ b/website/docs/r/cloudbuild_worker_pool.html.markdown @@ -106,7 +106,13 @@ The following arguments are supported: * `worker_config` - (Optional) Configuration to be used for a creating workers in the `WorkerPool`. Structure is [documented below](#nested_worker_config). - + +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `network_config` block supports: diff --git a/website/docs/r/cloudbuildv2_connection.html.markdown b/website/docs/r/cloudbuildv2_connection.html.markdown index 4fb56a9c9d2..a64abe0c6bf 100644 --- a/website/docs/r/cloudbuildv2_connection.html.markdown +++ b/website/docs/r/cloudbuildv2_connection.html.markdown @@ -214,6 +214,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `github_config` block supports: diff --git a/website/docs/r/cloudbuildv2_repository.html.markdown b/website/docs/r/cloudbuildv2_repository.html.markdown index 780566e7555..ce99e7f689f 100644 --- a/website/docs/r/cloudbuildv2_repository.html.markdown +++ b/website/docs/r/cloudbuildv2_repository.html.markdown @@ -185,6 +185,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/clouddeploy_automation.html.markdown b/website/docs/r/clouddeploy_automation.html.markdown index 2e88d95d022..e6ebc3e9e9b 100644 --- a/website/docs/r/clouddeploy_automation.html.markdown +++ b/website/docs/r/clouddeploy_automation.html.markdown @@ -228,6 +228,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `selector` block supports: diff --git a/website/docs/r/clouddeploy_custom_target_type.html.markdown b/website/docs/r/clouddeploy_custom_target_type.html.markdown index 9c0fd3e7227..977b80511e7 100644 --- a/website/docs/r/clouddeploy_custom_target_type.html.markdown +++ b/website/docs/r/clouddeploy_custom_target_type.html.markdown @@ -211,6 +211,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `custom_actions` block supports: diff --git a/website/docs/r/clouddeploy_delivery_pipeline.html.markdown b/website/docs/r/clouddeploy_delivery_pipeline.html.markdown index c80eaec6823..601370ba4ba 100644 --- a/website/docs/r/clouddeploy_delivery_pipeline.html.markdown +++ b/website/docs/r/clouddeploy_delivery_pipeline.html.markdown @@ -288,7 +288,13 @@ Please refer to the field `effective_labels` for all of the labels present on th * `suspended` - (Optional) When suspended, no new releases or rollouts can be created, but in-progress ones will complete. - + +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `serial_pipeline` block supports: diff --git a/website/docs/r/clouddeploy_deploy_policy.html.markdown b/website/docs/r/clouddeploy_deploy_policy.html.markdown index 44a76199dab..bda614a4194 100644 --- a/website/docs/r/clouddeploy_deploy_policy.html.markdown +++ b/website/docs/r/clouddeploy_deploy_policy.html.markdown @@ -217,6 +217,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `selectors` block supports: diff --git a/website/docs/r/clouddeploy_target.html.markdown b/website/docs/r/clouddeploy_target.html.markdown index 0798fd52614..7e4c2da2067 100644 --- a/website/docs/r/clouddeploy_target.html.markdown +++ b/website/docs/r/clouddeploy_target.html.markdown @@ -203,7 +203,13 @@ Please refer to the field `effective_labels` for all of the labels present on th * `run` - (Optional) Information specifying a Cloud Run deployment target. - + +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `anthos_cluster` block supports: diff --git a/website/docs/r/clouddomains_registration.html.markdown b/website/docs/r/clouddomains_registration.html.markdown index cc35f6cb52e..0f7df203e53 100644 --- a/website/docs/r/clouddomains_registration.html.markdown +++ b/website/docs/r/clouddomains_registration.html.markdown @@ -152,6 +152,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `yearly_price` block supports: diff --git a/website/docs/r/cloudfunctions2_function.html.markdown b/website/docs/r/cloudfunctions2_function.html.markdown index 05447db123f..babee0c0f47 100644 --- a/website/docs/r/cloudfunctions2_function.html.markdown +++ b/website/docs/r/cloudfunctions2_function.html.markdown @@ -1091,6 +1091,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `build_config` block supports: diff --git a/website/docs/r/cloudfunctions_function.html.markdown b/website/docs/r/cloudfunctions_function.html.markdown index cb26ea0e9f6..ed4898dd8fa 100644 --- a/website/docs/r/cloudfunctions_function.html.markdown +++ b/website/docs/r/cloudfunctions_function.html.markdown @@ -197,6 +197,13 @@ Please refer to the field 'effective_labels' for all of the labels present on th * `on_deploy_update_policy` - (Optional) Security patches are only applied when a function is redeployed. This should be specified as an empty block and cannot be set alongside `automatic_update_policy`. Structure is [documented below](#nested_on_deploy_update_policy). +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. + The `event_trigger` block supports: * `event_type` - (Required) The type of event to observe. For example: `"google.storage.object.finalize"`. diff --git a/website/docs/r/colab_notebook_execution.html.markdown b/website/docs/r/colab_notebook_execution.html.markdown index 5c85d90aa26..bae8c7475d5 100644 --- a/website/docs/r/colab_notebook_execution.html.markdown +++ b/website/docs/r/colab_notebook_execution.html.markdown @@ -458,6 +458,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `dataform_repository_source` block supports: diff --git a/website/docs/r/colab_runtime.html.markdown b/website/docs/r/colab_runtime.html.markdown index 3d877c78fe1..43cf4468ed9 100644 --- a/website/docs/r/colab_runtime.html.markdown +++ b/website/docs/r/colab_runtime.html.markdown @@ -218,6 +218,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. * `desired_state` - (Optional) Desired state of the Colab Runtime. Set this field to `RUNNING` to start the runtime, and `STOPPED` to stop it. * `auto_upgrade` - (Optional) Triggers an upgrade anytime the runtime is started if it is upgradable. diff --git a/website/docs/r/colab_runtime_template.html.markdown b/website/docs/r/colab_runtime_template.html.markdown index 7f25223354b..302a3ac0e31 100644 --- a/website/docs/r/colab_runtime_template.html.markdown +++ b/website/docs/r/colab_runtime_template.html.markdown @@ -240,6 +240,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `machine_spec` block supports: diff --git a/website/docs/r/colab_schedule.html.markdown b/website/docs/r/colab_schedule.html.markdown index 2583c44f466..042c3d7ef47 100644 --- a/website/docs/r/colab_schedule.html.markdown +++ b/website/docs/r/colab_schedule.html.markdown @@ -367,6 +367,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. * `desired_state` - (Optional) Desired state of the Colab Schedule. Set this field to `ACTIVE` to start/resume the schedule, and `PAUSED` to pause the schedule. diff --git a/website/docs/r/composer_environment.html.markdown b/website/docs/r/composer_environment.html.markdown index 4140bf296da..ded4daaba96 100644 --- a/website/docs/r/composer_environment.html.markdown +++ b/website/docs/r/composer_environment.html.markdown @@ -472,6 +472,14 @@ The following arguments are supported: (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - + (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. + * `storage_config` - (Optional) Configuration options for storage used by the environment. Structure is diff --git a/website/docs/r/composer_user_workloads_config_map.html.markdown b/website/docs/r/composer_user_workloads_config_map.html.markdown index cd405452925..66e6ef9fd78 100644 --- a/website/docs/r/composer_user_workloads_config_map.html.markdown +++ b/website/docs/r/composer_user_workloads_config_map.html.markdown @@ -101,6 +101,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/composer_user_workloads_secret.html.markdown b/website/docs/r/composer_user_workloads_secret.html.markdown index 0710fa534af..b957fac937d 100644 --- a/website/docs/r/composer_user_workloads_secret.html.markdown +++ b/website/docs/r/composer_user_workloads_secret.html.markdown @@ -80,6 +80,13 @@ The following arguments are supported: The values for all keys have to be base64-encoded strings. For details see: https://kubernetes.io/docs/concepts/configuration/secret/ +* `deletion_policy` - + (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/compute_address.html.markdown b/website/docs/r/compute_address.html.markdown index 7d4e8065ebb..ea578b4fe8c 100644 --- a/website/docs/r/compute_address.html.markdown +++ b/website/docs/r/compute_address.html.markdown @@ -292,6 +292,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/compute_attached_disk.html.markdown b/website/docs/r/compute_attached_disk.html.markdown index 47be7baa3be..a202d3fbf71 100644 --- a/website/docs/r/compute_attached_disk.html.markdown +++ b/website/docs/r/compute_attached_disk.html.markdown @@ -127,6 +127,13 @@ The following arguments are supported: "SCSI" "NVME" +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. + ## Attributes Reference In addition to the arguments listed above, the following computed attributes are exported: diff --git a/website/docs/r/compute_autoscaler.html.markdown b/website/docs/r/compute_autoscaler.html.markdown index 05495e5be06..79962c1f5cb 100644 --- a/website/docs/r/compute_autoscaler.html.markdown +++ b/website/docs/r/compute_autoscaler.html.markdown @@ -233,6 +233,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `autoscaling_policy` block supports: diff --git a/website/docs/r/compute_backend_bucket.html.markdown b/website/docs/r/compute_backend_bucket.html.markdown index 2aa14410095..1bd0a836477 100644 --- a/website/docs/r/compute_backend_bucket.html.markdown +++ b/website/docs/r/compute_backend_bucket.html.markdown @@ -202,6 +202,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `cdn_policy` block supports: diff --git a/website/docs/r/compute_backend_bucket_signed_url_key.html.markdown b/website/docs/r/compute_backend_bucket_signed_url_key.html.markdown index 66133674133..ac53db25873 100644 --- a/website/docs/r/compute_backend_bucket_signed_url_key.html.markdown +++ b/website/docs/r/compute_backend_bucket_signed_url_key.html.markdown @@ -84,6 +84,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/compute_backend_service.html.markdown b/website/docs/r/compute_backend_service.html.markdown index d8a82d464e9..10c96b581b2 100644 --- a/website/docs/r/compute_backend_service.html.markdown +++ b/website/docs/r/compute_backend_service.html.markdown @@ -1047,6 +1047,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `backend` block supports: diff --git a/website/docs/r/compute_backend_service_signed_url_key.html.markdown b/website/docs/r/compute_backend_service_signed_url_key.html.markdown index 5f936730157..eb7d8feb221 100644 --- a/website/docs/r/compute_backend_service_signed_url_key.html.markdown +++ b/website/docs/r/compute_backend_service_signed_url_key.html.markdown @@ -122,6 +122,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/compute_cross_site_network.html.markdown b/website/docs/r/compute_cross_site_network.html.markdown index 4235d02b546..8abd02d61bc 100644 --- a/website/docs/r/compute_cross_site_network.html.markdown +++ b/website/docs/r/compute_cross_site_network.html.markdown @@ -64,6 +64,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/compute_disk.html.markdown b/website/docs/r/compute_disk.html.markdown index 3d3c06e1c99..0a3f3e7bfaa 100644 --- a/website/docs/r/compute_disk.html.markdown +++ b/website/docs/r/compute_disk.html.markdown @@ -353,6 +353,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. * `create_snapshot_before_destroy` - (Optional) If set to true, a snapshot of the disk will be created before it is destroyed. If your disk is encrypted with customer managed encryption keys these will be reused for the snapshot creation. The name of the snapshot by default will be `{{disk-name}}-YYYYMMDD-HHmm` diff --git a/website/docs/r/compute_disk_async_replication.html.markdown b/website/docs/r/compute_disk_async_replication.html.markdown index 0224aa365f9..b0e16b2c966 100644 --- a/website/docs/r/compute_disk_async_replication.html.markdown +++ b/website/docs/r/compute_disk_async_replication.html.markdown @@ -63,6 +63,13 @@ The following arguments are supported: * `secondary_disk` - (Required) The secondary disk (target of replication). You can specify only one value. Structure is documented below. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. + The `secondary_disk` block includes: * `disk` - (Required) The secondary disk. diff --git a/website/docs/r/compute_disk_resource_policy_attachment.html.markdown b/website/docs/r/compute_disk_resource_policy_attachment.html.markdown index ce3ada00577..a2429f90668 100644 --- a/website/docs/r/compute_disk_resource_policy_attachment.html.markdown +++ b/website/docs/r/compute_disk_resource_policy_attachment.html.markdown @@ -92,6 +92,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/compute_external_vpn_gateway.html.markdown b/website/docs/r/compute_external_vpn_gateway.html.markdown index f9880e82d03..dfad0996a19 100644 --- a/website/docs/r/compute_external_vpn_gateway.html.markdown +++ b/website/docs/r/compute_external_vpn_gateway.html.markdown @@ -184,6 +184,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `interface` block supports: diff --git a/website/docs/r/compute_firewall.html.markdown b/website/docs/r/compute_firewall.html.markdown index 4ec42ada824..640e362d3ac 100644 --- a/website/docs/r/compute_firewall.html.markdown +++ b/website/docs/r/compute_firewall.html.markdown @@ -228,6 +228,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. * `enable_logging` - (Optional, Deprecated) This field denotes whether to enable logging for a particular firewall rule. If logging is enabled, logs will be exported to Stackdriver. Deprecated in favor of `log_config` diff --git a/website/docs/r/compute_firewall_policy.html.markdown b/website/docs/r/compute_firewall_policy.html.markdown index 3a2356a1132..4f47a3133fe 100644 --- a/website/docs/r/compute_firewall_policy.html.markdown +++ b/website/docs/r/compute_firewall_policy.html.markdown @@ -63,6 +63,12 @@ The following arguments are supported: (Optional) An optional description of this resource. Provide this property when you create the resource. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/compute_firewall_policy_association.html.markdown b/website/docs/r/compute_firewall_policy_association.html.markdown index 21bf85fe748..1f37646c80a 100644 --- a/website/docs/r/compute_firewall_policy_association.html.markdown +++ b/website/docs/r/compute_firewall_policy_association.html.markdown @@ -99,6 +99,12 @@ The following arguments are supported: on your exisiting firewall policy so as to prevent a situation where your attachment target has no associated policy. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/compute_firewall_policy_rule.html.markdown b/website/docs/r/compute_firewall_policy_rule.html.markdown index 51e1f13991b..abd5e96f46d 100644 --- a/website/docs/r/compute_firewall_policy_rule.html.markdown +++ b/website/docs/r/compute_firewall_policy_rule.html.markdown @@ -369,6 +369,12 @@ The following arguments are supported: When set to true, the firewall policy rule is not enforced and traffic behaves as if it did not exist. If this is unspecified, the firewall policy rule will be enabled. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `match` block supports: diff --git a/website/docs/r/compute_firewall_policy_with_rules.html.markdown b/website/docs/r/compute_firewall_policy_with_rules.html.markdown index 7c4d25b3648..8fef803ebd7 100644 --- a/website/docs/r/compute_firewall_policy_with_rules.html.markdown +++ b/website/docs/r/compute_firewall_policy_with_rules.html.markdown @@ -199,6 +199,12 @@ The following arguments are supported: (Optional) An optional description of this resource. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `rule` block supports: diff --git a/website/docs/r/compute_forwarding_rule.html.markdown b/website/docs/r/compute_forwarding_rule.html.markdown index 3f70c818d42..936eb9d406f 100644 --- a/website/docs/r/compute_forwarding_rule.html.markdown +++ b/website/docs/r/compute_forwarding_rule.html.markdown @@ -1626,6 +1626,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. * `recreate_closed_psc` - (Optional) This is used in PSC consumer ForwardingRule to make terraform recreate the ForwardingRule when the status is closed diff --git a/website/docs/r/compute_future_reservation.html.markdown b/website/docs/r/compute_future_reservation.html.markdown index e90e0fc9c86..5c3de29af6a 100644 --- a/website/docs/r/compute_future_reservation.html.markdown +++ b/website/docs/r/compute_future_reservation.html.markdown @@ -191,6 +191,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `time_window` block supports: diff --git a/website/docs/r/compute_global_address.html.markdown b/website/docs/r/compute_global_address.html.markdown index 5b3ac788a89..32fb44ce488 100644 --- a/website/docs/r/compute_global_address.html.markdown +++ b/website/docs/r/compute_global_address.html.markdown @@ -138,6 +138,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/compute_global_forwarding_rule.html.markdown b/website/docs/r/compute_global_forwarding_rule.html.markdown index 4c138f13da9..b7b6f650a7a 100644 --- a/website/docs/r/compute_global_forwarding_rule.html.markdown +++ b/website/docs/r/compute_global_forwarding_rule.html.markdown @@ -1405,6 +1405,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `metadata_filters` block supports: diff --git a/website/docs/r/compute_global_network_endpoint.html.markdown b/website/docs/r/compute_global_network_endpoint.html.markdown index a4ad040685d..ffb9991841a 100644 --- a/website/docs/r/compute_global_network_endpoint.html.markdown +++ b/website/docs/r/compute_global_network_endpoint.html.markdown @@ -75,6 +75,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/compute_global_network_endpoint_group.html.markdown b/website/docs/r/compute_global_network_endpoint_group.html.markdown index 859d0b55d77..35d8fecf916 100644 --- a/website/docs/r/compute_global_network_endpoint_group.html.markdown +++ b/website/docs/r/compute_global_network_endpoint_group.html.markdown @@ -100,6 +100,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/compute_ha_vpn_gateway.html.markdown b/website/docs/r/compute_ha_vpn_gateway.html.markdown index 52dfa74ff8b..1cc95d97f81 100644 --- a/website/docs/r/compute_ha_vpn_gateway.html.markdown +++ b/website/docs/r/compute_ha_vpn_gateway.html.markdown @@ -211,6 +211,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `vpn_interfaces` block supports: diff --git a/website/docs/r/compute_health_check.html.markdown b/website/docs/r/compute_health_check.html.markdown index 2a930d81190..6a576e193e6 100644 --- a/website/docs/r/compute_health_check.html.markdown +++ b/website/docs/r/compute_health_check.html.markdown @@ -559,6 +559,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `http_health_check` block supports: diff --git a/website/docs/r/compute_http_health_check.html.markdown b/website/docs/r/compute_http_health_check.html.markdown index 62919859bd9..b314708ec4b 100644 --- a/website/docs/r/compute_http_health_check.html.markdown +++ b/website/docs/r/compute_http_health_check.html.markdown @@ -116,6 +116,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/compute_https_health_check.html.markdown b/website/docs/r/compute_https_health_check.html.markdown index 34f015597c6..8508e982189 100644 --- a/website/docs/r/compute_https_health_check.html.markdown +++ b/website/docs/r/compute_https_health_check.html.markdown @@ -116,6 +116,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/compute_image.html.markdown b/website/docs/r/compute_image.html.markdown index f9485a59e92..21970a8feac 100644 --- a/website/docs/r/compute_image.html.markdown +++ b/website/docs/r/compute_image.html.markdown @@ -279,6 +279,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `guest_os_features` block supports: diff --git a/website/docs/r/compute_instance.html.markdown b/website/docs/r/compute_instance.html.markdown index 4914384e8e3..11ab51f9e0a 100644 --- a/website/docs/r/compute_instance.html.markdown +++ b/website/docs/r/compute_instance.html.markdown @@ -270,6 +270,13 @@ is desired, you will need to modify your state file manually using * `erase_windows_vss_signature` - (optional) [Beta](../guides/provider_versions.html.markdown) Specifies whether the disks restored from source snapshots or source machine image should erase Windows specific VSS signature. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. + --- The `boot_disk` block supports: diff --git a/website/docs/r/compute_instance_group.html.markdown b/website/docs/r/compute_instance_group.html.markdown index d331034d387..4206f6af025 100644 --- a/website/docs/r/compute_instance_group.html.markdown +++ b/website/docs/r/compute_instance_group.html.markdown @@ -160,6 +160,13 @@ The following arguments are supported: fails. Defaults to the network where the instances are in (if neither `network` nor `instances` is specified, this field will be blank). +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. + The `named_port` block supports: * `name` - (Required) The name which the port will be mapped to. diff --git a/website/docs/r/compute_instance_group_manager.html.markdown b/website/docs/r/compute_instance_group_manager.html.markdown index 493b3e47faf..55b3353a25b 100644 --- a/website/docs/r/compute_instance_group_manager.html.markdown +++ b/website/docs/r/compute_instance_group_manager.html.markdown @@ -272,6 +272,13 @@ group. You can specify only one value. Structure is [documented below](#nested_a * `target_size_policy` - (Optional) The policy that specifies how the MIG creates its VMs to achieve the target size. Structure is [documented below](#nested_target_size_policy). +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. + - - - The `standby_policy` block supports: diff --git a/website/docs/r/compute_instance_group_membership.html.markdown b/website/docs/r/compute_instance_group_membership.html.markdown index d9ae2504a1b..59c433b173c 100644 --- a/website/docs/r/compute_instance_group_membership.html.markdown +++ b/website/docs/r/compute_instance_group_membership.html.markdown @@ -95,6 +95,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/compute_instance_group_named_port.html.markdown b/website/docs/r/compute_instance_group_named_port.html.markdown index 66373c34b71..3afcae4de55 100644 --- a/website/docs/r/compute_instance_group_named_port.html.markdown +++ b/website/docs/r/compute_instance_group_named_port.html.markdown @@ -113,6 +113,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/compute_instance_settings.html.markdown b/website/docs/r/compute_instance_settings.html.markdown index ebe7764e370..508bc97d246 100644 --- a/website/docs/r/compute_instance_settings.html.markdown +++ b/website/docs/r/compute_instance_settings.html.markdown @@ -68,6 +68,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `metadata` block supports: diff --git a/website/docs/r/compute_instant_snapshot.html.markdown b/website/docs/r/compute_instant_snapshot.html.markdown index 9b72e5ea032..5b9b859ff2d 100644 --- a/website/docs/r/compute_instant_snapshot.html.markdown +++ b/website/docs/r/compute_instant_snapshot.html.markdown @@ -100,6 +100,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `params` block supports: diff --git a/website/docs/r/compute_interconnect.html.markdown b/website/docs/r/compute_interconnect.html.markdown index bda62c1e6af..6b5b1b7b078 100644 --- a/website/docs/r/compute_interconnect.html.markdown +++ b/website/docs/r/compute_interconnect.html.markdown @@ -163,6 +163,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `params` block supports: diff --git a/website/docs/r/compute_interconnect_attachment.html.markdown b/website/docs/r/compute_interconnect_attachment.html.markdown index 4e1ff853439..61cc572ce35 100644 --- a/website/docs/r/compute_interconnect_attachment.html.markdown +++ b/website/docs/r/compute_interconnect_attachment.html.markdown @@ -319,6 +319,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `params` block supports: diff --git a/website/docs/r/compute_interconnect_attachment_group.html.markdown b/website/docs/r/compute_interconnect_attachment_group.html.markdown index ba541a2438d..7c5afeea38e 100644 --- a/website/docs/r/compute_interconnect_attachment_group.html.markdown +++ b/website/docs/r/compute_interconnect_attachment_group.html.markdown @@ -91,6 +91,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `intent` block supports: diff --git a/website/docs/r/compute_interconnect_group.html.markdown b/website/docs/r/compute_interconnect_group.html.markdown index c0726b7b36b..06df384fc3f 100644 --- a/website/docs/r/compute_interconnect_group.html.markdown +++ b/website/docs/r/compute_interconnect_group.html.markdown @@ -85,6 +85,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `intent` block supports: diff --git a/website/docs/r/compute_machine_image.html.markdown b/website/docs/r/compute_machine_image.html.markdown index c59118fd816..d2f45d5b59c 100644 --- a/website/docs/r/compute_machine_image.html.markdown +++ b/website/docs/r/compute_machine_image.html.markdown @@ -203,6 +203,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `machine_image_encryption_key` block supports: diff --git a/website/docs/r/compute_managed_ssl_certificate.html.markdown b/website/docs/r/compute_managed_ssl_certificate.html.markdown index 531543d39f6..4c829b24a6f 100644 --- a/website/docs/r/compute_managed_ssl_certificate.html.markdown +++ b/website/docs/r/compute_managed_ssl_certificate.html.markdown @@ -229,6 +229,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `managed` block supports: diff --git a/website/docs/r/compute_network.html.markdown b/website/docs/r/compute_network.html.markdown index 58051482e0e..7caa661832c 100644 --- a/website/docs/r/compute_network.html.markdown +++ b/website/docs/r/compute_network.html.markdown @@ -217,6 +217,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. * `delete_default_routes_on_create` - (Optional) If set to `true`, default routes (`0.0.0.0/0`) will be deleted immediately after network creation. Defaults to `false`. diff --git a/website/docs/r/compute_network_attachment.html.markdown b/website/docs/r/compute_network_attachment.html.markdown index 3d40bfb2f18..6bbbffd4b84 100644 --- a/website/docs/r/compute_network_attachment.html.markdown +++ b/website/docs/r/compute_network_attachment.html.markdown @@ -176,6 +176,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/compute_network_edge_security_service.html.markdown b/website/docs/r/compute_network_edge_security_service.html.markdown index 208b3192ca4..bf932dba1a0 100644 --- a/website/docs/r/compute_network_edge_security_service.html.markdown +++ b/website/docs/r/compute_network_edge_security_service.html.markdown @@ -70,6 +70,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/compute_network_endpoint.html.markdown b/website/docs/r/compute_network_endpoint.html.markdown index 564abda67e9..0e14e213198 100644 --- a/website/docs/r/compute_network_endpoint.html.markdown +++ b/website/docs/r/compute_network_endpoint.html.markdown @@ -129,6 +129,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/compute_network_endpoint_group.html.markdown b/website/docs/r/compute_network_endpoint_group.html.markdown index a9d9192d8d3..9ae94a7ae4a 100644 --- a/website/docs/r/compute_network_endpoint_group.html.markdown +++ b/website/docs/r/compute_network_endpoint_group.html.markdown @@ -157,6 +157,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/compute_network_endpoints.html.markdown b/website/docs/r/compute_network_endpoints.html.markdown index fad79df4394..668ff430193 100644 --- a/website/docs/r/compute_network_endpoints.html.markdown +++ b/website/docs/r/compute_network_endpoints.html.markdown @@ -144,6 +144,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `network_endpoints` block supports: diff --git a/website/docs/r/compute_network_firewall_policy.html.markdown b/website/docs/r/compute_network_firewall_policy.html.markdown index d5239fb7c2a..710fd32ffe7 100644 --- a/website/docs/r/compute_network_firewall_policy.html.markdown +++ b/website/docs/r/compute_network_firewall_policy.html.markdown @@ -64,6 +64,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/compute_network_firewall_policy_association.html.markdown b/website/docs/r/compute_network_firewall_policy_association.html.markdown index fba1a0c2369..d2fc18ca403 100644 --- a/website/docs/r/compute_network_firewall_policy_association.html.markdown +++ b/website/docs/r/compute_network_firewall_policy_association.html.markdown @@ -72,6 +72,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/compute_network_firewall_policy_packet_mirroring_rule.html.markdown b/website/docs/r/compute_network_firewall_policy_packet_mirroring_rule.html.markdown index 788f0a754de..450b0704d55 100644 --- a/website/docs/r/compute_network_firewall_policy_packet_mirroring_rule.html.markdown +++ b/website/docs/r/compute_network_firewall_policy_packet_mirroring_rule.html.markdown @@ -192,6 +192,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `match` block supports: diff --git a/website/docs/r/compute_network_firewall_policy_rule.html.markdown b/website/docs/r/compute_network_firewall_policy_rule.html.markdown index 0ec2b0c9f89..30d28470d09 100644 --- a/website/docs/r/compute_network_firewall_policy_rule.html.markdown +++ b/website/docs/r/compute_network_firewall_policy_rule.html.markdown @@ -309,6 +309,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `match` block supports: diff --git a/website/docs/r/compute_network_firewall_policy_with_rules.html.markdown b/website/docs/r/compute_network_firewall_policy_with_rules.html.markdown index d91ebe40c47..710863a4eae 100644 --- a/website/docs/r/compute_network_firewall_policy_with_rules.html.markdown +++ b/website/docs/r/compute_network_firewall_policy_with_rules.html.markdown @@ -183,6 +183,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `rule` block supports: diff --git a/website/docs/r/compute_network_peering.html.markdown b/website/docs/r/compute_network_peering.html.markdown index 176cd839d51..504e037c609 100644 --- a/website/docs/r/compute_network_peering.html.markdown +++ b/website/docs/r/compute_network_peering.html.markdown @@ -85,6 +85,14 @@ Which IP version(s) of traffic and routes are allowed to be imported or exported * `update_strategy` - (Optional) The update strategy determines the semantics for updates and deletes to the peering connection configuration. The default value is INDEPENDENT. Possible values: ["INDEPENDENT", "CONSENSUS"] +* `deletion_policy` - + (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. + ## Attributes Reference In addition to the arguments listed above, the following computed attributes are diff --git a/website/docs/r/compute_network_peering_routes_config.html.markdown b/website/docs/r/compute_network_peering_routes_config.html.markdown index c44b9428735..9c0fcea92d2 100644 --- a/website/docs/r/compute_network_peering_routes_config.html.markdown +++ b/website/docs/r/compute_network_peering_routes_config.html.markdown @@ -118,6 +118,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/compute_node_group.html.markdown b/website/docs/r/compute_node_group.html.markdown index 93b7a0a80be..65a9a30a9c9 100644 --- a/website/docs/r/compute_node_group.html.markdown +++ b/website/docs/r/compute_node_group.html.markdown @@ -206,6 +206,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `maintenance_window` block supports: diff --git a/website/docs/r/compute_node_template.html.markdown b/website/docs/r/compute_node_template.html.markdown index fdd568e5331..41b66f26173 100644 --- a/website/docs/r/compute_node_template.html.markdown +++ b/website/docs/r/compute_node_template.html.markdown @@ -188,6 +188,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `node_type_flexibility` block supports: diff --git a/website/docs/r/compute_organization_security_policy.html.markdown b/website/docs/r/compute_organization_security_policy.html.markdown index 3a642625559..cc84634c86b 100644 --- a/website/docs/r/compute_organization_security_policy.html.markdown +++ b/website/docs/r/compute_organization_security_policy.html.markdown @@ -97,6 +97,12 @@ The following arguments are supported: Additional options for this security policy. Structure is [documented below](#nested_advanced_options_config). +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `advanced_options_config` block supports: diff --git a/website/docs/r/compute_organization_security_policy_association.html.markdown b/website/docs/r/compute_organization_security_policy_association.html.markdown index c0677f54f91..7576643dd64 100644 --- a/website/docs/r/compute_organization_security_policy_association.html.markdown +++ b/website/docs/r/compute_organization_security_policy_association.html.markdown @@ -79,6 +79,12 @@ The following arguments are supported: (Optional) A list of folders to exclude from the security policy. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/compute_organization_security_policy_rule.html.markdown b/website/docs/r/compute_organization_security_policy_rule.html.markdown index 664e855c867..9b185631a3a 100644 --- a/website/docs/r/compute_organization_security_policy_rule.html.markdown +++ b/website/docs/r/compute_organization_security_policy_rule.html.markdown @@ -299,6 +299,12 @@ The following arguments are supported: A list of service accounts indicating the sets of instances that are applied with this rule. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `match` block supports: diff --git a/website/docs/r/compute_packet_mirroring.html.markdown b/website/docs/r/compute_packet_mirroring.html.markdown index 013cd0bb4ba..c943fe24122 100644 --- a/website/docs/r/compute_packet_mirroring.html.markdown +++ b/website/docs/r/compute_packet_mirroring.html.markdown @@ -183,6 +183,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `network` block supports: diff --git a/website/docs/r/compute_per_instance_config.html.markdown b/website/docs/r/compute_per_instance_config.html.markdown index b5acf44062b..4128bf3dc14 100644 --- a/website/docs/r/compute_per_instance_config.html.markdown +++ b/website/docs/r/compute_per_instance_config.html.markdown @@ -131,6 +131,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. * `minimal_action` - (Optional) The minimal action to perform on the instance during an update. Default is `NONE`. Possible values are: * REPLACE diff --git a/website/docs/r/compute_preview_feature.html.markdown b/website/docs/r/compute_preview_feature.html.markdown index 2bd577d2146..26c0a1f5b76 100644 --- a/website/docs/r/compute_preview_feature.html.markdown +++ b/website/docs/r/compute_preview_feature.html.markdown @@ -73,6 +73,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `rollout_operation` block supports: diff --git a/website/docs/r/compute_project_cloud_armor_tier.html.markdown b/website/docs/r/compute_project_cloud_armor_tier.html.markdown index 15653dc1f3d..fa1c9239642 100644 --- a/website/docs/r/compute_project_cloud_armor_tier.html.markdown +++ b/website/docs/r/compute_project_cloud_armor_tier.html.markdown @@ -76,6 +76,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/compute_project_metadata.html.markdown b/website/docs/r/compute_project_metadata.html.markdown index 03f62a60657..2c8451ea304 100644 --- a/website/docs/r/compute_project_metadata.html.markdown +++ b/website/docs/r/compute_project_metadata.html.markdown @@ -71,6 +71,13 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. + ## Attributes Reference In addition to the arguments listed above, the following computed attributes are exported: diff --git a/website/docs/r/compute_project_metadata_item.html.markdown b/website/docs/r/compute_project_metadata_item.html.markdown index fd50d7adacf..666e7392bbc 100644 --- a/website/docs/r/compute_project_metadata_item.html.markdown +++ b/website/docs/r/compute_project_metadata_item.html.markdown @@ -47,6 +47,13 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. + ## Attributes Reference In addition to the arguments listed above, the following computed attributes are exported: diff --git a/website/docs/r/compute_public_advertised_prefix.html.markdown b/website/docs/r/compute_public_advertised_prefix.html.markdown index 3c7225e4826..7e613e65eb1 100644 --- a/website/docs/r/compute_public_advertised_prefix.html.markdown +++ b/website/docs/r/compute_public_advertised_prefix.html.markdown @@ -117,6 +117,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/compute_public_delegated_prefix.html.markdown b/website/docs/r/compute_public_delegated_prefix.html.markdown index daec54c88f4..9e6a48e386b 100644 --- a/website/docs/r/compute_public_delegated_prefix.html.markdown +++ b/website/docs/r/compute_public_delegated_prefix.html.markdown @@ -192,6 +192,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/compute_region_autoscaler.html.markdown b/website/docs/r/compute_region_autoscaler.html.markdown index 022215cdb15..d50df2a047f 100644 --- a/website/docs/r/compute_region_autoscaler.html.markdown +++ b/website/docs/r/compute_region_autoscaler.html.markdown @@ -152,6 +152,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `autoscaling_policy` block supports: diff --git a/website/docs/r/compute_region_backend_bucket.html.markdown b/website/docs/r/compute_region_backend_bucket.html.markdown index bc7dca2d377..937e5892e41 100644 --- a/website/docs/r/compute_region_backend_bucket.html.markdown +++ b/website/docs/r/compute_region_backend_bucket.html.markdown @@ -211,6 +211,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/compute_region_backend_service.html.markdown b/website/docs/r/compute_region_backend_service.html.markdown index 7486f632fc9..4fc3085f481 100644 --- a/website/docs/r/compute_region_backend_service.html.markdown +++ b/website/docs/r/compute_region_backend_service.html.markdown @@ -1023,6 +1023,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `backend` block supports: diff --git a/website/docs/r/compute_region_commitment.html.markdown b/website/docs/r/compute_region_commitment.html.markdown index ae3db3c4ac0..28f01c9cd1a 100644 --- a/website/docs/r/compute_region_commitment.html.markdown +++ b/website/docs/r/compute_region_commitment.html.markdown @@ -162,6 +162,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `resources` block supports: diff --git a/website/docs/r/compute_region_composite_health_check.html.markdown b/website/docs/r/compute_region_composite_health_check.html.markdown index 4fbd69f5d02..480f83e901a 100644 --- a/website/docs/r/compute_region_composite_health_check.html.markdown +++ b/website/docs/r/compute_region_composite_health_check.html.markdown @@ -143,6 +143,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/compute_region_disk.html.markdown b/website/docs/r/compute_region_disk.html.markdown index b901bba27c9..917d057ce6e 100644 --- a/website/docs/r/compute_region_disk.html.markdown +++ b/website/docs/r/compute_region_disk.html.markdown @@ -329,6 +329,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. * `create_snapshot_before_destroy` - (Optional) If set to true, a snapshot of the disk will be created before it is destroyed. If your disk is encrypted with customer managed encryption keys these will be reused for the snapshot creation. The name of the snapshot by default will be `{{disk-name}}-YYYYMMDD-HHmm` diff --git a/website/docs/r/compute_region_disk_resource_policy_attachment.html.markdown b/website/docs/r/compute_region_disk_resource_policy_attachment.html.markdown index 355532d3cff..b7d59961316 100644 --- a/website/docs/r/compute_region_disk_resource_policy_attachment.html.markdown +++ b/website/docs/r/compute_region_disk_resource_policy_attachment.html.markdown @@ -107,6 +107,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/compute_region_health_aggregation_policy.html.markdown b/website/docs/r/compute_region_health_aggregation_policy.html.markdown index 000e59b4e8b..8cca97f6f11 100644 --- a/website/docs/r/compute_region_health_aggregation_policy.html.markdown +++ b/website/docs/r/compute_region_health_aggregation_policy.html.markdown @@ -110,6 +110,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/compute_region_health_check.html.markdown b/website/docs/r/compute_region_health_check.html.markdown index c7dfacf172f..fdc1c816dcb 100644 --- a/website/docs/r/compute_region_health_check.html.markdown +++ b/website/docs/r/compute_region_health_check.html.markdown @@ -482,6 +482,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `http_health_check` block supports: diff --git a/website/docs/r/compute_region_health_source.html.markdown b/website/docs/r/compute_region_health_source.html.markdown index 9cc13cb7137..4ff63f3bde0 100644 --- a/website/docs/r/compute_region_health_source.html.markdown +++ b/website/docs/r/compute_region_health_source.html.markdown @@ -122,6 +122,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/compute_region_instance_group_manager.html.markdown b/website/docs/r/compute_region_instance_group_manager.html.markdown index e7fa5014131..4785bb0c205 100644 --- a/website/docs/r/compute_region_instance_group_manager.html.markdown +++ b/website/docs/r/compute_region_instance_group_manager.html.markdown @@ -151,6 +151,13 @@ The following arguments are supported: * `region` - (Optional) The region where the managed instance group resides. If not provided, the provider region is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. + - - - * `description` - (Optional) An optional textual description of the instance diff --git a/website/docs/r/compute_region_instance_template.html.markdown b/website/docs/r/compute_region_instance_template.html.markdown index f966c78b20a..6887b690394 100644 --- a/website/docs/r/compute_region_instance_template.html.markdown +++ b/website/docs/r/compute_region_instance_template.html.markdown @@ -409,6 +409,13 @@ The following arguments are supported: * `key_revocation_action_type` - (optional) Action to be taken when a customer's encryption key is revoked. Supports `STOP` and `NONE`, with `NONE` being the default. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. + The `disk` block supports: * `auto_delete` - (Optional) Whether or not the disk should be auto-deleted. diff --git a/website/docs/r/compute_region_instant_snapshot.html.markdown b/website/docs/r/compute_region_instant_snapshot.html.markdown index 37423e5d702..dd9e48ad98b 100644 --- a/website/docs/r/compute_region_instant_snapshot.html.markdown +++ b/website/docs/r/compute_region_instant_snapshot.html.markdown @@ -102,6 +102,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `params` block supports: diff --git a/website/docs/r/compute_region_network_endpoint.html.markdown b/website/docs/r/compute_region_network_endpoint.html.markdown index 12c8514df7f..9819a4a17c4 100644 --- a/website/docs/r/compute_region_network_endpoint.html.markdown +++ b/website/docs/r/compute_region_network_endpoint.html.markdown @@ -201,6 +201,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/compute_region_network_endpoint_group.html.markdown b/website/docs/r/compute_region_network_endpoint_group.html.markdown index 6578b851a1a..68d579d93ed 100644 --- a/website/docs/r/compute_region_network_endpoint_group.html.markdown +++ b/website/docs/r/compute_region_network_endpoint_group.html.markdown @@ -474,6 +474,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `psc_data` block supports: diff --git a/website/docs/r/compute_region_network_firewall_policy.html.markdown b/website/docs/r/compute_region_network_firewall_policy.html.markdown index 171be6d6363..968e28122c6 100644 --- a/website/docs/r/compute_region_network_firewall_policy.html.markdown +++ b/website/docs/r/compute_region_network_firewall_policy.html.markdown @@ -83,6 +83,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/compute_region_network_firewall_policy_association.html.markdown b/website/docs/r/compute_region_network_firewall_policy_association.html.markdown index cf2c6cccb05..ba59e6009a4 100644 --- a/website/docs/r/compute_region_network_firewall_policy_association.html.markdown +++ b/website/docs/r/compute_region_network_firewall_policy_association.html.markdown @@ -110,6 +110,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/compute_region_network_firewall_policy_rule.html.markdown b/website/docs/r/compute_region_network_firewall_policy_rule.html.markdown index 158261c1a35..4e9065e4c2a 100644 --- a/website/docs/r/compute_region_network_firewall_policy_rule.html.markdown +++ b/website/docs/r/compute_region_network_firewall_policy_rule.html.markdown @@ -379,6 +379,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `match` block supports: diff --git a/website/docs/r/compute_region_network_firewall_policy_with_rules.html.markdown b/website/docs/r/compute_region_network_firewall_policy_with_rules.html.markdown index d17a1fde19e..0c5e9e1c753 100644 --- a/website/docs/r/compute_region_network_firewall_policy_with_rules.html.markdown +++ b/website/docs/r/compute_region_network_firewall_policy_with_rules.html.markdown @@ -185,6 +185,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `rule` block supports: diff --git a/website/docs/r/compute_region_per_instance_config.html.markdown b/website/docs/r/compute_region_per_instance_config.html.markdown index b5988a79300..9688b5d0403 100644 --- a/website/docs/r/compute_region_per_instance_config.html.markdown +++ b/website/docs/r/compute_region_per_instance_config.html.markdown @@ -138,6 +138,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. * `minimal_action` - (Optional) The minimal action to perform on the instance during an update. Default is `NONE`. Possible values are: * REPLACE diff --git a/website/docs/r/compute_region_resize_request.html.markdown b/website/docs/r/compute_region_resize_request.html.markdown index 5beb32f95a1..6f078b1985b 100644 --- a/website/docs/r/compute_region_resize_request.html.markdown +++ b/website/docs/r/compute_region_resize_request.html.markdown @@ -159,6 +159,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `requested_run_duration` block supports: diff --git a/website/docs/r/compute_region_security_policy.html.markdown b/website/docs/r/compute_region_security_policy.html.markdown index cf1f27a8240..e644d31aa35 100644 --- a/website/docs/r/compute_region_security_policy.html.markdown +++ b/website/docs/r/compute_region_security_policy.html.markdown @@ -185,6 +185,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `ddos_protection_config` block supports: diff --git a/website/docs/r/compute_region_security_policy_rule.html.markdown b/website/docs/r/compute_region_security_policy_rule.html.markdown index 318482f2b56..e788fa0d86c 100644 --- a/website/docs/r/compute_region_security_policy_rule.html.markdown +++ b/website/docs/r/compute_region_security_policy_rule.html.markdown @@ -335,6 +335,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `match` block supports: diff --git a/website/docs/r/compute_region_ssl_certificate.html.markdown b/website/docs/r/compute_region_ssl_certificate.html.markdown index 5e9be8f108a..1275d70725e 100644 --- a/website/docs/r/compute_region_ssl_certificate.html.markdown +++ b/website/docs/r/compute_region_ssl_certificate.html.markdown @@ -248,6 +248,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. * `name_prefix` - (Optional) Creates a unique name beginning with the specified prefix. Conflicts with `name`. Max length is 54 characters. Prefixes with lengths longer than 37 characters will use a shortened diff --git a/website/docs/r/compute_region_ssl_policy.html.markdown b/website/docs/r/compute_region_ssl_policy.html.markdown index a28d5564ce1..04ec6d792f0 100644 --- a/website/docs/r/compute_region_ssl_policy.html.markdown +++ b/website/docs/r/compute_region_ssl_policy.html.markdown @@ -90,6 +90,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/compute_region_target_http_proxy.html.markdown b/website/docs/r/compute_region_target_http_proxy.html.markdown index 0825e8c834f..8ca2fc56390 100644 --- a/website/docs/r/compute_region_target_http_proxy.html.markdown +++ b/website/docs/r/compute_region_target_http_proxy.html.markdown @@ -209,6 +209,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/compute_region_target_https_proxy.html.markdown b/website/docs/r/compute_region_target_https_proxy.html.markdown index 5bbfce5b19e..ad722e0136f 100644 --- a/website/docs/r/compute_region_target_https_proxy.html.markdown +++ b/website/docs/r/compute_region_target_https_proxy.html.markdown @@ -388,6 +388,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/compute_region_target_tcp_proxy.html.markdown b/website/docs/r/compute_region_target_tcp_proxy.html.markdown index 74203a629ab..c0bc4e62d05 100644 --- a/website/docs/r/compute_region_target_tcp_proxy.html.markdown +++ b/website/docs/r/compute_region_target_tcp_proxy.html.markdown @@ -236,6 +236,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/compute_region_url_map.html.markdown b/website/docs/r/compute_region_url_map.html.markdown index 4b75933c64a..308491c19f4 100644 --- a/website/docs/r/compute_region_url_map.html.markdown +++ b/website/docs/r/compute_region_url_map.html.markdown @@ -1562,6 +1562,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `host_rule` block supports: diff --git a/website/docs/r/compute_reservation.html.markdown b/website/docs/r/compute_reservation.html.markdown index 1214bc56d40..e961ae6bb5d 100644 --- a/website/docs/r/compute_reservation.html.markdown +++ b/website/docs/r/compute_reservation.html.markdown @@ -266,6 +266,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. * `block_names` - (Optional) List of all reservation block names in the parent reservation. diff --git a/website/docs/r/compute_resize_request.html.markdown b/website/docs/r/compute_resize_request.html.markdown index f025c71fd5c..d16611bbd0b 100644 --- a/website/docs/r/compute_resize_request.html.markdown +++ b/website/docs/r/compute_resize_request.html.markdown @@ -149,6 +149,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `requested_run_duration` block supports: diff --git a/website/docs/r/compute_resource_policy.html.markdown b/website/docs/r/compute_resource_policy.html.markdown index bf2c70ebd71..2f2ac73f868 100644 --- a/website/docs/r/compute_resource_policy.html.markdown +++ b/website/docs/r/compute_resource_policy.html.markdown @@ -361,6 +361,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `snapshot_schedule_policy` block supports: diff --git a/website/docs/r/compute_resource_policy_attachment.html.markdown b/website/docs/r/compute_resource_policy_attachment.html.markdown index 895dde2a75d..baa3e26a2f8 100644 --- a/website/docs/r/compute_resource_policy_attachment.html.markdown +++ b/website/docs/r/compute_resource_policy_attachment.html.markdown @@ -106,6 +106,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/compute_rollout_plan.html.markdown b/website/docs/r/compute_rollout_plan.html.markdown index 4d927a2c673..574d843dbdf 100644 --- a/website/docs/r/compute_rollout_plan.html.markdown +++ b/website/docs/r/compute_rollout_plan.html.markdown @@ -91,6 +91,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `waves` block supports: diff --git a/website/docs/r/compute_route.html.markdown b/website/docs/r/compute_route.html.markdown index d4863f92fe2..1e3feb7217a 100644 --- a/website/docs/r/compute_route.html.markdown +++ b/website/docs/r/compute_route.html.markdown @@ -318,6 +318,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. * `next_hop_instance_zone` - (Optional when `next_hop_instance` is specified) The zone of the instance specified in `next_hop_instance`. Omit if `next_hop_instance` is specified as diff --git a/website/docs/r/compute_router.html.markdown b/website/docs/r/compute_router.html.markdown index 9744c54ef13..1afc971087c 100644 --- a/website/docs/r/compute_router.html.markdown +++ b/website/docs/r/compute_router.html.markdown @@ -207,6 +207,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `bgp` block supports: diff --git a/website/docs/r/compute_router_interface.html.markdown b/website/docs/r/compute_router_interface.html.markdown index d3b5aec7db4..3266831d2ee 100644 --- a/website/docs/r/compute_router_interface.html.markdown +++ b/website/docs/r/compute_router_interface.html.markdown @@ -83,6 +83,13 @@ In addition to the above required fields, a router interface must have specified * `region` - (Optional) The region this interface's router sits in. If not specified, the project region will be used. Changing this forces a new interface to be created. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. + ## Attributes Reference In addition to the arguments listed above, the following computed attributes are exported: diff --git a/website/docs/r/compute_router_named_set.html.markdown b/website/docs/r/compute_router_named_set.html.markdown index 706cf685a55..b6359c09de2 100644 --- a/website/docs/r/compute_router_named_set.html.markdown +++ b/website/docs/r/compute_router_named_set.html.markdown @@ -218,6 +218,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `elements` block supports: diff --git a/website/docs/r/compute_router_nat.html.markdown b/website/docs/r/compute_router_nat.html.markdown index d9a99693e08..16cadfa490b 100644 --- a/website/docs/r/compute_router_nat.html.markdown +++ b/website/docs/r/compute_router_nat.html.markdown @@ -408,6 +408,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `subnetwork` block supports: diff --git a/website/docs/r/compute_router_nat_address.html.markdown b/website/docs/r/compute_router_nat_address.html.markdown index 91740bcede3..8127b204a5e 100644 --- a/website/docs/r/compute_router_nat_address.html.markdown +++ b/website/docs/r/compute_router_nat_address.html.markdown @@ -119,6 +119,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/compute_router_peer.html.markdown b/website/docs/r/compute_router_peer.html.markdown index cdd818f80b1..c607b5744f9 100644 --- a/website/docs/r/compute_router_peer.html.markdown +++ b/website/docs/r/compute_router_peer.html.markdown @@ -549,6 +549,13 @@ The following arguments are supported: * `md5_authentication_key` - (Optional) Configuration for MD5 authentication on the BGP session. Structure is [documented below](#nested_md5_authentication_key). +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. + The `advertised_ip_ranges` block supports: * `range` - diff --git a/website/docs/r/compute_router_route_policy.html.markdown b/website/docs/r/compute_router_route_policy.html.markdown index 33b251ad541..d42d82b2b11 100644 --- a/website/docs/r/compute_router_route_policy.html.markdown +++ b/website/docs/r/compute_router_route_policy.html.markdown @@ -148,6 +148,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `terms` block supports: diff --git a/website/docs/r/compute_security_policy.html.markdown b/website/docs/r/compute_security_policy.html.markdown index fa827ec904b..36f81aeaf24 100644 --- a/website/docs/r/compute_security_policy.html.markdown +++ b/website/docs/r/compute_security_policy.html.markdown @@ -240,6 +240,13 @@ The following arguments are supported: * `label_fingerprint` - The unique fingerprint of the labels. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. + The `advanced_options_config` block supports: * `json_parsing` - Whether or not to JSON parse the payload body. Defaults to `DISABLED`. diff --git a/website/docs/r/compute_security_policy_rule.html.markdown b/website/docs/r/compute_security_policy_rule.html.markdown index d96bed54bb8..b9396467a78 100644 --- a/website/docs/r/compute_security_policy_rule.html.markdown +++ b/website/docs/r/compute_security_policy_rule.html.markdown @@ -375,6 +375,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `match` block supports: diff --git a/website/docs/r/compute_service_attachment.html.markdown b/website/docs/r/compute_service_attachment.html.markdown index d0ff1de6c1e..4c00ae20ea4 100644 --- a/website/docs/r/compute_service_attachment.html.markdown +++ b/website/docs/r/compute_service_attachment.html.markdown @@ -670,6 +670,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. * `send_propagated_connection_limit_if_zero` - (Optional) Controls the behavior of propagated_connection_limit. When false, setting propagated_connection_limit to zero causes the provider to use to the API's default value. When true, the provider will set propagated_connection_limit to zero. diff --git a/website/docs/r/compute_shared_vpc_host_project.html.markdown b/website/docs/r/compute_shared_vpc_host_project.html.markdown index e2898dd4512..c59f4c1acca 100644 --- a/website/docs/r/compute_shared_vpc_host_project.html.markdown +++ b/website/docs/r/compute_shared_vpc_host_project.html.markdown @@ -55,6 +55,13 @@ The following arguments are expected: * `project` - (Required) The ID of the project that will serve as a Shared VPC host project +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. + ## Attributes Reference In addition to the arguments listed above, the following computed attributes are exported: diff --git a/website/docs/r/compute_snapshot.html.markdown b/website/docs/r/compute_snapshot.html.markdown index 416393f2a76..554827806ce 100644 --- a/website/docs/r/compute_snapshot.html.markdown +++ b/website/docs/r/compute_snapshot.html.markdown @@ -270,6 +270,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `snapshot_encryption_key` block supports: diff --git a/website/docs/r/compute_snapshot_settings.html.markdown b/website/docs/r/compute_snapshot_settings.html.markdown index 9304ff121ab..ffff53a28a4 100644 --- a/website/docs/r/compute_snapshot_settings.html.markdown +++ b/website/docs/r/compute_snapshot_settings.html.markdown @@ -60,6 +60,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `storage_location` block supports: diff --git a/website/docs/r/compute_ssl_certificate.html.markdown b/website/docs/r/compute_ssl_certificate.html.markdown index f4a3fd85410..cc57de28a0f 100644 --- a/website/docs/r/compute_ssl_certificate.html.markdown +++ b/website/docs/r/compute_ssl_certificate.html.markdown @@ -234,6 +234,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. * `name_prefix` - (Optional) Creates a unique name beginning with the specified prefix. Conflicts with `name`. Max length is 54 characters. Prefixes with lengths longer than 37 characters will use a shortened diff --git a/website/docs/r/compute_ssl_policy.html.markdown b/website/docs/r/compute_ssl_policy.html.markdown index d0bdb9a1a5c..186d78cf67e 100644 --- a/website/docs/r/compute_ssl_policy.html.markdown +++ b/website/docs/r/compute_ssl_policy.html.markdown @@ -116,6 +116,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/compute_storage_pool.html.markdown b/website/docs/r/compute_storage_pool.html.markdown index ef67cc8164a..71052fc00d1 100644 --- a/website/docs/r/compute_storage_pool.html.markdown +++ b/website/docs/r/compute_storage_pool.html.markdown @@ -169,6 +169,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. * `deletion_protection` - (Optional) Whether Terraform will be prevented from destroying the StoragePool. When the field is set to true or unset in Terraform state, a `terraform apply` or `terraform destroy` that would delete the StoragePool will fail. diff --git a/website/docs/r/compute_subnetwork.html.markdown b/website/docs/r/compute_subnetwork.html.markdown index 389c1436733..26b1ae73de3 100644 --- a/website/docs/r/compute_subnetwork.html.markdown +++ b/website/docs/r/compute_subnetwork.html.markdown @@ -493,6 +493,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. * `send_secondary_ip_range_if_empty` - (Optional) Controls the removal behavior of secondary_ip_range. When false, removing secondary_ip_range from config will not produce a diff as the provider will default to the API's value. diff --git a/website/docs/r/compute_target_grpc_proxy.html.markdown b/website/docs/r/compute_target_grpc_proxy.html.markdown index 4f7db5fb583..dc7018979bf 100644 --- a/website/docs/r/compute_target_grpc_proxy.html.markdown +++ b/website/docs/r/compute_target_grpc_proxy.html.markdown @@ -173,6 +173,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/compute_target_http_proxy.html.markdown b/website/docs/r/compute_target_http_proxy.html.markdown index 7309351f52f..a8d3bbfec4f 100644 --- a/website/docs/r/compute_target_http_proxy.html.markdown +++ b/website/docs/r/compute_target_http_proxy.html.markdown @@ -257,6 +257,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/compute_target_https_proxy.html.markdown b/website/docs/r/compute_target_https_proxy.html.markdown index abc2833b928..6d23edc37c2 100644 --- a/website/docs/r/compute_target_https_proxy.html.markdown +++ b/website/docs/r/compute_target_https_proxy.html.markdown @@ -478,6 +478,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/compute_target_instance.html.markdown b/website/docs/r/compute_target_instance.html.markdown index 31d9d6e7408..4e67c28a13e 100644 --- a/website/docs/r/compute_target_instance.html.markdown +++ b/website/docs/r/compute_target_instance.html.markdown @@ -255,6 +255,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/compute_target_pool.html.markdown b/website/docs/r/compute_target_pool.html.markdown index 19e798c1225..3067b8f0f51 100644 --- a/website/docs/r/compute_target_pool.html.markdown +++ b/website/docs/r/compute_target_pool.html.markdown @@ -89,6 +89,13 @@ The following arguments are supported: * `security_policy` - (Optional, [Beta](../guides/provider_versions.html.markdown)) The resource URL for the security policy associated with this target pool. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. + ## Attributes Reference In addition to the arguments listed above, the following computed attributes are diff --git a/website/docs/r/compute_target_ssl_proxy.html.markdown b/website/docs/r/compute_target_ssl_proxy.html.markdown index 20e047abeb1..8de103158b9 100644 --- a/website/docs/r/compute_target_ssl_proxy.html.markdown +++ b/website/docs/r/compute_target_ssl_proxy.html.markdown @@ -129,6 +129,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/compute_target_tcp_proxy.html.markdown b/website/docs/r/compute_target_tcp_proxy.html.markdown index 10f10eb6f38..2744dcc7afc 100644 --- a/website/docs/r/compute_target_tcp_proxy.html.markdown +++ b/website/docs/r/compute_target_tcp_proxy.html.markdown @@ -218,6 +218,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/compute_url_map.html.markdown b/website/docs/r/compute_url_map.html.markdown index 71f15b4acfd..d69b74bbc76 100644 --- a/website/docs/r/compute_url_map.html.markdown +++ b/website/docs/r/compute_url_map.html.markdown @@ -1785,6 +1785,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `header_action` block supports: diff --git a/website/docs/r/compute_vpn_gateway.html.markdown b/website/docs/r/compute_vpn_gateway.html.markdown index 56522de6722..1ec46b60c49 100644 --- a/website/docs/r/compute_vpn_gateway.html.markdown +++ b/website/docs/r/compute_vpn_gateway.html.markdown @@ -223,6 +223,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `params` block supports: diff --git a/website/docs/r/compute_vpn_tunnel.html.markdown b/website/docs/r/compute_vpn_tunnel.html.markdown index 24fd2d090f7..61f477d56bd 100644 --- a/website/docs/r/compute_vpn_tunnel.html.markdown +++ b/website/docs/r/compute_vpn_tunnel.html.markdown @@ -316,6 +316,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `params` block supports: diff --git a/website/docs/r/compute_wire_group.html.markdown b/website/docs/r/compute_wire_group.html.markdown index a3bf5d1bb77..ce39bf8f19b 100644 --- a/website/docs/r/compute_wire_group.html.markdown +++ b/website/docs/r/compute_wire_group.html.markdown @@ -135,6 +135,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `endpoints` block supports: diff --git a/website/docs/r/contact_center_insights_analysis_rule.html.markdown b/website/docs/r/contact_center_insights_analysis_rule.html.markdown index 9adfa2510ff..4e8674a65de 100644 --- a/website/docs/r/contact_center_insights_analysis_rule.html.markdown +++ b/website/docs/r/contact_center_insights_analysis_rule.html.markdown @@ -157,6 +157,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `annotator_selector` block supports: diff --git a/website/docs/r/contact_center_insights_assessment_rule.html.markdown b/website/docs/r/contact_center_insights_assessment_rule.html.markdown index 5f172600f84..e14d8bfb038 100644 --- a/website/docs/r/contact_center_insights_assessment_rule.html.markdown +++ b/website/docs/r/contact_center_insights_assessment_rule.html.markdown @@ -120,6 +120,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `sample_rule` block supports: diff --git a/website/docs/r/contact_center_insights_auto_labeling_rule.html.markdown b/website/docs/r/contact_center_insights_auto_labeling_rule.html.markdown index 6ffe217487c..5a6ef51abb7 100644 --- a/website/docs/r/contact_center_insights_auto_labeling_rule.html.markdown +++ b/website/docs/r/contact_center_insights_auto_labeling_rule.html.markdown @@ -102,6 +102,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `conditions` block supports: diff --git a/website/docs/r/contact_center_insights_qa_question.html.markdown b/website/docs/r/contact_center_insights_qa_question.html.markdown index fc4a1d676e4..8c065b65fd4 100644 --- a/website/docs/r/contact_center_insights_qa_question.html.markdown +++ b/website/docs/r/contact_center_insights_qa_question.html.markdown @@ -149,6 +149,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `answer_choices` block supports: diff --git a/website/docs/r/contact_center_insights_qa_scorecard.html.markdown b/website/docs/r/contact_center_insights_qa_scorecard.html.markdown index b2e959b7e83..d1edfaec380 100644 --- a/website/docs/r/contact_center_insights_qa_scorecard.html.markdown +++ b/website/docs/r/contact_center_insights_qa_scorecard.html.markdown @@ -85,6 +85,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/contact_center_insights_qa_scorecard_revision.html.markdown b/website/docs/r/contact_center_insights_qa_scorecard_revision.html.markdown index 822c1f0b3e5..f5cde992d9b 100644 --- a/website/docs/r/contact_center_insights_qa_scorecard_revision.html.markdown +++ b/website/docs/r/contact_center_insights_qa_scorecard_revision.html.markdown @@ -70,6 +70,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/contact_center_insights_view.html.markdown b/website/docs/r/contact_center_insights_view.html.markdown index 03e7440fa25..86d35e04097 100644 --- a/website/docs/r/contact_center_insights_view.html.markdown +++ b/website/docs/r/contact_center_insights_view.html.markdown @@ -82,6 +82,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/container_analysis_note.html.markdown b/website/docs/r/container_analysis_note.html.markdown index dd59411577c..4af1a30526a 100644 --- a/website/docs/r/container_analysis_note.html.markdown +++ b/website/docs/r/container_analysis_note.html.markdown @@ -131,6 +131,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `attestation_authority` block supports: diff --git a/website/docs/r/container_analysis_occurrence.html.markdown b/website/docs/r/container_analysis_occurrence.html.markdown index 3de3a9ef007..91c1d4d8d0f 100644 --- a/website/docs/r/container_analysis_occurrence.html.markdown +++ b/website/docs/r/container_analysis_occurrence.html.markdown @@ -126,6 +126,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `attestation` block supports: diff --git a/website/docs/r/container_attached_cluster.html.markdown b/website/docs/r/container_attached_cluster.html.markdown index 2c85806edd8..27c209ac225 100644 --- a/website/docs/r/container_attached_cluster.html.markdown +++ b/website/docs/r/container_attached_cluster.html.markdown @@ -251,7 +251,15 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. -* `deletion_policy` - (Optional) Policy to determine what flags to send on delete. Possible values: DELETE, DELETE_IGNORE_ERRORS +* `deletion_policy` - (Optional) Policy to determine what flags to send on delete. + +When a 'terraform destroy' or 'terraform apply' would delete the resource, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. + +Possible values: DELETE, DELETE_IGNORE_ERRORS, PREVENT, ABANDON'. Defaults to 'DELETE'. + The `oidc_config` block supports: diff --git a/website/docs/r/container_aws_cluster.html.markdown b/website/docs/r/container_aws_cluster.html.markdown index a06a6c2f697..82dc06ebea2 100644 --- a/website/docs/r/container_aws_cluster.html.markdown +++ b/website/docs/r/container_aws_cluster.html.markdown @@ -338,7 +338,13 @@ The following arguments are supported: * `networking` - (Required) Cluster-wide networking configuration. - + +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `authorization` block supports: diff --git a/website/docs/r/container_aws_node_pool.html.markdown b/website/docs/r/container_aws_node_pool.html.markdown index d135b085a35..defd317fad2 100644 --- a/website/docs/r/container_aws_node_pool.html.markdown +++ b/website/docs/r/container_aws_node_pool.html.markdown @@ -547,7 +547,13 @@ The following arguments are supported: * `version` - (Required) The Kubernetes version to run on this node pool (e.g. `1.19.10-gke.1000`). You can list all supported versions on a given Google Cloud region by calling GetAwsServerConfig. - + +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `autoscaling` block supports: diff --git a/website/docs/r/container_azure_client.html.markdown b/website/docs/r/container_azure_client.html.markdown index 5bc5261248b..4b28f038338 100644 --- a/website/docs/r/container_azure_client.html.markdown +++ b/website/docs/r/container_azure_client.html.markdown @@ -64,6 +64,13 @@ The following arguments are supported: * `project` - (Optional) The project for the resource + +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. diff --git a/website/docs/r/container_azure_cluster.html.markdown b/website/docs/r/container_azure_cluster.html.markdown index e2a0a61f285..822eabeac95 100644 --- a/website/docs/r/container_azure_cluster.html.markdown +++ b/website/docs/r/container_azure_cluster.html.markdown @@ -181,7 +181,13 @@ The following arguments are supported: * `resource_group_id` - (Required) The ARM ID of the resource group where the cluster resources are deployed. For example: `/subscriptions/*/resourceGroups/*` - + +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `authorization` block supports: diff --git a/website/docs/r/container_azure_node_pool.html.markdown b/website/docs/r/container_azure_node_pool.html.markdown index cfd5c4c34fb..8dc3053119e 100644 --- a/website/docs/r/container_azure_node_pool.html.markdown +++ b/website/docs/r/container_azure_node_pool.html.markdown @@ -168,7 +168,13 @@ The following arguments are supported: * `version` - (Required) The Kubernetes version (e.g. `1.19.10-gke.1000`) running on this node pool. - + +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `autoscaling` block supports: diff --git a/website/docs/r/container_cluster.html.markdown b/website/docs/r/container_cluster.html.markdown index 8e2c9ab3314..d8c2cb5fef8 100644 --- a/website/docs/r/container_cluster.html.markdown +++ b/website/docs/r/container_cluster.html.markdown @@ -461,6 +461,14 @@ Fleet configuration for the cluster. Structure is [documented below](#nested_fle * `rbac_binding_config` - (Optional) RBACBindingConfig allows user to restrict ClusterRoleBindings an RoleBindings that can be created. Structure is [documented below](#nested_rbac_binding_config). +* `deletion_policy` - + (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. + The `default_snat_status` block supports * `disabled` - (Required) Whether the cluster disables default in-node sNAT rules. In-node sNAT rules will be disabled when defaultSnatStatus is disabled.When disabled is set to false, default IP masquerade rules will be applied to the nodes to prevent sNAT on cluster internal traffic diff --git a/website/docs/r/container_node_pool.html.markdown b/website/docs/r/container_node_pool.html.markdown index 55923f9efcb..d214d931091 100644 --- a/website/docs/r/container_node_pool.html.markdown +++ b/website/docs/r/container_node_pool.html.markdown @@ -189,6 +189,13 @@ cluster. * `queued_provisioning` - (Optional) Specifies node pool-level settings of queued provisioning. Structure is [documented below](#nested_queued_provisioning). +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. + The `autoscaling` block supports (either total or per zone limits are required): * `min_node_count` - (Optional) Minimum number of nodes per zone in the NodePool. diff --git a/website/docs/r/data_catalog_entry.html.markdown b/website/docs/r/data_catalog_entry.html.markdown index 65491400720..0c612810106 100644 --- a/website/docs/r/data_catalog_entry.html.markdown +++ b/website/docs/r/data_catalog_entry.html.markdown @@ -210,6 +210,12 @@ The following arguments are supported: Specification that applies to a Cloud Storage fileset. This is only valid on entries of type FILESET. Structure is [documented below](#nested_gcs_fileset_spec). +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `gcs_fileset_spec` block supports: diff --git a/website/docs/r/data_catalog_entry_group.html.markdown b/website/docs/r/data_catalog_entry_group.html.markdown index fc160da5574..6d12854d44f 100644 --- a/website/docs/r/data_catalog_entry_group.html.markdown +++ b/website/docs/r/data_catalog_entry_group.html.markdown @@ -87,6 +87,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/data_catalog_policy_tag.html.markdown b/website/docs/r/data_catalog_policy_tag.html.markdown index 59cf6ae9b6d..9e31b3657e7 100644 --- a/website/docs/r/data_catalog_policy_tag.html.markdown +++ b/website/docs/r/data_catalog_policy_tag.html.markdown @@ -118,6 +118,12 @@ The following arguments are supported: If empty, it means this policy tag is a top level policy tag. If not set, defaults to an empty string. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/data_catalog_tag.html.markdown b/website/docs/r/data_catalog_tag.html.markdown index 0dc788b662d..5b29c8d8ee6 100644 --- a/website/docs/r/data_catalog_tag.html.markdown +++ b/website/docs/r/data_catalog_tag.html.markdown @@ -362,6 +362,12 @@ The following arguments are supported: The name of the parent this tag is attached to. This can be the name of an entry or an entry group. If an entry group, the tag will be attached to all entries in that group. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `fields` block supports: diff --git a/website/docs/r/data_catalog_tag_template.html.markdown b/website/docs/r/data_catalog_tag_template.html.markdown index a59d0369089..1b901e8ff59 100644 --- a/website/docs/r/data_catalog_tag_template.html.markdown +++ b/website/docs/r/data_catalog_tag_template.html.markdown @@ -115,6 +115,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `fields` block supports: diff --git a/website/docs/r/data_catalog_taxonomy.html.markdown b/website/docs/r/data_catalog_taxonomy.html.markdown index 0efd5613286..ca0bea1db08 100644 --- a/website/docs/r/data_catalog_taxonomy.html.markdown +++ b/website/docs/r/data_catalog_taxonomy.html.markdown @@ -79,6 +79,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/data_fusion_instance.html.markdown b/website/docs/r/data_fusion_instance.html.markdown index 813ad645934..70dba4dab92 100644 --- a/website/docs/r/data_fusion_instance.html.markdown +++ b/website/docs/r/data_fusion_instance.html.markdown @@ -384,6 +384,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `network_config` block supports: diff --git a/website/docs/r/data_lineage_config.html.markdown b/website/docs/r/data_lineage_config.html.markdown index 0dbec537f06..dec84d9b046 100644 --- a/website/docs/r/data_lineage_config.html.markdown +++ b/website/docs/r/data_lineage_config.html.markdown @@ -151,6 +151,12 @@ The following arguments are supported: The region of the data lineage configuration for integration. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `ingestion` block supports: diff --git a/website/docs/r/data_loss_prevention_deidentify_template.html.markdown b/website/docs/r/data_loss_prevention_deidentify_template.html.markdown index 34890bbe6e3..34866bfb036 100644 --- a/website/docs/r/data_loss_prevention_deidentify_template.html.markdown +++ b/website/docs/r/data_loss_prevention_deidentify_template.html.markdown @@ -205,6 +205,12 @@ The following arguments are supported: that is, it must match the regular expression: [a-zA-Z\d-_]+. The maximum length is 100 characters. Can be empty to allow the system to generate one. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `deidentify_config` block supports: diff --git a/website/docs/r/data_loss_prevention_discovery_config.html.markdown b/website/docs/r/data_loss_prevention_discovery_config.html.markdown index e346e2a7173..019c0a7b8df 100644 --- a/website/docs/r/data_loss_prevention_discovery_config.html.markdown +++ b/website/docs/r/data_loss_prevention_discovery_config.html.markdown @@ -561,6 +561,12 @@ The following arguments are supported: Required. A status for this configuration Possible values are: `RUNNING`, `PAUSED`. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `org_config` block supports: diff --git a/website/docs/r/data_loss_prevention_inspect_template.html.markdown b/website/docs/r/data_loss_prevention_inspect_template.html.markdown index 553bdcbed21..aac76a623db 100644 --- a/website/docs/r/data_loss_prevention_inspect_template.html.markdown +++ b/website/docs/r/data_loss_prevention_inspect_template.html.markdown @@ -332,6 +332,12 @@ The following arguments are supported: The core content of the template. Structure is [documented below](#nested_inspect_config). +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `inspect_config` block supports: diff --git a/website/docs/r/data_loss_prevention_job_trigger.html.markdown b/website/docs/r/data_loss_prevention_job_trigger.html.markdown index 8abec5e56cd..f0e18fe1c20 100644 --- a/website/docs/r/data_loss_prevention_job_trigger.html.markdown +++ b/website/docs/r/data_loss_prevention_job_trigger.html.markdown @@ -648,6 +648,12 @@ The following arguments are supported: Controls what and how to inspect for findings. Structure is [documented below](#nested_inspect_job). +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `triggers` block supports: diff --git a/website/docs/r/data_loss_prevention_stored_info_type.html.markdown b/website/docs/r/data_loss_prevention_stored_info_type.html.markdown index a4024858c19..b5a26f4514e 100644 --- a/website/docs/r/data_loss_prevention_stored_info_type.html.markdown +++ b/website/docs/r/data_loss_prevention_stored_info_type.html.markdown @@ -152,6 +152,12 @@ The following arguments are supported: Dictionary which defines the rule. Structure is [documented below](#nested_large_custom_dictionary). +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `regex` block supports: diff --git a/website/docs/r/data_pipeline_pipeline.html.markdown b/website/docs/r/data_pipeline_pipeline.html.markdown index 6bf1c92ff41..8b3b1944322 100644 --- a/website/docs/r/data_pipeline_pipeline.html.markdown +++ b/website/docs/r/data_pipeline_pipeline.html.markdown @@ -146,6 +146,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `workload` block supports: diff --git a/website/docs/r/database_migration_service_connection_profile.html.markdown b/website/docs/r/database_migration_service_connection_profile.html.markdown index bca0d0a9b5f..46674d4e2c4 100644 --- a/website/docs/r/database_migration_service_connection_profile.html.markdown +++ b/website/docs/r/database_migration_service_connection_profile.html.markdown @@ -568,6 +568,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `mysql` block supports: diff --git a/website/docs/r/database_migration_service_migration_job.html.markdown b/website/docs/r/database_migration_service_migration_job.html.markdown index 01b44658666..26bbff7c62e 100644 --- a/website/docs/r/database_migration_service_migration_job.html.markdown +++ b/website/docs/r/database_migration_service_migration_job.html.markdown @@ -582,6 +582,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `dump_flags` block supports: diff --git a/website/docs/r/database_migration_service_private_connection.html.markdown b/website/docs/r/database_migration_service_private_connection.html.markdown index 043262b5fef..3df4c1cd16f 100644 --- a/website/docs/r/database_migration_service_private_connection.html.markdown +++ b/website/docs/r/database_migration_service_private_connection.html.markdown @@ -99,6 +99,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `vpc_peering_config` block supports: diff --git a/website/docs/r/dataflow_flex_template_job.html.markdown b/website/docs/r/dataflow_flex_template_job.html.markdown index 5aad523da59..fa747fb31e2 100644 --- a/website/docs/r/dataflow_flex_template_job.html.markdown +++ b/website/docs/r/dataflow_flex_template_job.html.markdown @@ -166,6 +166,13 @@ and will remove the resource from terraform state and move on. See above note. * `transform_name_mapping` - (Optional) Only applicable when updating a pipeline. Map of transform name prefixes of the job to be replaced with the corresponding name prefixes of the new job.Only applicable when updating a pipeline. Map of transform name prefixes of the job to be replaced with the corresponding name prefixes of the new job. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. + ## Attributes Reference In addition to the arguments listed above, the following computed attributes are exported: diff --git a/website/docs/r/dataflow_job.html.markdown b/website/docs/r/dataflow_job.html.markdown index ad0cde9bf5d..26d44701eda 100644 --- a/website/docs/r/dataflow_job.html.markdown +++ b/website/docs/r/dataflow_job.html.markdown @@ -138,6 +138,12 @@ The following arguments are supported: * `ip_configuration` - (Optional) The configuration for VM IPs. Options are `"WORKER_IP_PUBLIC"` or `"WORKER_IP_PRIVATE"`. * `additional_experiments` - (Optional) List of experiments that should be used by the job. An example value is `["enable_stackdriver_agent_metrics"]`. * `enable_streaming_engine` - (Optional) Enable/disable the use of [Streaming Engine](https://cloud.google.com/dataflow/docs/guides/deploying-a-pipeline#streaming-engine) for the job. Note that Streaming Engine is enabled by default for pipelines developed against the Beam SDK for Python v2.21.0 or later when using Python 3. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/dataform_config.html.markdown b/website/docs/r/dataform_config.html.markdown index 7981ab34d03..10ed2b31373 100644 --- a/website/docs/r/dataform_config.html.markdown +++ b/website/docs/r/dataform_config.html.markdown @@ -178,6 +178,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/dataform_folder.html.markdown b/website/docs/r/dataform_folder.html.markdown index 62512b125f0..d6f32d4635c 100644 --- a/website/docs/r/dataform_folder.html.markdown +++ b/website/docs/r/dataform_folder.html.markdown @@ -87,6 +87,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/dataform_repository.html.markdown b/website/docs/r/dataform_repository.html.markdown index ce6fb26475f..c829a8b704c 100644 --- a/website/docs/r/dataform_repository.html.markdown +++ b/website/docs/r/dataform_repository.html.markdown @@ -159,7 +159,15 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. -* `deletion_policy` - (Optional) Policy to control how the repository and its child resources are deleted. When set to `FORCE`, any child resources of this repository will also be deleted. Possible values: `DELETE`, `FORCE`. Defaults to `DELETE`. +* `deletion_policy` - (Optional) Policy to control how the repository and its child resources are deleted. +When set to `FORCE`, any child resources of this repository will also be deleted. + +When a 'terraform destroy' or 'terraform apply' would delete the resource, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. + +Possible values: `DELETE`, `FORCE`, 'PREVENT', 'ABANDON'. Defaults to `DELETE`. diff --git a/website/docs/r/dataform_repository_release_config.html.markdown b/website/docs/r/dataform_repository_release_config.html.markdown index cbf4eba9726..2242c8983aa 100644 --- a/website/docs/r/dataform_repository_release_config.html.markdown +++ b/website/docs/r/dataform_repository_release_config.html.markdown @@ -211,6 +211,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `code_compilation_config` block supports: diff --git a/website/docs/r/dataform_repository_workflow_config.html.markdown b/website/docs/r/dataform_repository_workflow_config.html.markdown index fc8263b106f..fc6ba4f6448 100644 --- a/website/docs/r/dataform_repository_workflow_config.html.markdown +++ b/website/docs/r/dataform_repository_workflow_config.html.markdown @@ -182,6 +182,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `invocation_config` block supports: diff --git a/website/docs/r/dataform_team_folder.html.markdown b/website/docs/r/dataform_team_folder.html.markdown index b1793f731c9..ad91620f137 100644 --- a/website/docs/r/dataform_team_folder.html.markdown +++ b/website/docs/r/dataform_team_folder.html.markdown @@ -62,6 +62,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/dataplex_aspect_type.html.markdown b/website/docs/r/dataplex_aspect_type.html.markdown index 6c4bc488cc2..59bf4de352f 100644 --- a/website/docs/r/dataplex_aspect_type.html.markdown +++ b/website/docs/r/dataplex_aspect_type.html.markdown @@ -253,6 +253,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/dataplex_asset.html.markdown b/website/docs/r/dataplex_asset.html.markdown index f0719970a8e..16134c5e6ab 100644 --- a/website/docs/r/dataplex_asset.html.markdown +++ b/website/docs/r/dataplex_asset.html.markdown @@ -119,7 +119,13 @@ The following arguments are supported: * `resource_spec` - (Required) Required. Immutable. Specification of the resource that is referenced by this asset. - + +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `discovery_spec` block supports: diff --git a/website/docs/r/dataplex_data_asset.html.markdown b/website/docs/r/dataplex_data_asset.html.markdown index a13f519c4c4..d3c3d50af74 100644 --- a/website/docs/r/dataplex_data_asset.html.markdown +++ b/website/docs/r/dataplex_data_asset.html.markdown @@ -174,6 +174,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `access_group_configs` block supports: diff --git a/website/docs/r/dataplex_data_product.html.markdown b/website/docs/r/dataplex_data_product.html.markdown index 645b23eb60b..0d3187c8585 100644 --- a/website/docs/r/dataplex_data_product.html.markdown +++ b/website/docs/r/dataplex_data_product.html.markdown @@ -140,6 +140,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `access_groups` block supports: diff --git a/website/docs/r/dataplex_data_product_data_asset.html.markdown b/website/docs/r/dataplex_data_product_data_asset.html.markdown index c2ccae0e960..bbc066b941a 100644 --- a/website/docs/r/dataplex_data_product_data_asset.html.markdown +++ b/website/docs/r/dataplex_data_product_data_asset.html.markdown @@ -173,6 +173,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `access_group_configs` block supports: diff --git a/website/docs/r/dataplex_datascan.html.markdown b/website/docs/r/dataplex_datascan.html.markdown index f038e8379b0..e0059bc1ec2 100644 --- a/website/docs/r/dataplex_datascan.html.markdown +++ b/website/docs/r/dataplex_datascan.html.markdown @@ -1192,6 +1192,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `data` block supports: diff --git a/website/docs/r/dataplex_entry.html.markdown b/website/docs/r/dataplex_entry.html.markdown index ec7973b7580..4710cd7281e 100644 --- a/website/docs/r/dataplex_entry.html.markdown +++ b/website/docs/r/dataplex_entry.html.markdown @@ -418,6 +418,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `aspects` block supports: diff --git a/website/docs/r/dataplex_entry_group.html.markdown b/website/docs/r/dataplex_entry_group.html.markdown index edfdc4b818a..7c8aa8b4962 100644 --- a/website/docs/r/dataplex_entry_group.html.markdown +++ b/website/docs/r/dataplex_entry_group.html.markdown @@ -82,6 +82,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/dataplex_entry_link.html.markdown b/website/docs/r/dataplex_entry_link.html.markdown index a3259d19908..816abcf3eb2 100644 --- a/website/docs/r/dataplex_entry_link.html.markdown +++ b/website/docs/r/dataplex_entry_link.html.markdown @@ -240,6 +240,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `entry_references` block supports: diff --git a/website/docs/r/dataplex_entry_type.html.markdown b/website/docs/r/dataplex_entry_type.html.markdown index bd4a0dada2d..4bc06c577fa 100644 --- a/website/docs/r/dataplex_entry_type.html.markdown +++ b/website/docs/r/dataplex_entry_type.html.markdown @@ -140,6 +140,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `required_aspects` block supports: diff --git a/website/docs/r/dataplex_glossary.html.markdown b/website/docs/r/dataplex_glossary.html.markdown index 84ac353ec03..6406545b020 100644 --- a/website/docs/r/dataplex_glossary.html.markdown +++ b/website/docs/r/dataplex_glossary.html.markdown @@ -90,6 +90,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/dataplex_glossary_category.html.markdown b/website/docs/r/dataplex_glossary_category.html.markdown index 8363504e5ea..59cea1c5409 100644 --- a/website/docs/r/dataplex_glossary_category.html.markdown +++ b/website/docs/r/dataplex_glossary_category.html.markdown @@ -112,6 +112,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/dataplex_glossary_term.html.markdown b/website/docs/r/dataplex_glossary_term.html.markdown index 5639814028c..eb0bc20ea22 100644 --- a/website/docs/r/dataplex_glossary_term.html.markdown +++ b/website/docs/r/dataplex_glossary_term.html.markdown @@ -112,6 +112,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/dataplex_lake.html.markdown b/website/docs/r/dataplex_lake.html.markdown index 1189a630acf..d5c9d3f68d3 100644 --- a/website/docs/r/dataplex_lake.html.markdown +++ b/website/docs/r/dataplex_lake.html.markdown @@ -78,6 +78,13 @@ Please refer to the field `effective_labels` for all of the labels present on th * `project` - (Optional) The project for the resource + +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. diff --git a/website/docs/r/dataplex_task.html.markdown b/website/docs/r/dataplex_task.html.markdown index 9cd3f63bac0..3f2bbeb75aa 100644 --- a/website/docs/r/dataplex_task.html.markdown +++ b/website/docs/r/dataplex_task.html.markdown @@ -269,6 +269,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `trigger_spec` block supports: diff --git a/website/docs/r/dataplex_zone.html.markdown b/website/docs/r/dataplex_zone.html.markdown index c63e852c1b6..26db1fbbc2e 100644 --- a/website/docs/r/dataplex_zone.html.markdown +++ b/website/docs/r/dataplex_zone.html.markdown @@ -87,7 +87,13 @@ The following arguments are supported: * `type` - (Required) Required. Immutable. The type of the zone. Possible values: TYPE_UNSPECIFIED, RAW, CURATED - + +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `discovery_spec` block supports: diff --git a/website/docs/r/dataproc_autoscaling_policy.html.markdown b/website/docs/r/dataproc_autoscaling_policy.html.markdown index b6fe7ab1481..e922381f444 100644 --- a/website/docs/r/dataproc_autoscaling_policy.html.markdown +++ b/website/docs/r/dataproc_autoscaling_policy.html.markdown @@ -99,6 +99,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `worker_config` block supports: diff --git a/website/docs/r/dataproc_batch.html.markdown b/website/docs/r/dataproc_batch.html.markdown index 46893f2fbac..096f2c12fd9 100644 --- a/website/docs/r/dataproc_batch.html.markdown +++ b/website/docs/r/dataproc_batch.html.markdown @@ -349,6 +349,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `runtime_config` block supports: diff --git a/website/docs/r/dataproc_cluster.html.markdown b/website/docs/r/dataproc_cluster.html.markdown index cd6829e2fa8..766811ea6ee 100644 --- a/website/docs/r/dataproc_cluster.html.markdown +++ b/website/docs/r/dataproc_cluster.html.markdown @@ -170,6 +170,14 @@ resource "google_dataproc_cluster" "accelerated_cluster" { [Duration](https://developers.google.com/protocol-buffers/docs/proto3#json)). Only supported on Dataproc image versions 1.2 and higher. For more context see the [docs](https://cloud.google.com/dataproc/docs/reference/rest/v1/projects.regions.clusters/patch#query-parameters) + +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. + - - - The `virtual_cluster_config` block supports: diff --git a/website/docs/r/dataproc_gdc_application_environment.html.markdown b/website/docs/r/dataproc_gdc_application_environment.html.markdown index b1472dca23b..6bf20ed0da5 100644 --- a/website/docs/r/dataproc_gdc_application_environment.html.markdown +++ b/website/docs/r/dataproc_gdc_application_environment.html.markdown @@ -124,6 +124,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `spark_application_environment_config` block supports: diff --git a/website/docs/r/dataproc_gdc_service_instance.html.markdown b/website/docs/r/dataproc_gdc_service_instance.html.markdown index cb20808458a..a56a13a64e5 100644 --- a/website/docs/r/dataproc_gdc_service_instance.html.markdown +++ b/website/docs/r/dataproc_gdc_service_instance.html.markdown @@ -94,6 +94,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `gdce_cluster` block supports: diff --git a/website/docs/r/dataproc_gdc_spark_application.html.markdown b/website/docs/r/dataproc_gdc_spark_application.html.markdown index cd921e93e22..b5d87af69d3 100644 --- a/website/docs/r/dataproc_gdc_spark_application.html.markdown +++ b/website/docs/r/dataproc_gdc_spark_application.html.markdown @@ -275,6 +275,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `pyspark_application_config` block supports: diff --git a/website/docs/r/dataproc_job.html.markdown b/website/docs/r/dataproc_job.html.markdown index 6136e572599..0ad838af9e5 100644 --- a/website/docs/r/dataproc_job.html.markdown +++ b/website/docs/r/dataproc_job.html.markdown @@ -131,6 +131,13 @@ output "pyspark_status" { * `wait_for_completion` - (Optional) If set to true, Terraform will wait for the job to reach a terminal state (`DONE`, `ERROR`, `CANCELLED`, `ATTEMPT_FAILURE`). Otherwise, Terraform will consider the job 'created' once it is in the `RUNNING` state. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. + The `pyspark_config` block supports: Submitting a pyspark job to the cluster. Below is an example configuration: diff --git a/website/docs/r/dataproc_metastore_federation.html.markdown b/website/docs/r/dataproc_metastore_federation.html.markdown index c6d3aa5bfee..65a546ba651 100644 --- a/website/docs/r/dataproc_metastore_federation.html.markdown +++ b/website/docs/r/dataproc_metastore_federation.html.markdown @@ -141,6 +141,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. * `deletion_protection` - (Optional) Whether Terraform will be prevented from destroying the federation. Defaults to false. When the field is set to true in Terraform state, a `terraform apply` or `terraform destroy` that would delete the federation will fail. diff --git a/website/docs/r/dataproc_metastore_service.html.markdown b/website/docs/r/dataproc_metastore_service.html.markdown index 46523cfccb5..ad3755779e7 100644 --- a/website/docs/r/dataproc_metastore_service.html.markdown +++ b/website/docs/r/dataproc_metastore_service.html.markdown @@ -515,6 +515,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `scaling_config` block supports: diff --git a/website/docs/r/dataproc_session_template.html.markdown b/website/docs/r/dataproc_session_template.html.markdown index 8e5548163cb..cb441cd1798 100644 --- a/website/docs/r/dataproc_session_template.html.markdown +++ b/website/docs/r/dataproc_session_template.html.markdown @@ -250,6 +250,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `runtime_config` block supports: diff --git a/website/docs/r/dataproc_workflow_template.html.markdown b/website/docs/r/dataproc_workflow_template.html.markdown index ad94c14b5d7..d48310d8f03 100644 --- a/website/docs/r/dataproc_workflow_template.html.markdown +++ b/website/docs/r/dataproc_workflow_template.html.markdown @@ -169,6 +169,13 @@ The following arguments are supported: * `encryption_config` - (Optional) Encryption settings for encrypting workflow template job arguments. Structure is [documented below](#nested_encryption_config) +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. + The `encryption_config` block supports: * `kms_key` - (Optional) The Cloud KMS key name to use for encrypting workflow template [job arguments](https://docs.docs.cloud.google.com/dataproc/docs/concepts/workflows/use-workflows). diff --git a/website/docs/r/datastream_connection_profile.html.markdown b/website/docs/r/datastream_connection_profile.html.markdown index 674ae1ca6ec..4cc86962147 100644 --- a/website/docs/r/datastream_connection_profile.html.markdown +++ b/website/docs/r/datastream_connection_profile.html.markdown @@ -611,6 +611,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `oracle_profile` block supports: diff --git a/website/docs/r/datastream_private_connection.html.markdown b/website/docs/r/datastream_private_connection.html.markdown index 3298f16c2bf..a51fa9b52ba 100644 --- a/website/docs/r/datastream_private_connection.html.markdown +++ b/website/docs/r/datastream_private_connection.html.markdown @@ -176,7 +176,12 @@ The following arguments are supported: * `deletion_policy` - (Optional) The deletion policy for the private connection. Setting `FORCE` will also delete any child routes that belong to this private connection. Setting `DEFAULT` will fail the delete if child routes exist. Defaults to `FORCE` for backwards compatibility. -Possible values: `DEFAULT`, `FORCE`. + +When a 'terraform destroy' or 'terraform apply' would delete the resource, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", the command will behave as if set to "DEFAULT". diff --git a/website/docs/r/datastream_stream.html.markdown b/website/docs/r/datastream_stream.html.markdown index 6113abf59c8..765db0a12f8 100644 --- a/website/docs/r/datastream_stream.html.markdown +++ b/website/docs/r/datastream_stream.html.markdown @@ -1655,6 +1655,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. * `desired_state` - (Optional) Desired state of the Stream. Set this field to `RUNNING` to start the stream, `NOT_STARTED` to create the stream without starting and `PAUSED` to pause the stream from a `RUNNING` state. diff --git a/website/docs/r/deployment_manager_deployment.html.markdown b/website/docs/r/deployment_manager_deployment.html.markdown index 7136f58a2b5..265c995cf1c 100644 --- a/website/docs/r/deployment_manager_deployment.html.markdown +++ b/website/docs/r/deployment_manager_deployment.html.markdown @@ -154,6 +154,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `target` block supports: diff --git a/website/docs/r/developer_connect_account_connector.html.markdown b/website/docs/r/developer_connect_account_connector.html.markdown index ddb54a1dc88..e9e5a03ee88 100644 --- a/website/docs/r/developer_connect_account_connector.html.markdown +++ b/website/docs/r/developer_connect_account_connector.html.markdown @@ -285,6 +285,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `custom_oauth_config` block supports: diff --git a/website/docs/r/developer_connect_connection.html.markdown b/website/docs/r/developer_connect_connection.html.markdown index 4958047d015..fd42a0c8a41 100644 --- a/website/docs/r/developer_connect_connection.html.markdown +++ b/website/docs/r/developer_connect_connection.html.markdown @@ -882,6 +882,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `github_config` block supports: diff --git a/website/docs/r/developer_connect_git_repository_link.html.markdown b/website/docs/r/developer_connect_git_repository_link.html.markdown index 6aab464c38b..134e50f4f29 100644 --- a/website/docs/r/developer_connect_git_repository_link.html.markdown +++ b/website/docs/r/developer_connect_git_repository_link.html.markdown @@ -126,6 +126,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/developer_connect_insights_config.html.markdown b/website/docs/r/developer_connect_insights_config.html.markdown index 4b65d9b395b..59af7318288 100644 --- a/website/docs/r/developer_connect_insights_config.html.markdown +++ b/website/docs/r/developer_connect_insights_config.html.markdown @@ -341,6 +341,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `target_projects` block supports: diff --git a/website/docs/r/dialogflow_agent.html.markdown b/website/docs/r/dialogflow_agent.html.markdown index 5a68c8823cd..aa42c6ae4dd 100644 --- a/website/docs/r/dialogflow_agent.html.markdown +++ b/website/docs/r/dialogflow_agent.html.markdown @@ -154,6 +154,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/dialogflow_conversation_profile.html.markdown b/website/docs/r/dialogflow_conversation_profile.html.markdown index 63e826defbe..f1e6ac4d38d 100644 --- a/website/docs/r/dialogflow_conversation_profile.html.markdown +++ b/website/docs/r/dialogflow_conversation_profile.html.markdown @@ -191,6 +191,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `automated_agent_config` block supports: diff --git a/website/docs/r/dialogflow_cx_agent.html.markdown b/website/docs/r/dialogflow_cx_agent.html.markdown index cd5eadfa86c..d671a011d6f 100644 --- a/website/docs/r/dialogflow_cx_agent.html.markdown +++ b/website/docs/r/dialogflow_cx_agent.html.markdown @@ -259,6 +259,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. * `delete_chat_engine_on_destroy` - (Optional) If set to `true`, Terraform will delete the chat engine associated with the agent when the agent is destroyed. Otherwise, the chat engine will persist. diff --git a/website/docs/r/dialogflow_cx_entity_type.html.markdown b/website/docs/r/dialogflow_cx_entity_type.html.markdown index af4c657e8b5..f74c68d8681 100644 --- a/website/docs/r/dialogflow_cx_entity_type.html.markdown +++ b/website/docs/r/dialogflow_cx_entity_type.html.markdown @@ -129,6 +129,12 @@ The following arguments are supported: EntityType.excluded_phrases.value If not specified, the agent's default language is used. Many languages are supported. Note: languages must be enabled in the agent before they can be used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `entities` block supports: diff --git a/website/docs/r/dialogflow_cx_environment.html.markdown b/website/docs/r/dialogflow_cx_environment.html.markdown index 70fb727f909..054176ca63b 100644 --- a/website/docs/r/dialogflow_cx_environment.html.markdown +++ b/website/docs/r/dialogflow_cx_environment.html.markdown @@ -96,6 +96,12 @@ The following arguments are supported: The Agent to create an Environment for. Format: projects//locations//agents/. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `version_configs` block supports: diff --git a/website/docs/r/dialogflow_cx_flow.html.markdown b/website/docs/r/dialogflow_cx_flow.html.markdown index 1fd5280de8c..b5308d18998 100644 --- a/website/docs/r/dialogflow_cx_flow.html.markdown +++ b/website/docs/r/dialogflow_cx_flow.html.markdown @@ -612,6 +612,12 @@ The following arguments are supported: Flow.transition_routes.trigger_fulfillment.conditional_cases If not specified, the agent's default language is used. Many languages are supported. Note: languages must be enabled in the agent before they can be used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. * `is_default_start_flow` - (Optional) Marks this as the [Default Start Flow](https://cloud.google.com/dialogflow/cx/docs/concept/flow#start) for an agent. When you create an agent, the Default Start Flow is created automatically. The Default Start Flow cannot be deleted; deleting the `google_dialogflow_cx_flow` resource does nothing to the underlying GCP resources. diff --git a/website/docs/r/dialogflow_cx_generative_settings.html.markdown b/website/docs/r/dialogflow_cx_generative_settings.html.markdown index 23c61a8824d..25c093c987c 100644 --- a/website/docs/r/dialogflow_cx_generative_settings.html.markdown +++ b/website/docs/r/dialogflow_cx_generative_settings.html.markdown @@ -120,6 +120,12 @@ The following arguments are supported: The agent to create a flow for. Format: projects//locations//agents/. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `fallback_settings` block supports: diff --git a/website/docs/r/dialogflow_cx_generator.html.markdown b/website/docs/r/dialogflow_cx_generator.html.markdown index a74dc41f75a..28d0520419a 100644 --- a/website/docs/r/dialogflow_cx_generator.html.markdown +++ b/website/docs/r/dialogflow_cx_generator.html.markdown @@ -106,6 +106,12 @@ The following arguments are supported: * Generator.prompt_text.text If not specified, the agent's default language is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `prompt_text` block supports: diff --git a/website/docs/r/dialogflow_cx_intent.html.markdown b/website/docs/r/dialogflow_cx_intent.html.markdown index 73100a1a5f7..16721ab8474 100644 --- a/website/docs/r/dialogflow_cx_intent.html.markdown +++ b/website/docs/r/dialogflow_cx_intent.html.markdown @@ -144,6 +144,12 @@ The following arguments are supported: Intent.training_phrases.parts.text If not specified, the agent's default language is used. Many languages are supported. Note: languages must be enabled in the agent before they can be used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. * `is_default_welcome_intent` - (Optional) Marks this as the [Default Welcome Intent](https://cloud.google.com/dialogflow/cx/docs/concept/intent#welcome) for an agent. When you create an agent, a Default Welcome Intent is created automatically. The Default Welcome Intent cannot be deleted; deleting the `google_dialogflow_cx_intent` resource does nothing to the underlying GCP resources. diff --git a/website/docs/r/dialogflow_cx_page.html.markdown b/website/docs/r/dialogflow_cx_page.html.markdown index 17e68b91ae7..a16f273becf 100644 --- a/website/docs/r/dialogflow_cx_page.html.markdown +++ b/website/docs/r/dialogflow_cx_page.html.markdown @@ -806,6 +806,12 @@ The following arguments are supported: Page.transition_routes.trigger_fulfillment.conditional_cases If not specified, the agent's default language is used. Many languages are supported. Note: languages must be enabled in the agent before they can be used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `entry_fulfillment` block supports: diff --git a/website/docs/r/dialogflow_cx_playbook.html.markdown b/website/docs/r/dialogflow_cx_playbook.html.markdown index c8250946db7..d9f00ab40f1 100644 --- a/website/docs/r/dialogflow_cx_playbook.html.markdown +++ b/website/docs/r/dialogflow_cx_playbook.html.markdown @@ -219,6 +219,12 @@ The following arguments are supported: The agent to create a Playbook for. Format: projects//locations//agents/. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `instruction` block supports: diff --git a/website/docs/r/dialogflow_cx_security_settings.html.markdown b/website/docs/r/dialogflow_cx_security_settings.html.markdown index c864bc89754..8d30ce8d7c1 100644 --- a/website/docs/r/dialogflow_cx_security_settings.html.markdown +++ b/website/docs/r/dialogflow_cx_security_settings.html.markdown @@ -178,6 +178,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `audio_export_settings` block supports: diff --git a/website/docs/r/dialogflow_cx_test_case.html.markdown b/website/docs/r/dialogflow_cx_test_case.html.markdown index e76d37f6b02..aeb081ddfee 100644 --- a/website/docs/r/dialogflow_cx_test_case.html.markdown +++ b/website/docs/r/dialogflow_cx_test_case.html.markdown @@ -200,6 +200,12 @@ The following arguments are supported: The agent to create the test case for. Format: projects//locations//agents/. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `test_config` block supports: diff --git a/website/docs/r/dialogflow_cx_tool.html.markdown b/website/docs/r/dialogflow_cx_tool.html.markdown index 8ed49332f9f..d554ce1f9a0 100644 --- a/website/docs/r/dialogflow_cx_tool.html.markdown +++ b/website/docs/r/dialogflow_cx_tool.html.markdown @@ -374,6 +374,12 @@ The following arguments are supported: The agent to create a Tool for. Format: projects//locations//agents/. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `open_api_spec` block supports: diff --git a/website/docs/r/dialogflow_cx_tool_version.html.markdown b/website/docs/r/dialogflow_cx_tool_version.html.markdown index bac10aac0a1..d113387e4f0 100644 --- a/website/docs/r/dialogflow_cx_tool_version.html.markdown +++ b/website/docs/r/dialogflow_cx_tool_version.html.markdown @@ -505,6 +505,12 @@ The following arguments are supported: Format: projects//locations//agents//tools/. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `tool` block supports: diff --git a/website/docs/r/dialogflow_cx_version.html.markdown b/website/docs/r/dialogflow_cx_version.html.markdown index 95e455c9198..73e1d266996 100644 --- a/website/docs/r/dialogflow_cx_version.html.markdown +++ b/website/docs/r/dialogflow_cx_version.html.markdown @@ -82,6 +82,12 @@ The following arguments are supported: The Flow to create an Version for. Format: projects//locations//agents//flows/. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/dialogflow_cx_webhook.html.markdown b/website/docs/r/dialogflow_cx_webhook.html.markdown index 79ae87b61ba..afbf61fe4e9 100644 --- a/website/docs/r/dialogflow_cx_webhook.html.markdown +++ b/website/docs/r/dialogflow_cx_webhook.html.markdown @@ -341,6 +341,12 @@ The following arguments are supported: The agent to create a webhook for. Format: projects//locations//agents/. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `generic_web_service` block supports: diff --git a/website/docs/r/dialogflow_encryption_spec.html.markdown b/website/docs/r/dialogflow_encryption_spec.html.markdown index 3ce5fa0b833..771ae4109d4 100644 --- a/website/docs/r/dialogflow_encryption_spec.html.markdown +++ b/website/docs/r/dialogflow_encryption_spec.html.markdown @@ -128,6 +128,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `encryption_spec` block supports: diff --git a/website/docs/r/dialogflow_entity_type.html.markdown b/website/docs/r/dialogflow_entity_type.html.markdown index adb1b2287ee..a165120ef88 100644 --- a/website/docs/r/dialogflow_entity_type.html.markdown +++ b/website/docs/r/dialogflow_entity_type.html.markdown @@ -86,6 +86,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `entities` block supports: diff --git a/website/docs/r/dialogflow_environment.html.markdown b/website/docs/r/dialogflow_environment.html.markdown index a33660a8fa0..a9eaa18305b 100644 --- a/website/docs/r/dialogflow_environment.html.markdown +++ b/website/docs/r/dialogflow_environment.html.markdown @@ -107,6 +107,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `text_to_speech_settings` block supports: diff --git a/website/docs/r/dialogflow_fulfillment.html.markdown b/website/docs/r/dialogflow_fulfillment.html.markdown index 5902f55ce51..83a3a0a362b 100644 --- a/website/docs/r/dialogflow_fulfillment.html.markdown +++ b/website/docs/r/dialogflow_fulfillment.html.markdown @@ -82,6 +82,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `features` block supports: diff --git a/website/docs/r/dialogflow_generator.html.markdown b/website/docs/r/dialogflow_generator.html.markdown index 32df52242da..2ccfae44472 100644 --- a/website/docs/r/dialogflow_generator.html.markdown +++ b/website/docs/r/dialogflow_generator.html.markdown @@ -96,6 +96,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `summarization_context` block supports: diff --git a/website/docs/r/dialogflow_intent.html.markdown b/website/docs/r/dialogflow_intent.html.markdown index 6951d17996f..84ebb44f92c 100644 --- a/website/docs/r/dialogflow_intent.html.markdown +++ b/website/docs/r/dialogflow_intent.html.markdown @@ -165,6 +165,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/dialogflow_version.html.markdown b/website/docs/r/dialogflow_version.html.markdown index 4fbe22d2495..7f6db77eb2c 100644 --- a/website/docs/r/dialogflow_version.html.markdown +++ b/website/docs/r/dialogflow_version.html.markdown @@ -80,6 +80,12 @@ The following arguments are supported: (Optional) The developer-provided description of this version. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/discovery_engine_acl_config.html.markdown b/website/docs/r/discovery_engine_acl_config.html.markdown index fb8873f68bd..d001eed6fa2 100644 --- a/website/docs/r/discovery_engine_acl_config.html.markdown +++ b/website/docs/r/discovery_engine_acl_config.html.markdown @@ -67,6 +67,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `idp_config` block supports: diff --git a/website/docs/r/discovery_engine_assistant.html.markdown b/website/docs/r/discovery_engine_assistant.html.markdown index ffc9c4bee46..32c48e0cf78 100644 --- a/website/docs/r/discovery_engine_assistant.html.markdown +++ b/website/docs/r/discovery_engine_assistant.html.markdown @@ -130,6 +130,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `generation_config` block supports: diff --git a/website/docs/r/discovery_engine_chat_engine.html.markdown b/website/docs/r/discovery_engine_chat_engine.html.markdown index c6336133eb6..19c13992d87 100644 --- a/website/docs/r/discovery_engine_chat_engine.html.markdown +++ b/website/docs/r/discovery_engine_chat_engine.html.markdown @@ -163,6 +163,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `chat_engine_config` block supports: diff --git a/website/docs/r/discovery_engine_cmek_config.html.markdown b/website/docs/r/discovery_engine_cmek_config.html.markdown index e8294f01682..afed1406673 100644 --- a/website/docs/r/discovery_engine_cmek_config.html.markdown +++ b/website/docs/r/discovery_engine_cmek_config.html.markdown @@ -83,6 +83,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `single_region_keys` block supports: diff --git a/website/docs/r/discovery_engine_control.html.markdown b/website/docs/r/discovery_engine_control.html.markdown index 8ec73901ff5..8f4ea4912c3 100644 --- a/website/docs/r/discovery_engine_control.html.markdown +++ b/website/docs/r/discovery_engine_control.html.markdown @@ -145,6 +145,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `conditions` block supports: diff --git a/website/docs/r/discovery_engine_data_connector.html.markdown b/website/docs/r/discovery_engine_data_connector.html.markdown index 22087784048..f78633901b1 100644 --- a/website/docs/r/discovery_engine_data_connector.html.markdown +++ b/website/docs/r/discovery_engine_data_connector.html.markdown @@ -333,6 +333,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `entities` block supports: diff --git a/website/docs/r/discovery_engine_data_store.html.markdown b/website/docs/r/discovery_engine_data_store.html.markdown index bf769c425a4..692b4da3287 100644 --- a/website/docs/r/discovery_engine_data_store.html.markdown +++ b/website/docs/r/discovery_engine_data_store.html.markdown @@ -203,6 +203,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `advanced_site_search_config` block supports: diff --git a/website/docs/r/discovery_engine_license_config.html.markdown b/website/docs/r/discovery_engine_license_config.html.markdown index 068fa0ab6e9..728521a8bd4 100644 --- a/website/docs/r/discovery_engine_license_config.html.markdown +++ b/website/docs/r/discovery_engine_license_config.html.markdown @@ -101,6 +101,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `start_date` block supports: diff --git a/website/docs/r/discovery_engine_recommendation_engine.html.markdown b/website/docs/r/discovery_engine_recommendation_engine.html.markdown index 50601c0e084..a23cc18a61a 100644 --- a/website/docs/r/discovery_engine_recommendation_engine.html.markdown +++ b/website/docs/r/discovery_engine_recommendation_engine.html.markdown @@ -144,6 +144,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `media_recommendation_engine_config` block supports: diff --git a/website/docs/r/discovery_engine_schema.html.markdown b/website/docs/r/discovery_engine_schema.html.markdown index 2e2fc98afeb..190efe86048 100644 --- a/website/docs/r/discovery_engine_schema.html.markdown +++ b/website/docs/r/discovery_engine_schema.html.markdown @@ -84,6 +84,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/discovery_engine_search_engine.html.markdown b/website/docs/r/discovery_engine_search_engine.html.markdown index 685546158d9..0c95ce4ddec 100644 --- a/website/docs/r/discovery_engine_search_engine.html.markdown +++ b/website/docs/r/discovery_engine_search_engine.html.markdown @@ -169,6 +169,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `search_engine_config` block supports: diff --git a/website/docs/r/discovery_engine_serving_config.html.markdown b/website/docs/r/discovery_engine_serving_config.html.markdown index f709c392b3a..7b3c93ae5a4 100644 --- a/website/docs/r/discovery_engine_serving_config.html.markdown +++ b/website/docs/r/discovery_engine_serving_config.html.markdown @@ -75,6 +75,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/discovery_engine_sitemap.html.markdown b/website/docs/r/discovery_engine_sitemap.html.markdown index 9b41d2d3baa..ea9ccc73a60 100644 --- a/website/docs/r/discovery_engine_sitemap.html.markdown +++ b/website/docs/r/discovery_engine_sitemap.html.markdown @@ -79,6 +79,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/discovery_engine_target_site.html.markdown b/website/docs/r/discovery_engine_target_site.html.markdown index 60052fcc7bd..5eb9a1e4ec7 100644 --- a/website/docs/r/discovery_engine_target_site.html.markdown +++ b/website/docs/r/discovery_engine_target_site.html.markdown @@ -124,6 +124,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/discovery_engine_user_store.html.markdown b/website/docs/r/discovery_engine_user_store.html.markdown index 6d618377e8d..a8c3abd3928 100644 --- a/website/docs/r/discovery_engine_user_store.html.markdown +++ b/website/docs/r/discovery_engine_user_store.html.markdown @@ -100,6 +100,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/discovery_engine_widget_config.html.markdown b/website/docs/r/discovery_engine_widget_config.html.markdown index e98303f579b..6fbe2a1fa3b 100644 --- a/website/docs/r/discovery_engine_widget_config.html.markdown +++ b/website/docs/r/discovery_engine_widget_config.html.markdown @@ -129,6 +129,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `access_settings` block supports: diff --git a/website/docs/r/dns_managed_zone.html.markdown b/website/docs/r/dns_managed_zone.html.markdown index 0bfbe508af6..a02bb2aef00 100644 --- a/website/docs/r/dns_managed_zone.html.markdown +++ b/website/docs/r/dns_managed_zone.html.markdown @@ -454,6 +454,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. * `force_destroy` - (Optional) Set this true to delete all records in the zone. diff --git a/website/docs/r/dns_policy.html.markdown b/website/docs/r/dns_policy.html.markdown index 52a96f45e39..d06041463eb 100644 --- a/website/docs/r/dns_policy.html.markdown +++ b/website/docs/r/dns_policy.html.markdown @@ -122,6 +122,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `alternative_name_server_config` block supports: diff --git a/website/docs/r/dns_record_set.html.markdown b/website/docs/r/dns_record_set.html.markdown index 80f745890f8..7f6128294ed 100644 --- a/website/docs/r/dns_record_set.html.markdown +++ b/website/docs/r/dns_record_set.html.markdown @@ -329,6 +329,13 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. + The `routing_policy` block supports: * `wrr` - (Optional) The configuration for Weighted Round Robin based routing policy. diff --git a/website/docs/r/dns_response_policy.html.markdown b/website/docs/r/dns_response_policy.html.markdown index afedd4e47b9..72201fa7174 100644 --- a/website/docs/r/dns_response_policy.html.markdown +++ b/website/docs/r/dns_response_policy.html.markdown @@ -135,6 +135,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `networks` block supports: diff --git a/website/docs/r/dns_response_policy_rule.html.markdown b/website/docs/r/dns_response_policy_rule.html.markdown index b11c265071d..5f56fce428e 100644 --- a/website/docs/r/dns_response_policy_rule.html.markdown +++ b/website/docs/r/dns_response_policy_rule.html.markdown @@ -106,6 +106,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `local_data` block supports: diff --git a/website/docs/r/document_ai_processor.html.markdown b/website/docs/r/document_ai_processor.html.markdown index f277f2dda20..c510f25c841 100644 --- a/website/docs/r/document_ai_processor.html.markdown +++ b/website/docs/r/document_ai_processor.html.markdown @@ -71,6 +71,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/document_ai_processor_default_version.html.markdown b/website/docs/r/document_ai_processor_default_version.html.markdown index 86c02621c69..db37571fe0d 100644 --- a/website/docs/r/document_ai_processor_default_version.html.markdown +++ b/website/docs/r/document_ai_processor_default_version.html.markdown @@ -68,6 +68,12 @@ The following arguments are supported: The processor to set the version on. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/document_ai_schema.html.markdown b/website/docs/r/document_ai_schema.html.markdown index 689e643516d..d74da0c4eaf 100644 --- a/website/docs/r/document_ai_schema.html.markdown +++ b/website/docs/r/document_ai_schema.html.markdown @@ -70,6 +70,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/document_ai_warehouse_document_schema.html.markdown b/website/docs/r/document_ai_warehouse_document_schema.html.markdown index 0f10f360c33..085f2526010 100644 --- a/website/docs/r/document_ai_warehouse_document_schema.html.markdown +++ b/website/docs/r/document_ai_warehouse_document_schema.html.markdown @@ -88,6 +88,12 @@ The following arguments are supported: (Optional) Tells whether the document is a folder or a typical document. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `property_definitions` block supports: diff --git a/website/docs/r/document_ai_warehouse_location.html.markdown b/website/docs/r/document_ai_warehouse_location.html.markdown index a052b50c98a..76f444b8d37 100644 --- a/website/docs/r/document_ai_warehouse_location.html.markdown +++ b/website/docs/r/document_ai_warehouse_location.html.markdown @@ -84,6 +84,12 @@ The following arguments are supported: The default role for the person who create a document. Possible values are: `DOCUMENT_ADMIN`, `DOCUMENT_EDITOR`, `DOCUMENT_VIEWER`. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/edgecontainer_cluster.html.markdown b/website/docs/r/edgecontainer_cluster.html.markdown index f012113f73b..2843edb99ba 100644 --- a/website/docs/r/edgecontainer_cluster.html.markdown +++ b/website/docs/r/edgecontainer_cluster.html.markdown @@ -156,6 +156,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `fleet` block supports: diff --git a/website/docs/r/edgecontainer_node_pool.html.markdown b/website/docs/r/edgecontainer_node_pool.html.markdown index 5b8b0b16d61..b568f6ec54f 100644 --- a/website/docs/r/edgecontainer_node_pool.html.markdown +++ b/website/docs/r/edgecontainer_node_pool.html.markdown @@ -127,6 +127,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `local_disk_encryption` block supports: diff --git a/website/docs/r/edgecontainer_vpn_connection.html.markdown b/website/docs/r/edgecontainer_vpn_connection.html.markdown index 938d600bf7b..b704d8ddfcd 100644 --- a/website/docs/r/edgecontainer_vpn_connection.html.markdown +++ b/website/docs/r/edgecontainer_vpn_connection.html.markdown @@ -132,6 +132,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `vpc_project` block supports: diff --git a/website/docs/r/edgenetwork_interconnect_attachment.html.markdown b/website/docs/r/edgenetwork_interconnect_attachment.html.markdown index bd50f9899b1..abdfd5cd272 100644 --- a/website/docs/r/edgenetwork_interconnect_attachment.html.markdown +++ b/website/docs/r/edgenetwork_interconnect_attachment.html.markdown @@ -107,6 +107,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/edgenetwork_network.html.markdown b/website/docs/r/edgenetwork_network.html.markdown index 8837975150f..2dbdddabb45 100644 --- a/website/docs/r/edgenetwork_network.html.markdown +++ b/website/docs/r/edgenetwork_network.html.markdown @@ -83,6 +83,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/edgenetwork_subnet.html.markdown b/website/docs/r/edgenetwork_subnet.html.markdown index a6993275fe3..f92acadb49c 100644 --- a/website/docs/r/edgenetwork_subnet.html.markdown +++ b/website/docs/r/edgenetwork_subnet.html.markdown @@ -131,6 +131,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/essential_contacts_contact.html.markdown b/website/docs/r/essential_contacts_contact.html.markdown index d50f7838a9b..20ad70a30e2 100644 --- a/website/docs/r/essential_contacts_contact.html.markdown +++ b/website/docs/r/essential_contacts_contact.html.markdown @@ -78,6 +78,12 @@ The following arguments are supported: The resource to save this contact for. Format: organizations/{organization_id}, folders/{folder_id} or projects/{project_id} +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/eventarc_channel.html.markdown b/website/docs/r/eventarc_channel.html.markdown index 6cbb8887003..82efbd8bcea 100644 --- a/website/docs/r/eventarc_channel.html.markdown +++ b/website/docs/r/eventarc_channel.html.markdown @@ -73,6 +73,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/eventarc_enrollment.html.markdown b/website/docs/r/eventarc_enrollment.html.markdown index 19932674db7..523de5b0bf9 100644 --- a/website/docs/r/eventarc_enrollment.html.markdown +++ b/website/docs/r/eventarc_enrollment.html.markdown @@ -111,6 +111,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/eventarc_google_api_source.html.markdown b/website/docs/r/eventarc_google_api_source.html.markdown index 6e14881a63d..7956371122e 100644 --- a/website/docs/r/eventarc_google_api_source.html.markdown +++ b/website/docs/r/eventarc_google_api_source.html.markdown @@ -121,6 +121,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `logging_config` block supports: diff --git a/website/docs/r/eventarc_google_channel_config.html.markdown b/website/docs/r/eventarc_google_channel_config.html.markdown index 779fae752f5..8746845419c 100644 --- a/website/docs/r/eventarc_google_channel_config.html.markdown +++ b/website/docs/r/eventarc_google_channel_config.html.markdown @@ -83,6 +83,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/eventarc_message_bus.html.markdown b/website/docs/r/eventarc_message_bus.html.markdown index 962b6a8d7b7..72e0ef72982 100644 --- a/website/docs/r/eventarc_message_bus.html.markdown +++ b/website/docs/r/eventarc_message_bus.html.markdown @@ -109,6 +109,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `logging_config` block supports: diff --git a/website/docs/r/eventarc_pipeline.html.markdown b/website/docs/r/eventarc_pipeline.html.markdown index 84f6caad263..2ac3171f28e 100644 --- a/website/docs/r/eventarc_pipeline.html.markdown +++ b/website/docs/r/eventarc_pipeline.html.markdown @@ -356,6 +356,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `destinations` block supports: diff --git a/website/docs/r/eventarc_trigger.html.markdown b/website/docs/r/eventarc_trigger.html.markdown index 8cd29f0872e..9d5ac1a61a1 100644 --- a/website/docs/r/eventarc_trigger.html.markdown +++ b/website/docs/r/eventarc_trigger.html.markdown @@ -149,6 +149,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `matching_criteria` block supports: diff --git a/website/docs/r/filestore_backup.html.markdown b/website/docs/r/filestore_backup.html.markdown index fb9dcca888e..ac3b0946415 100644 --- a/website/docs/r/filestore_backup.html.markdown +++ b/website/docs/r/filestore_backup.html.markdown @@ -120,6 +120,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/filestore_instance.html.markdown b/website/docs/r/filestore_instance.html.markdown index 1c1f1414659..8549154ec40 100644 --- a/website/docs/r/filestore_instance.html.markdown +++ b/website/docs/r/filestore_instance.html.markdown @@ -259,6 +259,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. * `desired_replica_state` - (Optional) The desired_replica_state field controls the state of a replica. Terraform will attempt to make the actual state of the replica match the desired state. diff --git a/website/docs/r/filestore_snapshot.html.markdown b/website/docs/r/filestore_snapshot.html.markdown index 40f849fa7ff..1abab1c7957 100644 --- a/website/docs/r/filestore_snapshot.html.markdown +++ b/website/docs/r/filestore_snapshot.html.markdown @@ -138,6 +138,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/firebase_ai_logic_config.html.markdown b/website/docs/r/firebase_ai_logic_config.html.markdown index 9cacbf71b1a..e18ebf1f74d 100644 --- a/website/docs/r/firebase_ai_logic_config.html.markdown +++ b/website/docs/r/firebase_ai_logic_config.html.markdown @@ -206,6 +206,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `generative_language_config` block supports: diff --git a/website/docs/r/firebase_ai_logic_prompt_template.html.markdown b/website/docs/r/firebase_ai_logic_prompt_template.html.markdown index db1ebb5f653..572b6e4db33 100644 --- a/website/docs/r/firebase_ai_logic_prompt_template.html.markdown +++ b/website/docs/r/firebase_ai_logic_prompt_template.html.markdown @@ -98,6 +98,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/firebase_ai_logic_prompt_template_lock.html.markdown b/website/docs/r/firebase_ai_logic_prompt_template_lock.html.markdown index 02630fd5713..e4d28b22d05 100644 --- a/website/docs/r/firebase_ai_logic_prompt_template_lock.html.markdown +++ b/website/docs/r/firebase_ai_logic_prompt_template_lock.html.markdown @@ -69,6 +69,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/firebase_android_app.html.markdown b/website/docs/r/firebase_android_app.html.markdown index 1a0c7a44148..8eeb0adb27b 100644 --- a/website/docs/r/firebase_android_app.html.markdown +++ b/website/docs/r/firebase_android_app.html.markdown @@ -109,10 +109,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. -* `deletion_policy` - (Optional) (Optional) Set to `ABANDON` to allow the AndroidApp to be untracked from terraform state -rather than deleted upon `terraform destroy`. This is useful because the AndroidApp may be -serving traffic. Set to `DELETE` to delete the AndroidApp. Defaults to `DELETE`. - +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/firebase_app_check_app_attest_config.html.markdown b/website/docs/r/firebase_app_check_app_attest_config.html.markdown index cefa2ab39ad..d2505e76062 100644 --- a/website/docs/r/firebase_app_check_app_attest_config.html.markdown +++ b/website/docs/r/firebase_app_check_app_attest_config.html.markdown @@ -125,6 +125,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/firebase_app_check_debug_token.html.markdown b/website/docs/r/firebase_app_check_debug_token.html.markdown index 78de4c02de8..90acb4b8957 100644 --- a/website/docs/r/firebase_app_check_debug_token.html.markdown +++ b/website/docs/r/firebase_app_check_debug_token.html.markdown @@ -98,6 +98,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/firebase_app_check_device_check_config.html.markdown b/website/docs/r/firebase_app_check_device_check_config.html.markdown index 2853c4dcc6b..ce3f3a953ac 100644 --- a/website/docs/r/firebase_app_check_device_check_config.html.markdown +++ b/website/docs/r/firebase_app_check_device_check_config.html.markdown @@ -104,6 +104,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/firebase_app_check_play_integrity_config.html.markdown b/website/docs/r/firebase_app_check_play_integrity_config.html.markdown index 998ec05fb30..7ed3f532744 100644 --- a/website/docs/r/firebase_app_check_play_integrity_config.html.markdown +++ b/website/docs/r/firebase_app_check_play_integrity_config.html.markdown @@ -145,6 +145,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/firebase_app_check_recaptcha_enterprise_config.html.markdown b/website/docs/r/firebase_app_check_recaptcha_enterprise_config.html.markdown index 2e83abd57e4..6ad0f959521 100644 --- a/website/docs/r/firebase_app_check_recaptcha_enterprise_config.html.markdown +++ b/website/docs/r/firebase_app_check_recaptcha_enterprise_config.html.markdown @@ -93,6 +93,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/firebase_app_check_recaptcha_v3_config.html.markdown b/website/docs/r/firebase_app_check_recaptcha_v3_config.html.markdown index 9edd659126c..28788a8f716 100644 --- a/website/docs/r/firebase_app_check_recaptcha_v3_config.html.markdown +++ b/website/docs/r/firebase_app_check_recaptcha_v3_config.html.markdown @@ -90,6 +90,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/firebase_app_check_resource_policy.html.markdown b/website/docs/r/firebase_app_check_resource_policy.html.markdown index 1bf3fec2a66..2e1c229faa0 100644 --- a/website/docs/r/firebase_app_check_resource_policy.html.markdown +++ b/website/docs/r/firebase_app_check_resource_policy.html.markdown @@ -100,6 +100,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/firebase_app_check_service_config.html.markdown b/website/docs/r/firebase_app_check_service_config.html.markdown index d58f32fa3bc..344f6c8254d 100644 --- a/website/docs/r/firebase_app_check_service_config.html.markdown +++ b/website/docs/r/firebase_app_check_service_config.html.markdown @@ -127,6 +127,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/firebase_app_hosting_backend.html.markdown b/website/docs/r/firebase_app_hosting_backend.html.markdown index 7d53cc50324..e919a7de720 100644 --- a/website/docs/r/firebase_app_hosting_backend.html.markdown +++ b/website/docs/r/firebase_app_hosting_backend.html.markdown @@ -276,6 +276,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `codebase` block supports: diff --git a/website/docs/r/firebase_app_hosting_build.html.markdown b/website/docs/r/firebase_app_hosting_build.html.markdown index 0e46c048ce1..d6b8ce5e5b4 100644 --- a/website/docs/r/firebase_app_hosting_build.html.markdown +++ b/website/docs/r/firebase_app_hosting_build.html.markdown @@ -273,6 +273,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `source` block supports: diff --git a/website/docs/r/firebase_app_hosting_default_domain.html.markdown b/website/docs/r/firebase_app_hosting_default_domain.html.markdown index 9b08ab35f62..b9633adff68 100644 --- a/website/docs/r/firebase_app_hosting_default_domain.html.markdown +++ b/website/docs/r/firebase_app_hosting_default_domain.html.markdown @@ -154,6 +154,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/firebase_app_hosting_domain.html.markdown b/website/docs/r/firebase_app_hosting_domain.html.markdown index 509e402e6f2..d798bd000b3 100644 --- a/website/docs/r/firebase_app_hosting_domain.html.markdown +++ b/website/docs/r/firebase_app_hosting_domain.html.markdown @@ -127,6 +127,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `serve` block supports: diff --git a/website/docs/r/firebase_app_hosting_traffic.html.markdown b/website/docs/r/firebase_app_hosting_traffic.html.markdown index da794297076..83354399fe9 100644 --- a/website/docs/r/firebase_app_hosting_traffic.html.markdown +++ b/website/docs/r/firebase_app_hosting_traffic.html.markdown @@ -231,6 +231,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `target` block supports: diff --git a/website/docs/r/firebase_apple_app.html.markdown b/website/docs/r/firebase_apple_app.html.markdown index c602f0f7c5c..c35ca540435 100644 --- a/website/docs/r/firebase_apple_app.html.markdown +++ b/website/docs/r/firebase_apple_app.html.markdown @@ -103,10 +103,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. -* `deletion_policy` - (Optional) (Optional) Set to `ABANDON` to allow the Apple to be untracked from terraform state -rather than deleted upon `terraform destroy`. This is useful because the Apple may be -serving traffic. Set to `DELETE` to delete the Apple. Defaults to `DELETE`. - +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/firebase_data_connect_service.html.markdown b/website/docs/r/firebase_data_connect_service.html.markdown index 289362e52b0..8e13574f8b4 100644 --- a/website/docs/r/firebase_data_connect_service.html.markdown +++ b/website/docs/r/firebase_data_connect_service.html.markdown @@ -118,7 +118,14 @@ The following arguments are supported: Service to be deleted even if a Schema or Connector is present. By default, the Service deletion will only succeed when no Schema or Connectors are present. -Possible values: DEFAULT, FORCE + +When a 'terraform destroy' or 'terraform apply' would delete the resource, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", the command will behave as if set to "DEFAULT". + +Possible values: DEFAULT, FORCE, PREVENT, ABANDON, DELETE ## Attributes Reference diff --git a/website/docs/r/firebase_database_instance.html.markdown b/website/docs/r/firebase_database_instance.html.markdown index e33459ea908..d0eefabc9e8 100644 --- a/website/docs/r/firebase_database_instance.html.markdown +++ b/website/docs/r/firebase_database_instance.html.markdown @@ -133,6 +133,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. * `desired_state` - (Optional) The intended database state. Possible values: ACTIVE, DISABLED. diff --git a/website/docs/r/firebase_extensions_instance.html.markdown b/website/docs/r/firebase_extensions_instance.html.markdown index 2a9fc518b66..ca14c1592eb 100644 --- a/website/docs/r/firebase_extensions_instance.html.markdown +++ b/website/docs/r/firebase_extensions_instance.html.markdown @@ -104,6 +104,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `config` block supports: diff --git a/website/docs/r/firebase_hosting_channel.html.markdown b/website/docs/r/firebase_hosting_channel.html.markdown index 904d9c70261..2e0242b3d73 100644 --- a/website/docs/r/firebase_hosting_channel.html.markdown +++ b/website/docs/r/firebase_hosting_channel.html.markdown @@ -109,6 +109,12 @@ The following arguments are supported: duration past the time of the request. A duration in seconds with up to nine fractional digits, terminated by 's'. Example: "86400s" (one day). +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/firebase_hosting_custom_domain.html.markdown b/website/docs/r/firebase_hosting_custom_domain.html.markdown index 6869221c923..953149f119e 100644 --- a/website/docs/r/firebase_hosting_custom_domain.html.markdown +++ b/website/docs/r/firebase_hosting_custom_domain.html.markdown @@ -160,6 +160,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. * `wait_dns_verification` - (Optional) If true, Terraform will wait for DNS records to be fully resolved on the `CustomDomain`. If false, Terraform will not wait for DNS records on the `CustomDomain`. Any issues in the `CustomDomain` will be returned and stored in the Terraform state. diff --git a/website/docs/r/firebase_hosting_release.html.markdown b/website/docs/r/firebase_hosting_release.html.markdown index a1c5d9b6600..6e545b00fba 100644 --- a/website/docs/r/firebase_hosting_release.html.markdown +++ b/website/docs/r/firebase_hosting_release.html.markdown @@ -150,6 +150,12 @@ The following arguments are supported: The Version must belong to the same site as in the `site_id`. This parameter must be empty if the `type` of the release is `SITE_DISABLE`. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/firebase_hosting_site.html.markdown b/website/docs/r/firebase_hosting_site.html.markdown index c54c80ee18a..8b0f0f8eec2 100644 --- a/website/docs/r/firebase_hosting_site.html.markdown +++ b/website/docs/r/firebase_hosting_site.html.markdown @@ -90,6 +90,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/firebase_hosting_version.html.markdown b/website/docs/r/firebase_hosting_version.html.markdown index 61167b1fd8c..71184b5a965 100644 --- a/website/docs/r/firebase_hosting_version.html.markdown +++ b/website/docs/r/firebase_hosting_version.html.markdown @@ -285,6 +285,12 @@ The following arguments are supported: The configuration for the behavior of the site. This configuration exists in the `firebase.json` file. Structure is [documented below](#nested_config). +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `config` block supports: diff --git a/website/docs/r/firebase_project.html.markdown b/website/docs/r/firebase_project.html.markdown index 795933a65a6..53205fbf353 100644 --- a/website/docs/r/firebase_project.html.markdown +++ b/website/docs/r/firebase_project.html.markdown @@ -71,6 +71,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/firebase_remote_config_remote_config.html.markdown b/website/docs/r/firebase_remote_config_remote_config.html.markdown index 832b9ff997a..77f837bfbdf 100644 --- a/website/docs/r/firebase_remote_config_remote_config.html.markdown +++ b/website/docs/r/firebase_remote_config_remote_config.html.markdown @@ -108,6 +108,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `conditions` block supports: diff --git a/website/docs/r/firebase_storage_bucket.html.markdown b/website/docs/r/firebase_storage_bucket.html.markdown index 53ba8f5bdf5..8eb7878cfb5 100644 --- a/website/docs/r/firebase_storage_bucket.html.markdown +++ b/website/docs/r/firebase_storage_bucket.html.markdown @@ -64,6 +64,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/firebase_storage_default_bucket.html.markdown b/website/docs/r/firebase_storage_default_bucket.html.markdown index 3767b7b50f5..8e1b5509a07 100644 --- a/website/docs/r/firebase_storage_default_bucket.html.markdown +++ b/website/docs/r/firebase_storage_default_bucket.html.markdown @@ -58,6 +58,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/firebase_web_app.html.markdown b/website/docs/r/firebase_web_app.html.markdown index e604876b531..1e58edadf63 100644 --- a/website/docs/r/firebase_web_app.html.markdown +++ b/website/docs/r/firebase_web_app.html.markdown @@ -114,10 +114,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. -* `deletion_policy` - (Optional) Set to `ABANDON` to allow the WebApp to be untracked from terraform state -rather than deleted upon `terraform destroy`. This is useful becaue the WebApp may be -serving traffic. Set to `DELETE` to delete the WebApp. Default to `DELETE` - +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/firebaserules_release.html.markdown b/website/docs/r/firebaserules_release.html.markdown index e8211d39406..6a9765bf6db 100644 --- a/website/docs/r/firebaserules_release.html.markdown +++ b/website/docs/r/firebaserules_release.html.markdown @@ -134,7 +134,13 @@ The following arguments are supported: * `project` - (Optional) The project for the resource - + +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/firebaserules_ruleset.html.markdown b/website/docs/r/firebaserules_ruleset.html.markdown index 82cc3ba8f0c..db399955908 100644 --- a/website/docs/r/firebaserules_ruleset.html.markdown +++ b/website/docs/r/firebaserules_ruleset.html.markdown @@ -85,7 +85,13 @@ The `source` block supports: * `project` - (Optional) The project for the resource - + +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `files` block supports: diff --git a/website/docs/r/firestore_backup_schedule.html.markdown b/website/docs/r/firestore_backup_schedule.html.markdown index 86e4cf9d558..4d7a5c67085 100644 --- a/website/docs/r/firestore_backup_schedule.html.markdown +++ b/website/docs/r/firestore_backup_schedule.html.markdown @@ -114,6 +114,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `weekly_recurrence` block supports: diff --git a/website/docs/r/firestore_database.html.markdown b/website/docs/r/firestore_database.html.markdown index 5742aec78d4..5b54e563665 100644 --- a/website/docs/r/firestore_database.html.markdown +++ b/website/docs/r/firestore_database.html.markdown @@ -325,12 +325,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. -* `deletion_policy` - (Optional) Deletion behavior for this database. -If the deletion policy is `ABANDON`, the database will be removed from Terraform state but not deleted from Google Cloud upon destruction. -If the deletion policy is `DELETE`, the database will both be removed from Terraform state and deleted from Google Cloud upon destruction. -The default value is `ABANDON`. -See also `delete_protection`. - +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to ABANDON. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `cmek_config` block supports: diff --git a/website/docs/r/firestore_document.html.markdown b/website/docs/r/firestore_document.html.markdown index fa66508eef5..4471de7e287 100644 --- a/website/docs/r/firestore_document.html.markdown +++ b/website/docs/r/firestore_document.html.markdown @@ -166,6 +166,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/firestore_field.html.markdown b/website/docs/r/firestore_field.html.markdown index 88d4113c9ec..1cc808809ef 100644 --- a/website/docs/r/firestore_field.html.markdown +++ b/website/docs/r/firestore_field.html.markdown @@ -194,6 +194,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `index_config` block supports: diff --git a/website/docs/r/firestore_index.html.markdown b/website/docs/r/firestore_index.html.markdown index 3c396813d82..2141851d55c 100644 --- a/website/docs/r/firestore_index.html.markdown +++ b/website/docs/r/firestore_index.html.markdown @@ -498,12 +498,13 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. * `skip_wait` - (Optional) Whether to skip waiting for the index to be created. -* `deletion_policy` - (Optional) Deletion behavior for this index. -If the deletion policy is `PREVENT`, the index cannot be deleted and a terraform destroy will fail. -If the deletion policy is `DELETE`, the index will both be removed from Terraform state and deleted from Google Cloud upon destruction. -The default value is `DELETE`. - The `fields` block supports: diff --git a/website/docs/r/firestore_user_creds.html.markdown b/website/docs/r/firestore_user_creds.html.markdown index eda5dce257b..a7b6c643995 100644 --- a/website/docs/r/firestore_user_creds.html.markdown +++ b/website/docs/r/firestore_user_creds.html.markdown @@ -113,6 +113,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/folder_access_approval_settings.html.markdown b/website/docs/r/folder_access_approval_settings.html.markdown index 772e7ac2239..ab4f46b7728 100644 --- a/website/docs/r/folder_access_approval_settings.html.markdown +++ b/website/docs/r/folder_access_approval_settings.html.markdown @@ -136,6 +136,12 @@ The following arguments are supported: Empty active_key_version indicates that a Google-managed key should be used for signing. This property will be ignored if set by an ancestor of the resource, and new non-empty values may not be set. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `enrolled_services` block supports: diff --git a/website/docs/r/gemini_code_repository_index.html.markdown b/website/docs/r/gemini_code_repository_index.html.markdown index d75ce496a60..9626e2d7563 100644 --- a/website/docs/r/gemini_code_repository_index.html.markdown +++ b/website/docs/r/gemini_code_repository_index.html.markdown @@ -69,6 +69,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. * `force_destroy` - (Optional) If set to true, will allow deletion of the CodeRepositoryIndex even if there are existing RepositoryGroups for the resource. These RepositoryGroups will also be deleted. diff --git a/website/docs/r/gemini_code_tools_setting.html.markdown b/website/docs/r/gemini_code_tools_setting.html.markdown index cce67e625f7..9f328b41bc9 100644 --- a/website/docs/r/gemini_code_tools_setting.html.markdown +++ b/website/docs/r/gemini_code_tools_setting.html.markdown @@ -74,6 +74,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `enabled_tool` block supports: diff --git a/website/docs/r/gemini_code_tools_setting_binding.html.markdown b/website/docs/r/gemini_code_tools_setting_binding.html.markdown index c1b0afdfbe6..b64a533bc54 100644 --- a/website/docs/r/gemini_code_tools_setting_binding.html.markdown +++ b/website/docs/r/gemini_code_tools_setting_binding.html.markdown @@ -92,6 +92,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/gemini_data_sharing_with_google_setting.html.markdown b/website/docs/r/gemini_data_sharing_with_google_setting.html.markdown index a911fc800e3..8895fa04c5b 100644 --- a/website/docs/r/gemini_data_sharing_with_google_setting.html.markdown +++ b/website/docs/r/gemini_data_sharing_with_google_setting.html.markdown @@ -69,6 +69,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/gemini_data_sharing_with_google_setting_binding.html.markdown b/website/docs/r/gemini_data_sharing_with_google_setting_binding.html.markdown index 9637fe4f569..c6f0713910c 100644 --- a/website/docs/r/gemini_data_sharing_with_google_setting_binding.html.markdown +++ b/website/docs/r/gemini_data_sharing_with_google_setting_binding.html.markdown @@ -83,6 +83,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/gemini_gemini_gcp_enablement_setting.html.markdown b/website/docs/r/gemini_gemini_gcp_enablement_setting.html.markdown index bd6883d1f15..231c1150e2b 100644 --- a/website/docs/r/gemini_gemini_gcp_enablement_setting.html.markdown +++ b/website/docs/r/gemini_gemini_gcp_enablement_setting.html.markdown @@ -83,6 +83,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/gemini_gemini_gcp_enablement_setting_binding.html.markdown b/website/docs/r/gemini_gemini_gcp_enablement_setting_binding.html.markdown index 768126abd9b..7d29c7a0724 100644 --- a/website/docs/r/gemini_gemini_gcp_enablement_setting_binding.html.markdown +++ b/website/docs/r/gemini_gemini_gcp_enablement_setting_binding.html.markdown @@ -83,6 +83,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/gemini_logging_setting.html.markdown b/website/docs/r/gemini_logging_setting.html.markdown index b8ff6e06a5f..014cc40a52b 100644 --- a/website/docs/r/gemini_logging_setting.html.markdown +++ b/website/docs/r/gemini_logging_setting.html.markdown @@ -74,6 +74,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/gemini_logging_setting_binding.html.markdown b/website/docs/r/gemini_logging_setting_binding.html.markdown index 25ba6ad3de5..2ddbbb1d157 100644 --- a/website/docs/r/gemini_logging_setting_binding.html.markdown +++ b/website/docs/r/gemini_logging_setting_binding.html.markdown @@ -83,6 +83,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/gemini_release_channel_setting.html.markdown b/website/docs/r/gemini_release_channel_setting.html.markdown index 5c71523a0e9..9e60bdb8539 100644 --- a/website/docs/r/gemini_release_channel_setting.html.markdown +++ b/website/docs/r/gemini_release_channel_setting.html.markdown @@ -72,6 +72,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/gemini_release_channel_setting_binding.html.markdown b/website/docs/r/gemini_release_channel_setting_binding.html.markdown index 8f7b991da60..aab36656777 100644 --- a/website/docs/r/gemini_release_channel_setting_binding.html.markdown +++ b/website/docs/r/gemini_release_channel_setting_binding.html.markdown @@ -83,6 +83,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/gemini_repository_group.html.markdown b/website/docs/r/gemini_repository_group.html.markdown index d4c9675d2ef..b01cb2a6a9b 100644 --- a/website/docs/r/gemini_repository_group.html.markdown +++ b/website/docs/r/gemini_repository_group.html.markdown @@ -76,6 +76,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `repositories` block supports: diff --git a/website/docs/r/gke_backup_backup_channel.html.markdown b/website/docs/r/gke_backup_backup_channel.html.markdown index fc54aa7620f..2f5ffc63fcf 100644 --- a/website/docs/r/gke_backup_backup_channel.html.markdown +++ b/website/docs/r/gke_backup_backup_channel.html.markdown @@ -82,6 +82,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/gke_backup_backup_plan.html.markdown b/website/docs/r/gke_backup_backup_plan.html.markdown index 993ea3b9973..c741d0810c8 100644 --- a/website/docs/r/gke_backup_backup_plan.html.markdown +++ b/website/docs/r/gke_backup_backup_plan.html.markdown @@ -477,6 +477,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `retention_policy` block supports: diff --git a/website/docs/r/gke_backup_restore_channel.html.markdown b/website/docs/r/gke_backup_restore_channel.html.markdown index f4ec0dd0dab..7770da34def 100644 --- a/website/docs/r/gke_backup_restore_channel.html.markdown +++ b/website/docs/r/gke_backup_restore_channel.html.markdown @@ -82,6 +82,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/gke_backup_restore_plan.html.markdown b/website/docs/r/gke_backup_restore_plan.html.markdown index a9166d9fa5f..373867a25b9 100644 --- a/website/docs/r/gke_backup_restore_plan.html.markdown +++ b/website/docs/r/gke_backup_restore_plan.html.markdown @@ -595,6 +595,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `restore_config` block supports: diff --git a/website/docs/r/gke_hub_feature.html.markdown b/website/docs/r/gke_hub_feature.html.markdown index 30f0edff520..b446a14a60d 100644 --- a/website/docs/r/gke_hub_feature.html.markdown +++ b/website/docs/r/gke_hub_feature.html.markdown @@ -370,6 +370,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `spec` block supports: diff --git a/website/docs/r/gke_hub_feature_membership.html.markdown b/website/docs/r/gke_hub_feature_membership.html.markdown index fd0df46bbb7..a2b0a308d60 100644 --- a/website/docs/r/gke_hub_feature_membership.html.markdown +++ b/website/docs/r/gke_hub_feature_membership.html.markdown @@ -372,6 +372,13 @@ The following arguments are supported: * `project` - (Optional) The project of the feature + +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. diff --git a/website/docs/r/gke_hub_fleet.html.markdown b/website/docs/r/gke_hub_fleet.html.markdown index 28fe2ed97a7..22f21d4af0a 100644 --- a/website/docs/r/gke_hub_fleet.html.markdown +++ b/website/docs/r/gke_hub_fleet.html.markdown @@ -64,6 +64,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `default_cluster_config` block supports: diff --git a/website/docs/r/gke_hub_membership.html.markdown b/website/docs/r/gke_hub_membership.html.markdown index 483aa88b5cc..3bfcd71cb72 100644 --- a/website/docs/r/gke_hub_membership.html.markdown +++ b/website/docs/r/gke_hub_membership.html.markdown @@ -150,6 +150,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `endpoint` block supports: diff --git a/website/docs/r/gke_hub_membership_binding.html.markdown b/website/docs/r/gke_hub_membership_binding.html.markdown index 239ae196cc1..cd97bbd1191 100644 --- a/website/docs/r/gke_hub_membership_binding.html.markdown +++ b/website/docs/r/gke_hub_membership_binding.html.markdown @@ -108,6 +108,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/gke_hub_membership_rbac_role_binding.html.markdown b/website/docs/r/gke_hub_membership_rbac_role_binding.html.markdown index c3c85dbe92c..1977f146395 100644 --- a/website/docs/r/gke_hub_membership_rbac_role_binding.html.markdown +++ b/website/docs/r/gke_hub_membership_rbac_role_binding.html.markdown @@ -108,6 +108,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `role` block supports: diff --git a/website/docs/r/gke_hub_namespace.html.markdown b/website/docs/r/gke_hub_namespace.html.markdown index e1b45121a8c..1b9f4b530d4 100644 --- a/website/docs/r/gke_hub_namespace.html.markdown +++ b/website/docs/r/gke_hub_namespace.html.markdown @@ -93,6 +93,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/gke_hub_rollout_sequence.html.markdown b/website/docs/r/gke_hub_rollout_sequence.html.markdown index 8b5b311aabd..33e54b05379 100644 --- a/website/docs/r/gke_hub_rollout_sequence.html.markdown +++ b/website/docs/r/gke_hub_rollout_sequence.html.markdown @@ -72,6 +72,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `stages` block supports: diff --git a/website/docs/r/gke_hub_scope.html.markdown b/website/docs/r/gke_hub_scope.html.markdown index c3df95996c9..36116371118 100644 --- a/website/docs/r/gke_hub_scope.html.markdown +++ b/website/docs/r/gke_hub_scope.html.markdown @@ -77,6 +77,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/gke_hub_scope_rbac_role_binding.html.markdown b/website/docs/r/gke_hub_scope_rbac_role_binding.html.markdown index 80df4a3321b..ab5f80b1347 100644 --- a/website/docs/r/gke_hub_scope_rbac_role_binding.html.markdown +++ b/website/docs/r/gke_hub_scope_rbac_role_binding.html.markdown @@ -124,6 +124,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `role` block supports: diff --git a/website/docs/r/gkeonprem_bare_metal_admin_cluster.html.markdown b/website/docs/r/gkeonprem_bare_metal_admin_cluster.html.markdown index f42cb07a892..918589c2bbd 100644 --- a/website/docs/r/gkeonprem_bare_metal_admin_cluster.html.markdown +++ b/website/docs/r/gkeonprem_bare_metal_admin_cluster.html.markdown @@ -322,6 +322,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `network_config` block supports: diff --git a/website/docs/r/gkeonprem_bare_metal_cluster.html.markdown b/website/docs/r/gkeonprem_bare_metal_cluster.html.markdown index 8d3cc24d523..959ba5e1b31 100644 --- a/website/docs/r/gkeonprem_bare_metal_cluster.html.markdown +++ b/website/docs/r/gkeonprem_bare_metal_cluster.html.markdown @@ -417,6 +417,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `network_config` block supports: diff --git a/website/docs/r/gkeonprem_bare_metal_node_pool.html.markdown b/website/docs/r/gkeonprem_bare_metal_node_pool.html.markdown index fa7e845059f..16c22f76f7a 100644 --- a/website/docs/r/gkeonprem_bare_metal_node_pool.html.markdown +++ b/website/docs/r/gkeonprem_bare_metal_node_pool.html.markdown @@ -254,6 +254,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `node_pool_config` block supports: diff --git a/website/docs/r/gkeonprem_vmware_admin_cluster.html.markdown b/website/docs/r/gkeonprem_vmware_admin_cluster.html.markdown index 6f6958dd1b4..db801a7a3fa 100644 --- a/website/docs/r/gkeonprem_vmware_admin_cluster.html.markdown +++ b/website/docs/r/gkeonprem_vmware_admin_cluster.html.markdown @@ -337,6 +337,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `network_config` block supports: diff --git a/website/docs/r/gkeonprem_vmware_cluster.html.markdown b/website/docs/r/gkeonprem_vmware_cluster.html.markdown index 7af53441f5f..9da0bb904a8 100644 --- a/website/docs/r/gkeonprem_vmware_cluster.html.markdown +++ b/website/docs/r/gkeonprem_vmware_cluster.html.markdown @@ -362,6 +362,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `control_plane_node` block supports: diff --git a/website/docs/r/gkeonprem_vmware_node_pool.html.markdown b/website/docs/r/gkeonprem_vmware_node_pool.html.markdown index 50d58adfe63..a151e2544bf 100644 --- a/website/docs/r/gkeonprem_vmware_node_pool.html.markdown +++ b/website/docs/r/gkeonprem_vmware_node_pool.html.markdown @@ -220,6 +220,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `config` block supports: diff --git a/website/docs/r/google_billing_subaccount.html.markdown b/website/docs/r/google_billing_subaccount.html.markdown index a9a1871e62e..e6625e02256 100644 --- a/website/docs/r/google_billing_subaccount.html.markdown +++ b/website/docs/r/google_billing_subaccount.html.markdown @@ -40,7 +40,13 @@ resource "google_billing_subaccount" "subaccount" { * `deletion_policy` (Optional) - If set to "RENAME_ON_DESTROY" the billing account display_name will be changed to "Terraform Destroyed" along with a timestamp. If set to "" this will not occur. - Default is "". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", the command will behave as if set to "". + + Possible values: RENAME_ON_DESTROY, PREVENT, ABANDON, DELETE. ## Attributes Reference diff --git a/website/docs/r/google_folder.html.markdown b/website/docs/r/google_folder.html.markdown index 56961f9af7f..f570a1a7785 100644 --- a/website/docs/r/google_folder.html.markdown +++ b/website/docs/r/google_folder.html.markdown @@ -73,6 +73,13 @@ The following arguments are supported: * `tags` - (Optional) A map of resource manager tags. Resource manager tag keys and values have the same definition as resource manager tags. Keys must be in the format tagKeys/{tag_key_id}, and values are in the format tagValues/456. The field is ignored when empty. The field is immutable and causes resource replacement when mutated. This field is only set at create time and modifying this field after creation will trigger recreation. To apply tags to an existing resource, see the `google_tags_tag_value` resource. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. + ## Attributes Reference In addition to the arguments listed above, the following computed attributes are diff --git a/website/docs/r/google_folder_organization_policy.html.markdown b/website/docs/r/google_folder_organization_policy.html.markdown index ed78516ad78..1d7eda2922a 100644 --- a/website/docs/r/google_folder_organization_policy.html.markdown +++ b/website/docs/r/google_folder_organization_policy.html.markdown @@ -114,6 +114,13 @@ can also be used to allow or deny all values. Structure is [documented below](#n ~> **Note:** If none of [`boolean_policy`, `list_policy`, `restore_policy`] are defined the policy for a given constraint will effectively be unset. This is represented in the UI as the constraint being 'Inherited'. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. + - - - The `boolean_policy` block supports: diff --git a/website/docs/r/google_organization_iam_custom_role.html.markdown b/website/docs/r/google_organization_iam_custom_role.html.markdown index 24eafc97161..9350706d7fa 100644 --- a/website/docs/r/google_organization_iam_custom_role.html.markdown +++ b/website/docs/r/google_organization_iam_custom_role.html.markdown @@ -64,6 +64,13 @@ The following arguments are supported: * `description` - (Optional) A human-readable description for the role. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. + ## Attributes Reference In addition to the arguments listed above, the following computed attributes are diff --git a/website/docs/r/google_organization_policy.html.markdown b/website/docs/r/google_organization_policy.html.markdown index 1e1672980c8..5864d8ff2f0 100644 --- a/website/docs/r/google_organization_policy.html.markdown +++ b/website/docs/r/google_organization_policy.html.markdown @@ -113,6 +113,13 @@ below](#nested_boolean_policy). ~> **Note:** If none of [`boolean_policy`, `list_policy`, `restore_policy`] are defined the policy for a given constraint will effectively be unset. This is represented in the UI as the constraint being 'Inherited'. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. + - - - The `boolean_policy` block supports: diff --git a/website/docs/r/google_project_iam_custom_role.html.markdown b/website/docs/r/google_project_iam_custom_role.html.markdown index 602e15c69f2..822312ea108 100644 --- a/website/docs/r/google_project_iam_custom_role.html.markdown +++ b/website/docs/r/google_project_iam_custom_role.html.markdown @@ -64,6 +64,13 @@ The following arguments are supported: * `description` - (Optional) A human-readable description for the role. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. + ## Attributes Reference In addition to the arguments listed above, the following computed attributes are diff --git a/website/docs/r/google_project_iam_member_remove.html.markdown b/website/docs/r/google_project_iam_member_remove.html.markdown index ce820a091ae..c4de9845e90 100644 --- a/website/docs/r/google_project_iam_member_remove.html.markdown +++ b/website/docs/r/google_project_iam_member_remove.html.markdown @@ -67,3 +67,10 @@ The following arguments are supported: * **group:{emailid}**: An email address that represents a Google group. For example, admins@example.com. * **domain:{domain}**: A G Suite domain (primary, instead of alias) name that represents all the users of that domain. For example, google.com or example.com. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. + diff --git a/website/docs/r/google_project_organization_policy.html.markdown b/website/docs/r/google_project_organization_policy.html.markdown index dd2719316eb..ecfa5d8715b 100644 --- a/website/docs/r/google_project_organization_policy.html.markdown +++ b/website/docs/r/google_project_organization_policy.html.markdown @@ -113,6 +113,13 @@ The following arguments are supported: ~> **Note:** If none of [`boolean_policy`, `list_policy`, `restore_policy`] are defined the policy for a given constraint will effectively be unset. This is represented in the UI as the constraint being 'Inherited'. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. + - - - The `boolean_policy` block supports: diff --git a/website/docs/r/google_project_service.html.markdown b/website/docs/r/google_project_service.html.markdown index 79f96126c7d..e86d8677098 100644 --- a/website/docs/r/google_project_service.html.markdown +++ b/website/docs/r/google_project_service.html.markdown @@ -74,6 +74,13 @@ services depend on this service when attempting to destroy it. If `true`, the usage of the service to be disabled will be checked and an error will be returned if the service to be disabled has usage in last 30 days. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. + ## Attributes Reference In addition to the arguments listed above, the following computed attributes are diff --git a/website/docs/r/google_service_account.html.markdown b/website/docs/r/google_service_account.html.markdown index 96767f8b9ab..c40cde5c428 100644 --- a/website/docs/r/google_service_account.html.markdown +++ b/website/docs/r/google_service_account.html.markdown @@ -67,6 +67,13 @@ The following arguments are supported: * `create_ignore_already_exists` - (Optional) If set to true, skip service account creation if a service account with the same email already exists. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. + ## Attributes Reference In addition to the arguments listed above, the following computed attributes are diff --git a/website/docs/r/google_service_account_key.html.markdown b/website/docs/r/google_service_account_key.html.markdown index ef6a07b6200..db04476ddb1 100644 --- a/website/docs/r/google_service_account_key.html.markdown +++ b/website/docs/r/google_service_account_key.html.markdown @@ -115,6 +115,13 @@ Valid values are listed at * `keepers` (Optional) Arbitrary map of values that, when changed, will trigger a new key to be generated. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. + ## Attributes Reference The following attributes are exported in addition to the arguments listed above: diff --git a/website/docs/r/google_service_networking_peered_dns_domain.html.markdown b/website/docs/r/google_service_networking_peered_dns_domain.html.markdown index c7b9ccb6e62..fa0f5f1ddb8 100644 --- a/website/docs/r/google_service_networking_peered_dns_domain.html.markdown +++ b/website/docs/r/google_service_networking_peered_dns_domain.html.markdown @@ -52,6 +52,13 @@ The following arguments are supported: * `service` - (Optional) Private service connection between service and consumer network, defaults to `servicenetworking.googleapis.com` +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. + ## Attributes Reference In addition to the arguments listed above, the following computed attributes are exported: diff --git a/website/docs/r/google_tags_location_tag_binding.html.markdown b/website/docs/r/google_tags_location_tag_binding.html.markdown index 315ab4463c9..12164ab3c1f 100644 --- a/website/docs/r/google_tags_location_tag_binding.html.markdown +++ b/website/docs/r/google_tags_location_tag_binding.html.markdown @@ -126,6 +126,13 @@ The following arguments are supported: (Required) Location of the target resource. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. + - - - diff --git a/website/docs/r/healthcare_consent_store.html.markdown b/website/docs/r/healthcare_consent_store.html.markdown index 785d28c58a0..93f2b0355bf 100644 --- a/website/docs/r/healthcare_consent_store.html.markdown +++ b/website/docs/r/healthcare_consent_store.html.markdown @@ -147,6 +147,12 @@ The following arguments are supported: **Note**: This field is non-authoritative, and will only manage the labels present in your configuration. Please refer to the field `effective_labels` for all of the labels present on the resource. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/healthcare_dataset.html.markdown b/website/docs/r/healthcare_dataset.html.markdown index dd9b4771900..69aff29e2b6 100644 --- a/website/docs/r/healthcare_dataset.html.markdown +++ b/website/docs/r/healthcare_dataset.html.markdown @@ -114,6 +114,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `encryption_spec` block supports: diff --git a/website/docs/r/healthcare_dicom_store.html.markdown b/website/docs/r/healthcare_dicom_store.html.markdown index 3b106c7769a..5058fb9da29 100644 --- a/website/docs/r/healthcare_dicom_store.html.markdown +++ b/website/docs/r/healthcare_dicom_store.html.markdown @@ -167,6 +167,12 @@ The following arguments are supported: streamConfigs is an array, so you can specify multiple BigQuery destinations. You can stream metadata from a single DICOM store to up to five BigQuery tables in a BigQuery dataset. Structure is [documented below](#nested_stream_configs). +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `notification_config` block supports: diff --git a/website/docs/r/healthcare_fhir_store.html.markdown b/website/docs/r/healthcare_fhir_store.html.markdown index 272ae6ad710..8e66d1a3f55 100644 --- a/website/docs/r/healthcare_fhir_store.html.markdown +++ b/website/docs/r/healthcare_fhir_store.html.markdown @@ -388,6 +388,12 @@ The following arguments are supported: A list of notifcation configs that configure the notification for every resource mutation in this FHIR store. Structure is [documented below](#nested_notification_configs). +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `consent_config` block supports: diff --git a/website/docs/r/healthcare_hl7_v2_store.html.markdown b/website/docs/r/healthcare_hl7_v2_store.html.markdown index 497daa02eeb..0f01e18c974 100644 --- a/website/docs/r/healthcare_hl7_v2_store.html.markdown +++ b/website/docs/r/healthcare_hl7_v2_store.html.markdown @@ -250,6 +250,12 @@ The following arguments are supported: ~> **Warning:** `notification_config` is deprecated and will be removed in a future major release. Use `notification_configs` instead. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `parser_config` block supports: diff --git a/website/docs/r/healthcare_pipeline_job.html.markdown b/website/docs/r/healthcare_pipeline_job.html.markdown index 12ee6615957..12cdd978d09 100644 --- a/website/docs/r/healthcare_pipeline_job.html.markdown +++ b/website/docs/r/healthcare_pipeline_job.html.markdown @@ -345,6 +345,12 @@ The following arguments are supported: Specifies the backfill configuration. Structure is [documented below](#nested_backfill_pipeline_job). +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `mapping_pipeline_job` block supports: diff --git a/website/docs/r/healthcare_workspace.html.markdown b/website/docs/r/healthcare_workspace.html.markdown index 8b2ad936e97..526ec61b667 100644 --- a/website/docs/r/healthcare_workspace.html.markdown +++ b/website/docs/r/healthcare_workspace.html.markdown @@ -86,6 +86,12 @@ The following arguments are supported: **Note**: This field is non-authoritative, and will only manage the labels present in your configuration. Please refer to the field `effective_labels` for all of the labels present on the resource. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `settings` block supports: diff --git a/website/docs/r/hypercomputecluster_cluster.html.markdown b/website/docs/r/hypercomputecluster_cluster.html.markdown index ae2ac26ae7b..565b27d96ed 100644 --- a/website/docs/r/hypercomputecluster_cluster.html.markdown +++ b/website/docs/r/hypercomputecluster_cluster.html.markdown @@ -157,6 +157,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `compute_resources` block supports: diff --git a/website/docs/r/iam_access_boundary_policy.html.markdown b/website/docs/r/iam_access_boundary_policy.html.markdown index 4d5e26192f4..269bface4a0 100644 --- a/website/docs/r/iam_access_boundary_policy.html.markdown +++ b/website/docs/r/iam_access_boundary_policy.html.markdown @@ -106,6 +106,12 @@ The following arguments are supported: (Optional) The display name of the rule. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `rules` block supports: diff --git a/website/docs/r/iam_deny_policy.html.markdown b/website/docs/r/iam_deny_policy.html.markdown index 2ad339558da..922a729e320 100644 --- a/website/docs/r/iam_deny_policy.html.markdown +++ b/website/docs/r/iam_deny_policy.html.markdown @@ -101,6 +101,12 @@ The following arguments are supported: (Optional) The display name of the rule. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `rules` block supports: diff --git a/website/docs/r/iam_folders_policy_binding.html.markdown b/website/docs/r/iam_folders_policy_binding.html.markdown index 8b425773dee..687fd02326f 100644 --- a/website/docs/r/iam_folders_policy_binding.html.markdown +++ b/website/docs/r/iam_folders_policy_binding.html.markdown @@ -137,6 +137,12 @@ The following arguments are supported: additional information. Structure is [documented below](#nested_condition). +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `target` block supports: diff --git a/website/docs/r/iam_oauth_client.html.markdown b/website/docs/r/iam_oauth_client.html.markdown index 6d40075b62f..38a0cedc253 100644 --- a/website/docs/r/iam_oauth_client.html.markdown +++ b/website/docs/r/iam_oauth_client.html.markdown @@ -122,6 +122,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/iam_oauth_client_credential.html.markdown b/website/docs/r/iam_oauth_client_credential.html.markdown index 88f613deb9b..0ea476b3897 100644 --- a/website/docs/r/iam_oauth_client_credential.html.markdown +++ b/website/docs/r/iam_oauth_client_credential.html.markdown @@ -97,6 +97,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/iam_organizations_policy_binding.html.markdown b/website/docs/r/iam_organizations_policy_binding.html.markdown index 2e4ff34d7d4..890353cb0cc 100644 --- a/website/docs/r/iam_organizations_policy_binding.html.markdown +++ b/website/docs/r/iam_organizations_policy_binding.html.markdown @@ -131,6 +131,12 @@ The following arguments are supported: additional information. Structure is [documented below](#nested_condition). +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `target` block supports: diff --git a/website/docs/r/iam_principal_access_boundary_policy.html.markdown b/website/docs/r/iam_principal_access_boundary_policy.html.markdown index 521cedd14b5..c0cb3292a0d 100644 --- a/website/docs/r/iam_principal_access_boundary_policy.html.markdown +++ b/website/docs/r/iam_principal_access_boundary_policy.html.markdown @@ -111,6 +111,12 @@ The following arguments are supported: Principal access boundary policy details Structure is [documented below](#nested_details). +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `details` block supports: diff --git a/website/docs/r/iam_projects_policy_binding.html.markdown b/website/docs/r/iam_projects_policy_binding.html.markdown index a90dcdf195e..6497ef06c5b 100644 --- a/website/docs/r/iam_projects_policy_binding.html.markdown +++ b/website/docs/r/iam_projects_policy_binding.html.markdown @@ -134,6 +134,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `target` block supports: diff --git a/website/docs/r/iam_workforce_pool.html.markdown b/website/docs/r/iam_workforce_pool.html.markdown index 292381ce0e1..7b9b91f1244 100644 --- a/website/docs/r/iam_workforce_pool.html.markdown +++ b/website/docs/r/iam_workforce_pool.html.markdown @@ -112,6 +112,12 @@ The following arguments are supported: sign-in can be restricted to given set of services or programmatic sign-in can be disabled for pool users. Structure is [documented below](#nested_access_restrictions). +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `access_restrictions` block supports: diff --git a/website/docs/r/iam_workforce_pool_provider.html.markdown b/website/docs/r/iam_workforce_pool_provider.html.markdown index 291eabfd50c..a0648903169 100644 --- a/website/docs/r/iam_workforce_pool_provider.html.markdown +++ b/website/docs/r/iam_workforce_pool_provider.html.markdown @@ -625,6 +625,12 @@ The following arguments are supported: (Optional) If true, populates additional debug information in Cloud Audit Logs for this provider. Logged attribute mappings and values can be found in `sts.googleapis.com` data access logs. Default value is false. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `saml` block supports: diff --git a/website/docs/r/iam_workforce_pool_provider_key.html.markdown b/website/docs/r/iam_workforce_pool_provider_key.html.markdown index 7cfecc4add8..77bf98ed89b 100644 --- a/website/docs/r/iam_workforce_pool_provider_key.html.markdown +++ b/website/docs/r/iam_workforce_pool_provider_key.html.markdown @@ -99,6 +99,12 @@ The following arguments are supported: The ID to use for the key, which becomes the final component of the resource name. This value must be 4-32 characters, and may contain the characters [a-z0-9-]. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `key_data` block supports: diff --git a/website/docs/r/iam_workforce_pool_provider_scim_tenant.html.markdown b/website/docs/r/iam_workforce_pool_provider_scim_tenant.html.markdown index c4bfbfc14c3..c9206dab11b 100644 --- a/website/docs/r/iam_workforce_pool_provider_scim_tenant.html.markdown +++ b/website/docs/r/iam_workforce_pool_provider_scim_tenant.html.markdown @@ -124,6 +124,12 @@ The following arguments are supported: (Optional) Deletes the SCIM tenant immediately. This operation cannot be undone. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/iam_workforce_pool_provider_scim_token.html.markdown b/website/docs/r/iam_workforce_pool_provider_scim_token.html.markdown index 74f6dc8b97a..3af4e61a8ab 100644 --- a/website/docs/r/iam_workforce_pool_provider_scim_token.html.markdown +++ b/website/docs/r/iam_workforce_pool_provider_scim_token.html.markdown @@ -125,6 +125,12 @@ The following arguments are supported: (Optional) A user-specified display name for the scim token. Cannot exceed 32 characters. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/iam_workload_identity_pool.html.markdown b/website/docs/r/iam_workload_identity_pool.html.markdown index e95e340a725..4031cfa434e 100644 --- a/website/docs/r/iam_workload_identity_pool.html.markdown +++ b/website/docs/r/iam_workload_identity_pool.html.markdown @@ -229,6 +229,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `inline_certificate_issuance_config` block supports: diff --git a/website/docs/r/iam_workload_identity_pool_managed_identity.html.markdown b/website/docs/r/iam_workload_identity_pool_managed_identity.html.markdown index c33c9c6c991..cef0c58233d 100644 --- a/website/docs/r/iam_workload_identity_pool_managed_identity.html.markdown +++ b/website/docs/r/iam_workload_identity_pool_managed_identity.html.markdown @@ -136,6 +136,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `attestation_rules` block supports: diff --git a/website/docs/r/iam_workload_identity_pool_namespace.html.markdown b/website/docs/r/iam_workload_identity_pool_namespace.html.markdown index 5c50b28da0a..e2d1358e079 100644 --- a/website/docs/r/iam_workload_identity_pool_namespace.html.markdown +++ b/website/docs/r/iam_workload_identity_pool_namespace.html.markdown @@ -108,6 +108,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/iam_workload_identity_pool_provider.html.markdown b/website/docs/r/iam_workload_identity_pool_provider.html.markdown index cd9d139b38d..6ebcaf42fa0 100644 --- a/website/docs/r/iam_workload_identity_pool_provider.html.markdown +++ b/website/docs/r/iam_workload_identity_pool_provider.html.markdown @@ -459,6 +459,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `aws` block supports: diff --git a/website/docs/r/iap_brand.html.markdown b/website/docs/r/iap_brand.html.markdown index 22c2eae0efe..53b50e89094 100644 --- a/website/docs/r/iap_brand.html.markdown +++ b/website/docs/r/iap_brand.html.markdown @@ -83,6 +83,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/iap_client.html.markdown b/website/docs/r/iap_client.html.markdown index 6441d877085..b14b4719d3e 100644 --- a/website/docs/r/iap_client.html.markdown +++ b/website/docs/r/iap_client.html.markdown @@ -83,6 +83,12 @@ The following arguments are supported: `projects/{project_number}/brands/{brand_id}`. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/iap_settings.html.markdown b/website/docs/r/iap_settings.html.markdown index 6a99cfcd957..15e71a383ba 100644 --- a/website/docs/r/iap_settings.html.markdown +++ b/website/docs/r/iap_settings.html.markdown @@ -184,6 +184,12 @@ The following arguments are supported: Top level wrapper for all application related settings in IAP. Structure is [documented below](#nested_application_settings). +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `access_settings` block supports: diff --git a/website/docs/r/iap_tunnel_dest_group.html.markdown b/website/docs/r/iap_tunnel_dest_group.html.markdown index ae6b3072d0f..29c3982de6d 100644 --- a/website/docs/r/iap_tunnel_dest_group.html.markdown +++ b/website/docs/r/iap_tunnel_dest_group.html.markdown @@ -74,6 +74,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/identity_platform_config.html.markdown b/website/docs/r/identity_platform_config.html.markdown index 4090beaf0fe..29de15d4048 100644 --- a/website/docs/r/identity_platform_config.html.markdown +++ b/website/docs/r/identity_platform_config.html.markdown @@ -171,6 +171,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `sign_in` block supports: diff --git a/website/docs/r/identity_platform_default_supported_idp_config.html.markdown b/website/docs/r/identity_platform_default_supported_idp_config.html.markdown index 3599bb1f157..cd40c85ca31 100644 --- a/website/docs/r/identity_platform_default_supported_idp_config.html.markdown +++ b/website/docs/r/identity_platform_default_supported_idp_config.html.markdown @@ -76,6 +76,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/identity_platform_inbound_saml_config.html.markdown b/website/docs/r/identity_platform_inbound_saml_config.html.markdown index 0b2cbc55a73..d186bac5a70 100644 --- a/website/docs/r/identity_platform_inbound_saml_config.html.markdown +++ b/website/docs/r/identity_platform_inbound_saml_config.html.markdown @@ -91,6 +91,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `idp_config` block supports: diff --git a/website/docs/r/identity_platform_oauth_idp_config.html.markdown b/website/docs/r/identity_platform_oauth_idp_config.html.markdown index 9f5154bfe83..c7f7ffb80fa 100644 --- a/website/docs/r/identity_platform_oauth_idp_config.html.markdown +++ b/website/docs/r/identity_platform_oauth_idp_config.html.markdown @@ -92,6 +92,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `response_type` block supports: diff --git a/website/docs/r/identity_platform_tenant.html.markdown b/website/docs/r/identity_platform_tenant.html.markdown index b55fd45ea48..739234bde6c 100644 --- a/website/docs/r/identity_platform_tenant.html.markdown +++ b/website/docs/r/identity_platform_tenant.html.markdown @@ -79,6 +79,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `client` block supports: diff --git a/website/docs/r/identity_platform_tenant_default_supported_idp_config.html.markdown b/website/docs/r/identity_platform_tenant_default_supported_idp_config.html.markdown index d55bec86606..765058cc611 100644 --- a/website/docs/r/identity_platform_tenant_default_supported_idp_config.html.markdown +++ b/website/docs/r/identity_platform_tenant_default_supported_idp_config.html.markdown @@ -90,6 +90,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/identity_platform_tenant_inbound_saml_config.html.markdown b/website/docs/r/identity_platform_tenant_inbound_saml_config.html.markdown index 0eced074c11..61c0b08cc77 100644 --- a/website/docs/r/identity_platform_tenant_inbound_saml_config.html.markdown +++ b/website/docs/r/identity_platform_tenant_inbound_saml_config.html.markdown @@ -100,6 +100,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `idp_config` block supports: diff --git a/website/docs/r/identity_platform_tenant_oauth_idp_config.html.markdown b/website/docs/r/identity_platform_tenant_oauth_idp_config.html.markdown index efabb3381a2..55cbe9fb86d 100644 --- a/website/docs/r/identity_platform_tenant_oauth_idp_config.html.markdown +++ b/website/docs/r/identity_platform_tenant_oauth_idp_config.html.markdown @@ -90,6 +90,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/integration_connectors_connection.html.markdown b/website/docs/r/integration_connectors_connection.html.markdown index 06942e57dae..c23b43c0411 100644 --- a/website/docs/r/integration_connectors_connection.html.markdown +++ b/website/docs/r/integration_connectors_connection.html.markdown @@ -375,6 +375,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `config_variable` block supports: diff --git a/website/docs/r/integration_connectors_endpoint_attachment.html.markdown b/website/docs/r/integration_connectors_endpoint_attachment.html.markdown index 5ecb7d58b74..9f7f4502cc0 100644 --- a/website/docs/r/integration_connectors_endpoint_attachment.html.markdown +++ b/website/docs/r/integration_connectors_endpoint_attachment.html.markdown @@ -86,6 +86,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/integration_connectors_managed_zone.html.markdown b/website/docs/r/integration_connectors_managed_zone.html.markdown index 50beabd47f0..45d42e0e28d 100644 --- a/website/docs/r/integration_connectors_managed_zone.html.markdown +++ b/website/docs/r/integration_connectors_managed_zone.html.markdown @@ -130,6 +130,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/integrations_auth_config.html.markdown b/website/docs/r/integrations_auth_config.html.markdown index 9734ae106ae..682e0b0fdf6 100644 --- a/website/docs/r/integrations_auth_config.html.markdown +++ b/website/docs/r/integrations_auth_config.html.markdown @@ -100,6 +100,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `decrypted_credential` block supports: diff --git a/website/docs/r/integrations_client.html.markdown b/website/docs/r/integrations_client.html.markdown index 0b25373ed56..b5e73c2f0a8 100644 --- a/website/docs/r/integrations_client.html.markdown +++ b/website/docs/r/integrations_client.html.markdown @@ -111,6 +111,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `cloud_kms_config` block supports: diff --git a/website/docs/r/kms_autokey_config.html.markdown b/website/docs/r/kms_autokey_config.html.markdown index ed174858f30..cbff554dba2 100644 --- a/website/docs/r/kms_autokey_config.html.markdown +++ b/website/docs/r/kms_autokey_config.html.markdown @@ -141,6 +141,12 @@ The following arguments are supported: How Autokey determines which project to use when provisioning CMEK keys. Possible values are: `DEDICATED_KEY_PROJECT`, `RESOURCE_PROJECT`, `DISABLED`. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/kms_crypto_key.html.markdown b/website/docs/r/kms_crypto_key.html.markdown index 68ea0b34639..0c827edaf11 100644 --- a/website/docs/r/kms_crypto_key.html.markdown +++ b/website/docs/r/kms_crypto_key.html.markdown @@ -157,6 +157,12 @@ The following arguments are supported: or `google_kms_key_ring_import_job` resource to import the CryptoKeyVersion. This field is only applicable during initial CryptoKey creation. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `version_template` block supports: diff --git a/website/docs/r/kms_crypto_key_version.html.markdown b/website/docs/r/kms_crypto_key_version.html.markdown index a7f7016435a..73e276056d0 100644 --- a/website/docs/r/kms_crypto_key_version.html.markdown +++ b/website/docs/r/kms_crypto_key_version.html.markdown @@ -75,6 +75,12 @@ The following arguments are supported: ExternalProtectionLevelOptions stores a group of additional fields for configuring a CryptoKeyVersion that are specific to the EXTERNAL protection level and EXTERNAL_VPC protection levels. Structure is [documented below](#nested_external_protection_level_options). +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `external_protection_level_options` block supports: diff --git a/website/docs/r/kms_ekm_connection.html.markdown b/website/docs/r/kms_ekm_connection.html.markdown index a57a6779f1f..da77f3ae07c 100644 --- a/website/docs/r/kms_ekm_connection.html.markdown +++ b/website/docs/r/kms_ekm_connection.html.markdown @@ -89,6 +89,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `service_resolvers` block supports: diff --git a/website/docs/r/kms_folder_kaj_policy_config.html.markdown b/website/docs/r/kms_folder_kaj_policy_config.html.markdown index 31e576ac68b..b68348293e8 100644 --- a/website/docs/r/kms_folder_kaj_policy_config.html.markdown +++ b/website/docs/r/kms_folder_kaj_policy_config.html.markdown @@ -109,6 +109,12 @@ The following arguments are supported: policy is not provided in the CreateCryptoKeyRequest. Structure is [documented below](#nested_default_key_access_justification_policy). +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `default_key_access_justification_policy` block supports: diff --git a/website/docs/r/kms_key_handle.html.markdown b/website/docs/r/kms_key_handle.html.markdown index 3cfc77c0170..b79be0fa32c 100644 --- a/website/docs/r/kms_key_handle.html.markdown +++ b/website/docs/r/kms_key_handle.html.markdown @@ -159,6 +159,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/kms_key_ring.html.markdown b/website/docs/r/kms_key_ring.html.markdown index 7acc6bb625a..737d2a58aff 100644 --- a/website/docs/r/kms_key_ring.html.markdown +++ b/website/docs/r/kms_key_ring.html.markdown @@ -63,6 +63,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/kms_key_ring_import_job.html.markdown b/website/docs/r/kms_key_ring_import_job.html.markdown index ec2d0bba04a..c1a3327b3d1 100644 --- a/website/docs/r/kms_key_ring_import_job.html.markdown +++ b/website/docs/r/kms_key_ring_import_job.html.markdown @@ -89,6 +89,12 @@ The following arguments are supported: It must be unique within a KeyRing and match the regular expression [a-zA-Z0-9_-]{1,63} +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/kms_organization_kaj_policy_config.html.markdown b/website/docs/r/kms_organization_kaj_policy_config.html.markdown index 2c2fcd2f4e8..4d22aa518e9 100644 --- a/website/docs/r/kms_organization_kaj_policy_config.html.markdown +++ b/website/docs/r/kms_organization_kaj_policy_config.html.markdown @@ -71,6 +71,12 @@ The following arguments are supported: policy is not provided in the CreateCryptoKeyRequest. Structure is [documented below](#nested_default_key_access_justification_policy). +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `default_key_access_justification_policy` block supports: diff --git a/website/docs/r/kms_project_autokey_config.html.markdown b/website/docs/r/kms_project_autokey_config.html.markdown index 80d96c11690..e43e65fb78b 100644 --- a/website/docs/r/kms_project_autokey_config.html.markdown +++ b/website/docs/r/kms_project_autokey_config.html.markdown @@ -117,6 +117,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/kms_project_kaj_policy_config.html.markdown b/website/docs/r/kms_project_kaj_policy_config.html.markdown index b8d85a624a0..8a2d9f92854 100644 --- a/website/docs/r/kms_project_kaj_policy_config.html.markdown +++ b/website/docs/r/kms_project_kaj_policy_config.html.markdown @@ -95,6 +95,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `default_key_access_justification_policy` block supports: diff --git a/website/docs/r/kms_secret_ciphertext.html.markdown b/website/docs/r/kms_secret_ciphertext.html.markdown index 29be79fcd53..02204959d3c 100644 --- a/website/docs/r/kms_secret_ciphertext.html.markdown +++ b/website/docs/r/kms_secret_ciphertext.html.markdown @@ -109,6 +109,12 @@ The following arguments are supported: The additional authenticated data used for integrity checks during encryption and decryption. **Note**: This property is sensitive and will not be displayed in the plan. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/logging_billing_account_bucket_config.html.markdown b/website/docs/r/logging_billing_account_bucket_config.html.markdown index edf9f986d84..eab74ffb217 100644 --- a/website/docs/r/logging_billing_account_bucket_config.html.markdown +++ b/website/docs/r/logging_billing_account_bucket_config.html.markdown @@ -73,6 +73,13 @@ The following arguments are supported: * `index_configs` - (Optional) A list of indexed fields and related configuration data. Structure is [documented below](#nested_index_configs). +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. + The `index_configs` block supports: * `field_path` - The LogEntry field path to index. diff --git a/website/docs/r/logging_billing_account_sink.html.markdown b/website/docs/r/logging_billing_account_sink.html.markdown index 990d4d43590..22e59ab5369 100644 --- a/website/docs/r/logging_billing_account_sink.html.markdown +++ b/website/docs/r/logging_billing_account_sink.html.markdown @@ -86,6 +86,13 @@ The following arguments are supported: * `exclusions` - (Optional) Log entries that match any of the exclusion filters will not be exported. If a log entry is matched by both `filter` and one of `exclusions.filter`, it will not be exported. Can be repeated multiple times for multiple exclusions. Structure is [documented below](#nested_exclusions). +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. + The `bigquery_options` block supports: * `use_partitioned_tables` - (Required) Whether to use [BigQuery's partition tables](https://cloud.google.com/bigquery/docs/partitioned-tables). diff --git a/website/docs/r/logging_folder_bucket_config.html.markdown b/website/docs/r/logging_folder_bucket_config.html.markdown index e0a5e82ee08..c5df798d215 100644 --- a/website/docs/r/logging_folder_bucket_config.html.markdown +++ b/website/docs/r/logging_folder_bucket_config.html.markdown @@ -63,6 +63,13 @@ The following arguments are supported: * `index_configs` - (Optional) A list of indexed fields and related configuration data. Structure is [documented below](#nested_index_configs). +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. + The `index_configs` block supports: * `field_path` - The LogEntry field path to index. diff --git a/website/docs/r/logging_folder_settings.html.markdown b/website/docs/r/logging_folder_settings.html.markdown index 05f0a4698ee..2eef11737c4 100644 --- a/website/docs/r/logging_folder_settings.html.markdown +++ b/website/docs/r/logging_folder_settings.html.markdown @@ -81,6 +81,12 @@ The following arguments are supported: (Optional) If set to true, the _Default sink in newly created projects and folders will created in a disabled state. This can be used to automatically disable log storage if there is already an aggregated sink configured in the hierarchy. The _Default sink can be re-enabled manually if needed. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/logging_folder_sink.html.markdown b/website/docs/r/logging_folder_sink.html.markdown index 5727e6051a4..141330de708 100644 --- a/website/docs/r/logging_folder_sink.html.markdown +++ b/website/docs/r/logging_folder_sink.html.markdown @@ -98,6 +98,13 @@ The following arguments are supported: * `exclusions` - (Optional) Log entries that match any of the exclusion filters will not be exported. If a log entry is matched by both `filter` and one of `exclusions.filter`, it will not be exported. Can be repeated multiple times for multiple exclusions. Structure is [documented below](#nested_exclusions). +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. + The `bigquery_options` block supports: * `use_partitioned_tables` - (Required) Whether to use [BigQuery's partition tables](https://cloud.google.com/bigquery/docs/partitioned-tables). diff --git a/website/docs/r/logging_linked_dataset.html.markdown b/website/docs/r/logging_linked_dataset.html.markdown index 00439615d02..aa0721edf3e 100644 --- a/website/docs/r/logging_linked_dataset.html.markdown +++ b/website/docs/r/logging_linked_dataset.html.markdown @@ -95,6 +95,12 @@ The following arguments are supported: (Optional) The location of the linked dataset. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/logging_log_scope.html.markdown b/website/docs/r/logging_log_scope.html.markdown index 6bf240a8447..ab279cbcf88 100644 --- a/website/docs/r/logging_log_scope.html.markdown +++ b/website/docs/r/logging_log_scope.html.markdown @@ -73,6 +73,12 @@ The following arguments are supported: (Optional) The location of the resource. The only supported location is global so far. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/logging_log_view.html.markdown b/website/docs/r/logging_log_view.html.markdown index e7853bd5bef..940be42faf4 100644 --- a/website/docs/r/logging_log_view.html.markdown +++ b/website/docs/r/logging_log_view.html.markdown @@ -79,6 +79,12 @@ The following arguments are supported: (Optional) The location of the resource. The supported locations are: global, us-central1, us-east1, us-west1, asia-east1, europe-west1. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/logging_metric.html.markdown b/website/docs/r/logging_metric.html.markdown index 010c334f361..3fa4d0042ed 100644 --- a/website/docs/r/logging_metric.html.markdown +++ b/website/docs/r/logging_metric.html.markdown @@ -222,6 +222,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `metric_descriptor` block supports: diff --git a/website/docs/r/logging_organization_bucket_config.html.markdown b/website/docs/r/logging_organization_bucket_config.html.markdown index 0e7005e2499..5ac94685e5e 100644 --- a/website/docs/r/logging_organization_bucket_config.html.markdown +++ b/website/docs/r/logging_organization_bucket_config.html.markdown @@ -62,6 +62,13 @@ The following arguments are supported: * `index_configs` - (Optional) A list of indexed fields and related configuration data. Structure is [documented below](#nested_index_configs). +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. + The `index_configs` block supports: * `field_path` - The LogEntry field path to index. diff --git a/website/docs/r/logging_organization_settings.html.markdown b/website/docs/r/logging_organization_settings.html.markdown index 0dd0b00034e..630ed217e3d 100644 --- a/website/docs/r/logging_organization_settings.html.markdown +++ b/website/docs/r/logging_organization_settings.html.markdown @@ -75,6 +75,12 @@ The following arguments are supported: (Optional) If set to true, the _Default sink in newly created projects and folders will created in a disabled state. This can be used to automatically disable log storage if there is already an aggregated sink configured in the hierarchy. The _Default sink can be re-enabled manually if needed. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/logging_organization_sink.html.markdown b/website/docs/r/logging_organization_sink.html.markdown index 4cdbef9ca65..661fbffece1 100644 --- a/website/docs/r/logging_organization_sink.html.markdown +++ b/website/docs/r/logging_organization_sink.html.markdown @@ -88,6 +88,13 @@ The following arguments are supported: * `exclusions` - (Optional) Log entries that match any of the exclusion filters will not be exported. If a log entry is matched by both `filter` and one of `exclusions.filter`, it will not be exported. Can be repeated multiple times for multiple exclusions. Structure is [documented below](#nested_exclusions). +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. + The `bigquery_options` block supports: * `use_partitioned_tables` - (Required) Whether to use [BigQuery's partition tables](https://cloud.google.com/bigquery/docs/partitioned-tables). diff --git a/website/docs/r/logging_project_bucket_config.html.markdown b/website/docs/r/logging_project_bucket_config.html.markdown index fe967a869e0..d6ef39087f0 100644 --- a/website/docs/r/logging_project_bucket_config.html.markdown +++ b/website/docs/r/logging_project_bucket_config.html.markdown @@ -145,6 +145,13 @@ The following arguments are supported: * `index_configs` - (Optional) A list of indexed fields and related configuration data. Structure is [documented below](#nested_index_configs). +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. + The `cmek_settings` block supports: * `name` - The resource name of the CMEK settings. diff --git a/website/docs/r/logging_project_sink.html.markdown b/website/docs/r/logging_project_sink.html.markdown index c2ce72023bc..8234aea9b76 100644 --- a/website/docs/r/logging_project_sink.html.markdown +++ b/website/docs/r/logging_project_sink.html.markdown @@ -217,6 +217,13 @@ The following arguments are supported: * `exclusions` - (Optional) Log entries that match any of the exclusion filters will not be exported. If a log entry is matched by both `filter` and one of `exclusions.filter`, it will not be exported. Can be repeated multiple times for multiple exclusions. Structure is [documented below](#nested_exclusions). +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. + The `bigquery_options` block supports: * `use_partitioned_tables` - (Required) Whether to use [BigQuery's partition tables](https://cloud.google.com/bigquery/docs/partitioned-tables). diff --git a/website/docs/r/logging_saved_query.html.markdown b/website/docs/r/logging_saved_query.html.markdown index d1a42a254af..493f49be1bb 100644 --- a/website/docs/r/logging_saved_query.html.markdown +++ b/website/docs/r/logging_saved_query.html.markdown @@ -155,6 +155,12 @@ The following arguments are supported: The contents of the saved query. Structure is [documented below](#nested_ops_analytics_query). +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `logging_query` block supports: diff --git a/website/docs/r/looker_instance.html.markdown b/website/docs/r/looker_instance.html.markdown index 04fe46ab66f..c0d21dcd548 100644 --- a/website/docs/r/looker_instance.html.markdown +++ b/website/docs/r/looker_instance.html.markdown @@ -425,7 +425,15 @@ The following arguments are supported: * `deletion_policy` - (Optional) Policy to determine if the cluster should be deleted forcefully. If setting deletion_policy = "FORCE", the Looker instance will be deleted regardless of its nested resources. If set to "DEFAULT", Looker instances that still have -nested resources will return an error. Possible values: DEFAULT, FORCE +nested resources will return an error. + +When a 'terraform destroy' or 'terraform apply' would delete the resource, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", the command will behave as if set to "DEFAULT". + +Possible values: DEFAULT, FORCE, PREVENT, ABANDON, DELETE diff --git a/website/docs/r/lustre_instance.html.markdown b/website/docs/r/lustre_instance.html.markdown index 81dd1ef19bb..99cb1296d4f 100644 --- a/website/docs/r/lustre_instance.html.markdown +++ b/website/docs/r/lustre_instance.html.markdown @@ -164,6 +164,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `access_rules_options` block supports: diff --git a/website/docs/r/managed_kafka_acl.html.markdown b/website/docs/r/managed_kafka_acl.html.markdown index 18b1576ffd2..0233e3f53f3 100644 --- a/website/docs/r/managed_kafka_acl.html.markdown +++ b/website/docs/r/managed_kafka_acl.html.markdown @@ -102,6 +102,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `acl_entries` block supports: diff --git a/website/docs/r/managed_kafka_cluster.html.markdown b/website/docs/r/managed_kafka_cluster.html.markdown index 7a6b6c4e652..d85291bf70d 100644 --- a/website/docs/r/managed_kafka_cluster.html.markdown +++ b/website/docs/r/managed_kafka_cluster.html.markdown @@ -193,6 +193,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `gcp_config` block supports: diff --git a/website/docs/r/managed_kafka_connect_cluster.html.markdown b/website/docs/r/managed_kafka_connect_cluster.html.markdown index edb208793d0..b16472b916a 100644 --- a/website/docs/r/managed_kafka_connect_cluster.html.markdown +++ b/website/docs/r/managed_kafka_connect_cluster.html.markdown @@ -117,6 +117,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `capacity_config` block supports: diff --git a/website/docs/r/managed_kafka_connector.html.markdown b/website/docs/r/managed_kafka_connector.html.markdown index 7b6df918a04..460e8517ab5 100644 --- a/website/docs/r/managed_kafka_connector.html.markdown +++ b/website/docs/r/managed_kafka_connector.html.markdown @@ -147,6 +147,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `task_restart_policy` block supports: diff --git a/website/docs/r/managed_kafka_topic.html.markdown b/website/docs/r/managed_kafka_topic.html.markdown index 0ea0ecab638..3a1264bd37f 100644 --- a/website/docs/r/managed_kafka_topic.html.markdown +++ b/website/docs/r/managed_kafka_topic.html.markdown @@ -98,6 +98,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/memcache_instance.html.markdown b/website/docs/r/memcache_instance.html.markdown index b7b003cec98..9d92ec64c08 100644 --- a/website/docs/r/memcache_instance.html.markdown +++ b/website/docs/r/memcache_instance.html.markdown @@ -162,6 +162,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. * `deletion_protection` - (Optional) Whether Terraform will be prevented from destroying the instance. When a `terraform destroy` or `terraform apply` would delete the instance, the command will fail if this field is not set to false in Terraform state. diff --git a/website/docs/r/memorystore_instance.html.markdown b/website/docs/r/memorystore_instance.html.markdown index 765978de80f..f9585165e88 100644 --- a/website/docs/r/memorystore_instance.html.markdown +++ b/website/docs/r/memorystore_instance.html.markdown @@ -628,6 +628,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. * `desired_psc_auto_connections` - (Optional) `desired_psc_auto_connections` is deprecated Use `desired_auto_created_endpoints` instead `terraform import` will only work with desired_auto_created_endpoints`. * `desired_auto_created_endpoints` - (Optional) Immutable. User inputs for the auto-created endpoints connections. diff --git a/website/docs/r/memorystore_instance_desired_user_created_endpoints.html.markdown b/website/docs/r/memorystore_instance_desired_user_created_endpoints.html.markdown index 07f8fd76c35..8193e82f21a 100644 --- a/website/docs/r/memorystore_instance_desired_user_created_endpoints.html.markdown +++ b/website/docs/r/memorystore_instance_desired_user_created_endpoints.html.markdown @@ -335,6 +335,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `desired_user_created_endpoints` block supports: diff --git a/website/docs/r/migration_center_group.html.markdown b/website/docs/r/migration_center_group.html.markdown index 1bcda2ecbb1..c3a19f8d5a4 100644 --- a/website/docs/r/migration_center_group.html.markdown +++ b/website/docs/r/migration_center_group.html.markdown @@ -76,6 +76,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/migration_center_preference_set.html.markdown b/website/docs/r/migration_center_preference_set.html.markdown index 43acb3e46d4..26ed50c661a 100644 --- a/website/docs/r/migration_center_preference_set.html.markdown +++ b/website/docs/r/migration_center_preference_set.html.markdown @@ -158,6 +158,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `virtual_machine_preferences` block supports: diff --git a/website/docs/r/ml_engine_model.html.markdown b/website/docs/r/ml_engine_model.html.markdown index 65fe049c199..aba72a44596 100644 --- a/website/docs/r/ml_engine_model.html.markdown +++ b/website/docs/r/ml_engine_model.html.markdown @@ -102,6 +102,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `default_version` block supports: diff --git a/website/docs/r/model_armor_floorsetting.html.markdown b/website/docs/r/model_armor_floorsetting.html.markdown index d984189be38..f28183bef59 100644 --- a/website/docs/r/model_armor_floorsetting.html.markdown +++ b/website/docs/r/model_armor_floorsetting.html.markdown @@ -144,6 +144,12 @@ The following arguments are supported: Metadata to enable multi language detection via floor setting. Structure is [documented below](#nested_floor_setting_metadata). +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `filter_config` block supports: diff --git a/website/docs/r/model_armor_template.html.markdown b/website/docs/r/model_armor_template.html.markdown index 5a288bd23d9..800eaccd5c6 100644 --- a/website/docs/r/model_armor_template.html.markdown +++ b/website/docs/r/model_armor_template.html.markdown @@ -198,6 +198,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `filter_config` block supports: diff --git a/website/docs/r/monitoring_alert_policy.html.markdown b/website/docs/r/monitoring_alert_policy.html.markdown index 52de003fd53..3755887fcc9 100644 --- a/website/docs/r/monitoring_alert_policy.html.markdown +++ b/website/docs/r/monitoring_alert_policy.html.markdown @@ -232,6 +232,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `conditions` block supports: diff --git a/website/docs/r/monitoring_custom_service.html.markdown b/website/docs/r/monitoring_custom_service.html.markdown index e430ba9a252..c36fb1ebec3 100644 --- a/website/docs/r/monitoring_custom_service.html.markdown +++ b/website/docs/r/monitoring_custom_service.html.markdown @@ -92,6 +92,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `telemetry` block supports: diff --git a/website/docs/r/monitoring_dashboard.html.markdown b/website/docs/r/monitoring_dashboard.html.markdown index c5489419518..d887623fd20 100644 --- a/website/docs/r/monitoring_dashboard.html.markdown +++ b/website/docs/r/monitoring_dashboard.html.markdown @@ -140,6 +140,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/monitoring_group.html.markdown b/website/docs/r/monitoring_group.html.markdown index 58602f063f5..d304a90a84d 100644 --- a/website/docs/r/monitoring_group.html.markdown +++ b/website/docs/r/monitoring_group.html.markdown @@ -100,6 +100,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/monitoring_metric_descriptor.html.markdown b/website/docs/r/monitoring_metric_descriptor.html.markdown index faa268bc9bf..dce72c9973d 100644 --- a/website/docs/r/monitoring_metric_descriptor.html.markdown +++ b/website/docs/r/monitoring_metric_descriptor.html.markdown @@ -156,6 +156,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `labels` block supports: diff --git a/website/docs/r/monitoring_monitored_project.html.markdown b/website/docs/r/monitoring_monitored_project.html.markdown index c1aa2dd644a..fb113df572d 100644 --- a/website/docs/r/monitoring_monitored_project.html.markdown +++ b/website/docs/r/monitoring_monitored_project.html.markdown @@ -61,6 +61,12 @@ The following arguments are supported: Required. The resource name of the existing Metrics Scope that will monitor this project. Example: locations/global/metricsScopes/{SCOPING_PROJECT_ID_OR_NUMBER} +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/monitoring_notification_channel.html.markdown b/website/docs/r/monitoring_notification_channel.html.markdown index c6b7c0adafd..105da56ea7d 100644 --- a/website/docs/r/monitoring_notification_channel.html.markdown +++ b/website/docs/r/monitoring_notification_channel.html.markdown @@ -136,6 +136,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. * `force_delete` - (Optional) If true, the notification channel will be deleted regardless of its use in alert policies (the policies will be updated to remove the channel). If false, channels that are still diff --git a/website/docs/r/monitoring_service.html.markdown b/website/docs/r/monitoring_service.html.markdown index 18c3ae2ccc0..963773b8c9e 100644 --- a/website/docs/r/monitoring_service.html.markdown +++ b/website/docs/r/monitoring_service.html.markdown @@ -97,6 +97,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `basic_service` block supports: diff --git a/website/docs/r/monitoring_slo.html.markdown b/website/docs/r/monitoring_slo.html.markdown index 59281e2d124..59180a873e2 100644 --- a/website/docs/r/monitoring_slo.html.markdown +++ b/website/docs/r/monitoring_slo.html.markdown @@ -323,6 +323,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `basic_sli` block supports: diff --git a/website/docs/r/monitoring_uptime_check_config.html.markdown b/website/docs/r/monitoring_uptime_check_config.html.markdown index 1d387c03fbd..6be0197103e 100644 --- a/website/docs/r/monitoring_uptime_check_config.html.markdown +++ b/website/docs/r/monitoring_uptime_check_config.html.markdown @@ -367,6 +367,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `content_matchers` block supports: diff --git a/website/docs/r/netapp_active_directory.html.markdown b/website/docs/r/netapp_active_directory.html.markdown index 24d93e1af18..0e3644bc107 100644 --- a/website/docs/r/netapp_active_directory.html.markdown +++ b/website/docs/r/netapp_active_directory.html.markdown @@ -167,6 +167,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/netapp_backup.html.markdown b/website/docs/r/netapp_backup.html.markdown index 0e54e002906..9ab8e4bf09a 100644 --- a/website/docs/r/netapp_backup.html.markdown +++ b/website/docs/r/netapp_backup.html.markdown @@ -133,6 +133,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/netapp_backup_policy.html.markdown b/website/docs/r/netapp_backup_policy.html.markdown index d80dc899104..8af832a9c53 100644 --- a/website/docs/r/netapp_backup_policy.html.markdown +++ b/website/docs/r/netapp_backup_policy.html.markdown @@ -100,6 +100,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/netapp_backup_vault.html.markdown b/website/docs/r/netapp_backup_vault.html.markdown index ba62050a950..97c3d964f2c 100644 --- a/website/docs/r/netapp_backup_vault.html.markdown +++ b/website/docs/r/netapp_backup_vault.html.markdown @@ -93,6 +93,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `backup_retention_policy` block supports: diff --git a/website/docs/r/netapp_host_group.html.markdown b/website/docs/r/netapp_host_group.html.markdown index 86f0e8532a8..37fbd63ef8b 100644 --- a/website/docs/r/netapp_host_group.html.markdown +++ b/website/docs/r/netapp_host_group.html.markdown @@ -93,6 +93,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/netapp_kmsconfig.html.markdown b/website/docs/r/netapp_kmsconfig.html.markdown index da7fe4f32b3..97d49c8dcdc 100644 --- a/website/docs/r/netapp_kmsconfig.html.markdown +++ b/website/docs/r/netapp_kmsconfig.html.markdown @@ -81,6 +81,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/netapp_storage_pool.html.markdown b/website/docs/r/netapp_storage_pool.html.markdown index 41082f5fc8d..7605ee78844 100644 --- a/website/docs/r/netapp_storage_pool.html.markdown +++ b/website/docs/r/netapp_storage_pool.html.markdown @@ -228,6 +228,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/netapp_volume.html.markdown b/website/docs/r/netapp_volume.html.markdown index 1cc4f9d836b..644375f7e90 100644 --- a/website/docs/r/netapp_volume.html.markdown +++ b/website/docs/r/netapp_volume.html.markdown @@ -207,7 +207,14 @@ The following arguments are supported: * `deletion_policy` - (Optional) Policy to determine if the volume should be deleted forcefully. Volumes may have nested snapshot resources. Deleting such a volume will fail. Setting this parameter to FORCE will delete volumes including nested snapshots. -Possible values: DEFAULT, FORCE. + +When a 'terraform destroy' or 'terraform apply' would delete the resource, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", the command will behave as if set to "DEFAULT". + +Possible values: DEFAULT, FORCE, PREVENT, ABANDON, DELETE. diff --git a/website/docs/r/netapp_volume_quota_rule.html.markdown b/website/docs/r/netapp_volume_quota_rule.html.markdown index 31096ad372f..c938b050d32 100644 --- a/website/docs/r/netapp_volume_quota_rule.html.markdown +++ b/website/docs/r/netapp_volume_quota_rule.html.markdown @@ -121,6 +121,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/netapp_volume_replication.html.markdown b/website/docs/r/netapp_volume_replication.html.markdown index cc295d10403..102644d8ce2 100644 --- a/website/docs/r/netapp_volume_replication.html.markdown +++ b/website/docs/r/netapp_volume_replication.html.markdown @@ -154,6 +154,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. * `delete_destination_volume` - (Optional) A destination volume is created as part of replication creation. The destination volume will not became under Terraform management unless you import it manually. If you delete the replication, this volume will remain. diff --git a/website/docs/r/netapp_volume_snapshot.html.markdown b/website/docs/r/netapp_volume_snapshot.html.markdown index 21337d503e4..0c6bad0a62e 100644 --- a/website/docs/r/netapp_volume_snapshot.html.markdown +++ b/website/docs/r/netapp_volume_snapshot.html.markdown @@ -105,6 +105,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/network_connectivity_destination.html.markdown b/website/docs/r/network_connectivity_destination.html.markdown index bfa2b1b57f6..0ba0fec122c 100644 --- a/website/docs/r/network_connectivity_destination.html.markdown +++ b/website/docs/r/network_connectivity_destination.html.markdown @@ -102,6 +102,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `endpoints` block supports: diff --git a/website/docs/r/network_connectivity_gateway_advertised_route.html.markdown b/website/docs/r/network_connectivity_gateway_advertised_route.html.markdown index fe2a0bef4d7..f81bb33fec9 100644 --- a/website/docs/r/network_connectivity_gateway_advertised_route.html.markdown +++ b/website/docs/r/network_connectivity_gateway_advertised_route.html.markdown @@ -144,6 +144,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/network_connectivity_group.html.markdown b/website/docs/r/network_connectivity_group.html.markdown index 10a407c0ba6..13aa42dde72 100644 --- a/website/docs/r/network_connectivity_group.html.markdown +++ b/website/docs/r/network_connectivity_group.html.markdown @@ -96,6 +96,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `auto_accept` block supports: diff --git a/website/docs/r/network_connectivity_hub.html.markdown b/website/docs/r/network_connectivity_hub.html.markdown index 10c93f13c8c..89c8d4fbe1a 100644 --- a/website/docs/r/network_connectivity_hub.html.markdown +++ b/website/docs/r/network_connectivity_hub.html.markdown @@ -156,6 +156,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/network_connectivity_internal_range.html.markdown b/website/docs/r/network_connectivity_internal_range.html.markdown index a5c224adf27..b2bc857ebb0 100644 --- a/website/docs/r/network_connectivity_internal_range.html.markdown +++ b/website/docs/r/network_connectivity_internal_range.html.markdown @@ -321,6 +321,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `allocation_options` block supports: diff --git a/website/docs/r/network_connectivity_multicloud_data_transfer_config.html.markdown b/website/docs/r/network_connectivity_multicloud_data_transfer_config.html.markdown index f3f7732ba39..6071479224f 100644 --- a/website/docs/r/network_connectivity_multicloud_data_transfer_config.html.markdown +++ b/website/docs/r/network_connectivity_multicloud_data_transfer_config.html.markdown @@ -89,6 +89,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `services` block supports: diff --git a/website/docs/r/network_connectivity_policy_based_route.html.markdown b/website/docs/r/network_connectivity_policy_based_route.html.markdown index 4ac879a2cd0..3cf48f575ee 100644 --- a/website/docs/r/network_connectivity_policy_based_route.html.markdown +++ b/website/docs/r/network_connectivity_policy_based_route.html.markdown @@ -154,6 +154,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `filter` block supports: diff --git a/website/docs/r/network_connectivity_regional_endpoint.html.markdown b/website/docs/r/network_connectivity_regional_endpoint.html.markdown index 531f838a51b..04a644b8fcd 100644 --- a/website/docs/r/network_connectivity_regional_endpoint.html.markdown +++ b/website/docs/r/network_connectivity_regional_endpoint.html.markdown @@ -145,6 +145,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/network_connectivity_service_connection_policy.html.markdown b/website/docs/r/network_connectivity_service_connection_policy.html.markdown index 6077c9d3a51..e27ad07251f 100644 --- a/website/docs/r/network_connectivity_service_connection_policy.html.markdown +++ b/website/docs/r/network_connectivity_service_connection_policy.html.markdown @@ -108,6 +108,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `psc_config` block supports: diff --git a/website/docs/r/network_connectivity_spoke.html.markdown b/website/docs/r/network_connectivity_spoke.html.markdown index 8cdd77c3cdf..810f42b194c 100644 --- a/website/docs/r/network_connectivity_spoke.html.markdown +++ b/website/docs/r/network_connectivity_spoke.html.markdown @@ -648,6 +648,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `linked_vpn_tunnels` block supports: diff --git a/website/docs/r/network_connectivity_transport.html.markdown b/website/docs/r/network_connectivity_transport.html.markdown index 1ed155f6f86..1429ea092f4 100644 --- a/website/docs/r/network_connectivity_transport.html.markdown +++ b/website/docs/r/network_connectivity_transport.html.markdown @@ -143,6 +143,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/network_management_connectivity_test.html.markdown b/website/docs/r/network_management_connectivity_test.html.markdown index e580084f923..03c22b8c7cc 100644 --- a/website/docs/r/network_management_connectivity_test.html.markdown +++ b/website/docs/r/network_management_connectivity_test.html.markdown @@ -259,6 +259,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `source` block supports: diff --git a/website/docs/r/network_management_organization_vpc_flow_logs_config.html.markdown b/website/docs/r/network_management_organization_vpc_flow_logs_config.html.markdown index 5bda6712ce2..9f90d87b411 100644 --- a/website/docs/r/network_management_organization_vpc_flow_logs_config.html.markdown +++ b/website/docs/r/network_management_organization_vpc_flow_logs_config.html.markdown @@ -111,6 +111,12 @@ The following arguments are supported: CROSS_PROJECT_METADATA_DISABLED Possible values are: `CROSS_PROJECT_METADATA_ENABLED`, `CROSS_PROJECT_METADATA_DISABLED`. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/network_management_vpc_flow_logs_config.html.markdown b/website/docs/r/network_management_vpc_flow_logs_config.html.markdown index 8d38799a24a..2df602764a3 100644 --- a/website/docs/r/network_management_vpc_flow_logs_config.html.markdown +++ b/website/docs/r/network_management_vpc_flow_logs_config.html.markdown @@ -272,6 +272,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/network_security_address_group.html.markdown b/website/docs/r/network_security_address_group.html.markdown index ad7586674d5..0622632abf0 100644 --- a/website/docs/r/network_security_address_group.html.markdown +++ b/website/docs/r/network_security_address_group.html.markdown @@ -135,6 +135,12 @@ The following arguments are supported: (Optional) The name of the parent this address group belongs to. Format: organizations/{organization_id} or projects/{project_id}. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/network_security_authorization_policy.html.markdown b/website/docs/r/network_security_authorization_policy.html.markdown index ea8969a464e..3e6bfccd572 100644 --- a/website/docs/r/network_security_authorization_policy.html.markdown +++ b/website/docs/r/network_security_authorization_policy.html.markdown @@ -129,6 +129,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `rules` block supports: diff --git a/website/docs/r/network_security_authz_policy.html.markdown b/website/docs/r/network_security_authz_policy.html.markdown index b678ce6eb94..712600da961 100644 --- a/website/docs/r/network_security_authz_policy.html.markdown +++ b/website/docs/r/network_security_authz_policy.html.markdown @@ -376,6 +376,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `target` block supports: diff --git a/website/docs/r/network_security_backend_authentication_config.html.markdown b/website/docs/r/network_security_backend_authentication_config.html.markdown index 93c6c04c9d9..8390fb49e52 100644 --- a/website/docs/r/network_security_backend_authentication_config.html.markdown +++ b/website/docs/r/network_security_backend_authentication_config.html.markdown @@ -183,6 +183,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/network_security_client_tls_policy.html.markdown b/website/docs/r/network_security_client_tls_policy.html.markdown index 565f4e23644..ab07587f2fb 100644 --- a/website/docs/r/network_security_client_tls_policy.html.markdown +++ b/website/docs/r/network_security_client_tls_policy.html.markdown @@ -118,6 +118,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `client_certificate` block supports: diff --git a/website/docs/r/network_security_dns_threat_detector.html.markdown b/website/docs/r/network_security_dns_threat_detector.html.markdown index de4253a04d8..30bd5bac4af 100644 --- a/website/docs/r/network_security_dns_threat_detector.html.markdown +++ b/website/docs/r/network_security_dns_threat_detector.html.markdown @@ -83,6 +83,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/network_security_firewall_endpoint.html.markdown b/website/docs/r/network_security_firewall_endpoint.html.markdown index 43a96843d80..2cdc5187526 100644 --- a/website/docs/r/network_security_firewall_endpoint.html.markdown +++ b/website/docs/r/network_security_firewall_endpoint.html.markdown @@ -109,6 +109,12 @@ The following arguments are supported: Settings for the endpoint. Structure is [documented below](#nested_endpoint_settings). +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `endpoint_settings` block supports: diff --git a/website/docs/r/network_security_firewall_endpoint_association.html.markdown b/website/docs/r/network_security_firewall_endpoint_association.html.markdown index 12a5cf31af3..411f3c0c0db 100644 --- a/website/docs/r/network_security_firewall_endpoint_association.html.markdown +++ b/website/docs/r/network_security_firewall_endpoint_association.html.markdown @@ -119,6 +119,12 @@ The following arguments are supported: The name of the parent this firewall endpoint association belongs to. Format: projects/{project_id}. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/network_security_gateway_security_policy.html.markdown b/website/docs/r/network_security_gateway_security_policy.html.markdown index 0ac01d71948..82cf9fe5a2f 100644 --- a/website/docs/r/network_security_gateway_security_policy.html.markdown +++ b/website/docs/r/network_security_gateway_security_policy.html.markdown @@ -164,6 +164,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/network_security_gateway_security_policy_rule.html.markdown b/website/docs/r/network_security_gateway_security_policy_rule.html.markdown index af37d415504..35f6fb210cb 100644 --- a/website/docs/r/network_security_gateway_security_policy_rule.html.markdown +++ b/website/docs/r/network_security_gateway_security_policy_rule.html.markdown @@ -137,6 +137,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/network_security_intercept_deployment.html.markdown b/website/docs/r/network_security_intercept_deployment.html.markdown index 6fcd8fde2c4..9feeda4e2f6 100644 --- a/website/docs/r/network_security_intercept_deployment.html.markdown +++ b/website/docs/r/network_security_intercept_deployment.html.markdown @@ -136,6 +136,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/network_security_intercept_deployment_group.html.markdown b/website/docs/r/network_security_intercept_deployment_group.html.markdown index e00b64ba212..e5ca3fa562f 100644 --- a/website/docs/r/network_security_intercept_deployment_group.html.markdown +++ b/website/docs/r/network_security_intercept_deployment_group.html.markdown @@ -88,6 +88,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/network_security_intercept_endpoint_group.html.markdown b/website/docs/r/network_security_intercept_endpoint_group.html.markdown index 35f0870f549..7fcfa0662d0 100644 --- a/website/docs/r/network_security_intercept_endpoint_group.html.markdown +++ b/website/docs/r/network_security_intercept_endpoint_group.html.markdown @@ -95,6 +95,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/network_security_intercept_endpoint_group_association.html.markdown b/website/docs/r/network_security_intercept_endpoint_group_association.html.markdown index 909b44f305b..71e98231155 100644 --- a/website/docs/r/network_security_intercept_endpoint_group_association.html.markdown +++ b/website/docs/r/network_security_intercept_endpoint_group_association.html.markdown @@ -111,6 +111,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/network_security_mirroring_deployment.html.markdown b/website/docs/r/network_security_mirroring_deployment.html.markdown index 2ebdaa2ceaa..4c6c8cf3f14 100644 --- a/website/docs/r/network_security_mirroring_deployment.html.markdown +++ b/website/docs/r/network_security_mirroring_deployment.html.markdown @@ -142,6 +142,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/network_security_mirroring_deployment_group.html.markdown b/website/docs/r/network_security_mirroring_deployment_group.html.markdown index e2e9081f3be..a619e6b1487 100644 --- a/website/docs/r/network_security_mirroring_deployment_group.html.markdown +++ b/website/docs/r/network_security_mirroring_deployment_group.html.markdown @@ -93,6 +93,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/network_security_mirroring_endpoint.html.markdown b/website/docs/r/network_security_mirroring_endpoint.html.markdown index 124372f2999..4bc2eb03c3e 100644 --- a/website/docs/r/network_security_mirroring_endpoint.html.markdown +++ b/website/docs/r/network_security_mirroring_endpoint.html.markdown @@ -102,6 +102,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/network_security_mirroring_endpoint_group.html.markdown b/website/docs/r/network_security_mirroring_endpoint_group.html.markdown index d68b51516a1..f9198a74f99 100644 --- a/website/docs/r/network_security_mirroring_endpoint_group.html.markdown +++ b/website/docs/r/network_security_mirroring_endpoint_group.html.markdown @@ -146,6 +146,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/network_security_mirroring_endpoint_group_association.html.markdown b/website/docs/r/network_security_mirroring_endpoint_group_association.html.markdown index 73368c4a85f..d09fedce60c 100644 --- a/website/docs/r/network_security_mirroring_endpoint_group_association.html.markdown +++ b/website/docs/r/network_security_mirroring_endpoint_group_association.html.markdown @@ -116,6 +116,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/network_security_sac_attachment.html.markdown b/website/docs/r/network_security_sac_attachment.html.markdown index c8ab2677ec8..292727129da 100644 --- a/website/docs/r/network_security_sac_attachment.html.markdown +++ b/website/docs/r/network_security_sac_attachment.html.markdown @@ -93,6 +93,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `symantec_options` block supports: diff --git a/website/docs/r/network_security_sac_realm.html.markdown b/website/docs/r/network_security_sac_realm.html.markdown index e0978e6ea61..9ad8a22ee95 100644 --- a/website/docs/r/network_security_sac_realm.html.markdown +++ b/website/docs/r/network_security_sac_realm.html.markdown @@ -97,6 +97,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `symantec_options` block supports: diff --git a/website/docs/r/network_security_security_profile.html.markdown b/website/docs/r/network_security_security_profile.html.markdown index 965501b179d..6d6d5420c6b 100644 --- a/website/docs/r/network_security_security_profile.html.markdown +++ b/website/docs/r/network_security_security_profile.html.markdown @@ -267,6 +267,12 @@ The following arguments are supported: The name of the parent this security profile belongs to. Format: `organizations/{organization_id}` or `projects/{project_id}`. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `threat_prevention_profile` block supports: diff --git a/website/docs/r/network_security_security_profile_group.html.markdown b/website/docs/r/network_security_security_profile_group.html.markdown index 57b47797c7a..ae5b2f10b50 100644 --- a/website/docs/r/network_security_security_profile_group.html.markdown +++ b/website/docs/r/network_security_security_profile_group.html.markdown @@ -219,6 +219,12 @@ The following arguments are supported: The name of the parent this security profile group belongs to. Format: `organizations/{organization_id}` or `projects/{project_id}`. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/network_security_server_tls_policy.html.markdown b/website/docs/r/network_security_server_tls_policy.html.markdown index 12eee48e849..cf932915ccb 100644 --- a/website/docs/r/network_security_server_tls_policy.html.markdown +++ b/website/docs/r/network_security_server_tls_policy.html.markdown @@ -200,6 +200,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `server_certificate` block supports: diff --git a/website/docs/r/network_security_tls_inspection_policy.html.markdown b/website/docs/r/network_security_tls_inspection_policy.html.markdown index 43a9b800027..95eba9bd4a4 100644 --- a/website/docs/r/network_security_tls_inspection_policy.html.markdown +++ b/website/docs/r/network_security_tls_inspection_policy.html.markdown @@ -306,6 +306,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/network_security_ull_mirroring_collector.html.markdown b/website/docs/r/network_security_ull_mirroring_collector.html.markdown index 89b664b510a..43444a92811 100644 --- a/website/docs/r/network_security_ull_mirroring_collector.html.markdown +++ b/website/docs/r/network_security_ull_mirroring_collector.html.markdown @@ -131,6 +131,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/network_security_ull_mirroring_collector_rule.html.markdown b/website/docs/r/network_security_ull_mirroring_collector_rule.html.markdown index 6f9bfbbe778..756cc1bc44a 100644 --- a/website/docs/r/network_security_ull_mirroring_collector_rule.html.markdown +++ b/website/docs/r/network_security_ull_mirroring_collector_rule.html.markdown @@ -140,6 +140,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `match` block supports: diff --git a/website/docs/r/network_security_ull_mirroring_engine.html.markdown b/website/docs/r/network_security_ull_mirroring_engine.html.markdown index 5efa045d336..3246381dbc2 100644 --- a/website/docs/r/network_security_ull_mirroring_engine.html.markdown +++ b/website/docs/r/network_security_ull_mirroring_engine.html.markdown @@ -67,6 +67,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/network_security_url_lists.html.markdown b/website/docs/r/network_security_url_lists.html.markdown index 62f5dff3c7f..eef14a37212 100644 --- a/website/docs/r/network_security_url_lists.html.markdown +++ b/website/docs/r/network_security_url_lists.html.markdown @@ -88,6 +88,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/network_services_agent_gateway.html.markdown b/website/docs/r/network_services_agent_gateway.html.markdown index 985d656c2a8..d4b830ad47d 100644 --- a/website/docs/r/network_services_agent_gateway.html.markdown +++ b/website/docs/r/network_services_agent_gateway.html.markdown @@ -154,6 +154,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `google_managed` block supports: diff --git a/website/docs/r/network_services_authz_extension.html.markdown b/website/docs/r/network_services_authz_extension.html.markdown index dbc5e764c5b..95ef8ac6c22 100644 --- a/website/docs/r/network_services_authz_extension.html.markdown +++ b/website/docs/r/network_services_authz_extension.html.markdown @@ -193,6 +193,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/network_services_edge_cache_keyset.html.markdown b/website/docs/r/network_services_edge_cache_keyset.html.markdown index 0640505b873..5cfa5389d53 100644 --- a/website/docs/r/network_services_edge_cache_keyset.html.markdown +++ b/website/docs/r/network_services_edge_cache_keyset.html.markdown @@ -136,6 +136,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `public_key` block supports: diff --git a/website/docs/r/network_services_edge_cache_origin.html.markdown b/website/docs/r/network_services_edge_cache_origin.html.markdown index db9f21ce2c5..59b59f4d0e2 100644 --- a/website/docs/r/network_services_edge_cache_origin.html.markdown +++ b/website/docs/r/network_services_edge_cache_origin.html.markdown @@ -250,6 +250,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `timeout` block supports: diff --git a/website/docs/r/network_services_edge_cache_service.html.markdown b/website/docs/r/network_services_edge_cache_service.html.markdown index 9e528ed0bc5..e8ec4f9cc23 100644 --- a/website/docs/r/network_services_edge_cache_service.html.markdown +++ b/website/docs/r/network_services_edge_cache_service.html.markdown @@ -472,6 +472,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `routing` block supports: diff --git a/website/docs/r/network_services_endpoint_policy.html.markdown b/website/docs/r/network_services_endpoint_policy.html.markdown index 6c9d9ff830c..e05dc10ea2e 100644 --- a/website/docs/r/network_services_endpoint_policy.html.markdown +++ b/website/docs/r/network_services_endpoint_policy.html.markdown @@ -137,6 +137,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `endpoint_matcher` block supports: diff --git a/website/docs/r/network_services_gateway.html.markdown b/website/docs/r/network_services_gateway.html.markdown index 6dcc0b8ee19..7ea6553b2c8 100644 --- a/website/docs/r/network_services_gateway.html.markdown +++ b/website/docs/r/network_services_gateway.html.markdown @@ -331,6 +331,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. * `delete_swg_autogen_router_on_destroy` - (Optional) When deleting a gateway of type 'SECURE_WEB_GATEWAY', this boolean option will also delete auto generated router by the gateway creation. If there is no other gateway of type 'SECURE_WEB_GATEWAY' remaining for that region and network it will be deleted. diff --git a/website/docs/r/network_services_grpc_route.html.markdown b/website/docs/r/network_services_grpc_route.html.markdown index 56fdd097b14..a9c4ed9383d 100644 --- a/website/docs/r/network_services_grpc_route.html.markdown +++ b/website/docs/r/network_services_grpc_route.html.markdown @@ -224,6 +224,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `rules` block supports: diff --git a/website/docs/r/network_services_http_route.html.markdown b/website/docs/r/network_services_http_route.html.markdown index 92c40bfdccd..f54faf22149 100644 --- a/website/docs/r/network_services_http_route.html.markdown +++ b/website/docs/r/network_services_http_route.html.markdown @@ -298,6 +298,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `rules` block supports: diff --git a/website/docs/r/network_services_lb_edge_extension.html.markdown b/website/docs/r/network_services_lb_edge_extension.html.markdown index 4627a884b80..23323030664 100644 --- a/website/docs/r/network_services_lb_edge_extension.html.markdown +++ b/website/docs/r/network_services_lb_edge_extension.html.markdown @@ -179,6 +179,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `extension_chains` block supports: diff --git a/website/docs/r/network_services_lb_route_extension.html.markdown b/website/docs/r/network_services_lb_route_extension.html.markdown index 0dcf368197d..a9bc0693cbc 100644 --- a/website/docs/r/network_services_lb_route_extension.html.markdown +++ b/website/docs/r/network_services_lb_route_extension.html.markdown @@ -802,6 +802,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `extension_chains` block supports: diff --git a/website/docs/r/network_services_lb_traffic_extension.html.markdown b/website/docs/r/network_services_lb_traffic_extension.html.markdown index 8045f2ae88f..f24e1d617e8 100644 --- a/website/docs/r/network_services_lb_traffic_extension.html.markdown +++ b/website/docs/r/network_services_lb_traffic_extension.html.markdown @@ -427,6 +427,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `extension_chains` block supports: diff --git a/website/docs/r/network_services_mesh.html.markdown b/website/docs/r/network_services_mesh.html.markdown index 532a49471d9..e2557e088cb 100644 --- a/website/docs/r/network_services_mesh.html.markdown +++ b/website/docs/r/network_services_mesh.html.markdown @@ -116,6 +116,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/network_services_multicast_consumer_association.html.markdown b/website/docs/r/network_services_multicast_consumer_association.html.markdown index ecd6a5de4e2..937b74b6202 100644 --- a/website/docs/r/network_services_multicast_consumer_association.html.markdown +++ b/website/docs/r/network_services_multicast_consumer_association.html.markdown @@ -110,6 +110,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/network_services_multicast_domain.html.markdown b/website/docs/r/network_services_multicast_domain.html.markdown index 6eb49511f52..a167e6c01e8 100644 --- a/website/docs/r/network_services_multicast_domain.html.markdown +++ b/website/docs/r/network_services_multicast_domain.html.markdown @@ -113,6 +113,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `connection_config` block supports: diff --git a/website/docs/r/network_services_multicast_domain_activation.html.markdown b/website/docs/r/network_services_multicast_domain_activation.html.markdown index c0675b50425..27316600e82 100644 --- a/website/docs/r/network_services_multicast_domain_activation.html.markdown +++ b/website/docs/r/network_services_multicast_domain_activation.html.markdown @@ -107,6 +107,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `traffic_spec` block supports: diff --git a/website/docs/r/network_services_multicast_domain_group.html.markdown b/website/docs/r/network_services_multicast_domain_group.html.markdown index c93b7800670..d437a124bdf 100644 --- a/website/docs/r/network_services_multicast_domain_group.html.markdown +++ b/website/docs/r/network_services_multicast_domain_group.html.markdown @@ -102,6 +102,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/network_services_multicast_group_consumer_activation.html.markdown b/website/docs/r/network_services_multicast_group_consumer_activation.html.markdown index c6890a89fa9..3bbb079e42c 100644 --- a/website/docs/r/network_services_multicast_group_consumer_activation.html.markdown +++ b/website/docs/r/network_services_multicast_group_consumer_activation.html.markdown @@ -146,6 +146,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `log_config` block supports: diff --git a/website/docs/r/network_services_multicast_group_producer_activation.html.markdown b/website/docs/r/network_services_multicast_group_producer_activation.html.markdown index 3ebe47923b2..c6e286e7b01 100644 --- a/website/docs/r/network_services_multicast_group_producer_activation.html.markdown +++ b/website/docs/r/network_services_multicast_group_producer_activation.html.markdown @@ -141,6 +141,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/network_services_multicast_group_range.html.markdown b/website/docs/r/network_services_multicast_group_range.html.markdown index c0558c2bdeb..23559ea1eb2 100644 --- a/website/docs/r/network_services_multicast_group_range.html.markdown +++ b/website/docs/r/network_services_multicast_group_range.html.markdown @@ -143,6 +143,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `log_config` block supports: diff --git a/website/docs/r/network_services_multicast_group_range_activation.html.markdown b/website/docs/r/network_services_multicast_group_range_activation.html.markdown index ed1a8e38ed7..63f0472f90a 100644 --- a/website/docs/r/network_services_multicast_group_range_activation.html.markdown +++ b/website/docs/r/network_services_multicast_group_range_activation.html.markdown @@ -133,6 +133,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `log_config` block supports: diff --git a/website/docs/r/network_services_multicast_producer_association.html.markdown b/website/docs/r/network_services_multicast_producer_association.html.markdown index 4e6f09f358c..c0bd69ea2a9 100644 --- a/website/docs/r/network_services_multicast_producer_association.html.markdown +++ b/website/docs/r/network_services_multicast_producer_association.html.markdown @@ -110,6 +110,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/network_services_service_binding.html.markdown b/website/docs/r/network_services_service_binding.html.markdown index 4eaeb90e231..ddb39b59fa8 100644 --- a/website/docs/r/network_services_service_binding.html.markdown +++ b/website/docs/r/network_services_service_binding.html.markdown @@ -88,6 +88,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/network_services_service_lb_policies.html.markdown b/website/docs/r/network_services_service_lb_policies.html.markdown index 40fa77d3ada..08ac64531ec 100644 --- a/website/docs/r/network_services_service_lb_policies.html.markdown +++ b/website/docs/r/network_services_service_lb_policies.html.markdown @@ -179,6 +179,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `auto_capacity_drain` block supports: diff --git a/website/docs/r/network_services_tcp_route.html.markdown b/website/docs/r/network_services_tcp_route.html.markdown index cb25b7bbba0..8d7a89a7cd6 100644 --- a/website/docs/r/network_services_tcp_route.html.markdown +++ b/website/docs/r/network_services_tcp_route.html.markdown @@ -271,6 +271,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `rules` block supports: diff --git a/website/docs/r/network_services_tls_route.html.markdown b/website/docs/r/network_services_tls_route.html.markdown index 98d440d2caa..f342d01688a 100644 --- a/website/docs/r/network_services_tls_route.html.markdown +++ b/website/docs/r/network_services_tls_route.html.markdown @@ -372,6 +372,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `rules` block supports: diff --git a/website/docs/r/network_services_wasm_plugin.html.markdown b/website/docs/r/network_services_wasm_plugin.html.markdown index 34a93ce747c..6f9917429f0 100644 --- a/website/docs/r/network_services_wasm_plugin.html.markdown +++ b/website/docs/r/network_services_wasm_plugin.html.markdown @@ -137,6 +137,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `versions` block supports: diff --git a/website/docs/r/notebooks_environment.html.markdown b/website/docs/r/notebooks_environment.html.markdown index e95fb8ddfaf..6c32b42d682 100644 --- a/website/docs/r/notebooks_environment.html.markdown +++ b/website/docs/r/notebooks_environment.html.markdown @@ -90,6 +90,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `vm_image` block supports: diff --git a/website/docs/r/notebooks_instance.html.markdown b/website/docs/r/notebooks_instance.html.markdown index d52b74128f9..c6655edf334 100644 --- a/website/docs/r/notebooks_instance.html.markdown +++ b/website/docs/r/notebooks_instance.html.markdown @@ -347,6 +347,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. * `desired_state` - (Optional) Desired state of the Notebook Instance. Set this field to `ACTIVE` to start the Instance, and `STOPPED` to stop the Instance. diff --git a/website/docs/r/notebooks_runtime.html.markdown b/website/docs/r/notebooks_runtime.html.markdown index 517493b709f..38b78647114 100644 --- a/website/docs/r/notebooks_runtime.html.markdown +++ b/website/docs/r/notebooks_runtime.html.markdown @@ -256,6 +256,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `virtual_machine` block supports: diff --git a/website/docs/r/observability_folder_settings.html.markdown b/website/docs/r/observability_folder_settings.html.markdown index 6b642edb620..2a3859686e7 100644 --- a/website/docs/r/observability_folder_settings.html.markdown +++ b/website/docs/r/observability_folder_settings.html.markdown @@ -128,6 +128,12 @@ The following arguments are supported: (Optional) The default Cloud KMS key to use for new resources. Only valid for regional locations. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/observability_organization_settings.html.markdown b/website/docs/r/observability_organization_settings.html.markdown index a66555fff1f..08d5f3d3ee9 100644 --- a/website/docs/r/observability_organization_settings.html.markdown +++ b/website/docs/r/observability_organization_settings.html.markdown @@ -99,6 +99,12 @@ The following arguments are supported: (Optional) The default Cloud KMS key to use for new resources. Only valid for regional locations. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/observability_project_settings.html.markdown b/website/docs/r/observability_project_settings.html.markdown index 7741e3e9cca..d4d082282a1 100644 --- a/website/docs/r/observability_project_settings.html.markdown +++ b/website/docs/r/observability_project_settings.html.markdown @@ -142,6 +142,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/observability_trace_scope.html.markdown b/website/docs/r/observability_trace_scope.html.markdown index 38ee982693e..38c81c86c40 100644 --- a/website/docs/r/observability_trace_scope.html.markdown +++ b/website/docs/r/observability_trace_scope.html.markdown @@ -79,6 +79,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/oracle_database_autonomous_database.html.markdown b/website/docs/r/oracle_database_autonomous_database.html.markdown index 0c572ecec9c..80757a8fbe8 100644 --- a/website/docs/r/oracle_database_autonomous_database.html.markdown +++ b/website/docs/r/oracle_database_autonomous_database.html.markdown @@ -278,6 +278,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. * `deletion_protection` - (Optional) Whether or not to allow Terraform to destroy the instance. Unless this field is set to false in Terraform state, a terraform destroy or terraform apply that would delete the instance will fail. diff --git a/website/docs/r/oracle_database_cloud_exadata_infrastructure.html.markdown b/website/docs/r/oracle_database_cloud_exadata_infrastructure.html.markdown index 1ab50f2ed71..417d14f14d2 100644 --- a/website/docs/r/oracle_database_cloud_exadata_infrastructure.html.markdown +++ b/website/docs/r/oracle_database_cloud_exadata_infrastructure.html.markdown @@ -135,6 +135,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. * `deletion_protection` - (Optional) Whether or not to allow Terraform to destroy the instance. Unless this field is set to false in Terraform state, a terraform destroy or terraform apply that would delete the instance will fail. diff --git a/website/docs/r/oracle_database_cloud_vm_cluster.html.markdown b/website/docs/r/oracle_database_cloud_vm_cluster.html.markdown index 1d9cb7e2b2f..d6201fb7039 100644 --- a/website/docs/r/oracle_database_cloud_vm_cluster.html.markdown +++ b/website/docs/r/oracle_database_cloud_vm_cluster.html.markdown @@ -271,6 +271,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. * `deletion_protection` - (Optional) Whether Terraform will be prevented from destroying the cluster. Deleting this cluster via terraform destroy or terraform apply will only succeed if this field is false in the Terraform state. diff --git a/website/docs/r/oracle_database_db_system.html.markdown b/website/docs/r/oracle_database_db_system.html.markdown index 6699117b674..6338f2e8c6f 100644 --- a/website/docs/r/oracle_database_db_system.html.markdown +++ b/website/docs/r/oracle_database_db_system.html.markdown @@ -167,6 +167,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. * `deletion_protection` - (Optional) Whether or not to allow Terraform to destroy the instance. Unless this field is set to false in Terraform state, a terraform destroy or terraform apply that would delete the instance will fail. diff --git a/website/docs/r/oracle_database_exadb_vm_cluster.html.markdown b/website/docs/r/oracle_database_exadb_vm_cluster.html.markdown index deb76a9df49..b2dcebd90c6 100644 --- a/website/docs/r/oracle_database_exadb_vm_cluster.html.markdown +++ b/website/docs/r/oracle_database_exadb_vm_cluster.html.markdown @@ -198,6 +198,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. * `deletion_protection` - (Optional) Whether or not to allow Terraform to destroy the instance. Unless this field is set to false in Terraform state, a terraform destroy or terraform apply that would delete the instance will fail. diff --git a/website/docs/r/oracle_database_exascale_db_storage_vault.html.markdown b/website/docs/r/oracle_database_exascale_db_storage_vault.html.markdown index b28ffd44bb3..479e49edb09 100644 --- a/website/docs/r/oracle_database_exascale_db_storage_vault.html.markdown +++ b/website/docs/r/oracle_database_exascale_db_storage_vault.html.markdown @@ -124,6 +124,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. * `deletion_protection` - (Optional) Whether or not to allow Terraform to destroy the instance. Unless this field is set to false in Terraform state, a terraform destroy or terraform apply that would delete the instance will fail. diff --git a/website/docs/r/oracle_database_odb_network.html.markdown b/website/docs/r/oracle_database_odb_network.html.markdown index 7e47709c35a..e952fac7ec0 100644 --- a/website/docs/r/oracle_database_odb_network.html.markdown +++ b/website/docs/r/oracle_database_odb_network.html.markdown @@ -117,6 +117,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. * `deletion_protection` - (Optional) Whether or not to allow Terraform to destroy the instance. Unless this field is set to false in Terraform state, a terraform destroy or terraform apply that would delete the instance will fail. diff --git a/website/docs/r/oracle_database_odb_subnet.html.markdown b/website/docs/r/oracle_database_odb_subnet.html.markdown index 01f2ac3876f..a8422134f0e 100644 --- a/website/docs/r/oracle_database_odb_subnet.html.markdown +++ b/website/docs/r/oracle_database_odb_subnet.html.markdown @@ -92,6 +92,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. * `deletion_protection` - (Optional) Whether or not to allow Terraform to destroy the instance. Unless this field is set to false in Terraform state, a terraform destroy or terraform apply that would delete the instance will fail. diff --git a/website/docs/r/org_policy_custom_constraint.html.markdown b/website/docs/r/org_policy_custom_constraint.html.markdown index 6ce0034be42..8fbdd9246ef 100644 --- a/website/docs/r/org_policy_custom_constraint.html.markdown +++ b/website/docs/r/org_policy_custom_constraint.html.markdown @@ -115,6 +115,12 @@ The following arguments are supported: (Optional) A human-friendly description of the constraint to display as an error message when the policy is violated. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/org_policy_policy.html.markdown b/website/docs/r/org_policy_policy.html.markdown index d59bdc7d0d2..04ccc06b187 100644 --- a/website/docs/r/org_policy_policy.html.markdown +++ b/website/docs/r/org_policy_policy.html.markdown @@ -207,6 +207,12 @@ The following arguments are supported: Dry-run policy. Audit-only policy, can be used to monitor how the policy would have impacted the existing and future resources if it's enforced. Structure is [documented below](#nested_dry_run_spec). +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `spec` block supports: diff --git a/website/docs/r/organization_access_approval_settings.html.markdown b/website/docs/r/organization_access_approval_settings.html.markdown index c3945c184c5..c1fa403beb8 100644 --- a/website/docs/r/organization_access_approval_settings.html.markdown +++ b/website/docs/r/organization_access_approval_settings.html.markdown @@ -128,6 +128,12 @@ The following arguments are supported: The asymmetric crypto key version to use for signing approval requests. Empty active_key_version indicates that a Google-managed key should be used for signing. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `enrolled_services` block supports: diff --git a/website/docs/r/os_config_guest_policies.html.markdown b/website/docs/r/os_config_guest_policies.html.markdown index a7d9353fc14..38495c12707 100644 --- a/website/docs/r/os_config_guest_policies.html.markdown +++ b/website/docs/r/os_config_guest_policies.html.markdown @@ -244,6 +244,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `assignment` block supports: diff --git a/website/docs/r/os_config_os_policy_assignment.html.markdown b/website/docs/r/os_config_os_policy_assignment.html.markdown index cd76300e6b9..6398b24f6a4 100644 --- a/website/docs/r/os_config_os_policy_assignment.html.markdown +++ b/website/docs/r/os_config_os_policy_assignment.html.markdown @@ -144,6 +144,13 @@ The following arguments are supported: * `location` - (Required) The location for the resource +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. + The `os_policies` block supports: * `id` - (Required) The id of the OS policy with the following restrictions: diff --git a/website/docs/r/os_config_patch_deployment.html.markdown b/website/docs/r/os_config_patch_deployment.html.markdown index 2d58ef01a38..77632bc54a2 100644 --- a/website/docs/r/os_config_patch_deployment.html.markdown +++ b/website/docs/r/os_config_patch_deployment.html.markdown @@ -354,6 +354,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `instance_filter` block supports: diff --git a/website/docs/r/os_config_v2_policy_orchestrator.html.markdown b/website/docs/r/os_config_v2_policy_orchestrator.html.markdown index 209031a3172..54f0600ad77 100644 --- a/website/docs/r/os_config_v2_policy_orchestrator.html.markdown +++ b/website/docs/r/os_config_v2_policy_orchestrator.html.markdown @@ -131,6 +131,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `orchestrated_resource` block supports: diff --git a/website/docs/r/os_config_v2_policy_orchestrator_for_folder.html.markdown b/website/docs/r/os_config_v2_policy_orchestrator_for_folder.html.markdown index 54e34abbb46..8f917eec6f1 100644 --- a/website/docs/r/os_config_v2_policy_orchestrator_for_folder.html.markdown +++ b/website/docs/r/os_config_v2_policy_orchestrator_for_folder.html.markdown @@ -199,6 +199,12 @@ The following arguments are supported: **Note**: This field is non-authoritative, and will only manage the labels present in your configuration. Please refer to the field `effective_labels` for all of the labels present on the resource. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `orchestrated_resource` block supports: diff --git a/website/docs/r/os_config_v2_policy_orchestrator_for_organization.html.markdown b/website/docs/r/os_config_v2_policy_orchestrator_for_organization.html.markdown index 1325d1ebd55..25e29d5f2df 100644 --- a/website/docs/r/os_config_v2_policy_orchestrator_for_organization.html.markdown +++ b/website/docs/r/os_config_v2_policy_orchestrator_for_organization.html.markdown @@ -143,6 +143,12 @@ The following arguments are supported: (Optional) Optional. Freeform text describing the purpose of the resource. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `orchestrated_resource` block supports: diff --git a/website/docs/r/os_login_ssh_public_key.html.markdown b/website/docs/r/os_login_ssh_public_key.html.markdown index b0d209ebb8b..25fcad2f88c 100644 --- a/website/docs/r/os_login_ssh_public_key.html.markdown +++ b/website/docs/r/os_login_ssh_public_key.html.markdown @@ -70,6 +70,12 @@ The following arguments are supported: (Optional) The project ID of the Google Cloud Platform project. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/parallelstore_instance.html.markdown b/website/docs/r/parallelstore_instance.html.markdown index 934233e382b..5642c392a51 100644 --- a/website/docs/r/parallelstore_instance.html.markdown +++ b/website/docs/r/parallelstore_instance.html.markdown @@ -218,6 +218,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/parameter_manager_parameter.html.markdown b/website/docs/r/parameter_manager_parameter.html.markdown index 6056ff994cc..9d3f9b5288f 100644 --- a/website/docs/r/parameter_manager_parameter.html.markdown +++ b/website/docs/r/parameter_manager_parameter.html.markdown @@ -131,6 +131,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/parameter_manager_parameter_version.html.markdown b/website/docs/r/parameter_manager_parameter_version.html.markdown index 0f9794bcdbc..3c3a91b02cb 100644 --- a/website/docs/r/parameter_manager_parameter_version.html.markdown +++ b/website/docs/r/parameter_manager_parameter_version.html.markdown @@ -183,6 +183,12 @@ The following arguments are supported: (Optional) The current state of Parameter Version. This field is only applicable for updating Parameter Version. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/parameter_manager_regional_parameter.html.markdown b/website/docs/r/parameter_manager_regional_parameter.html.markdown index 6eb50e9eb2a..12f2c725086 100644 --- a/website/docs/r/parameter_manager_regional_parameter.html.markdown +++ b/website/docs/r/parameter_manager_regional_parameter.html.markdown @@ -140,6 +140,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/parameter_manager_regional_parameter_version.html.markdown b/website/docs/r/parameter_manager_regional_parameter_version.html.markdown index 369aa730f8f..269f73d48da 100644 --- a/website/docs/r/parameter_manager_regional_parameter_version.html.markdown +++ b/website/docs/r/parameter_manager_regional_parameter_version.html.markdown @@ -190,6 +190,12 @@ The following arguments are supported: (Optional) The current state of Regional Parameter Version. This field is only applicable for updating Regional Parameter Version. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/privateca_ca_pool.html.markdown b/website/docs/r/privateca_ca_pool.html.markdown index b53812c9661..6aecb94d781 100644 --- a/website/docs/r/privateca_ca_pool.html.markdown +++ b/website/docs/r/privateca_ca_pool.html.markdown @@ -224,6 +224,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `issuance_policy` block supports: diff --git a/website/docs/r/privateca_certificate.html.markdown b/website/docs/r/privateca_certificate.html.markdown index a42af78cd00..e0e9a8bb75b 100644 --- a/website/docs/r/privateca_certificate.html.markdown +++ b/website/docs/r/privateca_certificate.html.markdown @@ -584,6 +584,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `config` block supports: diff --git a/website/docs/r/privateca_certificate_authority.html.markdown b/website/docs/r/privateca_certificate_authority.html.markdown index 264b8ddaa60..34607a995ec 100644 --- a/website/docs/r/privateca_certificate_authority.html.markdown +++ b/website/docs/r/privateca_certificate_authority.html.markdown @@ -475,6 +475,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. * `deletion_protection` - (Optional) Whether Terraform will be prevented from destroying the CertificateAuthority. When the field is set to true or unset in Terraform state, a `terraform apply` or `terraform destroy` that would delete the CertificateAuthority will fail. diff --git a/website/docs/r/privateca_certificate_template.html.markdown b/website/docs/r/privateca_certificate_template.html.markdown index 05d74d3b9e8..ccb9dbcf527 100644 --- a/website/docs/r/privateca_certificate_template.html.markdown +++ b/website/docs/r/privateca_certificate_template.html.markdown @@ -256,6 +256,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `predefined_values` block supports: diff --git a/website/docs/r/privileged_access_manager_entitlement.html.markdown b/website/docs/r/privileged_access_manager_entitlement.html.markdown index 984af5aa126..343f83633a6 100644 --- a/website/docs/r/privileged_access_manager_entitlement.html.markdown +++ b/website/docs/r/privileged_access_manager_entitlement.html.markdown @@ -137,6 +137,12 @@ The following arguments are supported: AdditionalNotificationTargets includes email addresses to be notified. Structure is [documented below](#nested_additional_notification_targets). +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `eligible_users` block supports: diff --git a/website/docs/r/privileged_access_manager_settings.html.markdown b/website/docs/r/privileged_access_manager_settings.html.markdown index 2996739dad1..cc3d5c8c878 100644 --- a/website/docs/r/privileged_access_manager_settings.html.markdown +++ b/website/docs/r/privileged_access_manager_settings.html.markdown @@ -93,6 +93,12 @@ The following arguments are supported: EmailNotificationSettings defines node-wide email notification preferences for various PAM events. Structure is [documented below](#nested_email_notification_settings). +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `service_account_approver_settings` block supports: diff --git a/website/docs/r/project_access_approval_settings.html.markdown b/website/docs/r/project_access_approval_settings.html.markdown index dc6123e61ef..c3ff69cb320 100644 --- a/website/docs/r/project_access_approval_settings.html.markdown +++ b/website/docs/r/project_access_approval_settings.html.markdown @@ -124,6 +124,12 @@ The following arguments are supported: ~> **Warning:** `project` is deprecated and will be removed in a future major release. Use `project_id` instead. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `enrolled_services` block supports: diff --git a/website/docs/r/project_usage_export_bucket.html.markdown b/website/docs/r/project_usage_export_bucket.html.markdown index fb9cd3b51cf..5171431794c 100644 --- a/website/docs/r/project_usage_export_bucket.html.markdown +++ b/website/docs/r/project_usage_export_bucket.html.markdown @@ -50,6 +50,14 @@ resource "google_project_usage_export_bucket" "usage_export" { * `project`: (Optional) The project to set the export bucket on. If it is not provided, the provider project is used. + +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. + ## Timeouts This resource provides the following diff --git a/website/docs/r/public_ca_external_account_key.html.markdown b/website/docs/r/public_ca_external_account_key.html.markdown index 95718b32a45..e59d656c8a5 100644 --- a/website/docs/r/public_ca_external_account_key.html.markdown +++ b/website/docs/r/public_ca_external_account_key.html.markdown @@ -64,6 +64,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/pubsub_lite_reservation.html.markdown b/website/docs/r/pubsub_lite_reservation.html.markdown index dfb82ff90d5..d3cbda3b2f4 100644 --- a/website/docs/r/pubsub_lite_reservation.html.markdown +++ b/website/docs/r/pubsub_lite_reservation.html.markdown @@ -73,6 +73,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/pubsub_lite_subscription.html.markdown b/website/docs/r/pubsub_lite_subscription.html.markdown index 4976feda5c5..212678f9e3e 100644 --- a/website/docs/r/pubsub_lite_subscription.html.markdown +++ b/website/docs/r/pubsub_lite_subscription.html.markdown @@ -100,6 +100,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `delivery_config` block supports: diff --git a/website/docs/r/pubsub_lite_topic.html.markdown b/website/docs/r/pubsub_lite_topic.html.markdown index 634d28e8d57..e726e18636f 100644 --- a/website/docs/r/pubsub_lite_topic.html.markdown +++ b/website/docs/r/pubsub_lite_topic.html.markdown @@ -107,6 +107,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `partition_config` block supports: diff --git a/website/docs/r/pubsub_schema.html.markdown b/website/docs/r/pubsub_schema.html.markdown index cc6705704c0..f07c2f623c5 100644 --- a/website/docs/r/pubsub_schema.html.markdown +++ b/website/docs/r/pubsub_schema.html.markdown @@ -97,6 +97,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/pubsub_subscription.html.markdown b/website/docs/r/pubsub_subscription.html.markdown index 362680fd78f..77674883c8a 100644 --- a/website/docs/r/pubsub_subscription.html.markdown +++ b/website/docs/r/pubsub_subscription.html.markdown @@ -841,6 +841,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `bigquery_config` block supports: diff --git a/website/docs/r/pubsub_topic.html.markdown b/website/docs/r/pubsub_topic.html.markdown index 5b5d80c65cc..288b4aca086 100644 --- a/website/docs/r/pubsub_topic.html.markdown +++ b/website/docs/r/pubsub_topic.html.markdown @@ -448,6 +448,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `message_storage_policy` block supports: diff --git a/website/docs/r/recaptcha_enterprise_key.html.markdown b/website/docs/r/recaptcha_enterprise_key.html.markdown index f0543b01c79..d24280effbd 100644 --- a/website/docs/r/recaptcha_enterprise_key.html.markdown +++ b/website/docs/r/recaptcha_enterprise_key.html.markdown @@ -212,7 +212,13 @@ Please refer to the field `effective_labels` for all of the labels present on th * `web_settings` - (Optional) Settings for keys that can be used by websites. - + +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `android_settings` block supports: diff --git a/website/docs/r/redis_cluster.html.markdown b/website/docs/r/redis_cluster.html.markdown index b9d2021a827..e370605c533 100644 --- a/website/docs/r/redis_cluster.html.markdown +++ b/website/docs/r/redis_cluster.html.markdown @@ -885,6 +885,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `gcs_source` block supports: diff --git a/website/docs/r/redis_cluster_user_created_connections.html.markdown b/website/docs/r/redis_cluster_user_created_connections.html.markdown index d7f2ff87aaa..66b8714465a 100644 --- a/website/docs/r/redis_cluster_user_created_connections.html.markdown +++ b/website/docs/r/redis_cluster_user_created_connections.html.markdown @@ -334,6 +334,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `cluster_endpoints` block supports: diff --git a/website/docs/r/redis_instance.html.markdown b/website/docs/r/redis_instance.html.markdown index 95b85b9fd28..ce5a80602a1 100644 --- a/website/docs/r/redis_instance.html.markdown +++ b/website/docs/r/redis_instance.html.markdown @@ -422,6 +422,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. * `deletion_protection` - (Optional) Whether Terraform will be prevented from destroying the instance. When a`terraform destroy` or `terraform apply` would delete the instance, the command will fail if this field is not set to false in Terraform state. diff --git a/website/docs/r/resource_manager_capability.html.markdown b/website/docs/r/resource_manager_capability.html.markdown index 84092e2627d..784e5d59a5d 100644 --- a/website/docs/r/resource_manager_capability.html.markdown +++ b/website/docs/r/resource_manager_capability.html.markdown @@ -69,6 +69,12 @@ The following arguments are supported: Capability Value. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/resource_manager_lien.html.markdown b/website/docs/r/resource_manager_lien.html.markdown index 13b3003ed56..19ae64dbfd2 100644 --- a/website/docs/r/resource_manager_lien.html.markdown +++ b/website/docs/r/resource_manager_lien.html.markdown @@ -80,6 +80,12 @@ The following arguments are supported: e.g. ['resourcemanager.projects.delete'] +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/runtimeconfig_config.html.markdown b/website/docs/r/runtimeconfig_config.html.markdown index 5f073ae7fb7..5edbd4e74ef 100644 --- a/website/docs/r/runtimeconfig_config.html.markdown +++ b/website/docs/r/runtimeconfig_config.html.markdown @@ -56,6 +56,13 @@ is not provided, the provider project is used. * `description` - (Optional) The description to associate with the runtime config. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. + ## Attributes Reference In addition to the arguments listed above, the following computed attributes are exported: diff --git a/website/docs/r/runtimeconfig_variable.html.markdown b/website/docs/r/runtimeconfig_variable.html.markdown index 1db28ae14ef..f0458a19fdd 100644 --- a/website/docs/r/runtimeconfig_variable.html.markdown +++ b/website/docs/r/runtimeconfig_variable.html.markdown @@ -83,6 +83,13 @@ is specified, it must be base64 encoded and less than 4096 bytes in length. * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. + ## Attributes Reference In addition to the arguments listed above, the following computed attributes are diff --git a/website/docs/r/saas_runtime_release.html.markdown b/website/docs/r/saas_runtime_release.html.markdown index 61cb1ff0bf5..f07e8e8cc95 100644 --- a/website/docs/r/saas_runtime_release.html.markdown +++ b/website/docs/r/saas_runtime_release.html.markdown @@ -131,6 +131,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `blueprint` block supports: diff --git a/website/docs/r/saas_runtime_rollout_kind.html.markdown b/website/docs/r/saas_runtime_rollout_kind.html.markdown index e6c745237b0..436253ef78b 100644 --- a/website/docs/r/saas_runtime_rollout_kind.html.markdown +++ b/website/docs/r/saas_runtime_rollout_kind.html.markdown @@ -136,6 +136,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `error_budget` block supports: diff --git a/website/docs/r/saas_runtime_saas.html.markdown b/website/docs/r/saas_runtime_saas.html.markdown index 30d687d9395..9e5e989134c 100644 --- a/website/docs/r/saas_runtime_saas.html.markdown +++ b/website/docs/r/saas_runtime_saas.html.markdown @@ -89,6 +89,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `locations` block supports: diff --git a/website/docs/r/saas_runtime_tenant.html.markdown b/website/docs/r/saas_runtime_tenant.html.markdown index 46b8eada240..79c2504df30 100644 --- a/website/docs/r/saas_runtime_tenant.html.markdown +++ b/website/docs/r/saas_runtime_tenant.html.markdown @@ -96,6 +96,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/saas_runtime_unit.html.markdown b/website/docs/r/saas_runtime_unit.html.markdown index 42c4d08101c..9d2532b8bb5 100644 --- a/website/docs/r/saas_runtime_unit.html.markdown +++ b/website/docs/r/saas_runtime_unit.html.markdown @@ -115,6 +115,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `maintenance` block supports: diff --git a/website/docs/r/saas_runtime_unit_kind.html.markdown b/website/docs/r/saas_runtime_unit_kind.html.markdown index 714eb900c49..d97c93dd1b8 100644 --- a/website/docs/r/saas_runtime_unit_kind.html.markdown +++ b/website/docs/r/saas_runtime_unit_kind.html.markdown @@ -137,6 +137,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `dependencies` block supports: diff --git a/website/docs/r/saas_runtime_unit_operation.html.markdown b/website/docs/r/saas_runtime_unit_operation.html.markdown index edcaf61e39b..e9635e3d3d8 100644 --- a/website/docs/r/saas_runtime_unit_operation.html.markdown +++ b/website/docs/r/saas_runtime_unit_operation.html.markdown @@ -269,6 +269,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. * `wait_for_completion` - (Optional) If true, wait for the UnitOperation to reach a terminal state (SUCCEEDED, FAILED, CANCELLED) before completing the apply. diff --git a/website/docs/r/scc_event_threat_detection_custom_module.html.markdown b/website/docs/r/scc_event_threat_detection_custom_module.html.markdown index 58522cf7d30..f46c81de73b 100644 --- a/website/docs/r/scc_event_threat_detection_custom_module.html.markdown +++ b/website/docs/r/scc_event_threat_detection_custom_module.html.markdown @@ -85,6 +85,12 @@ The following arguments are supported: (Optional) The human readable name to be displayed for the module. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/scc_folder_custom_module.html.markdown b/website/docs/r/scc_folder_custom_module.html.markdown index ab4c27e15c6..ed8e28236b3 100644 --- a/website/docs/r/scc_folder_custom_module.html.markdown +++ b/website/docs/r/scc_folder_custom_module.html.markdown @@ -136,6 +136,12 @@ The following arguments are supported: Numerical ID of the parent folder. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `custom_config` block supports: diff --git a/website/docs/r/scc_folder_notification_config.html.markdown b/website/docs/r/scc_folder_notification_config.html.markdown index 5381ffef1a1..89393bf521d 100644 --- a/website/docs/r/scc_folder_notification_config.html.markdown +++ b/website/docs/r/scc_folder_notification_config.html.markdown @@ -90,6 +90,12 @@ The following arguments are supported: (Optional) The description of the notification config (max of 1024 characters). +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `streaming_config` block supports: diff --git a/website/docs/r/scc_folder_scc_big_query_export.html.markdown b/website/docs/r/scc_folder_scc_big_query_export.html.markdown index adbf8b95f18..6ce83fc9263 100644 --- a/website/docs/r/scc_folder_scc_big_query_export.html.markdown +++ b/website/docs/r/scc_folder_scc_big_query_export.html.markdown @@ -120,6 +120,12 @@ The following arguments are supported: This must be unique within the organization. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/scc_management_folder_security_health_analytics_custom_module.html.markdown b/website/docs/r/scc_management_folder_security_health_analytics_custom_module.html.markdown index a218223829f..2573edcbd05 100644 --- a/website/docs/r/scc_management_folder_security_health_analytics_custom_module.html.markdown +++ b/website/docs/r/scc_management_folder_security_health_analytics_custom_module.html.markdown @@ -142,6 +142,12 @@ The following arguments are supported: (Optional) Location ID of the parent organization. If not provided, 'global' will be used as the default location. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `custom_config` block supports: diff --git a/website/docs/r/scc_management_organization_event_threat_detection_custom_module.html.markdown b/website/docs/r/scc_management_organization_event_threat_detection_custom_module.html.markdown index ac2b3bac59e..ad530e6ab60 100644 --- a/website/docs/r/scc_management_organization_event_threat_detection_custom_module.html.markdown +++ b/website/docs/r/scc_management_organization_event_threat_detection_custom_module.html.markdown @@ -90,6 +90,12 @@ The following arguments are supported: (Optional) Location ID of the parent organization. Only global is supported at the moment. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/scc_management_organization_security_health_analytics_custom_module.html.markdown b/website/docs/r/scc_management_organization_security_health_analytics_custom_module.html.markdown index 9bfd5c7195c..5eee3997151 100644 --- a/website/docs/r/scc_management_organization_security_health_analytics_custom_module.html.markdown +++ b/website/docs/r/scc_management_organization_security_health_analytics_custom_module.html.markdown @@ -130,6 +130,12 @@ The following arguments are supported: (Optional) Location ID of the parent organization. If not provided, 'global' will be used as the default location. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `custom_config` block supports: diff --git a/website/docs/r/scc_management_project_security_health_analytics_custom_module.html.markdown b/website/docs/r/scc_management_project_security_health_analytics_custom_module.html.markdown index dfdfa4a829f..6a2c78d92e5 100644 --- a/website/docs/r/scc_management_project_security_health_analytics_custom_module.html.markdown +++ b/website/docs/r/scc_management_project_security_health_analytics_custom_module.html.markdown @@ -127,6 +127,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `custom_config` block supports: diff --git a/website/docs/r/scc_mute_config.html.markdown b/website/docs/r/scc_mute_config.html.markdown index e432a9272a0..24eb6a1fc4b 100644 --- a/website/docs/r/scc_mute_config.html.markdown +++ b/website/docs/r/scc_mute_config.html.markdown @@ -89,6 +89,12 @@ The following arguments are supported: A timestamp in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine fractional digits. Examples: "2014-10-02T15:01:23Z" and "2014-10-02T15:01:23.045123456Z". +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/scc_notification_config.html.markdown b/website/docs/r/scc_notification_config.html.markdown index 949e0deefc9..b4f547d257b 100644 --- a/website/docs/r/scc_notification_config.html.markdown +++ b/website/docs/r/scc_notification_config.html.markdown @@ -85,6 +85,12 @@ The following arguments are supported: (Optional) The description of the notification config (max of 1024 characters). +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `streaming_config` block supports: diff --git a/website/docs/r/scc_organization_custom_module.html.markdown b/website/docs/r/scc_organization_custom_module.html.markdown index 0164bfa7360..b9d7792e997 100644 --- a/website/docs/r/scc_organization_custom_module.html.markdown +++ b/website/docs/r/scc_organization_custom_module.html.markdown @@ -124,6 +124,12 @@ The following arguments are supported: Numerical ID of the parent organization. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `custom_config` block supports: diff --git a/website/docs/r/scc_organization_scc_big_query_export.html.markdown b/website/docs/r/scc_organization_scc_big_query_export.html.markdown index 6220fbc6b7a..5f06d4807c7 100644 --- a/website/docs/r/scc_organization_scc_big_query_export.html.markdown +++ b/website/docs/r/scc_organization_scc_big_query_export.html.markdown @@ -113,6 +113,12 @@ The following arguments are supported: [Filtering notifications](https://cloud.google.com/security-command-center/docs/how-to-api-filter-notifications) for information on how to write a filter. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/scc_project_custom_module.html.markdown b/website/docs/r/scc_project_custom_module.html.markdown index 100ad9aa345..552899a2629 100644 --- a/website/docs/r/scc_project_custom_module.html.markdown +++ b/website/docs/r/scc_project_custom_module.html.markdown @@ -121,6 +121,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `custom_config` block supports: diff --git a/website/docs/r/scc_project_notification_config.html.markdown b/website/docs/r/scc_project_notification_config.html.markdown index df15773239a..f780b46371b 100644 --- a/website/docs/r/scc_project_notification_config.html.markdown +++ b/website/docs/r/scc_project_notification_config.html.markdown @@ -83,6 +83,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `streaming_config` block supports: diff --git a/website/docs/r/scc_project_scc_big_query_export.html.markdown b/website/docs/r/scc_project_scc_big_query_export.html.markdown index bb92270d286..46b8a153420 100644 --- a/website/docs/r/scc_project_scc_big_query_export.html.markdown +++ b/website/docs/r/scc_project_scc_big_query_export.html.markdown @@ -111,6 +111,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/scc_source.html.markdown b/website/docs/r/scc_source.html.markdown index 4bf5c9f9544..f788ac36cad 100644 --- a/website/docs/r/scc_source.html.markdown +++ b/website/docs/r/scc_source.html.markdown @@ -67,6 +67,12 @@ The following arguments are supported: (Optional) The description of the source (max of 1024 characters). +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/scc_v2_folder_mute_config.html.markdown b/website/docs/r/scc_v2_folder_mute_config.html.markdown index 2ab7ad0f100..f3fb21a8a78 100644 --- a/website/docs/r/scc_v2_folder_mute_config.html.markdown +++ b/website/docs/r/scc_v2_folder_mute_config.html.markdown @@ -88,6 +88,12 @@ The following arguments are supported: (Optional) location Id is provided by folder. If not provided, Use global as default. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/scc_v2_folder_notification_config.html.markdown b/website/docs/r/scc_v2_folder_notification_config.html.markdown index 22947124aee..7ab9a2da708 100644 --- a/website/docs/r/scc_v2_folder_notification_config.html.markdown +++ b/website/docs/r/scc_v2_folder_notification_config.html.markdown @@ -88,6 +88,12 @@ The following arguments are supported: (Optional) Location ID of the parent organization. If not provided, 'global' will be used as the default location. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `streaming_config` block supports: diff --git a/website/docs/r/scc_v2_folder_scc_big_query_export.html.markdown b/website/docs/r/scc_v2_folder_scc_big_query_export.html.markdown index 378c462bd7e..340dba971f6 100644 --- a/website/docs/r/scc_v2_folder_scc_big_query_export.html.markdown +++ b/website/docs/r/scc_v2_folder_scc_big_query_export.html.markdown @@ -126,6 +126,12 @@ The following arguments are supported: (Optional) The BigQuery export configuration is stored in this location. If not provided, Use global as default. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/scc_v2_organization_mute_config.html.markdown b/website/docs/r/scc_v2_organization_mute_config.html.markdown index 59d596fdcbc..2a2d0acaea7 100644 --- a/website/docs/r/scc_v2_organization_mute_config.html.markdown +++ b/website/docs/r/scc_v2_organization_mute_config.html.markdown @@ -83,6 +83,12 @@ The following arguments are supported: (Optional) location Id is provided by organization. If not provided, Use global as default. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/scc_v2_organization_notification_config.html.markdown b/website/docs/r/scc_v2_organization_notification_config.html.markdown index 3eaa2d82329..564bc87a23f 100644 --- a/website/docs/r/scc_v2_organization_notification_config.html.markdown +++ b/website/docs/r/scc_v2_organization_notification_config.html.markdown @@ -84,6 +84,12 @@ The following arguments are supported: (Optional) location Id is provided by organization. If not provided, Use global as default. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `streaming_config` block supports: diff --git a/website/docs/r/scc_v2_organization_scc_big_query_export.html.markdown b/website/docs/r/scc_v2_organization_scc_big_query_export.html.markdown index 2d3418d98a3..7d057f53f56 100644 --- a/website/docs/r/scc_v2_organization_scc_big_query_export.html.markdown +++ b/website/docs/r/scc_v2_organization_scc_big_query_export.html.markdown @@ -124,6 +124,12 @@ The following arguments are supported: (Optional) location Id is provided by organization. If not provided, Use global as default. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/scc_v2_organization_scc_big_query_exports.html.markdown b/website/docs/r/scc_v2_organization_scc_big_query_exports.html.markdown index bb144841a5b..80eadcb3f29 100644 --- a/website/docs/r/scc_v2_organization_scc_big_query_exports.html.markdown +++ b/website/docs/r/scc_v2_organization_scc_big_query_exports.html.markdown @@ -125,6 +125,12 @@ The following arguments are supported: (Optional) location Id is provided by organization. If not provided, Use global as default. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/scc_v2_organization_source.html.markdown b/website/docs/r/scc_v2_organization_source.html.markdown index 8fd27fbaf8e..8faf6d6e9cc 100644 --- a/website/docs/r/scc_v2_organization_source.html.markdown +++ b/website/docs/r/scc_v2_organization_source.html.markdown @@ -67,6 +67,12 @@ The following arguments are supported: (Optional) The description of the source (max of 1024 characters). +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/scc_v2_project_mute_config.html.markdown b/website/docs/r/scc_v2_project_mute_config.html.markdown index bf853d81429..62a01bad79b 100644 --- a/website/docs/r/scc_v2_project_mute_config.html.markdown +++ b/website/docs/r/scc_v2_project_mute_config.html.markdown @@ -81,6 +81,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/scc_v2_project_notification_config.html.markdown b/website/docs/r/scc_v2_project_notification_config.html.markdown index 01c71dbd996..0483ed39514 100644 --- a/website/docs/r/scc_v2_project_notification_config.html.markdown +++ b/website/docs/r/scc_v2_project_notification_config.html.markdown @@ -81,6 +81,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `streaming_config` block supports: diff --git a/website/docs/r/scc_v2_project_scc_big_query_export.html.markdown b/website/docs/r/scc_v2_project_scc_big_query_export.html.markdown index 436f682b6eb..a7ad8d047ed 100644 --- a/website/docs/r/scc_v2_project_scc_big_query_export.html.markdown +++ b/website/docs/r/scc_v2_project_scc_big_query_export.html.markdown @@ -116,6 +116,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/secret_manager_regional_secret.html.markdown b/website/docs/r/secret_manager_regional_secret.html.markdown index b7831b2a1d0..767f21a073d 100644 --- a/website/docs/r/secret_manager_regional_secret.html.markdown +++ b/website/docs/r/secret_manager_regional_secret.html.markdown @@ -302,6 +302,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. * `deletion_protection` - (Optional) Whether Terraform will be prevented from destroying the regional secret. Defaults to false. When the field is set to true in Terraform state, a `terraform apply` or `terraform destroy` that would delete the federation will fail. diff --git a/website/docs/r/secret_manager_regional_secret_version.html.markdown b/website/docs/r/secret_manager_regional_secret_version.html.markdown index f8498410559..dfdbb8ddae0 100644 --- a/website/docs/r/secret_manager_regional_secret_version.html.markdown +++ b/website/docs/r/secret_manager_regional_secret_version.html.markdown @@ -159,12 +159,18 @@ The following arguments are supported: (Optional) The current state of the regional secret version. -* `deletion_policy` - (Optional) The deletion policy for the regional secret version. Setting `ABANDON` allows the resource +* `deletion_policy` - (Optional) The deletion policy for the secret version. Setting `ABANDON` allows the resource to be abandoned rather than deleted. Setting `DISABLE` allows the resource to be -disabled rather than deleted. Default is `DELETE`. Possible values are: +disabled rather than deleted. + +When a 'terraform destroy' or 'terraform apply' would delete the resource, +the command will fail if this field is set to "PREVENT" in Terraform state. + +Default is `DELETE`. Possible values are: * DELETE * DISABLE * ABANDON + * PREVENT * `is_secret_data_base64` - (Optional) If set to 'true', the secret data is expected to be base64-encoded string and would be sent as is. diff --git a/website/docs/r/secret_manager_secret.html.markdown b/website/docs/r/secret_manager_secret.html.markdown index 936eff49086..61eb695b6d0 100644 --- a/website/docs/r/secret_manager_secret.html.markdown +++ b/website/docs/r/secret_manager_secret.html.markdown @@ -234,6 +234,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. * `deletion_protection` - (Optional) Whether Terraform will be prevented from destroying the secret. Defaults to false. When the field is set to true in Terraform state, a `terraform apply` or `terraform destroy` that would delete the secret will fail. diff --git a/website/docs/r/secret_manager_secret_version.html.markdown b/website/docs/r/secret_manager_secret_version.html.markdown index 42bb1bed85c..f76a1fd3e14 100644 --- a/website/docs/r/secret_manager_secret_version.html.markdown +++ b/website/docs/r/secret_manager_secret_version.html.markdown @@ -250,10 +250,16 @@ The following arguments are supported: * `deletion_policy` - (Optional) The deletion policy for the secret version. Setting `ABANDON` allows the resource to be abandoned rather than deleted. Setting `DISABLE` allows the resource to be -disabled rather than deleted. Default is `DELETE`. Possible values are: +disabled rather than deleted. + +When a 'terraform destroy' or 'terraform apply' would delete the resource, +the command will fail if this field is set to "PREVENT" in Terraform state. + +Default is `DELETE`. Possible values are: * DELETE * DISABLE * ABANDON + * PREVENT * `is_secret_data_base64` - (Optional) If set to 'true', the secret data is expected to be base64-encoded string and would be sent as is. diff --git a/website/docs/r/secure_source_manager_branch_rule.html.markdown b/website/docs/r/secure_source_manager_branch_rule.html.markdown index 4087e1c8e76..3d428f13f2e 100644 --- a/website/docs/r/secure_source_manager_branch_rule.html.markdown +++ b/website/docs/r/secure_source_manager_branch_rule.html.markdown @@ -158,6 +158,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/secure_source_manager_hook.html.markdown b/website/docs/r/secure_source_manager_hook.html.markdown index 8a18967a194..39a6f11ba36 100644 --- a/website/docs/r/secure_source_manager_hook.html.markdown +++ b/website/docs/r/secure_source_manager_hook.html.markdown @@ -152,6 +152,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `push_option` block supports: diff --git a/website/docs/r/secure_source_manager_instance.html.markdown b/website/docs/r/secure_source_manager_instance.html.markdown index f3b27dc8a24..c548210b201 100644 --- a/website/docs/r/secure_source_manager_instance.html.markdown +++ b/website/docs/r/secure_source_manager_instance.html.markdown @@ -679,15 +679,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. -* `deletion_policy` - (Optional) The deletion policy for the instance. Setting `ABANDON` allows the resource -to be abandoned, rather than deleted. Setting `DELETE` deletes the resource -and all its contents. Setting `PREVENT` prevents the resource from accidental -deletion by erroring out during plan. -Default is `PREVENT`. Possible values are: - * DELETE - * PREVENT - * ABANDON - +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to PREVENT. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `private_config` block supports: diff --git a/website/docs/r/secure_source_manager_repository.html.markdown b/website/docs/r/secure_source_manager_repository.html.markdown index 76b9e07d364..2304b144783 100644 --- a/website/docs/r/secure_source_manager_repository.html.markdown +++ b/website/docs/r/secure_source_manager_repository.html.markdown @@ -121,15 +121,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. -* `deletion_policy` - (Optional) The deletion policy for the repository. Setting `ABANDON` allows the resource -to be abandoned, rather than deleted. Setting `DELETE` deletes the resource -and all its contents. Setting `PREVENT` prevents the resource from accidental deletion -by erroring out during plan. -Default is `PREVENT`. Possible values are: - * DELETE - * PREVENT - * ABANDON - +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to PREVENT. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `initial_config` block supports: diff --git a/website/docs/r/security_scanner_scan_config.html.markdown b/website/docs/r/security_scanner_scan_config.html.markdown index eba66de0f39..af76c7fd0e3 100644 --- a/website/docs/r/security_scanner_scan_config.html.markdown +++ b/website/docs/r/security_scanner_scan_config.html.markdown @@ -113,6 +113,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `authentication` block supports: diff --git a/website/docs/r/securityposture_posture.html.markdown b/website/docs/r/securityposture_posture.html.markdown index 97388ebff42..016e2a8bddd 100644 --- a/website/docs/r/securityposture_posture.html.markdown +++ b/website/docs/r/securityposture_posture.html.markdown @@ -166,6 +166,12 @@ The following arguments are supported: (Optional) Description of the posture. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `policy_sets` block supports: diff --git a/website/docs/r/securityposture_posture_deployment.html.markdown b/website/docs/r/securityposture_posture_deployment.html.markdown index c1bd1c1d700..755a35655e3 100644 --- a/website/docs/r/securityposture_posture_deployment.html.markdown +++ b/website/docs/r/securityposture_posture_deployment.html.markdown @@ -72,6 +72,12 @@ The following arguments are supported: (Optional) Description of the posture deployment. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/service_directory_endpoint.html.markdown b/website/docs/r/service_directory_endpoint.html.markdown index e5ac03d707b..8aa61af5d5a 100644 --- a/website/docs/r/service_directory_endpoint.html.markdown +++ b/website/docs/r/service_directory_endpoint.html.markdown @@ -138,6 +138,12 @@ The following arguments are supported: (Optional) The URL to the network, such as projects/PROJECT_NUMBER/locations/global/networks/NETWORK_NAME. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/service_directory_namespace.html.markdown b/website/docs/r/service_directory_namespace.html.markdown index df170504ea9..6a6f219f748 100644 --- a/website/docs/r/service_directory_namespace.html.markdown +++ b/website/docs/r/service_directory_namespace.html.markdown @@ -78,6 +78,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/service_directory_service.html.markdown b/website/docs/r/service_directory_service.html.markdown index 5093c9da41f..1ad2b1a84da 100644 --- a/website/docs/r/service_directory_service.html.markdown +++ b/website/docs/r/service_directory_service.html.markdown @@ -77,6 +77,12 @@ The following arguments are supported: up to 2000 characters, spread across all key-value pairs. Metadata that goes beyond any these limits will be rejected. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/service_networking_connection.html.markdown b/website/docs/r/service_networking_connection.html.markdown index 67e2882f89f..2c3c86323e3 100644 --- a/website/docs/r/service_networking_connection.html.markdown +++ b/website/docs/r/service_networking_connection.html.markdown @@ -73,7 +73,13 @@ The following arguments are supported: this service provider. Note that invoking this method with a different range when connection is already established will not reallocate already provisioned service producer subnetworks. -* `deletion_policy` - (Optional) The deletion policy for the service networking connection. Setting to ABANDON allows the resource to be abandoned rather than deleted. This will enable a successful terraform destroy when destroying CloudSQL instances. Use with care as it can lead to dangling resources. + +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE" or any other value, deleting the resource is allowed. * `update_on_creation_fail` - (Optional) When set to true, enforce an update of the reserved peering ranges on the existing service networking connection in case of a new connection creation failure. diff --git a/website/docs/r/service_networking_vpc_service_controls.html.markdown b/website/docs/r/service_networking_vpc_service_controls.html.markdown index e59765a61f0..adb825a63bc 100644 --- a/website/docs/r/service_networking_vpc_service_controls.html.markdown +++ b/website/docs/r/service_networking_vpc_service_controls.html.markdown @@ -128,6 +128,12 @@ The following arguments are supported: (Optional) The id of the Google Cloud project containing the consumer network. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/service_usage_consumer_quota_override.html.markdown b/website/docs/r/service_usage_consumer_quota_override.html.markdown index f76a0a9703e..e7fdfefc39b 100644 --- a/website/docs/r/service_usage_consumer_quota_override.html.markdown +++ b/website/docs/r/service_usage_consumer_quota_override.html.markdown @@ -142,6 +142,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/site_verification_owner.html.markdown b/website/docs/r/site_verification_owner.html.markdown index 82ed0a8932c..73d1b758e59 100644 --- a/website/docs/r/site_verification_owner.html.markdown +++ b/website/docs/r/site_verification_owner.html.markdown @@ -110,6 +110,13 @@ The following arguments are supported: (Required) The email of the user to be added as an owner. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. + - - - diff --git a/website/docs/r/site_verification_web_resource.html.markdown b/website/docs/r/site_verification_web_resource.html.markdown index d26c05b1b3e..6a917e57703 100644 --- a/website/docs/r/site_verification_web_resource.html.markdown +++ b/website/docs/r/site_verification_web_resource.html.markdown @@ -84,6 +84,12 @@ The following arguments are supported: Possible values are: `ANALYTICS`, `DNS_CNAME`, `DNS_TXT`, `FILE`, `META`, `TAG_MANAGER`. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `site` block supports: diff --git a/website/docs/r/sourcerepo_repository.html.markdown b/website/docs/r/sourcerepo_repository.html.markdown index 538b81a3359..d82d69224ea 100644 --- a/website/docs/r/sourcerepo_repository.html.markdown +++ b/website/docs/r/sourcerepo_repository.html.markdown @@ -91,6 +91,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. * `create_ignore_already_exists` - (Optional) If set to true, skip repository creation if a repository with the same name already exists. diff --git a/website/docs/r/spanner_backup_schedule.html.markdown b/website/docs/r/spanner_backup_schedule.html.markdown index 9cd32e305f7..d2427298fb2 100644 --- a/website/docs/r/spanner_backup_schedule.html.markdown +++ b/website/docs/r/spanner_backup_schedule.html.markdown @@ -193,6 +193,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `spec` block supports: diff --git a/website/docs/r/spanner_database.html.markdown b/website/docs/r/spanner_database.html.markdown index c7632aeb582..5c578fb8a0d 100644 --- a/website/docs/r/spanner_database.html.markdown +++ b/website/docs/r/spanner_database.html.markdown @@ -125,6 +125,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. * `deletion_protection` - (Optional) Whether Terraform will be prevented from destroying the database. Defaults to true. When a`terraform destroy` or `terraform apply` would delete the database, the command will fail if this field is not set to false in Terraform state. diff --git a/website/docs/r/spanner_instance.html.markdown b/website/docs/r/spanner_instance.html.markdown index fe4c76c58f4..55a20a6a4ea 100644 --- a/website/docs/r/spanner_instance.html.markdown +++ b/website/docs/r/spanner_instance.html.markdown @@ -166,6 +166,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. * `force_destroy` - (Optional) When deleting a spanner instance, this boolean option will delete all backups of this instance. This must be set to true if you created a backup manually in the console. diff --git a/website/docs/r/spanner_instance_config.html.markdown b/website/docs/r/spanner_instance_config.html.markdown index c617be3b503..03322289316 100644 --- a/website/docs/r/spanner_instance_config.html.markdown +++ b/website/docs/r/spanner_instance_config.html.markdown @@ -92,6 +92,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `replicas` block supports: diff --git a/website/docs/r/spanner_instance_partition.html.markdown b/website/docs/r/spanner_instance_partition.html.markdown index 2e4917f47cf..4eb4c79691b 100644 --- a/website/docs/r/spanner_instance_partition.html.markdown +++ b/website/docs/r/spanner_instance_partition.html.markdown @@ -142,6 +142,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `autoscaling_config` block supports: diff --git a/website/docs/r/sql_database.html.markdown b/website/docs/r/sql_database.html.markdown index 3efaaa2db1f..3e5e4e3af67 100644 --- a/website/docs/r/sql_database.html.markdown +++ b/website/docs/r/sql_database.html.markdown @@ -116,11 +116,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. -* `deletion_policy` - (Optional) The deletion policy for the database. Setting ABANDON allows the resource -to be abandoned rather than deleted. This is useful for Postgres, where databases cannot be -deleted from the API if there are users other than cloudsqlsuperuser with access. Possible -values are: "ABANDON", "DELETE". Defaults to "DELETE". - +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/sql_database_instance.html.markdown b/website/docs/r/sql_database_instance.html.markdown index eedf3cbbaa3..939e3c8c0e7 100644 --- a/website/docs/r/sql_database_instance.html.markdown +++ b/website/docs/r/sql_database_instance.html.markdown @@ -434,6 +434,13 @@ includes an up-to-date reference of supported versions. **NOTE:** Restoring from a backup is an imperative action and not recommended via Terraform. Adding or modifying this block during resource creation/update will trigger the restore action after the resource is created/updated. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. + The `settings` block supports: * `tier` - (Required) The machine type to use. See [tiers](https://cloud.google.com/sql/docs/admin-api/v1beta4/tiers) diff --git a/website/docs/r/sql_source_representation_instance.html.markdown b/website/docs/r/sql_source_representation_instance.html.markdown index a7504353580..f015752ad0b 100644 --- a/website/docs/r/sql_source_representation_instance.html.markdown +++ b/website/docs/r/sql_source_representation_instance.html.markdown @@ -131,6 +131,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/sql_ssl_cert.html.markdown b/website/docs/r/sql_ssl_cert.html.markdown index 34aedcb9669..d3e1a6df3fa 100644 --- a/website/docs/r/sql_ssl_cert.html.markdown +++ b/website/docs/r/sql_ssl_cert.html.markdown @@ -61,6 +61,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/sql_user.html.markdown b/website/docs/r/sql_user.html.markdown index 10c79498815..d6164e07367 100644 --- a/website/docs/r/sql_user.html.markdown +++ b/website/docs/r/sql_user.html.markdown @@ -175,11 +175,14 @@ The following arguments are supported: [Postgres](https://cloud.google.com/sql/docs/postgres/admin-api/rest/v1beta4/users#sqlusertype) and [MySQL](https://cloud.google.com/sql/docs/mysql/admin-api/rest/v1beta4/users#sqlusertype). -* `deletion_policy` - (Optional) The deletion policy for the user. - Setting `ABANDON` allows the resource to be abandoned rather than deleted. This is useful +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. This is useful for Postgres, where users cannot be deleted from the API if they have been granted SQL roles. - Possible values are: `ABANDON`. + When set to "DELETE", deleting the resource is allowed. - - - diff --git a/website/docs/r/storage_anywhere_cache.html.markdown b/website/docs/r/storage_anywhere_cache.html.markdown index 21626350fe7..115f8175f26 100644 --- a/website/docs/r/storage_anywhere_cache.html.markdown +++ b/website/docs/r/storage_anywhere_cache.html.markdown @@ -84,6 +84,12 @@ The following arguments are supported: (Optional) Whether or not the cache ingests data as the data is written to the bucket. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/storage_batch_operations_job.html.markdown b/website/docs/r/storage_batch_operations_job.html.markdown index f18590e88fb..79c2a6c932b 100644 --- a/website/docs/r/storage_batch_operations_job.html.markdown +++ b/website/docs/r/storage_batch_operations_job.html.markdown @@ -103,6 +103,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. * `delete_protection` - (Optional) If set to `true`, the storage batch operation job will not be deleted and new job will be created. diff --git a/website/docs/r/storage_bucket.html.markdown b/website/docs/r/storage_bucket.html.markdown index fe08881eb66..807e4daea9e 100644 --- a/website/docs/r/storage_bucket.html.markdown +++ b/website/docs/r/storage_bucket.html.markdown @@ -252,6 +252,13 @@ The following arguments are supported: * `ip_filter` - (Optional) The bucket IP filtering configuration. Specifies the network sources that can access the bucket, as well as its underlying objects. Structure is [documented below](#nested_ip_filter). +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. + The `lifecycle_rule` block supports: * `action` - (Required) The Lifecycle Rule's action configuration. A single block of this type is supported. Structure is [documented below](#nested_action). diff --git a/website/docs/r/storage_bucket_access_control.html.markdown b/website/docs/r/storage_bucket_access_control.html.markdown index 64536ba5ce4..caf54f879d9 100644 --- a/website/docs/r/storage_bucket_access_control.html.markdown +++ b/website/docs/r/storage_bucket_access_control.html.markdown @@ -101,6 +101,12 @@ The following arguments are supported: The access permission for the entity. Possible values are: `OWNER`, `READER`, `WRITER`. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/storage_bucket_acl.html.markdown b/website/docs/r/storage_bucket_acl.html.markdown index 26118e891f9..03fac6af65c 100644 --- a/website/docs/r/storage_bucket_acl.html.markdown +++ b/website/docs/r/storage_bucket_acl.html.markdown @@ -63,6 +63,13 @@ resource "google_storage_bucket_acl" "image-store-acl" { * `default_acl` - (Optional) Configure this ACL to be the default ACL. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. + ## Attributes Reference Only the arguments listed above are exposed as attributes. diff --git a/website/docs/r/storage_bucket_object.html.markdown b/website/docs/r/storage_bucket_object.html.markdown index 88716aaac5c..d30d9c4ccf6 100644 --- a/website/docs/r/storage_bucket_object.html.markdown +++ b/website/docs/r/storage_bucket_object.html.markdown @@ -127,7 +127,13 @@ One of the following is required: * `force_empty_content_type` - (Optional) When set to true, it ensure the object's Content-Type is empty. -* `deletion_policy` - (Optional) When set to ABANDON, the object won't be deleted from storage bucket. Instead, it will only be removed from terraform's state file. + +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. * `contexts` - (Optional) Contexts attached to an object, in key-value pairs. For more information about object contexts, see [Object contexts overview](https://cloud.google.com/storage/docs/object-contexts). Structure is [documented below](#nested_contexts). diff --git a/website/docs/r/storage_control_folder_intelligence_config.html.markdown b/website/docs/r/storage_control_folder_intelligence_config.html.markdown index b28ddaff56c..63ee426ffb7 100644 --- a/website/docs/r/storage_control_folder_intelligence_config.html.markdown +++ b/website/docs/r/storage_control_folder_intelligence_config.html.markdown @@ -67,6 +67,12 @@ The following arguments are supported: Filter over location and bucket using include or exclude semantics. Resources that match the include or exclude filter are exclusively included or excluded from the Storage Intelligence plan. Structure is [documented below](#nested_filter). +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `filter` block supports: diff --git a/website/docs/r/storage_control_organization_intelligence_config.html.markdown b/website/docs/r/storage_control_organization_intelligence_config.html.markdown index 8973bdd84a8..52ee9e8ac06 100644 --- a/website/docs/r/storage_control_organization_intelligence_config.html.markdown +++ b/website/docs/r/storage_control_organization_intelligence_config.html.markdown @@ -67,6 +67,12 @@ The following arguments are supported: Filter over location and bucket using include or exclude semantics. Resources that match the include or exclude filter are exclusively included or excluded from the Storage Intelligence plan. Structure is [documented below](#nested_filter). +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `filter` block supports: diff --git a/website/docs/r/storage_control_project_intelligence_config.html.markdown b/website/docs/r/storage_control_project_intelligence_config.html.markdown index 87a80b4668f..5d4eef9f35d 100644 --- a/website/docs/r/storage_control_project_intelligence_config.html.markdown +++ b/website/docs/r/storage_control_project_intelligence_config.html.markdown @@ -64,6 +64,12 @@ The following arguments are supported: Filter over location and bucket using include or exclude semantics. Resources that match the include or exclude filter are exclusively included or excluded from the Storage Intelligence plan. Structure is [documented below](#nested_filter). +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `filter` block supports: diff --git a/website/docs/r/storage_default_object_access_control.html.markdown b/website/docs/r/storage_default_object_access_control.html.markdown index f2e84ba34b8..312a2014ee3 100644 --- a/website/docs/r/storage_default_object_access_control.html.markdown +++ b/website/docs/r/storage_default_object_access_control.html.markdown @@ -96,6 +96,12 @@ The following arguments are supported: (Optional) The name of the object, if applied to an object. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/storage_default_object_acl.html.markdown b/website/docs/r/storage_default_object_acl.html.markdown index d514874e5b9..64a2e539ed1 100644 --- a/website/docs/r/storage_default_object_acl.html.markdown +++ b/website/docs/r/storage_default_object_acl.html.markdown @@ -63,6 +63,13 @@ resource "google_storage_default_object_acl" "image-store-default-acl" { See [GCS Object ACL documentation](https://cloud.google.com/storage/docs/json_api/v1/objectAccessControls) for more details. Omitting the field is the same as providing an empty list. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. + ## Attributes Reference Only the arguments listed above are exposed as attributes. diff --git a/website/docs/r/storage_folder.html.markdown b/website/docs/r/storage_folder.html.markdown index c94f88743ed..3b222ae0239 100644 --- a/website/docs/r/storage_folder.html.markdown +++ b/website/docs/r/storage_folder.html.markdown @@ -76,6 +76,12 @@ The following arguments are supported: trailing '/'. For example, `example_dir/example_dir2/`, `example@#/`, `a-b/d-f/`. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. * `force_destroy` - (Optional) If set to true, items within folder if any will be force destroyed. diff --git a/website/docs/r/storage_hmac_key.html.markdown b/website/docs/r/storage_hmac_key.html.markdown index 58c3f64498d..e020a72bc59 100644 --- a/website/docs/r/storage_hmac_key.html.markdown +++ b/website/docs/r/storage_hmac_key.html.markdown @@ -79,6 +79,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/storage_insights_dataset_config.html.markdown b/website/docs/r/storage_insights_dataset_config.html.markdown index 28f6fee6236..a8ea0311c21 100644 --- a/website/docs/r/storage_insights_dataset_config.html.markdown +++ b/website/docs/r/storage_insights_dataset_config.html.markdown @@ -174,6 +174,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. * `link_dataset` - (Optional) A boolean terraform only flag to link/unlink dataset. Setting this field to true while creation will automatically link the created dataset as an additional functionality. diff --git a/website/docs/r/storage_insights_report_config.html.markdown b/website/docs/r/storage_insights_report_config.html.markdown index 353865935fb..d2c7637a696 100644 --- a/website/docs/r/storage_insights_report_config.html.markdown +++ b/website/docs/r/storage_insights_report_config.html.markdown @@ -130,6 +130,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. * `force_destroy` - (Optional) If set, all the inventory report details associated with this report configuration are deleted. diff --git a/website/docs/r/storage_managed_folder.html.markdown b/website/docs/r/storage_managed_folder.html.markdown index d831fc69d38..90780f75864 100644 --- a/website/docs/r/storage_managed_folder.html.markdown +++ b/website/docs/r/storage_managed_folder.html.markdown @@ -77,6 +77,12 @@ The following arguments are supported: trailing '/'. For example, `example_dir/example_dir2/`. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. * `force_destroy` - (Optional) Allows the deletion of a managed folder even if contains objects. If a non-empty managed folder is deleted, any objects within the folder will remain in a simulated folder with the diff --git a/website/docs/r/storage_object_access_control.html.markdown b/website/docs/r/storage_object_access_control.html.markdown index 9bcc28de904..6fb494e3918 100644 --- a/website/docs/r/storage_object_access_control.html.markdown +++ b/website/docs/r/storage_object_access_control.html.markdown @@ -101,6 +101,12 @@ The following arguments are supported: Possible values are: `OWNER`, `READER`. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/storage_object_acl.html.markdown b/website/docs/r/storage_object_acl.html.markdown index b2b089dd9bb..3122740f8be 100644 --- a/website/docs/r/storage_object_acl.html.markdown +++ b/website/docs/r/storage_object_acl.html.markdown @@ -76,6 +76,12 @@ Must be set if `predefined_acl` is not. adds that role/entity pair to your `terraform plan` results when it is omitted in your config; `terraform plan` will show the correct final state at every point except for at `Create` time, where the object role/entity pair is omitted if not explicitly set. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/storage_transfer_agent_pool.html.markdown b/website/docs/r/storage_transfer_agent_pool.html.markdown index 20346689181..4907bbad354 100644 --- a/website/docs/r/storage_transfer_agent_pool.html.markdown +++ b/website/docs/r/storage_transfer_agent_pool.html.markdown @@ -84,6 +84,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `bandwidth_limit` block supports: diff --git a/website/docs/r/storage_transfer_job.html.markdown b/website/docs/r/storage_transfer_job.html.markdown index 4cc3f213d19..0197187a6c3 100644 --- a/website/docs/r/storage_transfer_job.html.markdown +++ b/website/docs/r/storage_transfer_job.html.markdown @@ -162,6 +162,13 @@ The following arguments are supported: * `logging_config` - (Optional) Logging configuration. Structure [documented below](#nested_logging_config). +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE". + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. + The `transfer_spec` block supports: * `source_agent_pool_name` - (Optional) Specifies the agent pool name associated with the posix data source. When unspecified, the default name is used. diff --git a/website/docs/r/tags_tag_binding.html.markdown b/website/docs/r/tags_tag_binding.html.markdown index bc19c300f78..b381deca68f 100644 --- a/website/docs/r/tags_tag_binding.html.markdown +++ b/website/docs/r/tags_tag_binding.html.markdown @@ -98,6 +98,12 @@ The following arguments are supported: The TagValue of the TagBinding. Must be either in id format `tagValues/{tag-value-id}`, or namespaced format `{parent-id}/{tag-key-short-name}/{tag-value-short-name}`. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/tags_tag_key.html.markdown b/website/docs/r/tags_tag_key.html.markdown index 4281920d32c..f61c4cc579d 100644 --- a/website/docs/r/tags_tag_key.html.markdown +++ b/website/docs/r/tags_tag_key.html.markdown @@ -75,6 +75,12 @@ The following arguments are supported: (Optional) Regular expression constraint for dynamic tag values, follows RE2 syntax. If present, it implicitly allows dynamic values (constrained by the regex). +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/tags_tag_value.html.markdown b/website/docs/r/tags_tag_value.html.markdown index 1e09665d9bb..5c4dd182cd1 100644 --- a/website/docs/r/tags_tag_value.html.markdown +++ b/website/docs/r/tags_tag_value.html.markdown @@ -66,6 +66,12 @@ The following arguments are supported: (Optional) User-assigned description of the TagValue. Must not exceed 256 characters. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/tpu_v2_queued_resource.html.markdown b/website/docs/r/tpu_v2_queued_resource.html.markdown index 1611b1af1f7..0ff93b6822a 100644 --- a/website/docs/r/tpu_v2_queued_resource.html.markdown +++ b/website/docs/r/tpu_v2_queued_resource.html.markdown @@ -127,6 +127,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `tpu` block supports: diff --git a/website/docs/r/tpu_v2_vm.html.markdown b/website/docs/r/tpu_v2_vm.html.markdown index 44aeaf4ad56..3981c37b0c4 100644 --- a/website/docs/r/tpu_v2_vm.html.markdown +++ b/website/docs/r/tpu_v2_vm.html.markdown @@ -261,6 +261,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `network_config` block supports: diff --git a/website/docs/r/transcoder_job.html.markdown b/website/docs/r/transcoder_job.html.markdown index 457a99c2cae..c55acacd91b 100644 --- a/website/docs/r/transcoder_job.html.markdown +++ b/website/docs/r/transcoder_job.html.markdown @@ -790,6 +790,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `config` block supports: diff --git a/website/docs/r/transcoder_job_template.html.markdown b/website/docs/r/transcoder_job_template.html.markdown index fe790f3135d..47e589f5eff 100644 --- a/website/docs/r/transcoder_job_template.html.markdown +++ b/website/docs/r/transcoder_job_template.html.markdown @@ -529,6 +529,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `config` block supports: diff --git a/website/docs/r/vector_search_collection.html.markdown b/website/docs/r/vector_search_collection.html.markdown index 0850b909008..e456b450e12 100644 --- a/website/docs/r/vector_search_collection.html.markdown +++ b/website/docs/r/vector_search_collection.html.markdown @@ -202,6 +202,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `encryption_spec` block supports: diff --git a/website/docs/r/vertex_ai_cache_config.html.markdown b/website/docs/r/vertex_ai_cache_config.html.markdown index 82ece901142..594b241f4a7 100644 --- a/website/docs/r/vertex_ai_cache_config.html.markdown +++ b/website/docs/r/vertex_ai_cache_config.html.markdown @@ -53,6 +53,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/vertex_ai_dataset.html.markdown b/website/docs/r/vertex_ai_dataset.html.markdown index 81dbd6e5a10..77ee5f33cc4 100644 --- a/website/docs/r/vertex_ai_dataset.html.markdown +++ b/website/docs/r/vertex_ai_dataset.html.markdown @@ -83,6 +83,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `encryption_spec` block supports: diff --git a/website/docs/r/vertex_ai_deployment_resource_pool.html.markdown b/website/docs/r/vertex_ai_deployment_resource_pool.html.markdown index cf3a3c9ce5a..50d218ff9bb 100644 --- a/website/docs/r/vertex_ai_deployment_resource_pool.html.markdown +++ b/website/docs/r/vertex_ai_deployment_resource_pool.html.markdown @@ -82,6 +82,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `dedicated_resources` block supports: diff --git a/website/docs/r/vertex_ai_endpoint.html.markdown b/website/docs/r/vertex_ai_endpoint.html.markdown index a7a056084ff..80cf7b30a73 100644 --- a/website/docs/r/vertex_ai_endpoint.html.markdown +++ b/website/docs/r/vertex_ai_endpoint.html.markdown @@ -225,6 +225,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `encryption_spec` block supports: diff --git a/website/docs/r/vertex_ai_endpoint_with_model_garden_deployment.html.markdown b/website/docs/r/vertex_ai_endpoint_with_model_garden_deployment.html.markdown index 934b9036776..83a7e8b8dbf 100644 --- a/website/docs/r/vertex_ai_endpoint_with_model_garden_deployment.html.markdown +++ b/website/docs/r/vertex_ai_endpoint_with_model_garden_deployment.html.markdown @@ -296,6 +296,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `model_config` block supports: diff --git a/website/docs/r/vertex_ai_feature_group.html.markdown b/website/docs/r/vertex_ai_feature_group.html.markdown index 99b37508c2c..8759cd861a4 100644 --- a/website/docs/r/vertex_ai_feature_group.html.markdown +++ b/website/docs/r/vertex_ai_feature_group.html.markdown @@ -116,6 +116,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `big_query` block supports: diff --git a/website/docs/r/vertex_ai_feature_group_feature.html.markdown b/website/docs/r/vertex_ai_feature_group_feature.html.markdown index fff9e43505e..dff548a1e5e 100644 --- a/website/docs/r/vertex_ai_feature_group_feature.html.markdown +++ b/website/docs/r/vertex_ai_feature_group_feature.html.markdown @@ -135,6 +135,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/vertex_ai_feature_online_store.html.markdown b/website/docs/r/vertex_ai_feature_online_store.html.markdown index b2aee3c6ca9..deb5679304e 100644 --- a/website/docs/r/vertex_ai_feature_online_store.html.markdown +++ b/website/docs/r/vertex_ai_feature_online_store.html.markdown @@ -167,6 +167,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. * `force_destroy` - (Optional) If set to true, any FeatureViews and Features for this FeatureOnlineStore will also be deleted. diff --git a/website/docs/r/vertex_ai_feature_online_store_featureview.html.markdown b/website/docs/r/vertex_ai_feature_online_store_featureview.html.markdown index 679950baeef..91dbdb5febb 100644 --- a/website/docs/r/vertex_ai_feature_online_store_featureview.html.markdown +++ b/website/docs/r/vertex_ai_feature_online_store_featureview.html.markdown @@ -517,6 +517,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `sync_config` block supports: diff --git a/website/docs/r/vertex_ai_featurestore.html.markdown b/website/docs/r/vertex_ai_featurestore.html.markdown index 41ecfb16f1a..80a6107f4f0 100644 --- a/website/docs/r/vertex_ai_featurestore.html.markdown +++ b/website/docs/r/vertex_ai_featurestore.html.markdown @@ -131,6 +131,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. * `force_destroy` - (Optional) If set to true, any EntityTypes and Features for this Featurestore will also be deleted diff --git a/website/docs/r/vertex_ai_featurestore_entitytype.html.markdown b/website/docs/r/vertex_ai_featurestore_entitytype.html.markdown index 18e530a45c2..14ee5ce9255 100644 --- a/website/docs/r/vertex_ai_featurestore_entitytype.html.markdown +++ b/website/docs/r/vertex_ai_featurestore_entitytype.html.markdown @@ -153,6 +153,12 @@ The following arguments are supported: (Optional, [Beta](../guides/provider_versions.html.markdown)) Config for data retention policy in offline storage. TTL in days for feature values that will be stored in offline storage. The Feature Store offline storage periodically removes obsolete feature values older than offlineStorageTtlDays since the feature generation time. If unset (or explicitly set to 0), default to 4000 days TTL. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `monitoring_config` block supports: diff --git a/website/docs/r/vertex_ai_featurestore_entitytype_feature.html.markdown b/website/docs/r/vertex_ai_featurestore_entitytype_feature.html.markdown index 26795ab770f..741d79f7f09 100644 --- a/website/docs/r/vertex_ai_featurestore_entitytype_feature.html.markdown +++ b/website/docs/r/vertex_ai_featurestore_entitytype_feature.html.markdown @@ -153,6 +153,12 @@ The following arguments are supported: (Optional) Description of the feature. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/vertex_ai_index.html.markdown b/website/docs/r/vertex_ai_index.html.markdown index 812a2fbfdc7..f8b43845af3 100644 --- a/website/docs/r/vertex_ai_index.html.markdown +++ b/website/docs/r/vertex_ai_index.html.markdown @@ -185,6 +185,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `metadata` block supports: diff --git a/website/docs/r/vertex_ai_index_endpoint.html.markdown b/website/docs/r/vertex_ai_index_endpoint.html.markdown index 5f24d13cac6..81fe1281a40 100644 --- a/website/docs/r/vertex_ai_index_endpoint.html.markdown +++ b/website/docs/r/vertex_ai_index_endpoint.html.markdown @@ -161,6 +161,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `private_service_connect_config` block supports: diff --git a/website/docs/r/vertex_ai_index_endpoint_deployed_index.html.markdown b/website/docs/r/vertex_ai_index_endpoint_deployed_index.html.markdown index 383ec7065db..a1b49ecbd3a 100644 --- a/website/docs/r/vertex_ai_index_endpoint_deployed_index.html.markdown +++ b/website/docs/r/vertex_ai_index_endpoint_deployed_index.html.markdown @@ -282,6 +282,12 @@ The following arguments are supported: (Optional) The region of the index endpoint deployment. eg us-central1 +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `automatic_resources` block supports: diff --git a/website/docs/r/vertex_ai_metadata_store.html.markdown b/website/docs/r/vertex_ai_metadata_store.html.markdown index d64f291870d..62fa6701f25 100644 --- a/website/docs/r/vertex_ai_metadata_store.html.markdown +++ b/website/docs/r/vertex_ai_metadata_store.html.markdown @@ -69,6 +69,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `encryption_spec` block supports: diff --git a/website/docs/r/vertex_ai_rag_engine_config.html.markdown b/website/docs/r/vertex_ai_rag_engine_config.html.markdown index f06fa472176..8e36444b1b9 100644 --- a/website/docs/r/vertex_ai_rag_engine_config.html.markdown +++ b/website/docs/r/vertex_ai_rag_engine_config.html.markdown @@ -85,6 +85,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `rag_managed_db_config` block supports: diff --git a/website/docs/r/vertex_ai_reasoning_engine.html.markdown b/website/docs/r/vertex_ai_reasoning_engine.html.markdown index 13ad3f9b83f..902fabe17af 100644 --- a/website/docs/r/vertex_ai_reasoning_engine.html.markdown +++ b/website/docs/r/vertex_ai_reasoning_engine.html.markdown @@ -591,7 +591,14 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. -* `deletion_policy` - (Optional) Optional. The deletion policy for the reasoning engine. Setting this to FORCE allows the reasoning engine to be deleted regardless of child undeleted resources. +* `deletion_policy` - (Optional) Optional. The deletion policy for the reasoning engine. +Setting this to FORCE allows the reasoning engine to be deleted regardless of child undeleted resources. + +When a 'terraform destroy' or 'terraform apply' would delete the resource, +the command will fail if this field is set to "PREVENT" in Terraform state. +When set to "ABANDON", the command will remove the resource from Terraform +management without updating or deleting the resource in the API. +When set to "DELETE", deleting the resource is permitted. diff --git a/website/docs/r/vertex_ai_tensorboard.html.markdown b/website/docs/r/vertex_ai_tensorboard.html.markdown index c5c9bae6d63..9e33dcf6c14 100644 --- a/website/docs/r/vertex_ai_tensorboard.html.markdown +++ b/website/docs/r/vertex_ai_tensorboard.html.markdown @@ -114,6 +114,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `encryption_spec` block supports: diff --git a/website/docs/r/vmwareengine_cluster.html.markdown b/website/docs/r/vmwareengine_cluster.html.markdown index 2add24f2817..4b27645d420 100644 --- a/website/docs/r/vmwareengine_cluster.html.markdown +++ b/website/docs/r/vmwareengine_cluster.html.markdown @@ -411,6 +411,12 @@ The following arguments are supported: for unmount remove 'datastore_mount_config' config from the update of cluster resource Structure is [documented below](#nested_datastore_mount_config). +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `node_type_configs` block supports: diff --git a/website/docs/r/vmwareengine_datastore.html.markdown b/website/docs/r/vmwareengine_datastore.html.markdown index d306682cf36..3dc8b41b97e 100644 --- a/website/docs/r/vmwareengine_datastore.html.markdown +++ b/website/docs/r/vmwareengine_datastore.html.markdown @@ -131,6 +131,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `nfs_datastore` block supports: diff --git a/website/docs/r/vmwareengine_external_access_rule.html.markdown b/website/docs/r/vmwareengine_external_access_rule.html.markdown index c16c82ae87d..45d5281164f 100644 --- a/website/docs/r/vmwareengine_external_access_rule.html.markdown +++ b/website/docs/r/vmwareengine_external_access_rule.html.markdown @@ -175,6 +175,12 @@ The following arguments are supported: (Optional) User-provided description for the external access rule. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `source_ip_ranges` block supports: diff --git a/website/docs/r/vmwareengine_external_address.html.markdown b/website/docs/r/vmwareengine_external_address.html.markdown index 70d9c1a40ae..a3e91687760 100644 --- a/website/docs/r/vmwareengine_external_address.html.markdown +++ b/website/docs/r/vmwareengine_external_address.html.markdown @@ -99,6 +99,12 @@ The following arguments are supported: (Optional) User-provided description for this resource. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/vmwareengine_network.html.markdown b/website/docs/r/vmwareengine_network.html.markdown index 072a8d459cd..2cbf9b113b2 100644 --- a/website/docs/r/vmwareengine_network.html.markdown +++ b/website/docs/r/vmwareengine_network.html.markdown @@ -107,6 +107,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/vmwareengine_network_peering.html.markdown b/website/docs/r/vmwareengine_network_peering.html.markdown index 7b93a2b762f..4012b3f1020 100644 --- a/website/docs/r/vmwareengine_network_peering.html.markdown +++ b/website/docs/r/vmwareengine_network_peering.html.markdown @@ -124,6 +124,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/vmwareengine_network_policy.html.markdown b/website/docs/r/vmwareengine_network_policy.html.markdown index 36147f93035..ab0d67d609b 100644 --- a/website/docs/r/vmwareengine_network_policy.html.markdown +++ b/website/docs/r/vmwareengine_network_policy.html.markdown @@ -118,6 +118,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `internet_access` block supports: diff --git a/website/docs/r/vmwareengine_private_cloud.html.markdown b/website/docs/r/vmwareengine_private_cloud.html.markdown index 00a010e3112..00240863631 100644 --- a/website/docs/r/vmwareengine_private_cloud.html.markdown +++ b/website/docs/r/vmwareengine_private_cloud.html.markdown @@ -147,6 +147,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. * `deletion_delay_hours` - (Optional) The number of hours to delay this request. You can set this value to an hour between 0 to 8, where setting it to 0 starts the deletion request immediately. If no value is set, a default value is set at the API Level. * `send_deletion_delay_hours_if_zero` - (Optional) While set true, deletion_delay_hours value will be sent in the request even for zero value of the field. This field is only useful for setting 0 value to the deletion_delay_hours field. It can be used both alone and together with deletion_delay_hours. diff --git a/website/docs/r/vmwareengine_subnet.html.markdown b/website/docs/r/vmwareengine_subnet.html.markdown index fe272e8d604..5e690694f90 100644 --- a/website/docs/r/vmwareengine_subnet.html.markdown +++ b/website/docs/r/vmwareengine_subnet.html.markdown @@ -87,6 +87,12 @@ The following arguments are supported: where n ranges from 1 to 5. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/vpc_access_connector.html.markdown b/website/docs/r/vpc_access_connector.html.markdown index 6798f1a2ad9..9ab90454726 100644 --- a/website/docs/r/vpc_access_connector.html.markdown +++ b/website/docs/r/vpc_access_connector.html.markdown @@ -130,6 +130,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `subnet` block supports: diff --git a/website/docs/r/workbench_instance.html.markdown b/website/docs/r/workbench_instance.html.markdown index c9d456c0dfb..fc5e431fdcd 100644 --- a/website/docs/r/workbench_instance.html.markdown +++ b/website/docs/r/workbench_instance.html.markdown @@ -408,6 +408,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. * `desired_state` - (Optional) Desired state of the Workbench Instance. Set this field to `ACTIVE` to start the Instance, and `STOPPED` to stop the Instance. diff --git a/website/docs/r/workflows_workflow.html.markdown b/website/docs/r/workflows_workflow.html.markdown index 1baae80f3c4..a4c23a13211 100644 --- a/website/docs/r/workflows_workflow.html.markdown +++ b/website/docs/r/workflows_workflow.html.markdown @@ -225,6 +225,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. * `deletion_protection` - (Optional) Whether Terraform will be prevented from destroying the workflow. Defaults to true. When a`terraform destroy` or `terraform apply` would delete the workflow, the command will fail if this field is not set to false in Terraform state. diff --git a/website/docs/r/workload_identity_service_agent.html.markdown b/website/docs/r/workload_identity_service_agent.html.markdown index 69eb10bddec..fe5a4834a49 100644 --- a/website/docs/r/workload_identity_service_agent.html.markdown +++ b/website/docs/r/workload_identity_service_agent.html.markdown @@ -47,6 +47,12 @@ The following arguments are supported: The parent resource path. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/workstations_workstation.html.markdown b/website/docs/r/workstations_workstation.html.markdown index b9fd1c8123b..bb6277803c6 100644 --- a/website/docs/r/workstations_workstation.html.markdown +++ b/website/docs/r/workstations_workstation.html.markdown @@ -150,6 +150,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. ## Attributes Reference diff --git a/website/docs/r/workstations_workstation_cluster.html.markdown b/website/docs/r/workstations_workstation_cluster.html.markdown index 80264c508cd..9546fc3e40e 100644 --- a/website/docs/r/workstations_workstation_cluster.html.markdown +++ b/website/docs/r/workstations_workstation_cluster.html.markdown @@ -265,6 +265,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `private_cluster_config` block supports: diff --git a/website/docs/r/workstations_workstation_config.html.markdown b/website/docs/r/workstations_workstation_config.html.markdown index ef58e788fba..89b1612ce87 100644 --- a/website/docs/r/workstations_workstation_config.html.markdown +++ b/website/docs/r/workstations_workstation_config.html.markdown @@ -839,6 +839,12 @@ The following arguments are supported: * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. +* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. + When a 'terraform destroy' or 'terraform apply' would delete the resource, + the command will fail if this field is set to "PREVENT" in Terraform state. + When set to "ABANDON", the command will remove the resource from Terraform + management without updating or deleting the resource in the API. + When set to "DELETE", deleting the resource is allowed. The `host` block supports: