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

Terraform Crash dynamic tags #22043

Closed
udayanms opened this issue Jul 11, 2019 · 6 comments · Fixed by #22169
Closed

Terraform Crash dynamic tags #22043

udayanms opened this issue Jul 11, 2019 · 6 comments · Fixed by #22169

Comments

@udayanms
Copy link

udayanms commented Jul 11, 2019

Terraform Version

.12

Terraform Configuration Files

variables.tf:

variable "SpotFleetInstanceTags" {
  type        = map
  description = "EC2 Instance Tags"
}

main.tf:

resource "aws_spot_fleet_request" "xxxSpotFleet" {
  iam_fleet_role      = "${var.SpotFleetIamFleetRole}"
  spot_price          = "0.03"
  allocation_strategy = "diversified"
  target_capacity     = 2
  valid_until         = "2019-11-04T20:44:20Z"
  dynamic "launch_specification" {
    iterator = instanceType
    for_each = var.SpotFleetInstanceTypes
    content {
         instance_type            = instanceType.value
         ami                      = "${var.SpotFleetimageId}"
         key_name                 = "my-key"
         spot_price               = "${var.SpotFleetPrice}"
         iam_instance_profile_arn = "${var.SpotFleetIamInstanceProfile}"
         subnet_id                = "${var.SpotFleetSubnetId}"
         weighted_capacity        = "${var.SpotFleetWeightedCapacity}"
         dynamic "tags" {
             for_each = var.SpotFleetInstanceTags
             iterator = fleetTag
             content {
               key   = fleetTag.key
               value = fleetTag.value
               propagate_at_launch = true
             }
         }
   }
  }
}

vars.tfvars:

SpotFleetInstanceTags = {
    Name = "Create-Compute-SpotFleet-all-xxx-xxx"
    Environment = "production"
}

Debug Output

Crash Output

panic: AttributeTypes on non-object Type

goroutine 14 [running]:
github.com/zclconf/go-cty/cty.Type.AttributeTypes(...)
        /opt/teamcity-agent/work/9e329aa031982669/pkg/mod/github.com/zclconf/[email protected]/cty/object_type.go:134
github.com/hashicorp/terraform/lang/blocktoattr.SchemaForCtyElementType(0x2206c00, 0xc0000404e0, 0x2206c00)
        /opt/teamcity-agent/work/9e329aa031982669/src/github.com/hashicorp/terraform/lang/blocktoattr/schema.go:108 +0x24d
github.com/hashicorp/terraform/lang/blocktoattr.walkVariables(0x2205880, 0xc0003db4a0, 0xc000484660, 0x1, 0x2205880, 0xc0003db4a0, 0xc00116d080, 0x2, 0xc0011a3b00, 0x1)
        /opt/teamcity-agent/work/9e329aa031982669/src/github.com/hashicorp/terraform/lang/blocktoattr/variables.go:37 +0x476
github.com/hashicorp/terraform/lang/blocktoattr.walkVariables(0x2205880, 0xc0002d9130, 0x0, 0x1, 0x2205880, 0xc0002d9130, 0xc00113ee50, 0x0, 0x0, 0x3311ca0)
        /opt/teamcity-agent/work/9e329aa031982669/src/github.com/hashicorp/terraform/lang/blocktoattr/variables.go:35 +0x289
github.com/hashicorp/terraform/lang/blocktoattr.ExpandedVariables(...)
        /opt/teamcity-agent/work/9e329aa031982669/src/github.com/hashicorp/terraform/lang/blocktoattr/variables.go:24
github.com/hashicorp/terraform/lang.ReferencesInBlock(0x2205880, 0xc0002d9130, 0xc00113ee50, 0x0, 0x0, 0x0, 0x0, 0x0, 0xc000450d80)
        /opt/teamcity-agent/work/9e329aa031982669/src/github.com/hashicorp/terraform/lang/references.go:68 +0x66
github.com/hashicorp/terraform/terraform.(*NodeAbstractResource).References(0xc0000bc2c0, 0x0, 0x0, 0x0)
        /opt/teamcity-agent/work/9e329aa031982669/src/github.com/hashicorp/terraform/terraform/node_resource_abstract.go:190 +0x251
github.com/hashicorp/terraform/terraform.NewReferenceMap(0xc000470960, 0xf, 0xf, 0xf)
        /opt/teamcity-agent/work/9e329aa031982669/src/github.com/hashicorp/terraform/terraform/transform_reference.go:402 +0x24a
github.com/hashicorp/terraform/terraform.(*ReferenceTransformer).Transform(0x3311ca0, 0xc00009aaf0, 0x14, 0x0)
        /opt/teamcity-agent/work/9e329aa031982669/src/github.com/hashicorp/terraform/terraform/transform_reference.go:73 +0x71
