Skip to content

Error on state refresh for resources removed from device #273

Closed
@tomvrugt

Description

@tomvrugt

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Description

State refresh fails after removing a resource from the device that was previously configured by terraform:

$tofu plan
iosxr_vrf.vrf_TST_VRF_TOM: Refreshing state... [id=Cisco-IOS-XR-um-vrf-cfg:/vrfs/vrf[vrf-name=TST_VRF_TOM]]

Planning failed. OpenTofu encountered an error while generating this plan.

╷
│ Error: Client Error
│
│   with iosxr_vrf.vrf_TST_VRF_TOM,
│   on main.tf line 16, in resource "iosxr_vrf" "vrf_TST_VRF_TOM":
│   16: resource "iosxr_vrf" "vrf_TST_VRF_TOM" {
│
│ Get request failed, got error: rpc error: code = NotFound desc = Requested element(s) not found: 'vrf'
╵

Affected Resource(s):

  • all

IOS-XR version and Platform

IOS XRv 9000 Router running IOS XR 24.2.2

Provider version

ciscodevnet/iosxr v0.5.2

Expected Behavior

Resource should be removed from the state file during state refresh. If the resource is still present in terraform config, terraform plan should suggest to recreate the resource on the device.

Actual Behavior

Terraform plan produces Requested element(s) not found error during state refresh.

Terraform configuration to reproduce

terraform {
  required_providers {
    iosxr = {
      source  = "CiscoDevNet/iosxr"
      version = ">= 0.5.2"
    }
  }
}

provider "iosxr" {
  username = "***"
  password = "***"
  host     = "10.131.3.121:57777"
}

resource "iosxr_vrf" "vrf_TST_VRF_TOM" {
  vrf_name                    = "TST_VRF_TOM"
  address_family_ipv4_unicast = true
  rd_two_byte_as_as_number    = "65123"
  rd_two_byte_as_index        = 1
}

apply config

$ tofu apply

OpenTofu used the selected providers to generate the following execution plan. Resource actions are indicated with the
following symbols:
  + create

OpenTofu will perform the following actions:

  # iosxr_vrf.vrf_TST_VRF_TOM will be created
  + resource "iosxr_vrf" "vrf_TST_VRF_TOM" {
      + address_family_ipv4_unicast = true
      + id                          = (known after apply)
      + rd_two_byte_as_as_number    = "65123"
      + rd_two_byte_as_index        = 1
      + vrf_name                    = "TST_VRF_TOM"
    }

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

Do you want to perform these actions?
  OpenTofu will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

iosxr_vrf.vrf_TST_VRF_TOM: Creating...
iosxr_vrf.vrf_TST_VRF_TOM: Creation complete after 1s [id=Cisco-IOS-XR-um-vrf-cfg:/vrfs/vrf[vrf-name=TST_VRF_TOM]]

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

remove resource from device

RP/0/RP0/CPU0:xr9kv-dc1#conf t
Thu Dec 19 09:53:20.273 UTC
RP/0/RP0/CPU0:xr9kv-dc1(config)#no vrf TST_VRF_TOM
RP/0/RP0/CPU0:xr9kv-dc1(config)#commit

refresh state by running terraform plan

$tofu plan
iosxr_vrf.vrf_TST_VRF_TOM: Refreshing state... [id=Cisco-IOS-XR-um-vrf-cfg:/vrfs/vrf[vrf-name=TST_VRF_TOM]]

Planning failed. OpenTofu encountered an error while generating this plan.

╷
│ Error: Client Error
│
│   with iosxr_vrf.vrf_TST_VRF_TOM,
│   on main.tf line 16, in resource "iosxr_vrf" "vrf_TST_VRF_TOM":
│   16: resource "iosxr_vrf" "vrf_TST_VRF_TOM" {
│
│ Get request failed, got error: rpc error: code = NotFound desc = Requested element(s) not found: 'vrf'
╵

Important Factoids

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions