Skip to content

Commit a90c726

Browse files
modular-magicianslevenick
authored andcommitted
Revert "Placement policy support for Compute Instance (#3217)" (#3250) (#1852)
This reverts commit d7d347f224561e053231452081bbff2ce4c877f2. Signed-off-by: Modular Magician <[email protected]>
1 parent df46440 commit a90c726

8 files changed

+3
-365
lines changed

.changelog/3250.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:none
2+
3+
```

google-beta/resource_compute_instance.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -593,15 +593,6 @@ func resourceComputeInstance() *schema.Resource {
593593
Optional: true,
594594
ForceNew: true,
595595
},
596-
597-
"resource_policies": {
598-
Type: schema.TypeList,
599-
Elem: &schema.Schema{Type: schema.TypeString},
600-
DiffSuppressFunc: compareSelfLinkRelativePaths,
601-
Optional: true,
602-
ForceNew: true,
603-
MaxItems: 1,
604-
},
605596
},
606597
CustomizeDiff: customdiff.All(
607598
customdiff.If(
@@ -729,7 +720,6 @@ func expandComputeInstance(project string, d *schema.ResourceData, config *Confi
729720
ForceSendFields: []string{"CanIpForward", "DeletionProtection"},
730721
ShieldedVmConfig: expandShieldedVmConfigs(d),
731722
DisplayDevice: expandDisplayDevice(d),
732-
ResourcePolicies: convertStringArr(d.Get("resource_policies").([]interface{})),
733723
}, nil
734724
}
735725

@@ -993,9 +983,6 @@ func resourceComputeInstanceRead(d *schema.ResourceData, meta interface{}) error
993983
}
994984
}
995985
}
996-
997-
d.Set("resource_policies", instance.ResourcePolicies)
998-
999986
// Remove nils from map in case there were disks in the config that were not present on read;
1000987
// i.e. a disk was detached out of band
1001988
ads := []map[string]interface{}{}

google-beta/resource_compute_instance_test.go

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1784,24 +1784,6 @@ func TestAccComputeInstance_updateTerminated_desiredStatusRunning_notAllowStoppi
17841784
})
17851785
}
17861786

1787-
func TestAccComputeInstance_resourcePolicyCollocate(t *testing.T) {
1788-
t.Parallel()
1789-
1790-
instanceName := fmt.Sprintf("terraform-test-%s", acctest.RandString(10))
1791-
1792-
resource.Test(t, resource.TestCase{
1793-
PreCheck: func() { testAccPreCheck(t) },
1794-
Providers: testAccProviders,
1795-
CheckDestroy: testAccCheckComputeInstanceDestroy,
1796-
Steps: []resource.TestStep{
1797-
{
1798-
Config: testAccComputeInstance_resourcePolicyCollocate(instanceName),
1799-
},
1800-
computeInstanceImportStep("us-central1-a", instanceName, []string{"allow_stopping_for_update"}),
1801-
},
1802-
})
1803-
}
1804-
18051787
func testAccCheckComputeInstanceUpdateMachineType(n string) resource.TestCheckFunc {
18061788
return func(s *terraform.State) error {
18071789
rs, ok := s.RootModule().Resources[n]
@@ -4536,49 +4518,3 @@ resource "google_compute_instance" "foobar" {
45364518
}
45374519
`, instance)
45384520
}
4539-
4540-
func testAccComputeInstance_resourcePolicyCollocate(instance string) string {
4541-
return fmt.Sprintf(`
4542-
data "google_compute_image" "my_image" {
4543-
family = "debian-9"
4544-
project = "debian-cloud"
4545-
}
4546-
4547-
resource "google_compute_instance" "foobar" {
4548-
name = "%s"
4549-
machine_type = "c2-standard-4"
4550-
zone = "us-central1-f"
4551-
can_ip_forward = false
4552-
tags = ["foo", "bar"]
4553-
4554-
//deletion_protection = false is implicit in this config due to default value
4555-
4556-
boot_disk {
4557-
initialize_params {
4558-
image = data.google_compute_image.my_image.self_link
4559-
}
4560-
}
4561-
4562-
network_interface {
4563-
network = "default"
4564-
}
4565-
4566-
scheduling {
4567-
# Instances with resource policies do not support live migration.
4568-
on_host_maintenance = "TERMINATE"
4569-
}
4570-
4571-
resource_policies = [google_compute_resource_policy.foo.self_link]
4572-
}
4573-
4574-
resource "google_compute_resource_policy" "foo" {
4575-
name = "tf-test-policy-%s"
4576-
region = "us-central1"
4577-
group_placement_policy {
4578-
vm_count = 2
4579-
collocation = "COLLOCATED"
4580-
}
4581-
}
4582-
4583-
`, instance, acctest.RandString(10))
4584-
}

