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 on state refresh for resources removed from device #273

Closed
tomvrugt opened this issue Dec 19, 2024 · 5 comments
Closed

Error on state refresh for resources removed from device #273

tomvrugt opened this issue Dec 19, 2024 · 5 comments
Labels
enhancement New feature or request

Comments

@tomvrugt
Copy link

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

@danischm
Copy link
Member

628fbcb

@danischm danischm added the enhancement New feature or request label Dec 20, 2024
@tomvrugt
Copy link
Author

628fbcb

Tested it, works! Thanks for the quick support Daniel!

@tomvrugt tomvrugt reopened this Feb 20, 2025
@tomvrugt
Copy link
Author

@danischm can you apply the same fix to the iosxr_gnmi resource?

@danischm
Copy link
Member

88d049e

@tomvrugt
Copy link
Author

88d049e

👍 Works, thanks Daniel!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants