Skip to content

Commit 64e13e4

Browse files
Added importer to site domain configuration (#408)
1 parent 8171ec1 commit 64e13e4

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

incapsula/client_site_domain_configuration.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ type ApiErrorResponse struct {
7777

7878
func (c *Client) GetWebsiteDomains(siteId string) (*SiteDomainDetailsDto, error) {
7979
reqURL := fmt.Sprintf("%s%s%s%s", c.config.BaseURLAPI, endpointDomainManagement, siteId, "/domains")
80-
if siteId != "" {
80+
if siteId == "" {
8181
fmt.Errorf("[ERROR] site ID was not provided")
8282
}
8383
var params = map[string]string{}

incapsula/resource_site_domain_configuration.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,18 @@ func resourceSiteDomainConfiguration() *schema.Resource {
1616
Delete: resourceDomainDelete,
1717
Update: resourceDomainUpdate,
1818
Importer: &schema.ResourceImporter{
19-
StateContext: schema.ImportStatePassthroughContext,
19+
State: func(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
20+
d.Set("site_id", d.Id())
21+
d.SetId(d.Id())
22+
return []*schema.ResourceData{d}, nil
23+
},
2024
},
2125
Schema: map[string]*schema.Schema{
2226
"site_id": {
2327
Description: "Numeric identifier of the site to operate on.",
2428
Type: schema.TypeString,
2529
Required: true,
30+
ForceNew: true,
2631
},
2732
"cname_redirection_record": {
2833
Description: "Cname record for traffic redirection. Point your domain's DNS to this record in order to forward the traffic to Imperva",
@@ -131,9 +136,11 @@ func resourceDomainRead(d *schema.ResourceData, m interface{}) error {
131136
domains.Add(domain)
132137
}
133138
d.SetId(d.Get("site_id").(string))
134-
d.Set("site_id", d.Get("site_id"))
135-
d.Set("cname_redirection_record", siteDomainDetailsDto.Data[0].CnameRedirectionRecord)
136-
d.Set("domain", domains)
139+
if len(siteDomainDetailsDto.Data) > 0 {
140+
d.Set("cname_redirection_record", siteDomainDetailsDto.Data[0].CnameRedirectionRecord)
141+
d.Set("domain", domains)
142+
}
143+
137144
return nil
138145
}
139146

0 commit comments

Comments
 (0)