-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Add deletion_protection field to Memcache Instance #13603
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
20685a4
7b0e1ec
f6b8672
c1df17d
520f182
e29369b
50aee9a
9a33ad4
3169bb4
c0ebded
434e7c8
5d136dd
fc09ffc
fd65ba9
f9f61a3
e7a0201
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -37,7 +37,8 @@ async: | |||||
base_url: '{{op_id}}' | ||||||
result: | ||||||
resource_inside_response: true | ||||||
custom_code: | ||||||
custom_code: !ruby/object:Provider::Terraform::CustomCode | ||||||
pre_delete: 'templates/terraform/pre_delete/memcache_instance.go.tmpl' | ||||||
examples: | ||||||
- name: 'memcache_instance_basic' | ||||||
primary_resource_id: 'instance' | ||||||
|
@@ -46,6 +47,8 @@ examples: | |||||
network_name: 'test-network' | ||||||
address_name: 'address' | ||||||
exclude_test: true | ||||||
ignore_read_extra: | ||||||
- 'deletion_protection' | ||||||
- name: 'memcache_instance_basic_test' | ||||||
primary_resource_id: 'instance' | ||||||
vars: | ||||||
|
@@ -330,3 +333,14 @@ properties: | |||||
ignore_read: true | ||||||
item_type: | ||||||
type: String | ||||||
virtual_fields: | ||||||
- name: 'deletion_protection' | ||||||
description: | | ||||||
Whether Terraform will be prevented from destroying the instance. Defaults to true. | ||||||
When a`terraform destroy` or `terraform apply` would delete the instance, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
the command will fail if this field is not set to false in Terraform state. | ||||||
When the field is set to true or unset in Terraform state, a `terraform apply` | ||||||
or `terraform destroy` that would delete the instance will fail. | ||||||
When the field is set to false, deleting the instance is allowed. | ||||||
type: Boolean | ||||||
default_value: true |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
if d.Get("deletion_protection").(bool) { | ||
return fmt.Errorf("cannot destroy memcache instance without setting deletion_protection=false and running `terraform apply`") | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -3,6 +3,7 @@ package memcache_test | |||||||||||||||||
import ( | ||||||||||||||||||
"fmt" | ||||||||||||||||||
"testing" | ||||||||||||||||||
"regexp" | ||||||||||||||||||
melinath marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||
|
||||||||||||||||||
"github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||||||||||||||||||
melinath marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||
"github.com/hashicorp/terraform-provider-google/google/acctest" | ||||||||||||||||||
|
@@ -97,3 +98,66 @@ data "google_compute_network" "memcache_network" { | |||||||||||||||||
} | ||||||||||||||||||
`, name, network) | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
func TestAccMemcacheInstance_deletionprotection(t *testing.T) { | ||||||||||||||||||
t.Parallel() | ||||||||||||||||||
|
||||||||||||||||||
prefix := fmt.Sprintf("%d", acctest.RandInt(t)) | ||||||||||||||||||
name := fmt.Sprintf("tf-test-%s", prefix) | ||||||||||||||||||
network := acctest.BootstrapSharedServiceNetworkingConnection(t, "memcache-instance-update-1") | ||||||||||||||||||
|
||||||||||||||||||
acctest.VcrTest(t, resource.TestCase{ | ||||||||||||||||||
PreCheck: func() { acctest.AccTestPreCheck(t) }, | ||||||||||||||||||
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), | ||||||||||||||||||
CheckDestroy: testAccCheckMemcacheInstanceDestroyProducer(t), | ||||||||||||||||||
Steps: []resource.TestStep{ | ||||||||||||||||||
{ | ||||||||||||||||||
Config: testAccMemcacheInstance_deletionprotection(prefix, name, network, "us-central1"), | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function needs to set deletion protection to |
||||||||||||||||||
}, | ||||||||||||||||||
{ | ||||||||||||||||||
ResourceName: "google_memcache_instance.test", | ||||||||||||||||||
ImportState: true, | ||||||||||||||||||
ImportStateVerify: true, | ||||||||||||||||||
ImportStateVerifyIgnore: []string{"reserved_ip_range_id", "deletion_protection"}, | ||||||||||||||||||
}, | ||||||||||||||||||
{ | ||||||||||||||||||
Config: testAccMemcacheInstance_deletionprotection(prefix, name, network, "us-west2"), | ||||||||||||||||||
ExpectError: regexp.MustCompile("deletion_protection"), | ||||||||||||||||||
melinath marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||
}, | ||||||||||||||||||
melinath marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||
{ | ||||||||||||||||||
melinath marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||
Config: testAccMemcacheInstance_update(prefix, name, network), | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function needs to set deletion protection to false. |
||||||||||||||||||
}, | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
}, | ||||||||||||||||||
}) | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
func testAccMemcacheInstance_deletionprotection(prefix, name, network, region string) string { | ||||||||||||||||||
return fmt.Sprintf(` | ||||||||||||||||||
provider "google" { | ||||||||||||||||||
project = "tags-partner-integ-test" | ||||||||||||||||||
user_project_override = true | ||||||||||||||||||
} | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is causing the test to fail; please remove.
Suggested change
|
||||||||||||||||||
resource "google_memcache_instance" "test" { | ||||||||||||||||||
name = "%s" | ||||||||||||||||||
region = "%s" | ||||||||||||||||||
authorized_network = data.google_compute_network.memcache_network.id | ||||||||||||||||||
deletion_protection = true | ||||||||||||||||||
node_config { | ||||||||||||||||||
cpu_count = 1 | ||||||||||||||||||
memory_size_mb = 1024 | ||||||||||||||||||
} | ||||||||||||||||||
node_count = 1 | ||||||||||||||||||
memcache_parameters { | ||||||||||||||||||
params = { | ||||||||||||||||||
"listen-backlog" = "2048" | ||||||||||||||||||
"max-item-size" = "8388608" | ||||||||||||||||||
} | ||||||||||||||||||
} | ||||||||||||||||||
reserved_ip_range_id = ["tf-bootstrap-addr-memcache-instance-update-1"] | ||||||||||||||||||
} | ||||||||||||||||||
data "google_compute_network" "memcache_network" { | ||||||||||||||||||
name = "%s" | ||||||||||||||||||
} | ||||||||||||||||||
`, name, region, network) | ||||||||||||||||||
} | ||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is no longer ruby-based yaml, so this is not necessary.