I am receiving an error while creating aws_launch_template
using Terraform, below the error message
I am using an existing Role which is pre-created in the account
Error message – An argument named "iam_instance_profile" is not expected here. Did you mean to define a block of type "iam_instance_profile"?
Code
data "aws_iam_roles" "seamless_domain_join_role" {
name = "seamless-domain-join-role"
}
data "aws_iam_instance_profile" "autoscale-instance-profile" {
name = "seamless-domain-join-role"
}
resource "aws_launch_template" "Windows-instance" {
name_prefix = "Windows_Instance"
image_id = "ami-0526b9747c2c87a0b"
iam_instance_profile = {
arn = data.aws_iam_instance_profile.autoscale-instance-profile.arn
}
instance_type = "t2.medium"
tag_specifications {
resource_type = "instance"
tags = {
Name : "sk-autoscaling-dj"
}
}
}
I am receiving same error with **name ** as well.
iam_instance_profile = {
name= data.aws_iam_instance_profile.autoscale-instance-profile.name
}
Any suggestions will be appreciated.
Any suggestions on how to fix this issue?
2
Answers
You don’t need the
=
sign as that is a block not an argument:This should really be clear from the provider documentation for
aws_launch_template
resource [1].[1] https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/launch_template#example-usage
I see two mistakes in the code-
It should be
aws_iam_role
, rather thanaws_iam_roles
.It doesn’t need a
=
as its a block.The correct code is –
terraform validate
Success! The configuration is valid.