Skip to content

Commit

Permalink
compute: Add support for IGM/RIGM list_managed_instances_results fiel…
Browse files Browse the repository at this point in the history
  • Loading branch information
msiedlarek authored and kimihrr committed Dec 6, 2022
1 parent 17d9c6e commit d599bc4
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,14 @@ func resourceComputeInstanceGroupManager() *schema.Resource {
Description: `The target number of running instances for this managed instance group. This value should always be explicitly set unless this resource is attached to an autoscaler, in which case it should never be set. Defaults to 0.`,
},

"list_managed_instances_results": {
Type: schema.TypeString,
Optional: true,
Default: "PAGELESS",
ValidateFunc: validation.StringInSlice([]string{"PAGELESS", "PAGINATED"}, false),
Description: `Pagination behavior of the listManagedInstances API method for this managed instance group. Valid values are: "PAGELESS", "PAGINATED". If PAGELESS (default), Pagination is disabled for the group's listManagedInstances API method. maxResults and pageToken query parameters are ignored and all instances are returned in a single response. If PAGINATED, pagination is enabled, maxResults and pageToken query parameters are respected.`,
},

"auto_healing_policies": {
Type: schema.TypeList,
Optional: true,
Expand Down Expand Up @@ -466,19 +474,20 @@ func resourceComputeInstanceGroupManagerCreate(d *schema.ResourceData, meta inte

// Build the parameter
manager := &compute.InstanceGroupManager{
Name: d.Get("name").(string),
Description: d.Get("description").(string),
BaseInstanceName: d.Get("base_instance_name").(string),
TargetSize: int64(d.Get("target_size").(int)),
NamedPorts: getNamedPortsBeta(d.Get("named_port").(*schema.Set).List()),
TargetPools: convertStringSet(d.Get("target_pools").(*schema.Set)),
AutoHealingPolicies: expandAutoHealingPolicies(d.Get("auto_healing_policies").([]interface{})),
Versions: expandVersions(d.Get("version").([]interface{})),
UpdatePolicy: expandUpdatePolicy(d.Get("update_policy").([]interface{})),
Name: d.Get("name").(string),
Description: d.Get("description").(string),
BaseInstanceName: d.Get("base_instance_name").(string),
TargetSize: int64(d.Get("target_size").(int)),
ListManagedInstancesResults: d.Get("list_managed_instances_results").(string),
NamedPorts: getNamedPortsBeta(d.Get("named_port").(*schema.Set).List()),
TargetPools: convertStringSet(d.Get("target_pools").(*schema.Set)),
AutoHealingPolicies: expandAutoHealingPolicies(d.Get("auto_healing_policies").([]interface{})),
Versions: expandVersions(d.Get("version").([]interface{})),
UpdatePolicy: expandUpdatePolicy(d.Get("update_policy").([]interface{})),
<% unless version == "ga" -%>
AllInstancesConfig: expandAllInstancesConfig(nil, d.Get("all_instances_config").([]interface{})),
AllInstancesConfig: expandAllInstancesConfig(nil, d.Get("all_instances_config").([]interface{})),
<% end -%>
StatefulPolicy: expandStatefulPolicy(d.Get("stateful_disk").(*schema.Set).List()),
StatefulPolicy: expandStatefulPolicy(d.Get("stateful_disk").(*schema.Set).List()),
// Force send TargetSize to allow a value of 0.
ForceSendFields: []string{"TargetSize"},
}
Expand Down Expand Up @@ -657,6 +666,9 @@ func resourceComputeInstanceGroupManagerRead(d *schema.ResourceData, meta interf
if err := d.Set("target_size", manager.TargetSize); err != nil {
return fmt.Errorf("Error setting target_size: %s", err)
}
if err := d.Set("list_managed_instances_results", manager.ListManagedInstancesResults); err != nil {
return fmt.Errorf("Error setting list_managed_instances_results: %s", err)
}
if err = d.Set("target_pools", mapStringArr(manager.TargetPools, ConvertSelfLinkToV1)); err != nil {
return fmt.Errorf("Error setting target_pools in state: %s", err.Error())
}
Expand Down Expand Up @@ -774,6 +786,11 @@ func resourceComputeInstanceGroupManagerUpdate(d *schema.ResourceData, meta inte
change = true
}

if d.HasChange("list_managed_instances_results") {
updatedManager.ListManagedInstancesResults = d.Get("list_managed_instances_results").(string)
change = true
}

if change {
op, err := config.NewComputeClient(userAgent).InstanceGroupManagers.Patch(project, zone, d.Get("name").(string), updatedManager).Do()
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,14 @@ func resourceComputeRegionInstanceGroupManager() *schema.Resource {
Description: `The target number of running instances for this managed instance group. This value should always be explicitly set unless this resource is attached to an autoscaler, in which case it should never be set. Defaults to 0.`,
},

"list_managed_instances_results": {
Type: schema.TypeString,
Optional: true,
Default: "PAGELESS",
ValidateFunc: validation.StringInSlice([]string{"PAGELESS", "PAGINATED"}, false),
Description: `Pagination behavior of the listManagedInstances API method for this managed instance group. Valid values are: "PAGELESS", "PAGINATED". If PAGELESS (default), Pagination is disabled for the group's listManagedInstances API method. maxResults and pageToken query parameters are ignored and all instances are returned in a single response. If PAGINATED, pagination is enabled, maxResults and pageToken query parameters are respected.`,
},

// If true, the resource will report ready only after no instances are being created.
// This will not block future reads if instances are being recreated, and it respects
// the "createNoRetry" parameter that's available for this resource.
Expand Down Expand Up @@ -468,20 +476,21 @@ func resourceComputeRegionInstanceGroupManagerCreate(d *schema.ResourceData, met
}

manager := &compute.InstanceGroupManager{
Name: d.Get("name").(string),
Description: d.Get("description").(string),
BaseInstanceName: d.Get("base_instance_name").(string),
TargetSize: int64(d.Get("target_size").(int)),
NamedPorts: getNamedPortsBeta(d.Get("named_port").(*schema.Set).List()),
TargetPools: convertStringSet(d.Get("target_pools").(*schema.Set)),
AutoHealingPolicies: expandAutoHealingPolicies(d.Get("auto_healing_policies").([]interface{})),
Versions: expandVersions(d.Get("version").([]interface{})),
UpdatePolicy: expandRegionUpdatePolicy(d.Get("update_policy").([]interface{})),
Name: d.Get("name").(string),
Description: d.Get("description").(string),
BaseInstanceName: d.Get("base_instance_name").(string),
TargetSize: int64(d.Get("target_size").(int)),
ListManagedInstancesResults: d.Get("list_managed_instances_results").(string),
NamedPorts: getNamedPortsBeta(d.Get("named_port").(*schema.Set).List()),
TargetPools: convertStringSet(d.Get("target_pools").(*schema.Set)),
AutoHealingPolicies: expandAutoHealingPolicies(d.Get("auto_healing_policies").([]interface{})),
Versions: expandVersions(d.Get("version").([]interface{})),
UpdatePolicy: expandRegionUpdatePolicy(d.Get("update_policy").([]interface{})),
<% unless version == "ga" -%>
AllInstancesConfig: expandAllInstancesConfig(nil, d.Get("all_instances_config").([]interface{})),
AllInstancesConfig: expandAllInstancesConfig(nil, d.Get("all_instances_config").([]interface{})),
<% end -%>
DistributionPolicy: expandDistributionPolicy(d),
StatefulPolicy: expandStatefulPolicy(d.Get("stateful_disk").(*schema.Set).List()),
DistributionPolicy: expandDistributionPolicy(d),
StatefulPolicy: expandStatefulPolicy(d.Get("stateful_disk").(*schema.Set).List()),
// Force send TargetSize to allow size of 0.
ForceSendFields: []string{"TargetSize"},
}
Expand Down Expand Up @@ -632,6 +641,9 @@ func resourceComputeRegionInstanceGroupManagerRead(d *schema.ResourceData, meta
if err := d.Set("target_size", manager.TargetSize); err != nil {
return fmt.Errorf("Error setting target_size: %s", err)
}
if err := d.Set("list_managed_instances_results", manager.ListManagedInstancesResults); err != nil {
return fmt.Errorf("Error setting list_managed_instances_results: %s", err)
}
if err := d.Set("target_pools", mapStringArr(manager.TargetPools, ConvertSelfLinkToV1)); err != nil {
return fmt.Errorf("Error setting target_pools in state: %s", err.Error())
}
Expand Down Expand Up @@ -749,6 +761,11 @@ func resourceComputeRegionInstanceGroupManagerUpdate(d *schema.ResourceData, met
change = true
}

if d.HasChange("list_managed_instances_results") {
updatedManager.ListManagedInstancesResults = d.Get("list_managed_instances_results").(string)
change = true
}

if change {
op, err := config.NewComputeClient(userAgent).RegionInstanceGroupManagers.Patch(project, region, d.Get("name").(string), updatedManager).Do()
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -493,10 +493,11 @@ resource "google_compute_instance_group_manager" "igm-basic" {
instance_template = google_compute_instance_template.igm-basic.self_link
}

target_pools = [google_compute_target_pool.igm-basic.self_link]
base_instance_name = "tf-test-igm-basic"
zone = "us-central1-c"
target_size = 2
target_pools = [google_compute_target_pool.igm-basic.self_link]
base_instance_name = "tf-test-igm-basic"
zone = "us-central1-c"
target_size = 2
list_managed_instances_results = "PAGINATED"
}

resource "google_compute_instance_group_manager" "igm-no-tp" {
Expand Down Expand Up @@ -698,9 +699,10 @@ resource "google_compute_instance_group_manager" "igm-update" {
google_compute_target_pool.igm-update.self_link,
google_compute_target_pool.igm-update2.self_link,
]
base_instance_name = "tf-test-igm-update"
zone = "us-central1-c"
target_size = 3
base_instance_name = "tf-test-igm-update"
zone = "us-central1-c"
target_size = 3
list_managed_instances_results = "PAGINATED"
named_port {
name = "customhttp"
port = 8080
Expand Down Expand Up @@ -795,9 +797,10 @@ resource "google_compute_instance_group_manager" "igm-update" {
instance_template = google_compute_instance_template.igm-update2.self_link
}

base_instance_name = "tf-test-igm-update"
zone = "us-central1-c"
target_size = 3
base_instance_name = "tf-test-igm-update"
zone = "us-central1-c"
target_size = 3
list_managed_instances_results = "PAGINATED"
named_port {
name = "customhttp"
port = 8080
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -463,9 +463,10 @@ resource "google_compute_region_instance_group_manager" "igm-basic" {
instance_template = google_compute_instance_template.igm-basic.self_link
}

target_pools = [google_compute_target_pool.igm-basic.self_link]
base_instance_name = "tf-test-igm-basic"
target_size = 2
target_pools = [google_compute_target_pool.igm-basic.self_link]
base_instance_name = "tf-test-igm-basic"
target_size = 2
list_managed_instances_results = "PAGINATED"
}

resource "google_compute_region_instance_group_manager" "igm-no-tp" {
Expand All @@ -477,9 +478,9 @@ resource "google_compute_region_instance_group_manager" "igm-no-tp" {
instance_template = google_compute_instance_template.igm-basic.self_link
}

base_instance_name = "tf-test-igm-no-tp"
region = "us-central1"
target_size = 2
base_instance_name = "tf-test-igm-no-tp"
region = "us-central1"
target_size = 2
}
`, template, target, igm1, igm2)
}
Expand Down Expand Up @@ -668,9 +669,10 @@ resource "google_compute_region_instance_group_manager" "igm-update" {
google_compute_target_pool.igm-update.self_link,
google_compute_target_pool.igm-update2.self_link,
]
base_instance_name = "tf-test-igm-update"
region = "us-central1"
target_size = 3
base_instance_name = "tf-test-igm-update"
region = "us-central1"
target_size = 3
list_managed_instances_results = "PAGINATED"
named_port {
name = "customhttp"
port = 8080
Expand Down Expand Up @@ -765,9 +767,10 @@ resource "google_compute_region_instance_group_manager" "igm-update" {
name = "primary"
}

base_instance_name = "tf-test-igm-update"
region = "us-central1"
target_size = 3
base_instance_name = "tf-test-igm-update"
region = "us-central1"
target_size = 3
list_managed_instances_results = "PAGINATED"
named_port {
name = "customhttp"
port = 8080
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ resource "google_compute_instance_group_manager" "appserver" {
version {
instance_template = google_compute_instance_template.appserver.id
}
all_instances_config {
metadata = {
metadata_key = "metadata_value"
Expand Down Expand Up @@ -128,6 +128,13 @@ The following arguments are supported:
instance group. This value should always be explicitly set unless this resource is attached to
an autoscaler, in which case it should never be set. Defaults to `0`.

* `list_managed_instances_results` - (Optional) Pagination behavior of the `listManagedInstances` API
method for this managed instance group. Valid values are: `PAGELESS`, `PAGINATED`.
If `PAGELESS` (default), Pagination is disabled for the group's `listManagedInstances` API method.
`maxResults` and `pageToken` query parameters are ignored and all instances are returned in a single
response. If `PAGINATED`, pagination is enabled, `maxResults` and `pageToken` query parameters are
respected.

* `target_pools` - (Optional) The full URL of all target pools to which new
instances in the group are added. Updating the target pools attribute does
not affect existing instances.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ resource "google_compute_region_instance_group_manager" "appserver" {
version {
instance_template = google_compute_instance_template.appserver.id
}
all_instances_config {
metadata = {
metadata_key = "metadata_value"
Expand Down Expand Up @@ -130,6 +130,13 @@ The following arguments are supported:
instance group. This value should always be explicitly set unless this resource is attached to
an autoscaler, in which case it should never be set. Defaults to `0`.

* `list_managed_instances_results` - (Optional) Pagination behavior of the `listManagedInstances` API
method for this managed instance group. Valid values are: `PAGELESS`, `PAGINATED`.
If `PAGELESS` (default), Pagination is disabled for the group's `listManagedInstances` API method.
`maxResults` and `pageToken` query parameters are ignored and all instances are returned in a single
response. If `PAGINATED`, pagination is enabled, `maxResults` and `pageToken` query parameters are
respected.

* `target_pools` - (Optional) The full URL of all target pools to which new
instances in the group are added. Updating the target pools attribute does
not affect existing instances.
Expand Down

0 comments on commit d599bc4

Please sign in to comment.