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

add wait_for_fulfillment to spot_fleet_request #1241

Merged
merged 2 commits into from
Jul 28, 2017
Merged

add wait_for_fulfillment to spot_fleet_request #1241

merged 2 commits into from
Jul 28, 2017

Conversation

svenwltr
Copy link
Contributor

@svenwltr svenwltr commented Jul 26, 2017

emerged from #1203

work-in-progress: There are still many tests to fix. Fixing them will take some time, since I am busy right now.

This adds the wait_for_fulfillment argument to aws_spot_fleet_request. Also many of the acceptance test actually don't work, therefore I am fixing everything which doesn't require #1203 and which I am able to fix. The most code is copied from aws_spot_instance_request.

Occured Issues:

  • The AMI for m1.small instances don't work, since they don't support HVM images: Repeated errors have occured processing the launch specification "m1.small, ami-d06a90b0, Linux/UNIX, us-west-2a". It will not be retried for at least 13 minutes. Error message: com.amazonaws.services.ec2.model.AmazonEC2Exception: Non-Windows instances with a virtualization type of 'hvm' are currently not supported for this instance type. (Service: AmazonEC2; Status Code: 400; Error Code: InvalidParameterCombination)
  • Some Tests had a race condition, because the aws_spot_fleet_request might get created before aws_iam_policy_attachment, which caused permission issues.
  • Since the launch_specification changed in some tests the hash changed, which was confusing and took some time to figure out.
  • Some bid prices were below market price, so I had to raise them.

Progress so far:

  • TestAccAWSSpotFleetRequest_associatePublicIpAddress
  • TestAccAWSSpotFleetRequest_changePriceForcesNewRequest
  • TestAccAWSSpotFleetRequest_lowestPriceAzOrSubnetInRegion
  • TestAccAWSSpotFleetRequest_lowestPriceAzInGivenList wrong AMI
  • TestAccAWSSpotFleetRequest_lowestPriceSubnetInGivenList
  • TestAccAWSSpotFleetRequest_multipleInstanceTypesInSameAz
  • TestAccAWSSpotFleetRequest_multipleInstanceTypesInSameSubnet
  • TestAccAWSSpotFleetRequest_overriddingSpotPrice
  • TestAccAWSSpotFleetRequest_diversifiedAllocation – worked out of the box
  • TestAccAWSSpotFleetRequest_withWeightedCapacity – worked out of the box
  • TestAccAWSSpotFleetRequest_withEBSDisk – requires empty key_name
  • TestAccAWSSpotFleetRequest_placementTenancy – This is hard to fix, since I get this error message regardless of which instance type I chose: Instance type m4.large is not supported for the tenancy value (dedicated)

@radeksimko radeksimko added the enhancement Requests to existing resources that expand the functionality or scope. label Jul 26, 2017
@svenwltr svenwltr changed the title [WIP] add wait_for_fulfillment to spot_fleet_request add wait_for_fulfillment to spot_fleet_request Jul 28, 2017
@svenwltr
Copy link
Contributor Author

@radeksimko This PR is ready now.

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.

I left you one more and one less important note. Other than that the code looks very good. Thanks for this taking the time to submit this PR!

@@ -653,6 +681,33 @@ func resourceAwsSpotFleetRequestStateRefreshFunc(d *schema.ResourceData, meta in
}
}