github.com/hashicorp/terraform/terraform.(*BasicGraphBuilder).Build(0xc0004ef8e0, 0x0, 0x0, 0x0, 0x32f1fe0, 0xc0004ef910, 0x4e5650, 0xc00009a000)
        /opt/teamcity-agent/work/9e329aa031982669/src/github.com/hashicorp/terraform/terraform/graph_builder.go:50 +0x477
github.com/hashicorp/terraform/terraform.(*PlanGraphBuilder).Build(0xc0000ecf50, 0x0, 0x0, 0x0, 0x1, 0x0, 0x1a7b780, 0xc0002f2cc0)
        /opt/teamcity-agent/work/9e329aa031982669/src/github.com/hashicorp/terraform/terraform/graph_builder_plan.go:65 +0xbc
github.com/hashicorp/terraform/terraform.(*Context).Graph(0xc000e2e000, 0x6, 0xc0004ef966, 0xc0004efa00, 0x1, 0x1, 0x0)
        /opt/teamcity-agent/work/9e329aa031982669/src/github.com/hashicorp/terraform/terraform/context.go:292 +0x1b8
github.com/hashicorp/terraform/terraform.(*Context).Validate(0xc000e2e000, 0x0, 0x0, 0x0)
        /opt/teamcity-agent/work/9e329aa031982669/src/github.com/hashicorp/terraform/terraform/context.go:670 +0xf3
github.com/hashicorp/terraform/backend/local.(*Local).context(0xc0004cc270, 0xc0004a1180, 0x1, 0x1, 0x2, 0xc00000c100, 0x1, 0x2, 0x0)
        /opt/teamcity-agent/work/9e329aa031982669/src/github.com/hashicorp/terraform/backend/local/backend_local.go:120 +0x974
github.com/hashicorp/terraform/backend/local.(*Local).opPlan(0xc0004cc270, 0x22051c0, 0xc000084280, 0x22051c0, 0xc000084740, 0xc0004a1180, 0xc0000841c0)
        /opt/teamcity-agent/work/9e329aa031982669/src/github.com/hashicorp/terraform/backend/local/backend_plan.go:67 +0x2a3
github.com/hashicorp/terraform/backend/local.(*Local).Operation.func1(0xc0000825a0, 0xc000082710, 0xc000082a70, 0xc0004a1180, 0xc0004cc270, 0xc0000841c0, 0xc000082000, 0x22051c0, 0xc000084280, 0x22051c0, ...)
        /opt/teamcity-agent/work/9e329aa031982669/src/github.com/hashicorp/terraform/backend/local/backend.go:356 +0x135
created by github.com/hashicorp/terraform/backend/local.(*Local).Operation
        /opt/teamcity-agent/work/9e329aa031982669/src/github.com/hashicorp/terraform/backend/local/backend.go:340 +0x36b
!!!!!!!!!!!!!!!!!!!!!!!!!!! TERRAFORM CRASH !!!!!!!!!!!!!!!!!!!!!!!!!!!!

Expected Behavior

Just add tags to spot fleet.

Actual Behavior

Crashed

Steps to Reproduce

I just need terraform plan --var-file="vars.tfvars"
every run even if I delete the state files gives same error.

Additional Context

the only feeling I have it Dynamic loop inside another dynamic loop.
in the code I am running thru instance types using dynamic and then again dynamics for tags. Code was running until I change the standard tag syntax to Dynamic tags.

References

@ghost ghost added bug crash labels Jul 11, 2019
@jbardin jbardin added the config label Jul 11, 2019
@jbardin
Copy link
Member

jbardin commented Jul 11, 2019

Hi @udayanms,

Thanks for filing the issue!

This is due to the inappropriate application of dynamic to a map attribute.

A simpler reproduction for later reference:

resource "null_resource" "a" {
  dynamic "triggers" {
    for_each = {}
    content {
      key   = each.key
      value = each.value
    }
  }
}

@udayanms
Copy link
Author

thanks James, could you elaborate what should have been the right way? above its not clear.

@jbardin
Copy link
Member

jbardin commented Jul 11, 2019

The tags attribute is a map of string values, and dynamic can only be used on blocks: https://www.terraform.io/docs/configuration/expressions.html#dynamic-blocks.

You can assign a map to tags directly:

tags = var.SpotFleetInstanceTags

@udayanms
Copy link
Author

Thanks, actually intention was to build a model where I could enforce some standard tags along with the new tags. But this does the job at this moment.

As a short note the validation should highlight the mistake than crashing. I feel it still falls under a category of Bug. The challenge is there is no extensive documentation of different scenarios of TF. e.g. it would have been helpful for each feature if there was any examples attached for each type of variable. I had to dig across multiple samples of code to understand this Dynamic feature.

Thanks again,

@udayanms
Copy link
Author

I believe it should lead to a graceful termination with appropriate error. Exit with Crash leaves lose end which may come back as a negative aspect of the tool.

@ghost
Copy link

ghost commented Aug 23, 2019

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 Aug 23, 2019
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.

2 participants