From 548a93ec88d4fcfd0d3592d3d236ad6dbbc19e93 Mon Sep 17 00:00:00 2001 From: Sugata Mazumdar Date: Mon, 4 Apr 2022 20:31:05 +0530 Subject: [PATCH 1/9] SCC-PostureManagement Create scope issue Create scope issue --- ibm/service/scc/resource_ibm_scc_posture_scope.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ibm/service/scc/resource_ibm_scc_posture_scope.go b/ibm/service/scc/resource_ibm_scc_posture_scope.go index a2b3445207..8b49dff9c7 100644 --- a/ibm/service/scc/resource_ibm_scc_posture_scope.go +++ b/ibm/service/scc/resource_ibm_scc_posture_scope.go @@ -114,7 +114,12 @@ func resourceIBMSccPostureScopesCreate(context context.Context, d *schema.Resour createScopeOptions.SetName(d.Get("name").(string)) createScopeOptions.SetDescription(d.Get("description").(string)) - createScopeOptions.SetCollectorIds([]string{"4188"}) //[]string{ + collector_ids_int := d.Get("collector_ids").([]interface{}) + collector_ids := make([]string, len(collector_ids_int)) + for i, collector_id := range collector_ids_int { + collector_ids[i] = collector_id.(string) + } + createScopeOptions.SetCollectorIds(collector_ids) //[]string{ createScopeOptions.SetCredentialID(d.Get("credential_id").(string)) createScopeOptions.SetCredentialType(d.Get("credential_type").(string)) From d5af6917f0a087a3b6fd7f0bd2a045644cf8895f Mon Sep 17 00:00:00 2001 From: Sugata Mazumdar Date: Wed, 6 Apr 2022 12:00:45 +0530 Subject: [PATCH 2/9] SCC-PostureManagement Collector ID, Account ID fix Collector ID issue in resourceIBMSccPostureCollectorsRead and Account Id issue --- .../scc/resource_ibm_scc_posture_collector.go | 34 +++++++++++++------ 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/ibm/service/scc/resource_ibm_scc_posture_collector.go b/ibm/service/scc/resource_ibm_scc_posture_collector.go index ffb53b718f..f3d987c0e1 100644 --- a/ibm/service/scc/resource_ibm_scc_posture_collector.go +++ b/ibm/service/scc/resource_ibm_scc_posture_collector.go @@ -7,7 +7,6 @@ import ( "context" "fmt" "log" - "os" "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" "github.com/IBM-Cloud/terraform-provider-ibm/ibm/validate" @@ -115,7 +114,12 @@ func resourceIBMSccPostureCollectorsCreate(context context.Context, d *schema.Re } createCollectorOptions := &posturemanagementv2.CreateCollectorOptions{} - createCollectorOptions.SetAccountID(os.Getenv("SCC_POSTURE_ACCOUNT_ID")) + + userDetails, err := meta.(conns.ClientSession).BluemixUserDetails() + if err != nil { + return diag.FromErr(fmt.Errorf("[ERROR] Error getting userDetails %s", err)) + } + createCollectorOptions.SetAccountID(userDetails.UserAccount) createCollectorOptions.SetName(d.Get("name").(string)) createCollectorOptions.SetIsPublic(d.Get("is_public").(bool)) @@ -147,25 +151,25 @@ func resourceIBMSccPostureCollectorsRead(context context.Context, d *schema.Reso return diag.FromErr(err) } - listCollectorsOptions := &posturemanagementv2.ListCollectorsOptions{} + getCollectorsOptions := &posturemanagementv2.GetCollectorOptions{} userDetails, err := meta.(conns.ClientSession).BluemixUserDetails() if err != nil { return diag.FromErr(fmt.Errorf("[ERROR] Error getting userDetails %s", err)) } accountID := userDetails.UserAccount - listCollectorsOptions.SetAccountID(accountID) + getCollectorsOptions.SetAccountID(accountID) - collectorList, response, err := postureManagementClient.ListCollectorsWithContext(context, listCollectorsOptions) + collector, response, err := postureManagementClient.GetCollectorWithContext(context, getCollectorsOptions) if err != nil { if response != nil && response.StatusCode == 404 { d.SetId("") return nil } - log.Printf("[DEBUG] ListCollectorsWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("ListCollectorsWithContext failed %s\n%s", err, response)) + log.Printf("[DEBUG] GetCollectorWithContext failed %s\n%s", err, response) + return diag.FromErr(fmt.Errorf("GetCollectorWithContext failed %s\n%s", err, response)) } - d.SetId(*(collectorList.Collectors[0].ID)) + d.SetId(*(collector.ID)) return nil } @@ -176,7 +180,12 @@ func resourceIBMSccPostureCollectorsUpdate(context context.Context, d *schema.Re } updateCollectorOptions := &posturemanagementv2.UpdateCollectorOptions{} - updateCollectorOptions.SetAccountID(os.Getenv("SCC_POSTURE_ACCOUNT_ID")) + + userDetails, err := meta.(conns.ClientSession).BluemixUserDetails() + if err != nil { + return diag.FromErr(fmt.Errorf("[ERROR] Error getting userDetails %s", err)) + } + updateCollectorOptions.SetAccountID(userDetails.UserAccount) updateCollectorOptions.SetID(d.Id()) @@ -201,7 +210,12 @@ func resourceIBMSccPostureCollectorsDelete(context context.Context, d *schema.Re } deleteCollectorOptions := &posturemanagementv2.DeleteCollectorOptions{} - deleteCollectorOptions.SetAccountID(os.Getenv("SCC_POSTURE_ACCOUNT_ID")) + + userDetails, err := meta.(conns.ClientSession).BluemixUserDetails() + if err != nil { + return diag.FromErr(fmt.Errorf("[ERROR] Error getting userDetails %s", err)) + } + deleteCollectorOptions.SetAccountID(userDetails.UserAccount) deleteCollectorOptions.SetID(d.Id()) From 3cd54ba875e32fd6162615ff806395a5c3c001e2 Mon Sep 17 00:00:00 2001 From: Sugata Mazumdar Date: Wed, 6 Apr 2022 12:04:50 +0530 Subject: [PATCH 3/9] SCC-PostureManagement Account ID fix Account Id issue from client session and not env var. --- .../resource_ibm_scc_posture_collector_test.go | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/ibm/service/scc/resource_ibm_scc_posture_collector_test.go b/ibm/service/scc/resource_ibm_scc_posture_collector_test.go index e0469328fc..e9de21e39e 100644 --- a/ibm/service/scc/resource_ibm_scc_posture_collector_test.go +++ b/ibm/service/scc/resource_ibm_scc_posture_collector_test.go @@ -5,7 +5,6 @@ package scc_test import ( "fmt" - "os" "testing" "time" @@ -143,7 +142,13 @@ func testAccCheckIBMSccPostureCollectorsExists(n string, obj posturemanagementv2 } listCollectorsOptions := &posturemanagementv2.ListCollectorsOptions{} - listCollectorsOptions.SetAccountID(os.Getenv("SCC_POSTURE_ACCOUNT_ID")) + + userDetails, err := acc.TestAccProvider.Meta().(conns.ClientSession).BluemixUserDetails() + if err != nil { + return err + } + + listCollectorsOptions.SetAccountID(userDetails.UserAccount) newCollector, _, err := postureManagementClient.ListCollectors(listCollectorsOptions) if err != nil { @@ -166,7 +171,13 @@ func testAccCheckIBMSccPostureCollectorsDestroy(s *terraform.State) error { } listCollectorsOptions := &posturemanagementv2.ListCollectorsOptions{} - listCollectorsOptions.SetAccountID(os.Getenv("SCC_POSTURE_ACCOUNT_ID")) + + userDetails, err := acc.TestAccProvider.Meta().(conns.ClientSession).BluemixUserDetails() + if err != nil { + return err + } + + listCollectorsOptions.SetAccountID(userDetails.UserAccount) // Try to find the key _, response, err := postureManagementClient.ListCollectors(listCollectorsOptions) From ae82e4a93ec8abc1b077734029ef83ff97227dfd Mon Sep 17 00:00:00 2001 From: Sugata Mazumdar Date: Wed, 6 Apr 2022 12:08:39 +0530 Subject: [PATCH 4/9] SCC-PostureManagement Account ID fix Account Id issue from client session and not env var. --- .../resource_ibm_scc_posture_credential_test.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/ibm/service/scc/resource_ibm_scc_posture_credential_test.go b/ibm/service/scc/resource_ibm_scc_posture_credential_test.go index 7ff1f38945..eecafcad3c 100644 --- a/ibm/service/scc/resource_ibm_scc_posture_credential_test.go +++ b/ibm/service/scc/resource_ibm_scc_posture_credential_test.go @@ -5,7 +5,6 @@ package scc_test import ( "fmt" - "os" "testing" acc "github.com/IBM-Cloud/terraform-provider-ibm/ibm/acctest" @@ -101,7 +100,13 @@ func testAccCheckIBMSccPostureCredentialsExists(n string, obj posturemanagementv } listCredentialsOptions := &posturemanagementv2.ListCredentialsOptions{} - listCredentialsOptions.SetAccountID(os.Getenv("SCC_POSTURE_ACCOUNT_ID")) + + userDetails, err := acc.TestAccProvider.Meta().(conns.ClientSession).BluemixUserDetails() + if err != nil { + return err + } + + listCredentialsOptions.SetAccountID(userDetails.UserAccount) newCredential, _, err := postureManagementClient.ListCredentials(listCredentialsOptions) if err != nil { @@ -124,7 +129,12 @@ func testAccCheckIBMSccPostureCredentialsDestroy(s *terraform.State) error { } listCredentialsOptions := &posturemanagementv2.ListCredentialsOptions{} - listCredentialsOptions.SetAccountID(os.Getenv("SCC_POSTURE_ACCOUNT_ID")) + + userDetails, err := acc.TestAccProvider.Meta().(conns.ClientSession).BluemixUserDetails() + if err != nil { + return err + } + listCredentialsOptions.SetAccountID(userDetails.UserAccount) // Try to find the key _, response, err := postureManagementClient.ListCredentials(listCredentialsOptions) From 61db0496389d130b1f4a1012588f29c6577c0e2f Mon Sep 17 00:00:00 2001 From: Sugata Mazumdar Date: Wed, 6 Apr 2022 12:15:44 +0530 Subject: [PATCH 5/9] SCC-PostureManagement Cred ID, Account ID fix Cred ID issue in resourceIBMSccPostureCredentialsRead and Account Id issue --- .../resource_ibm_scc_posture_credential.go | 34 +++++++++++++------ 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/ibm/service/scc/resource_ibm_scc_posture_credential.go b/ibm/service/scc/resource_ibm_scc_posture_credential.go index b6403ef5c8..c48fc990dc 100644 --- a/ibm/service/scc/resource_ibm_scc_posture_credential.go +++ b/ibm/service/scc/resource_ibm_scc_posture_credential.go @@ -7,7 +7,6 @@ import ( "context" "fmt" "log" - "os" "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" "github.com/IBM-Cloud/terraform-provider-ibm/ibm/validate" @@ -148,7 +147,12 @@ func resourceIBMSccPostureCredentialsCreate(context context.Context, d *schema.R } createCredentialOptions := &posturemanagementv2.CreateCredentialOptions{} - createCredentialOptions.SetAccountID(os.Getenv("SCC_POSTURE_ACCOUNT_ID")) + + userDetails, err := meta.(conns.ClientSession).BluemixUserDetails() + if err != nil { + return diag.FromErr(fmt.Errorf("[ERROR] Error getting userDetails %s", err)) + } + createCredentialOptions.SetAccountID(userDetails.UserAccount) createCredentialOptions.SetEnabled(d.Get("enabled").(bool)) createCredentialOptions.SetType(d.Get("type").(string)) @@ -206,25 +210,25 @@ func resourceIBMSccPostureCredentialsRead(context context.Context, d *schema.Res return diag.FromErr(err) } - listCredentialsOptions := &posturemanagementv2.ListCredentialsOptions{} + getCredentialsOptions := &posturemanagementv2.GetCredentialOptions{} userDetails, err := meta.(conns.ClientSession).BluemixUserDetails() if err != nil { return diag.FromErr(fmt.Errorf("[ERROR] Error getting userDetails %s", err)) } accountID := userDetails.UserAccount - listCredentialsOptions.SetAccountID(accountID) + getCredentialsOptions.SetAccountID(accountID) - credentialList, response, err := postureManagementClient.ListCredentialsWithContext(context, listCredentialsOptions) + credential, response, err := postureManagementClient.GetCredentialWithContext(context, getCredentialsOptions) if err != nil { if response != nil && response.StatusCode == 404 { d.SetId("") return nil } - log.Printf("[DEBUG] ListCredentialsWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("ListCredentialsWithContext failed %s\n%s", err, response)) + log.Printf("[DEBUG] GetCredentialWithContext failed %s\n%s", err, response) + return diag.FromErr(fmt.Errorf("GetCredentialWithContext failed %s\n%s", err, response)) } - d.SetId(*(credentialList.Credentials[0].ID)) + d.SetId(*(credential.ID)) return nil } @@ -254,7 +258,12 @@ func resourceIBMSccPostureCredentialsUpdate(context context.Context, d *schema.R } updateCredentialOptions := &posturemanagementv2.UpdateCredentialOptions{} - updateCredentialOptions.SetAccountID(os.Getenv("SCC_POSTURE_ACCOUNT_ID")) + + userDetails, err := meta.(conns.ClientSession).BluemixUserDetails() + if err != nil { + return diag.FromErr(fmt.Errorf("[ERROR] Error getting userDetails %s", err)) + } + updateCredentialOptions.SetAccountID(userDetails.UserAccount) updateCredentialOptions.SetID(d.Id()) @@ -290,7 +299,12 @@ func resourceIBMSccPostureCredentialsDelete(context context.Context, d *schema.R } deleteCredentialOptions := &posturemanagementv2.DeleteCredentialOptions{} - deleteCredentialOptions.SetAccountID(os.Getenv("SCC_POSTURE_ACCOUNT_ID")) + + userDetails, err := meta.(conns.ClientSession).BluemixUserDetails() + if err != nil { + return diag.FromErr(fmt.Errorf("[ERROR] Error getting userDetails %s", err)) + } + deleteCredentialOptions.SetAccountID(userDetails.UserAccount) deleteCredentialOptions.SetID(d.Id()) From 06b60be45fea696c206952769f13604cd06b413a Mon Sep 17 00:00:00 2001 From: Sugata Mazumdar Date: Wed, 6 Apr 2022 12:21:36 +0530 Subject: [PATCH 6/9] SCC-PostureManagement Account ID fix Account Id issue from client session and not env var. --- .../scc/resource_ibm_scc_posture_scope_test.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/ibm/service/scc/resource_ibm_scc_posture_scope_test.go b/ibm/service/scc/resource_ibm_scc_posture_scope_test.go index 73c9ebd09e..b7fc51f836 100644 --- a/ibm/service/scc/resource_ibm_scc_posture_scope_test.go +++ b/ibm/service/scc/resource_ibm_scc_posture_scope_test.go @@ -5,7 +5,6 @@ package scc_test import ( "fmt" - "os" "testing" "time" @@ -136,7 +135,12 @@ func testAccCheckIBMSccPostureScopesExists(n string, obj posturemanagementv2.Sco } listScopesOptions := &posturemanagementv2.ListScopesOptions{} - listScopesOptions.SetAccountID(os.Getenv("SCC_POSTURE_ACCOUNT_ID")) + + userDetails, err := acc.TestAccProvider.Meta().(conns.ClientSession).BluemixUserDetails() + if err != nil { + return err + } + listScopesOptions.SetAccountID(userDetails.UserAccount) newScope, _, err := postureManagementClient.ListScopes(listScopesOptions) if err != nil { @@ -159,7 +163,13 @@ func testAccCheckIBMSccPostureScopesDestroy(s *terraform.State) error { } listScopesOptions := &posturemanagementv2.ListScopesOptions{} - listScopesOptions.SetAccountID(os.Getenv("SCC_POSTURE_ACCOUNT_ID")) + + userDetails, err := acc.TestAccProvider.Meta().(conns.ClientSession).BluemixUserDetails() + if err != nil { + return err + } + + listScopesOptions.SetAccountID(userDetails.UserAccount) // Try to find the key _, response, err := postureManagementClient.ListScopes(listScopesOptions) From 31855041087a757c1c5ae85f3b184d9c84a2e7b9 Mon Sep 17 00:00:00 2001 From: Sugata Mazumdar Date: Wed, 6 Apr 2022 12:31:30 +0530 Subject: [PATCH 7/9] SCC-PostureManagement Scope ID, Account ID fix Scope ID issue in resourceIBMSccPostureScopesRead and Account Id issue --- .../scc/resource_ibm_scc_posture_scope.go | 34 +++++++++++++------ 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/ibm/service/scc/resource_ibm_scc_posture_scope.go b/ibm/service/scc/resource_ibm_scc_posture_scope.go index 8b49dff9c7..1047354103 100644 --- a/ibm/service/scc/resource_ibm_scc_posture_scope.go +++ b/ibm/service/scc/resource_ibm_scc_posture_scope.go @@ -7,7 +7,6 @@ import ( "context" "fmt" "log" - "os" "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" "github.com/IBM-Cloud/terraform-provider-ibm/ibm/validate" @@ -110,7 +109,12 @@ func resourceIBMSccPostureScopesCreate(context context.Context, d *schema.Resour } createScopeOptions := &posturemanagementv2.CreateScopeOptions{} - createScopeOptions.SetAccountID(os.Getenv("SCC_POSTURE_ACCOUNT_ID")) + + userDetails, err := meta.(conns.ClientSession).BluemixUserDetails() + if err != nil { + return diag.FromErr(fmt.Errorf("[ERROR] Error getting userDetails %s", err)) + } + createScopeOptions.SetAccountID(userDetails.UserAccount) createScopeOptions.SetName(d.Get("name").(string)) createScopeOptions.SetDescription(d.Get("description").(string)) @@ -140,24 +144,24 @@ func resourceIBMSccPostureScopesRead(context context.Context, d *schema.Resource return diag.FromErr(err) } - listScopesOptions := &posturemanagementv2.ListScopesOptions{} + getScopesOptions := &posturemanagementv2.GetScopeDetailsOptions{} userDetails, err := meta.(conns.ClientSession).BluemixUserDetails() if err != nil { return diag.FromErr(fmt.Errorf("[ERROR] Error getting userDetails %s", err)) } accountID := userDetails.UserAccount - listScopesOptions.SetAccountID(accountID) + getScopesOptions.SetAccountID(accountID) - scopeList, response, err := postureManagementClient.ListScopesWithContext(context, listScopesOptions) - d.SetId(*(scopeList.Scopes[0].ID)) + scope, response, err := postureManagementClient.GetScopeDetailsWithContext(context, getScopesOptions) + d.SetId(*(scope.ID)) if err != nil { if response != nil && response.StatusCode == 404 { d.SetId("") return nil } - log.Printf("[DEBUG] ListScopesWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("ListScopesWithContext failed %s\n%s", err, response)) + log.Printf("[DEBUG] GetScopeDetailsWithContext failed %s\n%s", err, response) + return diag.FromErr(fmt.Errorf("GetScopeDetailsWithContext failed %s\n%s", err, response)) } return nil @@ -170,7 +174,12 @@ func resourceIBMSccPostureScopesUpdate(context context.Context, d *schema.Resour } updateScopeDetailsOptions := &posturemanagementv2.UpdateScopeDetailsOptions{} - updateScopeDetailsOptions.SetAccountID(os.Getenv("SCC_POSTURE_ACCOUNT_ID")) + + userDetails, err := meta.(conns.ClientSession).BluemixUserDetails() + if err != nil { + return diag.FromErr(fmt.Errorf("[ERROR] Error getting userDetails %s", err)) + } + updateScopeDetailsOptions.SetAccountID(userDetails.UserAccount) hasChange := false @@ -203,7 +212,12 @@ func resourceIBMSccPostureScopesDelete(context context.Context, d *schema.Resour } deleteScopeOptions := &posturemanagementv2.DeleteScopeOptions{} - deleteScopeOptions.SetAccountID(os.Getenv("SCC_POSTURE_ACCOUNT_ID")) + + userDetails, err := meta.(conns.ClientSession).BluemixUserDetails() + if err != nil { + return diag.FromErr(fmt.Errorf("[ERROR] Error getting userDetails %s", err)) + } + deleteScopeOptions.SetAccountID(userDetails.UserAccount) deleteScopeOptions.SetID(d.Id()) From 17c059d15b09a5b1811d0f7da3080a19a0b8ad0b Mon Sep 17 00:00:00 2001 From: Sugata Mazumdar Date: Thu, 7 Apr 2022 11:20:04 +0530 Subject: [PATCH 8/9] Add format code --- .../scc/resource_ibm_scc_posture_collector.go | 6 +++--- .../resource_ibm_scc_posture_collector_test.go | 4 ++-- .../scc/resource_ibm_scc_posture_credential.go | 6 +++--- .../resource_ibm_scc_posture_credential_test.go | 4 ++-- .../scc/resource_ibm_scc_posture_scope.go | 16 ++++++++-------- .../scc/resource_ibm_scc_posture_scope_test.go | 4 ++-- 6 files changed, 20 insertions(+), 20 deletions(-) diff --git a/ibm/service/scc/resource_ibm_scc_posture_collector.go b/ibm/service/scc/resource_ibm_scc_posture_collector.go index f3d987c0e1..5ae301a672 100644 --- a/ibm/service/scc/resource_ibm_scc_posture_collector.go +++ b/ibm/service/scc/resource_ibm_scc_posture_collector.go @@ -114,7 +114,7 @@ func resourceIBMSccPostureCollectorsCreate(context context.Context, d *schema.Re } createCollectorOptions := &posturemanagementv2.CreateCollectorOptions{} - + userDetails, err := meta.(conns.ClientSession).BluemixUserDetails() if err != nil { return diag.FromErr(fmt.Errorf("[ERROR] Error getting userDetails %s", err)) @@ -180,7 +180,7 @@ func resourceIBMSccPostureCollectorsUpdate(context context.Context, d *schema.Re } updateCollectorOptions := &posturemanagementv2.UpdateCollectorOptions{} - + userDetails, err := meta.(conns.ClientSession).BluemixUserDetails() if err != nil { return diag.FromErr(fmt.Errorf("[ERROR] Error getting userDetails %s", err)) @@ -210,7 +210,7 @@ func resourceIBMSccPostureCollectorsDelete(context context.Context, d *schema.Re } deleteCollectorOptions := &posturemanagementv2.DeleteCollectorOptions{} - + userDetails, err := meta.(conns.ClientSession).BluemixUserDetails() if err != nil { return diag.FromErr(fmt.Errorf("[ERROR] Error getting userDetails %s", err)) diff --git a/ibm/service/scc/resource_ibm_scc_posture_collector_test.go b/ibm/service/scc/resource_ibm_scc_posture_collector_test.go index e9de21e39e..e1a1f22b14 100644 --- a/ibm/service/scc/resource_ibm_scc_posture_collector_test.go +++ b/ibm/service/scc/resource_ibm_scc_posture_collector_test.go @@ -142,7 +142,7 @@ func testAccCheckIBMSccPostureCollectorsExists(n string, obj posturemanagementv2 } listCollectorsOptions := &posturemanagementv2.ListCollectorsOptions{} - + userDetails, err := acc.TestAccProvider.Meta().(conns.ClientSession).BluemixUserDetails() if err != nil { return err @@ -171,7 +171,7 @@ func testAccCheckIBMSccPostureCollectorsDestroy(s *terraform.State) error { } listCollectorsOptions := &posturemanagementv2.ListCollectorsOptions{} - + userDetails, err := acc.TestAccProvider.Meta().(conns.ClientSession).BluemixUserDetails() if err != nil { return err diff --git a/ibm/service/scc/resource_ibm_scc_posture_credential.go b/ibm/service/scc/resource_ibm_scc_posture_credential.go index c48fc990dc..7c17e4a4de 100644 --- a/ibm/service/scc/resource_ibm_scc_posture_credential.go +++ b/ibm/service/scc/resource_ibm_scc_posture_credential.go @@ -147,7 +147,7 @@ func resourceIBMSccPostureCredentialsCreate(context context.Context, d *schema.R } createCredentialOptions := &posturemanagementv2.CreateCredentialOptions{} - + userDetails, err := meta.(conns.ClientSession).BluemixUserDetails() if err != nil { return diag.FromErr(fmt.Errorf("[ERROR] Error getting userDetails %s", err)) @@ -258,7 +258,7 @@ func resourceIBMSccPostureCredentialsUpdate(context context.Context, d *schema.R } updateCredentialOptions := &posturemanagementv2.UpdateCredentialOptions{} - + userDetails, err := meta.(conns.ClientSession).BluemixUserDetails() if err != nil { return diag.FromErr(fmt.Errorf("[ERROR] Error getting userDetails %s", err)) @@ -299,7 +299,7 @@ func resourceIBMSccPostureCredentialsDelete(context context.Context, d *schema.R } deleteCredentialOptions := &posturemanagementv2.DeleteCredentialOptions{} - + userDetails, err := meta.(conns.ClientSession).BluemixUserDetails() if err != nil { return diag.FromErr(fmt.Errorf("[ERROR] Error getting userDetails %s", err)) diff --git a/ibm/service/scc/resource_ibm_scc_posture_credential_test.go b/ibm/service/scc/resource_ibm_scc_posture_credential_test.go index eecafcad3c..90c2eaf119 100644 --- a/ibm/service/scc/resource_ibm_scc_posture_credential_test.go +++ b/ibm/service/scc/resource_ibm_scc_posture_credential_test.go @@ -100,7 +100,7 @@ func testAccCheckIBMSccPostureCredentialsExists(n string, obj posturemanagementv } listCredentialsOptions := &posturemanagementv2.ListCredentialsOptions{} - + userDetails, err := acc.TestAccProvider.Meta().(conns.ClientSession).BluemixUserDetails() if err != nil { return err @@ -129,7 +129,7 @@ func testAccCheckIBMSccPostureCredentialsDestroy(s *terraform.State) error { } listCredentialsOptions := &posturemanagementv2.ListCredentialsOptions{} - + userDetails, err := acc.TestAccProvider.Meta().(conns.ClientSession).BluemixUserDetails() if err != nil { return err diff --git a/ibm/service/scc/resource_ibm_scc_posture_scope.go b/ibm/service/scc/resource_ibm_scc_posture_scope.go index 1047354103..2dd97d8e37 100644 --- a/ibm/service/scc/resource_ibm_scc_posture_scope.go +++ b/ibm/service/scc/resource_ibm_scc_posture_scope.go @@ -109,7 +109,7 @@ func resourceIBMSccPostureScopesCreate(context context.Context, d *schema.Resour } createScopeOptions := &posturemanagementv2.CreateScopeOptions{} - + userDetails, err := meta.(conns.ClientSession).BluemixUserDetails() if err != nil { return diag.FromErr(fmt.Errorf("[ERROR] Error getting userDetails %s", err)) @@ -119,11 +119,11 @@ func resourceIBMSccPostureScopesCreate(context context.Context, d *schema.Resour createScopeOptions.SetName(d.Get("name").(string)) createScopeOptions.SetDescription(d.Get("description").(string)) collector_ids_int := d.Get("collector_ids").([]interface{}) - collector_ids := make([]string, len(collector_ids_int)) - for i, collector_id := range collector_ids_int { - collector_ids[i] = collector_id.(string) - } - createScopeOptions.SetCollectorIds(collector_ids) //[]string{ + collector_ids := make([]string, len(collector_ids_int)) + for i, collector_id := range collector_ids_int { + collector_ids[i] = collector_id.(string) + } + createScopeOptions.SetCollectorIds(collector_ids) //[]string{ createScopeOptions.SetCredentialID(d.Get("credential_id").(string)) createScopeOptions.SetCredentialType(d.Get("credential_type").(string)) @@ -174,7 +174,7 @@ func resourceIBMSccPostureScopesUpdate(context context.Context, d *schema.Resour } updateScopeDetailsOptions := &posturemanagementv2.UpdateScopeDetailsOptions{} - + userDetails, err := meta.(conns.ClientSession).BluemixUserDetails() if err != nil { return diag.FromErr(fmt.Errorf("[ERROR] Error getting userDetails %s", err)) @@ -212,7 +212,7 @@ func resourceIBMSccPostureScopesDelete(context context.Context, d *schema.Resour } deleteScopeOptions := &posturemanagementv2.DeleteScopeOptions{} - + userDetails, err := meta.(conns.ClientSession).BluemixUserDetails() if err != nil { return diag.FromErr(fmt.Errorf("[ERROR] Error getting userDetails %s", err)) diff --git a/ibm/service/scc/resource_ibm_scc_posture_scope_test.go b/ibm/service/scc/resource_ibm_scc_posture_scope_test.go index b7fc51f836..bda5ac2163 100644 --- a/ibm/service/scc/resource_ibm_scc_posture_scope_test.go +++ b/ibm/service/scc/resource_ibm_scc_posture_scope_test.go @@ -135,7 +135,7 @@ func testAccCheckIBMSccPostureScopesExists(n string, obj posturemanagementv2.Sco } listScopesOptions := &posturemanagementv2.ListScopesOptions{} - + userDetails, err := acc.TestAccProvider.Meta().(conns.ClientSession).BluemixUserDetails() if err != nil { return err @@ -163,7 +163,7 @@ func testAccCheckIBMSccPostureScopesDestroy(s *terraform.State) error { } listScopesOptions := &posturemanagementv2.ListScopesOptions{} - + userDetails, err := acc.TestAccProvider.Meta().(conns.ClientSession).BluemixUserDetails() if err != nil { return err From 3e762cfb2165d0542808e37b8ad717735664954e Mon Sep 17 00:00:00 2001 From: Sugata Mazumdar Date: Tue, 12 Apr 2022 17:08:07 +0530 Subject: [PATCH 9/9] Fixes for id field --- ibm/service/scc/resource_ibm_scc_posture_collector.go | 1 + ibm/service/scc/resource_ibm_scc_posture_credential.go | 1 + ibm/service/scc/resource_ibm_scc_posture_scope.go | 4 +++- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ibm/service/scc/resource_ibm_scc_posture_collector.go b/ibm/service/scc/resource_ibm_scc_posture_collector.go index 5ae301a672..b6f14542b4 100644 --- a/ibm/service/scc/resource_ibm_scc_posture_collector.go +++ b/ibm/service/scc/resource_ibm_scc_posture_collector.go @@ -159,6 +159,7 @@ func resourceIBMSccPostureCollectorsRead(context context.Context, d *schema.Reso accountID := userDetails.UserAccount getCollectorsOptions.SetAccountID(accountID) + getCollectorsOptions.SetID(d.Id()) collector, response, err := postureManagementClient.GetCollectorWithContext(context, getCollectorsOptions) if err != nil { diff --git a/ibm/service/scc/resource_ibm_scc_posture_credential.go b/ibm/service/scc/resource_ibm_scc_posture_credential.go index 7c17e4a4de..b51d9c2fd0 100644 --- a/ibm/service/scc/resource_ibm_scc_posture_credential.go +++ b/ibm/service/scc/resource_ibm_scc_posture_credential.go @@ -218,6 +218,7 @@ func resourceIBMSccPostureCredentialsRead(context context.Context, d *schema.Res accountID := userDetails.UserAccount getCredentialsOptions.SetAccountID(accountID) + getCredentialsOptions.SetID(d.Id()) credential, response, err := postureManagementClient.GetCredentialWithContext(context, getCredentialsOptions) if err != nil { diff --git a/ibm/service/scc/resource_ibm_scc_posture_scope.go b/ibm/service/scc/resource_ibm_scc_posture_scope.go index 2dd97d8e37..f85fcec222 100644 --- a/ibm/service/scc/resource_ibm_scc_posture_scope.go +++ b/ibm/service/scc/resource_ibm_scc_posture_scope.go @@ -152,9 +152,10 @@ func resourceIBMSccPostureScopesRead(context context.Context, d *schema.Resource accountID := userDetails.UserAccount getScopesOptions.SetAccountID(accountID) + getScopesOptions.SetID(d.Id()) scope, response, err := postureManagementClient.GetScopeDetailsWithContext(context, getScopesOptions) - d.SetId(*(scope.ID)) + if err != nil { if response != nil && response.StatusCode == 404 { d.SetId("") @@ -163,6 +164,7 @@ func resourceIBMSccPostureScopesRead(context context.Context, d *schema.Resource log.Printf("[DEBUG] GetScopeDetailsWithContext failed %s\n%s", err, response) return diag.FromErr(fmt.Errorf("GetScopeDetailsWithContext failed %s\n%s", err, response)) } + d.SetId(*scope.ID) return nil }