GoogleCloudPlatform/cloud-foundation-fabric

fast/extras/0-cicd-github creates corrupted PNG (base 64 encoded content)

lyricnz opened this issue · 9 comments

Describe the bug

Applying fast/extras/0-cicd-github creates corrupted PNG output and ultimately fails with error.

Environment

❯ terraform -version
Terraform v1.5.6
on darwin_amd64

Also tried with opentofu (same result)

❯ tofu --version
OpenTofu v1.8.1
on darwin_amd64
❯ git rev-parse --short HEAD
0420dec3

To Reproduce
Create a tfvars with any repo:

repositories = {
  fast_00_bootstrap = {
    create_options = {
      description = "FAST bootstrap."
      features = {
        issues = true
      }
    }
    populate_from = "../../stages/0-bootstrap"
  }

Execute: terraform init + apply

Look at PNG in the output - they are base64 encoded text, not the original binary content.

Expected behavior
Files in the new repos to be intact, and mostly identical to the original.

Result
Terraform output and/or error messages

github_repository_file.default["fast_02_networking/IAM.md"]: Creation complete after 36s [id=fast_02_networking/IAM.md]
github_repository_file.default["fast_00_bootstrap/IAM.md"]: Creation complete after 35s [id=fast_00_bootstrap/IAM.md]
github_repository_file.default["fast_01_resman/outputs-gcs.tf"]: Creation complete after 36s [id=fast_01_resman/outputs-gcs.tf]
github_repository_file.default["fast_00_bootstrap/variables.tf"]: Creation complete after 36s [id=fast_00_bootstrap/variables.tf]
github_repository_file.default["fast_00_bootstrap/diagram.png"]: Creation complete after 36s [id=fast_00_bootstrap/diagram.png]
github_repository_file.default["fast_00_bootstrap/outputs.tf"]: Creation complete after 36s [id=fast_00_bootstrap/outputs.tf]
╷
│ Error: unsupported content encoding: none
│
│   with github_repository_file.default["fast_02_networking/diagram-ncc.png"],
│   on main.tf line 159, in resource "github_repository_file" "default":
│  159: resource "github_repository_file" "default" {
│
╵

Additional context
Add any other context about the problem here

I can't see how https://registry.terraform.io/providers/integrations/github/latest/docs/resources/repository_file actually supports uploading a binary file (there's no flag to let it know that the content is base64 encoded).

This commit totally doesn't work (for me)
a514ce0#diff-75d6741a4ff5654842d3a983ac5376d3485db0914e89f004825fda996162c569
@jayBana

My guess is that the actual error message comes from around here.

But due how the code looks as of now you should not get this exact message. This suggests that you use v5.43.0 or earlier of github provider. Is this the case? Can you try with newer version?

My last attempt was with opentofu:

❯ tofu --version
OpenTofu v1.8.1
on darwin_amd64
+ provider registry.opentofu.org/hashicorp/tls v4.0.5
+ provider registry.opentofu.org/integrations/github v4.31.0

PS: it "works fine" if I comment out the *.png line in main.tf - but obviously doesn't include those files in the output repo.

Will reinstall terraform, and see which version it installed. Sec.

Even with latest terraform, and running terraform init it installed that old version:

❯ terraform --version
Terraform v1.9.4
on darwin_amd64
+ provider registry.terraform.io/hashicorp/tls v4.0.5
+ provider registry.terraform.io/integrations/github v4.31.0

Updating required_providers to "~> 6.0"

❯ terraform --version
Terraform v1.9.4
on darwin_amd64
+ provider registry.terraform.io/hashicorp/tls v4.0.5
+ provider registry.terraform.io/integrations/github v6.2.3

Then applying the stock terraform, I didn't get any error, but the PNG is still corrupt:

image

Given there seems to be little to fix on our side, can we close this issue?

Maybe it would be worth it to mention this in the stage README, what do you think?

Yes, documenting "this process will corrupt any binary files, including PNG". In the alternative, maybe a non-terraform solution would work better?