微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

我的.tf文件中的terraform init命令失败

如何解决我的.tf文件中的terraform init命令失败

文件terraform代码-“ myec2.tf”

provider "aws" {
  region     = "eu-west-1"
  access_key = "<<access key id>>"
  secret_key = "<<secret key id>>"
}

# chosen from the RESOURCE section in terraform 'Provider' section
resource "aws_instance" "terra_ec2" {
    ami = "ami-07d9160fa81ccffb5"
    instance_type = "t2.micro"
    provider = "https://registry.terraform.io/hashicorp/aws"
}

发出“ terrain init”命令后获得的错误消息

There are some problems with the configuration,described below.

The terraform configuration must be valid before initialization so that
terraform can determine which modules and providers need to be installed.

Warning: Quoted references are deprecated

  on first_ec2.tf line 11,in resource "aws_instance" "terra_ec2":
  11:     provider = "https://registry.terraform.io/hashicorp/aws"

In this context,references are expected literally rather than in quotes.
terraform 0.11 and earlier required quotes,but quoted references are Now
deprecated and will be removed in a future version of terraform. Remove the
quotes surrounding this reference to silence this warning.


Error: Invalid character

  on first_ec2.tf line 11,in resource "aws_instance" "terra_ec2":
  11:     provider = "https://registry.terraform.io/hashicorp/aws"

期望属性访问或索引运算符。

解决方法

您已经在Terraform代码中设置了provider

您不需要资源中的提供者密钥。

删除提供者:

resource "aws_instance" "terra_ec2" {
    ami = "ami-07d9160fa81ccffb5"
    instance_type = "t2.micro"
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。