1
votes

I've been working through a LinuxAcademy lab for terraform using docker containers, which has all been going fine. I've been putting all my code into a private repo so I can refer to it and pull it down onto my home workstation off the linuxacademy lab servers.

I've run into an issue after creating an S3 bucket using a terraform script, it's pretty simple code:

# 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"
  }
}

If I do a terraform init it downloads the plugins:

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)...

And a terraform apply runs the code successfully:

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

Here's the problem, if I go to commit the changes git wants to commit the .terraform/plugins directory, along with the plugins themselves. But the plugins are too big for git to handle, so I get this error:

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 [email protected]:foobaruser/private.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to '[email protected]:foobaruser/private.git'

I cannot for the life of me figure out how to get git to ignore the plugins. I have tried adding a gitignore file with the directory explictly listed, but the directory still appears when I run "git status". I'm tearing my hair out as I don't have this issue at work where we use bitbucket, if terraform automatically downloads the plugins like this how are other people using terraform in git without masses of large plugin files everywhere?

edit Thank you SO much to the commentator below, somehow I'd missed that in all the terraform installation and update process. Installed the stock .gitignore file in my root terraform directory and voila, no more issues. Much appreciated!

1

1 Answers

1
votes

I've always used the .gitignore file generated by gitignore.io/api/terraform - give that a shot and see if it helps.

Make sure you commit and push your updated .gitignore file first before trying git status and making a separate commit for the rest of your files.