VS工作室中的地形代码不起作用



我试图在我的代码中找到错误。当我做地形应用时,它给了我错误....

错误:不支持的参数

在 Jenkins yourself.tf 第 9 行,在资源"AWS 安全组"Web-Node"中:

9:VPC 安全组 ID = ["####

此处不需要名为"VPC 安全group_ids"的参数。

错误:属性值类型不正确

在 Jenkins 自己第 10 行,在资源"AWS 安全组"Web-Node"中:

属性"标签"的值不合适:元素"security_groups":字符串 必填。 错误:不支持的块类型 在 Jenkins 自己第 39 行,在资源"AWS 安全组"Web-Node"中 39: 资源 "ec2 实例" "EC2Terraform" {

此处不应使用"资源"类型的块。

provider "aws"  {
access_key = "access key"
secret_key = "secret key"
region = "us-east-1"
}
#resource Configuration for AWS
resource "aws_security_group" "web-node" {
vpc_security_group_ids = ["sg-############"]
tags = {
name = "Week4 Node"
description = "My Security Group"
security_groups = ["${aws_security_group.web-node.name}"]
}
ingress {
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}    
ingress {
from_port = 443
to_port = 443
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}    
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr blocks = ["0.0.0.0/0"]
}
resource "ec2 instance" "EC2Terraform" {
ami = "ami-01d025118d8e760db"
instance_type = "t2.micro"
key_name ="XXXXXXXXXX"
vpc security group ids = ["##################"]
tags = {
Name = "My Jenkins " 
}
}
}

代码片段中存在一些错误。资源aws_security_group不接受名为vpc_security_group_ids的参数,如 Terraform 文档所示。您正在定义一个 AWS 安全组,您根本不需要提供任何security_group ID,您可以做的是引用该安全组的idaws_security_group.web-node.id。尝试这样的事情:

provider "aws" {
access_key = "access key"
secret_key = "secret key"
region     = "us-east-1"
}
#resource Configuration for AWS
resource "aws_security_group" "web-node" {
name        = "Week4 Node"
description = "My Security Group"
ingress {
from_port   = 80
to_port     = 80
protocol    = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
from_port   = 22
to_port     = 22
protocol    = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
from_port   = 443
to_port     = 443
protocol    = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
egress {
from_port   = 0
to_port     = 0
protocol    = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
resource "aws_instance" "ec2terraform" {
ami                     = "ami-01d025118d8e760db"
instance_type           = "t2.micro"
key_name                = "XXXXXXXXXX"
vpc_security_groups_ids = [aws_security_group.web-node.id]
tags = {
Name = "My Jenkins "
}
}

相关内容

  • 没有找到相关文章

最新更新