Skip to content

Commit 1b0af00

Browse files
karolgorcc2thornmelinathNickElliot
authored andcommitted
Add key_revocation_action_field to google_compute_instance and related resources (GoogleCloudPlatform#11920)
Co-authored-by: Cameron Thornton <[email protected]> Co-authored-by: Stephen Lewis (Burrows) <[email protected]> Co-authored-by: Nick Elliot <[email protected]>
1 parent a3331cf commit 1b0af00

13 files changed

+284
-0
lines changed

mmv1/third_party/terraform/services/compute/data_source_google_compute_instance.go.tmpl

+4
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,13 @@ func dataSourceGoogleComputeInstanceRead(d *schema.ResourceData, meta interface{
202202
if err := d.Set("name", instance.Name); err != nil {
203203
return fmt.Errorf("Error setting name: %s", err)
204204
}
205+
if err := d.Set("key_revocation_action_type", instance.KeyRevocationActionType); err != nil {
206+
return fmt.Errorf("Error setting key_revocation_action_type: %s", err)
207+
}
205208
if err := d.Set("creation_timestamp", instance.CreationTimestamp); err != nil {
206209
return fmt.Errorf("Error setting creation_timestamp: %s", err)
207210
}
211+
208212
d.SetId(fmt.Sprintf("projects/%s/zones/%s/instances/%s", project, tpgresource.GetResourceNameFromSelfLink(instance.Zone), instance.Name))
209213
return nil
210214
}

mmv1/third_party/terraform/services/compute/resource_compute_instance.go.tmpl

+12
Original file line numberDiff line numberDiff line change
@@ -1268,6 +1268,14 @@ be from 0 to 999,999,999 inclusive.`,
12681268
},
12691269
},
12701270
},
1271+
1272+
"key_revocation_action_type": {
1273+
Type: schema.TypeString,
1274+
Optional: true,
1275+
ForceNew: true,
1276+
ValidateFunc: validation.StringInSlice([]string{"STOP", "NONE", ""}, false),
1277+
Description: `Action to be taken when a customer's encryption key is revoked. Supports "STOP" and "NONE", with "NONE" being the default.`,
1278+
},
12711279
},
12721280
CustomizeDiff: customdiff.All(
12731281
tpgresource.DefaultProviderProject,
@@ -1443,6 +1451,7 @@ func expandComputeInstance(project string, d *schema.ResourceData, config *trans
14431451
DisplayDevice: expandDisplayDevice(d),
14441452
ResourcePolicies: tpgresource.ConvertStringArr(d.Get("resource_policies").([]interface{})),
14451453
ReservationAffinity: reservationAffinity,
1454+
KeyRevocationActionType: d.Get("key_revocation_action_type").(string),
14461455
}, nil
14471456
}
14481457

@@ -1844,6 +1853,9 @@ func resourceComputeInstanceRead(d *schema.ResourceData, meta interface{}) error
18441853
if err := d.Set("reservation_affinity", flattenReservationAffinity(instance.ReservationAffinity)); err != nil {
18451854
return fmt.Errorf("Error setting reservation_affinity: %s", err)
18461855
}
1856+
if err := d.Set("key_revocation_action_type", instance.KeyRevocationActionType); err != nil {
1857+
return fmt.Errorf("Error setting key_revocation_action_type: %s", err)
1858+
}
18471859

18481860
d.SetId(fmt.Sprintf("projects/%s/zones/%s/instances/%s", project, zone, instance.Name))
18491861

mmv1/third_party/terraform/services/compute/resource_compute_instance_template.go.tmpl

+12
Original file line numberDiff line numberDiff line change
@@ -1104,6 +1104,14 @@ be from 0 to 999,999,999 inclusive.`,
11041104
},
11051105
},
11061106
},
1107+
1108+
"key_revocation_action_type": {
1109+
Type: schema.TypeString,
1110+
Optional: true,
1111+
ForceNew: true,
1112+
ValidateFunc: validation.StringInSlice([]string{"NONE", "STOP", ""}, false),
1113+
Description: `Action to be taken when a customer's encryption key is revoked. Supports "STOP" and "NONE", with "NONE" being the default.`,
1114+
},
11071115
},
11081116
UseJSONNumber: true,
11091117
}
@@ -1445,6 +1453,7 @@ func resourceComputeInstanceTemplateCreate(d *schema.ResourceData, meta interfac
14451453
{{- end }}
14461454
ResourcePolicies: resourcePolicies,
14471455
ReservationAffinity: reservationAffinity,
1456+
KeyRevocationActionType: d.Get("key_revocation_action_type").(string),
14481457
}
14491458

