github.com/graywolf-at-work-2/terraform-vendor@v1.4.5/internal/command/jsonchecks/objects.go (about) 1 package jsonchecks 2 3 import ( 4 "fmt" 5 6 "github.com/hashicorp/terraform/internal/addrs" 7 ) 8 9 type staticObjectAddr map[string]interface{} 10 11 func makeStaticObjectAddr(addr addrs.ConfigCheckable) staticObjectAddr { 12 ret := map[string]interface{}{ 13 "to_display": addr.String(), 14 } 15 16 switch addr := addr.(type) { 17 case addrs.ConfigResource: 18 if kind := addr.CheckableKind(); kind != addrs.CheckableResource { 19 // Something has gone very wrong 20 panic(fmt.Sprintf("%T has CheckableKind %s", addr, kind)) 21 } 22 23 ret["kind"] = "resource" 24 switch addr.Resource.Mode { 25 case addrs.ManagedResourceMode: 26 ret["mode"] = "managed" 27 case addrs.DataResourceMode: 28 ret["mode"] = "data" 29 default: 30 panic(fmt.Sprintf("unsupported resource mode %#v", addr.Resource.Mode)) 31 } 32 ret["type"] = addr.Resource.Type 33 ret["name"] = addr.Resource.Name 34 if !addr.Module.IsRoot() { 35 ret["module"] = addr.Module.String() 36 } 37 case addrs.ConfigOutputValue: 38 if kind := addr.CheckableKind(); kind != addrs.CheckableOutputValue { 39 // Something has gone very wrong 40 panic(fmt.Sprintf("%T has CheckableKind %s", addr, kind)) 41 } 42 43 ret["kind"] = "output_value" 44 ret["name"] = addr.OutputValue.Name 45 if !addr.Module.IsRoot() { 46 ret["module"] = addr.Module.String() 47 } 48 default: 49 panic(fmt.Sprintf("unsupported ConfigCheckable implementation %T", addr)) 50 } 51 52 return ret 53 } 54 55 type dynamicObjectAddr map[string]interface{} 56 57 func makeDynamicObjectAddr(addr addrs.Checkable) dynamicObjectAddr { 58 ret := map[string]interface{}{ 59 "to_display": addr.String(), 60 } 61 62 switch addr := addr.(type) { 63 case addrs.AbsResourceInstance: 64 if !addr.Module.IsRoot() { 65 ret["module"] = addr.Module.String() 66 } 67 if addr.Resource.Key != addrs.NoKey { 68 ret["instance_key"] = addr.Resource.Key 69 } 70 case addrs.AbsOutputValue: 71 if !addr.Module.IsRoot() { 72 ret["module"] = addr.Module.String() 73 } 74 default: 75 panic(fmt.Sprintf("unsupported Checkable implementation %T", addr)) 76 } 77 78 return ret 79 }