【问题标题】:The terraform init command is failing in my .tf fileterraform init 命令在我的 .tf 文件中失败
【发布时间】:2020-12-18 05:06:44
【问题描述】:

文件的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"
}

发出“terraform init”命令后得到的ERROR MESSAGES

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"

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

【问题讨论】:

  • 这一次,当我从“资源”块中删除“提供者”时,我得到了这个:初始化后端...正在初始化提供者插件... - 查找最新版本的 hashcorp/aws...错误:无法查询可用提供程序包无法检索提供程序 hashcorp/aws 的可用版本列表:无法连接到 registry.terraform.io:无法请求发现文档:获取“registry.terraform.io/.well-known/terraform.json”:读取 tcp >:51717->>:443: wsarecv: 现有连接被远程主机强行关闭。

标签: terraform terraform-provider-aws


【解决方案1】:

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

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

删除提供者:

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

【讨论】:

  • 将“terraform-provider-aws_v3.5.0_x5.exe”与“terraform_0.12.0_windows_amd64”一起使用。 “terraform init”命令运行良好,但“terraform plan”命令给出错误 - 错误:配置 Terraform AWS 提供者时出错:验证提供者凭据时出错:调用 sts:GetCallerIdentity: RequestError: 发送请求失败,原因是:发布“@987654321 @": read tcp >:56837->>:443: wsarecv: 现有连接被远程主机强行关闭。
  • 我浏览了github.com/terraform-providers/terraform-provider-aws/issues/…,但无法正确理解。我不知道FIX是否在那里。
  • 您似乎需要设置用于 terraform 的帐户,以使用正确的角色/策略访问 AWS
  • 文章github.com/terraform-providers/terraform-provider-aws/issues/…够好吗?也请参考一些链接
  • 谢谢彼得,我将再次生成凭据并更新您。
猜你喜欢
  • 2022-07-01
  • 1970-01-01
  • 2018-10-15
  • 2017-11-12
  • 2019-04-18
  • 1970-01-01
  • 2018-05-22
  • 2020-05-18
  • 2020-08-15
相关资源
最近更新 更多