Skip to content

Commit 6e74a79

Browse files
c2thornkarolgorc
authored andcommitted
Convert from Ruby to Go
add region_instance_template Add key_revocation_action_type field
1 parent c39d3e8 commit 6e74a79

12 files changed

+208
-0
lines changed

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

+3
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,9 @@ 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
d.SetId(fmt.Sprintf("projects/%s/zones/%s/instances/%s", project, tpgresource.GetResourceNameFromSelfLink(instance.Zone), instance.Name))
206209
return nil
207210
}

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

+13
Original file line numberDiff line numberDiff line change
@@ -1262,6 +1262,15 @@ be from 0 to 999,999,999 inclusive.`,
12621262
},
12631263
},
12641264
},
1265+
1266+
"key_revocation_action_type": {
1267+
Type: schema.TypeString,
1268+
Optional: true,
1269+
ForceNew: true,
1270+
ValidateFunc: validation.StringInSlice([]string{"STOP", "NONE"}, false),
1271+
Default: "NONE",
1272+
Description: `Action to be taken when a customer's encryption key is revoked. Supports "STOP" and "NONE", with "NONE" being the default.`,
1273+
},
12651274
},
12661275
CustomizeDiff: customdiff.All(
12671276
tpgresource.DefaultProviderProject,
@@ -1437,6 +1446,7 @@ func expandComputeInstance(project string, d *schema.ResourceData, config *trans
14371446
DisplayDevice: expandDisplayDevice(d),
14381447
ResourcePolicies: tpgresource.ConvertStringArr(d.Get("resource_policies").([]interface{})),
14391448
ReservationAffinity: reservationAffinity,
1449+
KeyRevocationActionType: d.Get("key_revocation_action_type").(string),
14401450
}, nil
14411451
}
14421452

@@ -1835,6 +1845,9 @@ func resourceComputeInstanceRead(d *schema.ResourceData, meta interface{}) error
18351845
if err := d.Set("reservation_affinity", flattenReservationAffinity(instance.ReservationAffinity)); err != nil {
18361846
return fmt.Errorf("Error setting reservation_affinity: %s", err)
18371847
}
1848+
if err := d.Set("key_revocation_action_type", instance.KeyRevocationActionType); err != nil {
1849+
return fmt.Errorf("Error setting key_revocation_action_type: %s", err)
1850+
}
18381851

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

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

+13
Original file line numberDiff line numberDiff line change
@@ -1089,6 +1089,15 @@ be from 0 to 999,999,999 inclusive.`,
10891089
},
10901090
},
10911091
},
1092+
1093+
"key_revocation_action_type": {
1094+
Type: schema.TypeString,
1095+
Optional: true,
1096+
ForceNew: true,
1097+
ValidateFunc: validation.StringInSlice([]string{"NONE", "STOP"}, false),
1098+
Default: "NONE",
1099+
Description: `Action to be taken when a customer's encryption key is revoked. Supports "STOP" and "NONE", with "NONE" being the default.`,
1100+
},
10921101
},
10931102
UseJSONNumber: true,
10941103
}
@@ -1427,6 +1436,7 @@ func resourceComputeInstanceTemplateCreate(d *schema.ResourceData, meta interfac
14271436
{{- end }}
14281437
ResourcePolicies: resourcePolicies,
14291438
ReservationAffinity: reservationAffinity,
1439+
KeyRevocationActionType: d.Get("key_revocation_action_type").(string),
14301440
}
14311441