14501459
if _, ok := d.GetOk("effective_labels"); ok {
@@ -1858,6 +1867,9 @@ func resourceComputeInstanceTemplateRead(d *schema.ResourceData, meta interface{
18581867
if err = d.Set("instance_description", instanceTemplate.Properties.Description); err != nil {
18591868
return fmt.Errorf("Error setting instance_description: %s", err)
18601869
}
1870+
if err = d.Set("key_revocation_action_type", instanceTemplate.Properties.KeyRevocationActionType); err != nil {
1871+
return fmt.Errorf("Error setting key_revocation_action_type: %s", err)
1872+
}
18611873
if err = d.Set("project", project); err != nil {
18621874
return fmt.Errorf("Error setting project: %s", err)
18631875
}

mmv1/third_party/terraform/services/compute/resource_compute_instance_template_test.go.tmpl

+77
Original file line numberDiff line numberDiff line change
@@ -1634,6 +1634,56 @@ func TestAccComputeInstanceTemplate_resourceManagerTags(t *testing.T) {
16341634
})
16351635
}
16361636

1637+
func TestAccComputeInstanceTemplate_keyRevocationActionType(t *testing.T) {
1638+
t.Parallel()
1639+
1640+
var instanceTemplate compute.InstanceTemplate
1641+
context_1 := map[string]interface{}{
1642+
"instance_name": fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10)),
1643+
"key_revocation_action_type": `"NONE"`,
1644+
}
1645+
context_2 := map[string]interface{}{
1646+
"instance_name": context_1["instance_name"].(string),
1647+
"key_revocation_action_type": `"STOP"`,
1648+
}
1649+
context_3 := map[string]interface{}{
1650+
"instance_name": context_1["instance_name"].(string),
1651+
"key_revocation_action_type": `""`,
1652+
}
1653+
1654+
acctest.VcrTest(t, resource.TestCase{
1655+
PreCheck: func() { acctest.AccTestPreCheck(t) },
1656+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
1657+
CheckDestroy: testAccCheckComputeInstanceTemplateDestroyProducer(t),
1658+
Steps: []resource.TestStep{
1659+
{
1660+
Config: testAccComputeInstanceTemplate_keyRevocationActionType(context_1),
1661+
Check: resource.ComposeTestCheckFunc(
1662+
testAccCheckComputeInstanceTemplateExists(
1663+
t, "google_compute_instance_template.foobar", &instanceTemplate),
1664+
resource.TestCheckResourceAttr("google_compute_instance_template.foobar", "key_revocation_action_type", "NONE"),
1665+
),
1666+
},
1667+
{
1668+
Config: testAccComputeInstanceTemplate_keyRevocationActionType(context_2),
1669+
Check: resource.ComposeTestCheckFunc(
1670+
testAccCheckComputeInstanceTemplateExists(
1671+
t, "google_compute_instance_template.foobar", &instanceTemplate),
1672+
resource.TestCheckResourceAttr("google_compute_instance_template.foobar", "key_revocation_action_type", "STOP"),
1673+
),
1674+
},
1675+
{
1676+
Config: testAccComputeInstanceTemplate_keyRevocationActionType(context_3),
1677+
Check: resource.ComposeTestCheckFunc(
1678+
testAccCheckComputeInstanceTemplateExists(
1679+
t, "google_compute_instance_template.foobar", &instanceTemplate),
1680+
resource.TestCheckResourceAttr("google_compute_instance_template.foobar", "key_revocation_action_type", ""),
1681+
),
1682+
},
1683+
},
1684+
})
1685+
}
1686+
16371687
func TestUnitComputeInstanceTemplate_IpCidrRangeDiffSuppress(t *testing.T) {
16381688
cases := map[string]struct {
16391689
Old, New string
@@ -4453,3 +4503,30 @@ resource "google_compute_instance_template" "foobar" {
44534503
`, context)
44544504
}
44554505
{{- end }}
4506+
4507+
func testAccComputeInstanceTemplate_keyRevocationActionType(context map[string]interface{}) string {
4508+
return acctest.Nprintf(`
4509+
data "google_compute_image" "my_image" {
4510+
family = "debian-11"
4511+
project = "debian-cloud"
4512+
}
4513+
4514+
resource "google_compute_instance_template" "foobar" {
4515+
name = "%{instance_name}"
4516+
machine_type = "e2-medium"
4517+
4518+
disk {
4519+
source_image = data.google_compute_image.my_image.self_link
4520+
auto_delete = true
4521+
disk_size_gb = 10
4522+
boot = true
4523+
}
4524+
4525+
network_interface {
4526+
network = "default"
4527+
}
4528+
4529+
key_revocation_action_type = %{key_revocation_action_type}
4530+
}
4531+
`, context)
4532+
}

mmv1/third_party/terraform/services/compute/resource_compute_instance_test.go.tmpl

+77
Original file line numberDiff line numberDiff line change
@@ -3532,6 +3532,56 @@ func TestAccComputeInstance_proactiveAttributionLabel(t *testing.T) {
35323532
})
35333533
}
35343534

3535+
func TestAccComputeInstance_keyRevocationActionType(t *testing.T) {
3536+
t.Parallel()
3537+
3538+
var instance compute.Instance
3539+
context_1 := map[string]interface{}{
3540+
"instance_name": fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10)),
3541+
"key_revocation_action_type": `"NONE"`,
3542+
}
3543+
context_2 := map[string]interface{}{
3544+
"instance_name": context_1["instance_name"].(string),
3545+
"key_revocation_action_type": `"STOP"`,
3546+
}
3547+
context_3 := map[string]interface{}{
3548+
"instance_name": context_1["instance_name"].(string),
3549+
"key_revocation_action_type": `""`,
3550+
}
3551+
3552+
acctest.VcrTest(t, resource.TestCase{
3553+
PreCheck: func() { acctest.AccTestPreCheck(t) },
3554+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
3555+
CheckDestroy: testAccCheckComputeInstanceDestroyProducer(t),
3556+
Steps: []resource.TestStep{
3557+
{
3558+
Config: testAccComputeInstance_keyRevocationActionType(context_1),
3559+
Check: resource.ComposeTestCheckFunc(
3560+
testAccCheckComputeInstanceExists(
3561+
t, "google_compute_instance.foobar", &instance),
3562+
resource.TestCheckResourceAttr("google_compute_instance.foobar", "key_revocation_action_type", "NONE"),
3563+
),
3564+
},
3565+
{
3566+
Config: testAccComputeInstance_keyRevocationActionType(context_2),
3567+
Check: resource.ComposeTestCheckFunc(
3568+
testAccCheckComputeInstanceExists(
3569+
t, "google_compute_instance.foobar", &instance),
3570+
resource.TestCheckResourceAttr("google_compute_instance.foobar", "key_revocation_action_type", "STOP"),
3571+
),
3572+
},
3573+
{
3574+
Config: testAccComputeInstance_keyRevocationActionType(context_3),
3575+
Check: resource.ComposeTestCheckFunc(
3576+
testAccCheckComputeInstanceExists(
3577+
t, "google_compute_instance.foobar", &instance),
3578+
resource.TestCheckResourceAttr("google_compute_instance.foobar", "key_revocation_action_type", ""),
3579+
),
3580+
},
3581+
},
3582+
})
3583+
}
3584+
35353585
{{ if ne $.TargetVersionName `ga` -}}
35363586
const errorDeleteAccessConfigWithSecPolicy = "Cannot delete an access config with a security policy set. Please remove the security policy first"
35373587

@@ -10838,3 +10888,30 @@ resource "google_compute_instance" "foobar" {
1083810888
}
1083910889
`, diskName, instanceName, machineType, zone, bootDiskInterface, allowStoppingForUpdate)
1084010890
}
10891+
10892+
func testAccComputeInstance_keyRevocationActionType(context map[string]interface{}) string {
10893+
return acctest.Nprintf(`
10894+
data "google_compute_image" "my_image" {
10895+
family = "debian-11"
10896+
project = "debian-cloud"
10897+
}
10898+
10899+
resource "google_compute_instance" "foobar" {
10900+
name = "%{instance_name}"
10901+
machine_type = "e2-medium"
10902+
zone = "us-central1-a"
10903+
10904+
boot_disk {
10905+
initialize_params {
10906+
image = data.google_compute_image.my_image.self_link
10907+
}
10908+
}
10909+
10910+
network_interface {
10911+
network = "default"
10912+
}
10913+
10914+
key_revocation_action_type = %{key_revocation_action_type}
10915+
}
10916+
`, context)
10917+
}

mmv1/third_party/terraform/services/compute/resource_compute_region_instance_template.go.tmpl

+12
Original file line numberDiff line numberDiff line change
@@ -1056,6 +1056,14 @@ be from 0 to 999,999,999 inclusive.`,
10561056
},
10571057
},
10581058
},
1059+
1060+
"key_revocation_action_type": {
1061+
Type: schema.TypeString,
1062+
Optional: true,
1063+
ForceNew: true,
1064+
ValidateFunc: validation.StringInSlice([]string{"NONE", "STOP", ""}, false),
1065+
Description: `Action to be taken when a customer's encryption key is revoked. Supports "STOP" and "NONE", with "NONE" being the default.`,
1066+
},
10591067
},
10601068
UseJSONNumber: true,
10611069
}
@@ -1138,6 +1146,7 @@ func resourceComputeRegionInstanceTemplateCreate(d *schema.ResourceData, meta in
11381146
{{- end }}
11391147
ResourcePolicies: resourcePolicies,
11401148
ReservationAffinity: reservationAffinity,
1149+
KeyRevocationActionType: d.Get("key_revocation_action_type").(string),
11411150
}
11421151

