2021-02-23 16:16:09 +01:00
|
|
|
package json
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/zclconf/go-cty/cty"
|
|
|
|
ctyjson "github.com/zclconf/go-cty/cty/json"
|
|
|
|
|
2021-05-17 21:00:50 +02:00
|
|
|
"github.com/hashicorp/terraform/internal/addrs"
|
2021-02-23 16:16:09 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
type ResourceAddr struct {
|
|
|
|
Addr string `json:"addr"`
|
|
|
|
Module string `json:"module"`
|
|
|
|
Resource string `json:"resource"`
|
|
|
|
ImpliedProvider string `json:"implied_provider"`
|
|
|
|
ResourceType string `json:"resource_type"`
|
|
|
|
ResourceName string `json:"resource_name"`
|
|
|
|
ResourceKey ctyjson.SimpleJSONValue `json:"resource_key"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func newResourceAddr(addr addrs.AbsResourceInstance) ResourceAddr {
|
|
|
|
resourceKey := ctyjson.SimpleJSONValue{Value: cty.NilVal}
|
|
|
|
if addr.Resource.Key != nil {
|
|
|
|
resourceKey.Value = addr.Resource.Key.Value()
|
|
|
|
}
|
|
|
|
return ResourceAddr{
|
|
|
|
Addr: addr.String(),
|
|
|
|
Module: addr.Module.String(),
|
|
|
|
Resource: addr.Resource.String(),
|
|
|
|
ImpliedProvider: addr.Resource.Resource.ImpliedProvider(),
|
|
|
|
ResourceType: addr.Resource.Resource.Type,
|
|
|
|
ResourceName: addr.Resource.Resource.Name,
|
|
|
|
ResourceKey: resourceKey,
|
|
|
|
}
|
|
|
|
}
|