Skip to content

Commit

Permalink
Merge pull request #1482 from Coolomina/add-sni-support
Browse files Browse the repository at this point in the history
feat: adds support for custom_origin_sni field in cloudflare_custom_hostname
  • Loading branch information
jacobbednarz authored Feb 26, 2022
2 parents c6b79d1 + 9037247 commit 3cc7d23
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/1482.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/cloudflare_custom_hostname: adds support for custom_origin_sni
```
2 changes: 2 additions & 0 deletions cloudflare/resource_cloudflare_custom_hostname.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func resourceCloudflareCustomHostnameRead(d *schema.ResourceData, meta interface

d.Set("hostname", customHostname.Hostname)
d.Set("custom_origin_server", customHostname.CustomOriginServer)
d.Set("custom_origin_sni", customHostname.CustomOriginSNI)
var sslConfig []map[string]interface{}

if !reflect.ValueOf(customHostname.SSL).IsNil() {
Expand Down Expand Up @@ -172,6 +173,7 @@ func buildCustomHostname(d *schema.ResourceData) cloudflare.CustomHostname {
ch := cloudflare.CustomHostname{
Hostname: d.Get("hostname").(string),
CustomOriginServer: d.Get("custom_origin_server").(string),
CustomOriginSNI: d.Get("custom_origin_sni").(string),
}

if _, ok := d.GetOk("ssl"); ok {
Expand Down
2 changes: 2 additions & 0 deletions cloudflare/resource_cloudflare_custom_hostname_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ func TestAccCloudflareCustomHostname_WithCustomOriginServer(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "zone_id", zoneID),
resource.TestCheckResourceAttr(resourceName, "hostname", fmt.Sprintf("%s.%s", rnd, domain)),
resource.TestCheckResourceAttr(resourceName, "custom_origin_server", fmt.Sprintf("origin.%s.terraform.cfapi.net", rnd)),
resource.TestCheckResourceAttr(resourceName, "custom_origin_sni", fmt.Sprintf("origin.%s.terraform.cfapi.net", rnd)),
resource.TestCheckResourceAttr(resourceName, "ssl.0.method", "txt"),
resource.TestCheckResourceAttrSet(resourceName, "ownership_verification.value"),
resource.TestCheckResourceAttrSet(resourceName, "ownership_verification.type"),
Expand All @@ -126,6 +127,7 @@ resource "cloudflare_custom_hostname" "%[2]s" {
zone_id = "%[1]s"
hostname = "%[2]s.%[3]s"
custom_origin_server = "origin.%[2]s.terraform.cfapi.net"
custom_origin_sni = "origin.%[2]s.terraform.cfapi.net"
ssl {
method = "txt"
}
Expand Down
4 changes: 4 additions & 0 deletions cloudflare/schema_cloudflare_custom_hostname.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ func resourceCloudflareCustomHostnameSchema() map[string]*schema.Schema {
Type: schema.TypeString,
Optional: true,
},
"custom_origin_sni": {
Type: schema.TypeString,
Optional: true,
},
"ssl": {
Type: schema.TypeList,
Optional: true,
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/custom_hostname.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ The following arguments are supported:
* `zone_id` - (Required) The DNS zone ID where the custom hostname should be assigned.
* `hostname` - (Required) Hostname you intend to request a certificate for.
* `custom_origin_server` - (Optional) The custom origin server used for certificates.
* `custom_origin_sni` - (Optional) The [custom origin SNI](https://developers.cloudflare.com/ssl/ssl-for-saas/hostname-specific-behavior/custom-origin) used for certificates.
* `ssl` - (Required) SSL configuration of the certificate. See further notes below.

**ssl** block supports:
Expand Down

0 comments on commit 3cc7d23

Please sign in to comment.