Skip to content

Commit aa6b967

Browse files
ashimpthlsashimpthls
andauthored
account_id musnt be changed on update of site (#605)
Co-authored-by: ashimpthls <ashwinsubramaniam.hariharan@imperva.com>
1 parent 2ee2e28 commit aa6b967

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

incapsula/resource_site_v3.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ package incapsula
33
import (
44
"context"
55
"fmt"
6-
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
7-
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
86
"log"
97
"strconv"
108
"strings"
9+
10+
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
11+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1112
)
1213

1314
func resourceSiteV3() *schema.Resource {
@@ -16,6 +17,12 @@ func resourceSiteV3() *schema.Resource {
1617
ReadContext: resourceSiteV3Read,
1718
UpdateContext: resourceSiteV3Update,
1819
DeleteContext: resourceSiteV3Delete,
20+
CustomizeDiff: func(ctx context.Context, d *schema.ResourceDiff, m interface{}) error {
21+
if d.HasChange("account_id") {
22+
return fmt.Errorf("account_id cannot be updated for an existing site")
23+
}
24+
return nil
25+
},
1926
Importer: &schema.ResourceImporter{
2027
State: func(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
2128

incapsula/resource_site_v3_test.go

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ package incapsula
22

33
import (
44
"fmt"
5+
"math/rand"
56
"os"
7+
"regexp"
68
"strconv"
79
"testing"
810
"time"
911

1012
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
1113
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
12-
"math/rand"
1314
)
1415

1516
const siteV3ResourceName = "incapsula_site_v3.test-terraform-site-v3"
@@ -98,6 +99,27 @@ func TestIncapsulaSiteV3_isActive(t *testing.T) {
9899
})
99100
}
100101

102+
func TestIncapsulaSiteV3_AccountIdUpdateFails(t *testing.T) {
103+
resource.Test(t, resource.TestCase{
104+
Providers: testAccProviders,
105+
CheckDestroy: testCheckIncapsulaSiteV3Destroy,
106+
Steps: []resource.TestStep{
107+
{
108+
Config: testCheckIncapsulaSiteV3ConfigBasic(GenerateTestSiteName(nil), "CLOUD_WAF", ""),
109+
Check: resource.ComposeTestCheckFunc(
110+
testCheckIncapsulaSiteExists(siteV3ResourceName),
111+
resource.TestCheckResourceAttr(siteV3ResourceName, "name", siteName),
112+
resource.TestCheckResourceAttr(siteV3ResourceName, "type", "CLOUD_WAF"),
113+
),
114+
},
115+
{
116+
Config: testCheckIncapsulaSiteV3ConfigWithAccountId(siteName, "CLOUD_WAF", "999999"),
117+
ExpectError: regexp.MustCompile("account_id cannot be updated for an existing site"),
118+
},
119+
},
120+
})
121+
}
122+
101123
func testCheckIncapsulaSiteV3Destroy(state *terraform.State) error {
102124
client := testAccProvider.Meta().(*Client)
103125

@@ -141,6 +163,19 @@ func testCheckIncapsulaSiteV3ConfigBasic(name string, siteType string, extraAttr
141163
)
142164
}
143165

166+
func testCheckIncapsulaSiteV3ConfigWithAccountId(name string, siteType string, accountId string) string {
167+
return fmt.Sprintf(`
168+
resource "incapsula_site_v3" "test-terraform-site-v3" {
169+
name = "%s"
170+
type = "%s"
171+
account_id = "%s"
172+
}`,
173+
name,
174+
siteType,
175+
accountId,
176+
)
177+
}
178+
144179
func testSiteV3Importer(s *terraform.State) (string, error) {
145180
for _, rs := range s.RootModule().Resources {
146181

0 commit comments

Comments
 (0)