首页 > 解决方案 > Terraform 在配置 S3 后端时出错

问题描述

尝试将我的状态文件存储在 s3 存储桶中,但在尝试“Terraform init”时出现此错误:

error configuring S3 Backend: error validating provider credentials: 
error calling sts:GetCallerIdentity: 
InvalidClientTokenId: The security token included in the request is invalid.

主文件:

provider "aws" {
  region     = var.region
  access_key = var.acc_key
  secret_key = var.sec_key
}

terraform {
  backend "s3" {
    bucket         = "mybucket-terra-prac"
    key            = "terraform.tfstate"
    region         = "eu-central-1"
  }
}
resource "aws_instance" "web" {
  ami           = var.ami
  instance_type = "t2.large"
  associate_public_ip_address=true
  key_name = var.public_key
  tags = {
    Name = var.ec2_name
  }
}

我在 variables.tf 文件中的变量(具有类型和默认值):

variable "acc_key" {}
variable "sec_key" {}
variable "public_key" {}
variable "ami" {}

标签: amazon-web-servicesamazon-s3terraformterraform-provider-aws

解决方案


尝试执行aws sts get-caller-identity命令,看看您使用的是正确的凭据。


推荐阅读