Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New resource: aws_autoscalingplans_scaling_plan #8965

Merged
merged 20 commits into from
Oct 21, 2020
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
d3eb4da
Add 'aws_autoscalingplans_scaling_plan' resource.
Jun 12, 2019
ce4c98e
Terraform Plugin SDK migration.
ewbankkit Oct 5, 2019
df98e92
Add 'subcategory'.
ewbankkit Nov 22, 2019
b254cec
Replace 'validateStringDoesNotContainAny' with 'validation.StringDoes…
Nov 27, 2019
e88b0dc
Remove 'sidebar_current'.
ewbankkit Mar 17, 2020
6fa9aa6
Use 'go-multierror' in test sweeper.
ewbankkit May 11, 2020
1c979ff
Add 'internal/service/autoscalingplans/waiter' package.
ewbankkit May 11, 2020
2bddadc
Simplify acceptance tests a bit.
ewbankkit May 12, 2020
dadedfe
r/aws_autoscalingplans_scaling_plan: Remove custom set hash functions.
ewbankkit May 21, 2020
22726cf
Use 'testAccAvailableEc2InstanceTypeForRegion', not 'testAccAvailable…
ewbankkit Jul 6, 2020
c21359e
Use 'tfawsresource' acceptance test checkers.
ewbankkit Jul 6, 2020
8304317
Upgrade to Plugin SDK v2 and use Terraform 0.12 syntax in documentation.
ewbankkit Aug 16, 2020
0662a1b
r/aws_autoscalingplans_scaling_plan: Use '_Values()' (#14601).
ewbankkit Oct 16, 2020
3883d3d
r/aws_autoscalingplans_scaling_plan: Better handling of eventual cons…
ewbankkit Oct 16, 2020
bb43021
Add documentation note about service-linked role.
ewbankkit Oct 19, 2020
a2ab9dc
Update website/docs/r/autoscalingplans_scaling_plan.html.markdown
ewbankkit Oct 19, 2020
1b8260e
Add 'testAccPreCheckIamServiceLinkedRole' and use for scaling plans w…
ewbankkit Oct 19, 2020
a9751f7
Merge branch 'issue-6562' of https://github.com/ewbankkit/terraform-p…
ewbankkit Oct 19, 2020
4e83eb6
Use 'StateChangeConf.Delay' to better handle API eventual consistency…
ewbankkit Oct 20, 2020
543e5d3
Update aws/internal/service/autoscalingplans/finder/finder.go
ewbankkit Oct 21, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions aws/internal/service/autoscalingplans/waiter/status.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package waiter

import (
"log"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/autoscalingplans"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

const (
// ScalingPlan NotFound
ScalingPlanStatusNotFound = "NotFound"

// ScalingPlan Unknown
ScalingPlanStatusUnknown = "Unknown"
)

// ScalingPlanStatus fetches the ScalingPlan and its Status
func ScalingPlanStatus(conn *autoscalingplans.AutoScalingPlans, scalingPlanName string, scalingPlanVersion int) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
input := &autoscalingplans.DescribeScalingPlansInput{
ScalingPlanNames: aws.StringSlice([]string{scalingPlanName}),
ScalingPlanVersion: aws.Int64(int64(scalingPlanVersion)),
}

output, err := conn.DescribeScalingPlans(input)

if err != nil {
return nil, ScalingPlanStatusUnknown, err
}

if len(output.ScalingPlans) == 0 {
return "", ScalingPlanStatusNotFound, nil
}

scalingPlan := output.ScalingPlans[0]
if statusMessage := aws.StringValue(scalingPlan.StatusMessage); statusMessage != "" {
log.Printf("[INFO] Auto Scaling Scaling Plan (%s/%d) status message: %s", scalingPlanName, scalingPlanVersion, statusMessage)
}

return scalingPlan, aws.StringValue(scalingPlan.StatusCode), nil
}
}
73 changes: 73 additions & 0 deletions aws/internal/service/autoscalingplans/waiter/waiter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package waiter

import (
"time"

"github.com/aws/aws-sdk-go/service/autoscalingplans"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

const (
// Maximum amount of time to wait for a ScalingPlan to return Created
ScalingPlanCreatedTimeout = 5 * time.Minute

// Maximum amount of time to wait for a ScalingPlan to return Deleted
ScalingPlanDeletedTimeout = 5 * time.Minute

// Maximum amount of time to wait for a ScalingPlan to return Updated
ScalingPlanUpdatedTimeout = 5 * time.Minute
)

// ScalingPlanCreated waits for a ScalingPlan to return Created
func ScalingPlanCreated(conn *autoscalingplans.AutoScalingPlans, scalingPlanName string, scalingPlanVersion int) (*autoscalingplans.ScalingPlan, error) {
stateConf := &resource.StateChangeConf{
Pending: []string{autoscalingplans.ScalingPlanStatusCodeCreationInProgress},
Target: []string{autoscalingplans.ScalingPlanStatusCodeActive, autoscalingplans.ScalingPlanStatusCodeActiveWithProblems},
Refresh: ScalingPlanStatus(conn, scalingPlanName, scalingPlanVersion),
Timeout: ScalingPlanCreatedTimeout,
}

outputRaw, err := stateConf.WaitForState()

if v, ok := outputRaw.(*autoscalingplans.ScalingPlan); ok {
return v, err
}

return nil, err
}

// ScalingPlanDeleted waits for a ScalingPlan to return Deleted
func ScalingPlanDeleted(conn *autoscalingplans.AutoScalingPlans, scalingPlanName string, scalingPlanVersion int) (*autoscalingplans.ScalingPlan, error) {
stateConf := &resource.StateChangeConf{
Pending: []string{autoscalingplans.ScalingPlanStatusCodeDeletionInProgress},
Target: []string{ScalingPlanStatusNotFound},
Refresh: ScalingPlanStatus(conn, scalingPlanName, scalingPlanVersion),
Timeout: ScalingPlanDeletedTimeout,
}

outputRaw, err := stateConf.WaitForState()

if v, ok := outputRaw.(*autoscalingplans.ScalingPlan); ok {
return v, err
}

return nil, err
}

// ScalingPlanUpdated waits for a ScalingPlan to return Updated
func ScalingPlanUpdated(conn *autoscalingplans.AutoScalingPlans, scalingPlanName string, scalingPlanVersion int) (*autoscalingplans.ScalingPlan, error) {
stateConf := &resource.StateChangeConf{
Pending: []string{autoscalingplans.ScalingPlanStatusCodeUpdateInProgress},
Target: []string{autoscalingplans.ScalingPlanStatusCodeActive, autoscalingplans.ScalingPlanStatusCodeActiveWithProblems},
Refresh: ScalingPlanStatus(conn, scalingPlanName, scalingPlanVersion),
Timeout: ScalingPlanUpdatedTimeout,
}

outputRaw, err := stateConf.WaitForState()

if v, ok := outputRaw.(*autoscalingplans.ScalingPlan); ok {
return v, err
}

return nil, err
}
1 change: 1 addition & 0 deletions aws/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ func Provider() *schema.Provider {
"aws_autoscaling_notification": resourceAwsAutoscalingNotification(),
"aws_autoscaling_policy": resourceAwsAutoscalingPolicy(),
"aws_autoscaling_schedule": resourceAwsAutoscalingSchedule(),
"aws_autoscalingplans_scaling_plan": resourceAwsAutoScalingPlansScalingPlan(),
"aws_backup_plan": resourceAwsBackupPlan(),
"aws_backup_selection": resourceAwsBackupSelection(),
"aws_backup_vault": resourceAwsBackupVault(),
Expand Down
Loading