github.com/opentofu/opentofu@v1.7.1/internal/command/views/json/resource_addr.go (about) 1 // Copyright (c) The OpenTofu Authors 2 // SPDX-License-Identifier: MPL-2.0 3 // Copyright (c) 2023 HashiCorp, Inc. 4 // SPDX-License-Identifier: MPL-2.0 5 6 package json 7 8 import ( 9 "github.com/zclconf/go-cty/cty" 10 ctyjson "github.com/zclconf/go-cty/cty/json" 11 12 "github.com/opentofu/opentofu/internal/addrs" 13 ) 14 15 type ResourceAddr struct { 16 Addr string `json:"addr"` 17 Module string `json:"module"` 18 Resource string `json:"resource"` 19 ImpliedProvider string `json:"implied_provider"` 20 ResourceType string `json:"resource_type"` 21 ResourceName string `json:"resource_name"` 22 ResourceKey ctyjson.SimpleJSONValue `json:"resource_key"` 23 } 24 25 func newResourceAddr(addr addrs.AbsResourceInstance) ResourceAddr { 26 resourceKey := ctyjson.SimpleJSONValue{Value: cty.NilVal} 27 if addr.Resource.Key != nil { 28 resourceKey.Value = addr.Resource.Key.Value() 29 } 30 return ResourceAddr{ 31 Addr: addr.String(), 32 Module: addr.Module.String(), 33 Resource: addr.Resource.String(), 34 ImpliedProvider: addr.Resource.Resource.ImpliedProvider(), 35 ResourceType: addr.Resource.Resource.Type, 36 ResourceName: addr.Resource.Resource.Name, 37 ResourceKey: resourceKey, 38 } 39 }