-
Notifications
You must be signed in to change notification settings - Fork 9.4k
/
resource_addr.go
34 lines (30 loc) · 1.13 KB
/
resource_addr.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package json
import (
"github.com/zclconf/go-cty/cty"
ctyjson "github.com/zclconf/go-cty/cty/json"
"github.com/hashicorp/terraform/internal/addrs"
)
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,
}
}