Skip to content
This repository was archived by the owner on Dec 9, 2020. It is now read-only.

Add support for 'domain_aliases' #30

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions netlify/resource_site.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ func resourceSite() *schema.Resource {
Type: schema.TypeString,
Optional: true,
},
"domain_aliases": {
Type: schema.TypeList,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be a set, or does the order matter here?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think order really matters in this scenario

Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
},

"deploy_url": {
Type: schema.TypeString,
Expand Down Expand Up @@ -108,6 +113,7 @@ func resourceSiteRead(d *schema.ResourceData, metaRaw interface{}) error {
site := resp.Payload
d.Set("name", site.Name)
d.Set("custom_domain", site.CustomDomain)
d.Set("domain_aliases", site.DomainAliases)
d.Set("deploy_url", site.DeployURL)
d.Set("repo", nil)

Expand Down Expand Up @@ -149,12 +155,26 @@ func resourceSiteDelete(d *schema.ResourceData, metaRaw interface{}) error {
return err
}

func expandStringSlice(s []interface{}) []string {
result := make([]string, len(s), len(s))
for k, v := range s {
// Handle the Terraform parser bug which turns empty strings in lists to nil.
if v == nil {
result[k] = ""
} else {
result[k] = v.(string)
}
}
return result
}

// Returns the SiteSetup structure that can be used for creation or updating.
func resourceSite_setupStruct(d *schema.ResourceData) *models.SiteSetup {
result := &models.SiteSetup{
Site: models.Site{
Name: d.Get("name").(string),
CustomDomain: d.Get("custom_domain").(string),
Name: d.Get("name").(string),
CustomDomain: d.Get("custom_domain").(string),
DomainAliases: expandStringSlice(d.Get("domain_aliases").([]interface{})),
},
}

Expand Down
1 change: 1 addition & 0 deletions website/docs/r/netlify_site.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ The following arguments are supported:
* `name` - (Required) - Name of your site on Netlify (e.g. **mysite**.netlify.com)
* `repo` - (Required) - See [Repository](#repo)
* `custom_domain` - (Optional) - Custom domain of the site, must be configured using a CNAME in accordance with [Netlify's docs](https://www.netlify.com/docs/custom-domains). (e.g. `www.example.com`)
* `domain_aliases` - (Optional) - List of extra domain aliases for the site, must be configured using a CNAME in accordance with [Netlify's docs](https://www.netlify.com/docs/custom-domains). (e.g. `www.example.com`)
* `deploy_url` - (Optional)

### Repository
Expand Down