func resourceAwsSpotFleetRequestFulfillmentRefreshFunc(d *schema.ResourceData, meta interface{}) resource.StateRefreshFunc {
Copy link
Member

Choose a reason for hiding this comment

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

Just a nitpick but I feel the interface of this refresh function could be less greedy, i.e. it doesn't need all of the resource data nor all metadata. How about reducing it to something like this?

func resourceAwsSpotFleetRequestFulfillmentRefreshFunc(id string, conn *ec2.EC2)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good to me. I just copied the whole function from above. Also I already thought about merging these two somehow since they look almost the same.

Pending: []string{"pending_fulfillment"},
Target: []string{"fulfilled"},
Refresh: resourceAwsSpotFleetRequestFulfillmentRefreshFunc(d, meta),
Timeout: 10 * time.Minute,
Copy link
Member

Choose a reason for hiding this comment

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

The customizable timeout is currently ignored here - do you mind changing it to d.Timeout(schema.TimeoutCreate)? 😉

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@radeksimko radeksimko added the waiting-response Maintainers are waiting on response from community or contributor. label Jul 28, 2017
@svenwltr
Copy link
Contributor Author

I fixed the remarks. The acceptance tests are still running on my machine.

@radeksimko radeksimko removed the waiting-response Maintainers are waiting on response from community or contributor. label Jul 28, 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.

The acceptance tests are still running on my machine.

My run just finished. I noticed 2 failures, but I believe they're either unrelated or can be addressed in a separate PR.

I'm specifically talking about

  • aws_spot_fleet_request.foo: fleet still has (...) running instances

I believe these are intermittent.

@radeksimko radeksimko merged commit 3bcc4fd into hashicorp:master Jul 28, 2017
@svenwltr
Copy link
Contributor Author

Hmm ... I didn't had any failures in the run of my first commit.

$ make testacc TESTARGS="-run TestAccAWSSpotFleetRequest"
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test $(go list ./... |grep -v 'vendor') -v -run TestAccAWSSpotFleetRequest -timeout 120m
?   	github.com/terraform-providers/terraform-provider-aws	[no test files]
=== RUN   TestAccAWSSpotFleetRequest_associatePublicIpAddress
--- PASS: TestAccAWSSpotFleetRequest_associatePublicIpAddress (409.18s)
=== RUN   TestAccAWSSpotFleetRequest_changePriceForcesNewRequest
--- PASS: TestAccAWSSpotFleetRequest_changePriceForcesNewRequest (585.67s)
=== RUN   TestAccAWSSpotFleetRequest_lowestPriceAzOrSubnetInRegion
--- PASS: TestAccAWSSpotFleetRequest_lowestPriceAzOrSubnetInRegion (280.77s)
=== RUN   TestAccAWSSpotFleetRequest_lowestPriceAzInGivenList
--- PASS: TestAccAWSSpotFleetRequest_lowestPriceAzInGivenList (411.74s)
=== RUN   TestAccAWSSpotFleetRequest_lowestPriceSubnetInGivenList
--- PASS: TestAccAWSSpotFleetRequest_lowestPriceSubnetInGivenList (325.72s)
=== RUN   TestAccAWSSpotFleetRequest_multipleInstanceTypesInSameAz
--- PASS: TestAccAWSSpotFleetRequest_multipleInstanceTypesInSameAz (315.49s)
=== RUN   TestAccAWSSpotFleetRequest_multipleInstanceTypesInSameSubnet
--- PASS: TestAccAWSSpotFleetRequest_multipleInstanceTypesInSameSubnet (314.08s)
=== RUN   TestAccAWSSpotFleetRequest_overriddingSpotPrice
--- PASS: TestAccAWSSpotFleetRequest_overriddingSpotPrice (277.63s)
=== RUN   TestAccAWSSpotFleetRequest_diversifiedAllocation
--- PASS: TestAccAWSSpotFleetRequest_diversifiedAllocation (382.94s)
=== RUN   TestAccAWSSpotFleetRequest_withWeightedCapacity
--- PASS: TestAccAWSSpotFleetRequest_withWeightedCapacity (342.73s)
=== RUN   TestAccAWSSpotFleetRequest_withEBSDisk
--- PASS: TestAccAWSSpotFleetRequest_withEBSDisk (77.91s)
=== RUN   TestAccAWSSpotFleetRequest_placementTenancy
--- PASS: TestAccAWSSpotFleetRequest_placementTenancy (78.22s)
=== RUN   TestAccAWSSpotFleetRequest_CannotUseEmptyKeyName
--- PASS: TestAccAWSSpotFleetRequest_CannotUseEmptyKeyName (0.00s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	3802.078s

@radeksimko
Copy link
Member

radeksimko commented Jul 28, 2017

Which confirms my theory of those failures being intermittent 😃

@svenwltr svenwltr deleted the wait-for-fulfillment branch July 28, 2017 15:52
@Sprinkle
Copy link

With the 0.1.4 version of the provider, anyone having the problem where this "wait_for_fulliment" is not persisted back into state? Hence every run of "terraform plan" will show

wait_for_fulfillment: "" => "false"

Even after "terraform apply" or "terraform refresh" ?

@svenwltr
Copy link
Contributor Author

I can confirm this issue. I tested it with the following template (in eu-west-1). First, I applied it without wait_for_fulfillment and after applying I did it again with wait_for_fulfillment.

resource "aws_iam_policy_attachment" "test-attach" {
  name       = "test-attachment-123"
  roles      = ["${aws_iam_role.test-role.name}"]
  policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonEC2SpotFleetRole"
}

resource "aws_iam_role" "test-role" {
  name = "test-role-123"

  assume_role_policy = <<EOF
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "",
      "Effect": "Allow",
      "Principal": {
        "Service": [
          "spotfleet.amazonaws.com",
          "ec2.amazonaws.com"
        ]
      },
      "Action": "sts:AssumeRole"
    }
  ]
}
EOF
}

resource "aws_spot_fleet_request" "foo" {
  iam_fleet_role                      = "${aws_iam_role.test-role.arn}"
  spot_price                          = "0.555"
  target_capacity                     = 2
  valid_until                         = "2019-11-04T20:44:20Z"
  terminate_instances_with_expiration = true

  # wait_for_fulfillment = true

  launch_specification {
    instance_type = "m4.large"
    ami           = "ami-417abe38"
  }

  depends_on = ["aws_iam_policy_attachment.test-attach"]
}

@radeksimko
Copy link
Member

radeksimko commented Sep 25, 2017

@Sprinkle @svenwltr do you mind raising a new issue for this? Otherwise it will very likely get lost and forgotten here.

Thanks.

@svenwltr
Copy link
Contributor Author

svenwltr commented Oct 5, 2017

@radeksimko Done: #1816

@ghost
Copy link

ghost commented Apr 11, 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 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement Requests to existing resources that expand the functionality or scope.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants