问题描述
文件的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"
}