Terraform 抛出“groupName 不能与参数子网一起使用";或“VPC 安全组不得用于非 VPC 启动" [英] Terraform throws "groupName cannot be used with the parameter subnet" or "VPC security groups may not be used for a non-VPC launch"

查看:18
本文介绍了Terraform 抛出“groupName 不能与参数子网一起使用";或“VPC 安全组不得用于非 VPC 启动"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当试图弄清楚如何使用 AWS VPC 配置 aws_instance 时,会出现以下错误:

When trying to figure out how to configure a aws_instance with AWS VPC the following errors occur:

* Error launching source instance: InvalidParameterCombination: The parameter groupName cannot be used with the parameter subnet
    status code: 400, request id: []

* Error launching source instance: InvalidParameterCombination: VPC security groups may not be used for a non-VPC launch
    status code: 400, request id: []

推荐答案

这是由于安全组与实例的关联方式.

This is due to how a security group is associated with an instance.

如果没有子网,可以使用安全组的名称来关联它:

Without a subnet it is OK to associate it using the security group's name:

resource "aws_instance" "server" {
  ...
  security_groups = [ "${aws_security_group.my_security_group.name}" ]
}

在子网也关联的情况下,您不能使用名称,而应使用安全组的 ID:

In the case where a subnet is also associated you cannot use the name, but should instead use the security group's ID:

security_groups = [ "${aws_security_group.my_security_group.id}" ]
subnet_id = "${aws_subnet.my_subnet.id}"

以上假设您已经创建了一个名为 my_security_group 的安全组和一个名为 my_subnet

The above assumes you've created a security group named my_security_group, and a subnet named my_subnet

这篇关于Terraform 抛出“groupName 不能与参数子网一起使用";或“VPC 安全组不得用于非 VPC 启动"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