Skip to content

Commit

Permalink
deprecating account id for incapsula_policy use incapsula_account_pol…
Browse files Browse the repository at this point in the history
…icy_association instead (#400)

* #CWMS-3818
setting the account id according to resource file in case its provided

* #CWMS-3818
setting the account id according to resource file in case its provided

* #CWMS-3818
setting the account id according to resource file in case its provided

---------

Co-authored-by: nir-parizer-Imperva <[email protected]>
  • Loading branch information
snirp90 and nir-parizer-Imperva authored Mar 19, 2024
1 parent 226c513 commit 85b7d5c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
11 changes: 9 additions & 2 deletions incapsula/resource_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func resourcePolicy() *schema.Resource {
"account_id": {
Description: "The Account ID of the policy.",
Type: schema.TypeInt,
Deprecated: "Use the incapsula_account_policy_association resource instead",
Computed: true,
Optional: true,
ForceNew: true,
Expand Down Expand Up @@ -138,7 +139,11 @@ func resourcePolicyRead(d *schema.ResourceData, m interface{}) error {
d.Set("enabled", policyGetResponse.Value.Enabled)
d.Set("policy_type", policyGetResponse.Value.PolicyType)
d.Set("description", policyGetResponse.Value.Description)
d.Set("account_id", policyGetResponse.Value.AccountID)
if d.Get("account_id") != nil {
d.Set("account_id", d.Get("account_id"))
} else {
d.Set("account_id", policyGetResponse.Value.AccountID)
}

// JSON encode policy settings
policySettingsJSONBytes, err := json.MarshalIndent(policyGetResponse.Value.PolicySettings, "", " ")
Expand All @@ -158,7 +163,9 @@ func resourcePolicyUpdate(d *schema.ResourceData, m interface{}) error {
if err != nil {
return err
}

if d.Get("account_id") != nil {
log.Printf("[WARN] Incapsula policy account id attribute is deprecated - please remove it\n")
}
policySettingsString := d.Get("policy_settings").(string)
var policySettings []PolicySetting
err = json.Unmarshal([]byte(policySettingsString), &policySettings)
Expand Down
1 change: 0 additions & 1 deletion website/docs/r/policy.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ resource "incapsula_policy" "example-whitelist-ip-policy" {
}
resource "incapsula_policy" "example-acl-country-block-policy" {
# account_id = var.account_id //should not be defined
description = "EXAMPLE ACL Block Countries based on attack."
enabled = true
policy_type = "ACL"
Expand Down

0 comments on commit 85b7d5c

Please sign in to comment.