Skip to content

Commit e5b837d

Browse files
authored
add support for universal deletion_policy (GoogleCloudPlatform#17380)
1 parent cd05ed5 commit e5b837d

319 files changed

Lines changed: 3168 additions & 278 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

mmv1/api/metadata/metadata.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ func FromResource(r api.Resource) Metadata {
3535
ApiField: "selfLink",
3636
})
3737
}
38+
if !r.DeletionPolicyExclude && !r.ExcludeDelete {
39+
m.Fields = append(m.Fields, Field{
40+
Field: "deletion_policy",
41+
ProviderOnly: true,
42+
})
43+
}
3844
return m
3945
}
4046

mmv1/api/metadata/metadata_test.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ func TestFromResource(t *testing.T) {
2121
wantMetadata Metadata
2222
}{
2323
{
24-
name: "empty resource",
25-
resource: api.Resource{},
24+
name: "empty resource",
25+
resource: api.Resource{
26+
DeletionPolicyExclude: true,
27+
},
2628
wantMetadata: Metadata{
2729
Resource: "google_product_",
2830
GenerationType: "mmv1",
@@ -55,6 +57,10 @@ func TestFromResource(t *testing.T) {
5557
{
5658
ApiField: "field",
5759
},
60+
{
61+
Field: "deletion_policy",
62+
ProviderOnly: true,
63+
},
5864
},
5965
},
6066
},
@@ -87,6 +93,10 @@ func TestFromResource(t *testing.T) {
8793
{
8894
ApiField: "selfLink",
8995
},
96+
{
97+
Field: "deletion_policy",
98+
ProviderOnly: true,
99+
},
90100
},
91101
},
92102
},

