hashicorp / hashicorp/terraform-exec

Support for `terraform state show`

Open
#336 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
786
Forks
129
PR merge metrics
No merged PRs in 30d

Description

The difference of `terraform state show` and `terraform show` is that the former only shows one resource, while the latter shows every resources in the state file.

One use case when we want to only show one resource is when we have an existing state file, which was originally generated from provider, e.g. v1.1.0. Later, if we initialized another terraform working directory with an old provider version, .e.g v1.0.0, whose main purpose is to import new resources to the state file (as v1.1.0 is backward compatible with v1.0.0, so it is not a problem to import with an older version). By following the official [import guide](https://learn.hashicorp.com/tutorials/terraform/state-import?in=terraform/state&utm_source=WEBSITE&utm_medium=WEB_IO&utm_offer=ARTICLE_PAGE&utm_content=DOCS), after importing the resource, we will need to leverage the `terraform state show`/`terraform show` to construct the corresponding HCL, at this point, `terraform show` might raise error if there are resources (properties) in the state file that only exist in v1.1.0. While what we actually want to show is only the imported resources (for v1.0.0).

I've also found #27 said that:

> Output from the latter (`terraform state show`) is intended for human consumption, so we will not be implementing it.

If that is the case, can we extend the `terraform show` with some option to make it able to only show one resource?

Contributor guide

Open the contributing guide

Research direction

Start by examining the existing terraform show command entry point and the behavior discussed in issue #27. Determine how a resource selector or equivalent option should be exposed, then verify that showing one resource works when other state resources use incompatible provider properties.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, terraform
Domain
cli
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.