Trying to delete Object from State File - Getting 404 Error

Hi,

I’m trying to remove an object from Terrafrom State but I’m getting following error. Initially I tired to re-create the object through apply command as I’ve refactored ElasticCache Redis Cluster Objects. When I ran the Apply command after refactoring the code, All the old objects have been removed from Plan File, But Some Subnet Groups were not unable to delete, So I tried to delete them through AWS Console, After they got deleted, I tried to run the plan command and getting following command

Error: CacheParameterGroupNotFound: CacheParameterGroup http-apicluster not found.
status code: 404, request id: 6011c644-aefc-11e9-9ecc-a93f05e7d3c9

When I try to run remove command, I’m getting folowing error :slight_smile:

terraform state rm CacheParameterGroup.http-apicluster

Acquiring state lock. This may take a few moments…
No matching resource instances found.

I tired this below command also but no luck.
terraform state rm resource.http-api-cluster
No matching resource instances found.

How to remove this object as I’m not able to re-run the refactored code? Any thoughts

Found way to resolve this issue. Ran TF Plan again after setting up TF_LOG & TF_LOG_PATH environment variables. The Following error is displayed in Log out put :slight_smile:

2019/07/26 05:35:02 [ERROR] module.elasticache_redis: eval: *terraform.EvalRefresh, err: CacheParameterGroupNotFound: CacheParameterGroup http-apicluster not found.
status code: 404, request id: 1d7638cb-af67-11e9-9c0b-8bdab75dab1a

Ran the following rm state command to remove the object from state file :sunny:

terraform state rm module.elasticache_redis.aws_elasticache_parameter_group.default

Re-Ran the Plan & Apply - It worked fine and proivsioed re-factored infrastructure sucessfully.

Though of sharing this in group, It will be useful in those circumstances, who wants to remove objects from state file , either they have been deleted through other means like aws console or aws cli which will not let re-build terraform plan until you references to them in config file.