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

Error when attempting to use Terraform Import block to import "bigip_ltm_pool_attachment" #999

Open
ratsalad21 opened this issue Jul 9, 2024 · 2 comments

Comments

@ratsalad21
Copy link

Environment

  • TMOS/Bigip Version: BIG-IP 17.1.0.3 Build 0.75.4 Engineering Hotfix
  • Terraform Version: 1.9.1
  • Terraform bigip provider Version: 1.22.2

Summary

I am attempting to import an existing bigip_ltm_pool_attachment. The pool and attached node already exist in the environment. I am using a terraform import block. When I run a terraform plan, I recieve the following message:

│ Error: Incorrect value type

│ on main.tf line 107, in import:
│ 107: id = { "pool": "/Common/service.test.com_8065_pool", "node": "/common/node01.test.com:8065" }

│ Invalid expression value: string required.


│ Error: Invalid import id argument

│ on main.tf line 107, in import:
│ 107: id = { "pool": "/Common/service.test.com_8065_pool", "node": "/common/node01.test.com:8065" }

│ The import block "id" argument depends on resource attributes that cannot be determined until apply, so Terraform cannot plan to import this resource.

Steps To Reproduce

Steps to reproduce the behavior:

This is the terraform config I am using when I recieve the above error:

locals {
keys = var.node_name
values = var.node_state
node_map = zipmap(local.keys, local.values)
}

output "node_map" {
description = "Mapping of Hostname/IPs for F5 nodes"
value = local.node_map
}

Import Node(s)

import {
for_each = local.node_map
to = bigip_ltm_node.nodes[each.key]
id = "/Common/${each.key}.${var.domain}"
}

Create Node(s)

resource "bigip_ltm_node" "nodes" {
for_each = local.node_map
name = "/Common/${each.key}.${var.domain}"
address = "${each.key}.${var.domain}"
state = each.value
monitor = "default"
description = "Managed by Terraform"
}

Import Attach node(s) to pool

import {
for_each = bigip_ltm_node.nodes
to = bigip_ltm_pool_attachment.attach_node_8065
id = { "pool": bigip_ltm_pool.service_8065.name, "node": "${bigip_ltm_node.nodes[each.value.name]}:8065" }
}

Attach node(s) to pool

resource "bigip_ltm_pool_attachment" "attach_node_8065" {
for_each = bigip_ltm_node.nodes
pool = bigip_ltm_pool.service_8065.name
node = "${bigip_ltm_node.nodes[each.value.name]}:8065"

depends_on = [
bigip_ltm_pool.service_8065
]
}

Expected Behavior

When running terraform plan, I expect the bigip_ltm_pool_attachement to be imported.

Actual Behavior

│ Error: Incorrect value type

│ on main.tf line 107, in import:
│ 107: id = { "pool": "/Common/service.test.com_8065_pool", "node": "/common/node01.test.com:8065" }

│ Invalid expression value: string required.


│ Error: Invalid import id argument

│ on main.tf line 107, in import:
│ 107: id = { "pool": "/Common/service.test.com_8065_pool", "node": "/common/node01.test.com:8065" }

│ The import block "id" argument depends on resource attributes that cannot be determined until apply, so Terraform cannot plan to import this resource.

@ratsalad21 ratsalad21 added the bug label Jul 9, 2024
@pgouband
Copy link
Collaborator

Hi @ratsalad21,

I tested the following with success:

import {
  to = bigip_ltm_pool_attachment.attach_node_mypool
  id = "{ \"pool\": \"/Common/my-pool2\", \"node\": \"/Common/server2:80\" }"
}
$ terraform plan -generate-config-out=generated.tf
bigip_ltm_pool_attachment.attach_node_mypool: Preparing import... [id={ "pool": "/Common/my-pool2", "node": "/Common/server2:80" }]
bigip_ltm_pool_attachment.attach_node_mypool: Refreshing state... [id=/Common/my-pool2-/Common/server2:80]

Terraform used the selected providers to generate the following execution plan.
Resource actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  # bigip_ltm_pool_attachment.attach_node_mypool will be updated in-place
  # (imported from "{ "pool": "/Common/my-pool2", "node": "/Common/server2:80" }")
  ~ resource "bigip_ltm_pool_attachment" "attach_node_mypool" {
        id    = "/Common/my-pool2-/Common/server2:80"
        node  = "/Common/server2:80"
        pool  = "/Common/my-pool2"
      + state = "enabled"
    }

Plan: 1 to import, 0 to add, 1 to change, 0 to destroy.

│ Warning: Config generation is experimental

│ Generating configuration during import is currently experimental, and the
│ generated configuration format may change in future versions.


───────────────────────────────────────────────────────────────────────────────

Terraform has generated configuration and written it to generated.tf. Please
review the configuration and edit it as necessary before adding it to version
control.

Note: You didn't use the -out option to save this plan, so Terraform can't
guarantee to take exactly these actions if you run "terraform apply" now.

@jtgasper3
Copy link

I'm not the OP, but can confirmed this worked for me.

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

No branches or pull requests

3 participants