14321442
if _, ok := d.GetOk("effective_labels"); ok {
@@ -1829,6 +1839,9 @@ func resourceComputeInstanceTemplateRead(d *schema.ResourceData, meta interface{
18291839
if err = d.Set("instance_description", instanceTemplate.Properties.Description); err != nil {
18301840
return fmt.Errorf("Error setting instance_description: %s", err)
18311841
}
1842+
if err = d.Set("key_revocation_action_type", instanceTemplate.Properties.KeyRevocationActionType); err != nil {
1843+
return fmt.Errorf("Error setting key_revocation_action_type: %s", err)
1844+
}
18321845
if err = d.Set("project", project); err != nil {
18331846
return fmt.Errorf("Error setting project: %s", err)
18341847
}

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

+77
Original file line numberDiff line numberDiff line change
@@ -1613,6 +1613,56 @@ func TestAccComputeInstanceTemplate_resourceManagerTags(t *testing.T) {
16131613
})
16141614
}
16151615

1616+
func TestAccComputeInstanceTemplate_keyRevocationActionType(t *testing.T) {
1617+
t.Parallel()
1618+
1619+
var instanceTemplate compute.InstanceTemplate
1620+
context_1 := map[string]interface{}{
1621+
"instance_name": fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10)),
1622+
"key_revocation_action_type": `key_revocation_action_type = "NONE"`,
1623+
}
1624+
context_2 := map[string]interface{}{
1625+
"instance_name": context_1["instance_name"].(string),
1626+
"key_revocation_action_type": `key_revocation_action_type = "STOP"`,
1627+
}
1628+
context_3 := map[string]interface{}{
1629+
"instance_name": context_1["instance_name"].(string),
1630+
"key_revocation_action_type": ``, //no parameter should be set to NONE as default
1631+
}
1632+
1633+
acctest.VcrTest(t, resource.TestCase{
1634+
PreCheck: func() { acctest.AccTestPreCheck(t) },
1635+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
1636+
CheckDestroy: testAccCheckComputeInstanceDestroyProducer(t),
1637+
Steps: []resource.TestStep{
1638+
{
1639+
Config: testAccComputeInstanceTemplate_keyRevocationActionType(context_1),
1640+
Check: resource.ComposeTestCheckFunc(
1641+
testAccCheckComputeInstanceTemplateExists(
1642+
t, "google_compute_instance_template.foobar", &instanceTemplate),
1643+
resource.TestCheckResourceAttr("google_compute_instance_template.foobar", "key_revocation_action_type", "NONE"),
1644+
),
1645+
},
1646+
{
1647+
Config: testAccComputeInstanceTemplate_keyRevocationActionType(context_2),
1648+
Check: resource.ComposeTestCheckFunc(
1649+
testAccCheckComputeInstanceTemplateExists(
1650+
t, "google_compute_instance_template.foobar", &instanceTemplate),
1651+
resource.TestCheckResourceAttr("google_compute_instance_template.foobar", "key_revocation_action_type", "STOP"),
1652+
),
1653+
},
1654+
{
1655+
Config: testAccComputeInstanceTemplate_keyRevocationActionType(context_3),
1656+
Check: resource.ComposeTestCheckFunc(
1657+
testAccCheckComputeInstanceTemplateExists(
1658+
t, "google_compute_instance_template.foobar", &instanceTemplate),
1659+
resource.TestCheckResourceAttr("google_compute_instance_template.foobar", "key_revocation_action_type", "NONE"),
1660+
),
1661+
},
1662+
},
1663+
})
1664+
}
1665+
16161666
func TestUnitComputeInstanceTemplate_IpCidrRangeDiffSuppress(t *testing.T) {
16171667
cases := map[string]struct {
16181668
Old, New string
@@ -4401,3 +4451,30 @@ resource "google_compute_instance_template" "foobar" {
44014451
`, context)
44024452
}
44034453
{{- end }}
4454+
4455+
func testAccComputeInstanceTemplate_keyRevocationActionType(context map[string]interface{}) string {
4456+
return acctest.Nprintf(`
4457+
data "google_compute_image" "my_image" {
4458+
family = "debian-11"
4459+
project = "debian-cloud"
4460+
}
4461+
4462+
resource "google_compute_instance_template" "foobar" {
4463+
name = "%{instance_name}"
4464+
machine_type = "e2-medium"
4465+
4466+
disk {
4467+
source_image = data.google_compute_image.my_image.self_link
4468+
auto_delete = true
4469+
disk_size_gb = 10
4470+
boot = true
4471+
}
4472+
4473+
network_interface {
4474+
network = "default"
4475+
}
4476+
4477+
%{key_revocation_action_type}
4478+
}
4479+
`, context)
4480+
}

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

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

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

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

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

+13
Original file line numberDiff line numberDiff line change
@@ -1041,6 +1041,15 @@ be from 0 to 999,999,999 inclusive.`,
10411041
},
10421042
},
10431043
},
1044+
1045+
"key_revocation_action_type": {
1046+
Type: schema.TypeString,
1047+
Optional: true,
1048+
ForceNew: true,
1049+
ValidateFunc: validation.StringInSlice([]string{"NONE", "STOP"}, false),
1050+
Default: "NONE",
1051+
Description: `Action to be taken when a customer's encryption key is revoked. Supports "STOP" and "NONE", with "NONE" being the default.`,
1052+
},
10441053
},
10451054
UseJSONNumber: true,
10461055
}
@@ -1123,6 +1132,7 @@ func resourceComputeRegionInstanceTemplateCreate(d *schema.ResourceData, meta in
11231132
{{- end }}
11241133
ResourcePolicies: resourcePolicies,
11251134
ReservationAffinity: reservationAffinity,
1135+
KeyRevocationActionType: d.Get("key_revocation_action_type").(string),
11261136
}
11271137

