-
Notifications
You must be signed in to change notification settings - Fork 74
/
config.go
181 lines (154 loc) · 5.84 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/*
Copyright 2021 The Crossplane Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package sql
import (
"fmt"
"github.com/crossplane/upjet/pkg/config"
"github.com/pkg/errors"
xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1"
"github.com/upbound/provider-azure/apis/rconfig"
)
func msSQLConnectionDetails(attr map[string]interface{}) (map[string][]byte, error) {
dbName, ok := attr["name"].(string)
if !ok {
return nil, errors.New("cannot get name attribute")
}
username, ok := attr["administrator_login"].(string)
if !ok {
return nil, errors.New("cannot get administrator_login attribute")
}
endpoint, ok := attr["fully_qualified_domain_name"].(string)
if !ok {
return nil, errors.New("cannot get fully_qualified_domain_name attribute")
}
conn := map[string][]byte{
xpv1.ResourceCredentialsSecretUserKey: []byte(fmt.Sprintf("%s@%s", username, dbName)),
xpv1.ResourceCredentialsSecretEndpointKey: []byte(endpoint),
}
// Note(turkenh): include password only if available, might not be available
// depending on the auth type.
if password, ok := attr["administrator_login_password"].(string); ok {
conn[xpv1.ResourceCredentialsSecretPasswordKey] = []byte(password)
}
return conn, nil
}
// Configure configures sql group
func Configure(p *config.Provider) {
p.AddResourceConfigurator("azurerm_mssql_server", func(r *config.Resource) {
r.Sensitive.AdditionalConnectionDetailsFn = msSQLConnectionDetails
})
p.AddResourceConfigurator("azurerm_mssql_server_transparent_data_encryption", func(r *config.Resource) {
r.UseAsync = false
r.References["server_id"] = config.Reference{
Type: "MSSQLServer",
Extractor: rconfig.ExtractResourceIDFuncPath,
}
r.References["key_vault_key_id"] = config.Reference{
Type: rconfig.VaultKeyReferencePath,
Extractor: rconfig.ExtractResourceIDFuncPath,
}
})
p.AddResourceConfigurator("azurerm_mssql_virtual_network_rule", func(r *config.Resource) {
r.References["server_id"] = config.Reference{
Type: "MSSQLServer",
Extractor: rconfig.ExtractResourceIDFuncPath,
}
})
p.AddResourceConfigurator("azurerm_mssql_managed_instance", func(r *config.Resource) {
r.References["dns_zone_partner_id"] = config.Reference{
Type: "MSSQLManagedInstance",
Extractor: rconfig.ExtractResourceIDFuncPath,
}
})
p.AddResourceConfigurator("azurerm_mssql_managed_database", func(r *config.Resource) {
r.References["managed_instance_id"] = config.Reference{
Type: "MSSQLManagedInstance",
Extractor: rconfig.ExtractResourceIDFuncPath,
}
})
p.AddResourceConfigurator("azurerm_mssql_managed_instance_active_directory_administrator", func(r *config.Resource) {
r.References["managed_instance_id"] = config.Reference{
Type: "MSSQLManagedInstance",
Extractor: rconfig.ExtractResourceIDFuncPath,
}
})
p.AddResourceConfigurator("azurerm_mssql_failover_group", func(r *config.Resource) {
r.References["server_id"] = config.Reference{
Type: "MSSQLServer",
Extractor: rconfig.ExtractResourceIDFuncPath,
}
r.References["partner_server.id"] = config.Reference{
Type: "MSSQLServer",
Extractor: rconfig.ExtractResourceIDFuncPath,
}
r.References["databases"] = config.Reference{
Type: "MSSQLDatabase",
Extractor: rconfig.ExtractResourceIDFuncPath,
}
})
p.AddResourceConfigurator("azurerm_mssql_managed_instance_failover_group", func(r *config.Resource) {
r.References["managed_instance_id"] = config.Reference{
Type: "MSSQLManagedInstance",
Extractor: rconfig.ExtractResourceIDFuncPath,
}
r.References["partner_managed_instance_id"] = config.Reference{
Type: "MSSQLManagedInstance",
Extractor: rconfig.ExtractResourceIDFuncPath,
}
})
p.AddResourceConfigurator("azurerm_mssql_managed_instance_vulnerability_assessment", func(r *config.Resource) {
r.References["managed_instance_id"] = config.Reference{
Type: "MSSQLManagedInstance",
Extractor: rconfig.ExtractResourceIDFuncPath,
}
})
p.AddResourceConfigurator("azurerm_mssql_database", func(r *config.Resource) {
r.References["server_id"] = config.Reference{
Type: "MSSQLServer",
Extractor: rconfig.ExtractResourceIDFuncPath,
}
r.LateInitializer = config.LateInitializer{
IgnoredFields: []string{"maintenance_configuration_name", "elastic_pool_id"},
}
})
p.AddResourceConfigurator("azurerm_mssql_outbound_firewall_rule", func(r *config.Resource) {
r.References["server_id"] = config.Reference{
Type: "MSSQLServer",
Extractor: rconfig.ExtractResourceIDFuncPath,
}
})
p.AddResourceConfigurator("azurerm_mssql_server_dns_alias", func(r *config.Resource) {
r.References["mssql_server_id"] = config.Reference{
Type: "MSSQLServer",
Extractor: rconfig.ExtractResourceIDFuncPath,
}
})
p.AddResourceConfigurator("azurerm_mssql_server_security_alert_policy", func(r *config.Resource) {
r.References["server_name"] = config.Reference{
Type: "MSSQLServer",
}
})
p.AddResourceConfigurator("azurerm_mssql_elasticpool", func(r *config.Resource) {
r.LateInitializer = config.LateInitializer{
IgnoredFields: []string{"max_size_bytes"},
}
r.References["server_name"] = config.Reference{
Type: "MSSQLServer",
}
})
p.AddResourceConfigurator("azurerm_mssql_database_vulnerability_assessment_rule_baseline", func(r *config.Resource) {
r.References["database_name"] = config.Reference{
Type: "MSSQLDatabase",
}
})
}