Skip to content
This repository has been archived by the owner on Mar 1, 2024. It is now read-only.

Can't import ip addresses as terraform resources #250

Open
Leejjon opened this issue Oct 8, 2023 · 2 comments
Open

Can't import ip addresses as terraform resources #250

Leejjon opened this issue Oct 8, 2023 · 2 comments

Comments

@Leejjon
Copy link

Leejjon commented Oct 8, 2023

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
Copy link
Author

Leejjon commented Oct 8, 2023

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
Copy link

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants