cloudposse / terraform-aws-ec2-instance

Terraform module for provisioning a general purpose EC2 host
https://cloudposse.com/accelerate
Apache License 2.0
168 stars 221 forks source link

Invalid index in aws_volume_attachment volume_id parameter #165

Closed riccardomassullo closed 1 year ago

riccardomassullo commented 1 year ago

Describe the Bug

The following error is returned if the value of ebs_volume_count is more than 0, for any value.

plan. Resource actions are indicated with the following symbols:                                                                                                                     
  + create                                                                                                                                                                           

Terraform planned the following actions, but then encountered a problem:                                                                                                             

  # module.ec2_instance_test.aws_ebs_volume.default[0] will be created                                                                                                         
  + resource "aws_ebs_volume" "default" {                                                                                                                                                                                                                                                                                                                                  
      + arn               = (known after apply)                                                                                                                                      
      + availability_zone = "eu-central-1a"                                                                                                                                             
      + encrypted         = true                                                                                                                                                     
      + final_snapshot    = false                                                                                                                                                    
      + id                = (known after apply)                                                                                                                                                                                                                                                                                                                            
      + iops              = 3000                                                                                                                                                                                                                                                                                                                                           
      + kms_key_id        = "arn:aws:kms:eu-central-1:xxxxxxxxxxxx:key/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"                                                                            
      + size              = 200                                                                                                                                                      
      + snapshot_id       = (known after apply)                                                                                                                                      
      + tags              = {                                                                                                                                                        
          + "Backup"      = "daily"                                                                                                                                                  
          + "Environment" = "legacy"                                                                                                                                                 
          + "Name"        = "test-legacy-test"                                                                                                                                  
          + "Namespace"   = "test"                                                                                                                                                                                                                                                                                                                                          
        }                                                                                                                                                                                                                                                                                                                                                                  
      + tags_all          = {                                                                                                                                                        
          + "Backup"      = "daily"                                                                                                                                                                                                                                                                                                                                        
          + "Environment" = "legacy"                                                                                                                                                 
          + "Name"        = "test-legacy-test"                                                                                                                                                                                                                                                                                                                        
          + "Namespace"   = "test"                                                                                                                                                    
        }                                                                                                                                                                                                                                                                                                                                                                  
      + throughput        = 125                                                                                                                                                                                                                                                                                                                                            
      + type              = "gp3"                                                                                                                                                                                                                                                                                                                                          
    }                                                                                                                                                                                

Plan: 1 to add, 0 to change, 0 to destroy.                                                                                                                                                                                                                                                                                                                                 
╷                                                                                                                                                                                    
│ Error: Invalid index                                                                                                                                                               
│                                                                                                                                                                                    
│   on .terraform/modules/ec2_instance_controller/main.tf line 194, in resource "aws_volume_attachment" "default":                                                                                                                                                                                                                                                         
│  194:   volume_id   = one(aws_ebs_volume.default[*].id[count.index])                                                                                                               
│     ├────────────────                                                                                                                                                              
│     │ count.index is 0                                                                                                                                                             
│                                                                                                                                                                                    
│ This value does not have any indices.                                                                                                                                                                                                                                                                                                                                    
╵                                                                                                                                                                                    
Releasing state lock. This may take a few moments...                                                                                                                                 
ERRO[0018] 1 error occurred:                                                              
        * exit status 1 

The problem seems to be at line 194 of the main.tf file in resource aws_volume_attachment and it is fixed changing line 194 from one(aws_ebs_volume.default[*].id[count.index]) to one(aws_ebs_volume.default[*].id)

Expected Behavior

Attach the EBS volume with no errors

Steps to Reproduce

Set variable ebs_volume_count to be > 0

Screenshots

No response

Environment

Additional Context

No response

shomodj commented 1 year ago

I can confirm the same issue, version 0.48 works but 0.49 this starts happening