added applicationautoscaling from aws-sdk-go
using: `govendor add github.com/aws/aws-sdk-go/service/applicationautoscaling@v1.2.5` introduce a retry for scalable target creation Due to possible inconsistencies in IAM, let's retry creation of the scalable target before we fail. Added IAM role as part of acceptance test
This commit is contained in:
parent
cc912c39e5
commit
1f400671c8
|
@ -2,7 +2,6 @@ package aws
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
|
@ -14,9 +13,8 @@ import (
|
|||
|
||||
func TestAccAWSAppautoscalingPolicy_basic(t *testing.T) {
|
||||
var policy applicationautoscaling.ScalingPolicy
|
||||
var awsAccountId = os.Getenv("AWS_ACCOUNT_ID")
|
||||
|
||||
randClusterName := fmt.Sprintf("cluster-%s", acctest.RandString(10))
|
||||
randClusterName := fmt.Sprintf("cluster%s", acctest.RandString(10))
|
||||
// randResourceId := fmt.Sprintf("service/%s/%s", randClusterName, acctest.RandString(10))
|
||||
randPolicyName := fmt.Sprintf("terraform-test-foobar-%s", acctest.RandString(5))
|
||||
|
||||
|
@ -26,7 +24,7 @@ func TestAccAWSAppautoscalingPolicy_basic(t *testing.T) {
|
|||
CheckDestroy: testAccCheckAWSAppautoscalingPolicyDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testAccAWSAppautoscalingPolicyConfig(randClusterName, randPolicyName, awsAccountId),
|
||||
Config: testAccAWSAppautoscalingPolicyConfig(randClusterName, randPolicyName),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckAWSAppautoscalingPolicyExists("aws_appautoscaling_policy.foobar_simple", &policy),
|
||||
resource.TestCheckResourceAttr("aws_appautoscaling_policy.foobar_simple", "adjustment_type", "ChangeInCapacity"),
|
||||
|
@ -90,9 +88,37 @@ func testAccCheckAWSAppautoscalingPolicyDestroy(s *terraform.State) error {
|
|||
|
||||
func testAccAWSAppautoscalingPolicyConfig(
|
||||
randClusterName string,
|
||||
randPolicyName string,
|
||||
awsAccountId string) string {
|
||||
randPolicyName string) string {
|
||||
return fmt.Sprintf(`
|
||||
resource "aws_iam_role" "autoscale_role" {
|
||||
name = "%s"
|
||||
path = "/"
|
||||
|
||||
assume_role_policy = "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":{\"AWS\":\"*\"},\"Action\":[\"sts:AssumeRole\"]}]}"
|
||||
}
|
||||
|
||||
resource "aws_iam_role_policy" "autoscale_role_policy" {
|
||||
name = "%s"
|
||||
role = "${aws_iam_role.autoscale_role.id}"
|
||||
|
||||
policy = <<EOF
|
||||
{
|
||||
"Version": "2012-10-17",
|
||||
"Statement": [
|
||||
{
|
||||
"Effect": "Allow",
|
||||
"Action": [
|
||||
"ecs:DescribeServices",
|
||||
"ecs:UpdateService",
|
||||
"cloudwatch:DescribeAlarms"
|
||||
],
|
||||
"Resource": ["*"]
|
||||
}
|
||||
]
|
||||
}
|
||||
EOF
|
||||
}
|
||||
|
||||
resource "aws_ecs_cluster" "foo" {
|
||||
name = "%s"
|
||||
}
|
||||
|
@ -125,7 +151,7 @@ resource "aws_appautoscaling_target" "tgt" {
|
|||
service_namespace = "ecs"
|
||||
resource_id = "service/${aws_ecs_cluster.foo.name}/${aws_ecs_service.service.name}"
|
||||
scalable_dimension = "ecs:service:DesiredCount"
|
||||
role_arn = "arn:aws:iam::%s:role/ecsAutoscaleRole"
|
||||
role_arn = "${aws_iam_role.autoscale_role.arn}"
|
||||
min_capacity = 1
|
||||
max_capacity = 4
|
||||
}
|
||||
|
@ -144,5 +170,5 @@ resource "aws_appautoscaling_policy" "foobar_simple" {
|
|||
}
|
||||
depends_on = ["aws_appautoscaling_target.tgt"]
|
||||
}
|
||||
`, randClusterName, awsAccountId, randPolicyName)
|
||||
`, randClusterName, randClusterName, randClusterName, randPolicyName)
|
||||
}
|
||||
|
|
|
@ -88,7 +88,21 @@ func resourceAwsAppautoscalingTargetCreate(d *schema.ResourceData, meta interfac
|
|||
targetOpts.ServiceNamespace = aws.String(d.Get("service_namespace").(string))
|
||||
|
||||
log.Printf("[DEBUG] Application autoscaling target create configuration %#v", targetOpts)
|
||||
_, err := conn.RegisterScalableTarget(&targetOpts)
|
||||
var out *applicationautoscaling.RegisterScalableTargetOutput
|
||||
var err error
|
||||
err = resource.Retry(1*time.Minute, func() *resource.RetryError {
|
||||
out, err = conn.RegisterScalableTarget(&targetOpts)
|
||||
|
||||
if err != nil {
|
||||
if awsErr, ok := err.(awserr.Error); ok && awsErr.Code() == "ValidationException" {
|
||||
log.Printf("[DEBUG] Retrying creation of Application Autoscaling Scalable Target due to possible issues with IAM: %s", awsErr)
|
||||
return resource.RetryableError(err)
|
||||
}
|
||||
return resource.NonRetryableError(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error creating application autoscaling target: %s", err)
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ package aws
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
|
@ -15,7 +14,6 @@ import (
|
|||
|
||||
func TestAccAWSAppautoScalingTarget_basic(t *testing.T) {
|
||||
var target applicationautoscaling.ScalableTarget
|
||||
var awsAccountId = os.Getenv("AWS_ACCOUNT_ID")
|
||||
|
||||
randClusterName := fmt.Sprintf("cluster-%s", acctest.RandString(10))
|
||||
randResourceId := fmt.Sprintf("service/%s/%s", randClusterName, acctest.RandString(10))
|
||||
|
@ -27,7 +25,7 @@ func TestAccAWSAppautoScalingTarget_basic(t *testing.T) {
|
|||
CheckDestroy: testAccCheckAWSAppautoscalingTargetDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testAccAWSAppautoscalingTargetConfig(randClusterName, randResourceId, awsAccountId),
|
||||
Config: testAccAWSAppautoscalingTargetConfig(randClusterName, randResourceId),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckAWSAppautoscalingTargetExists("aws_appautoscaling_target.bar", &target),
|
||||
testAccCheckAWSAppautoscalingTargetAttributes(&target, randResourceId),
|
||||
|
@ -40,7 +38,7 @@ func TestAccAWSAppautoScalingTarget_basic(t *testing.T) {
|
|||
},
|
||||
|
||||
resource.TestStep{
|
||||
Config: testAccAWSAppautoscalingTargetConfigUpdate(randClusterName, randResourceId, awsAccountId),
|
||||
Config: testAccAWSAppautoscalingTargetConfigUpdate(randClusterName, randResourceId),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckAWSAppautoscalingTargetExists("aws_appautoscaling_target.bar", &target),
|
||||
resource.TestCheckResourceAttr("aws_appautoscaling_target.bar", "min_capacity", "3"),
|
||||
|
@ -126,9 +124,60 @@ func testAccCheckAWSAppautoscalingTargetAttributes(target *applicationautoscalin
|
|||
|
||||
func testAccAWSAppautoscalingTargetConfig(
|
||||
randClusterName string,
|
||||
randResourceId string,
|
||||
awsAccountId string) string {
|
||||
randResourceId string) string {
|
||||
return fmt.Sprintf(`
|
||||
resource "aws_iam_role" "autoscale_role" {
|
||||
name = "autoscalerole%s"
|
||||
path = "/"
|
||||
|
||||
assume_role_policy = <<EOF
|
||||
{
|
||||
"Version": "2012-10-17",
|
||||
"Statement": [
|
||||
{
|
||||
"Effect": "Allow",
|
||||
"Principal": {
|
||||
"Service": "application-autoscaling.amazonaws.com"
|
||||
},
|
||||
"Action": "sts:AssumeRole"
|
||||
}
|
||||
]
|
||||
}
|
||||
EOF
|
||||
}
|
||||
|
||||
resource "aws_iam_role_policy" "autoscale_role_policy" {
|
||||
name = "autoscalepolicy%s"
|
||||
role = "${aws_iam_role.autoscale_role.id}"
|
||||
|
||||
policy = <<EOF
|
||||
{
|
||||
"Version": "2012-10-17",
|
||||
"Statement": [
|
||||
{
|
||||
"Effect": "Allow",
|
||||
"Action": [
|
||||
"ecs:DescribeServices",
|
||||
"ecs:UpdateService"
|
||||
],
|
||||
"Resource": [
|
||||
"*"
|
||||
]
|
||||
},
|
||||
{
|
||||
"Effect": "Allow",
|
||||
"Action": [
|
||||
"cloudwatch:DescribeAlarms"
|
||||
],
|
||||
"Resource": [
|
||||
"*"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
EOF
|
||||
}
|
||||
|
||||
resource "aws_ecs_cluster" "foo" {
|
||||
name = "%s"
|
||||
}
|
||||
|
@ -159,18 +208,69 @@ resource "aws_appautoscaling_target" "bar" {
|
|||
service_namespace = "ecs"
|
||||
resource_id = "service/${aws_ecs_cluster.foo.name}/${aws_ecs_service.service.name}"
|
||||
scalable_dimension = "ecs:service:DesiredCount"
|
||||
role_arn = "arn:aws:iam::%s:role/ecsAutoscaleRole"
|
||||
role_arn = "${aws_iam_role.autoscale_role.arn}"
|
||||
min_capacity = 1
|
||||
max_capacity = 4
|
||||
}
|
||||
`, randClusterName, awsAccountId)
|
||||
`, randClusterName, randClusterName, randClusterName)
|
||||
}
|
||||
|
||||
func testAccAWSAppautoscalingTargetConfigUpdate(
|
||||
randClusterName,
|
||||
randResourceId string,
|
||||
awsAccountId string) string {
|
||||
randResourceId string) string {
|
||||
return fmt.Sprintf(`
|
||||
resource "aws_iam_role" "autoscale_role" {
|
||||
name = "autoscalerole%s"
|
||||
path = "/"
|
||||
|
||||
assume_role_policy = <<EOF
|
||||
{
|
||||
"Version": "2012-10-17",
|
||||
"Statement": [
|
||||
{
|
||||
"Effect": "Allow",
|
||||
"Principal": {
|
||||
"Service": "application-autoscaling.amazonaws.com"
|
||||
},
|
||||
"Action": "sts:AssumeRole"
|
||||
}
|
||||
]
|
||||
}
|
||||
EOF
|
||||
}
|
||||
|
||||
resource "aws_iam_role_policy" "autoscale_role_policy" {
|
||||
name = "autoscalepolicy%s"
|
||||
role = "${aws_iam_role.autoscale_role.id}"
|
||||
|
||||
policy = <<EOF
|
||||
{
|
||||
"Version": "2012-10-17",
|
||||
"Statement": [
|
||||
{
|
||||
"Effect": "Allow",
|
||||
"Action": [
|
||||
"ecs:DescribeServices",
|
||||
"ecs:UpdateService"
|
||||
],
|
||||
"Resource": [
|
||||
"*"
|
||||
]
|
||||
},
|
||||
{
|
||||
"Effect": "Allow",
|
||||
"Action": [
|
||||
"cloudwatch:DescribeAlarms"
|
||||
],
|
||||
"Resource": [
|
||||
"*"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
EOF
|
||||
}
|
||||
|
||||
resource "aws_ecs_cluster" "foo" {
|
||||
name = "%s"
|
||||
}
|
||||
|
@ -201,9 +301,9 @@ resource "aws_appautoscaling_target" "bar" {
|
|||
service_namespace = "ecs"
|
||||
resource_id = "service/${aws_ecs_cluster.foo.name}/${aws_ecs_service.service.name}"
|
||||
scalable_dimension = "ecs:service:DesiredCount"
|
||||
role_arn = "arn:aws:iam::%s:role/ecsAutoscaleRole"
|
||||
role_arn = "${aws_iam_role.autoscale_role.arn}"
|
||||
min_capacity = 2
|
||||
max_capacity = 8
|
||||
}
|
||||
`, randClusterName, awsAccountId)
|
||||
`, randClusterName, randClusterName, randClusterName)
|
||||
}
|
||||
|
|
1450
vendor/github.com/aws/aws-sdk-go/service/applicationautoscaling/api.go
generated
vendored
Normal file
1450
vendor/github.com/aws/aws-sdk-go/service/applicationautoscaling/api.go
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
112
vendor/github.com/aws/aws-sdk-go/service/applicationautoscaling/service.go
generated
vendored
Normal file
112
vendor/github.com/aws/aws-sdk-go/service/applicationautoscaling/service.go
generated
vendored
Normal file
|
@ -0,0 +1,112 @@
|
|||
// THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT.
|
||||
|
||||
package applicationautoscaling
|
||||
|
||||
import (
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/aws/client"
|
||||
"github.com/aws/aws-sdk-go/aws/client/metadata"
|
||||
"github.com/aws/aws-sdk-go/aws/request"
|
||||
"github.com/aws/aws-sdk-go/aws/signer/v4"
|
||||
"github.com/aws/aws-sdk-go/private/protocol/jsonrpc"
|
||||
)
|
||||
|
||||
// Application Auto Scaling is a general purpose Auto Scaling service for supported
|
||||
// elastic AWS resources. With Application Auto Scaling, you can automatically
|
||||
// scale your AWS resources, with an experience similar to that of Auto Scaling.
|
||||
//
|
||||
// At this time, Application Auto Scaling only supports scaling Amazon ECS
|
||||
// services.
|
||||
//
|
||||
// For example, you can use Application Auto Scaling to accomplish the following
|
||||
// tasks:
|
||||
//
|
||||
// Define scaling policies for automatically adjusting your application’s
|
||||
// resources
|
||||
//
|
||||
// Scale your resources in response to CloudWatch alarms
|
||||
//
|
||||
// View history of your scaling events
|
||||
//
|
||||
// Application Auto Scaling is available in the following regions:
|
||||
//
|
||||
// us-east-1
|
||||
//
|
||||
// us-west-2
|
||||
//
|
||||
// eu-west-1
|
||||
//The service client's operations are safe to be used concurrently.
|
||||
// It is not safe to mutate any of the client's properties though.
|
||||
type ApplicationAutoScaling struct {
|
||||
*client.Client
|
||||
}
|
||||
|
||||
// Used for custom client initialization logic
|
||||
var initClient func(*client.Client)
|
||||
|
||||
// Used for custom request initialization logic
|
||||
var initRequest func(*request.Request)
|
||||
|
||||
// A ServiceName is the name of the service the client will make API calls to.
|
||||
const ServiceName = "autoscaling"
|
||||
|
||||
// New creates a new instance of the ApplicationAutoScaling client with a session.
|
||||
// If additional configuration is needed for the client instance use the optional
|
||||
// aws.Config parameter to add your extra config.
|
||||
//
|
||||
// Example:
|
||||
// // Create a ApplicationAutoScaling client from just a session.
|
||||
// svc := applicationautoscaling.New(mySession)
|
||||
//
|
||||
// // Create a ApplicationAutoScaling client with additional configuration
|
||||
// svc := applicationautoscaling.New(mySession, aws.NewConfig().WithRegion("us-west-2"))
|
||||
func New(p client.ConfigProvider, cfgs ...*aws.Config) *ApplicationAutoScaling {
|
||||
c := p.ClientConfig(ServiceName, cfgs...)
|
||||
return newClient(*c.Config, c.Handlers, c.Endpoint, c.SigningRegion)
|
||||
}
|
||||
|
||||
// newClient creates, initializes and returns a new service client instance.
|
||||
func newClient(cfg aws.Config, handlers request.Handlers, endpoint, signingRegion string) *ApplicationAutoScaling {
|
||||
svc := &ApplicationAutoScaling{
|
||||
Client: client.New(
|
||||
cfg,
|
||||
metadata.ClientInfo{
|
||||
ServiceName: ServiceName,
|
||||
SigningName: "application-autoscaling",
|
||||
SigningRegion: signingRegion,
|
||||
Endpoint: endpoint,
|
||||
APIVersion: "2016-02-06",
|
||||
JSONVersion: "1.1",
|
||||
TargetPrefix: "AnyScaleFrontendService",
|
||||
},
|
||||
handlers,
|
||||
),
|
||||
}
|
||||
|
||||
// Handlers
|
||||
svc.Handlers.Sign.PushBackNamed(v4.SignRequestHandler)
|
||||
svc.Handlers.Build.PushBackNamed(jsonrpc.BuildHandler)
|
||||
svc.Handlers.Unmarshal.PushBackNamed(jsonrpc.UnmarshalHandler)
|
||||
svc.Handlers.UnmarshalMeta.PushBackNamed(jsonrpc.UnmarshalMetaHandler)
|
||||
svc.Handlers.UnmarshalError.PushBackNamed(jsonrpc.UnmarshalErrorHandler)
|
||||
|
||||
// Run custom client initialization if present
|
||||
if initClient != nil {
|
||||
initClient(svc.Client)
|
||||
}
|
||||
|
||||
return svc
|
||||
}
|
||||
|
||||
// newRequest creates a new request for a ApplicationAutoScaling operation and runs any
|
||||
// custom request initialization.
|
||||
func (c *ApplicationAutoScaling) newRequest(op *request.Operation, params, data interface{}) *request.Request {
|
||||
req := c.NewRequest(op, params, data)
|
||||
|
||||
// Run custom request initialization if present
|
||||
if initRequest != nil {
|
||||
initRequest(req)
|
||||
}
|
||||
|
||||
return req
|
||||
}
|
|
@ -532,6 +532,12 @@
|
|||
"version": "v1.2.7",
|
||||
"versionExact": "v1.2.7"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "Td30Frd+lrCLlkMAirUTbjBXq5Q=",
|
||||
"path": "github.com/aws/aws-sdk-go/service/applicationautoscaling",
|
||||
"revision": "90dec2183a5f5458ee79cbaf4b8e9ab910bc81a6",
|
||||
"revisionTime": "2016-07-08T00:08:20Z"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "AUA6op9dlm0X4vv1YPFnIFs6404=",
|
||||
"comment": "v1.1.23",
|
||||
|
|
Loading…
Reference in New Issue