fly-apps / terraform-provider-fly

Terraform provider for the Fly.io API
BSD 3-Clause "New" or "Revised" License
114 stars 38 forks source link

Can't import ip addresses as terraform resources #249

Closed Leejjon closed 11 months ago

Leejjon commented 11 months ago

I created a fly.io app with the flyctl launch command, and it generated an app with a shared ipv4 ip address and an ipv6 address.

leejjon@leejjon-XPS:~/projects/node-sqlite-fly-tutorial/steps/02-docker$ flyctl apps list
NAME                                    OWNER           STATUS          PLATFORM        LATEST DEPLOY        
fly-builder-quiet-snow-9145             personal        suspended       machines                                
leejjon-node-sqlite-fly-tutorial        personal        deployed        machines        2023-10-07T09:26:45Z    
leejjon@leejjon-XPS-:~/projects/node-sqlite-fly-tutorial/steps/02-docker$ flyctl ip list
VERSION IP                      TYPE            REGION  CREATED AT           
v6      2a09:8280:1::2d:7e61    public          global  2023-10-01T21:18:25Z    
v4      66.241.125.225          public (shared)       

I created a main.tf file that has definitions for the app and two ip addresses:

terraform {
  required_providers {
    fly = {
      source = "fly-apps/fly"
      version = "0.0.20"
    }
  }
}

provider "fly" {
  fly_api_token = var.token
  useinternaltunnel    = true
  internaltunnelorg    = "personal"
  internaltunnelregion = "ams"
}

resource "fly_app" "our-fly-app" {
  name = "leejjon-node-sqlite-fly-tutorial" #Replace this with your own app name
  org  = "personal"
}

resource "fly_ip" "ourIpv4" {
  app        = fly_app.our-fly-app.name
  type       = "v4"
  depends_on = [fly_app.our-fly-app]
}

resource "fly_ip" "ourIpv6" {
  app        = fly_app.our-fly-app.name
  type       = "v6"
  depends_on = [fly_app.our-fly-app]
}

I could import the app perfectly fine with the command: terraform import fly_app.our-fly-app leejjon-node-sqlite-fly-tutorial

Now terraform nicely shows that my app exists.

leejjon@leejjon-XPS:~/projects/node-sqlite-fly-tutorial/steps/02-docker/terraform$ terraform show
# fly_app.our-fly-app:
resource "fly_app" "our-fly-app" {
    appurl = "https://2a09:8280:1::2d:7e61"
    id     = "leejjon-node-sqlite-fly-tutorial"
    name   = "leejjon-node-sqlite-fly-tutorial"
    org    = "personal"
    orgid  = "3KXm0g39B6X2ZT01Nkv4g83lV4hgYYXBp"
}

According to the docs you can do this command: terraform import fly_ip.exampleIp ,

It doesn't seem to split the commas correctly:

leejjon@leejjon-XPS:~/projects/node-sqlite-fly-tutorial/steps/02-docker/terraform$ terraform import fly_ip.ourIpv4 "leejjon-node-sqlite-fly-tutorial,66.241.125.225"

fly_ip.ourIpv4: Importing from ID "leejjon-node-sqlite-fly-tutorial,66.241.125.225"...
fly_ip.ourIpv4: Import prepared!
  Prepared fly_ip for import
fly_ip.ourIpv4: Refreshing state... [id=leejjon-node-sqlite-fly-tutorial,66.241.125.225]
╷
│ Error: Could not find App
│ 
│ app
╵

I also tried it without the quotes.

But even if I leave out the ip address it gives the same error:

leejjon@leejjon-XPS:~/projects/node-sqlite-fly-tutorial/steps/02-docker/terraform$ terraform import fly_ip.ourIpv4 leejjon-node-sqlite-fly-tutorial

fly_ip.ourIpv4: Importing from ID "leejjon-node-sqlite-fly-tutorial"...
fly_ip.ourIpv4: Import prepared!
  Prepared fly_ip for import
fly_ip.ourIpv4: Refreshing state... [id=leejjon-node-sqlite-fly-tutorial]
╷
│ Error: Could not find App
│ 
│ app
╵
Leejjon commented 11 months ago

whoops, I just noticed there is a 0.0.23 version, and I'm getting a different error when I upgrade, so I'll close this issue and look into the new error.