google-beta/resource_compute_resource_policy.go

Lines changed: 0 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -53,41 +53,6 @@ first character must be a lowercase letter, and all following characters
5353
must be a dash, lowercase letter, or digit, except the last character,
5454
which cannot be a dash.`,
5555
},
56-
"group_placement_policy": {
57-
Type: schema.TypeList,
58-
Optional: true,
59-
ForceNew: true,
60-
Description: `Policy for creating snapshots of persistent disks.`,
61-
MaxItems: 1,
62-
Elem: &schema.Resource{
63-
Schema: map[string]*schema.Schema{
64-
"availability_domain_count": {
65-
Type: schema.TypeInt,
66-
Optional: true,
67-
ForceNew: true,
68-
Description: `The number of availability domains instances will be spread across. If two instances are in different
69-
availability domain, they will not be put in the same low latency network`,
70-
AtLeastOneOf: []string{"group_placement_policy.0.vm_count", "group_placement_policy.0.availability_domain_count"},
71-
},
72-
"collocation": {
73-
Type: schema.TypeString,
74-
Optional: true,
75-
ForceNew: true,
76-
ValidateFunc: validation.StringInSlice([]string{"COLLOCATED", ""}, false),
77-
Description: `Collocation specifies whether to place VMs inside the same availability domain on the same low-latency network.
78-
Specify 'COLLOCATED' to enable collocation. Can only be specified with 'vm_count'.`,
79-
},
80-
"vm_count": {
81-
Type: schema.TypeInt,
82-
Optional: true,
83-
ForceNew: true,
84-
Description: `Number of vms in this placement group`,
85-
AtLeastOneOf: []string{"group_placement_policy.0.vm_count", "group_placement_policy.0.availability_domain_count"},
86-
},
87-
},
88-
},
89-
ConflictsWith: []string{"snapshot_schedule_policy"},
90-
},
9156
"region": {
9257
Type: schema.TypeString,
9358
Computed: true,
@@ -260,7 +225,6 @@ Valid options are KEEP_AUTO_SNAPSHOTS and APPLY_RETENTION_POLICY`,
260225
},
261226
},
262227
},
263-
ConflictsWith: []string{"group_placement_policy"},
264228
},
265229
"project": {
266230
Type: schema.TypeString,
@@ -313,12 +277,6 @@ func resourceComputeResourcePolicyCreate(d *schema.ResourceData, meta interface{
313277
} else if v, ok := d.GetOkExists("snapshot_schedule_policy"); !isEmptyValue(reflect.ValueOf(snapshotSchedulePolicyProp)) && (ok || !reflect.DeepEqual(v, snapshotSchedulePolicyProp)) {
314278
obj["snapshotSchedulePolicy"] = snapshotSchedulePolicyProp
315279
}
316-
groupPlacementPolicyProp, err := expandComputeResourcePolicyGroupPlacementPolicy(d.Get("group_placement_policy"), d, config)
317-
if err != nil {
318-
return err
319-
} else if v, ok := d.GetOkExists("group_placement_policy"); !isEmptyValue(reflect.ValueOf(groupPlacementPolicyProp)) && (ok || !reflect.DeepEqual(v, groupPlacementPolicyProp)) {
320-
obj["groupPlacementPolicy"] = groupPlacementPolicyProp
321-
}
322280
regionProp, err := expandComputeResourcePolicyRegion(d.Get("region"), d, config)
323281
if err != nil {
324282
return err
@@ -390,9 +348,6 @@ func resourceComputeResourcePolicyRead(d *schema.ResourceData, meta interface{})
390348
if err := d.Set("snapshot_schedule_policy", flattenComputeResourcePolicySnapshotSchedulePolicy(res["snapshotSchedulePolicy"], d, config)); err != nil {
391349
return fmt.Errorf("Error reading ResourcePolicy: %s", err)
392350
}
393-
if err := d.Set("group_placement_policy", flattenComputeResourcePolicyGroupPlacementPolicy(res["groupPlacementPolicy"], d, config)); err != nil {
394-
return fmt.Errorf("Error reading ResourcePolicy: %s", err)
395-
}
396351
if err := d.Set("region", flattenComputeResourcePolicyRegion(res["region"], d, config)); err != nil {
397352
return fmt.Errorf("Error reading ResourcePolicy: %s", err)
398353
}
@@ -654,47 +609,6 @@ func flattenComputeResourcePolicySnapshotSchedulePolicySnapshotPropertiesGuestFl
654609
return v
655610
}
656611

657-
func flattenComputeResourcePolicyGroupPlacementPolicy(v interface{}, d *schema.ResourceData, config *Config) interface{} {
658-
if v == nil {
659-
return nil
660-
}
661-
original := v.(map[string]interface{})
662-
if len(original) == 0 {
663-
return nil
664-
}
665-
transformed := make(map[string]interface{})
666-
transformed["vm_count"] =
667-
flattenComputeResourcePolicyGroupPlacementPolicyVmCount(original["vmCount"], d, config)
668-
transformed["availability_domain_count"] =
669-
flattenComputeResourcePolicyGroupPlacementPolicyAvailabilityDomainCount(original["availabilityDomainCount"], d, config)
670-
transformed["collocation"] =
671-
flattenComputeResourcePolicyGroupPlacementPolicyCollocation(original["collocation"], d, config)
672-
return []interface{}{transformed}
673-
}
674-
func flattenComputeResourcePolicyGroupPlacementPolicyVmCount(v interface{}, d *schema.ResourceData, config *Config) interface{} {
675-
// Handles the string fixed64 format
676-
if strVal, ok := v.(string); ok {
677-
if intVal, err := strconv.ParseInt(strVal, 10, 64); err == nil {
678-
return intVal
679-
} // let terraform core handle it if we can't convert the string to an int.
680-
}
681-
return v
682-
}
683-
684-
func flattenComputeResourcePolicyGroupPlacementPolicyAvailabilityDomainCount(v interface{}, d *schema.ResourceData, config *Config) interface{} {
685-
// Handles the string fixed64 format
686-
if strVal, ok := v.(string); ok {
687-
if intVal, err := strconv.ParseInt(strVal, 10, 64); err == nil {
688-
return intVal
689-
} // let terraform core handle it if we can't convert the string to an int.
690-
}
691-
return v
692-
}
693-
694-
func flattenComputeResourcePolicyGroupPlacementPolicyCollocation(v interface{}, d *schema.ResourceData, config *Config) interface{} {
695-
return v
696-
}
697-
698612
func flattenComputeResourcePolicyRegion(v interface{}, d *schema.ResourceData, config *Config) interface{} {
699613
if v == nil {
700614
return v
@@ -984,51 +898,6 @@ func expandComputeResourcePolicySnapshotSchedulePolicySnapshotPropertiesGuestFlu
984898
return v, nil
985899
}
986900

987-
func expandComputeResourcePolicyGroupPlacementPolicy(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
988-
l := v.([]interface{})
989-
if len(l) == 0 || l[0] == nil {
990-
return nil, nil
991-
}
992-
raw := l[0]
993-
original := raw.(map[string]interface{})
994-
transformed := make(map[string]interface{})
995-
996-
transformedVmCount, err := expandComputeResourcePolicyGroupPlacementPolicyVmCount(original["vm_count"], d, config)
997-
if err != nil {
998-
return nil, err
999-
} else if val := reflect.ValueOf(transformedVmCount); val.IsValid() && !isEmptyValue(val) {
1000-
transformed["vmCount"] = transformedVmCount
1001-
}
1002-
1003-
transformedAvailabilityDomainCount, err := expandComputeResourcePolicyGroupPlacementPolicyAvailabilityDomainCount(original["availability_domain_count"], d, config)
1004-
if err != nil {
1005-
return nil, err
1006-
} else if val := reflect.ValueOf(transformedAvailabilityDomainCount); val.IsValid() && !isEmptyValue(val) {
1007-
transformed["availabilityDomainCount"] = transformedAvailabilityDomainCount
1008-
}
1009-
1010-
transformedCollocation, err := expandComputeResourcePolicyGroupPlacementPolicyCollocation(original["collocation"], d, config)
1011-
if err != nil {
1012-
return nil, err
1013-
} else if val := reflect.ValueOf(transformedCollocation); val.IsValid() && !isEmptyValue(val) {
1014-
transformed["collocation"] = transformedCollocation
1015-
}
1016-
1017-
return transformed, nil
1018-
}
1019-
1020-
func expandComputeResourcePolicyGroupPlacementPolicyVmCount(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
1021-
return v, nil
1022-
}
1023-
1024-
func expandComputeResourcePolicyGroupPlacementPolicyAvailabilityDomainCount(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
1025-
return v, nil
1026-
}
1027-
1028-
func expandComputeResourcePolicyGroupPlacementPolicyCollocation(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
1029-
return v, nil
1030-
}
1031-
1032901
func expandComputeResourcePolicyRegion(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
1033902
f, err := parseGlobalFieldValue("regions", v.(string), "project", d, config, true)
1034903
if err != nil {

google-beta/resource_compute_resource_policy_generated_test.go

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -117,43 +117,6 @@ resource "google_compute_resource_policy" "bar" {
117117
`, context)
118118
}
119119

120-
func TestAccComputeResourcePolicy_resourcePolicyPlacementPolicyExample(t *testing.T) {
121-
t.Parallel()
122-
123-
context := map[string]interface{}{
124-
"random_suffix": acctest.RandString(10),
125-
}
126-
127-
resource.Test(t, resource.TestCase{
128-
PreCheck: func() { testAccPreCheck(t) },
129-
Providers: testAccProviders,
130-
CheckDestroy: testAccCheckComputeResourcePolicyDestroy,
131-
Steps: []resource.TestStep{
132-
{
133-
Config: testAccComputeResourcePolicy_resourcePolicyPlacementPolicyExample(context),
134-
},
135-
{
136-
ResourceName: "google_compute_resource_policy.baz",
137-
ImportState: true,
138-
ImportStateVerify: true,
139-
},
140-
},
141-
})
142-
}
143-
144-
func testAccComputeResourcePolicy_resourcePolicyPlacementPolicyExample(context map[string]interface{}) string {
145-
return Nprintf(`
146-
resource "google_compute_resource_policy" "baz" {
147-
name = "policy%{random_suffix}"
148-
region = "us-central1"
149-
group_placement_policy {
150-
vm_count = 2
151-
collocation = "COLLOCATED"
152-
}
153-
}
154-
`, context)
155-
}
156-
157120
func testAccCheckComputeResourcePolicyDestroy(s *terraform.State) error {
158121
for name, rs := range s.RootModule().Resources {
159122
if rs.Type != "google_compute_resource_policy" {

0 commit comments

Comments
 (0)