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_appautoscaling_scheduled_action #2231

Conversation

atsushi-ishibashi
Copy link
Contributor

@radeksimko radeksimko added the new-resource Introduces a new resource. label Nov 10, 2017
@atsushi-ishibashi
Copy link
Contributor Author

make testacc TEST=./aws TESTARGS='-run=TestAccAwsAppautoscalingScheduledAction_dynamo'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -run=TestAccAwsAppautoscalingScheduledAction_basic -timeout 120m
=== RUN   TestAccAwsAppautoscalingScheduledAction_basic
--- PASS: TestAccAwsAppautoscalingScheduledAction_basic (90.87s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	90.907s 
make testacc TEST=./aws TESTARGS='-run=TestAccAwsAppautoscalingScheduledAction_ECS'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -run=TestAccAwsAppautoscalingScheduledAction_ECS -timeout 120m
=== RUN   TestAccAwsAppautoscalingScheduledAction_ECS
--- PASS: TestAccAwsAppautoscalingScheduledAction_ECS (122.79s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	122.848s
make testacc TEST=./aws TESTARGS='-run=TestAccAwsAppautoscalingScheduledAction_EMR'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -run=TestAccAwsAppautoscalingScheduledAction_EMR -timeout 120m
=== RUN   TestAccAwsAppautoscalingScheduledAction_EMR
--- PASS: TestAccAwsAppautoscalingScheduledAction_EMR (701.34s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	701.407s
make testacc TEST=./aws TESTARGS='-run=TestAccAwsAppautoscalingScheduledAction_SpotFleet'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -run=TestAccAwsAppautoscalingScheduledAction_SpotFleet -timeout 120m
=== RUN   TestAccAwsAppautoscalingScheduledAction_SpotFleet
--- PASS: TestAccAwsAppautoscalingScheduledAction_SpotFleet (330.93s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	330.970s

@atsushi-ishibashi atsushi-ishibashi force-pushed the resource_aws_appautoscaling_scheduled_action branch from 502f7f8 to 99a586a Compare November 11, 2017 07:06
@atsushi-ishibashi atsushi-ishibashi changed the title [WIP]New Resource: aws_appautoscaling_scheduled_action New Resource: aws_appautoscaling_scheduled_action Nov 11, 2017
@radeksimko radeksimko added the size/XL Managed by automation to categorize the size of a PR. label Nov 15, 2017
Copy link
Member

@radeksimko radeksimko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this PR @atsushi-ishibashi
I left you some comments & questions, the most important one about support of updates and unique ID.

Let me know what you think.

validDimensions := []string{"ecs:service:DesiredCount", "ec2:spot-fleet-request:TargetCapacity",
"elasticmapreduce:instancegroup:InstanceCount", "appstream:fleet:DesiredCapacity",
"dynamodb:table:ReadCapacityUnits", "dynamodb:table:WriteCapacityUnits",
"dynamodb:index:ReadCapacityUnits", "dynamodb:index:WriteCapacityUnits"}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While offline, plan-time validation is usually useful I'm afraid it could be counter-productive here as the list of valid dimensions may and will expand and it did recently. I think we'd play a constant catch-up with AWS here and rushing to cut a release just to support a new dimension just because of this strict validation.
Theoretically we could validate for something like [a-zA-Z]+:[a-zA-Z]+:[a-zA-Z]+ but frankly I'd just rather avoid the validation altogether here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

docs lists constant strings so I removed ValidateFunc.

ForceNew: true,
ValidateFunc: func(v interface{}, k string) (ws []string, errors []error) {
value := v.(string)
validServiceNamespaces := []string{"ecs", "elasticmapreduce", "ec2", "appstream", "dynamodb"}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As below - I'm afraid the list of valid service namespaces may/will grow and I'd like us to avoid the maintenance burden associated with it, if possible.

Copy link
Contributor Author

@atsushi-ishibashi atsushi-ishibashi Dec 2, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I removed ValidateFunc.

}
}

func resourceAwsAppautoscalingScheduledActionCreate(d *schema.ResourceData, meta interface{}) error {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per docs I think we should support updates of this resource and basically just rename this function to something like resourceAwsAppautoscalingScheduledActionCreateOrUpdate or resourceAwsAppautoscalingScheduledActionPut and reference it in Update too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK👍

return resource.RetryableError(err)
default:
return resource.NonRetryableError(err)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: Is this related to eventual consistency?

Regardless of the reason I think the above conditional starting on L153 can be simplified to something like this:

if err != nil {
  if isAWSErr(err, applicationautoscaling.ErrCodeObjectNotFoundException, "") {
    return resource.RetryableError(err)
  }
  return resource.NonRetryableError(err)
}

Copy link
Contributor Author

@atsushi-ishibashi atsushi-ishibashi Dec 2, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assumed that soon after creating dynamo table and on...
I simplified handling error.

return nil
}
if len(resp.ScheduledActions) != 1 {
return fmt.Errorf("Number of Scheduled Action (%s) isn't one, got %d", saName, len(resp.ScheduledActions))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Grammar nitpick, do you mind changing this to Expected 1 scheduled action under %s, found %d?

"Action": [
"ecs:DescribeServices",
"ecs:UpdateService",
"cloudwatch:DescribeAlarms"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick - extra whitespace here 👀

}

resource "aws_ecs_cluster" "hoge" {
name = "tf-ecs-cluster-%s"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra whitespace here 👀

}

resource "aws_ecs_task_definition" "hoge" {
family = "foobar"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mind using a random name here too, please?

The following arguments are supported:

* `name` - (Required) The name of the scheduled action.
* `service_namespace` - (Required) The namespace of the AWS service. Documentation can be found in the parameter at: [AWS Application Auto Scaling API Reference](https://docs.aws.amazon.com/ApplicationAutoScaling/latest/APIReference/API_PutScheduledAction.html#ApplicationAutoScaling-PutScheduledAction-request-ServiceNamespace) Valid Values: ecs | elasticmapreduce | ec2 | appstream | dynamodb
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would avoid documenting all valid values as that will become a maintenance burden as these expand. How about we just mention a few examples? The user can always IMO look up all valid values in the docs, right?

* `name` - (Required) The name of the scheduled action.
* `service_namespace` - (Required) The namespace of the AWS service. Documentation can be found in the parameter at: [AWS Application Auto Scaling API Reference](https://docs.aws.amazon.com/ApplicationAutoScaling/latest/APIReference/API_PutScheduledAction.html#ApplicationAutoScaling-PutScheduledAction-request-ServiceNamespace) Valid Values: ecs | elasticmapreduce | ec2 | appstream | dynamodb
* `resource_id` - (Required) The identifier of the resource associated with the scheduled action. Documentation can be found in the parameter at: [AWS Application Auto Scaling API Reference](https://docs.aws.amazon.com/ApplicationAutoScaling/latest/APIReference/API_PutScheduledAction.html#ApplicationAutoScaling-PutScheduledAction-request-ResourceId)
* `scalable_dimension` - (Optional) The scalable dimension. Documentation can be found in the parameter at: [AWS Application Auto Scaling API Reference](https://docs.aws.amazon.com/ApplicationAutoScaling/latest/APIReference/API_PutScheduledAction.html#ApplicationAutoScaling-PutScheduledAction-request-ScalableDimension) Valid Values: ecs:service:DesiredCount | ec2:spot-fleet-request:TargetCapacity | elasticmapreduce:instancegroup:InstanceCount | appstream:fleet:DesiredCapacity | dynamodb:table:ReadCapacityUnits | dynamodb:table:WriteCapacityUnits | dynamodb:index:ReadCapacityUnits | dynamodb:index:WriteCapacityUnits
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would avoid documenting all valid values as that will become a maintenance burden as these expand. How about we just mention a few examples? The user can always IMO look up all valid values in the docs, right?

@radeksimko radeksimko added the waiting-response Maintainers are waiting on response from community or contributor. label Dec 2, 2017
@radeksimko radeksimko removed the waiting-response Maintainers are waiting on response from community or contributor. label Dec 4, 2017
Copy link
Member

@radeksimko radeksimko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 🚢

@radeksimko radeksimko merged commit 01ff393 into hashicorp:master Dec 4, 2017
mdlavin pushed a commit to mdlavin/terraform-provider-aws that referenced this pull request Dec 9, 2017
* Make files

* WIP

* WIP

* New Resource: aws_appautoscaling_scheduled_action

* Reflect reviews

* Used 3fields for id
@atsushi-ishibashi atsushi-ishibashi deleted the resource_aws_appautoscaling_scheduled_action branch December 13, 2017 15:16
@ghost
Copy link

ghost commented Apr 10, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked and limited conversation to collaborators Apr 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
new-resource Introduces a new resource. size/XL Managed by automation to categorize the size of a PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants