Skip to content

Fails to create EC2 when ami variable is defined #352

Closed
@Zonny

Description

@Zonny

Hello,

I am recently trying to use this module and ran into this issue

 Error: Missing required argument
 
   with module.mattermost_standalone_ecs_instance.aws_instance.this[0],
   on .terraform/modules/mattermost_standalone_ecs_instance/main.tf line 22, in resource "aws_instance" "this":
   22:   ami                  = try(coalesce(var.ami, nonsensitive(data.aws_ssm_parameter.this[0].value)), null)
 
 "ami": one of `ami,launch_template` must be specified

It seems like it might be due to merging this PR. The reason I believe is that the ami variable is always getting set to null because data.aws_ssm_parameter.this[0].value cannot be referenced. I removed the try block locally and get this error message

 Error: Invalid index
 
   on .terraform/modules/mattermost_standalone_ecs_instance/main.tf line 22, in resource "aws_instance" "this":
   22:   ami                  = coalesce(var.ami, nonsensitive(data.aws_ssm_parameter.this[0].value))
     ├────────────────
     │ data.aws_ssm_parameter.this is empty tuple
 
 The given key does not identify an element in this collection value: the collection has no elements.

I opened up a PR to address the issue. Let me know if it is acceptable or if changes will need to be required

Originally posted by @Zonny in #351 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions