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

aws_instance adds extra tag '#' #914

Closed
patricklucas opened this issue Feb 3, 2015 · 4 comments · Fixed by #921
Closed

aws_instance adds extra tag '#' #914

patricklucas opened this issue Feb 3, 2015 · 4 comments · Fixed by #921
Assignees

Comments

@patricklucas
Copy link

Terraform adds a superfluous tag to AWS instances '#' with a value of the quantity of other tags it applies.

I would guess this has something to do with the API convention of having a '.#' field that indicates the number of unique instances of .

$ cat asdf.tf
provider "aws" {
    region = "us-west-1"
}

resource "aws_instance" "foo-1" {
    ami = "ami-abcd1234"
    instance_type = "m3.large"
    subnet_id = "subnet-ab1234cd"
    security_groups = ["sg-01234567"]
    tags {
        Name = "test-foo-1"
        mytag = "foo"
    }
    block_device {
        device_name = "/dev/sda1"
        volume_type = "gp2"
        volume_size = 16
    }
    block_device {
        device_name = "/dev/sdf"
        volume_type = "gp2"
        volume_size = 1024
    }
}

$ terraform plan
Refreshing Terraform state prior to plan...


The Terraform execution plan has been generated and is shown below.
Resources are shown in alphabetical order for quick scanning. Green resources
will be created (or destroyed and then created if an existing resource
exists), yellow resources are being changed in-place, and red resources
will be destroyed.

Note: You didn't specify an "-out" parameter to save this plan, so when
"apply" is called, Terraform can't guarantee this is what will execute.

+ aws_instance.foo-1
    ami:                                           "" => "ami-abcd1234"
    availability_zone:                             "" => "<computed>"
    block_device.#:                                "" => "2"
    block_device.2382792209.delete_on_termination: "" => "1"
    block_device.2382792209.device_name:           "" => "/dev/sdf"
    block_device.2382792209.encrypted:             "" => "<computed>"
    block_device.2382792209.snapshot_id:           "" => "<computed>"
    block_device.2382792209.virtual_name:          "" => ""
    block_device.2382792209.volume_size:           "" => "1024"
    block_device.2382792209.volume_type:           "" => "gp2"
    block_device.2936417914.delete_on_termination: "" => "1"
    block_device.2936417914.device_name:           "" => "/dev/sda1"
    block_device.2936417914.encrypted:             "" => "<computed>"
    block_device.2936417914.snapshot_id:           "" => "<computed>"
    block_device.2936417914.virtual_name:          "" => ""
    block_device.2936417914.volume_size:           "" => "16"
    block_device.2936417914.volume_type:           "" => "gp2"
    instance_type:                                 "" => "m3.large"
    key_name:                                      "" => "<computed>"
    private_dns:                                   "" => "<computed>"
    private_ip:                                    "" => "<computed>"
    public_dns:                                    "" => "<computed>"
    public_ip:                                     "" => "<computed>"
    security_groups.#:                             "" => "1"
    security_groups.2681880818:                    "" => "sg-01234567"
    subnet_id:                                     "" => "subnet-ab1234cd"
    tags.#:                                        "" => "2"
    tags.Name:                                     "" => "test-foo-1"
    tags.mytag:                                    "" => "foo"
    tenancy:                                       "" => "<computed>"



