Chr*_*s F 4 terraform terraform-provider-aws
我稍后会更新,但现在...
$ terraform --version
Terraform v0.12.17
+ provider.aws v3.23.0
Run Code Online (Sandbox Code Playgroud)
./aws/credentials我在我的和文件中设置了 AWS 配置文件~/.aws/config,就像这样......
~/.aws/credentials
[default]
aws_access_key_id=****
aws_secret_access_key=****
[myprofile]
aws_access_key_id=****
aws_secret_access_key=****
~/.aws/config
[default]
region=us-east-1
output=json
[profile myprofile]
region=us-east-1
output=json
Run Code Online (Sandbox Code Playgroud)
在我的 Terraform 计划中,我有
provider "aws" {
region = "us-east-1"
profile = "myprofile"
}
terraform {
required_version = ">= 0.12.17, < 0.13"
}
resource "aws_vpc" "vpc" {
cidr_block = "10.123.123.0/24"
tags = {
Name = "test_vpc"
}
}
output "vpc_id" {
value = aws_vpc.vpc.id
}
Run Code Online (Sandbox Code Playgroud)
我有一个创建 VPC 的计划,所以我这样做了
$ export AWS_PROFILE=myprofile
$ terraform apply
Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
Outputs:
module_vpc_id = vpc-123456abced
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,该计划创建了 VPC,但是,VPC 不是在账户中创建的,myprofile而是在default账户中创建的。我知道这一点,因为 1)我在帐户中没有看到它myprofile,2)当我销毁计划时,它显示owner_id为default帐号。为什么?
更新:请注意,如果我在块中添加access_key和secret_key键/值对provider {},它会在正确的帐户中创建 VPC。当然我不想这样做,只是想证明该脚本确实适用于该myprofile帐户。
更新:请注意以下命令不返回任何内容(空白)
$ echo $AWS_ACCESS_KEY_ID
$ echo $AWS_SECRET_ACCESS_KEY
Run Code Online (Sandbox Code Playgroud)
并且运行env不会显示这些变量。
根据评论。
该问题是由于AWS_PROFILE设置了 env 变量而引起的。根据TF 文档,该变量具有更高的优先级Shared credentials/configuration file:
| 归档时间: |
|
| 查看次数: |
8110 次 |
| 最近记录: |