【发布时间】:2019-08-09 08:47:17
【问题描述】:
我一直在使用 docker 容器通过 LinuxAcademy 实验室进行 terraform 工作,一切顺利。我一直将我所有的代码放到一个私人仓库中,这样我就可以参考它并将其从 linuxacademy 实验室服务器上下载到我的家庭工作站上。
我在使用 terraform 脚本创建 S3 存储桶后遇到了一个问题,这是非常简单的代码:
# Create random id
resource "random_id" "tf_bucket_id" {
byte_length = 2
}
# Create the bucket
resource "aws_s3_bucket" "tf_code" {
bucket = "${var.project_name}-${random_id.tf_bucket_id.dec}"
acl = "private"
force_destroy = true
tags {
Name = "tf_bucket"
}
}
如果我执行 terraform init,它会下载插件:
Initializing provider plugins...
- Checking for available provider plugins on https://releases.hashicorp.com...
- Downloading plugin for provider "random" (2.0.0)...
- Downloading plugin for provider "aws" (2.2.0)...
然后一个 terraform apply 成功运行代码:
random_id.tf_bucket_id: Creating...
b64: "" => "<computed>"
b64_std: "" => "<computed>"
b64_url: "" => "<computed>"
byte_length: "" => "2"
dec: "" => "<computed>"
hex: "" => "<computed>"
random_id.tf_bucket_id: Creation complete after 0s (ID: 3Ok)
aws_s3_bucket.tf_code: Creating...
acceleration_status: "" => "<computed>"
acl: "" => "private"
arn: "" => "<computed>"
bucket: "" => "la-terraform-56553"
bucket_domain_name: "" => "<computed>"
bucket_regional_domain_name: "" => "<computed>"
force_destroy: "" => "true"
hosted_zone_id: "" => "<computed>"
region: "" => "<computed>"
request_payer: "" => "<computed>"
tags.%: "" => "1"
tags.Name: "" => "tf_bucket"
versioning.#: "" => "<computed>"
website_domain: "" => "<computed>"
website_endpoint: "" => "<computed>"
aws_s3_bucket.tf_code: Creation complete after 5s (ID: la-terraform-56553)
Apply complete! Resources: 2 added, 0 changed, 0 destroyed.
Outputs:
bucket_name = la-terraform-56553
这就是问题所在,如果我提交更改,git 想要提交 .terraform/plugins 目录以及插件本身。但是插件太大了 git 无法处理,所以我得到了这个错误:
terraform@foobarserver:~/repos/private/terraform$ git push
Counting objects: 13, done.
Compressing objects: 100% (10/10), done.
Writing objects: 100% (13/13), 28.65 MiB | 1.68 MiB/s, done.
Total 13 (delta 3), reused 0 (delta 0)
remote: Resolving deltas: 100% (3/3), completed with 3 local objects.
remote: error: GH001: Large files detected. You may want to try Git Large File Storage - https://git-lfs.github.com.
remote: error: Trace: c7cf151dfa233bfff86c3191eb63b5d9
remote: error: See http://git.io/iEPt8g for more information.
remote: error: File terraform/aws/LA_project/storage/.terraform/plugins/linux_amd64/terraform-provider-aws_v2.2.0_x4 is 111.33 MB; this exceeds GitHub's file size limit of 100.00 MB
To git@github.com:foobaruser/private.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'git@github.com:foobaruser/private.git'
我终其一生都无法弄清楚如何让 git 忽略插件。我尝试添加一个带有明确列出目录的 gitignore 文件,但是当我运行“git status”时该目录仍然出现。我正在撕扯我的头发,因为我在使用 bitbucket 的工作中没有这个问题,如果 terraform 自动下载这样的插件,其他人如何在 git 中使用 terraform 而没有大量的大型插件文件?
编辑 非常感谢下面的评论员,不知怎的,我在所有 terraform 安装和更新过程中都错过了这一点。在我的根 terraform 目录中安装了 stock .gitignore 文件,瞧,没有更多问题了。非常感谢!
【问题讨论】:
标签: git amazon-web-services github terraform terraform-provider-aws