Skip to content

Commit 8c1e296

Browse files
committed
Convert from Ruby to Go
add region_instance_template Add key_revocation_action_type field
1 parent c0fae5c commit 8c1e296

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
@@ -1261,6 +1261,15 @@ be from 0 to 999,999,999 inclusive.`,
12611261
},
12621262
},
12631263
},
1264+
1265+
"key_revocation_action_type": {
1266+
Type: schema.TypeString,
1267+
Optional: true,
1268+
ForceNew: true,
1269+
ValidateFunc: validation.StringInSlice([]string{"STOP", "NONE"}, false),
1270+
Default: "NONE",
1271+
Description: `Action to be taken when a customer's encryption key is revoked. Supports "STOP" and "NONE", with "NONE" being the default.`,
1272+
},
12641273
},
12651274
CustomizeDiff: customdiff.All(
12661275
tpgresource.DefaultProviderProject,
@@ -1436,6 +1445,7 @@ func expandComputeInstance(project string, d *schema.ResourceData, config *trans
14361445
DisplayDevice: expandDisplayDevice(d),
14371446
ResourcePolicies: tpgresource.ConvertStringArr(d.Get("resource_policies").([]interface{})),
14381447
ReservationAffinity: reservationAffinity,
1448+
KeyRevocationActionType: d.Get("key_revocation_action_type").(string),
14391449
}, nil
14401450
}
14411451

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

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

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
@@ -1615,6 +1615,56 @@ func TestAccComputeInstanceTemplate_resourceManagerTags(t *testing.T) {
16151615
})
16161616
}
16171617

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

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

+77
Original file line numberDiff line numberDiff line change
@@ -3476,6 +3476,56 @@ func TestAccComputeInstance_proactiveAttributionLabel(t *testing.T) {
34763476
})
34773477
}
34783478

3479+
func TestAccComputeInstance_keyRevocationActionType(t *testing.T) {
3480+
t.Parallel()
3481+
3482+
var instance compute.Instance
3483+
context_1 := map[string]interface{}{
3484+
"instance_name": fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10)),
3485+
"key_revocation_action_type": `key_revocation_action_type = "NONE"`,
3486+
}
3487+
context_2 := map[string]interface{}{
3488+
"instance_name": context_1["instance_name"].(string),
3489+
"key_revocation_action_type": `key_revocation_action_type = "STOP"`,
3490+
}
3491+
context_3 := map[string]interface{}{
3492+
"instance_name": context_1["instance_name"].(string),
3493+
"key_revocation_action_type": ``, //no parameter should be set to NONE as default
3494+
}
3495+
3496+
acctest.VcrTest(t, resource.TestCase{
3497+
PreCheck: func() { acctest.AccTestPreCheck(t) },
3498+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
3499+
CheckDestroy: testAccCheckComputeInstanceDestroyProducer(t),
3500+
Steps: []resource.TestStep{
3501+
{
3502+
Config: testAccComputeInstance_keyRevocationActionType(context_1),
3503+
Check: resource.ComposeTestCheckFunc(
3504+
testAccCheckComputeInstanceExists(
3505+
t, "google_compute_instance.foobar", &instance),
3506+
resource.TestCheckResourceAttr("google_compute_instance.foobar", "key_revocation_action_type", "NONE"),
3507+
),
3508+
},
3509+
{
3510+
Config: testAccComputeInstance_keyRevocationActionType(context_2),
3511+
Check: resource.ComposeTestCheckFunc(
3512+
testAccCheckComputeInstanceExists(
3513+
t, "google_compute_instance.foobar", &instance),
3514+
resource.TestCheckResourceAttr("google_compute_instance.foobar", "key_revocation_action_type", "STOP"),
3515+
),
3516+
},
3517+
{
3518+
Config: testAccComputeInstance_keyRevocationActionType(context_3),
3519+
Check: resource.ComposeTestCheckFunc(
3520+
testAccCheckComputeInstanceExists(
3521+
t, "google_compute_instance.foobar", &instance),
3522+
resource.TestCheckResourceAttr("google_compute_instance.foobar", "key_revocation_action_type", "NONE"),
3523+
),
3524+
},
3525+
},
3526+
})
3527+
}
3528+
34793529
{{ if ne $.TargetVersionName `ga` -}}
34803530
const errorDeleteAccessConfigWithSecPolicy = "Cannot delete an access config with a security policy set. Please remove the security policy first"
34813531

@@ -10729,3 +10779,30 @@ resource "google_compute_instance" "foobar" {
1072910779
}
1073010780
`, diskName, instanceName, machineType, zone, bootDiskInterface, allowStoppingForUpdate)
1073110781
}
10782+
10783+
func testAccComputeInstance_keyRevocationActionType(context map[string]interface{}) string {
10784+
return acctest.Nprintf(`
10785+
data "google_compute_image" "my_image" {
10786+
family = "debian-11"
10787+
project = "debian-cloud"
10788+
}
10789+
10790+
resource "google_compute_instance" "foobar" {
10791+
name = "%{instance_name}"
10792+
machine_type = "e2-medium"
10793+
zone = "us-central1-a"
10794+
10795+
boot_disk {
10796+
initialize_params {
10797+
image = data.google_compute_image.my_image.self_link
10798+
}
10799+
}
10800+
10801+
network_interface {
10802+
network = "default"
10803+
}
10804+
10805+
%{key_revocation_action_type}
10806+
}
10807+
`, context)
10808+
}

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

+13
Original file line numberDiff line numberDiff line change
@@ -1054,6 +1054,15 @@ be from 0 to 999,999,999 inclusive.`,
10541054
},
10551055
},
10561056
},
1057+
1058+
"key_revocation_action_type": {
1059+
Type: schema.TypeString,
1060+
Optional: true,
1061+
ForceNew: true,
1062+
ValidateFunc: validation.StringInSlice([]string{"NONE", "STOP"}, false),
1063+
Default: "NONE",
1064+
Description: `Action to be taken when a customer's encryption key is revoked. Supports "STOP" and "NONE", with "NONE" being the default.`,
1065+
},
10571066
},
10581067
UseJSONNumber: true,
10591068
}
@@ -1136,6 +1145,7 @@ func resourceComputeRegionInstanceTemplateCreate(d *schema.ResourceData, meta in
11361145
{{- end }}
11371146
ResourcePolicies: resourcePolicies,
11381147
ReservationAffinity: reservationAffinity,
1148+
KeyRevocationActionType: d.Get("key_revocation_action_type").(string),
11391149
}
11401150

11411151
if _, ok := d.GetOk("effective_labels"); ok {
@@ -1340,6 +1350,9 @@ func resourceComputeRegionInstanceTemplateRead(d *schema.ResourceData, meta inte
13401350
if err = d.Set("instance_description", instanceProperties.Description); err != nil {
13411351
return fmt.Errorf("Error setting instance_description: %s", err)
13421352
}
1353+
if err = d.Set("key_revocation_action_type", instanceTemplate.Properties.KeyRevocationActionType); err != nil {
1354+
return fmt.Errorf("Error setting key_revocation_action_type: %s", err)
1355+
}
13431356
if err = d.Set("project", project); err != nil {
13441357
return fmt.Errorf("Error setting project: %s", err)
13451358
}

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)