aliyun / terraform-provider-alicloud

Terraform AliCloud provider
https://www.terraform.io/docs/providers/alicloud/
Mozilla Public License 2.0
579 stars 539 forks source link

Problem with terraform state rm #1724

Open lukaszciechomski opened 4 years ago

lukaszciechomski commented 4 years ago

Hi there,

I'm not able to use terraform state rm for resources created using for_each. Here is the part of result from terraform state list

terraform state list module.cen.alicloud_cen_bandwidth_package.bandwidth_package["china-corp-cen-china-china"] module.cen.alicloud_cen_bandwidth_package.bandwidth_package["china-ratings-cen-china-singapore"] module.cen.alicloud_cen_bandwidth_package_attachment.bandwidth_package_attachment["china-ratings-cen-china-singapore"]

here is the rm command and result

`terraform state rm module.cen.alicloud_cen_bandwidth_package.bandwidth_package["china-corp-cen-china-china"]

Error: Index value required

on line 1: (source code not available)

Index brackets must contain either a literal number or a literal string.` Please fix it

xiaozhu36 commented 4 years ago

HI @lukaszciechomski It seems like you specify a invalid target resource. Please have a try to run the command terraform state list and find the valid resource index before running terraform state rm.

lukaszciechomski commented 4 years ago

Hi, @xiaozhu36 actually it was correct it was performed by copying a line from terraform state list as you mentioned. To be honest I wasn't able to remove any resource created using for_each feature with terraform state rm.

xiaozhu36 commented 4 years ago

HI @lukaszciechomski I am sorry. I can not get it. Do you want to remove several resources by using for_each?

lukaszciechomski commented 4 years ago

Hi @xiaozhu36

Here are the steps to reproduce the error 1) Create multiple resources using for_each 2) Try to manually remove one of the resources created using terraform state rm command

jholloway7 commented 4 years ago

I think this is a problem with shell escaping (e.g. Bash). There's a relevant comment in this seemingly unrelated issue: https://github.com/hashicorp/terraform/issues/22301

Passing the full resource name in single quotes or backslash escaping the brackets and quotes should work. For example:

terraform state rm 'module.cen.alicloud_cen_bandwidth_package.bandwidth_package["china-corp-cen-china-china"]'

jbrunetext commented 4 years ago

terraform import google_project_iam_member.google_project_iam_binding.team_gcp_compute_ssh_iam["ressource name_index"] "projectname/roles/iap.tunnelResourceAccessor group:finance@google.com"

==> Error: Resource already managed by Terraform Good

pebneter commented 1 year ago

On Windows, I also had to backslash escape the double quotes: terraform state rm 'module.cen.alicloud_cen_bandwidth_package.bandwidth_package[\"china-corp-cen-china-china\"]'