我的基本Terraform无法运行terraform plan的原因是什么?

huangapple go评论59阅读模式
英文:

why my basic terraform fails to run terraform plan?

问题

我有这个非常基本的Terraform文件:main.tf

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 4.16"
    }
  }

  required_version = ">= 1.2.0"
}

provider "aws" {
    profile = "default"
}

resource "aws_s3_bucket" "test-bucket-terraform-regergjegreg" {
  bucket = "test-bucket-terraform-regergjegreg"

  tags = {
    Name        = "My bucket"
    Environment = "Dev"
  }
}

在运行 terraform validate 时,我没有错误:

Success! The configuration is valid.

现在当我运行 terraform plan 时,我收到了这个错误:

Planning failed. Terraform encountered an error while generating this plan.

│ Error: configuring Terraform AWS Provider: credential type source_profile requires role_arn, profile default
│   with provider["registry.terraform.io/hashicorp/aws"],
│   on main.tf line 12, in provider "aws":
│   12: provider "aws" {

这是我的Terraform版本:

Terraform v1.4.6
on darwin_amd64
+ provider registry.terraform.io/hashicorp/aws v3.76.1

默认配置文件存在于我的 ~/.aws/credentials~/.aws/config 中。

不太确定问题出在哪里。感谢任何帮助。谢谢。

英文:

I have this very basic terraform file: main.tf

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 4.16"
    }
  }

  required_version = ">= 1.2.0"
}

provider "aws" {
    profile = "default"
}

resource "aws_s3_bucket" "test-bucket-terraform-regergjegreg" {
  bucket = "test-bucket-terraform-regergjegreg"

  tags = {
    Name        = "My bucket"
    Environment = "Dev"
  }
}

when doing terraform validate, I have no error:
Success! The configuration is valid.

Now when I do terraform plan, I got this error:

Planning failed. Terraform encountered an error while generating this plan.

╷
│ Error: configuring Terraform AWS Provider: credential type source_profile requires role_arn, profile default
│ 
│   with provider["registry.terraform.io/hashicorp/aws"],
│   on main.tf line 12, in provider "aws":
│   12: provider "aws" {
│ 
╵

Here is my terraform version:

Terraform v1.4.6
on darwin_amd64
+ provider registry.terraform.io/hashicorp/aws v3.76.1

the default profile exists in my /.aws/credentials and /.aws/config

Not sure what could be wrong really. Any help is appreciated. thanks

答案1

得分: 1

好的,我解决了这个问题。
我的问题不在凭证文件中,而在配置文件中。
出于某种原因,我有这个:

[default]
output = json
region = eu-west-1
source_profile = default

删除source_profile使其正常工作。

英文:

Ok, I resolved the issue.
My problem was not in credentials file but in config.
For some reason I had this:

[default]
output = json
region = eu-west-1
source_profile = default

removing source_profile makes it work.

huangapple
  • 本文由 发表于 2023年6月2日 03:45:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/76385226.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定