Terraform module registry with GCS bucket as a storage backend
We chose to configure the server only with envars, easy to set in a pod
PORT
: port to listen to, default8080
LISTEN
: accepted IP range, default0.0.0.0
BACKEND
: storage backend to use,gcs
orfake
, defaultgcs
OVERWRITE
: accepts to overwrite existing modules with same version, default0
VERBOSE
: debug logs, default0
MODULE_PATH
: default ""GOOGLE_BUCKET
: name of the GCS bucket to use. Mandatory is backend isgcp
curl localhost:8080/test/mymodule/gcp/versions
To create the module v0.0.2 from local tar.gz
curl -X POST --data-binary "@myfile.tar.gz" localhost:8080/test/mymodule/gcp/0.0.2 -H "module-source: https://whatever.com/wherever.git"
curl localhost:8080/test/mymodule/gcp
If you need to change the API, you have to install oapi-codegen
to generate code
go get github.com/deepmap/oapi-codegen/cmd/oapi-codegen
make generate
This generates the file pkg/modules/modules.gen.go
We build and push the image using ko
from Google
go install github.com/google/ko
make push
You can change the repository by overriding the variable IMAGE_REPOSITORY
make KO_DOCKER_REPO=wherever.com/whatever build
A test bucklet has been created in ml-calleocho-st
project.
Retrieve the JSON file in https://vault.magicleap.io/ui/vault/secrets/ci/show/sre/tfregistry/gcp_authent
Then
export GOOGLE_APPLICATION_CREDENTIALS=path/to/file.json
export GOOGLE_BUCKET=ml-test-modules-registry
export MODULE_PATH=/
make server
In another window :
curl -v localhost:8080/test/mymodule/gcp/versions
A fake
server is also available to test without having to connect to GCP. It is used for unit testing