11281138
if _, ok := d.GetOk("effective_labels"); ok {
@@ -1327,6 +1337,9 @@ func resourceComputeRegionInstanceTemplateRead(d *schema.ResourceData, meta inte
13271337
if err = d.Set("instance_description", instanceProperties.Description); err != nil {
13281338
return fmt.Errorf("Error setting instance_description: %s", err)
13291339
}
1340+
if err = d.Set("key_revocation_action_type", instanceTemplate.Properties.KeyRevocationActionType); err != nil {
1341+
return fmt.Errorf("Error setting key_revocation_action_type: %s", err)
1342+
}
13301343
if err = d.Set("project", project); err != nil {
13311344
return fmt.Errorf("Error setting project: %s", err)
13321345
}

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

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

110+
* `key_revocation_action_type` - Action to be taken when a customer's encryption key is revoked.
111+
110112
---
111113

112114
<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` - (optional) 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.

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

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

112112
* `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)
113113

114+
* `key_revocation_action_type` - (optional) Action to be taken when a customer's encryption key is revoked.
115+
114116
<a name="nested_disk"></a>The `disk` block supports:
115117

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

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

+2
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,8 @@ is desired, you will need to modify your state file manually using
249249

250250
* `partner_metadata` - (optional) [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html) key/value pair represents partner metadata assigned to instance where key represent a defined namespace and value is a json string represent the entries associted with the namespace.
251251

252+
* `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.
253+
252254
---
253255

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

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

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

426426
* `partner_metadata` - (optional) [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html) key/value pair represents partner metadata assigned to instance template where key represent a defined namespace and value is a json string represent the entries associted with the namespace.
427427

428+
* `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.
429+
428430
<a name="nested_disk"></a>The `disk` block supports:
429431

430432
* `auto_delete` - (Optional) Whether or not the disk should be auto-deleted.

mmv1/third_party/terraform/website/docs/r/compute_region_instance_template.html.markdown

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

394394
* `partner_metadata` - (optional) [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html) key/value pair represents partner metadata assigned to instance template where key represent a defined namespace and value is a json string represent the entries associted with the namespace.
395395

396+
* `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.
397+
396398
<a name="nested_disk"></a>The `disk` block supports:
397399

398400
* `auto_delete` - (Optional) Whether or not the disk should be auto-deleted.

0 commit comments

Comments
 (0)