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 'tags' support to aws_spot_fleet_request #2042

Merged
merged 3 commits into from
Oct 25, 2017

Conversation

jekh
Copy link
Contributor

@jekh jekh commented Oct 25, 2017

This adds support for tags on spot fleet requests. I tried to follow the pattern of the nearly-identical tags block in resource_aws_instance.go (the difference being Spot Fleet only supports instance, not volume, as a resource type).

Since the documentation for aws_spot_fleet_request simply references the aws_instance documentation, I didn't add any additional info about tags, but I did include a tags block in one of the examples.

This should resolve feature request #1232.

Closes #1232

@radeksimko radeksimko added the enhancement Requests to existing resources that expand the functionality or scope. label Oct 25, 2017
@@ -377,6 +382,21 @@ func buildSpotFleetLaunchSpecification(d map[string]interface{}, meta interface{
}
}

if v, ok := d["tags"]; ok {
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 adding an extra check here? i.e.

if m, ok := d["tags"].(map[string]interface{}); ok && len(m) > 0 {

otherwise this would break all configs without tags, see output from relevant acceptance tests:

=== RUN   TestAccAWSSpotFleetRequest_associatePublicIpAddress
--- FAIL: TestAccAWSSpotFleetRequest_associatePublicIpAddress (682.03s)
	testing.go:434: Step 0 error: Error applying: 1 error(s) occurred:

		* aws_spot_fleet_request.foo: 1 error(s) occurred:

		* aws_spot_fleet_request.foo: Error requesting spot fleet: [WARN] Error creating Spot fleet request, retrying: InvalidSpotFleetRequestConfig: Tag value cannot be null. Use empty string instead.
			status code: 400, request id: 42b4061d-3214-4bae-9fba-0751e13458ab

@radeksimko radeksimko added the waiting-response Maintainers are waiting on response from community or contributor. label Oct 25, 2017
@jekh
Copy link
Contributor Author

jekh commented Oct 25, 2017

Done! Thanks, for some reason this is one of the test cases I didn't test. That's what the acceptance tests are for, I suppose. Please let me know if there are any other issues you see with the change.

@radeksimko radeksimko removed the waiting-response Maintainers are waiting on response from community or contributor. label Oct 25, 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 the changes, I just added an acceptance test to make sure we don't break related functionality in the future & pushed that into your branch.

🚀

@radeksimko radeksimko merged commit 6514cc5 into hashicorp:master Oct 25, 2017
@jekh jekh deleted the add-spot-fleet-request-tags branch November 2, 2017 02:28
@jedi4ever
Copy link

@radeksimko in which TF version will this be available?

@bflad
Copy link
Contributor

bflad commented Jan 28, 2018

This was previously released in terraform-provider-aws version 1.2.0 and has been available in all releases since. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

@bflad bflad added this to the v1.2.0 milestone Jan 28, 2018
@cemo
Copy link

cemo commented Jan 28, 2018

You could also search the issue number 2042 in CHANGELOG.

@yogeek
Copy link

yogeek commented Jul 6, 2018

Sorry if I misuderstood but it seems to me that "tags" are possible only in the launch_specification{...} part of the aws_spot_fleet_request resource and not in the resource itself.

Indeed, if I apply the example in the documentation by using a tag like this :

resource "aws_spot_fleet_request" "cheap_compute" {
  iam_fleet_role          = "${var.arn}"
  allocation_strategy     = "lowestPrice"
  target_capacity         = 1

  launch_specification {
    ami                       = "${var.ami}"
    instance_type             = "${var.instance_type}"
    key_name                  = "${var.key_name}"
    vpc_security_group_ids    = "${var.vpc_security_group_ids}"
    subnet_id                 = "${var.subnet_id}"

    tags = {
        Name = "${var.name}"
    }
  }
}

the tag is in fact only on the spot instance created by the request but not on the request itself (whereas its possible to add tags in AWS conole for this resource)

And if I try to add a tag section directly under the aws_spot_fleet_request resource :

resource "aws_spot_fleet_request" "cheap_compute" {
  iam_fleet_role          = "${var.arn}"
  allocation_strategy     = "lowestPrice"
  target_capacity         = 1

  tags = {
        Name = "${var.name}"
    }

  launch_specification {
    ami                       = "${var.ami}"
    instance_type             = "${var.instance_type}"
    key_name                  = "${var.key_name}"
    vpc_security_group_ids    = "${var.vpc_security_group_ids}"
    subnet_id                 = "${var.subnet_id}"

    tags = {
        Name = "${var.name}"
    }
  }
}

I have the following error :

Error: aws_spot_fleet_request.cheap_compute: : invalid or unknown key: tags

I thought this PR would be to add tag on the resource directly...Did I misunderstood the PR here ?
Thank you

@bgaillard
Copy link

Hi, we encounter the same problem as @yogeek.

Error: module.jenkins.aws_spot_fleet_request.jenkins-spot-fleet-v2: : invalid or unknown key: tags

I upgraded the AWS provider to version 1.42 and this still not work.

Do you know what's the problem ?

@ghost
Copy link

ghost commented Apr 2, 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 2, 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.

add support tags for aws_spot_fleet_request
7 participants