-
Notifications
You must be signed in to change notification settings - Fork 9.2k
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,10 @@ func resourceAwsSpotFleetRequest() *schema.Resource { | |
Delete: resourceAwsSpotFleetRequestDelete, | ||
Update: resourceAwsSpotFleetRequestUpdate, | ||
|
||
Timeouts: &schema.ResourceTimeout{ | ||
Create: schema.DefaultTimeout(10 * time.Minute), | ||
}, | ||
|
||
SchemaVersion: 1, | ||
MigrateState: resourceAwsSpotFleetRequestMigrateState, | ||
|
||
|
@@ -37,6 +41,12 @@ func resourceAwsSpotFleetRequest() *schema.Resource { | |
ForceNew: true, | ||
Default: false, | ||
}, | ||
"wait_for_fulfillment": { | ||
Type: schema.TypeBool, | ||
Optional: true, | ||
ForceNew: false, | ||
Default: false, | ||
}, | ||
// http://docs.aws.amazon.com/sdk-for-go/api/service/ec2.html#type-SpotFleetLaunchSpecification | ||
// http://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_SpotFleetLaunchSpecification.html | ||
"launch_specification": { | ||
|
@@ -623,6 +633,24 @@ func resourceAwsSpotFleetRequestCreate(d *schema.ResourceData, meta interface{}) | |
return err | ||
} | ||
|
||
if d.Get("wait_for_fulfillment").(bool) { | ||
log.Println("[INFO] Waiting for Spot Fleet Request to be fulfilled") | ||
spotStateConf := &resource.StateChangeConf{ | ||
Pending: []string{"pending_fulfillment"}, | ||
Target: []string{"fulfilled"}, | ||
Refresh: resourceAwsSpotFleetRequestFulfillmentRefreshFunc(d, meta), | ||
Timeout: 10 * time.Minute, | ||
Delay: 10 * time.Second, | ||
MinTimeout: 3 * time.Second, | ||
} | ||
|
||
_, err = spotStateConf.WaitForState() | ||
|
||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return resourceAwsSpotFleetRequestRead(d, meta) | ||
} | ||
|
||
|
@@ -653,6 +681,33 @@ func resourceAwsSpotFleetRequestStateRefreshFunc(d *schema.ResourceData, meta in | |
} | ||
} | ||
|
||
func resourceAwsSpotFleetRequestFulfillmentRefreshFunc(d *schema.ResourceData, meta interface{}) resource.StateRefreshFunc { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
return func() (interface{}, string, error) { | ||
conn := meta.(*AWSClient).ec2conn | ||
req := &ec2.DescribeSpotFleetRequestsInput{ | ||
SpotFleetRequestIds: []*string{aws.String(d.Id())}, | ||
} | ||
resp, err := conn.DescribeSpotFleetRequests(req) | ||
|
||
if err != nil { | ||
log.Printf("Error on retrieving Spot Fleet Request when waiting: %s", err) | ||
return nil, "", nil | ||
} | ||
|
||
if resp == nil { | ||
return nil, "", nil | ||
} | ||
|
||
if len(resp.SpotFleetRequestConfigs) == 0 { | ||
return nil, "", nil | ||
} | ||
|
||
spotFleetRequest := resp.SpotFleetRequestConfigs[0] | ||
|
||
return spotFleetRequest, *spotFleetRequest.ActivityStatus, nil | ||
} | ||
} | ||
|
||
func resourceAwsSpotFleetRequestRead(d *schema.ResourceData, meta interface{}) error { | ||
// http://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeSpotFleetRequests.html | ||
conn := meta.(*AWSClient).ec2conn | ||
|
There was a problem hiding this comment.
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)
? 😉There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed