-
Notifications
You must be signed in to change notification settings - Fork 46
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
feat: Output terraform format #147
base: main
Are you sure you want to change the base?
Conversation
83fa2a5
to
de58436
Compare
Noting that Crossplane format offered could follow that presented by the Jet provider: https://github.com/crossplane-contrib/provider-tf-equinix-metal |
I'm going to use this stub to catalog some alternatives (even if they are currently unaware of Equinix resource types): |
Another tool in a similar spirit: https://techcommunity.microsoft.com/t5/azure-tools-blog/announcing-azure-terrafy-and-azapi-terraform-provider-previews/ba-p/3270937 |
Yes another tool that will generate Terraform from existing state: |
This should be updated to use the equinix Terraform provider and the Terraform generated Crossplane provider. |
de58436
to
0eaf348
Compare
0eaf348
to
0633c2e
Compare
0633c2e
to
b64d055
Compare
The Terraform import lines can now be expressed as Perhaps the output format should allow users to take advantage of this feature in a few ways. Metal CLI could offer this as an option, |
16afc28
to
e74db36
Compare
Signed-off-by: Marques Johansson <[email protected]>
…ort) Signed-off-by: Marques Johansson <[email protected]>
…vice Signed-off-by: ocobleseqx <[email protected]>
e74db36
to
e0da308
Compare
Signed-off-by: Chris Privitere <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This branch should probably be marked draft.
The terraform output function works (as in, they output text to the screen, didn't test for validity upon import).
The crossplane function does not work. Even after converting things to equinix-sdk-go, i still get this error:
Error: template: crossplane:8:35: executing "crossplane" at <.ID>: can't evaluate field ID in type metalv1.Device
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This branch should probably be marked draft.
The terraform output function works (as in, outputs text to the screen, didn't test for validity upon import).
The crossplane function does not work. Even after converting things to equinix-sdk-go, i still get this error:
Error: template: crossplane:8:35: executing "crossplane" at <.ID>: can't evaluate field ID in type metalv1.Device
Signed-off-by: Chris Privitere <[email protected]>
The import format can be improved with Terraform v1.5.0+ import {
to = equinix_metal_device.example
id = "abcd1234"
} This PR does not introduce that format. It uses a comment block today. This format could also handle list endpoints (again, not implemented in the PR): locals {
metal_devices = {
"hostnamea" = "uuid-a"
"hostnameb" = "uuid-b"
"hostnamec" = "uuid-c"
}
}
import {
for_each = local.metal_devices
to = equinix_metal_device.devices[each.key]
id = each.value
}
resource "equinix_metal_device" "devices" {
for_each = local.metal_devices
} |
This is a demonstration of how the Metal CLI can offer a Terraform output format for each supported resource type.
In this PR, since devices and device lists are translated into the most primitive Terraform HCL snippet, accompanied by the
terraform import
command needed to fetch the state of the configured resource.The same pattern could be used to offer Crossplane and Ansible resources, among others.
An elaborate use-case to consider is fetching a project, but rather than getting the single project resource, getting all objects contained within that project as HCL. The
--output
argument in that case may need sub-options (--output=tf,deep
)The hinted argument,
deep
, would walk all descendent resources.metal project get -i $PROJECT_ID -o tf,deep
, for example, would generate TF config for the project, devices, IPs, VLANs, etc.All devices in the project
A single devices in the project
Crossplane Format
The same single and multiple listing support can be used to emit Crossplane configuration. With Crossplane, the controller will synchronize the EM API settings, so only the UUID (as external-name) must be set in the resource.
See https://github.com/crossplane-contrib/provider-equinix-metal#install-the-equinix-metal-provider for more details about the EM Crossplane provider and https://crossplane.io/docs/v1.3/concepts/managed-resources.html for details on using Managed resources in Crossplane.
The utility this support would bring to the
metal-cli
has similar gains to the proposal for acrossplane import
tool: crossplane/crossplane-cli#66.