You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Terraform创建aws_launch_template时遇iam_instance_profile参数错误

解决Terraform aws_launch_template的iam_instance_profile错误

错误原因

你遇到的错误核心是:iam_instance_profile在aws_launch_template资源中是嵌套块结构,而非顶层属性参数,不能用iam_instance_profile = {...}这种键值对赋值的写法,必须以块的形式声明。

修正后的配置代码

使用ARN的正确写法

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"
  instance_type = "t2.medium"

  # 改为块形式声明iam_instance_profile
  iam_instance_profile {
    arn = data.aws_iam_instance_profile.autoscale-instance-profile.arn
  }

  tag_specifications {
    resource_type = "instance"
    tags = {
      Name = "sk-autoscaling-dj"
    }
  }
}

使用名称的正确写法

如果想用实例配置文件名称,同样改成块结构:

iam_instance_profile {
  name = data.aws_iam_instance_profile.autoscale-instance-profile.name
}

额外优化

你定义的data "aws_iam_roles" "seamless_domain_join_role"没有在后续配置中使用,可以直接删除,减少不必要的资源查询。

内容的提问来源于stack exchange,提问作者Sandeep SK

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.14 20:41:08