F5Networks / terraform-provider-bigip

Terraform resources that can configure F5 BIG-IP products
https://registry.terraform.io/providers/F5Networks/bigip/latest/docs
Mozilla Public License 2.0
104 stars 119 forks source link

Importing existing objects e.g. nodes #345

Closed cki-gh-rafal-gadomski closed 2 years ago

cki-gh-rafal-gadomski commented 4 years ago

Hello, I am trying to start using terraform in our environment. I have did some modules to create nodes, pools and vs and it is working fine since the all of objects is new fresh. Our production env have some pre-created objects manually i.e. nodes and pools, which i want to reuse in my code / convert into code. I can't see if I can import node or pool into terraform?

I have tried some imports with: terraform import 'module.int-elastic-nodes.bigip_ltm_node.make-node["172.18.10.20"]' /Common/172.18.10.20%2900 based on lessons learnt with openstack provider but as far i can see there is no function in sources to import node so it can't even work? Am I wrong?

Regards

jskirde commented 2 years ago

Just attempting to resurrect this 2 year old issue because it still appears to be unresolved in the latest (1.15.0) version and we have a need to import nodes from common. Attempted to import:

module.lbaas-pool-members.bigip_ltm_node.rcc_node["3.3.3.3"]: Importing from ID "\"/Common/3.3.3.3\""...
module.lbaas-pool-members.bigip_ltm_node.rcc_node["3.3.3.3"]: Import prepared!
  Prepared bigip_ltm_node for import
module.lbaas-pool-members.bigip_ltm_node.rcc_node["3.3.3.3"]: Refreshing state... [id="/Common/3.3.3.3"]
╷
│ Error: Cannot import non-existent remote object
│
│ While attempting to import an existing object to "module.lbaas-pool-members.bigip_ltm_node.rcc_node[\"3.3.3.3\"]", the provider detected that no object exists with the
│ given id. Only pre-existing objects can be imported; check that the id is correct and that it is associated with the provider's configured region or endpoint, or use
│ "terraform apply" to create a new remote object for this resource.

I also tried using "/Common/3.3.3.3", '{ "id": "/Common/3.3.3.3"}' but neither of these worked. I am able to import using "3.3.3.3" but this results in a node that has a mismatching id and the subsequent apply will destroy and recreate the mismatching resource. It appears the root cause of this issue is import doesn't support partitions.

RavinderReddyF5 commented 2 years ago

@rafalgadomski @jskirde please let me know reproduction steps for this issue, i am unable to reproduce this issue. one more thing don't use route domain for import node objects into state, route domains will added only to address field

$ terraform import 'bigip_ltm_node.site1_node["3.3.3.3"]' /Common/3.3.3.3
bigip_ltm_node.site1_node["3.3.3.3"]: Importing from ID "/Common/3.3.3.3"...
bigip_ltm_node.site1_node["3.3.3.3"]: Import prepared!
  Prepared bigip_ltm_node for import
bigip_ltm_node.site1_node["3.3.3.3"]: Refreshing state... [id=/Common/3.3.3.3]

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.

$ terraform state list
bigip_command.create_partition
bigip_ltm_node.site1_node["3.3.3.3"]
bigip_ltm_node.site2_node
bigip_ltm_pool.example
bigip_ltm_pool_attachment.attachment

$ terraform state show 'bigip_ltm_node.site1_node["3.3.3.3"]'
# bigip_ltm_node.site1_node["3.3.3.3"]:
resource "bigip_ltm_node" "site1_node" {
    address          = "3.3.3.3"
    connection_limit = 0
    dynamic_ratio    = 1
    id               = "/Common/3.3.3.3"
    name             = "/Common/3.3.3.3"
    rate_limit       = "disabled"
    ratio            = 1
    session          = "user-enabled"
}
RavinderReddyF5 commented 2 years ago

@rafalgadomski closing this issue, please reopen new issues if any issue seen