-
Notifications
You must be signed in to change notification settings - Fork 74
/
config.go
107 lines (98 loc) · 3.48 KB
/
config.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package pubsub
import "github.com/crossplane/upjet/pkg/config"
// Configure configures individual resources by adding custom
// ResourceConfigurators.
func Configure(p *config.Provider) {
p.AddResourceConfigurator("google_pubsub_lite_reservation", func(r *config.Resource) {
config.MarkAsRequired(r.TerraformResource, "region")
})
p.AddResourceConfigurator("google_pubsub_lite_subscription", func(r *config.Resource) {
r.References["topic"] = config.Reference{
Type: "LiteTopic",
}
r.Sensitive.AdditionalConnectionDetailsFn = pubsubLiteConnectionDetails
config.MarkAsRequired(r.TerraformResource, "zone")
})
p.AddResourceConfigurator("google_pubsub_lite_topic", func(r *config.Resource) {
r.References["reservation_config.throughput_reservation"] = config.Reference{
Type: "LiteReservation",
}
r.Sensitive.AdditionalConnectionDetailsFn = pubsubLiteConnectionDetails
config.MarkAsRequired(r.TerraformResource, "zone")
config.MarkAsRequired(r.TerraformResource, "partition_config")
config.MarkAsRequired(r.TerraformResource, "retention_config")
})
p.AddResourceConfigurator("google_pubsub_subscription", func(r *config.Resource) {
r.References["topic"] = config.Reference{
Type: "Topic",
}
r.Sensitive.AdditionalConnectionDetailsFn = pubsubConnectionDetails
})
p.AddResourceConfigurator("google_pubsub_subscription_iam_member", func(r *config.Resource) {
r.References["subscription"] = config.Reference{
Type: "Subscription",
}
})
p.AddResourceConfigurator("google_pubsub_topic", func(r *config.Resource) {
r.Sensitive.AdditionalConnectionDetailsFn = pubsubConnectionDetails
})
p.AddResourceConfigurator("google_pubsub_topic_iam_member", func(r *config.Resource) {
r.References["topic"] = config.Reference{
Type: "Topic",
}
})
}
func pubsubLiteConnectionDetails(attr map[string]interface{}) (map[string][]byte, error) {
conn := map[string][]byte{}
if a, ok := attr["id"].(string); ok {
conn["id"] = []byte(a)
}
if a, ok := attr["name"].(string); ok {
conn["topic"] = []byte(a)
}
// Note(donovanmuller): If this is a google_pubsub_lite_subscription
// resource, then the "topic" attribute will be used to override the
// "topic" connection key of the google_pubsub_lite_topic subscribed
// too and the "subscription" attribute to the "name" connection key
// of the subscription
if a, ok := attr["topic"].(string); ok {
conn["topic"] = []byte(a)
if a, ok := attr["name"].(string); ok {
conn["subscription"] = []byte(a)
}
}
if a, ok := attr["project"].(string); ok {
conn["project"] = []byte(a)
}
if a, ok := attr["zone"].(string); ok {
conn["zone"] = []byte(a)
}
if a, ok := attr["region"].(string); ok {
conn["region"] = []byte(a)
}
return conn, nil
}
func pubsubConnectionDetails(attr map[string]interface{}) (map[string][]byte, error) {
conn := map[string][]byte{}
if a, ok := attr["id"].(string); ok {
conn["id"] = []byte(a)
}
if a, ok := attr["name"].(string); ok {
conn["topic"] = []byte(a)
}
// Note(donovanmuller): If this is a google_pubsub_subscription
// resource, then the "topic" attribute will be used to override the
// "topic" connection key of the google_pubsub_topic subscribed
// too and the "subscription" attribute to the "name" connection key
// of the subscription
if a, ok := attr["topic"].(string); ok {
conn["topic"] = []byte(a)
if a, ok := attr["name"].(string); ok {
conn["subscription"] = []byte(a)
}
}
if a, ok := attr["project"].(string); ok {
conn["project"] = []byte(a)
}
return conn, nil
}