11431152
if _, ok := d.GetOk("effective_labels"); ok {
@@ -1345,6 +1354,9 @@ func resourceComputeRegionInstanceTemplateRead(d *schema.ResourceData, meta inte
13451354
if err = d.Set("instance_description", instanceProperties.Description); err != nil {
13461355
return fmt.Errorf("Error setting instance_description: %s", err)
13471356
}
1357+
if err = d.Set("key_revocation_action_type", instanceProperties.KeyRevocationActionType); err != nil {
1358+
return fmt.Errorf("Error setting key_revocation_action_type: %s", err)
1359+
}
13481360
if err = d.Set("project", project); err != nil {
13491361
return fmt.Errorf("Error setting project: %s", err)
13501362
}

mmv1/third_party/terraform/services/compute/resource_compute_region_instance_template_test.go.tmpl

+78
Original file line numberDiff line numberDiff line change
@@ -1282,6 +1282,56 @@ func TestAccComputeRegionInstanceTemplate_resourceManagerTags(t *testing.T) {
12821282
})
12831283
}
12841284

1285+
func TestAccComputeRegionInstanceTemplate_keyRevocationActionType(t *testing.T) {
1286+
t.Parallel()
1287+
1288+
var instanceTemplate compute.InstanceTemplate
1289+
context_1 := map[string]interface{}{
1290+
"instance_name": fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10)),
1291+
"key_revocation_action_type": `"NONE"`,
1292+
}
1293+
context_2 := map[string]interface{}{
1294+
"instance_name": context_1["instance_name"].(string),
1295+
"key_revocation_action_type": `"STOP"`,
1296+
}
1297+
context_3 := map[string]interface{}{
1298+
"instance_name": context_1["instance_name"].(string),
1299+
"key_revocation_action_type": `""`,
1300+
}
1301+
1302+
acctest.VcrTest(t, resource.TestCase{
1303+
PreCheck: func() { acctest.AccTestPreCheck(t) },
1304+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
1305+
CheckDestroy: testAccCheckComputeRegionInstanceTemplateDestroyProducer(t),
1306+
Steps: []resource.TestStep{
1307+
{
1308+
Config: testAccComputeRegionInstanceTemplate_keyRevocationActionType(context_1),
1309+
Check: resource.ComposeTestCheckFunc(
1310+
testAccCheckComputeRegionInstanceTemplateExists(
1311+
t, "google_compute_region_instance_template.foobar", &instanceTemplate),
1312+
resource.TestCheckResourceAttr("google_compute_region_instance_template.foobar", "key_revocation_action_type", "NONE"),
1313+
),
1314+
},
1315+
{
1316+
Config: testAccComputeRegionInstanceTemplate_keyRevocationActionType(context_2),
1317+
Check: resource.ComposeTestCheckFunc(
1318+
testAccCheckComputeRegionInstanceTemplateExists(
1319+
t, "google_compute_region_instance_template.foobar", &instanceTemplate),
1320+
resource.TestCheckResourceAttr("google_compute_region_instance_template.foobar", "key_revocation_action_type", "STOP"),
1321+
),
1322+
},
1323+
{
1324+
Config: testAccComputeRegionInstanceTemplate_keyRevocationActionType(context_3),
1325+
Check: resource.ComposeTestCheckFunc(
1326+
testAccCheckComputeRegionInstanceTemplateExists(
1327+
t, "google_compute_region_instance_template.foobar", &instanceTemplate),
1328+
resource.TestCheckResourceAttr("google_compute_region_instance_template.foobar", "key_revocation_action_type", ""),
1329+
),
1330+
},
1331+
},
1332+
})
1333+
}
1334+
12851335
func testAccCheckComputeRegionInstanceTemplateDestroyProducer(t *testing.T) func(s *terraform.State) error {
12861336
return func(s *terraform.State) error {
12871337
config := acctest.GoogleProviderConfig(t)
@@ -3818,3 +3868,31 @@ resource "google_compute_region_instance_template" "foobar" {
38183868
}
38193869
`, context)
38203870
}
3871+
3872+
func testAccComputeRegionInstanceTemplate_keyRevocationActionType(context map[string]interface{}) string {
3873+
return acctest.Nprintf(`
3874+
data "google_compute_image" "my_image" {
3875+
family = "debian-11"
3876+
project = "debian-cloud"
3877+
}
3878+
3879+
resource "google_compute_region_instance_template" "foobar" {
3880+
name = "%{instance_name}"
3881+
machine_type = "e2-medium"
3882+
region = "us-central1"
3883+
3884+
disk {
3885+
source_image = data.google_compute_image.my_image.self_link
3886+
auto_delete = true
3887+
disk_size_gb = 10
3888+
boot = true
3889+
}
3890+
3891+
network_interface {
3892+
network = "default"
3893+
}
3894+
3895+
key_revocation_action_type = %{key_revocation_action_type}
3896+
}
3897+
`, context)
3898+
}

mmv1/third_party/terraform/website/docs/d/compute_instance.html.markdown

+2
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ The following arguments are supported:
109109
encoded SHA-256 hash of the [customer-supplied encryption key]
110110
(https://cloud.google.com/compute/docs/disks/customer-supplied-encryption) that protects this resource.
111111

112+
* `key_revocation_action_type` - Action to be taken when a customer's encryption key is revoked.
113+
112114
---
113115

114116
<a name="nested_boot_disk"></a>The `boot_disk` block supports:

mmv1/third_party/terraform/website/docs/d/compute_instance_template.html.markdown

+2
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ The following arguments are supported:
125125

126126
* `confidential_instance_config` - Enable [Confidential Mode](https://cloud.google.com/compute/confidential-vm/docs/about-cvm) on this VM. Structure is [documented below](#nested_confidential_instance_config)
127127

128+
* `key_revocation_action_type` - Action to be taken when a customer's encryption key is revoked.
129+
128130
<a name="nested_disk"></a>The `disk` block supports:
129131

130132
* `auto_delete` - Whether or not the disk should be auto-deleted.

0 commit comments

Comments
 (0)