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

Include droplet gateway metadata in digitalocean_droplet resource and data returned attributes #1097

Open
tlowerison opened this issue Dec 20, 2023 · 2 comments
Labels
do-api Depends on changes to the DigitalOcean API

Comments

@tlowerison
Copy link

tlowerison commented Dec 20, 2023

Is your feature request related to a problem? Please describe.

I'd like to programmatically integrate a droplet configured as an internet gateway with k8s-staticroute-operator. I believe it'd be generally useful information and would possibly move progress along towards automatically provisioned internet gateways being a thing on Digital Ocean if droplet metadata, specifically the initial droplet gateway was accessible through terraform.

Describe the solution you'd like

Ideally, a metadata or some appropriately named attribute be returned from the digitalocean_droplet resource and data sources, which contains at least the droplet's configured gateway.

Describe alternatives you've considered

Adding an init-script or similar field to the digitalocean_kubernetes_node_pool arguments for initial node configuration.

@tlowerison tlowerison changed the title Include droplet metadata in digitalocean_droplet resource and data returned attributes Include droplet gateway metadata in digitalocean_droplet resource and data returned attributes Dec 20, 2023
@andrewsomething andrewsomething added the do-api Depends on changes to the DigitalOcean API label Dec 20, 2023
@andrewsomething
Copy link
Member

Hi @tlowerison,

Thanks for the suggestion. I definitely see how this would be useful. Though I'm not sure it is something we can accommodate in Terraform at the moment. The Droplet metadata API is only accessible from the Droplet itself. We'd need the information to be included in the public API.

Using a remote-exec provisioner, you could access the metadata API, but there is not currently an officially supported way to export data from a provisioner. Unfortunately this is not something HashiCorp is prioritizing: hashicorp/terraform#610

There is an interesting third-party SSH provider that I've seen used to achieve something similar:

https://registry.terraform.io/providers/loafoe/ssh/latest/docs

For example, this SSHs to the Droplet, calls the metadata API, and makes the result available for interpolation:

resource "digitalocean_droplet" "example" {
  image    = "ubuntu-20-04-x64"
  name     = "example-01"
  region   = "nyc1"
  size     = "s-1vcpu-1gb"
  ssh_keys = [123456]
}

resource "ssh_resource" "example" {
  host  = digitalocean_droplet.example.ipv4_address
  user  = "root"
  agent = true

  commands = [
    "curl http://169.254.169.254/metadata/v1.json",
  ]
}

output "result" {
  value = try(jsondecode(ssh_resource.example.result).interfaces, {})
}

The output includes all the network information from the metadata API.

@aanderse
Copy link

aanderse commented Mar 2, 2024

i was looking over the api usage in this codebase and noticed that network is available which has some useful information, including gateway. the addition of the network data would be super useful and was also requested here.

any chance if this making it into the terraform provider?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
do-api Depends on changes to the DigitalOcean API
Projects
None yet
Development

No branches or pull requests

3 participants