Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] add a Terraform module interface #73

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

displague
Copy link
Member

@displague displague commented Aug 11, 2020

This experimental branch adds a terraform module interface to packet-cli.
The goal of this is to make it easier to consume Packet provider modules from the official Terraform registry.

Only github.com/packethost and github.com/packet-labs modules would be considered.

_Update: Only the Equinix Metal provider and Equinix modules would be considered)

Current blockers

  • Hashicorp/terraform does not expose a "modules list" function.

Considerations

  • This adds a ton of dependency. Can packet terraform be built as an independent plugin through a plugin interface (like git plugins)? (possibly a shell script?)

Future workflow

Examples of use:

list all Packet modules

$ packet terraform get

show module details

The registry API includes the parameters of the module.

$ packet terraform get kubernetes-bgp
+----------------+---------+
|     SOURCE     | VERSION |
+----------------+---------+
| kubernetes-bgp | 0.0.1   |
+----------------+---------+

create an instance of that module

These module parameters could be exposed as arguments.

This would effectively perform terraform init --from-module=packet/k8s/packet.
What directory would this go in? Should the base directory be common - and pass workspace through? (Likening this to go get, this would be like go get registry/module@workspace)

The api token would be wired-up, since the packet cli already knows one. How does it do this? Well known APIKey / Token variable names?

$ packet terraform create k8s --workspace foo --facility ewr1

@displague displague added the enhancement New feature or request label Aug 11, 2020
@displague
Copy link
Member Author

Hashicorp/terraform does not expose a "modules list" function.

Depite the limitations from https://github.com/hashicorp/terraform/tree/main/internal/initwd not being public, there are several workarounds:

  • don't list modules, take whatever parameters are supplied and assume that equinix/$1/metal is a valid module. take all -- arguments that are not recognized and produce a terraform.tfvars with these values
  • bundle the terraform plugin with known module help scripts, each can validate the parameters to the variables supported by the module. Each script can also translate packet-cli variables (token) to the name of the variable in each specific module (metal_auth_token, auth_token, etc).

@displague
Copy link
Member Author

@ctreatma found https://github.com/hashicorp/terraform-config-inspect which may be a suitable workaround for the https://github.com/hashicorp/terraform/tree/main/internal/initwd concerns mentioned above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant