Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions mmv1/api/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,14 @@ type Resource struct {
// public ca external account keys
ExcludeRead bool `yaml:"exclude_read,omitempty"`

// Set to true for resources that are to exclude the default generated deletion policy field
// Primarily for resources that had deletion policy implementations before the universal generation.
DeletionPolicyExclude bool `yaml:"deletion_policy,omitempty"`

// Set to the default deletion policy value for the resource.
// By default this will be "DELETE".
DeletionPolicyDefault string `yaml:"deletion_policy_default,omitempty"`

// Set to true for resources that wish to disable automatic generation of default provider
// value customdiff functions
// TODO rewrite: 1 instance used
Expand Down Expand Up @@ -488,6 +496,11 @@ func (r *Resource) setShallowDefaults() {
if r.Timeouts == nil {
r.Timeouts = NewTimeouts() // This only sets defaults if Timeouts is nil
}
if !r.DeletionPolicyExclude {
if r.DeletionPolicyDefault == "" {
r.DeletionPolicyDefault = "DELETE"
}
}
}

// SetDefault sets default values for this Resource and all its properties.
Expand Down
1 change: 1 addition & 0 deletions mmv1/products/alloydb/Cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ custom_code:
pre_update: 'templates/terraform/pre_update/alloydb_cluster.go.tmpl'
pre_delete: 'templates/terraform/pre_delete/alloydb_cluster.go.tmpl'
# Skipping the sweeper because we need to force-delete clusters.
deletion_policy_exclude: true
exclude_sweeper: true
include_in_tgc_next: true
tgc_include_handwritten_tests: true
Expand Down
2 changes: 1 addition & 1 deletion mmv1/products/chronicle/Rule.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import_format:
update_verb: PATCH
update_mask: true
autogen_status: UnVsZQ==

deletion_policy_exclude: true
examples:
- name: 'chronicle_rule_basic'
primary_resource_id: example
Expand Down
1 change: 1 addition & 0 deletions mmv1/products/containerattached/Cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ custom_code:
constants: 'templates/terraform/constants/containerattached_cluster_diff.go.tmpl'
pre_update: 'templates/terraform/pre_update/containerattached_update.go.tmpl'
pre_delete: 'templates/terraform/pre_delete/container_attached_deletion_policy.go.tmpl'
deletion_policy_exclude: true
examples:
- name: 'container_attached_cluster_basic'
primary_resource_id: 'primary'
Expand Down
1 change: 1 addition & 0 deletions mmv1/products/dataform/Repository.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ iam_policy:
min_version: 'beta'
custom_code:
pre_delete: 'templates/terraform/pre_delete/dataform_repository.go.tmpl'
deletion_policy_exclude: true
examples:
- name: 'dataform_repository'
primary_resource_id: 'dataform_repository'
Expand Down
1 change: 1 addition & 0 deletions mmv1/products/firebase/AndroidApp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ identity:
- name
custom_code:
custom_delete: 'templates/terraform/custom_delete/firebase_app_deletion_policy.tmpl'
deletion_policy_exclude: true
# Sweeper skipped as this resource has customized deletion.
exclude_sweeper: true
examples:
Expand Down
1 change: 1 addition & 0 deletions mmv1/products/firebase/AppleApp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
- name
custom_code:
custom_delete: 'templates/terraform/custom_delete/firebase_app_deletion_policy.tmpl'
deletion_policy_exclude: true
# Sweeper skipped as this resource has customized deletion.
exclude_sweeper: true
examples:
Expand All @@ -70,7 +71,7 @@
display_name: 'Display Name Full'
bundle_id: 'apple.app.12345'
app_store_id: '12345'
# Has to be a 10-digit number.

Check warning on line 74 in mmv1/products/firebase/AppleApp.yaml

View workflow job for this annotation

GitHub Actions / lint-yaml

74:2 [comments-indentation] comment not indented like content
team_id: '9987654321'
api_key_name: 'api-key'
test_env_vars:
Expand Down
1 change: 1 addition & 0 deletions mmv1/products/firebase/WebApp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ identity:
- name
custom_code:
custom_delete: 'templates/terraform/custom_delete/firebase_app_deletion_policy.tmpl'
deletion_policy_exclude: true
# Sweeper skipped as this resource has customized deletion.
exclude_sweeper: true
examples:
Expand Down
1 change: 1 addition & 0 deletions mmv1/products/firebasedataconnect/Service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ async:
resource_inside_response: true
include_project: false
autogen_status: U2VydmljZQ==
deletion_policy_exclude: true
parameters:
- name: location
type: String
Expand Down
1 change: 1 addition & 0 deletions mmv1/products/firestore/Database.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ async:
resource_inside_response: true
custom_code:
pre_delete: 'templates/terraform/pre_delete/firestore_database.go.tmpl'
deletion_policy_exclude: true
examples:
- name: 'firestore_default_database'
primary_resource_id: 'database'
Expand Down
1 change: 1 addition & 0 deletions mmv1/products/looker/Instance.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ async:
base_url: '{{op_id}}'
result:
resource_inside_response: true
deletion_policy_exclude: true
exclude_sweeper: true
error_abort_predicates:

Expand Down
1 change: 1 addition & 0 deletions mmv1/products/netapp/Volume.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ custom_code:
pre_delete: 'templates/terraform/pre_delete/netapp_volume_force_delete.go.tmpl'
pre_update: 'templates/terraform/pre_update/netapp_volume_update.go.tmpl'
constants: 'templates/terraform/constants/netapp_volume.go.tmpl'
deletion_policy_exclude: true
examples:
- name: 'netapp_volume_basic'
primary_resource_id: 'test_volume'
Expand Down
1 change: 1 addition & 0 deletions mmv1/products/secretmanager/SecretVersion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ custom_code:
constants: 'templates/terraform/constants/secret_version.go.tmpl'
# Sweeper skipped as this resource has customized deletion.
exclude_sweeper: true
deletion_policy_exclude: true
examples:
- name: 'secret_version_basic'
primary_resource_id: 'secret-version-basic'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ custom_code:
pre_delete: 'templates/terraform/pre_delete/regional_secret_version_deletion_policy.go.tmpl'
custom_import: 'templates/terraform/custom_import/regional_secret_version.go.tmpl'
constants: 'templates/terraform/constants/regional_secret_version.go.tmpl'
deletion_policy_exclude: true
# Sweeper skipped as this resource has customized deletion.
exclude_sweeper: true
include_in_tgc_next: true
Expand Down
1 change: 1 addition & 0 deletions mmv1/products/securesourcemanager/Instance.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ iam_policy:
- '{{instance_id}}'
custom_code:
pre_delete: 'templates/terraform/pre_delete/securesourcemanager_deletion_policy.go.tmpl'
deletion_policy_exclude: true
examples:
- name: 'secure_source_manager_instance_basic'
primary_resource_id: 'default'
Expand Down
1 change: 1 addition & 0 deletions mmv1/products/securesourcemanager/Repository.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ iam_policy:
- '{{repository_id}}'
custom_code:
pre_delete: 'templates/terraform/pre_delete/securesourcemanager_deletion_policy.go.tmpl'
deletion_policy_exclude: true
examples:
- name: 'secure_source_manager_repository_basic'
primary_resource_id: 'default'
Expand Down
1 change: 1 addition & 0 deletions mmv1/products/sql/Database.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ collection_url_key: 'items'
custom_code:
pre_delete: 'templates/terraform/pre_delete/sql_database_deletion_policy.tmpl'
pre_read: 'templates/terraform/pre_read/sql_database_activation_policy.tmpl'
deletion_policy_exclude: true
# Sweeper skipped as this resource has customized deletion.
exclude_sweeper: true
read_error_transform: 'transformSQLDatabaseReadError'
Expand Down
23 changes: 23 additions & 0 deletions mmv1/templates/terraform/resource.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,20 @@ func Resource{{ $.ResourceName -}}() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
{{- end}}
{{- if not $.DeletionPolicyExclude }}
"deletion_policy": {
Type: schema.TypeString,
Optional: true,
Description: `Whether Terraform will be prevented from destroying the instance. Defaults to "{{$.DeletionPolicyDefault}}".
When a 'terraform destroy' or 'terraform apply' would delete the instance,
the command will fail if this field is set to "PREVENT" in Terraform state.
When set to "ABANDON", the command will remove the resource from Terraform
management without updating or deleting the resource in the API.
When set to "DELETE", deleting the resource is allowed.
`,
Default: "{{$.DeletionPolicyDefault}}",
},
{{- end}}
},
UseJSONNumber: true,
Expand Down Expand Up @@ -1125,6 +1139,15 @@ func resource{{ $.ResourceName }}Delete(d *schema.ResourceData, meta interface{}
{{- if $.CustomCode.PreDelete }}
{{ customTemplate $ $.CustomCode.PreDelete false -}}
{{- end }}
{{- if not $.DeletionPolicyExclude }}
if d.Get("deletion_policy").(string) == "PREVENT" {
return fmt.Errorf("cannot destroy {{$.ResourceName}} without setting deletion_policy=\"DELETE\" and running `terraform apply`")
}
if d.Get("deletion_policy").(string) == "ABANDON" {
log.Printf("[DEBUG] deletion_policy set to \"ABANDON\", removing {{ $.Name }} %q from Terraform state without deletion", d.Id())
return nil
}
{{- end }}

log.Printf("[DEBUG] Deleting {{ $.Name }} %q", d.Id())
res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{
Expand Down
8 changes: 8 additions & 0 deletions mmv1/templates/terraform/resource.html.markdown.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,14 @@ The following arguments are supported:
If it is not provided, the provider project is used.
{{ "" }}
{{- end }}
{{- if not $.DeletionPolicyExclude }}
* `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to {{$.DeletionPolicyDefault}}.
When a 'terraform destroy' or 'terraform apply' would delete the resource,
the command will fail if this field is set to "PREVENT" in Terraform state.
When set to "ABANDON", the command will remove the resource from Terraform
management without updating or deleting the resource in the API.
When set to "DELETE", deleting the resource is allowed.
{{- end }}
{{- range $f := $.VirtualFields }}
* `{{$f.Name}}` - (Optional) {{$f.Description}}
{{- end }}
Expand Down
Loading