-
Notifications
You must be signed in to change notification settings - Fork 74
/
config.go
112 lines (108 loc) · 4.12 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
108
109
110
111
112
package cloudplatform
import (
"encoding/base64"
"github.com/crossplane/upjet/pkg/config"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/pkg/errors"
"github.com/upbound/provider-gcp/config/common"
)
// Configure configures individual resources by adding custom
// ResourceConfigurators.
func Configure(p *config.Provider) {
p.AddResourceConfigurator("google_folder_iam_member", func(r *config.Resource) {
r.References["folder"] = config.Reference{
Type: "Folder",
Extractor: common.ExtractResourceIDFuncPath,
}
})
p.AddResourceConfigurator("google_project", func(r *config.Resource) {
r.TerraformResource.Schema["org_id"].Description =
"The numeric ID of the organization this project belongs to."
})
p.AddResourceConfigurator("google_project_default_service_accounts", func(r *config.Resource) {
r.References["project"] = config.Reference{
Type: "Project",
}
})
p.AddResourceConfigurator("google_project_iam_member", func(r *config.Resource) {
r.References["project"] = config.Reference{
Type: "Project",
}
})
p.AddResourceConfigurator("google_project_iam_audit_config", func(r *config.Resource) {
r.References["project"] = config.Reference{
Type: "Project",
}
})
p.AddResourceConfigurator("google_project_service", func(r *config.Resource) {
r.References["project"] = config.Reference{
Type: "Project",
}
})
p.AddResourceConfigurator("google_project_usage_export_bucket", func(r *config.Resource) {
r.References["project"] = config.Reference{
Type: "Project",
}
// Note(donovanmuller): Upjet does not generate this reference automatically
r.References["bucket_name"] = config.Reference{
Type: "github.com/upbound/provider-gcp/apis/storage/v1beta1.Bucket",
}
})
p.AddResourceConfigurator("google_service_account_key", func(r *config.Resource) {
// Note(turkenh): We have to modify schema of "keepers", since it is a
// map where elements configured as nil, but needs to be String:
r.TerraformResource.
Schema["keepers"].Elem = schema.TypeString
// Note(donovanmuller): The private_key attribute is already base64 encoded.
// Therefore, writing it as a connection Secret results in the Secret value being double encoded,
// so decode it and add to the connection details as private_key
r.Sensitive.AdditionalConnectionDetailsFn = func(attr map[string]interface{}) (map[string][]byte, error) {
if attr["private_key"] == nil {
return nil, nil
}
privateKeyEncoded, err := common.GetField(attr, "private_key")
if err != nil {
return nil, err
}
privateKey, err := base64.StdEncoding.DecodeString(privateKeyEncoded)
if err != nil {
return nil, errors.Wrapf(err, "cannot decode private_key")
}
return map[string][]byte{
"private_key": privateKey,
}, nil
}
r.References["service_account_id"] = config.Reference{
Type: "ServiceAccount",
Extractor: common.ExtractResourceIDFuncPath,
}
})
p.AddResourceConfigurator("google_service_account", func(r *config.Resource) {
r.Kind = "ServiceAccount"
})
p.AddResourceConfigurator("google_service_account_iam_policy", func(r *config.Resource) {
r.References["service_account_id"] = config.Reference{
Type: "ServiceAccount",
Extractor: common.ExtractResourceIDFuncPath,
}
config.MarkAsRequired(r.TerraformResource, "service_account_id")
})
p.AddResourceConfigurator("google_service_account_iam_binding", func(r *config.Resource) {
r.References["service_account_id"] = config.Reference{
Type: "ServiceAccount",
Extractor: common.ExtractResourceIDFuncPath,
}
config.MarkAsRequired(r.TerraformResource, "service_account_id")
})
p.AddResourceConfigurator("google_service_account_iam_member", func(r *config.Resource) {
r.References["service_account_id"] = config.Reference{
Type: "ServiceAccount",
Extractor: common.ExtractResourceIDFuncPath,
}
config.MarkAsRequired(r.TerraformResource, "service_account_id")
})
p.AddResourceConfigurator("google_service_networking_peered_dns_domain", func(r *config.Resource) {
config.MarkAsRequired(r.TerraformResource, "network")
config.MarkAsRequired(r.TerraformResource, "service")
})
}