Skip to content

Commit 5dd4869

Browse files
authored
fix sub-account 'read' method (#197)
1 parent 39a5eb7 commit 5dd4869

File tree

2 files changed

+28
-13
lines changed

2 files changed

+28
-13
lines changed

incapsula/client_subaccount.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func (c *Client) AddSubAccount(subAccountPayload *SubAccountPayload) (*SubAccoun
105105
// GetSubAccount gets the Incapsula list of SubAccounts
106106
func (c *Client) GetSubAccount(parentAccountID int, subAccountID int) (*SubAccount, error) {
107107

108-
log.Printf("[INFO] Reading Incapsula subaccounts for id: %d)", subAccountID)
108+
log.Printf("[INFO] Reading Incapsula subaccounts for id: %d", subAccountID)
109109

110110
var count = 0
111111
var shouldFetch = true

incapsula/resource_subaccount.go

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -93,26 +93,41 @@ func resourceSubAccountCreate(d *schema.ResourceData, m interface{}) error {
9393

9494
func resourceSubAccountRead(d *schema.ResourceData, m interface{}) error {
9595
client := m.(*Client)
96-
subAccountID, _ := strconv.Atoi(d.Id())
97-
subAccount, err := client.GetSubAccount(d.Get("parent_id").(int), subAccountID)
9896

99-
if err != nil {
100-
return err
101-
}
97+
accountID, _ := strconv.Atoi(d.Id())
10298

103-
if subAccount == nil {
104-
log.Printf("[INFO] Incapsula subaccount %s has already been deleted: %s\n", d.Id(), err)
99+
log.Printf("[INFO] Reading Incapsula account for Account ID: %d\n", accountID)
100+
101+
accountStatusResponse, err := client.AccountStatus(accountID)
102+
103+
// Account object may have been deleted
104+
if accountStatusResponse != nil && accountStatusResponse.Res.(float64) == 9403 {
105+
log.Printf("[INFO] Incapsula Account ID %d has already been deleted: %s\n", accountID, err)
105106
d.SetId("")
106107
return nil
107108
}
108109

109-
d.Set("sub_account_name", subAccount.SubAccountName)
110-
d.Set("ref_id", subAccount.RefID)
111-
d.Set("log_level", subAccount.LogLevel)
112-
d.Set("parent_id", subAccount.ParentID)
113-
d.Set("logs_account_id", subAccount.LogsAccountID)
110+
if err != nil {
111+
log.Printf("[ERROR] Could not read Incapsula subaccount for Account ID: %d, %s\n", accountID, err)
112+
return err
113+
}
114+
115+
d.Set("sub_account_name", accountStatusResponse.Account.AccountName)
116+
d.Set("ref_id", accountStatusResponse.Account.RefID)
117+
//d.Set("log_level", accountStatusResponse.Account.)
118+
d.Set("parent_id", accountStatusResponse.Account.ParentID)
119+
//d.Set("logs_account_id", accountStatusResponse.Account.LogsAccountID)
114120

115121
log.Printf("[INFO] Finished reading Incapsula subaccount: %s\n", d.Id())
122+
// Get the performance settings for the site
123+
defaultAccountDataStorageRegion, err := client.GetAccountDataStorageRegion(d.Id())
124+
if err != nil {
125+
log.Printf("[ERROR] Could not read Incapsula default data storage region for account id: %d, %s\n", accountID, err)
126+
return err
127+
}
128+
d.Set("data_storage_region", defaultAccountDataStorageRegion.Region)
129+
130+
log.Printf("[INFO] Finished reading Incapsula account for account ud: %d\n", accountID)
116131

117132
return nil
118133
}

0 commit comments

Comments
 (0)