mmv1/api/resource.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,19 @@ type Resource struct {
298298
// public ca external account keys
299299
ExcludeRead bool `yaml:"exclude_read,omitempty"`
300300

301+
// Set to true for resources that are excluded from universal deletion policy due to differing
302+
// behavior on a universal option or use a different data type
303+
DeletionPolicyExclude bool `yaml:"deletion_policy_exclude,omitempty"`
304+
305+
// Set to true for resources that have deletion policy fields with custom options that are
306+
// compatible with the universal deletion policy
307+
// if set to true, use implement `deletion_policy` within the yaml of the resource
308+
DeletionPolicyCustomDocs bool `yaml:"deletion_policy_custom_docs,omitempty"`
309+
310+
// Set to the default deletion policy value for the resource.
311+
// By default this will be "DELETE".
312+
DeletionPolicyDefault string `yaml:"deletion_policy_default,omitempty"`
313+
301314
// Set to true for resources that wish to disable automatic generation of default provider
302315
// value customdiff functions
303316
// TODO rewrite: 1 instance used
@@ -492,6 +505,11 @@ func (r *Resource) setShallowDefaults() {
492505
if r.Timeouts == nil {
493506
r.Timeouts = NewTimeouts() // This only sets defaults if Timeouts is nil
494507
}
508+
if !r.DeletionPolicyExclude {
509+
if r.DeletionPolicyDefault == "" {
510+
r.DeletionPolicyDefault = "DELETE"
511+
}
512+
}
495513
}
496514

497515
// SetDefault sets default values for this Resource and all its properties.

mmv1/products/alloydb/Cluster.yaml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ custom_code:
6060
pre_update: 'templates/terraform/pre_update/alloydb_cluster.go.tmpl'
6161
pre_delete: 'templates/terraform/pre_delete/alloydb_cluster.go.tmpl'
6262
test_constants: 'templates/terraform/test_constants/import_tpgcompute.go.tmpl'
63+
deletion_policy_default: "DEFAULT"
64+
deletion_policy_custom_docs: true
6365
# Skipping the sweeper because we need to force-delete clusters.
6466
exclude_sweeper: true
6567
include_in_tgc_next: true
@@ -139,9 +141,17 @@ virtual_fields:
139141
Policy to determine if the cluster should be deleted forcefully.
140142
Deleting a cluster forcefully, deletes the cluster and all its associated instances within the cluster.
141143
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.
142-
Possible values: DEFAULT, FORCE
144+
145+
When a 'terraform destroy' or 'terraform apply' would delete the resource,
146+
the command will fail if this field is set to "PREVENT" in Terraform state.
147+
When set to "ABANDON", the command will remove the resource from Terraform
148+
management without updating or deleting the resource in the API.
149+
When set to "DELETE", the command will behave as if set to "DEFAULT".
150+
151+
Possible values: DEFAULT, FORCE, PREVENT, ABANDON, DELETE
143152
type: String
144-
default_value: "DEFAULT"
153+
#excluded from generation due to Universal Deletion Policy
154+
exclude: true
145155
- name: 'deletion_protection'
146156
description: |
147157
Whether Terraform will be prevented from destroying the cluster.

mmv1/products/chronicle/DataTable.yaml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import_format:
2323

2424
update_verb: PATCH
2525
update_mask: true
26+
deletion_policy_default: "DEFAULT"
27+
deletion_policy_custom_docs: true
2628
references:
2729
guides:
2830
'Google SecOps Guides': 'https://cloud.google.com/chronicle/docs/secops/secops-overview'
@@ -52,9 +54,17 @@ virtual_fields:
5254
The policy governing the deletion of the data table.
5355
If set to `FORCE`, allows the deletion of the data table even if it contains rows.
5456
If set to `DEFAULT`,or if the field is omitted, the data table must be empty before it can be deleted.
55-
Possible values: DEFAULT, FORCE
57+
58+
When a 'terraform destroy' or 'terraform apply' would delete the resource,
59+
the command will fail if this field is set to "PREVENT" in Terraform state.
60+
When set to "ABANDON", the command will remove the resource from Terraform
61+
management without updating or deleting the resource in the API.
62+
When set to "DELETE", the command will behave as if set to "DEFAULT".
63+
64+
Possible values: DEFAULT, FORCE, PREVENT, ABANDON, DELETE
5665
type: String
57-
default_value: "DEFAULT"
66+
#excluded from generation due to Universal Deletion Policy
67+
exclude: true
5868

5969
parameters:
6070
- name: location

mmv1/products/chronicle/Rule.yaml

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ import_format:
2727
update_verb: PATCH
2828
update_mask: true
2929
autogen_status: UnVsZQ==
30-
30+
deletion_policy_default: "DEFAULT"
31+
deletion_policy_custom_docs: true
3132
examples:
3233
- name: 'chronicle_rule_basic'
3334
primary_resource_id: example
@@ -61,11 +62,19 @@ virtual_fields:
6162
If deletion_policy = "FORCE", any retrohunts and any detections associated with the rule
6263
will also be deleted. If deletion_policy = "DEFAULT", the call will only succeed if the
6364
rule has no associated retrohunts, including completed retrohunts, and no
64-
associated detections. Regardless of this field's value, the rule
65-
deployment associated with this rule will also be deleted.
66-
Possible values: DEFAULT, FORCE
65+
associated detections. Regardless of being set to "FORCE" the rule
66+
deployment associated with this rule will also be deleted if deletion is successful.
67+
68+
When a 'terraform destroy' or 'terraform apply' would delete the resource,
69+
the command will fail if this field is set to "PREVENT" in Terraform state.
70+
When set to "ABANDON", the command will remove the resource from Terraform
71+
management without updating or deleting the resource in the API.
72+
When set to "DELETE", the command will behave as if set to "DEFAULT".
73+
74+
Possible values: DEFAULT, FORCE, PREVENT, ABANDON, DELETE
6775
type: String
68-
default_value: "DEFAULT"
76+
#excluded from generation due to Universal Deletion Policy
77+
exclude: true
6978

7079
parameters:
7180
- name: location

mmv1/products/containerattached/Cluster.yaml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ custom_code:
4545
constants: 'templates/terraform/constants/containerattached_cluster_diff.go.tmpl'
4646
pre_update: 'templates/terraform/pre_update/containerattached_update.go.tmpl'
4747
pre_delete: 'templates/terraform/pre_delete/container_attached_deletion_policy.go.tmpl'
48+
deletion_policy_custom_docs: true
4849
examples:
4950
- name: 'container_attached_cluster_basic'
5051
primary_resource_id: 'primary'
@@ -71,9 +72,18 @@ examples:
7172
- 'deletion_policy'
7273
virtual_fields:
7374
- name: 'deletion_policy'
74-
description: 'Policy to determine what flags to send on delete. Possible values: DELETE, DELETE_IGNORE_ERRORS'
75+
description: |
76+
Policy to determine what flags to send on delete.
77+
78+
When a 'terraform destroy' or 'terraform apply' would delete the resource,
79+
the command will fail if this field is set to "PREVENT" in Terraform state.
80+
When set to "ABANDON", the command will remove the resource from Terraform
81+
management without updating or deleting the resource in the API.
82+
83+
Possible values: DELETE, DELETE_IGNORE_ERRORS, PREVENT, ABANDON'. Defaults to 'DELETE'.
7584
type: String
76-
default_value: "DELETE"
85+
#excluded from generation due to Universal Deletion Policy
86+
exclude: true
7787
parameters:
7888
properties:
7989
- name: 'location'

mmv1/products/dataform/Repository.yaml

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ iam_policy:
3737
min_version: 'beta'
3838
custom_code:
3939
pre_delete: 'templates/terraform/pre_delete/dataform_repository.go.tmpl'
40+
deletion_policy_custom_docs: true
4041
examples:
4142
- name: 'dataform_repository'
4243
primary_resource_id: 'dataform_repository'
@@ -92,11 +93,17 @@ virtual_fields:
9293
- name: 'deletion_policy'
9394
type: Enum
9495
description: |
95-
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`.
96-
default_value: 'DELETE'
97-
enum_values:
98-
- 'DELETE'
99-
- 'FORCE'
96+
Policy to control how the repository and its child resources are deleted.
97+
When set to `FORCE`, any child resources of this repository will also be deleted.
98+
99+
When a 'terraform destroy' or 'terraform apply' would delete the resource,
100+
the command will fail if this field is set to "PREVENT" in Terraform state.
101+
When set to "ABANDON", the command will remove the resource from Terraform
102+
management without updating or deleting the resource in the API.
103+
104+
Possible values: `DELETE`, `FORCE`, 'PREVENT', 'ABANDON'. Defaults to `DELETE`.
105+
#excluded from generation due to Universal Deletion Policy
106+
exclude: true
100107
parameters:
101108
- name: 'region'
102109
type: String

mmv1/products/datastream/PrivateConnection.yaml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ create_url: 'projects/{{project}}/locations/{{location}}/privateConnections?priv
2727
immutable: true
2828
import_format:
2929
- 'projects/{{project}}/locations/{{location}}/privateConnections/{{private_connection_id}}'
30+
deletion_policy_custom_docs: true
31+
deletion_policy_default: "FORCE"
3032
timeouts:
3133
insert_minutes: 30
3234
update_minutes: 30
@@ -82,9 +84,14 @@ virtual_fields:
8284
The deletion policy for the private connection. Setting `FORCE` will also delete any child
8385
routes that belong to this private connection. Setting `DEFAULT` will fail the delete if
8486
child routes exist. Defaults to `FORCE` for backwards compatibility.
85-
Possible values: `DEFAULT`, `FORCE`.
87+
88+
When a 'terraform destroy' or 'terraform apply' would delete the resource,
89+
the command will fail if this field is set to "PREVENT" in Terraform state.
90+
When set to "ABANDON", the command will remove the resource from Terraform
91+
management without updating or deleting the resource in the API.
92+
When set to "DELETE", the command will behave as if set to "DEFAULT".
8693
type: String
87-
default_value: "FORCE"
94+
exclude: true
8895
parameters:
8996
- name: 'privateConnectionId'
9097
type: String

mmv1/products/firebase/AndroidApp.yaml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,6 @@ examples:
8181
ignore_read_extra:
8282
- 'project'
8383
- 'deletion_policy'
84-
virtual_fields:
85-
- name: 'deletion_policy'
86-
description: |
87-
(Optional) Set to `ABANDON` to allow the AndroidApp to be untracked from terraform state
88-
rather than deleted upon `terraform destroy`. This is useful because the AndroidApp may be
89-
serving traffic. Set to `DELETE` to delete the AndroidApp. Defaults to `DELETE`.
90-
type: String
91-
default_value: "DELETE"
9284
parameters:
9385
properties:
9486
- name: 'name'

0 commit comments

Comments
 (0)