hashicorp / terraform

Terraform enables you to safely and predictably create, change, and improve infrastructure. It is a source-available tool that codifies APIs into declarative configuration files that can be shared amongst team members, treated as code, edited, reviewed, and versioned.
https://www.terraform.io/
Other
41.42k stars 9.36k forks source link

Unable to remove items from state where address contains name index #35156

Closed BrianRichardson closed 2 weeks ago

BrianRichardson commented 2 weeks ago

Terraform Version

Terraform v1.8.3
on windows_amd64
+ provider registry.terraform.io/hashicorp/azuread v2.48.0
+ provider registry.terraform.io/hashicorp/azurerm v3.99.0

Terraform Configuration Files

terraform {
  required_version = "~> 1.0"
  required_providers {
    azuread = {
      source  = "hashicorp/azuread"
      version = "~> 2.0"
    }
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "~> 3.0"
    }
  }
}

Debug Output

No additional output with trace debugging enabled.

Expected Behavior

Resource to be removed from state

Actual Behavior

Syntax error or failure to find existing resource within state

Steps to Reproduce

Attempt to remove existing resource from state where the address contains a name. The following command permutations (amongst others) were executed in desperate attempt to successfully remove an item.

Command: terraform state rm module.module_name.resource_type.resource_address["name"]

Result: │ Error: Index value required │ │ on line 1: │ (source code not available) │ │ Index brackets must contain either a literal number or a literal string.

Command: terraform state rm module.module_name.resource_type.resource_address[\"name\"]

Result: │ Error: Invalid target address │ │ No matching objects found. To view the available instances, use "terraform state list". Please modify the address to │ reference a specific instance.

Command: terraform state rm 'module.module_name.resource_type.resource_address[\"name\"]'

Result: │ Error: Invalid character │ │ on line 1: │ (source code not available) │ │ Single quotes are not valid. Use double quotes (") to enclose strings.

│ Error: Variable name required │ │ on line 1: │ (source code not available) │ │ Must begin with a variable name.

Command: terraform state rm "module.module_name.resource_type.resource_address[\"name\"]"

Result: │ Error: Invalid target address │ │ No matching objects found. To view the available instances, use "terraform state list". Please modify the address to │ reference a specific instance.

Additional Context

Suggestions within Referred to seem to no longer be valid.

References

BrianRichardson commented 2 weeks ago

Closed since I realised I was working in a different workspace to one which I thought I was. Why the light sometimes only seems to since only after creating an issue!