$ terraform apply
aws_instance.foo-1: Creating...
  ami:                                           "" => "ami-abcd1234"
  availability_zone:                             "" => "<computed>"
  block_device.#:                                "" => "2"
  block_device.2382792209.delete_on_termination: "" => "1"
  block_device.2382792209.device_name:           "" => "/dev/sdf"
  block_device.2382792209.encrypted:             "" => "<computed>"
  block_device.2382792209.snapshot_id:           "" => "<computed>"
  block_device.2382792209.virtual_name:          "" => ""
  block_device.2382792209.volume_size:           "" => "1024"
  block_device.2382792209.volume_type:           "" => "gp2"
  block_device.2936417914.delete_on_termination: "" => "1"
  block_device.2936417914.device_name:           "" => "/dev/sda1"
  block_device.2936417914.encrypted:             "" => "<computed>"
  block_device.2936417914.snapshot_id:           "" => "<computed>"
  block_device.2936417914.virtual_name:          "" => ""
  block_device.2936417914.volume_size:           "" => "16"
  block_device.2936417914.volume_type:           "" => "gp2"
  instance_type:                                 "" => "m3.large"
  key_name:                                      "" => "<computed>"
  private_dns:                                   "" => "<computed>"
  private_ip:                                    "" => "<computed>"
  public_dns:                                    "" => "<computed>"
  public_ip:                                     "" => "<computed>"
  security_groups.#:                             "" => "1"
  security_groups.2681880818:                    "" => "sg-01234567"
  subnet_id:                                     "" => "subnet-ab1234cd"
  tags.#:                                        "" => "2"
  tags.Name:                                     "" => "test-foo-1"
  tags.mytag:                                    "" => "foo"
  tenancy:                                       "" => "<computed>"
aws_instance.foo-1: Creation complete

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

The state of your infrastructure has been saved to the path
below. This state is required to modify and destroy your
infrastructure, so keep it safe. To inspect the complete state
use the `terraform show` command.

State path: terraform.tfstate

$ aws ec2 describe-tags --filters Name=resource-id,Values=i-5381849b
{
    "Tags": [
        {
            "ResourceType": "instance",
            "ResourceId": "i-5381849b",
            "Value": "test-foo-1",
            "Key": "Name"
        },
        {
            "ResourceType": "instance",
            "ResourceId": "i-5381849b",
            "Value": "foo",
            "Key": "mytag"
        },
        {
            "ResourceType": "instance",
            "ResourceId": "i-5381849b",
            "Value": "2",
            "Key": "#"
        }
    ]
}
@phinze
Copy link
Contributor

phinze commented Feb 3, 2015

This is probably a core bug but will tag as AWS for the moment. Will make sure to get this fixed before we cut 0.3.7

@phinze phinze self-assigned this Feb 3, 2015
phinze added a commit that referenced this issue Feb 4, 2015
An `InstanceDiff` will include `ResourceAttrDiff` entries for the
"length" / `#` field of maps. This makes sense, since for something like
`terraform plan` it's useful to see when counts are changing.

The `DiffFieldReader` was not taking these entries into account when
reading maps out, and was therefore incorrectly returning maps that
included an extra `'#'` field, which was causing all sorts of havoc
for providers (extra tags on AWS instances, broken google compute
instance launch, possibly others).

 * fixes #914 - extra tags on AWS instances
 * fixes #883 - general core issue sprouted from #757
 * removes the hack+TODO from #757
yahyapo pushed a commit to yahyapo/terraform that referenced this issue Mar 13, 2015
An `InstanceDiff` will include `ResourceAttrDiff` entries for the
"length" / `#` field of maps. This makes sense, since for something like
`terraform plan` it's useful to see when counts are changing.

The `DiffFieldReader` was not taking these entries into account when
reading maps out, and was therefore incorrectly returning maps that
included an extra `'#'` field, which was causing all sorts of havoc
for providers (extra tags on AWS instances, broken google compute
instance launch, possibly others).

 * fixes hashicorp#914 - extra tags on AWS instances
 * fixes hashicorp#883 - general core issue sprouted from hashicorp#757
 * removes the hack+TODO from hashicorp#757
@kamaljeetrathi
Copy link

Any provision to set the name of aws instance in terraform.

@phinze
Copy link
Contributor

phinze commented Oct 30, 2015

@kamaljeetrathi in EC2, the name of an instance is just a "Name" tag. So if you set a Name tag it will show up in the web console as the instance name.

@ghost
Copy link

ghost commented Apr 30, 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 have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Apr 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants