Skip to content

Commit

Permalink
wait for instance status only after create/update (#5057) (#9832)
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician authored Aug 17, 2021
1 parent 737df0f commit 4725a55
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 35 deletions.
3 changes: 3 additions & 0 deletions .changelog/5057.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
compute: changed `wait_for_instances` in `google_compute_instance_group_manager` and `google_compute_region_instance_group_manager` to no longer block plan / refresh, waiting on managed instance statuses during apply instead
```
63 changes: 47 additions & 16 deletions google/resource_compute_instance_group_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ func resourceComputeInstanceGroupManager() *schema.Resource {
State: resourceInstanceGroupManagerStateImporter,
},
Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(5 * time.Minute),
Update: schema.DefaultTimeout(5 * time.Minute),
Create: schema.DefaultTimeout(15 * time.Minute),
Update: schema.DefaultTimeout(15 * time.Minute),
Delete: schema.DefaultTimeout(15 * time.Minute),
},

Expand Down Expand Up @@ -459,6 +459,13 @@ func resourceComputeInstanceGroupManagerCreate(d *schema.ResourceData, meta inte
return err
}

if d.Get("wait_for_instances").(bool) {
err := computeIGMWaitForInstanceStatus(d, meta)
if err != nil {
return err
}
}

return resourceComputeInstanceGroupManagerRead(d, meta)
}

Expand Down Expand Up @@ -625,30 +632,24 @@ func resourceComputeInstanceGroupManagerRead(d *schema.ResourceData, meta interf

// If unset in state set to default value
if d.Get("wait_for_instances_status").(string) == "" {
if err = d.Set("wait_for_instances_status", "STABLE"); err != nil {
if err := d.Set("wait_for_instances_status", "STABLE"); err != nil {
return fmt.Errorf("Error setting wait_for_instances_status in state: %s", err.Error())
}
}

return nil
}

func resourceComputeInstanceGroupManagerUpdate(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)

if d.Get("wait_for_instances").(bool) {
waitForUpdates := d.Get("wait_for_instances_status").(string) == "UPDATED"
conf := resource.StateChangeConf{
Pending: []string{"creating", "error", "updating per instance configs", "reaching version target"},
Target: []string{"created"},
Refresh: waitForInstancesRefreshFunc(getManager, waitForUpdates, d, meta),
Timeout: d.Timeout(schema.TimeoutCreate),
}
_, err := conf.WaitForState()
err := computeIGMWaitForInstanceStatus(d, meta)
if err != nil {
return err
}
}

return nil
}

func resourceComputeInstanceGroupManagerUpdate(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
userAgent, err := generateUserAgentString(d, config.userAgent)
if err != nil {
return err
Expand Down Expand Up @@ -755,11 +756,26 @@ func resourceComputeInstanceGroupManagerUpdate(d *schema.ResourceData, meta inte

d.Partial(false)

if d.Get("wait_for_instances").(bool) {
err := computeIGMWaitForInstanceStatus(d, meta)
if err != nil {
return err
}
}

return resourceComputeInstanceGroupManagerRead(d, meta)
}

func resourceComputeInstanceGroupManagerDelete(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)

if d.Get("wait_for_instances").(bool) {
err := computeIGMWaitForInstanceStatus(d, meta)
if err != nil {
return err
}
}

userAgent, err := generateUserAgentString(d, config.userAgent)
if err != nil {
return err
Expand Down Expand Up @@ -816,6 +832,21 @@ func resourceComputeInstanceGroupManagerDelete(d *schema.ResourceData, meta inte
return nil
}

func computeIGMWaitForInstanceStatus(d *schema.ResourceData, meta interface{}) error {
waitForUpdates := d.Get("wait_for_instances_status").(string) == "UPDATED"
conf := resource.StateChangeConf{
Pending: []string{"creating", "error", "updating per instance configs", "reaching version target"},
Target: []string{"created"},
Refresh: waitForInstancesRefreshFunc(getManager, waitForUpdates, d, meta),
Timeout: d.Timeout(schema.TimeoutCreate),
}
_, err := conf.WaitForState()
if err != nil {
return err
}
return nil
}

func expandAutoHealingPolicies(configured []interface{}) []*computeBeta.InstanceGroupManagerAutoHealingPolicy {
autoHealingPolicies := make([]*computeBeta.InstanceGroupManagerAutoHealingPolicy, 0, len(configured))
for _, raw := range configured {
Expand Down
62 changes: 47 additions & 15 deletions google/resource_compute_region_instance_group_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ func resourceComputeRegionInstanceGroupManager() *schema.Resource {
State: resourceRegionInstanceGroupManagerStateImporter,
},
Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(5 * time.Minute),
Update: schema.DefaultTimeout(5 * time.Minute),
Create: schema.DefaultTimeout(15 * time.Minute),
Update: schema.DefaultTimeout(15 * time.Minute),
Delete: schema.DefaultTimeout(15 * time.Minute),
},

Expand Down Expand Up @@ -441,9 +441,32 @@ func resourceComputeRegionInstanceGroupManagerCreate(d *schema.ResourceData, met
if err != nil {
return err
}

if d.Get("wait_for_instances").(bool) {
err := computeRIGMWaitForInstanceStatus(d, meta)
if err != nil {
return err
}
}

return resourceComputeRegionInstanceGroupManagerRead(d, config)
}

func computeRIGMWaitForInstanceStatus(d *schema.ResourceData, meta interface{}) error {
waitForUpdates := d.Get("wait_for_instances_status").(string) == "UPDATED"
conf := resource.StateChangeConf{
Pending: []string{"creating", "error", "updating per instance configs", "reaching version target"},
Target: []string{"created"},
Refresh: waitForInstancesRefreshFunc(getRegionalManager, waitForUpdates, d, meta),
Timeout: d.Timeout(schema.TimeoutCreate),
}
_, err := conf.WaitForState()
if err != nil {
return err
}
return nil
}

type getInstanceManagerFunc func(*schema.ResourceData, interface{}) (*computeBeta.InstanceGroupManager, error)

func getRegionalManager(d *schema.ResourceData, meta interface{}) (*computeBeta.InstanceGroupManager, error) {
Expand Down Expand Up @@ -580,25 +603,19 @@ func resourceComputeRegionInstanceGroupManagerRead(d *schema.ResourceData, meta
}
}

return nil
}

func resourceComputeRegionInstanceGroupManagerUpdate(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)

if d.Get("wait_for_instances").(bool) {
waitForUpdates := d.Get("wait_for_instances_status").(string) == "UPDATED"
conf := resource.StateChangeConf{
Pending: []string{"creating", "error", "updating per instance configs", "reaching version target"},
Target: []string{"created"},
Refresh: waitForInstancesRefreshFunc(getRegionalManager, waitForUpdates, d, meta),
Timeout: d.Timeout(schema.TimeoutCreate),
}
_, err := conf.WaitForState()
err := computeRIGMWaitForInstanceStatus(d, meta)
if err != nil {
return err
}
}

return nil
}

func resourceComputeRegionInstanceGroupManagerUpdate(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
userAgent, err := generateUserAgentString(d, config.userAgent)
if err != nil {
return err
Expand Down Expand Up @@ -699,11 +716,26 @@ func resourceComputeRegionInstanceGroupManagerUpdate(d *schema.ResourceData, met

d.Partial(false)

if d.Get("wait_for_instances").(bool) {
err := computeRIGMWaitForInstanceStatus(d, meta)
if err != nil {
return err
}
}

return resourceComputeRegionInstanceGroupManagerRead(d, meta)
}

func resourceComputeRegionInstanceGroupManagerDelete(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)

if d.Get("wait_for_instances").(bool) {
err := computeRIGMWaitForInstanceStatus(d, meta)
if err != nil {
return err
}
}

userAgent, err := generateUserAgentString(d, config.userAgent)
if err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions website/docs/r/compute_instance_group_manager.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,8 @@ The `per_instance_configs` block holds:
This resource provides the following
[Timeouts](/docs/configuration/resources.html#timeouts) configuration options:

- `create` - Default is 5 minutes.
- `update` - Default is 5 minutes.
- `create` - Default is 15 minutes.
- `update` - Default is 15 minutes.
- `delete` - Default is 15 minutes.


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,8 @@ The `per_instance_configs` block holds:
This resource provides the following
[Timeouts](/docs/configuration/resources.html#timeouts) configuration options:

- `create` - Default is 5 minutes.
- `update` - Default is 5 minutes.
- `create` - Default is 15 minutes.
- `update` - Default is 15 minutes.
- `delete` - Default is 15 minutes.


Expand Down

0 comments on commit 4725a55

Please sign in to comment.