Skip to content

Commit 42ebcff

Browse files
committed
feat(website): add certificate option to website resource
1 parent 83c214a commit 42ebcff

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

iis/website.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,13 @@ type Website struct {
99
}
1010

1111
type WebsiteBinding struct {
12-
Protocol string `json:"protocol"`
13-
Port int `json:"port"`
14-
IPAddress string `json:"ip_address"`
15-
Hostname string `json:"hostname"`
12+
Protocol string `json:"protocol"`
13+
Port int `json:"port"`
14+
IPAddress string `json:"ip_address"`
15+
Hostname string `json:"hostname"`
16+
Certificate BindingCertificate `json:"certificate"`
17+
}
18+
19+
type BindingCertificate struct {
20+
ID string `json:"id"`
1621
}

provider/resource_website.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const bindingProtocolKey = "protocol"
1818
const bindingPortKey = "port"
1919
const bindingAddressKey = "ip_address"
2020
const bindingHostKey = "hostname"
21+
const bindingCertificateId = "certificate"
2122

2223
func resourceWebsite() *schema.Resource {
2324
return &schema.Resource{
@@ -70,6 +71,10 @@ var bindingSchema = &schema.Resource{
7071
Type: schema.TypeString,
7172
Optional: true,
7273
},
74+
bindingCertificateId: {
75+
Type: schema.TypeString,
76+
Optional: true,
77+
},
7378
},
7479
}
7580

@@ -149,12 +154,16 @@ func getBindings(b *schema.Set) []iis.WebsiteBinding {
149154
port := binding[bindingPortKey].(int)
150155
ipAddress := binding[bindingAddressKey].(string)
151156
hostname := binding[bindingHostKey].(string)
157+
id := binding[bindingCertificateId].(string)
152158

153159
bindings[i] = iis.WebsiteBinding{
154160
Port: port,
155161
IPAddress: ipAddress,
156162
Hostname: hostname,
157163
Protocol: protocol,
164+
Certificate: iis.BindingCertificate{
165+
ID: id,
166+
},
158167
}
159168
}
160169

@@ -165,10 +174,11 @@ func mapBindingsToSet(site *iis.Website) *schema.Set {
165174
var bindings []interface{}
166175
for _, binding := range site.Bindings {
167176
bindings = append(bindings, map[string]interface{}{
168-
bindingProtocolKey: binding.Protocol,
169-
bindingAddressKey: binding.IPAddress,
170-
bindingPortKey: binding.Port,
171-
bindingHostKey: binding.Hostname,
177+
bindingProtocolKey: binding.Protocol,
178+
bindingAddressKey: binding.IPAddress,
179+
bindingPortKey: binding.Port,
180+
bindingHostKey: binding.Hostname,
181+
bindingCertificateId: binding.Certificate.ID,
172182
})
173183
}
174184
set := schema.NewSet(hashBinding, bindings)
@@ -181,6 +191,7 @@ func hashBinding(v interface{}) int {
181191
protocol := schema.HashString(bindingMap[bindingProtocolKey].(string))
182192
port := schema.HashInt(bindingMap[bindingPortKey].(int))
183193
hostname := schema.HashString(bindingMap[bindingHostKey].(string))
194+
certificateId := schema.HashString(bindingMap[bindingCertificateId].(string))
184195

185-
return address + protocol + port + hostname
196+
return address + protocol + port + hostname + certificateId
186197
}

0 commit comments

Comments
 (0)