【问题标题】:Terraform - getting terraform_remote_state leads to access deniedTerraform - 获取 terraform_remote_state 导致访问被拒绝
【发布时间】:2021-10-14 10:08:55
【问题描述】:

我有 2 个模块 ..启动了一个 VPC 并添加了一些 s3 存储桶,输出保存在 s3 中。然后我添加了另一个模块重新初始化然后尝试计划

新模块如下所示。我需要使用数据来获取 vpc_id。

    provider "aws" {
  region                  = var.region
  shared_credentials_file = "$HOME/.aws/credentials"
  profile                 = "terraform"
}

terraform {
  backend "s3" {
    profile = "terraform"
    bucket = var.remote_state_bucket
    key    = var.remote_state_key
    region = var.region
  }
}

data "terraform_remote_state" "network_configuration" {
  backend = "s3"
  config = {
   bucket = var.remote_state_bucket
    key    = var.remote_state_key
    region = var.region
  }
}

当我跑步时

 terraform plan -var-file="test.tfvars"

由于 terraform_remote_state 块,我收到以下错误。我删除然后计划有效。

Error: AccessDenied: Access Denied
    status code: 403, request id: ZRTM92CVDQFRBF9T, host id: 0HYGuPq9Q7skZLtXvdR3mD6657g4fqUaQQNf2jP2GRcLx1vTxkYhFtyKAiTTLRBrEwECnPf0Y9A=

为什么?我不明白?我该如何解决?

【问题讨论】:

  • 您能否将profile = "terraform" 添加到您的terraform_remote_state 配置中。

标签: amazon-web-services terraform terraform-provider-aws


【解决方案1】:

您应该将profile 添加到您的config

data "terraform_remote_state" "network_configuration" {
  backend = "s3"
  config = {
   bucket   = var.remote_state_bucket
    key     = var.remote_state_key
    region  = var.region
    profile = "terraform"
  }
}

【讨论】:

    猜你喜欢
    • 2020-05-19
    • 2021-01-31
    • 2012-07-10
    • 2022-08-10
    • 2015-12-08
    • 1970-01-01
    • 1970-01-01
    • 2018-09-01
    • 2016-03-09
    相关资源
    最近更新 更多