Skip to content
This repository was archived by the owner on Dec 9, 2020. It is now read-only.
Merged
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
20 changes: 10 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,17 @@ test-compile:
go test -c $(TEST) $(TESTARGS)

website:
ifeq (,$(wildcard $(GOPATH)/src/$(WEBSITE_REPO)))
echo "$(WEBSITE_REPO) not found in your GOPATH (necessary for layouts and assets), get-ting..."
git clone https://$(WEBSITE_REPO) $(GOPATH)/src/$(WEBSITE_REPO)
endif
@$(MAKE) -C $(GOPATH)/src/$(WEBSITE_REPO) website-provider PROVIDER_PATH=$(shell pwd) PROVIDER_NAME=$(PKG_NAME)
ifeq (,$(wildcard $(GOPATH)/src/$(WEBSITE_REPO)))
echo "$(WEBSITE_REPO) not found in your GOPATH (necessary for layouts and assets), get-ting..."
git clone https://$(WEBSITE_REPO) $(GOPATH)/src/$(WEBSITE_REPO)
endif
@$(MAKE) -C $(GOPATH)/src/$(WEBSITE_REPO) website-provider PROVIDER_PATH=$(shell pwd) PROVIDER_NAME=$(PKG_NAME)

website-test:
ifeq (,$(wildcard $(GOPATH)/src/$(WEBSITE_REPO)))
echo "$(WEBSITE_REPO) not found in your GOPATH (necessary for layouts and assets), get-ting..."
git clone https://$(WEBSITE_REPO) $(GOPATH)/src/$(WEBSITE_REPO)
endif
@$(MAKE) -C $(GOPATH)/src/$(WEBSITE_REPO) website-provider-test PROVIDER_PATH=$(shell pwd) PROVIDER_NAME=$(PKG_NAME)
ifeq (,$(wildcard $(GOPATH)/src/$(WEBSITE_REPO)))
echo "$(WEBSITE_REPO) not found in your GOPATH (necessary for layouts and assets), get-ting..."
git clone https://$(WEBSITE_REPO) $(GOPATH)/src/$(WEBSITE_REPO)
endif
@$(MAKE) -C $(GOPATH)/src/$(WEBSITE_REPO) website-provider-test PROVIDER_PATH=$(shell pwd) PROVIDER_NAME=$(PKG_NAME)

.PHONY: build test testacc vet fmt fmtcheck errcheck vendor-status test-compile website website-test
43 changes: 37 additions & 6 deletions netlify/resource_site.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ func resourceSite() *schema.Resource {
Computed: true,
},

"account_slug": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},

"account_name": {
Type: schema.TypeString,
Computed: true,
},

"repo": {
Type: schema.TypeList,
MaxItems: 1,
Expand Down Expand Up @@ -78,15 +89,33 @@ func resourceSite() *schema.Resource {
func resourceSiteCreate(d *schema.ResourceData, metaRaw interface{}) error {
meta := metaRaw.(*Meta)

params := operations.NewCreateSiteParams()
params.Site = resourceSite_setupStruct(d)
// If we have an "account_slug" set we use a different API path that lets
// us create a site in a specific team. Unfortunately we have to duplicate
// a lot of stuff because the types are totally different even though
// structurally they are identical.
var site *models.Site
if v, ok := d.GetOk("account_slug"); ok {
params := operations.NewCreateSiteInTeamParams()
params.AccountSlug = v.(string)
params.Site = resourceSite_setupStruct(d)
resp, err := meta.Netlify.Operations.CreateSiteInTeam(params, meta.AuthInfo)
if err != nil {
return err
}

resp, err := meta.Netlify.Operations.CreateSite(params, meta.AuthInfo)
if err != nil {
return err
site = resp.Payload
} else {
params := operations.NewCreateSiteParams()
params.Site = resourceSite_setupStruct(d)
resp, err := meta.Netlify.Operations.CreateSite(params, meta.AuthInfo)
if err != nil {
return err
}

site = resp.Payload
}

d.SetId(resp.Payload.ID)
d.SetId(site.ID)
return resourceSiteRead(d, metaRaw)
}

Expand All @@ -109,6 +138,8 @@ func resourceSiteRead(d *schema.ResourceData, metaRaw interface{}) error {
d.Set("name", site.Name)
d.Set("custom_domain", site.CustomDomain)
d.Set("deploy_url", site.DeployURL)
d.Set("account_slug", site.AccountSlug)
d.Set("account_name", site.AccountName)
d.Set("repo", nil)

if site.BuildSettings != nil {
Expand Down