gpt4 book ai didi

amazon-web-services - 如何在 Terraform 中修复 "No default VPC for this user, status code: 400"?

转载 作者:行者123 更新时间:2023-12-05 00:55:49 25 4
gpt4 key购买 nike

我正在尝试修复这段代码,我想创建堡垒主机,但我收到:错误:应用计划时出错:

发生 1 个错误:* aws_instance.bastion:发生 1 个错误:* aws_instance.bastion:启动源实例时出错:VPCIdNotSpecified:此用户没有默认 VPC状态码:400,请求ID:daf3dd12-d7c4-469a-9be5-3707c0490c2a

我正在使用 Terraform 0.11

代码:

resource "aws_vpc" "main" {
cidr_block = "${var.main_vpc_cidr}"
instance_tenancy = "default"
enable_dns_support = true
enable_dns_hostnames = true

tags {
Name = "main"
}
}


resource "aws_subnet" "subnet1" {
vpc_id = "${aws_vpc.main.id}"
cidr_block = "10.0.1.0/24"
availability_zone = "${var.availability_zone1}"


tags {
Name = "app-subnet-1"
}
}



########## Create bastion host ######

##resource "aws_default_vpc" "default" {}

resource "aws_instance" "bastion" {

ami = "ami-0fdc6293d3e87a86e"
key_name = "${aws_key_pair.bastion_key.key_name}"
instance_type = "t2.micro"
security_groups = ["${aws_security_group.bastion-sg.name}"]
associate_public_ip_address = true

}

resource "aws_security_group" "bastion-sg" {
name = "bastion-security-group"
vpc_id = "${aws_vpc.main.id}"

ingress {
protocol = "tcp"
from_port = 22
to_port = 22
cidr_blocks = ["0.0.0.0/0"]
}

egress {
protocol = -1
from_port = 0
to_port = 0
cidr_blocks = ["0.0.0.0/0"]
}
}

resource "aws_key_pair" "bastion_key" {
key_name = "your_key_name"
public_key = "ssh-rsa AAA

output "bastion_public_ip" {
value = "${aws_instance.bastion.public_ip}"
}

variables.tf 文件:

variable "aws_access_key" {}
variable "aws_secret_key" {}

variable "aws_region" {
description = "EC2 Region for the VPC"
default = "eu-west-1"
}
variable "availability_zone1" {
description = "Avaialbility Zones"
default = "eu-west-1a"
}

variable "availability_zone2" {
description = "Avaialbility Zones"
default = "eu-west-1b"
}
variable "main_vpc_cidr" {
description = "CIDR of the VPC"
default = "10.0.0.0/16"
}

最佳答案

如果您只想让默认 VPC 运行,并且可以选择使用 AWS CLI,这对我有用:

aws ec2 create-default-vpc

引用:AWS Docs - Default VPC and default subnets

关于amazon-web-services - 如何在 Terraform 中修复 "No default VPC for this user, status code: 400"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63441544/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com