@@ -93,26 +93,41 @@ func resourceSubAccountCreate(d *schema.ResourceData, m interface{}) error {
9393
9494func 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