github.com/graywolf-at-work-2/terraform-vendor@v1.4.5/internal/command/views/json/resource_addr.go (about)

     1  package json
     2  
     3  import (
     4  	"github.com/zclconf/go-cty/cty"
     5  	ctyjson "github.com/zclconf/go-cty/cty/json"
     6  
     7  	"github.com/hashicorp/terraform/internal/addrs"
     8  )
     9  
    10  type ResourceAddr struct {
    11  	Addr            string                  `json:"addr"`
    12  	Module          string                  `json:"module"`
    13  	Resource        string                  `json:"resource"`
    14  	ImpliedProvider string                  `json:"implied_provider"`
    15  	ResourceType    string                  `json:"resource_type"`
    16  	ResourceName    string                  `json:"resource_name"`
    17  	ResourceKey     ctyjson.SimpleJSONValue `json:"resource_key"`
    18  }
    19  
    20  func newResourceAddr(addr addrs.AbsResourceInstance) ResourceAddr {
    21  	resourceKey := ctyjson.SimpleJSONValue{Value: cty.NilVal}
    22  	if addr.Resource.Key != nil {
    23  		resourceKey.Value = addr.Resource.Key.Value()
    24  	}
    25  	return ResourceAddr{
    26  		Addr:            addr.String(),
    27  		Module:          addr.Module.String(),
    28  		Resource:        addr.Resource.String(),
    29  		ImpliedProvider: addr.Resource.Resource.ImpliedProvider(),
    30  		ResourceType:    addr.Resource.Resource.Type,
    31  		ResourceName:    addr.Resource.Resource.Name,
    32  		ResourceKey:     resourceKey,
    33  	}
    34  }