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 #250

Open Leejjon opened 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.23"
    }
  }
}

provider "fly" {
  fly_api_token = var.token
}

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"
}

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

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

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 <app_id>,<ip_address>

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...
╷
│ Error: Could not find IPAssignment
│ 
│ app.ipAddress
╵

I also tried it without the quotes.

The ipv6 command does work:

leejjon@leejjon-XPS:~/projects/node-sqlite-fly-tutorial/steps/02-docker/terraform$ terraform import fly_ip.ourIpv6 "leejjon-node-sqlite-fly-tutorial,2a09:8280:1::2d:7e61"

fly_ip.ourIpv6: Importing from ID "leejjon-node-sqlite-fly-tutorial,2a09:8280:1::2d:7e61"...
fly_ip.ourIpv6: Import prepared!
  Prepared fly_ip for import
fly_ip.ourIpv6: Refreshing state...

Import successful!

The resources that were imported are shown above. These resources are now in
your Terraform state and will henceforth be managed by Terraform.

I cannot find the Error: Could not find IPAssignment on Google and I want to know if I'm doing something wrong or if this is a bug in the terraform provider.

Leejjon commented 10 months ago

When I try to just create a second app instead of importing, I get:


fly_app.our-fly-app: Creating...
╷
│ Error: Create app failed
│ 
│   with fly_app.our-fly-app,
│   on main.tf line 14, in resource "fly_app" "our-fly-app":
│   14: resource "fly_app" "our-fly-app" {
│ 
│ input:3: createApp Not authorized to deploy this app.
│ 
╵
andrewbaxter commented 8 months ago

Shared ip addresses aren't actually "ip address" resources apparently. It's a property of the app. I think just importing the app would be enough to get it using the (my updated) fork in #257