diff --git a/go.mod b/go.mod index 8ce6d70775..376c0cc5a4 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.16 require ( github.com/IBM-Cloud/bluemix-go v0.0.0-20220523145737-34645883de47 github.com/IBM-Cloud/container-services-go-sdk v0.0.0-20220622142911-811d18c8c775 - github.com/IBM-Cloud/power-go-client v1.1.10 + github.com/IBM-Cloud/power-go-client v1.1.11 github.com/IBM/apigateway-go-sdk v0.0.0-20210714141226-a5d5d49caaca github.com/IBM/appconfiguration-go-admin-sdk v0.2.3 github.com/IBM/appid-management-go-sdk v0.0.0-20210908164609-dd0e0eaf732f diff --git a/go.sum b/go.sum index e0134f8b46..b6c9780524 100644 --- a/go.sum +++ b/go.sum @@ -9,6 +9,8 @@ github.com/IBM-Cloud/container-services-go-sdk v0.0.0-20220622142911-811d18c8c77 github.com/IBM-Cloud/ibm-cloud-cli-sdk v0.5.3/go.mod h1:RiUvKuHKTBmBApDMUQzBL14pQUGKcx/IioKQPIcRQjs= github.com/IBM-Cloud/power-go-client v1.1.10 h1:NUGZwF5V0j2lFurA5LaigsYyOKDKwz4M0sCpm+YIbig= github.com/IBM-Cloud/power-go-client v1.1.10/go.mod h1:Qfx0fNi+9hms+xu9Z6Euhu9088ByW6C/TCMLECTRWNE= +github.com/IBM-Cloud/power-go-client v1.1.11 h1:/qTWCCuSZsmiksvQSfhM+mZKkY/Vli/W6b82WoYD2NM= +github.com/IBM-Cloud/power-go-client v1.1.11/go.mod h1:Qfx0fNi+9hms+xu9Z6Euhu9088ByW6C/TCMLECTRWNE= github.com/IBM-Cloud/softlayer-go v1.0.5-tf h1:koUAyF9b6X78lLLruGYPSOmrfY2YcGYKOj/Ug9nbKNw= github.com/IBM-Cloud/softlayer-go v1.0.5-tf/go.mod h1:6HepcfAXROz0Rf63krk5hPZyHT6qyx2MNvYyHof7ik4= github.com/IBM/apigateway-go-sdk v0.0.0-20210714141226-a5d5d49caaca h1:crniVcf+YcmgF03NmmfonXwSQ73oJF+IohFYBwknMxs= diff --git a/ibm/conns/config.go b/ibm/conns/config.go index a8daebc44d..5c742997e2 100644 --- a/ibm/conns/config.go +++ b/ibm/conns/config.go @@ -74,7 +74,6 @@ import ( resourcecontroller "github.com/IBM/platform-services-go-sdk/resourcecontrollerv2" resourcemanager "github.com/IBM/platform-services-go-sdk/resourcemanagerv2" "github.com/IBM/push-notifications-go-sdk/pushservicev1" - "github.com/IBM/scc-go-sdk/findingsv1" "github.com/IBM/scc-go-sdk/v3/adminserviceapiv1" "github.com/IBM/scc-go-sdk/v3/configurationgovernancev1" "github.com/IBM/scc-go-sdk/v3/posturemanagementv2" @@ -286,7 +285,6 @@ type ClientSession interface { AtrackerV1() (*atrackerv1.AtrackerV1, error) AtrackerV2() (*atrackerv2.AtrackerV2, error) ESschemaRegistrySession() (*schemaregistryv1.SchemaregistryV1, error) - FindingsV1() (*findingsv1.FindingsV1, error) AdminServiceApiV1() (*adminserviceapiv1.AdminServiceApiV1, error) ConfigurationGovernanceV1() (*configurationgovernancev1.ConfigurationGovernanceV1, error) PostureManagementV1() (*posturemanagementv1.PostureManagementV1, error) @@ -580,10 +578,6 @@ type clientSession struct { esSchemaRegistryClient *schemaregistryv1.SchemaregistryV1 esSchemaRegistryErr error - // Security and Compliance Center (SCC) - findingsClient *findingsv1.FindingsV1 - findingsClientErr error - // Security and Compliance Center (SCC) Admin adminServiceApiClient *adminserviceapiv1.AdminServiceApiV1 adminServiceApiClientErr error @@ -1123,14 +1117,6 @@ func (session clientSession) ESschemaRegistrySession() (*schemaregistryv1.Schema return session.esSchemaRegistryClient, session.esSchemaRegistryErr } -// Security and Compliance center Findings API -func (session clientSession) FindingsV1() (*findingsv1.FindingsV1, error) { - if session.findingsClientErr != nil { - return session.findingsClient, session.findingsClientErr - } - return session.findingsClient.Clone(), nil -} - //Security and Compliance center Admin API func (session clientSession) AdminServiceApiV1() (*adminserviceapiv1.AdminServiceApiV1, error) { return session.adminServiceApiClient, session.adminServiceApiClientErr @@ -1646,38 +1632,6 @@ func (c *Config) ClientSession() (interface{}, error) { session.atrackerClientV2Err = fmt.Errorf("Error occurred while configuring Activity Tracker API Version 2 service: %q", err) } - // SCC FINDINGS Service - var findingsClientURL string - if c.Visibility == "public" || c.Visibility == "public-and-private" { - findingsClientURL, err = findingsv1.GetServiceURLForRegion(c.Region) - if err != nil { - session.findingsClientErr = fmt.Errorf("[ERROR] Error occurred while configuring Security Insights Findings API service: `%s` region not supported", c.Region) - } - } else { - session.findingsClientErr = fmt.Errorf("[ERROR] Error occurred while configuring Security Insights Findings API service: `%v` visibility not supported", c.Visibility) - } - if fileMap != nil && c.Visibility != "public-and-private" { - findingsClientURL = fileFallBack(fileMap, c.Visibility, "IBMCLOUD_SCC_FINDINGS_API_ENDPOINT", c.Region, findingsClientURL) - } - findingsClientOptions := &findingsv1.FindingsV1Options{ - Authenticator: authenticator, - URL: EnvFallBack([]string{"IBMCLOUD_SCC_FINDINGS_API_ENDPOINT"}, findingsClientURL), - AccountID: core.StringPtr(userConfig.UserAccount), - } - // Construct the service client. - session.findingsClient, err = findingsv1.NewFindingsV1(findingsClientOptions) - if err != nil { - session.findingsClientErr = fmt.Errorf("[ERROR] Error occurred while configuring Security Insights Findings API service: %q", err) - } - if session.findingsClient != nil && session.findingsClient.Service != nil { - // Enable retries for API calls - session.findingsClient.Service.EnableRetries(c.RetryCount, c.RetryDelay) - // Add custom header for analytics - session.findingsClient.SetDefaultHeaders(gohttp.Header{ - "X-Original-User-Agent": {fmt.Sprintf("terraform-provider-ibm/%s", version.Version)}, - }) - } - // SCC ADMIN Service var adminServiceApiClientURL string if c.Visibility == "private" || c.Visibility == "public-and-private" { diff --git a/ibm/provider/provider.go b/ibm/provider/provider.go index a605cce71b..a1ba5d3e4a 100644 --- a/ibm/provider/provider.go +++ b/ibm/provider/provider.go @@ -625,15 +625,10 @@ func Provider() *schema.Provider { "ibm_atracker_endpoints": atracker.DataSourceIBMAtrackerEndpoints(), //Security and Compliance Center - "ibm_scc_si_providers": scc.DataSourceIBMSccSiProviders(), - "ibm_scc_si_note": scc.DataSourceIBMSccSiNote(), - "ibm_scc_si_notes": scc.DataSourceIBMSccSiNotes(), "ibm_scc_account_location": scc.DataSourceIBMSccAccountLocation(), "ibm_scc_account_locations": scc.DataSourceIBMSccAccountLocations(), "ibm_scc_account_location_settings": scc.DataSourceIBMSccAccountLocationSettings(), "ibm_scc_account_notification_settings": scc.DataSourceIBMSccNotificationSettings(), - "ibm_scc_si_occurrence": scc.DataSourceIBMSccSiOccurrence(), - "ibm_scc_si_occurrences": scc.DataSourceIBMSccSiOccurrences(), // Compliance Posture Management "ibm_scc_posture_scopes": scc.DataSourceIBMSccPostureScopes(), @@ -1048,9 +1043,7 @@ func Provider() *schema.Provider { "ibm_atracker_settings": atracker.ResourceIBMAtrackerSettings(), // //Security and Compliance Center - "ibm_scc_si_note": scc.ResourceIBMSccSiNote(), "ibm_scc_account_settings": scc.ResourceIBMSccAccountSettings(), - "ibm_scc_si_occurrence": scc.ResourceIBMSccSiOccurrence(), "ibm_scc_rule": scc.ResourceIBMSccRule(), "ibm_scc_rule_attachment": scc.ResourceIBMSccRuleAttachment(), "ibm_scc_template": scc.ResourceIBMSccTemplate(), @@ -1252,9 +1245,7 @@ func Validator() validate.ValidatorDict { "ibm_atracker_route": atracker.ResourceIBMAtrackerRouteValidator(), "ibm_atracker_settings": atracker.ResourceIBMAtrackerSettingsValidator(), "ibm_satellite_endpoint": satellite.ResourceIBMSatelliteEndpointValidator(), - "ibm_scc_si_note": scc.ResourceIBMSccSiNoteValidator(), "ibm_scc_account_settings": scc.ResourceIBMSccAccountSettingsValidator(), - "ibm_scc_si_occurrence": scc.ResourceIBMSccSiOccurrenceValidator(), "ibm_scc_posture_collector": scc.ResourceIBMSccPostureCollectorsValidator(), "ibm_scc_posture_scope": scc.ResourceIBMSccPostureScopesValidator(), "ibm_scc_posture_credential": scc.ResourceIBMSccPostureCredentialsValidator(), @@ -1311,8 +1302,6 @@ func Validator() validate.ValidatorDict { "ibm_is_vpc": vpc.DataSourceIBMISVpcValidator(), "ibm_is_volume": vpc.DataSourceIBMISVolumeValidator(), - "ibm_scc_si_notes": scc.DataSourceIBMSccSiNotesValidator(), - "ibm_scc_si_occurrences": scc.DataSourceIBMSccSiOccurrencesValidator(), "ibm_secrets_manager_secret": secretsmanager.DataSourceIBMSecretsManagerSecretValidator(), "ibm_secrets_manager_secrets": secretsmanager.DataSourceIBMSecretsManagerSecretsValidator(), }, diff --git a/ibm/service/power/ibm_pi_constants.go b/ibm/service/power/ibm_pi_constants.go index 8ff9e5e640..0fef570bbd 100644 --- a/ibm/service/power/ibm_pi_constants.go +++ b/ibm/service/power/ibm_pi_constants.go @@ -30,6 +30,7 @@ const ( Arg_DhcpCloudConnectionID = "pi_cloud_connection_id" Arg_DhcpDnsServer = "pi_dns_server" Arg_DhcpName = "pi_dhcp_name" + Arg_DhcpSnatEnabled = "pi_dhcp_snat_enabled" Attr_DhcpServers = "servers" Attr_DhcpID = "dhcp_id" diff --git a/ibm/service/power/resource_ibm_pi_dhcp.go b/ibm/service/power/resource_ibm_pi_dhcp.go index 070386f0da..f87acc0399 100644 --- a/ibm/service/power/resource_ibm_pi_dhcp.go +++ b/ibm/service/power/resource_ibm_pi_dhcp.go @@ -65,6 +65,13 @@ func ResourceIBMPIDhcp() *schema.Resource { Description: "Optional name of DHCP Service (will be prefixed by DHCP identifier)", ForceNew: true, }, + Arg_DhcpSnatEnabled: { + Type: schema.TypeBool, + Optional: true, + Default: true, + Description: "Indicates if SNAT will be enabled for the DHCP service", + ForceNew: true, + }, // Attributes Attr_DhcpID: { @@ -144,6 +151,8 @@ func resourceIBMPIDhcpCreate(ctx context.Context, d *schema.ResourceData, meta i n := name.(string) body.Name = &n } + snatEnabled := d.Get(Arg_DhcpSnatEnabled).(bool) + body.SnatEnabled = &snatEnabled // create dhcp client := st.NewIBMPIDhcpClient(ctx, sess, cloudInstanceID) diff --git a/ibm/service/power/resource_ibm_pi_dhcp_test.go b/ibm/service/power/resource_ibm_pi_dhcp_test.go index 7ff1fe6c0b..169936d6fa 100644 --- a/ibm/service/power/resource_ibm_pi_dhcp_test.go +++ b/ibm/service/power/resource_ibm_pi_dhcp_test.go @@ -133,3 +133,30 @@ func testAccCheckIBMPIDhcpWithCidrNameConfig(name string) string { } `, acc.Pi_cloud_instance_id, name) } + +func TestAccIBMPIDhcpSNAT(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { acc.TestAccPreCheck(t) }, + Providers: acc.TestAccProviders, + CheckDestroy: testAccCheckIBMPIDhcpDestroy, + Steps: []resource.TestStep{ + { + Config: testAccCheckIBMPIDhcpConfigWithSNATDisabled(), + Check: resource.ComposeTestCheckFunc( + testAccCheckIBMPIDhcpExists("ibm_pi_dhcp.dhcp_service"), + resource.TestCheckResourceAttrSet( + "ibm_pi_dhcp.dhcp_service", "dhcp_id"), + ), + }, + }, + }) +} + +func testAccCheckIBMPIDhcpConfigWithSNATDisabled() string { + return fmt.Sprintf(` + resource "ibm_pi_dhcp" "dhcp_service" { + pi_cloud_instance_id = "%s" + pi_dhcp_snat_enabled = false + } + `, acc.Pi_cloud_instance_id) +} diff --git a/ibm/service/scc/data_source_ibm_scc_si_note.go b/ibm/service/scc/data_source_ibm_scc_si_note.go deleted file mode 100644 index 95dff07812..0000000000 --- a/ibm/service/scc/data_source_ibm_scc_si_note.go +++ /dev/null @@ -1,671 +0,0 @@ -// Copyright IBM Corp. 2021 All Rights Reserved. -// Licensed under the Mozilla Public License v2.0 - -package scc - -import ( - "context" - "fmt" - "log" - - "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" - "github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex" - "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - - "github.com/IBM/scc-go-sdk/findingsv1" -) - -func DataSourceIBMSccSiNote() *schema.Resource { - return &schema.Resource{ - ReadContext: dataSourceIBMSccSiNoteRead, - - Schema: map[string]*schema.Schema{ - "account_id": { - Type: schema.TypeString, - Optional: true, - }, - "provider_id": { - Type: schema.TypeString, - Required: true, - Description: "Part of the parent. This field contains the provider ID. For example: providers/{provider_id}.", - }, - "note_id": { - Type: schema.TypeString, - Required: true, - Description: "Second part of note `name`: providers/{provider_id}/notes/{note_id}.", - }, - "short_description": { - Type: schema.TypeString, - Computed: true, - Description: "A one sentence description of your note.", - }, - "long_description": { - Type: schema.TypeString, - Computed: true, - Description: "A more detailed description of your note.", - }, - "kind": { - Type: schema.TypeString, - Computed: true, - Description: "The type of note. Use this field to filter notes and occurences by kind. - FINDING: The note and occurrence represent a finding. - KPI: The note and occurrence represent a KPI value. - CARD: The note represents a card showing findings and related metric values. - CARD_CONFIGURED: The note represents a card configured for a user account. - SECTION: The note represents a section in a dashboard.", - }, - "related_url": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "label": { - Type: schema.TypeString, - Computed: true, - Description: "Label to describe usage of the URL.", - }, - "url": { - Type: schema.TypeString, - Computed: true, - Description: "The URL that you want to associate with the note.", - }, - }, - }, - }, - "create_time": { - Type: schema.TypeString, - Computed: true, - Description: "Output only. The time this note was created. This field can be used as a filter in list requests.", - }, - "update_time": { - Type: schema.TypeString, - Computed: true, - Description: "Output only. The time this note was last updated. This field can be used as a filter in list requests.", - }, - "shared": { - Type: schema.TypeBool, - Computed: true, - Description: "True if this note can be shared by multiple accounts.", - }, - "reported_by": { - Type: schema.TypeList, - Computed: true, - Description: "The entity reporting a note.", - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "id": { - Type: schema.TypeString, - Computed: true, - Description: "The id of this reporter.", - }, - "title": { - Type: schema.TypeString, - Computed: true, - Description: "The title of this reporter.", - }, - "url": { - Type: schema.TypeString, - Computed: true, - Description: "The url of this reporter.", - }, - }, - }, - }, - "finding": { - Type: schema.TypeList, - Computed: true, - Description: "FindingType provides details about a finding note.", - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "severity": { - Type: schema.TypeString, - Computed: true, - Description: "Note provider-assigned severity/impact ranking- LOW: Low Impact- MEDIUM: Medium Impact- HIGH: High Impact- CRITICAL: Critical Impact.", - }, - "next_steps": { - Type: schema.TypeList, - Computed: true, - Description: "Common remediation steps for the finding of this type.", - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "title": { - Type: schema.TypeString, - Computed: true, - Description: "Title of this next step.", - }, - "url": { - Type: schema.TypeString, - Computed: true, - Description: "The URL associated to this next steps.", - }, - }, - }, - }, - }, - }, - }, - "kpi": { - Type: schema.TypeList, - Computed: true, - Description: "KpiType provides details about a KPI note.", - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "aggregation_type": { - Type: schema.TypeString, - Computed: true, - Description: "The aggregation type of the KPI values. - SUM: A single-value metrics aggregation type that sums up numeric values that are extracted from KPI occurrences.", - }, - }, - }, - }, - "card": { - Type: schema.TypeList, - Computed: true, - Description: "Card provides details about a card kind of note.", - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "section": { - Type: schema.TypeString, - Computed: true, - Description: "The section this card belongs to.", - }, - "title": { - Type: schema.TypeString, - Computed: true, - Description: "The title of this card.", - }, - "subtitle": { - Type: schema.TypeString, - Computed: true, - Description: "The subtitle of this card.", - }, - "order": { - Type: schema.TypeInt, - Computed: true, - Description: "The order of the card in which it will appear on SA dashboard in the mentioned section.", - }, - "finding_note_names": { - Type: schema.TypeList, - Computed: true, - Description: "The finding note names associated to this card.", - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - }, - "requires_configuration": { - Type: schema.TypeBool, - Computed: true, - }, - "badge_text": { - Type: schema.TypeString, - Computed: true, - Description: "The text associated to the card's badge.", - }, - "badge_image": { - Type: schema.TypeString, - Computed: true, - Description: "The base64 content of the image associated to the card's badge.", - }, - "elements": { - Type: schema.TypeList, - Computed: true, - Description: "The elements of this card.", - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "text": { - Type: schema.TypeString, - Computed: true, - Description: "The text of this card element.", - }, - "kind": { - Type: schema.TypeString, - Computed: true, - Description: "Kind of element- NUMERIC: Single numeric value- BREAKDOWN: Breakdown of numeric values- TIME_SERIES: Time-series of numeric values.", - }, - "default_time_range": { - Type: schema.TypeString, - Computed: true, - Description: "The default time range of this card element.", - }, - "value_type": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "kind": { - Type: schema.TypeString, - Computed: true, - Description: "Kind of element- KPI: Kind of value derived from a KPI occurrence.", - }, - "kpi_note_name": { - Type: schema.TypeString, - Computed: true, - Description: "The name of the kpi note associated to the occurrence with the value for this card element value type.", - }, - "text": { - Type: schema.TypeString, - Computed: true, - Description: "The text of this element type.", - }, - "finding_note_names": { - Type: schema.TypeList, - Computed: true, - Description: "the names of the finding note associated that act as filters for counting the occurrences.", - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - }, - }, - }, - }, - "value_types": { - Type: schema.TypeList, - Computed: true, - Description: "the value types associated to this card element.", - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "kind": { - Type: schema.TypeString, - Computed: true, - Description: "Kind of element- KPI: Kind of value derived from a KPI occurrence.", - }, - "kpi_note_name": { - Type: schema.TypeString, - Computed: true, - Description: "The name of the kpi note associated to the occurrence with the value for this card element value type.", - }, - "text": { - Type: schema.TypeString, - Computed: true, - Description: "The text of this element type.", - }, - "finding_note_names": { - Type: schema.TypeList, - Computed: true, - Description: "the names of the finding note associated that act as filters for counting the occurrences.", - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - }, - }, - }, - }, - "default_interval": { - Type: schema.TypeString, - Computed: true, - Description: "The default interval of the time series.", - }, - }, - }, - }, - }, - }, - }, - "section": { - Type: schema.TypeList, - Computed: true, - Description: "Card provides details about a card kind of note.", - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "title": { - Type: schema.TypeString, - Computed: true, - Description: "The title of this section.", - }, - "image": { - Type: schema.TypeString, - Computed: true, - Description: "The image of this section.", - }, - }, - }, - }, - }, - } -} - -func dataSourceIBMSccSiNoteRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - findingsClient, err := meta.(conns.ClientSession).FindingsV1() - if err != nil { - return diag.FromErr(err) - } - userDetails, err := meta.(conns.ClientSession).BluemixUserDetails() - if err != nil { - return diag.FromErr(err) - } - - accountID := d.Get("account_id").(string) - log.Println(fmt.Sprintf("[DEBUG] using specified AccountID %s", accountID)) - if accountID == "" { - accountID = userDetails.UserAccount - log.Println(fmt.Sprintf("[DEBUG] AccountID not spedified, using %s", accountID)) - } - findingsClient.AccountID = &accountID - - getNoteOptions := &findingsv1.GetNoteOptions{} - - getNoteOptions.SetProviderID(d.Get("provider_id").(string)) - getNoteOptions.SetNoteID(d.Get("note_id").(string)) - - apiNote, response, err := findingsClient.GetNoteWithContext(context, getNoteOptions) - if err != nil { - log.Printf("[DEBUG] GetNoteWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("GetNoteWithContext failed %s\n%s", err, response)) - } - - d.SetId(fmt.Sprintf("%s/%s/%s", *findingsClient.AccountID, *getNoteOptions.ProviderID, *getNoteOptions.NoteID)) - if err = d.Set("short_description", apiNote.ShortDescription); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting short_description: %s", err)) - } - if err = d.Set("long_description", apiNote.LongDescription); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting long_description: %s", err)) - } - if err = d.Set("kind", apiNote.Kind); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting kind: %s", err)) - } - - if apiNote.RelatedURL != nil { - err = d.Set("related_url", dataSourceAPINoteFlattenRelatedURL(apiNote.RelatedURL)) - if err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting related_url %s", err)) - } - } - if err = d.Set("create_time", flex.DateTimeToString(apiNote.CreateTime)); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting create_time: %s", err)) - } - if err = d.Set("update_time", flex.DateTimeToString(apiNote.UpdateTime)); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting update_time: %s", err)) - } - if err = d.Set("shared", apiNote.Shared); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting shared: %s", err)) - } - - if apiNote.ReportedBy != nil { - err = d.Set("reported_by", dataSourceAPINoteFlattenReportedBy(*apiNote.ReportedBy)) - if err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting reported_by %s", err)) - } - } - - if apiNote.Finding != nil { - err = d.Set("finding", dataSourceAPINoteFlattenFinding(*apiNote.Finding)) - if err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting finding %s", err)) - } - } - - if apiNote.Kpi != nil { - err = d.Set("kpi", dataSourceAPINoteFlattenKpi(*apiNote.Kpi)) - if err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting kpi %s", err)) - } - } - - if apiNote.Card != nil { - err = d.Set("card", dataSourceAPINoteFlattenCard(*apiNote.Card)) - if err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting card %s", err)) - } - } - - if apiNote.Section != nil { - err = d.Set("section", dataSourceAPINoteFlattenSection(*apiNote.Section)) - if err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting section %s", err)) - } - } - - return nil -} - -func dataSourceAPINoteFlattenRelatedURL(result []findingsv1.APINoteRelatedURL) (relatedURL []map[string]interface{}) { - for _, relatedURLItem := range result { - relatedURL = append(relatedURL, dataSourceAPINoteRelatedURLToMap(relatedURLItem)) - } - - return relatedURL -} - -func dataSourceAPINoteRelatedURLToMap(relatedURLItem findingsv1.APINoteRelatedURL) (relatedURLMap map[string]interface{}) { - relatedURLMap = map[string]interface{}{} - - if relatedURLItem.Label != nil { - relatedURLMap["label"] = relatedURLItem.Label - } - if relatedURLItem.URL != nil { - relatedURLMap["url"] = relatedURLItem.URL - } - - return relatedURLMap -} - -func dataSourceAPINoteFlattenReportedBy(result findingsv1.Reporter) (finalList []map[string]interface{}) { - finalList = []map[string]interface{}{} - finalMap := dataSourceAPINoteReportedByToMap(result) - finalList = append(finalList, finalMap) - - return finalList -} - -func dataSourceAPINoteReportedByToMap(reportedByItem findingsv1.Reporter) (reportedByMap map[string]interface{}) { - reportedByMap = map[string]interface{}{} - - if reportedByItem.ID != nil { - reportedByMap["id"] = reportedByItem.ID - } - if reportedByItem.Title != nil { - reportedByMap["title"] = reportedByItem.Title - } - if reportedByItem.URL != nil { - reportedByMap["url"] = reportedByItem.URL - } - - return reportedByMap -} - -func dataSourceAPINoteFlattenFinding(result findingsv1.FindingType) (finalList []map[string]interface{}) { - finalList = []map[string]interface{}{} - finalMap := dataSourceAPINoteFindingToMap(result) - finalList = append(finalList, finalMap) - - return finalList -} - -func dataSourceAPINoteFindingToMap(findingItem findingsv1.FindingType) (findingMap map[string]interface{}) { - findingMap = map[string]interface{}{} - - if findingItem.Severity != nil { - findingMap["severity"] = findingItem.Severity - } - if findingItem.NextSteps != nil { - nextStepsList := []map[string]interface{}{} - for _, nextStepsItem := range findingItem.NextSteps { - nextStepsList = append(nextStepsList, dataSourceAPINoteFindingNextStepsToMap(nextStepsItem)) - } - findingMap["next_steps"] = nextStepsList - } - - return findingMap -} - -func dataSourceAPINoteFindingNextStepsToMap(nextStepsItem findingsv1.RemediationStep) (nextStepsMap map[string]interface{}) { - nextStepsMap = map[string]interface{}{} - - if nextStepsItem.Title != nil { - nextStepsMap["title"] = nextStepsItem.Title - } - if nextStepsItem.URL != nil { - nextStepsMap["url"] = nextStepsItem.URL - } - - return nextStepsMap -} - -func dataSourceAPINoteFlattenKpi(result findingsv1.KpiType) (finalList []map[string]interface{}) { - finalList = []map[string]interface{}{} - finalMap := dataSourceAPINoteKpiToMap(result) - finalList = append(finalList, finalMap) - - return finalList -} - -func dataSourceAPINoteKpiToMap(kpiItem findingsv1.KpiType) (kpiMap map[string]interface{}) { - kpiMap = map[string]interface{}{} - - if kpiItem.AggregationType != nil { - kpiMap["aggregation_type"] = kpiItem.AggregationType - } - - return kpiMap -} - -func dataSourceAPINoteFlattenCard(result findingsv1.Card) (finalList []map[string]interface{}) { - finalList = []map[string]interface{}{} - finalMap := dataSourceAPINoteCardToMap(result) - finalList = append(finalList, finalMap) - - return finalList -} - -func dataSourceAPINoteCardToMap(cardItem findingsv1.Card) (cardMap map[string]interface{}) { - cardMap = map[string]interface{}{} - - if cardItem.Section != nil { - cardMap["section"] = cardItem.Section - } - if cardItem.Title != nil { - cardMap["title"] = cardItem.Title - } - if cardItem.Subtitle != nil { - cardMap["subtitle"] = cardItem.Subtitle - } - if cardItem.Order != nil { - cardMap["order"] = cardItem.Order - } - if cardItem.FindingNoteNames != nil { - cardMap["finding_note_names"] = cardItem.FindingNoteNames - } - if cardItem.RequiresConfiguration != nil { - cardMap["requires_configuration"] = cardItem.RequiresConfiguration - } - if cardItem.BadgeText != nil { - cardMap["badge_text"] = cardItem.BadgeText - } - if cardItem.BadgeImage != nil { - cardMap["badge_image"] = cardItem.BadgeImage - } - if cardItem.Elements != nil { - elementsList := []map[string]interface{}{} - for _, elementsItem := range cardItem.Elements { - elementsList = append(elementsList, dataSourceAPINoteCardElementsToMap(elementsItem)) - } - cardMap["elements"] = elementsList - } - - return cardMap -} - -func dataSourceAPINoteCardElementsToMap(elementsItem findingsv1.CardElementIntf) (elementsMap map[string]interface{}) { - cardElementMap := map[string]interface{}{} - - switch v := elementsItem.(type) { - case *findingsv1.CardElementNumericCardElement: - cardElementMap["value_type"] = dataSourceAPINoteElementsValueTypeToMap(*v.ValueType) - case *findingsv1.CardElementBreakdownCardElement: - cardElementMap["value_types"] = dataSourceAPINoteElementsValueTypesToMap(v.ValueTypes) - case *findingsv1.CardElementTimeSeriesCardElement: - cardElementMap["value_types"] = dataSourceAPINoteElementsValueTypesToMap(v.ValueTypes) - } - - return cardElementMap -} - -func dataSourceAPINoteElementsValueTypeToMap(valueTypeItem findingsv1.NumericCardElementValueType) (valueTypeMap map[string]interface{}) { - valueTypeMap = map[string]interface{}{} - - if valueTypeItem.Kind != nil { - valueTypeMap["kind"] = valueTypeItem.Kind - } - if valueTypeItem.KpiNoteName != nil { - valueTypeMap["kpi_note_name"] = valueTypeItem.KpiNoteName - } - if valueTypeItem.Text != nil { - valueTypeMap["text"] = valueTypeItem.Text - } - if valueTypeItem.FindingNoteNames != nil { - valueTypeMap["finding_note_names"] = valueTypeItem.FindingNoteNames - } - - return valueTypeMap -} - -func dataSourceAPINoteElementsFindingCountValueTypeToMap(valueTypeItem findingsv1.ValueTypeFindingCountValueType) (valueTypeMap map[string]interface{}) { - valueTypeMap = map[string]interface{}{} - - if valueTypeItem.Kind != nil { - valueTypeMap["kind"] = valueTypeItem.Kind - } - if valueTypeItem.Text != nil { - valueTypeMap["text"] = valueTypeItem.Text - } - if valueTypeItem.FindingNoteNames != nil { - valueTypeMap["finding_note_names"] = valueTypeItem.FindingNoteNames - } - - return valueTypeMap -} - -func dataSourceAPINoteElementsKpiValueTypeToMap(valueTypeItem findingsv1.ValueTypeKpiValueType) (valueTypeMap map[string]interface{}) { - valueTypeMap = map[string]interface{}{} - - if valueTypeItem.Kind != nil { - valueTypeMap["kind"] = valueTypeItem.Kind - } - if valueTypeItem.Text != nil { - valueTypeMap["text"] = valueTypeItem.Text - } - if valueTypeItem.KpiNoteName != nil { - valueTypeMap["kpi_note_name"] = valueTypeItem.KpiNoteName - } - - return valueTypeMap -} - -func dataSourceAPINoteElementsValueTypesToMap(valueTypesItem []findingsv1.ValueTypeIntf) (valueTypesMap []map[string]interface{}) { - valueTypesMap = []map[string]interface{}{} - - valueTypeMap := map[string]interface{}{} - - for _, valueType := range valueTypesItem { - - switch v := valueType.(type) { - case *findingsv1.NumericCardElementValueType: - valueTypeMap = dataSourceAPINoteElementsValueTypeToMap(*v) - case *findingsv1.ValueTypeFindingCountValueType: - valueTypeMap = dataSourceAPINoteElementsFindingCountValueTypeToMap(*v) - case *findingsv1.ValueTypeKpiValueType: - valueTypeMap = dataSourceAPINoteElementsKpiValueTypeToMap(*v) - } - - valueTypesMap = append(valueTypesMap, valueTypeMap) - } - - return valueTypesMap -} - -func dataSourceAPINoteFlattenSection(result findingsv1.Section) (finalList []map[string]interface{}) { - finalList = []map[string]interface{}{} - finalMap := dataSourceAPINoteSectionToMap(result) - finalList = append(finalList, finalMap) - - return finalList -} - -func dataSourceAPINoteSectionToMap(sectionItem findingsv1.Section) (sectionMap map[string]interface{}) { - sectionMap = map[string]interface{}{} - - if sectionItem.Title != nil { - sectionMap["title"] = sectionItem.Title - } - if sectionItem.Image != nil { - sectionMap["image"] = sectionItem.Image - } - - return sectionMap -} diff --git a/ibm/service/scc/data_source_ibm_scc_si_note_test.go b/ibm/service/scc/data_source_ibm_scc_si_note_test.go deleted file mode 100644 index e2d5c57863..0000000000 --- a/ibm/service/scc/data_source_ibm_scc_si_note_test.go +++ /dev/null @@ -1,143 +0,0 @@ -// Copyright IBM Corp. 2021 All Rights Reserved. -// Licensed under the Mozilla Public License v2.0 - -package scc_test - -import ( - "fmt" - "testing" - - acc "github.com/IBM-Cloud/terraform-provider-ibm/ibm/acctest" - - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" -) - -func TestAccIBMSccSiNoteDataSourceBasic(t *testing.T) { - apiNoteProviderID := fmt.Sprintf("tf_provider_id_%d", acctest.RandIntRange(10, 100)) - apiNoteShortDescription := fmt.Sprintf("tf_short_description_%d", acctest.RandIntRange(10, 100)) - apiNoteLongDescription := fmt.Sprintf("tf_long_description_%d", acctest.RandIntRange(10, 100)) - apiNoteKind := "FINDING" - apiNoteID := fmt.Sprintf("tf_note_id_%d", acctest.RandIntRange(10, 100)) - - resource.Test(t, resource.TestCase{ - PreCheck: func() { acc.TestAccPreCheck(t) }, - Providers: acc.TestAccProviders, - Steps: []resource.TestStep{ - { - Config: testAccCheckIBMSccSiNoteDataSourceConfigBasic(acc.Scc_si_account, apiNoteProviderID, apiNoteShortDescription, apiNoteLongDescription, apiNoteKind, apiNoteID), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet("data.ibm_scc_si_note.scc_si_note", "id"), - resource.TestCheckResourceAttrSet("data.ibm_scc_si_note.scc_si_note", "provider_id"), - resource.TestCheckResourceAttrSet("data.ibm_scc_si_note.scc_si_note", "note_id"), - resource.TestCheckResourceAttrSet("data.ibm_scc_si_note.scc_si_note", "short_description"), - resource.TestCheckResourceAttrSet("data.ibm_scc_si_note.scc_si_note", "long_description"), - resource.TestCheckResourceAttrSet("data.ibm_scc_si_note.scc_si_note", "kind"), - resource.TestCheckResourceAttrSet("data.ibm_scc_si_note.scc_si_note", "reported_by.#"), - ), - }, - }, - }) -} - -func TestAccIBMSccSiNoteDataSourceAllArgs(t *testing.T) { - apiNoteProviderID := fmt.Sprintf("tf_provider_id_%d", acctest.RandIntRange(10, 100)) - apiNoteShortDescription := fmt.Sprintf("tf_short_description_%d", acctest.RandIntRange(10, 100)) - apiNoteLongDescription := fmt.Sprintf("tf_long_description_%d", acctest.RandIntRange(10, 100)) - apiNoteKind := "FINDING" - apiNoteID := fmt.Sprintf("tf_note_id_%d", acctest.RandIntRange(10, 100)) - apiNoteShared := "true" - - resource.Test(t, resource.TestCase{ - PreCheck: func() { acc.TestAccPreCheck(t) }, - Providers: acc.TestAccProviders, - Steps: []resource.TestStep{ - { - Config: testAccCheckIBMSccSiNoteDataSourceConfig(acc.Scc_si_account, apiNoteProviderID, apiNoteShortDescription, apiNoteLongDescription, apiNoteKind, apiNoteID, apiNoteShared), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet("data.ibm_scc_si_note.scc_si_note", "id"), - resource.TestCheckResourceAttrSet("data.ibm_scc_si_note.scc_si_note", "provider_id"), - resource.TestCheckResourceAttrSet("data.ibm_scc_si_note.scc_si_note", "note_id"), - resource.TestCheckResourceAttrSet("data.ibm_scc_si_note.scc_si_note", "short_description"), - resource.TestCheckResourceAttrSet("data.ibm_scc_si_note.scc_si_note", "long_description"), - resource.TestCheckResourceAttrSet("data.ibm_scc_si_note.scc_si_note", "kind"), - resource.TestCheckResourceAttrSet("data.ibm_scc_si_note.scc_si_note", "related_url.#"), - resource.TestCheckResourceAttrSet("data.ibm_scc_si_note.scc_si_note", "related_url.0.label"), - resource.TestCheckResourceAttrSet("data.ibm_scc_si_note.scc_si_note", "related_url.0.url"), - resource.TestCheckResourceAttrSet("data.ibm_scc_si_note.scc_si_note", "create_time"), - resource.TestCheckResourceAttrSet("data.ibm_scc_si_note.scc_si_note", "update_time"), - resource.TestCheckResourceAttrSet("data.ibm_scc_si_note.scc_si_note", "shared"), - resource.TestCheckResourceAttrSet("data.ibm_scc_si_note.scc_si_note", "reported_by.#"), - resource.TestCheckResourceAttrSet("data.ibm_scc_si_note.scc_si_note", "finding.#"), - ), - }, - }, - }) -} - -func testAccCheckIBMSccSiNoteDataSourceConfigBasic(accountID string, apiNoteProviderID string, apiNoteShortDescription string, apiNoteLongDescription string, apiNoteKind string, apiNoteID string) string { - return fmt.Sprintf(` - resource "ibm_scc_si_note" "scc_si_note" { - account_id = "%s" - provider_id = "%s" - short_description = "%s" - long_description = "%s" - kind = "%s" - note_id = "%s" - reported_by { - id = "id" - title = "title" - url = "url" - } - finding { - severity = "LOW" - next_steps { - title = "title" - url = "url" - } - } - } - - data "ibm_scc_si_note" "scc_si_note" { - account_id = ibm_scc_si_note.scc_si_note.account_id - provider_id = ibm_scc_si_note.scc_si_note.provider_id - note_id = ibm_scc_si_note.scc_si_note.note_id - } - `, accountID, apiNoteProviderID, apiNoteShortDescription, apiNoteLongDescription, apiNoteKind, apiNoteID) -} - -func testAccCheckIBMSccSiNoteDataSourceConfig(accountID string, apiNoteProviderID string, apiNoteShortDescription string, apiNoteLongDescription string, apiNoteKind string, apiNoteID string, apiNoteShared string) string { - return fmt.Sprintf(` - resource "ibm_scc_si_note" "scc_si_note" { - account_id = "%s" - provider_id = "%s" - short_description = "%s" - long_description = "%s" - kind = "%s" - note_id = "%s" - reported_by { - id = "id" - title = "title" - url = "url" - } - related_url { - label = "label" - url = "url" - } - shared = %s - finding { - severity = "LOW" - next_steps { - title = "title" - url = "url" - } - } - } - - data "ibm_scc_si_note" "scc_si_note" { - account_id = ibm_scc_si_note.scc_si_note.account_id - provider_id = ibm_scc_si_note.scc_si_note.provider_id - note_id = ibm_scc_si_note.scc_si_note.note_id - } - `, accountID, apiNoteProviderID, apiNoteShortDescription, apiNoteLongDescription, apiNoteKind, apiNoteID, apiNoteShared) -} diff --git a/ibm/service/scc/data_source_ibm_scc_si_notes.go b/ibm/service/scc/data_source_ibm_scc_si_notes.go deleted file mode 100644 index 95373e2883..0000000000 --- a/ibm/service/scc/data_source_ibm_scc_si_notes.go +++ /dev/null @@ -1,776 +0,0 @@ -// Copyright IBM Corp. 2021 All Rights Reserved. -// Licensed under the Mozilla Public License v2.0 - -package scc - -import ( - "context" - "fmt" - "log" - "time" - - "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" - "github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex" - "github.com/IBM-Cloud/terraform-provider-ibm/ibm/validate" - "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - - "github.com/IBM/scc-go-sdk/findingsv1" -) - -func ValidatePageSize(val interface{}, key string) (warns []string, errs []error) { - v := int64(val.(int)) - if v < 2 { - errs = append(errs, fmt.Errorf("%q must be atleast 2, got: %d", key, v)) - } - return -} - -func DataSourceIBMSccSiNotes() *schema.Resource { - return &schema.Resource{ - ReadContext: dataSourceIBMSccSiNotesRead, - - Schema: map[string]*schema.Schema{ - "account_id": { - Type: schema.TypeString, - Optional: true, - }, - "provider_id": { - Type: schema.TypeString, - Required: true, - Description: "Part of the parent. This field contains the provider ID. For example: providers/{provider_id}.", - }, - "page_size": { - Type: schema.TypeInt, - Optional: true, - ValidateFunc: ValidatePageSize, - Description: "Number of notes to return in the list.", - }, - "page_token": { - Type: schema.TypeString, - Optional: true, - Description: "Token to provide to skip to a particular spot in the list.", - }, - "notes": { - Type: schema.TypeList, - Computed: true, - Description: "The notes requested.", - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "note_id": { - Type: schema.TypeString, - Computed: true, - Description: "The id of the note.", - }, - "short_description": { - Type: schema.TypeString, - Computed: true, - Description: "A one sentence description of your note.", - }, - "long_description": { - Type: schema.TypeString, - Computed: true, - Description: "A more detailed description of your note.", - }, - "kind": { - Type: schema.TypeString, - Computed: true, - Description: "The type of note. Use this field to filter notes and occurences by kind. - FINDING: The note and occurrence represent a finding. - KPI: The note and occurrence represent a KPI value. - CARD: The note represents a card showing findings and related metric values. - CARD_CONFIGURED: The note represents a card configured for a user account. - SECTION: The note represents a section in a dashboard.", - }, - "related_url": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "label": { - Type: schema.TypeString, - Computed: true, - Description: "Label to describe usage of the URL.", - }, - "url": { - Type: schema.TypeString, - Computed: true, - Description: "The URL that you want to associate with the note.", - }, - }, - }, - }, - "create_time": { - Type: schema.TypeString, - Computed: true, - Description: "Output only. The time this note was created. This field can be used as a filter in list requests.", - }, - "update_time": { - Type: schema.TypeString, - Computed: true, - Description: "Output only. The time this note was last updated. This field can be used as a filter in list requests.", - }, - "shared": { - Type: schema.TypeBool, - Computed: true, - Description: "True if this note can be shared by multiple accounts.", - }, - "reported_by": { - Type: schema.TypeList, - Computed: true, - Description: "The entity reporting a note.", - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "id": { - Type: schema.TypeString, - Computed: true, - Description: "The id of this reporter.", - }, - "title": { - Type: schema.TypeString, - Computed: true, - Description: "The title of this reporter.", - }, - "url": { - Type: schema.TypeString, - Computed: true, - Description: "The url of this reporter.", - }, - }, - }, - }, - "finding": { - Type: schema.TypeList, - Computed: true, - Description: "FindingType provides details about a finding note.", - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "severity": { - Type: schema.TypeString, - Computed: true, - Description: "Note provider-assigned severity/impact ranking- LOW: Low Impact- MEDIUM: Medium Impact- HIGH: High Impact- CRITICAL: Critical Impact.", - }, - "next_steps": { - Type: schema.TypeList, - Computed: true, - Description: "Common remediation steps for the finding of this type.", - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "title": { - Type: schema.TypeString, - Computed: true, - Description: "Title of this next step.", - }, - "url": { - Type: schema.TypeString, - Computed: true, - Description: "The URL associated to this next steps.", - }, - }, - }, - }, - }, - }, - }, - "kpi": { - Type: schema.TypeList, - Computed: true, - Description: "KpiType provides details about a KPI note.", - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "aggregation_type": { - Type: schema.TypeString, - Computed: true, - Description: "The aggregation type of the KPI values. - SUM: A single-value metrics aggregation type that sums up numeric values that are extracted from KPI occurrences.", - }, - }, - }, - }, - "card": { - Type: schema.TypeList, - Computed: true, - Description: "Card provides details about a card kind of note.", - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "section": { - Type: schema.TypeString, - Computed: true, - Description: "The section this card belongs to.", - }, - "title": { - Type: schema.TypeString, - Computed: true, - Description: "The title of this card.", - }, - "subtitle": { - Type: schema.TypeString, - Computed: true, - Description: "The subtitle of this card.", - }, - "order": { - Type: schema.TypeInt, - Computed: true, - Description: "The order of the card in which it will appear on SA dashboard in the mentioned section.", - }, - "finding_note_names": { - Type: schema.TypeList, - Computed: true, - Description: "The finding note names associated to this card.", - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - }, - "requires_configuration": { - Type: schema.TypeBool, - Computed: true, - }, - "badge_text": { - Type: schema.TypeString, - Computed: true, - Description: "The text associated to the card's badge.", - }, - "badge_image": { - Type: schema.TypeString, - Computed: true, - Description: "The base64 content of the image associated to the card's badge.", - }, - "elements": { - Type: schema.TypeList, - Computed: true, - Description: "The elements of this card.", - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "text": { - Type: schema.TypeString, - Computed: true, - Description: "The text of this card element.", - }, - "kind": { - Type: schema.TypeString, - Computed: true, - Description: "Kind of element- NUMERIC: Single numeric value- BREAKDOWN: Breakdown of numeric values- TIME_SERIES: Time-series of numeric values.", - }, - "default_time_range": { - Type: schema.TypeString, - Computed: true, - Description: "The default time range of this card element.", - }, - "value_type": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "kind": { - Type: schema.TypeString, - Computed: true, - Description: "Kind of element- KPI: Kind of value derived from a KPI occurrence.", - }, - "kpi_note_name": { - Type: schema.TypeString, - Computed: true, - Description: "The name of the kpi note associated to the occurrence with the value for this card element value type.", - }, - "text": { - Type: schema.TypeString, - Computed: true, - Description: "The text of this element type.", - }, - "finding_note_names": { - Type: schema.TypeList, - Computed: true, - Description: "the names of the finding note associated that act as filters for counting the occurrences.", - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - }, - }, - }, - }, - "value_types": { - Type: schema.TypeList, - Computed: true, - Description: "the value types associated to this card element.", - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "kind": { - Type: schema.TypeString, - Computed: true, - Description: "Kind of element- KPI: Kind of value derived from a KPI occurrence.", - }, - "kpi_note_name": { - Type: schema.TypeString, - Computed: true, - Description: "The name of the kpi note associated to the occurrence with the value for this card element value type.", - }, - "text": { - Type: schema.TypeString, - Computed: true, - Description: "The text of this element type.", - }, - "finding_note_names": { - Type: schema.TypeList, - Computed: true, - Description: "the names of the finding note associated that act as filters for counting the occurrences.", - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - }, - }, - }, - }, - "default_interval": { - Type: schema.TypeString, - Computed: true, - Description: "The default interval of the time series.", - }, - }, - }, - }, - }, - }, - }, - "section": { - Type: schema.TypeList, - Computed: true, - Description: "Card provides details about a card kind of note.", - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "title": { - Type: schema.TypeString, - Computed: true, - Description: "The title of this section.", - }, - "image": { - Type: schema.TypeString, - Computed: true, - Description: "The image of this section.", - }, - }, - }, - }, - }, - }, - }, - }, - } -} - -func DataSourceIBMSccSiNotesValidator() *validate.ResourceValidator { - validateSchema := make([]validate.ValidateSchema, 0) - validateSchema = append(validateSchema, - validate.ValidateSchema{ - Identifier: "page_size", - ValidateFunctionIdentifier: validate.IntBetween, - Required: false, - MinValue: "2"}) - - ibmSccSiNotesDataSourceValidator := validate.ResourceValidator{ResourceName: "ibm_scc_si_notes", Schema: validateSchema} - return &ibmSccSiNotesDataSourceValidator -} - -func dataSourceIBMSccSiNotesRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - findingsClient, err := meta.(conns.ClientSession).FindingsV1() - if err != nil { - return diag.FromErr(err) - } - userDetails, err := meta.(conns.ClientSession).BluemixUserDetails() - if err != nil { - return diag.FromErr(err) - } - - accountID := d.Get("account_id").(string) - log.Println(fmt.Sprintf("[DEBUG] using specified AccountID %s", accountID)) - if accountID == "" { - accountID = userDetails.UserAccount - log.Println(fmt.Sprintf("[DEBUG] AccountID not spedified, using %s", accountID)) - } - findingsClient.AccountID = &accountID - - listNoteOptions := &findingsv1.ListNotesOptions{} - - if pageSize, ok := d.GetOk("page_size"); ok { - listNoteOptions.SetPageSize(int64(pageSize.(int))) - } - if pageToken, ok := d.GetOk("page_token"); ok { - listNoteOptions.SetPageToken(pageToken.(string)) - } - listNoteOptions.SetProviderID(d.Get("provider_id").(string)) - - apiNotes := []findingsv1.APINote{} - - if listNoteOptions.PageToken != nil { - apiNotes, err = collectSpecificNotes(findingsClient, context, listNoteOptions) - if err != nil { - log.Printf("[DEBUG] GetNoteWithContext failed %s", err) - return diag.FromErr(fmt.Errorf("GetNoteWithContext failed %s", err)) - } - } else { - apiNotes, err = collectAllNotes(findingsClient, context, listNoteOptions) - if err != nil { - log.Printf("[DEBUG] GetNoteWithContext failed %s", err) - return diag.FromErr(fmt.Errorf("GetNoteWithContext failed %s", err)) - } - } - - d.SetId(dataSourceIBMSccSiNotesID(d)) - - if apiNotes != nil { - err = d.Set("notes", dataSourceAPIListNotesResponseFlattenProviders(apiNotes)) - if err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting notes %s", err)) - } - } - - return nil -} - -// dataSourceIBMSccSiNotesID returns a reasonable ID for the list. -func dataSourceIBMSccSiNotesID(d *schema.ResourceData) string { - return time.Now().UTC().String() -} - -func collectSpecificNotes(findingsClient *findingsv1.FindingsV1, ctx context.Context, options *findingsv1.ListNotesOptions) ([]findingsv1.APINote, error) { - apiListNotesResponse, response, err := findingsClient.ListNotesWithContext(ctx, options) - if err != nil { - return nil, fmt.Errorf("%s\n%s", err, response) - } - - return apiListNotesResponse.Notes, nil -} - -func collectAllNotes(findingsClient *findingsv1.FindingsV1, ctx context.Context, options *findingsv1.ListNotesOptions) ([]findingsv1.APINote, error) { - finalList := []findingsv1.APINote{} - - for { - apiListNotesResponse, response, err := findingsClient.ListNotesWithContext(ctx, options) - if err != nil { - return nil, fmt.Errorf("%s\n%s", err, response) - } - - finalList = append(finalList, apiListNotesResponse.Notes...) - - if options.PageSize != nil && int64(len(finalList)) == *options.PageSize { - break - } - - options.PageToken = apiListNotesResponse.NextPageToken - - if *apiListNotesResponse.NextPageToken == "" { - break - } - } - - return finalList, nil -} - -func dataSourceAPIListNotesResponseFlattenProviders(result []findingsv1.APINote) (notes []map[string]interface{}) { - for _, notesItem := range result { - notes = append(notes, dataSourceAPIListNotesResponseProvidersToMap(notesItem)) - } - - return notes -} - -func dataSourceAPIListNotesResponseProvidersToMap(notesItem findingsv1.APINote) (notesMap map[string]interface{}) { - notesMap = map[string]interface{}{} - - if notesItem.ID != nil { - notesMap["note_id"] = notesItem.ID - } - if notesItem.ShortDescription != nil { - notesMap["short_description"] = notesItem.ShortDescription - } - if notesItem.LongDescription != nil { - notesMap["long_description"] = notesItem.LongDescription - } - if notesItem.Kind != nil { - notesMap["kind"] = notesItem.Kind - } - - if notesItem.RelatedURL != nil { - notesMap["related_url"] = dataSourceAPINotesFlattenRelatedURL(notesItem.RelatedURL) - } - - if notesItem.CreateTime != nil { - notesMap["create_time"] = flex.DateTimeToString(notesItem.CreateTime) - } - if notesItem.UpdateTime != nil { - notesMap["update_time"] = flex.DateTimeToString(notesItem.UpdateTime) - } - if notesItem.Shared != nil { - notesMap["shared"] = notesItem.Shared - } - - if notesItem.ReportedBy != nil { - notesMap["reported_by"] = dataSourceAPINotesFlattenReportedBy(*notesItem.ReportedBy) - } - - if notesItem.Finding != nil { - notesMap["finding"] = dataSourceAPINotesFlattenFinding(*notesItem.Finding) - } - - if notesItem.Kpi != nil { - notesMap["kpi"] = dataSourceAPINotesFlattenKpi(*notesItem.Kpi) - } - - if notesItem.Card != nil { - notesMap["card"] = dataSourceAPINotesFlattenCard(*notesItem.Card) - } - - if notesItem.Section != nil { - notesMap["section"] = dataSourceAPINotesFlattenSection(*notesItem.Section) - } - - return notesMap -} - -func dataSourceAPINotesFlattenRelatedURL(result []findingsv1.APINoteRelatedURL) (relatedURL []map[string]interface{}) { - for _, relatedURLItem := range result { - relatedURL = append(relatedURL, dataSourceAPINotesRelatedURLToMap(relatedURLItem)) - } - - return relatedURL -} - -func dataSourceAPINotesRelatedURLToMap(relatedURLItem findingsv1.APINoteRelatedURL) (relatedURLMap map[string]interface{}) { - relatedURLMap = map[string]interface{}{} - - if relatedURLItem.Label != nil { - relatedURLMap["label"] = relatedURLItem.Label - } - if relatedURLItem.URL != nil { - relatedURLMap["url"] = relatedURLItem.URL - } - - return relatedURLMap -} - -func dataSourceAPINotesFlattenReportedBy(result findingsv1.Reporter) (finalList []map[string]interface{}) { - finalList = []map[string]interface{}{} - finalMap := dataSourceAPINotesReportedByToMap(result) - finalList = append(finalList, finalMap) - - return finalList -} - -func dataSourceAPINotesReportedByToMap(reportedByItem findingsv1.Reporter) (reportedByMap map[string]interface{}) { - reportedByMap = map[string]interface{}{} - - if reportedByItem.ID != nil { - reportedByMap["id"] = reportedByItem.ID - } - if reportedByItem.Title != nil { - reportedByMap["title"] = reportedByItem.Title - } - if reportedByItem.URL != nil { - reportedByMap["url"] = reportedByItem.URL - } - - return reportedByMap -} - -func dataSourceAPINotesFlattenFinding(result findingsv1.FindingType) (finalList []map[string]interface{}) { - finalList = []map[string]interface{}{} - finalMap := dataSourceAPINotesFindingToMap(result) - finalList = append(finalList, finalMap) - - return finalList -} - -func dataSourceAPINotesFindingToMap(findingItem findingsv1.FindingType) (findingMap map[string]interface{}) { - findingMap = map[string]interface{}{} - - if findingItem.Severity != nil { - findingMap["severity"] = findingItem.Severity - } - if findingItem.NextSteps != nil { - nextStepsList := []map[string]interface{}{} - for _, nextStepsItem := range findingItem.NextSteps { - nextStepsList = append(nextStepsList, dataSourceAPINotesFindingNextStepsToMap(nextStepsItem)) - } - findingMap["next_steps"] = nextStepsList - } - - return findingMap -} - -func dataSourceAPINotesFindingNextStepsToMap(nextStepsItem findingsv1.RemediationStep) (nextStepsMap map[string]interface{}) { - nextStepsMap = map[string]interface{}{} - - if nextStepsItem.Title != nil { - nextStepsMap["title"] = nextStepsItem.Title - } - if nextStepsItem.URL != nil { - nextStepsMap["url"] = nextStepsItem.URL - } - - return nextStepsMap -} - -func dataSourceAPINotesFlattenKpi(result findingsv1.KpiType) (finalList []map[string]interface{}) { - finalList = []map[string]interface{}{} - finalMap := dataSourceAPINotesKpiToMap(result) - finalList = append(finalList, finalMap) - - return finalList -} - -func dataSourceAPINotesKpiToMap(kpiItem findingsv1.KpiType) (kpiMap map[string]interface{}) { - kpiMap = map[string]interface{}{} - - if kpiItem.AggregationType != nil { - kpiMap["aggregation_type"] = kpiItem.AggregationType - } - - return kpiMap -} - -func dataSourceAPINotesFlattenCard(result findingsv1.Card) (finalList []map[string]interface{}) { - finalList = []map[string]interface{}{} - finalMap := dataSourceAPINotesCardToMap(result) - finalList = append(finalList, finalMap) - - return finalList -} - -func dataSourceAPINotesCardToMap(cardItem findingsv1.Card) (cardMap map[string]interface{}) { - cardMap = map[string]interface{}{} - - if cardItem.Section != nil { - cardMap["section"] = cardItem.Section - } - if cardItem.Title != nil { - cardMap["title"] = cardItem.Title - } - if cardItem.Subtitle != nil { - cardMap["subtitle"] = cardItem.Subtitle - } - if cardItem.Order != nil { - cardMap["order"] = cardItem.Order - } - if cardItem.FindingNoteNames != nil { - cardMap["finding_note_names"] = cardItem.FindingNoteNames - } - if cardItem.RequiresConfiguration != nil { - cardMap["requires_configuration"] = cardItem.RequiresConfiguration - } - if cardItem.BadgeText != nil { - cardMap["badge_text"] = cardItem.BadgeText - } - if cardItem.BadgeImage != nil { - cardMap["badge_image"] = cardItem.BadgeImage - } - if cardItem.Elements != nil { - elementsList := []map[string]interface{}{} - for _, elementsItem := range cardItem.Elements { - elementsList = append(elementsList, dataSourceAPINotesCardElementsToMap(elementsItem)) - } - cardMap["elements"] = elementsList - } - - return cardMap -} - -func dataSourceAPINotesCardElementsToMap(elementsItem findingsv1.CardElementIntf) (elementsMap map[string]interface{}) { - cardElementMap := map[string]interface{}{} - - switch v := elementsItem.(type) { - case *findingsv1.CardElementNumericCardElement: - cardElementMap["value_type"] = []map[string]interface{}{dataSourceAPINotesElementsValueTypeToMap(*v.ValueType)} - case *findingsv1.CardElementBreakdownCardElement: - cardElementMap["value_types"] = dataSourceAPINotesElementsValueTypesToMap(v.ValueTypes) - case *findingsv1.CardElementTimeSeriesCardElement: - cardElementMap["value_types"] = dataSourceAPINotesElementsValueTypesToMap(v.ValueTypes) - } - - return cardElementMap -} - -func dataSourceAPINotesElementsValueTypeToMap(valueTypeItem findingsv1.NumericCardElementValueType) (valueTypeMap map[string]interface{}) { - valueTypeMap = map[string]interface{}{} - - if valueTypeItem.Kind != nil { - valueTypeMap["kind"] = valueTypeItem.Kind - } - if valueTypeItem.KpiNoteName != nil { - valueTypeMap["kpi_note_name"] = valueTypeItem.KpiNoteName - } - if valueTypeItem.Text != nil { - valueTypeMap["text"] = valueTypeItem.Text - } - if valueTypeItem.FindingNoteNames != nil { - valueTypeMap["finding_note_names"] = valueTypeItem.FindingNoteNames - } - - return valueTypeMap -} - -func dataSourceAPINotesElementsFindingCountValueTypeToMap(valueTypeItem findingsv1.ValueTypeFindingCountValueType) (valueTypeMap map[string]interface{}) { - valueTypeMap = map[string]interface{}{} - - if valueTypeItem.Kind != nil { - valueTypeMap["kind"] = valueTypeItem.Kind - } - if valueTypeItem.Text != nil { - valueTypeMap["text"] = valueTypeItem.Text - } - if valueTypeItem.FindingNoteNames != nil { - valueTypeMap["finding_note_names"] = valueTypeItem.FindingNoteNames - } - - return valueTypeMap -} - -func dataSourceAPINotesElementsKpiValueTypeToMap(valueTypeItem findingsv1.ValueTypeKpiValueType) (valueTypeMap map[string]interface{}) { - valueTypeMap = map[string]interface{}{} - - if valueTypeItem.Kind != nil { - valueTypeMap["kind"] = valueTypeItem.Kind - } - if valueTypeItem.Text != nil { - valueTypeMap["text"] = valueTypeItem.Text - } - if valueTypeItem.KpiNoteName != nil { - valueTypeMap["kpi_note_name"] = valueTypeItem.KpiNoteName - } - - return valueTypeMap -} - -func dataSourceAPINotesElementsValueTypesToMap(valueTypesItem []findingsv1.ValueTypeIntf) (valueTypesMap []map[string]interface{}) { - valueTypesMap = []map[string]interface{}{} - - valueTypeMap := map[string]interface{}{} - - for _, valueType := range valueTypesItem { - - switch v := valueType.(type) { - case *findingsv1.NumericCardElementValueType: - valueTypeMap = dataSourceAPINotesElementsValueTypeToMap(*v) - case *findingsv1.ValueTypeFindingCountValueType: - valueTypeMap = dataSourceAPINotesElementsFindingCountValueTypeToMap(*v) - case *findingsv1.ValueTypeKpiValueType: - valueTypeMap = dataSourceAPINotesElementsKpiValueTypeToMap(*v) - } - - valueTypesMap = append(valueTypesMap, valueTypeMap) - } - - return valueTypesMap -} - -func dataSourceAPINotesFlattenSection(result findingsv1.Section) (finalList []map[string]interface{}) { - finalList = []map[string]interface{}{} - finalMap := dataSourceAPINotesSectionToMap(result) - finalList = append(finalList, finalMap) - - return finalList -} - -func dataSourceAPINotesSectionToMap(sectionItem findingsv1.Section) (sectionMap map[string]interface{}) { - sectionMap = map[string]interface{}{} - - if sectionItem.Title != nil { - sectionMap["title"] = sectionItem.Title - } - if sectionItem.Image != nil { - sectionMap["image"] = sectionItem.Image - } - - return sectionMap -} diff --git a/ibm/service/scc/data_source_ibm_scc_si_notes_test.go b/ibm/service/scc/data_source_ibm_scc_si_notes_test.go deleted file mode 100644 index 8291b50d4a..0000000000 --- a/ibm/service/scc/data_source_ibm_scc_si_notes_test.go +++ /dev/null @@ -1,143 +0,0 @@ -// Copyright IBM Corp. 2021 All Rights Reserved. -// Licensed under the Mozilla Public License v2.0 - -package scc_test - -import ( - "fmt" - "testing" - - acc "github.com/IBM-Cloud/terraform-provider-ibm/ibm/acctest" - - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" -) - -func TestAccIBMSccSiNotesDataSourceBasic(t *testing.T) { - apiNoteProviderID := fmt.Sprintf("tf_provider_id_%d", acctest.RandIntRange(10, 100)) - apiNoteShortDescription := fmt.Sprintf("tf_short_description_%d", acctest.RandIntRange(10, 100)) - apiNoteLongDescription := fmt.Sprintf("tf_long_description_%d", acctest.RandIntRange(10, 100)) - apiNoteKind := "FINDING" - apiNoteID := fmt.Sprintf("tf_note_id_%d", acctest.RandIntRange(10, 100)) - - resource.Test(t, resource.TestCase{ - PreCheck: func() { acc.TestAccPreCheck(t) }, - Providers: acc.TestAccProviders, - Steps: []resource.TestStep{ - { - Config: testAccCheckIBMSccSiNotesDataSourceConfigBasic(acc.Scc_si_account, apiNoteProviderID, apiNoteShortDescription, apiNoteLongDescription, apiNoteKind, apiNoteID), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet("data.ibm_scc_si_notes.scc_si_notes", "id"), - resource.TestCheckResourceAttrSet("data.ibm_scc_si_notes.scc_si_notes", "provider_id"), - resource.TestCheckResourceAttrSet("data.ibm_scc_si_notes.scc_si_notes", "notes.#"), - resource.TestCheckResourceAttrSet("data.ibm_scc_si_notes.scc_si_notes", "notes.0.short_description"), - resource.TestCheckResourceAttrSet("data.ibm_scc_si_notes.scc_si_notes", "notes.0.long_description"), - resource.TestCheckResourceAttrSet("data.ibm_scc_si_notes.scc_si_notes", "notes.0.kind"), - resource.TestCheckResourceAttrSet("data.ibm_scc_si_notes.scc_si_notes", "notes.0.related_url.#"), - resource.TestCheckResourceAttrSet("data.ibm_scc_si_notes.scc_si_notes", "notes.0.create_time"), - resource.TestCheckResourceAttrSet("data.ibm_scc_si_notes.scc_si_notes", "notes.0.update_time"), - ), - }, - }, - }) -} - -func TestAccIBMSccSiNotesDataSourceAllArgs(t *testing.T) { - apiNoteProviderID := fmt.Sprintf("tf_provider_id_%d", acctest.RandIntRange(10, 100)) - apiNoteShortDescription := fmt.Sprintf("tf_short_description_%d", acctest.RandIntRange(10, 100)) - apiNoteLongDescription := fmt.Sprintf("tf_long_description_%d", acctest.RandIntRange(10, 100)) - apiNoteKind := "FINDING" - apiNoteID := fmt.Sprintf("tf_note_id_%d", acctest.RandIntRange(10, 100)) - apiNoteShared := "true" - - resource.Test(t, resource.TestCase{ - PreCheck: func() { acc.TestAccPreCheck(t) }, - Providers: acc.TestAccProviders, - Steps: []resource.TestStep{ - { - Config: testAccCheckIBMSccSiNotesDataSourceConfig(acc.Scc_si_account, apiNoteProviderID, apiNoteShortDescription, apiNoteLongDescription, apiNoteKind, apiNoteID, apiNoteShared), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet("data.ibm_scc_si_notes.scc_si_notes", "id"), - resource.TestCheckResourceAttrSet("data.ibm_scc_si_notes.scc_si_notes", "provider_id"), - resource.TestCheckResourceAttrSet("data.ibm_scc_si_notes.scc_si_notes", "notes.#"), - resource.TestCheckResourceAttrSet("data.ibm_scc_si_notes.scc_si_notes", "notes.0.short_description"), - resource.TestCheckResourceAttrSet("data.ibm_scc_si_notes.scc_si_notes", "notes.0.long_description"), - resource.TestCheckResourceAttrSet("data.ibm_scc_si_notes.scc_si_notes", "notes.0.kind"), - resource.TestCheckResourceAttrSet("data.ibm_scc_si_notes.scc_si_notes", "notes.0.related_url.#"), - resource.TestCheckResourceAttrSet("data.ibm_scc_si_notes.scc_si_notes", "notes.0.related_url.0.label"), - resource.TestCheckResourceAttrSet("data.ibm_scc_si_notes.scc_si_notes", "notes.0.related_url.0.url"), - resource.TestCheckResourceAttrSet("data.ibm_scc_si_notes.scc_si_notes", "notes.0.create_time"), - resource.TestCheckResourceAttrSet("data.ibm_scc_si_notes.scc_si_notes", "notes.0.update_time"), - resource.TestCheckResourceAttrSet("data.ibm_scc_si_notes.scc_si_notes", "notes.0.shared"), - resource.TestCheckResourceAttrSet("data.ibm_scc_si_notes.scc_si_notes", "notes.0.reported_by.#"), - resource.TestCheckResourceAttrSet("data.ibm_scc_si_notes.scc_si_notes", "notes.0.finding.#"), - ), - }, - }, - }) -} - -func testAccCheckIBMSccSiNotesDataSourceConfigBasic(accountID string, apiNoteProviderID string, apiNoteShortDescription string, apiNoteLongDescription string, apiNoteKind string, apiNoteID string) string { - return fmt.Sprintf(` - resource "ibm_scc_si_note" "scc_si_note" { - account_id = "%s" - provider_id = "%s" - short_description = "%s" - long_description = "%s" - kind = "%s" - note_id = "%s" - reported_by { - id = "id" - title = "title" - url = "url" - } - finding { - severity = "LOW" - next_steps { - title = "title" - url = "url" - } - } - } - - data "ibm_scc_si_notes" "scc_si_notes" { - account_id = ibm_scc_si_note.scc_si_note.account_id - provider_id = ibm_scc_si_note.scc_si_note.provider_id - } - `, accountID, apiNoteProviderID, apiNoteShortDescription, apiNoteLongDescription, apiNoteKind, apiNoteID) -} - -func testAccCheckIBMSccSiNotesDataSourceConfig(accountID string, apiNoteProviderID string, apiNoteShortDescription string, apiNoteLongDescription string, apiNoteKind string, apiNoteID string, apiNoteShared string) string { - return fmt.Sprintf(` - resource "ibm_scc_si_note" "scc_si_note" { - account_id = "%s" - provider_id = "%s" - short_description = "%s" - long_description = "%s" - kind = "%s" - note_id = "%s" - reported_by { - id = "id" - title = "title" - url = "url" - } - related_url { - label = "label" - url = "url" - } - shared = %s - finding { - severity = "LOW" - next_steps { - title = "title" - url = "url" - } - } - } - - data "ibm_scc_si_notes" "scc_si_notes" { - account_id = ibm_scc_si_note.scc_si_note.account_id - provider_id = ibm_scc_si_note.scc_si_note.provider_id - } - `, accountID, apiNoteProviderID, apiNoteShortDescription, apiNoteLongDescription, apiNoteKind, apiNoteID, apiNoteShared) -} diff --git a/ibm/service/scc/data_source_ibm_scc_si_occurrence.go b/ibm/service/scc/data_source_ibm_scc_si_occurrence.go deleted file mode 100644 index 3cccc430ad..0000000000 --- a/ibm/service/scc/data_source_ibm_scc_si_occurrence.go +++ /dev/null @@ -1,534 +0,0 @@ -// Copyright IBM Corp. 2021 All Rights Reserved. -// Licensed under the Mozilla Public License v2.0 - -package scc - -import ( - "context" - "fmt" - "log" - - "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" - "github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex" - "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - - "github.com/IBM/scc-go-sdk/findingsv1" -) - -func DataSourceIBMSccSiOccurrence() *schema.Resource { - return &schema.Resource{ - ReadContext: dataSourceIBMSccSiOccurrenceRead, - - Schema: map[string]*schema.Schema{ - "account_id": { - Type: schema.TypeString, - Optional: true, - }, - "provider_id": { - Type: schema.TypeString, - Required: true, - Description: "Part of the parent. This field contains the provider ID. For example: providers/{provider_id}.", - }, - "occurrence_id": { - Type: schema.TypeString, - Required: true, - Description: "Second part of occurrence `name`: providers/{provider_id}/occurrences/{occurrence_id}.", - }, - "resource_url": { - Type: schema.TypeString, - Computed: true, - Description: "The unique URL of the resource, image or the container, for which the `Occurrence` applies. For example, https://gcr.io/provider/image@sha256:foo. This field can be used as a filter in list requests.", - }, - "note_name": { - Type: schema.TypeString, - Computed: true, - Description: "An analysis note associated with this image, in the form \"{account_id}/providers/{provider_id}/notes/{note_id}\" This field can be used as a filter in list requests.", - }, - "kind": { - Type: schema.TypeString, - Computed: true, - Description: "The type of note. Use this field to filter notes and occurences by kind. - FINDING: The note and occurrence represent a finding. - KPI: The note and occurrence represent a KPI value. - CARD: The note represents a card showing findings and related metric values. - CARD_CONFIGURED: The note represents a card configured for a user account. - SECTION: The note represents a section in a dashboard.", - }, - "remediation": { - Type: schema.TypeString, - Computed: true, - Description: "A description of actions that can be taken to remedy the `Note`.", - }, - "create_time": { - Type: schema.TypeString, - Computed: true, - Description: "Output only. The time this `Occurrence` was created.", - }, - "update_time": { - Type: schema.TypeString, - Computed: true, - Description: "Output only. The time this `Occurrence` was last updated.", - }, - "context": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "region": { - Type: schema.TypeString, - Computed: true, - Description: "The IBM Cloud region.", - }, - "resource_crn": { - Type: schema.TypeString, - Computed: true, - Description: "The resource CRN (e.g. certificate CRN, image CRN).", - }, - "resource_id": { - Type: schema.TypeString, - Computed: true, - Description: "The resource ID, in case the CRN is not available.", - }, - "resource_name": { - Type: schema.TypeString, - Computed: true, - Description: "The user-friendly resource name.", - }, - "resource_type": { - Type: schema.TypeString, - Computed: true, - Description: "The resource type name (e.g. Pod, Cluster, Certificate, Image).", - }, - "service_crn": { - Type: schema.TypeString, - Computed: true, - Description: "The service CRN (e.g. CertMgr Instance CRN).", - }, - "service_name": { - Type: schema.TypeString, - Computed: true, - Description: "The service name (e.g. CertMgr).", - }, - "environment_name": { - Type: schema.TypeString, - Computed: true, - Description: "The name of the environment the occurrence applies to.", - }, - "component_name": { - Type: schema.TypeString, - Computed: true, - Description: "The name of the component the occurrence applies to.", - }, - "toolchain_id": { - Type: schema.TypeString, - Computed: true, - Description: "The id of the toolchain the occurrence applies to.", - }, - }, - }, - }, - "finding": { - Type: schema.TypeList, - Computed: true, - Description: "Finding provides details about a finding occurrence.", - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "severity": { - Type: schema.TypeString, - Computed: true, - Description: "Note provider-assigned severity/impact ranking- LOW: Low Impact- MEDIUM: Medium Impact- HIGH: High Impact- CRITICAL: Critical Impact.", - }, - "certainty": { - Type: schema.TypeString, - Computed: true, - Description: "Note provider-assigned confidence on the validity of an occurrence- LOW: Low Certainty- MEDIUM: Medium Certainty- HIGH: High Certainty.", - }, - "next_steps": { - Type: schema.TypeList, - Computed: true, - Description: "Remediation steps for the issues reported in this finding. They override the note's next steps.", - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "title": { - Type: schema.TypeString, - Computed: true, - Description: "Title of this next step.", - }, - "url": { - Type: schema.TypeString, - Computed: true, - Description: "The URL associated to this next steps.", - }, - }, - }, - }, - "network_connection": { - Type: schema.TypeList, - Computed: true, - Description: "It provides details about a network connection.", - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "direction": { - Type: schema.TypeString, - Computed: true, - Description: "The direction of this network connection.", - }, - "protocol": { - Type: schema.TypeString, - Computed: true, - Description: "The protocol of this network connection.", - }, - "client": { - Type: schema.TypeList, - Computed: true, - Description: "It provides details about a socket address.", - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "address": { - Type: schema.TypeString, - Computed: true, - Description: "The IP address of this socket address.", - }, - "port": { - Type: schema.TypeInt, - Computed: true, - Description: "The port number of this socket address.", - }, - }, - }, - }, - "server": { - Type: schema.TypeList, - Computed: true, - Description: "It provides details about a socket address.", - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "address": { - Type: schema.TypeString, - Computed: true, - Description: "The IP address of this socket address.", - }, - "port": { - Type: schema.TypeInt, - Computed: true, - Description: "The port number of this socket address.", - }, - }, - }, - }, - }, - }, - }, - "data_transferred": { - Type: schema.TypeList, - Computed: true, - Description: "It provides details about data transferred between clients and servers.", - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "client_bytes": { - Type: schema.TypeInt, - Computed: true, - Description: "The number of client bytes transferred.", - }, - "server_bytes": { - Type: schema.TypeInt, - Computed: true, - Description: "The number of server bytes transferred.", - }, - "client_packets": { - Type: schema.TypeInt, - Computed: true, - Description: "The number of client packets transferred.", - }, - "server_packets": { - Type: schema.TypeInt, - Computed: true, - Description: "The number of server packets transferred.", - }, - }, - }, - }, - }, - }, - }, - "kpi": { - Type: schema.TypeList, - Computed: true, - Description: "Kpi provides details about a KPI occurrence.", - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "value": { - Type: schema.TypeFloat, - Computed: true, - Description: "The value of this KPI.", - }, - "total": { - Type: schema.TypeFloat, - Computed: true, - Description: "The total value of this KPI.", - }, - }, - }, - }, - }, - } -} - -func dataSourceIBMSccSiOccurrenceRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - findingsClient, err := meta.(conns.ClientSession).FindingsV1() - if err != nil { - return diag.FromErr(err) - } - - userDetails, err := meta.(conns.ClientSession).BluemixUserDetails() - if err != nil { - return diag.FromErr(err) - } - - accountID := d.Get("account_id").(string) - log.Println(fmt.Sprintf("[DEBUG] using specified AccountID %s", accountID)) - if accountID == "" { - accountID = userDetails.UserAccount - log.Println(fmt.Sprintf("[DEBUG] AccountID not spedified, using %s", accountID)) - } - findingsClient.AccountID = &accountID - - getOccurrenceOptions := &findingsv1.GetOccurrenceOptions{} - - getOccurrenceOptions.SetProviderID(d.Get("provider_id").(string)) - getOccurrenceOptions.SetOccurrenceID(d.Get("occurrence_id").(string)) - - apiOccurrence, response, err := findingsClient.GetOccurrenceWithContext(context, getOccurrenceOptions) - if err != nil { - log.Printf("[DEBUG] GetOccurrenceWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("GetOccurrenceWithContext failed %s\n%s", err, response)) - } - - d.SetId(fmt.Sprintf("%s/%s/%s", *findingsClient.AccountID, *getOccurrenceOptions.ProviderID, *getOccurrenceOptions.OccurrenceID)) - if err = d.Set("resource_url", apiOccurrence.ResourceURL); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting resource_url: %s", err)) - } - if err = d.Set("note_name", apiOccurrence.NoteName); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting note_name: %s", err)) - } - if err = d.Set("kind", apiOccurrence.Kind); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting kind: %s", err)) - } - if err = d.Set("remediation", apiOccurrence.Remediation); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting remediation: %s", err)) - } - if err = d.Set("create_time", flex.DateTimeToString(apiOccurrence.CreateTime)); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting create_time: %s", err)) - } - if err = d.Set("update_time", flex.DateTimeToString(apiOccurrence.UpdateTime)); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting update_time: %s", err)) - } - - if apiOccurrence.Context != nil { - err = d.Set("context", dataSourceAPIOccurrenceFlattenContext(*apiOccurrence.Context)) - if err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting context %s", err)) - } - } - - if apiOccurrence.Finding != nil { - err = d.Set("finding", dataSourceAPIOccurrenceFlattenFinding(*apiOccurrence.Finding)) - if err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting finding %s", err)) - } - } - - if apiOccurrence.Kpi != nil { - err = d.Set("kpi", dataSourceAPIOccurrenceFlattenKpi(*apiOccurrence.Kpi)) - if err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting kpi %s", err)) - } - } - - return nil -} - -func dataSourceAPIOccurrenceFlattenContext(result findingsv1.Context) (finalList []map[string]interface{}) { - finalList = []map[string]interface{}{} - finalMap := dataSourceAPIOccurrenceContextToMap(result) - finalList = append(finalList, finalMap) - - return finalList -} - -func dataSourceAPIOccurrenceContextToMap(contextItem findingsv1.Context) (contextMap map[string]interface{}) { - contextMap = map[string]interface{}{} - - if contextItem.Region != nil { - contextMap["region"] = contextItem.Region - } - if contextItem.ResourceCRN != nil { - contextMap["resource_crn"] = contextItem.ResourceCRN - } - if contextItem.ResourceID != nil { - contextMap["resource_id"] = contextItem.ResourceID - } - if contextItem.ResourceName != nil { - contextMap["resource_name"] = contextItem.ResourceName - } - if contextItem.ResourceType != nil { - contextMap["resource_type"] = contextItem.ResourceType - } - if contextItem.ServiceCRN != nil { - contextMap["service_crn"] = contextItem.ServiceCRN - } - if contextItem.ServiceName != nil { - contextMap["service_name"] = contextItem.ServiceName - } - if contextItem.EnvironmentName != nil { - contextMap["environment_name"] = contextItem.EnvironmentName - } - if contextItem.ComponentName != nil { - contextMap["component_name"] = contextItem.ComponentName - } - if contextItem.ToolchainID != nil { - contextMap["toolchain_id"] = contextItem.ToolchainID - } - - return contextMap -} - -func dataSourceAPIOccurrenceFlattenFinding(result findingsv1.Finding) (finalList []map[string]interface{}) { - finalList = []map[string]interface{}{} - finalMap := dataSourceAPIOccurrenceFindingToMap(result) - finalList = append(finalList, finalMap) - - return finalList -} - -func dataSourceAPIOccurrenceFindingToMap(findingItem findingsv1.Finding) (findingMap map[string]interface{}) { - findingMap = map[string]interface{}{} - - if findingItem.Severity != nil { - findingMap["severity"] = findingItem.Severity - } - if findingItem.Certainty != nil { - findingMap["certainty"] = findingItem.Certainty - } - if findingItem.NextSteps != nil { - nextStepsList := []map[string]interface{}{} - for _, nextStepsItem := range findingItem.NextSteps { - nextStepsList = append(nextStepsList, dataSourceAPIOccurrenceFindingNextStepsToMap(nextStepsItem)) - } - findingMap["next_steps"] = nextStepsList - } - if findingItem.NetworkConnection != nil { - networkConnectionList := []map[string]interface{}{} - networkConnectionMap := dataSourceAPIOccurrenceFindingNetworkConnectionToMap(*findingItem.NetworkConnection) - networkConnectionList = append(networkConnectionList, networkConnectionMap) - findingMap["network_connection"] = networkConnectionList - } - if findingItem.DataTransferred != nil { - dataTransferredList := []map[string]interface{}{} - dataTransferredMap := dataSourceAPIOccurrenceFindingDataTransferredToMap(*findingItem.DataTransferred) - dataTransferredList = append(dataTransferredList, dataTransferredMap) - findingMap["data_transferred"] = dataTransferredList - } - - return findingMap -} - -func dataSourceAPIOccurrenceFindingNextStepsToMap(nextStepsItem findingsv1.RemediationStep) (nextStepsMap map[string]interface{}) { - nextStepsMap = map[string]interface{}{} - - if nextStepsItem.Title != nil { - nextStepsMap["title"] = nextStepsItem.Title - } - if nextStepsItem.URL != nil { - nextStepsMap["url"] = nextStepsItem.URL - } - - return nextStepsMap -} - -func dataSourceAPIOccurrenceFindingNetworkConnectionToMap(networkConnectionItem findingsv1.NetworkConnection) (networkConnectionMap map[string]interface{}) { - networkConnectionMap = map[string]interface{}{} - - if networkConnectionItem.Direction != nil { - networkConnectionMap["direction"] = networkConnectionItem.Direction - } - if networkConnectionItem.Protocol != nil { - networkConnectionMap["protocol"] = networkConnectionItem.Protocol - } - if networkConnectionItem.Client != nil { - clientList := []map[string]interface{}{} - clientMap := dataSourceAPIOccurrenceNetworkConnectionClientToMap(*networkConnectionItem.Client) - clientList = append(clientList, clientMap) - networkConnectionMap["client"] = clientList - } - if networkConnectionItem.Server != nil { - serverList := []map[string]interface{}{} - serverMap := dataSourceAPIOccurrenceNetworkConnectionServerToMap(*networkConnectionItem.Server) - serverList = append(serverList, serverMap) - networkConnectionMap["server"] = serverList - } - - return networkConnectionMap -} - -func dataSourceAPIOccurrenceNetworkConnectionClientToMap(clientItem findingsv1.SocketAddress) (clientMap map[string]interface{}) { - clientMap = map[string]interface{}{} - - if clientItem.Address != nil { - clientMap["address"] = clientItem.Address - } - if clientItem.Port != nil { - clientMap["port"] = clientItem.Port - } - - return clientMap -} - -func dataSourceAPIOccurrenceNetworkConnectionServerToMap(serverItem findingsv1.SocketAddress) (serverMap map[string]interface{}) { - serverMap = map[string]interface{}{} - - if serverItem.Address != nil { - serverMap["address"] = serverItem.Address - } - if serverItem.Port != nil { - serverMap["port"] = serverItem.Port - } - - return serverMap -} - -func dataSourceAPIOccurrenceFindingDataTransferredToMap(dataTransferredItem findingsv1.DataTransferred) (dataTransferredMap map[string]interface{}) { - dataTransferredMap = map[string]interface{}{} - - if dataTransferredItem.ClientBytes != nil { - dataTransferredMap["client_bytes"] = dataTransferredItem.ClientBytes - } - if dataTransferredItem.ServerBytes != nil { - dataTransferredMap["server_bytes"] = dataTransferredItem.ServerBytes - } - if dataTransferredItem.ClientPackets != nil { - dataTransferredMap["client_packets"] = dataTransferredItem.ClientPackets - } - if dataTransferredItem.ServerPackets != nil { - dataTransferredMap["server_packets"] = dataTransferredItem.ServerPackets - } - - return dataTransferredMap -} - -func dataSourceAPIOccurrenceFlattenKpi(result findingsv1.Kpi) (finalList []map[string]interface{}) { - finalList = []map[string]interface{}{} - finalMap := dataSourceAPIOccurrenceKpiToMap(result) - finalList = append(finalList, finalMap) - - return finalList -} - -func dataSourceAPIOccurrenceKpiToMap(kpiItem findingsv1.Kpi) (kpiMap map[string]interface{}) { - kpiMap = map[string]interface{}{} - - if kpiItem.Value != nil { - kpiMap["value"] = kpiItem.Value - } - if kpiItem.Total != nil { - kpiMap["total"] = kpiItem.Total - } - - return kpiMap -} diff --git a/ibm/service/scc/data_source_ibm_scc_si_occurrence_test.go b/ibm/service/scc/data_source_ibm_scc_si_occurrence_test.go deleted file mode 100644 index c1b1eaadee..0000000000 --- a/ibm/service/scc/data_source_ibm_scc_si_occurrence_test.go +++ /dev/null @@ -1,214 +0,0 @@ -// Copyright IBM Corp. 2021 All Rights Reserved. -// Licensed under the Mozilla Public License v2.0 - -package scc_test - -import ( - "fmt" - "testing" - - acc "github.com/IBM-Cloud/terraform-provider-ibm/ibm/acctest" - - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" -) - -func TestAccIBMSccSiOccurrenceDataSourceBasic(t *testing.T) { - apiOccurrenceProviderID := fmt.Sprintf("tf_provider_id_%d", acctest.RandIntRange(10, 100)) - apiOccurrencenoteID := fmt.Sprintf("tf_note_id_%d", acctest.RandIntRange(10, 100)) - apiOccurrenceKind := "FINDING" - apiOccurrenceID := fmt.Sprintf("tf_occurrence_id_%d", acctest.RandIntRange(10, 100)) - - resource.Test(t, resource.TestCase{ - PreCheck: func() { acc.TestAccPreCheck(t) }, - Providers: acc.TestAccProviders, - Steps: []resource.TestStep{ - { - Config: testAccCheckIBMSccSiOccurrenceDataSourceConfigBasic(acc.Scc_si_account, apiOccurrenceProviderID, apiOccurrencenoteID, apiOccurrenceKind, apiOccurrenceID), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet("data.ibm_scc_si_occurrence.scc_si_occurrence", "id"), - resource.TestCheckResourceAttrSet("data.ibm_scc_si_occurrence.scc_si_occurrence", "provider_id"), - resource.TestCheckResourceAttrSet("data.ibm_scc_si_occurrence.scc_si_occurrence", "occurrence_id"), - resource.TestCheckResourceAttrSet("data.ibm_scc_si_occurrence.scc_si_occurrence", "note_name"), - resource.TestCheckResourceAttrSet("data.ibm_scc_si_occurrence.scc_si_occurrence", "kind"), - ), - }, - }, - }) -} - -func TestAccIBMSccSiOccurrenceDataSourceAllArgs(t *testing.T) { - apiOccurrenceProviderID := fmt.Sprintf("tf_provider_id_%d", acctest.RandIntRange(10, 100)) - apiOccurrencenoteID := fmt.Sprintf("tf_note_name_%d", acctest.RandIntRange(10, 100)) - apiOccurrenceKind := "FINDING" - apiOccurrenceID := fmt.Sprintf("tf_occurrence_id_%d", acctest.RandIntRange(10, 100)) - apiOccurrenceResourceURL := fmt.Sprintf("tf_resource_url_%d", acctest.RandIntRange(10, 100)) - apiOccurrenceRemediation := fmt.Sprintf("tf_remediation_%d", acctest.RandIntRange(10, 100)) - apiOccurrenceReplaceIfExists := "false" - - resource.Test(t, resource.TestCase{ - PreCheck: func() { acc.TestAccPreCheck(t) }, - Providers: acc.TestAccProviders, - Steps: []resource.TestStep{ - { - Config: testAccCheckIBMSccSiOccurrenceDataSourceConfig(acc.Scc_si_account, apiOccurrenceProviderID, apiOccurrencenoteID, apiOccurrenceKind, apiOccurrenceID, apiOccurrenceResourceURL, apiOccurrenceRemediation, apiOccurrenceReplaceIfExists), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet("data.ibm_scc_si_occurrence.scc_si_occurrence", "id"), - resource.TestCheckResourceAttrSet("data.ibm_scc_si_occurrence.scc_si_occurrence", "provider_id"), - resource.TestCheckResourceAttrSet("data.ibm_scc_si_occurrence.scc_si_occurrence", "occurrence_id"), - resource.TestCheckResourceAttrSet("data.ibm_scc_si_occurrence.scc_si_occurrence", "resource_url"), - resource.TestCheckResourceAttrSet("data.ibm_scc_si_occurrence.scc_si_occurrence", "note_name"), - resource.TestCheckResourceAttrSet("data.ibm_scc_si_occurrence.scc_si_occurrence", "kind"), - resource.TestCheckResourceAttrSet("data.ibm_scc_si_occurrence.scc_si_occurrence", "remediation"), - resource.TestCheckResourceAttrSet("data.ibm_scc_si_occurrence.scc_si_occurrence", "create_time"), - resource.TestCheckResourceAttrSet("data.ibm_scc_si_occurrence.scc_si_occurrence", "update_time"), - resource.TestCheckResourceAttrSet("data.ibm_scc_si_occurrence.scc_si_occurrence", "context.#"), - resource.TestCheckResourceAttrSet("data.ibm_scc_si_occurrence.scc_si_occurrence", "finding.#"), - ), - }, - }, - }) -} - -func testAccCheckIBMSccSiOccurrenceDataSourceConfigBasic(accountID string, apiOccurrenceProviderID string, apiOccurrencenoteID string, apiOccurrenceKind string, apiOccurrenceID string) string { - return fmt.Sprintf(` - - resource "ibm_scc_si_note" "finding" { - account_id = "%s" - provider_id = "%s" - short_description = "Security Threat" - long_description = "Security Threat found in your account" - kind = "FINDING" - note_id = "%s" - reported_by { - id = "scc-si-terraform" - title = "SCC SI Terraform" - url = "https://cloud.ibm.com" - } - finding { - severity = "LOW" - next_steps { - title = "Security Threat" - url = "https://cloud.ibm.com/security-compliance/findings" - } - } - } - - resource "ibm_scc_si_occurrence" "scc_si_occurrence" { - provider_id = "${ibm_scc_si_note.finding.provider_id}" - note_name = "%s/providers/${ibm_scc_si_note.finding.provider_id}/notes/${ibm_scc_si_note.finding.note_id}" - kind = "%s" - occurrence_id = "%s" - finding { - severity = "LOW" - certainty = "LOW" - next_steps { - title = "title" - url = "url" - } - network_connection { - direction = "direction" - protocol = "protocol" - client { - address = "address" - port = 1 - } - server { - address = "address" - port = 1 - } - } - data_transferred { - client_bytes = 1 - server_bytes = 1 - client_packets = 1 - server_packets = 1 - } - } - } - - data "ibm_scc_si_occurrence" "scc_si_occurrence" { - provider_id = ibm_scc_si_occurrence.scc_si_occurrence.provider_id - occurrence_id = ibm_scc_si_occurrence.scc_si_occurrence.occurrence_id - } - `, accountID, apiOccurrenceProviderID, apiOccurrencenoteID, accountID, apiOccurrenceKind, apiOccurrenceID) -} - -func testAccCheckIBMSccSiOccurrenceDataSourceConfig(accountID string, apiOccurrenceProviderID string, apiOccurrencenoteID string, apiOccurrenceKind string, apiOccurrenceID string, apiOccurrenceResourceURL string, apiOccurrenceRemediation string, apiOccurrenceReplaceIfExists string) string { - return fmt.Sprintf(` - - resource "ibm_scc_si_note" "finding" { - account_id = "%s" - provider_id = "%s" - short_description = "Security Threat" - long_description = "Security Threat found in your account" - kind = "FINDING" - note_id = "%s" - reported_by { - id = "scc-si-terraform" - title = "SCC SI Terraform" - url = "https://cloud.ibm.com" - } - finding { - severity = "LOW" - next_steps { - title = "Security Threat" - url = "https://cloud.ibm.com/security-compliance/findings" - } - } - } - - resource "ibm_scc_si_occurrence" "scc_si_occurrence" { - provider_id = "${ibm_scc_si_note.finding.provider_id}" - note_name = "%s/providers/${ibm_scc_si_note.finding.provider_id}/notes/${ibm_scc_si_note.finding.note_id}" - kind = "%s" - occurrence_id = "%s" - resource_url = "%s" - remediation = "%s" - context { - region = "region" - resource_crn = "resource_crn" - resource_id = "resource_id" - resource_name = "resource_name" - resource_type = "resource_type" - service_crn = "service_crn" - service_name = "service_name" - environment_name = "environment_name" - component_name = "component_name" - toolchain_id = "toolchain_id" - } - finding { - severity = "LOW" - certainty = "LOW" - next_steps { - title = "title" - url = "url" - } - network_connection { - direction = "direction" - protocol = "protocol" - client { - address = "address" - port = 1 - } - server { - address = "address" - port = 1 - } - } - data_transferred { - client_bytes = 1 - server_bytes = 1 - client_packets = 1 - server_packets = 1 - } - } - replace_if_exists = %s - } - - data "ibm_scc_si_occurrence" "scc_si_occurrence" { - provider_id = ibm_scc_si_occurrence.scc_si_occurrence.provider_id - occurrence_id = ibm_scc_si_occurrence.scc_si_occurrence.occurrence_id - } - `, accountID, apiOccurrenceProviderID, apiOccurrencenoteID, accountID, apiOccurrenceKind, apiOccurrenceID, apiOccurrenceResourceURL, apiOccurrenceRemediation, apiOccurrenceReplaceIfExists) -} diff --git a/ibm/service/scc/data_source_ibm_scc_si_occurrences.go b/ibm/service/scc/data_source_ibm_scc_si_occurrences.go deleted file mode 100644 index c33ba6eb70..0000000000 --- a/ibm/service/scc/data_source_ibm_scc_si_occurrences.go +++ /dev/null @@ -1,588 +0,0 @@ -// Copyright IBM Corp. 2021 All Rights Reserved. -// Licensed under the Mozilla Public License v2.0 - -package scc - -import ( - "context" - "fmt" - "log" - "time" - - "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" - "github.com/IBM-Cloud/terraform-provider-ibm/ibm/validate" - "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - - "github.com/IBM/scc-go-sdk/findingsv1" -) - -func DataSourceIBMSccSiOccurrences() *schema.Resource { - return &schema.Resource{ - ReadContext: dataSourceIBMSccSiOccurrencesRead, - - Schema: map[string]*schema.Schema{ - "account_id": { - Type: schema.TypeString, - Optional: true, - }, - "provider_id": { - Type: schema.TypeString, - Required: true, - Description: "Part of the parent. This field contains the provider ID. For example: providers/{provider_id}.", - }, - "page_size": { - Type: schema.TypeInt, - Optional: true, - ValidateFunc: ValidatePageSize, - Description: "Number of notes to return in the list.", - }, - "page_token": { - Type: schema.TypeString, - Optional: true, - Description: "Token to provide to skip to a particular spot in the list.", - }, - "occurrences": { - Type: schema.TypeList, - Computed: true, - Description: "The occurrences requested.", - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "resource_url": { - Type: schema.TypeString, - Computed: true, - Description: "The unique URL of the resource, image or the container, for which the `Occurrence` applies. For example, https://gcr.io/provider/image@sha256:foo. This field can be used as a filter in list requests.", - }, - "note_name": { - Type: schema.TypeString, - Computed: true, - Description: "An analysis note associated with this image, in the form \"{account_id}/providers/{provider_id}/notes/{note_id}\" This field can be used as a filter in list requests.", - }, - "kind": { - Type: schema.TypeString, - Computed: true, - Description: "The type of note. Use this field to filter notes and occurences by kind. - FINDING: The note and occurrence represent a finding. - KPI: The note and occurrence represent a KPI value. - CARD: The note represents a card showing findings and related metric values. - CARD_CONFIGURED: The note represents a card configured for a user account. - SECTION: The note represents a section in a dashboard.", - }, - "remediation": { - Type: schema.TypeString, - Computed: true, - Description: "A description of actions that can be taken to remedy the `Note`.", - }, - "create_time": { - Type: schema.TypeString, - Computed: true, - Description: "Output only. The time this `Occurrence` was created.", - }, - "update_time": { - Type: schema.TypeString, - Computed: true, - Description: "Output only. The time this `Occurrence` was last updated.", - }, - "occurrence_id": { - Type: schema.TypeString, - Computed: true, - Description: "The id of the occurrence.", - }, - "context": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "region": { - Type: schema.TypeString, - Computed: true, - Description: "The IBM Cloud region.", - }, - "resource_crn": { - Type: schema.TypeString, - Computed: true, - Description: "The resource CRN (e.g. certificate CRN, image CRN).", - }, - "resource_id": { - Type: schema.TypeString, - Computed: true, - Description: "The resource ID, in case the CRN is not available.", - }, - "resource_name": { - Type: schema.TypeString, - Computed: true, - Description: "The user-friendly resource name.", - }, - "resource_type": { - Type: schema.TypeString, - Computed: true, - Description: "The resource type name (e.g. Pod, Cluster, Certificate, Image).", - }, - "service_crn": { - Type: schema.TypeString, - Computed: true, - Description: "The service CRN (e.g. CertMgr Instance CRN).", - }, - "service_name": { - Type: schema.TypeString, - Computed: true, - Description: "The service name (e.g. CertMgr).", - }, - "environment_name": { - Type: schema.TypeString, - Computed: true, - Description: "The name of the environment the occurrence applies to.", - }, - "component_name": { - Type: schema.TypeString, - Computed: true, - Description: "The name of the component the occurrence applies to.", - }, - "toolchain_id": { - Type: schema.TypeString, - Computed: true, - Description: "The id of the toolchain the occurrence applies to.", - }, - }, - }, - }, - "finding": { - Type: schema.TypeList, - Computed: true, - Description: "Finding provides details about a finding occurrence.", - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "severity": { - Type: schema.TypeString, - Computed: true, - Description: "Note provider-assigned severity/impact ranking- LOW: Low Impact- MEDIUM: Medium Impact- HIGH: High Impact- CRITICAL: Critical Impact.", - }, - "certainty": { - Type: schema.TypeString, - Computed: true, - Description: "Note provider-assigned confidence on the validity of an occurrence- LOW: Low Certainty- MEDIUM: Medium Certainty- HIGH: High Certainty.", - }, - "next_steps": { - Type: schema.TypeList, - Computed: true, - Description: "Remediation steps for the issues reported in this finding. They override the note's next steps.", - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "title": { - Type: schema.TypeString, - Computed: true, - Description: "Title of this next step.", - }, - "url": { - Type: schema.TypeString, - Computed: true, - Description: "The URL associated to this next steps.", - }, - }, - }, - }, - "network_connection": { - Type: schema.TypeList, - Computed: true, - Description: "It provides details about a network connection.", - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "direction": { - Type: schema.TypeString, - Computed: true, - Description: "The direction of this network connection.", - }, - "protocol": { - Type: schema.TypeString, - Computed: true, - Description: "The protocol of this network connection.", - }, - "client": { - Type: schema.TypeList, - Computed: true, - Description: "It provides details about a socket address.", - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "address": { - Type: schema.TypeString, - Computed: true, - Description: "The IP address of this socket address.", - }, - "port": { - Type: schema.TypeInt, - Computed: true, - Description: "The port number of this socket address.", - }, - }, - }, - }, - "server": { - Type: schema.TypeList, - Computed: true, - Description: "It provides details about a socket address.", - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "address": { - Type: schema.TypeString, - Computed: true, - Description: "The IP address of this socket address.", - }, - "port": { - Type: schema.TypeInt, - Computed: true, - Description: "The port number of this socket address.", - }, - }, - }, - }, - }, - }, - }, - "data_transferred": { - Type: schema.TypeList, - Computed: true, - Description: "It provides details about data transferred between clients and servers.", - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "client_bytes": { - Type: schema.TypeInt, - Computed: true, - Description: "The number of client bytes transferred.", - }, - "server_bytes": { - Type: schema.TypeInt, - Computed: true, - Description: "The number of server bytes transferred.", - }, - "client_packets": { - Type: schema.TypeInt, - Computed: true, - Description: "The number of client packets transferred.", - }, - "server_packets": { - Type: schema.TypeInt, - Computed: true, - Description: "The number of server packets transferred.", - }, - }, - }, - }, - }, - }, - }, - "kpi": { - Type: schema.TypeList, - Computed: true, - Description: "Kpi provides details about a KPI occurrence.", - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "value": { - Type: schema.TypeFloat, - Computed: true, - Description: "The value of this KPI.", - }, - "total": { - Type: schema.TypeFloat, - Computed: true, - Description: "The total value of this KPI.", - }, - }, - }, - }, - }, - }, - }, - "next_page_token": { - Type: schema.TypeString, - Computed: true, - Description: "The next pagination token in the list response. It should be used as`page_token` for the following request. An empty value means no more results.", - }, - }, - } -} - -func DataSourceIBMSccSiOccurrencesValidator() *validate.ResourceValidator { - validateSchema := make([]validate.ValidateSchema, 0) - validateSchema = append(validateSchema, - validate.ValidateSchema{ - Identifier: "page_size", - ValidateFunctionIdentifier: validate.IntBetween, - Required: false, - MinValue: "2"}) - - ibmSccSiOccurrencesDataSourceValidator := validate.ResourceValidator{ResourceName: "ibm_scc_si_occurrences", Schema: validateSchema} - return &ibmSccSiOccurrencesDataSourceValidator -} - -func dataSourceIBMSccSiOccurrencesRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - findingsClient, err := meta.(conns.ClientSession).FindingsV1() - if err != nil { - return diag.FromErr(err) - } - - userDetails, err := meta.(conns.ClientSession).BluemixUserDetails() - if err != nil { - return diag.FromErr(err) - } - - accountID := d.Get("account_id").(string) - log.Println(fmt.Sprintf("[DEBUG] using specified AccountID %s", accountID)) - if accountID == "" { - accountID = userDetails.UserAccount - log.Println(fmt.Sprintf("[DEBUG] AccountID not spedified, using %s", accountID)) - } - findingsClient.AccountID = &accountID - - listOccurrencesOptions := &findingsv1.ListOccurrencesOptions{} - - if pageSize, ok := d.GetOk("page_size"); ok { - listOccurrencesOptions.SetPageSize(int64(pageSize.(int))) - } - if pageToken, ok := d.GetOk("page_token"); ok { - listOccurrencesOptions.SetPageToken(pageToken.(string)) - } - - listOccurrencesOptions.SetProviderID(d.Get("provider_id").(string)) - - apiListOccurrencesResponse, response, err := findingsClient.ListOccurrencesWithContext(context, listOccurrencesOptions) - if err != nil { - log.Printf("[DEBUG] ListOccurrencesWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("ListOccurrencesWithContext failed %s\n%s", err, response)) - } - - d.SetId(dataSourceIBMSccSiOccurrencesID(d)) - - if apiListOccurrencesResponse.Occurrences != nil { - err = d.Set("occurrences", dataSourceAPIListOccurrencesResponseFlattenOccurrences(apiListOccurrencesResponse.Occurrences)) - if err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting occurrences %s", err)) - } - } - if err = d.Set("next_page_token", apiListOccurrencesResponse.NextPageToken); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting next_page_token: %s", err)) - } - - return nil -} - -// dataSourceIBMSccSiOccurrencesID returns a reasonable ID for the list. -func dataSourceIBMSccSiOccurrencesID(d *schema.ResourceData) string { - return time.Now().UTC().String() -} - -func dataSourceAPIListOccurrencesResponseFlattenOccurrences(result []findingsv1.APIOccurrence) (occurrences []map[string]interface{}) { - for _, occurrencesItem := range result { - occurrences = append(occurrences, dataSourceAPIListOccurrencesResponseOccurrencesToMap(occurrencesItem)) - } - - return occurrences -} - -func dataSourceAPIListOccurrencesResponseOccurrencesToMap(occurrencesItem findingsv1.APIOccurrence) (occurrencesMap map[string]interface{}) { - occurrencesMap = map[string]interface{}{} - - if occurrencesItem.ID != nil { - occurrencesMap["occurrence_id"] = occurrencesItem.ID - } - if occurrencesItem.ResourceURL != nil { - occurrencesMap["resource_url"] = occurrencesItem.ResourceURL - } - if occurrencesItem.NoteName != nil { - occurrencesMap["note_name"] = occurrencesItem.NoteName - } - if occurrencesItem.Kind != nil { - occurrencesMap["kind"] = occurrencesItem.Kind - } - if occurrencesItem.Remediation != nil { - occurrencesMap["remediation"] = occurrencesItem.Remediation - } - if occurrencesItem.CreateTime != nil { - occurrencesMap["create_time"] = occurrencesItem.CreateTime.String() - } - if occurrencesItem.UpdateTime != nil { - occurrencesMap["update_time"] = occurrencesItem.UpdateTime.String() - } - if occurrencesItem.ID != nil { - occurrencesMap["occurrence_id"] = occurrencesItem.ID - } - if occurrencesItem.Context != nil { - contextList := []map[string]interface{}{} - contextMap := dataSourceAPIListOccurrencesResponseOccurrencesContextToMap(*occurrencesItem.Context) - contextList = append(contextList, contextMap) - occurrencesMap["context"] = contextList - } - if occurrencesItem.Finding != nil { - findingList := []map[string]interface{}{} - findingMap := dataSourceAPIListOccurrencesResponseOccurrencesFindingToMap(*occurrencesItem.Finding) - findingList = append(findingList, findingMap) - occurrencesMap["finding"] = findingList - } - if occurrencesItem.Kpi != nil { - kpiList := []map[string]interface{}{} - kpiMap := dataSourceAPIListOccurrencesResponseOccurrencesKpiToMap(*occurrencesItem.Kpi) - kpiList = append(kpiList, kpiMap) - occurrencesMap["kpi"] = kpiList - } - - return occurrencesMap -} - -func dataSourceAPIListOccurrencesResponseOccurrencesContextToMap(contextItem findingsv1.Context) (contextMap map[string]interface{}) { - contextMap = map[string]interface{}{} - - if contextItem.Region != nil { - contextMap["region"] = contextItem.Region - } - if contextItem.ResourceCRN != nil { - contextMap["resource_crn"] = contextItem.ResourceCRN - } - if contextItem.ResourceID != nil { - contextMap["resource_id"] = contextItem.ResourceID - } - if contextItem.ResourceName != nil { - contextMap["resource_name"] = contextItem.ResourceName - } - if contextItem.ResourceType != nil { - contextMap["resource_type"] = contextItem.ResourceType - } - if contextItem.ServiceCRN != nil { - contextMap["service_crn"] = contextItem.ServiceCRN - } - if contextItem.ServiceName != nil { - contextMap["service_name"] = contextItem.ServiceName - } - if contextItem.EnvironmentName != nil { - contextMap["environment_name"] = contextItem.EnvironmentName - } - if contextItem.ComponentName != nil { - contextMap["component_name"] = contextItem.ComponentName - } - if contextItem.ToolchainID != nil { - contextMap["toolchain_id"] = contextItem.ToolchainID - } - - return contextMap -} - -func dataSourceAPIListOccurrencesResponseOccurrencesFindingToMap(findingItem findingsv1.Finding) (findingMap map[string]interface{}) { - findingMap = map[string]interface{}{} - - if findingItem.Severity != nil { - findingMap["severity"] = findingItem.Severity - } - if findingItem.Certainty != nil { - findingMap["certainty"] = findingItem.Certainty - } - if findingItem.NextSteps != nil { - nextStepsList := []map[string]interface{}{} - for _, nextStepsItem := range findingItem.NextSteps { - nextStepsList = append(nextStepsList, dataSourceAPIListOccurrencesResponseFindingNextStepsToMap(nextStepsItem)) - } - findingMap["next_steps"] = nextStepsList - } - if findingItem.NetworkConnection != nil { - networkConnectionList := []map[string]interface{}{} - networkConnectionMap := dataSourceAPIListOccurrencesResponseFindingNetworkConnectionToMap(*findingItem.NetworkConnection) - networkConnectionList = append(networkConnectionList, networkConnectionMap) - findingMap["network_connection"] = networkConnectionList - } - if findingItem.DataTransferred != nil { - dataTransferredList := []map[string]interface{}{} - dataTransferredMap := dataSourceAPIListOccurrencesResponseFindingDataTransferredToMap(*findingItem.DataTransferred) - dataTransferredList = append(dataTransferredList, dataTransferredMap) - findingMap["data_transferred"] = dataTransferredList - } - - return findingMap -} - -func dataSourceAPIListOccurrencesResponseFindingNextStepsToMap(nextStepsItem findingsv1.RemediationStep) (nextStepsMap map[string]interface{}) { - nextStepsMap = map[string]interface{}{} - - if nextStepsItem.Title != nil { - nextStepsMap["title"] = nextStepsItem.Title - } - if nextStepsItem.URL != nil { - nextStepsMap["url"] = nextStepsItem.URL - } - - return nextStepsMap -} - -func dataSourceAPIListOccurrencesResponseFindingNetworkConnectionToMap(networkConnectionItem findingsv1.NetworkConnection) (networkConnectionMap map[string]interface{}) { - networkConnectionMap = map[string]interface{}{} - - if networkConnectionItem.Direction != nil { - networkConnectionMap["direction"] = networkConnectionItem.Direction - } - if networkConnectionItem.Protocol != nil { - networkConnectionMap["protocol"] = networkConnectionItem.Protocol - } - if networkConnectionItem.Client != nil { - clientList := []map[string]interface{}{} - clientMap := dataSourceAPIListOccurrencesResponseNetworkConnectionClientToMap(*networkConnectionItem.Client) - clientList = append(clientList, clientMap) - networkConnectionMap["client"] = clientList - } - if networkConnectionItem.Server != nil { - serverList := []map[string]interface{}{} - serverMap := dataSourceAPIListOccurrencesResponseNetworkConnectionServerToMap(*networkConnectionItem.Server) - serverList = append(serverList, serverMap) - networkConnectionMap["server"] = serverList - } - - return networkConnectionMap -} - -func dataSourceAPIListOccurrencesResponseNetworkConnectionClientToMap(clientItem findingsv1.SocketAddress) (clientMap map[string]interface{}) { - clientMap = map[string]interface{}{} - - if clientItem.Address != nil { - clientMap["address"] = clientItem.Address - } - if clientItem.Port != nil { - clientMap["port"] = clientItem.Port - } - - return clientMap -} - -func dataSourceAPIListOccurrencesResponseNetworkConnectionServerToMap(serverItem findingsv1.SocketAddress) (serverMap map[string]interface{}) { - serverMap = map[string]interface{}{} - - if serverItem.Address != nil { - serverMap["address"] = serverItem.Address - } - if serverItem.Port != nil { - serverMap["port"] = serverItem.Port - } - - return serverMap -} - -func dataSourceAPIListOccurrencesResponseFindingDataTransferredToMap(dataTransferredItem findingsv1.DataTransferred) (dataTransferredMap map[string]interface{}) { - dataTransferredMap = map[string]interface{}{} - - if dataTransferredItem.ClientBytes != nil { - dataTransferredMap["client_bytes"] = dataTransferredItem.ClientBytes - } - if dataTransferredItem.ServerBytes != nil { - dataTransferredMap["server_bytes"] = dataTransferredItem.ServerBytes - } - if dataTransferredItem.ClientPackets != nil { - dataTransferredMap["client_packets"] = dataTransferredItem.ClientPackets - } - if dataTransferredItem.ServerPackets != nil { - dataTransferredMap["server_packets"] = dataTransferredItem.ServerPackets - } - - return dataTransferredMap -} - -func dataSourceAPIListOccurrencesResponseOccurrencesKpiToMap(kpiItem findingsv1.Kpi) (kpiMap map[string]interface{}) { - kpiMap = map[string]interface{}{} - - if kpiItem.Value != nil { - kpiMap["value"] = kpiItem.Value - } - if kpiItem.Total != nil { - kpiMap["total"] = kpiItem.Total - } - - return kpiMap -} diff --git a/ibm/service/scc/data_source_ibm_scc_si_occurrences_test.go b/ibm/service/scc/data_source_ibm_scc_si_occurrences_test.go deleted file mode 100644 index 5392cff369..0000000000 --- a/ibm/service/scc/data_source_ibm_scc_si_occurrences_test.go +++ /dev/null @@ -1,209 +0,0 @@ -// Copyright IBM Corp. 2021 All Rights Reserved. -// Licensed under the Mozilla Public License v2.0 - -package scc_test - -import ( - "fmt" - "testing" - - acc "github.com/IBM-Cloud/terraform-provider-ibm/ibm/acctest" - - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" -) - -func TestAccIBMSccSiOccurrencesDataSourceBasic(t *testing.T) { - apiOccurrenceProviderID := fmt.Sprintf("tf_provider_id_%d", acctest.RandIntRange(10, 100)) - apiOccurrenceNoteID := fmt.Sprintf("tf_note_name_%d", acctest.RandIntRange(10, 100)) - apiOccurrenceKind := "FINDING" - apiOccurrenceID := fmt.Sprintf("tf_occurrence_id_%d", acctest.RandIntRange(10, 100)) - - resource.Test(t, resource.TestCase{ - PreCheck: func() { acc.TestAccPreCheck(t) }, - Providers: acc.TestAccProviders, - Steps: []resource.TestStep{ - { - Config: testAccCheckIBMSccSiOccurrencesDataSourceConfigBasic(acc.Scc_si_account, apiOccurrenceProviderID, apiOccurrenceNoteID, apiOccurrenceKind, apiOccurrenceID), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet("data.ibm_scc_si_occurrences.scc_si_occurrences", "id"), - resource.TestCheckResourceAttrSet("data.ibm_scc_si_occurrences.scc_si_occurrences", "provider_id"), - ), - }, - }, - }) -} - -func TestAccIBMSccSiOccurrencesDataSourceAllArgs(t *testing.T) { - apiOccurrenceProviderID := fmt.Sprintf("tf_provider_id_%d", acctest.RandIntRange(10, 100)) - apiOccurrenceNoteID := fmt.Sprintf("tf_note_name_%d", acctest.RandIntRange(10, 100)) - apiOccurrenceKind := "FINDING" - apiOccurrenceID := fmt.Sprintf("tf_occurrence_id_%d", acctest.RandIntRange(10, 100)) - apiOccurrenceResourceURL := fmt.Sprintf("tf_resource_url_%d", acctest.RandIntRange(10, 100)) - apiOccurrenceRemediation := fmt.Sprintf("tf_remediation_%d", acctest.RandIntRange(10, 100)) - apiOccurrenceReplaceIfExists := "false" - apiNoteID := fmt.Sprintf("%s/providers/%s/notes/%s", acc.Scc_si_account, apiOccurrenceProviderID, apiOccurrenceNoteID) - - resource.Test(t, resource.TestCase{ - PreCheck: func() { acc.TestAccPreCheck(t) }, - Providers: acc.TestAccProviders, - Steps: []resource.TestStep{ - { - Config: testAccCheckIBMSccSiOccurrencesDataSourceConfig(acc.Scc_si_account, apiOccurrenceProviderID, apiOccurrenceNoteID, apiOccurrenceKind, apiOccurrenceID, apiOccurrenceResourceURL, apiOccurrenceRemediation, apiOccurrenceReplaceIfExists), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet("data.ibm_scc_si_occurrences.scc_si_occurrences", "id"), - resource.TestCheckResourceAttrSet("data.ibm_scc_si_occurrences.scc_si_occurrences", "provider_id"), - resource.TestCheckResourceAttrSet("data.ibm_scc_si_occurrences.scc_si_occurrences", "occurrences.#"), - resource.TestCheckResourceAttr("data.ibm_scc_si_occurrences.scc_si_occurrences", "occurrences.0.resource_url", apiOccurrenceResourceURL), - resource.TestCheckResourceAttr("data.ibm_scc_si_occurrences.scc_si_occurrences", "occurrences.0.note_name", apiNoteID), - resource.TestCheckResourceAttr("data.ibm_scc_si_occurrences.scc_si_occurrences", "occurrences.0.kind", apiOccurrenceKind), - resource.TestCheckResourceAttr("data.ibm_scc_si_occurrences.scc_si_occurrences", "occurrences.0.remediation", apiOccurrenceRemediation), - resource.TestCheckResourceAttrSet("data.ibm_scc_si_occurrences.scc_si_occurrences", "occurrences.0.create_time"), - resource.TestCheckResourceAttrSet("data.ibm_scc_si_occurrences.scc_si_occurrences", "occurrences.0.update_time"), - resource.TestCheckResourceAttr("data.ibm_scc_si_occurrences.scc_si_occurrences", "occurrences.0.occurrence_id", apiOccurrenceID), - resource.TestCheckResourceAttrSet("data.ibm_scc_si_occurrences.scc_si_occurrences", "next_page_token"), - ), - }, - }, - }) -} - -func testAccCheckIBMSccSiOccurrencesDataSourceConfigBasic(accountID string, apiOccurrenceProviderID string, apiOccurrenceNoteID string, apiOccurrenceKind string, apiOccurrenceID string) string { - return fmt.Sprintf(` - - resource "ibm_scc_si_note" "finding" { - account_id = "%s" - provider_id = "%s" - short_description = "Security Threat" - long_description = "Security Threat found in your account" - kind = "FINDING" - note_id = "%s" - reported_by { - id = "scc-si-terraform" - title = "SCC SI Terraform" - url = "https://cloud.ibm.com" - } - finding { - severity = "LOW" - next_steps { - title = "Security Threat" - url = "https://cloud.ibm.com/security-compliance/findings" - } - } - } - resource "ibm_scc_si_occurrence" "scc_si_occurrence" { - provider_id = "${ibm_scc_si_note.finding.provider_id}" - note_name = "%s/providers/${ibm_scc_si_note.finding.provider_id}/notes/${ibm_scc_si_note.finding.note_id}" - kind = "%s" - occurrence_id = "%s" - finding { - severity = "LOW" - certainty = "LOW" - next_steps { - title = "title" - url = "url" - } - network_connection { - direction = "direction" - protocol = "protocol" - client { - address = "address" - port = 1 - } - server { - address = "address" - port = 1 - } - } - data_transferred { - client_bytes = 1 - server_bytes = 1 - client_packets = 1 - server_packets = 1 - } - } - } - - data "ibm_scc_si_occurrences" "scc_si_occurrences" { - provider_id = ibm_scc_si_occurrence.scc_si_occurrence.provider_id - } - `, accountID, apiOccurrenceProviderID, apiOccurrenceNoteID, accountID, apiOccurrenceKind, apiOccurrenceID) -} - -func testAccCheckIBMSccSiOccurrencesDataSourceConfig(accountID string, apiOccurrenceProviderID string, apiOccurrenceNoteID string, apiOccurrenceKind string, apiOccurrenceID string, apiOccurrenceResourceURL string, apiOccurrenceRemediation string, apiOccurrenceReplaceIfExists string) string { - return fmt.Sprintf(` - - resource "ibm_scc_si_note" "finding" { - account_id = "%s" - provider_id = "%s" - short_description = "Security Threat" - long_description = "Security Threat found in your account" - kind = "FINDING" - note_id = "%s" - reported_by { - id = "scc-si-terraform" - title = "SCC SI Terraform" - url = "https://cloud.ibm.com" - } - finding { - severity = "LOW" - next_steps { - title = "Security Threat" - url = "https://cloud.ibm.com/security-compliance/findings" - } - } - } - - resource "ibm_scc_si_occurrence" "scc_si_occurrence" { - provider_id = "${ibm_scc_si_note.finding.provider_id}" - note_name = "%s/providers/${ibm_scc_si_note.finding.provider_id}/notes/${ibm_scc_si_note.finding.note_id}" - kind = "%s" - occurrence_id = "%s" - resource_url = "%s" - remediation = "%s" - context { - region = "region" - resource_crn = "resource_crn" - resource_id = "resource_id" - resource_name = "resource_name" - resource_type = "resource_type" - service_crn = "service_crn" - service_name = "service_name" - environment_name = "environment_name" - component_name = "component_name" - toolchain_id = "toolchain_id" - } - finding { - severity = "LOW" - certainty = "LOW" - next_steps { - title = "title" - url = "url" - } - network_connection { - direction = "direction" - protocol = "protocol" - client { - address = "address" - port = 1 - } - server { - address = "address" - port = 1 - } - } - data_transferred { - client_bytes = 1 - server_bytes = 1 - client_packets = 1 - server_packets = 1 - } - } - replace_if_exists = %s - } - - data "ibm_scc_si_occurrences" "scc_si_occurrences" { - provider_id = ibm_scc_si_occurrence.scc_si_occurrence.provider_id - } - `, accountID, apiOccurrenceProviderID, apiOccurrenceNoteID, accountID, apiOccurrenceKind, apiOccurrenceID, apiOccurrenceResourceURL, apiOccurrenceRemediation, apiOccurrenceReplaceIfExists) -} diff --git a/ibm/service/scc/data_source_ibm_scc_si_providers.go b/ibm/service/scc/data_source_ibm_scc_si_providers.go deleted file mode 100644 index 23dc8781b0..0000000000 --- a/ibm/service/scc/data_source_ibm_scc_si_providers.go +++ /dev/null @@ -1,175 +0,0 @@ -// Copyright IBM Corp. 2021 All Rights Reserved. -// Licensed under the Mozilla Public License v2.0 - -package scc - -import ( - "context" - "fmt" - "log" - "time" - - "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" - "github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex" - "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - - "github.com/IBM/go-sdk-core/v5/core" - "github.com/IBM/scc-go-sdk/findingsv1" -) - -func DataSourceIBMSccSiProviders() *schema.Resource { - return &schema.Resource{ - ReadContext: dataSourceIBMSccSiProvidersRead, - - Schema: map[string]*schema.Schema{ - "account_id": { - Type: schema.TypeString, - Optional: true, - }, - "providers": { - Type: schema.TypeList, - Computed: true, - Description: "The providers requested.", - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "name": { - Type: schema.TypeString, - Computed: true, - Description: "The name of the provider in the form '{account_id}/providers/{provider_id}'.", - }, - "id": { - Type: schema.TypeString, - Computed: true, - Description: "The ID of the provider.", - }, - }, - }, - }, - "limit": { - Type: schema.TypeInt, - Optional: true, - ValidateFunc: ValidatePageSize, - Description: "The number of elements returned in the current instance. The default is 200.", - }, - "skip": { - Type: schema.TypeInt, - Optional: true, - Description: "The offset is the index of the item from which you want to start returning data from. The default is 0.", - }, - "total_count": { - Type: schema.TypeInt, - Computed: true, - Description: "The total number of providers available.", - }, - }, - } -} - -func dataSourceIBMSccSiProvidersRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - findingsClient, err := meta.(conns.ClientSession).FindingsV1() - if err != nil { - return diag.FromErr(err) - } - - userDetails, err := meta.(conns.ClientSession).BluemixUserDetails() - if err != nil { - return diag.FromErr(err) - } - - accountID := d.Get("account_id").(string) - log.Println(fmt.Sprintf("[DEBUG] using specified AccountID %s", accountID)) - if accountID == "" { - accountID = userDetails.UserAccount - log.Println(fmt.Sprintf("[DEBUG] AccountID not spedified, using %s", accountID)) - } - findingsClient.AccountID = &accountID - - listProvidersOptions := &findingsv1.ListProvidersOptions{} - - if skip, ok := d.GetOk("skip"); ok { - listProvidersOptions.SetSkip(int64(skip.(int))) - } - if limit, ok := d.GetOk("limit"); ok { - listProvidersOptions.SetLimit(int64(limit.(int))) - } - - apiProviders, totalCount, err := collectAllProviders(findingsClient, context, listProvidersOptions) - if err != nil { - log.Printf("[DEBUG] ListProvidersWithContext failed %s", err) - return diag.FromErr(fmt.Errorf("ListProvidersWithContext failed %s", err)) - } - - d.SetId(dataSourceIBMSccSiProvidersID(d)) - - if apiProviders != nil { - err = d.Set("providers", dataSourceAPIListProvidersResponseFlattenProviders(apiProviders)) - if err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting providers %s", err)) - } - } - if err = d.Set("total_count", flex.IntValue(totalCount)); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting total_count: %s", err)) - } - - return nil -} - -// dataSourceIBMSccSiProviderID returns a reasonable ID for the list. -func dataSourceIBMSccSiProvidersID(d *schema.ResourceData) string { - return time.Now().UTC().String() -} - -func collectAllProviders(findingsClient *findingsv1.FindingsV1, ctx context.Context, options *findingsv1.ListProvidersOptions) ([]findingsv1.APIProvider, *int64, error) { - finalList := []findingsv1.APIProvider{} - totalCount := core.Int64Ptr(0) - - for { - apiListProvidersResponse, response, err := findingsClient.ListProvidersWithContext(ctx, options) - if err != nil { - return nil, core.Int64Ptr(0), fmt.Errorf("%s\n%s", err, response) - } - - totalCount = apiListProvidersResponse.TotalCount - - finalList = append(finalList, apiListProvidersResponse.Providers...) - - // if user has specified some limit, then stop once finalList has length equal to the limit specified - if options.Limit != nil && int64(len(finalList)) == *options.Limit { - break - } - - // if skip is specified, then stop once the finalList has length equal to difference of totalCount and skip - if options.Skip != nil && int64(len(finalList)) == *apiListProvidersResponse.TotalCount-*options.Skip { - break - } - - // if user has not specified the limit, then stop once the finalList has length equal to totalCount - if options.Limit == nil && int64(len(finalList)) == *apiListProvidersResponse.TotalCount { - break - } - } - - return finalList, totalCount, nil -} - -func dataSourceAPIListProvidersResponseFlattenProviders(result []findingsv1.APIProvider) (providers []map[string]interface{}) { - for _, providersItem := range result { - providers = append(providers, dataSourceAPIListProvidersResponseProvidersToMap(providersItem)) - } - - return providers -} - -func dataSourceAPIListProvidersResponseProvidersToMap(providersItem findingsv1.APIProvider) (providersMap map[string]interface{}) { - providersMap = map[string]interface{}{} - - if providersItem.Name != nil { - providersMap["name"] = providersItem.Name - } - if providersItem.ID != nil { - providersMap["id"] = providersItem.ID - } - - return providersMap -} diff --git a/ibm/service/scc/data_source_ibm_scc_si_providers_test.go b/ibm/service/scc/data_source_ibm_scc_si_providers_test.go deleted file mode 100644 index 987d60ccdc..0000000000 --- a/ibm/service/scc/data_source_ibm_scc_si_providers_test.go +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright IBM Corp. 2021 All Rights Reserved. -// Licensed under the Mozilla Public License v2.0 - -package scc_test - -import ( - "fmt" - "testing" - - acc "github.com/IBM-Cloud/terraform-provider-ibm/ibm/acctest" - - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" -) - -func TestAccIBMSccSiProvidersDataSourceBasic(t *testing.T) { - resource.Test(t, resource.TestCase{ - PreCheck: func() { acc.TestAccPreCheck(t) }, - Providers: acc.TestAccProviders, - Steps: []resource.TestStep{ - { - Config: testAccCheckIBMSccSiProvidersDataSourceConfigBasic(acc.Scc_si_account), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet("data.ibm_scc_si_providers.scc_si_providers", "id"), - resource.TestCheckResourceAttrSet("data.ibm_scc_si_providers.scc_si_providers", "providers.#"), - ), - }, - }, - }) -} - -func testAccCheckIBMSccSiProvidersDataSourceConfigBasic(accountID string) string { - return fmt.Sprintf(` - data "ibm_scc_si_providers" "scc_si_providers" { - account_id = "%s" - } - `, accountID) -} diff --git a/ibm/service/scc/resource_ibm_scc_si_note.go b/ibm/service/scc/resource_ibm_scc_si_note.go deleted file mode 100644 index 27846901c0..0000000000 --- a/ibm/service/scc/resource_ibm_scc_si_note.go +++ /dev/null @@ -1,1178 +0,0 @@ -// Copyright IBM Corp. 2021 All Rights Reserved. -// Licensed under the Mozilla Public License v2.0 - -package scc - -import ( - "context" - "fmt" - "log" - - "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" - "github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex" - "github.com/IBM-Cloud/terraform-provider-ibm/ibm/validate" - "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - - "github.com/IBM/go-sdk-core/v5/core" - "github.com/IBM/scc-go-sdk/findingsv1" -) - -func ResourceIBMSccSiNote() *schema.Resource { - return &schema.Resource{ - CreateContext: resourceIBMSccSiNoteCreate, - ReadContext: resourceIBMSccSiNoteRead, - UpdateContext: resourceIBMSccSiNoteUpdate, - DeleteContext: resourceIBMSccSiNoteDelete, - Importer: &schema.ResourceImporter{}, - - Schema: map[string]*schema.Schema{ - "account_id": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, - Computed: true, - }, - "provider_id": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - Description: "Part of the parent. This field contains the provider ID. For example: providers/{provider_id}.", - }, - "short_description": { - Type: schema.TypeString, - Required: true, - Description: "A one sentence description of your note.", - }, - "long_description": { - Type: schema.TypeString, - Required: true, - Description: "A more detailed description of your note.", - }, - "kind": { - Type: schema.TypeString, - Required: true, - ValidateFunc: validate.InvokeValidator("ibm_scc_si_note", "kind"), - Description: "The type of note. Use this field to filter notes and occurences by kind. - FINDING: The note and occurrence represent a finding. - KPI: The note and occurrence represent a KPI value. - CARD: The note represents a card showing findings and related metric values. - CARD_CONFIGURED: The note represents a card configured for a user account. - SECTION: The note represents a section in a dashboard.", - }, - "note_id": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - Description: "The ID of the note.", - }, - "reported_by": { - Type: schema.TypeList, - MinItems: 1, - MaxItems: 1, - Required: true, - Description: "The entity reporting a note.", - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "id": { - Type: schema.TypeString, - Required: true, - Description: "The id of this reporter.", - }, - "title": { - Type: schema.TypeString, - Required: true, - Description: "The title of this reporter.", - }, - "url": { - Type: schema.TypeString, - Optional: true, - Description: "The url of this reporter.", - }, - }, - }, - }, - "related_url": { - Type: schema.TypeList, - Optional: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "label": { - Type: schema.TypeString, - Required: true, - Description: "Label to describe usage of the URL.", - }, - "url": { - Type: schema.TypeString, - Required: true, - Description: "The URL that you want to associate with the note.", - }, - }, - }, - }, - "shared": { - Type: schema.TypeBool, - Optional: true, - Default: true, - Description: "True if this note can be shared by multiple accounts.", - }, - "finding": { - Type: schema.TypeList, - MaxItems: 1, - Optional: true, - Description: "FindingType provides details about a finding note.", - ExactlyOneOf: []string{"finding", "kpi", "card", "section"}, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "severity": { - Type: schema.TypeString, - Required: true, - Description: "Note provider-assigned severity/impact ranking- LOW: Low Impact- MEDIUM: Medium Impact- HIGH: High Impact- CRITICAL: Critical Impact.", - }, - "next_steps": { - Type: schema.TypeList, - Optional: true, - Description: "Common remediation steps for the finding of this type.", - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "title": { - Type: schema.TypeString, - Optional: true, - Description: "Title of this next step.", - }, - "url": { - Type: schema.TypeString, - Optional: true, - Description: "The URL associated to this next steps.", - }, - }, - }, - }, - }, - }, - }, - "kpi": { - Type: schema.TypeList, - MaxItems: 1, - Optional: true, - Description: "KpiType provides details about a KPI note.", - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "aggregation_type": { - Type: schema.TypeString, - Required: true, - Description: "The aggregation type of the KPI values. - SUM: A single-value metrics aggregation type that sums up numeric values that are extracted from KPI occurrences.", - }, - }, - }, - }, - "card": { - Type: schema.TypeList, - MaxItems: 1, - Optional: true, - Description: "Card provides details about a card kind of note.", - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "section": { - Type: schema.TypeString, - Required: true, - Description: "The section this card belongs to.", - }, - "title": { - Type: schema.TypeString, - Required: true, - Description: "The title of this card.", - }, - "subtitle": { - Type: schema.TypeString, - Required: true, - Description: "The subtitle of this card.", - }, - "order": { - Type: schema.TypeInt, - Optional: true, - ValidateFunc: validate.InvokeValidator("ibm_scc_si_note", "order"), - Description: "The order of the card in which it will appear on SA dashboard in the mentioned section.", - }, - "finding_note_names": { - Type: schema.TypeList, - Required: true, - Description: "The finding note names associated to this card.", - Elem: &schema.Schema{Type: schema.TypeString}, - }, - "requires_configuration": { - Type: schema.TypeBool, - Optional: true, - Default: false, - }, - "badge_text": { - Type: schema.TypeString, - Optional: true, - Description: "The text associated to the card's badge.", - }, - "badge_image": { - Type: schema.TypeString, - Optional: true, - Description: "The base64 content of the image associated to the card's badge.", - }, - "elements": { - Type: schema.TypeList, - Required: true, - Description: "The elements of this card.", - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "text": { - Type: schema.TypeString, - Optional: true, - Description: "The text of this card element.", - }, - "kind": { - Type: schema.TypeString, - Optional: true, - Default: "NUMERIC", - Description: "Kind of element- NUMERIC: Single numeric value- BREAKDOWN: Breakdown of numeric values- TIME_SERIES: Time-series of numeric values.", - }, - "default_time_range": { - Type: schema.TypeString, - Optional: true, - Default: "4d", - Description: "The default time range of this card element.", - }, - "value_type": { - Type: schema.TypeList, - MaxItems: 1, - Optional: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "kind": { - Type: schema.TypeString, - Optional: true, - Description: "Kind of element- KPI: Kind of value derived from a KPI occurrence.", - }, - "kpi_note_name": { - Type: schema.TypeString, - Optional: true, - Description: "The name of the kpi note associated to the occurrence with the value for this card element value type.", - }, - "text": { - Type: schema.TypeString, - Optional: true, - Default: "label", - Description: "The text of this element type.", - }, - "finding_note_names": { - Type: schema.TypeList, - Optional: true, - Description: "the names of the finding note associated that act as filters for counting the occurrences.", - Elem: &schema.Schema{Type: schema.TypeString}, - }, - }, - }, - }, - "value_types": { - Type: schema.TypeList, - Optional: true, - Description: "the value types associated to this card element.", - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "kind": { - Type: schema.TypeString, - Optional: true, - Description: "Kind of element- KPI: Kind of value derived from a KPI occurrence.", - }, - "kpi_note_name": { - Type: schema.TypeString, - Optional: true, - Description: "The name of the kpi note associated to the occurrence with the value for this card element value type.", - }, - "text": { - Type: schema.TypeString, - Optional: true, - Default: "label", - Description: "The text of this element type.", - }, - "finding_note_names": { - Type: schema.TypeList, - Optional: true, - Description: "the names of the finding note associated that act as filters for counting the occurrences.", - Elem: &schema.Schema{Type: schema.TypeString}, - }, - }, - }, - }, - "default_interval": { - Type: schema.TypeString, - Optional: true, - Default: "d", - Description: "The default interval of the time series.", - }, - }, - }, - }, - }, - }, - }, - "section": { - Type: schema.TypeList, - MaxItems: 1, - Optional: true, - Description: "Card provides details about a card kind of note.", - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "title": { - Type: schema.TypeString, - Required: true, - Description: "The title of this section.", - }, - "image": { - Type: schema.TypeString, - Required: true, - Description: "The image of this section.", - }, - }, - }, - }, - "create_time": { - Type: schema.TypeString, - Computed: true, - Description: "Output only. The time this note was created. This field can be used as a filter in list requests.", - }, - "update_time": { - Type: schema.TypeString, - Computed: true, - Description: "Output only. The time this note was last updated. This field can be used as a filter in list requests.", - }, - }, - } -} - -func ResourceIBMSccSiNoteValidator() *validate.ResourceValidator { - validateSchema := make([]validate.ValidateSchema, 2) - validateSchema = append(validateSchema, - validate.ValidateSchema{ - Identifier: "kind", - ValidateFunctionIdentifier: validate.ValidateAllowedStringValue, - Type: validate.TypeString, - Required: true, - AllowedValues: "CARD, CARD_CONFIGURED, FINDING, KPI, SECTION", - }, - validate.ValidateSchema{ - Identifier: "order", - ValidateFunctionIdentifier: validate.IntBetween, - Type: validate.TypeInt, - Required: false, - MinValue: "1", - MaxValue: "6"}, - ) - - resourceValidator := validate.ResourceValidator{ResourceName: "ibm_scc_si_note", Schema: validateSchema} - return &resourceValidator -} - -func resourceIBMSccSiNoteCreate(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - findingsClient, err := meta.(conns.ClientSession).FindingsV1() - if err != nil { - return diag.FromErr(err) - } - - userDetails, err := meta.(conns.ClientSession).BluemixUserDetails() - if err != nil { - return diag.FromErr(err) - } - - accountID := d.Get("account_id").(string) - log.Println(fmt.Sprintf("[DEBUG] using specified AccountID %s", accountID)) - if accountID == "" { - accountID = userDetails.UserAccount - log.Println(fmt.Sprintf("[DEBUG] AccountID not spedified, using %s", accountID)) - } - findingsClient.AccountID = &accountID - - createNoteOptions := &findingsv1.CreateNoteOptions{} - - createNoteOptions.SetProviderID(d.Get("provider_id").(string)) - createNoteOptions.SetShortDescription(d.Get("short_description").(string)) - createNoteOptions.SetLongDescription(d.Get("long_description").(string)) - createNoteOptions.SetKind(d.Get("kind").(string)) - createNoteOptions.SetID(d.Get("note_id").(string)) - reportedBy := resourceIBMSccSiNoteMapToReporter(d.Get("reported_by.0").(map[string]interface{})) - createNoteOptions.SetReportedBy(&reportedBy) - if _, ok := d.GetOk("related_url"); ok { - var relatedURL []findingsv1.APINoteRelatedURL - for _, e := range d.Get("related_url").([]interface{}) { - value := e.(map[string]interface{}) - relatedURLItem := resourceIBMSccSiNoteMapToAPINoteRelatedURL(value) - relatedURL = append(relatedURL, relatedURLItem) - } - createNoteOptions.SetRelatedURL(relatedURL) - } - if _, ok := d.GetOk("shared"); ok { - createNoteOptions.SetShared(d.Get("shared").(bool)) - } - if _, ok := d.GetOk("finding"); ok { - finding := resourceIBMSccSiNoteMapToFindingType(d.Get("finding.0").(map[string]interface{})) - createNoteOptions.SetFinding(&finding) - } - if _, ok := d.GetOk("kpi"); ok { - kpi := resourceIBMSccSiNoteMapToKpiType(d.Get("kpi.0").(map[string]interface{})) - createNoteOptions.SetKpi(&kpi) - } - if _, ok := d.GetOk("card"); ok { - card := resourceIBMSccSiNoteMapToCard(d.Get("card.0").(map[string]interface{})) - createNoteOptions.SetCard(&card) - } - if _, ok := d.GetOk("section"); ok { - section := resourceIBMSccSiNoteMapToSection(d.Get("section.0").(map[string]interface{})) - createNoteOptions.SetSection(§ion) - } - - apiNote, response, err := findingsClient.CreateNoteWithContext(context, createNoteOptions) - if err != nil { - log.Printf("[DEBUG] CreateNoteWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("CreateNoteWithContext failed %s\n%s", err, response)) - } - - d.SetId(fmt.Sprintf("%s/%s/%s", *findingsClient.AccountID, *createNoteOptions.ProviderID, *apiNote.ID)) - - return resourceIBMSccSiNoteRead(context, d, meta) -} - -func resourceIBMSccSiNoteMapToReporter(reporterMap map[string]interface{}) findingsv1.Reporter { - reporter := findingsv1.Reporter{} - - reporter.ID = core.StringPtr(reporterMap["id"].(string)) - reporter.Title = core.StringPtr(reporterMap["title"].(string)) - if reporterMap["url"] != nil { - reporter.URL = core.StringPtr(reporterMap["url"].(string)) - } - - return reporter -} - -func resourceIBMSccSiNoteMapToAPINoteRelatedURL(apiNoteRelatedURLMap map[string]interface{}) findingsv1.APINoteRelatedURL { - apiNoteRelatedURL := findingsv1.APINoteRelatedURL{} - - apiNoteRelatedURL.Label = core.StringPtr(apiNoteRelatedURLMap["label"].(string)) - apiNoteRelatedURL.URL = core.StringPtr(apiNoteRelatedURLMap["url"].(string)) - - return apiNoteRelatedURL -} - -func resourceIBMSccSiNoteMapToFindingType(findingTypeMap map[string]interface{}) findingsv1.FindingType { - findingType := findingsv1.FindingType{} - - findingType.Severity = core.StringPtr(findingTypeMap["severity"].(string)) - if findingTypeMap["next_steps"] != nil { - nextSteps := []findingsv1.RemediationStep{} - for _, nextStepsItem := range findingTypeMap["next_steps"].([]interface{}) { - nextStepsItemModel := resourceIBMSccSiNoteMapToRemediationStep(nextStepsItem.(map[string]interface{})) - nextSteps = append(nextSteps, nextStepsItemModel) - } - findingType.NextSteps = nextSteps - } - - return findingType -} - -func resourceIBMSccSiNoteMapToRemediationStep(remediationStepMap map[string]interface{}) findingsv1.RemediationStep { - remediationStep := findingsv1.RemediationStep{} - - if remediationStepMap["title"] != nil { - remediationStep.Title = core.StringPtr(remediationStepMap["title"].(string)) - } - if remediationStepMap["url"] != nil { - remediationStep.URL = core.StringPtr(remediationStepMap["url"].(string)) - } - - return remediationStep -} - -func resourceIBMSccSiNoteMapToKpiType(kpiTypeMap map[string]interface{}) findingsv1.KpiType { - kpiType := findingsv1.KpiType{} - - kpiType.AggregationType = core.StringPtr(kpiTypeMap["aggregation_type"].(string)) - - return kpiType -} - -func resourceIBMSccSiNoteMapToCard(cardMap map[string]interface{}) findingsv1.Card { - card := findingsv1.Card{} - - card.Section = core.StringPtr(cardMap["section"].(string)) - card.Title = core.StringPtr(cardMap["title"].(string)) - card.Subtitle = core.StringPtr(cardMap["subtitle"].(string)) - if cardMap["order"] != nil && cardMap["order"].(int) > 0 { - card.Order = core.Int64Ptr(int64(cardMap["order"].(int))) - - } - findingNoteNames := []string{} - for _, findingNoteNamesItem := range cardMap["finding_note_names"].([]interface{}) { - findingNoteNames = append(findingNoteNames, findingNoteNamesItem.(string)) - } - card.FindingNoteNames = findingNoteNames - if cardMap["requires_configuration"] != nil { - card.RequiresConfiguration = core.BoolPtr(cardMap["requires_configuration"].(bool)) - } - if cardMap["badge_text"] != nil { - card.BadgeText = core.StringPtr(cardMap["badge_text"].(string)) - } - if cardMap["badge_image"] != nil { - card.BadgeImage = core.StringPtr(cardMap["badge_image"].(string)) - } - elements := []findingsv1.CardElementIntf{} - for _, elementsItem := range cardMap["elements"].([]interface{}) { - elementsItemModel := resourceIBMSccSiNoteMapToCardElement(elementsItem.(map[string]interface{})) - elements = append(elements, elementsItemModel) - } - card.Elements = elements - - return card -} - -func resourceIBMSccSiNoteMapToCardElement(cardElementMap map[string]interface{}) findingsv1.CardElementIntf { - cardElement := findingsv1.CardElement{} - - if cardElementMap["text"] != nil { - cardElement.Text = core.StringPtr(cardElementMap["text"].(string)) - } - if cardElementMap["kind"] != nil { - cardElement.Kind = core.StringPtr(cardElementMap["kind"].(string)) - } - if cardElementMap["default_time_range"] != nil { - cardElement.DefaultTimeRange = core.StringPtr(cardElementMap["default_time_range"].(string)) - } - - if cardElementMap["value_type"] != nil && len(cardElementMap["value_type"].([]interface{})) > 0 { - cardElementValueType := findingsv1.NumericCardElementValueType{} - - if cardElementMap["value_type"].([]interface{})[0].(map[string]interface{})["kind"] != nil { - cardElementValueType.Kind = core.StringPtr(cardElementMap["value_type"].([]interface{})[0].(map[string]interface{})["kind"].(string)) - } - if cardElementMap["value_type"].([]interface{})[0].(map[string]interface{})["text"] != nil { - cardElementValueType.Text = core.StringPtr(cardElementMap["value_type"].([]interface{})[0].(map[string]interface{})["text"].(string)) - } - if cardElementMap["value_type"].([]interface{})[0].(map[string]interface{})["kpi_note_name"] != nil && cardElementMap["value_type"].([]interface{})[0].(map[string]interface{})["kpi_note_name"] != "" { - cardElementValueType.KpiNoteName = core.StringPtr(cardElementMap["value_type"].([]interface{})[0].(map[string]interface{})["kpi_note_name"].(string)) - } - if cardElementMap["value_type"].([]interface{})[0].(map[string]interface{})["finding_note_names"] != nil && len(cardElementMap["value_type"].([]interface{})[0].(map[string]interface{})["finding_note_names"].([]interface{})) > 0 { - findingNoteNames := []string{} - for _, findingNoteNamesItem := range cardElementMap["value_type"].([]interface{})[0].(map[string]interface{})["finding_note_names"].([]interface{}) { - findingNoteNames = append(findingNoteNames, findingNoteNamesItem.(string)) - } - cardElementValueType.FindingNoteNames = findingNoteNames - } - cardElement.ValueType = &cardElementValueType - } - - if cardElementMap["value_types"] != nil { - valueTypes := []findingsv1.ValueTypeIntf{} - for _, valueTypesItem := range cardElementMap["value_types"].([]interface{}) { - valueTypesItemModel := resourceIBMSccSiNoteMapToValueType(valueTypesItem.(map[string]interface{})) - valueTypes = append(valueTypes, valueTypesItemModel) - } - cardElement.ValueTypes = valueTypes - } - if cardElementMap["default_interval"] != nil { - cardElement.DefaultInterval = core.StringPtr(cardElementMap["default_interval"].(string)) - } - - return &cardElement -} - -func resourceIBMSccSiNoteMapToNumericCardElementValueType(numericCardElementValueTypeMap map[string]interface{}) findingsv1.NumericCardElementValueType { - numericCardElementValueType := findingsv1.NumericCardElementValueType{} - - if numericCardElementValueTypeMap["kind"] != nil { - numericCardElementValueType.Kind = core.StringPtr(numericCardElementValueTypeMap["kind"].(string)) - } - if numericCardElementValueTypeMap["kpi_note_name"] != nil { - numericCardElementValueType.KpiNoteName = core.StringPtr(numericCardElementValueTypeMap["kpi_note_name"].(string)) - } - if numericCardElementValueTypeMap["text"] != nil { - numericCardElementValueType.Text = core.StringPtr(numericCardElementValueTypeMap["text"].(string)) - } - if numericCardElementValueTypeMap["finding_note_names"] != nil { - findingNoteNames := []string{} - for _, findingNoteNamesItem := range numericCardElementValueTypeMap["finding_note_names"].([]interface{}) { - findingNoteNames = append(findingNoteNames, findingNoteNamesItem.(string)) - } - numericCardElementValueType.FindingNoteNames = findingNoteNames - } - - return numericCardElementValueType -} - -func resourceIBMSccSiNoteMapToValueType(valueTypeMap map[string]interface{}) findingsv1.ValueTypeIntf { - valueType := findingsv1.ValueType{} - - if valueTypeMap["kind"] != nil { - valueType.Kind = core.StringPtr(valueTypeMap["kind"].(string)) - } - if valueTypeMap["kpi_note_name"] != nil && len(valueTypeMap["kpi_note_name"].(string)) > 0 { - valueType.KpiNoteName = core.StringPtr(valueTypeMap["kpi_note_name"].(string)) - } - if valueTypeMap["text"] != nil { - valueType.Text = core.StringPtr(valueTypeMap["text"].(string)) - } - if valueTypeMap["finding_note_names"] != nil { - findingNoteNames := []string{} - for _, findingNoteNamesItem := range valueTypeMap["finding_note_names"].([]interface{}) { - findingNoteNames = append(findingNoteNames, findingNoteNamesItem.(string)) - } - valueType.FindingNoteNames = findingNoteNames - } - - return &valueType -} - -func resourceIBMSccSiNoteMapToValueTypeFindingCountValueType(valueTypeFindingCountValueTypeMap map[string]interface{}) findingsv1.ValueTypeFindingCountValueType { - valueTypeFindingCountValueType := findingsv1.ValueTypeFindingCountValueType{} - - valueTypeFindingCountValueType.Kind = core.StringPtr(valueTypeFindingCountValueTypeMap["kind"].(string)) - findingNoteNames := []string{} - for _, findingNoteNamesItem := range valueTypeFindingCountValueTypeMap["finding_note_names"].([]interface{}) { - findingNoteNames = append(findingNoteNames, findingNoteNamesItem.(string)) - } - valueTypeFindingCountValueType.FindingNoteNames = findingNoteNames - valueTypeFindingCountValueType.Text = core.StringPtr(valueTypeFindingCountValueTypeMap["text"].(string)) - - return valueTypeFindingCountValueType -} - -func resourceIBMSccSiNoteMapToValueTypeKpiValueType(valueTypeKpiValueTypeMap map[string]interface{}) findingsv1.ValueTypeKpiValueType { - valueTypeKpiValueType := findingsv1.ValueTypeKpiValueType{} - - valueTypeKpiValueType.Kind = core.StringPtr(valueTypeKpiValueTypeMap["kind"].(string)) - valueTypeKpiValueType.KpiNoteName = core.StringPtr(valueTypeKpiValueTypeMap["kpi_note_name"].(string)) - valueTypeKpiValueType.Text = core.StringPtr(valueTypeKpiValueTypeMap["text"].(string)) - - return valueTypeKpiValueType -} - -func resourceIBMSccSiNoteMapToCardElementTimeSeriesCardElement(cardElementTimeSeriesCardElementMap map[string]interface{}) findingsv1.CardElementTimeSeriesCardElement { - cardElementTimeSeriesCardElement := findingsv1.CardElementTimeSeriesCardElement{} - - cardElementTimeSeriesCardElement.Text = core.StringPtr(cardElementTimeSeriesCardElementMap["text"].(string)) - if cardElementTimeSeriesCardElementMap["default_interval"] != nil { - cardElementTimeSeriesCardElement.DefaultInterval = core.StringPtr(cardElementTimeSeriesCardElementMap["default_interval"].(string)) - } - cardElementTimeSeriesCardElement.Kind = core.StringPtr(cardElementTimeSeriesCardElementMap["kind"].(string)) - if cardElementTimeSeriesCardElementMap["default_time_range"] != nil { - cardElementTimeSeriesCardElement.DefaultTimeRange = core.StringPtr(cardElementTimeSeriesCardElementMap["default_time_range"].(string)) - } - valueTypes := []findingsv1.ValueTypeIntf{} - for _, valueTypesItem := range cardElementTimeSeriesCardElementMap["value_types"].([]interface{}) { - valueTypesItemModel := resourceIBMSccSiNoteMapToValueType(valueTypesItem.(map[string]interface{})) - valueTypes = append(valueTypes, valueTypesItemModel) - } - cardElementTimeSeriesCardElement.ValueTypes = valueTypes - - return cardElementTimeSeriesCardElement -} - -func resourceIBMSccSiNoteMapToCardElementBreakdownCardElement(cardElementBreakdownCardElementMap map[string]interface{}) findingsv1.CardElementBreakdownCardElement { - cardElementBreakdownCardElement := findingsv1.CardElementBreakdownCardElement{} - - cardElementBreakdownCardElement.Text = core.StringPtr(cardElementBreakdownCardElementMap["text"].(string)) - cardElementBreakdownCardElement.Kind = core.StringPtr(cardElementBreakdownCardElementMap["kind"].(string)) - if cardElementBreakdownCardElementMap["default_time_range"] != nil { - cardElementBreakdownCardElement.DefaultTimeRange = core.StringPtr(cardElementBreakdownCardElementMap["default_time_range"].(string)) - } - valueTypes := []findingsv1.ValueTypeIntf{} - for _, valueTypesItem := range cardElementBreakdownCardElementMap["value_types"].([]interface{}) { - valueTypesItemModel := resourceIBMSccSiNoteMapToValueType(valueTypesItem.(map[string]interface{})) - valueTypes = append(valueTypes, valueTypesItemModel) - } - cardElementBreakdownCardElement.ValueTypes = valueTypes - - return cardElementBreakdownCardElement -} - -func resourceIBMSccSiNoteMapToCardElementNumericCardElement(cardElementNumericCardElementMap map[string]interface{}) findingsv1.CardElementNumericCardElement { - cardElementNumericCardElement := findingsv1.CardElementNumericCardElement{} - - cardElementNumericCardElement.Text = core.StringPtr(cardElementNumericCardElementMap["text"].(string)) - cardElementNumericCardElement.Kind = core.StringPtr(cardElementNumericCardElementMap["kind"].(string)) - if cardElementNumericCardElementMap["default_time_range"] != nil { - cardElementNumericCardElement.DefaultTimeRange = core.StringPtr(cardElementNumericCardElementMap["default_time_range"].(string)) - } - // TODO: handle ValueType of type NumericCardElementValueType -- not primitive type, not list - - return cardElementNumericCardElement -} - -func resourceIBMSccSiNoteMapToSection(sectionMap map[string]interface{}) findingsv1.Section { - section := findingsv1.Section{} - - section.Title = core.StringPtr(sectionMap["title"].(string)) - section.Image = core.StringPtr(sectionMap["image"].(string)) - - return section -} - -func resourceIBMSccSiNoteRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - findingsClient, err := meta.(conns.ClientSession).FindingsV1() - if err != nil { - return diag.FromErr(err) - } - - getNoteOptions := &findingsv1.GetNoteOptions{} - - parts, err := flex.SepIdParts(d.Id(), "/") - if err != nil { - return diag.FromErr(err) - } - - findingsClient.AccountID = &parts[0] - - d.Set("account_id", &parts[0]) - - getNoteOptions.SetProviderID(parts[1]) - getNoteOptions.SetNoteID(parts[2]) - - apiNote, response, err := findingsClient.GetNoteWithContext(context, getNoteOptions) - if err != nil { - if response != nil && response.StatusCode == 404 { - d.SetId("") - return nil - } - log.Printf("[DEBUG] GetNoteWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("GetNoteWithContext failed %s\n%s", err, response)) - } - - if err = d.Set("provider_id", getNoteOptions.ProviderID); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting provider_id: %s", err)) - } - if err = d.Set("short_description", apiNote.ShortDescription); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting short_description: %s", err)) - } - if err = d.Set("long_description", apiNote.LongDescription); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting long_description: %s", err)) - } - if err = d.Set("kind", apiNote.Kind); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting kind: %s", err)) - } - if err = d.Set("note_id", apiNote.ID); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting note_id: %s", err)) - } - reportedByMap := resourceIBMSccSiNoteReporterToMap(*apiNote.ReportedBy) - if err = d.Set("reported_by", []map[string]interface{}{reportedByMap}); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting reported_by: %s", err)) - } - if apiNote.RelatedURL != nil { - relatedURL := []map[string]interface{}{} - for _, relatedURLItem := range apiNote.RelatedURL { - relatedURLItemMap := resourceIBMSccSiNoteAPINoteRelatedURLToMap(relatedURLItem) - relatedURL = append(relatedURL, relatedURLItemMap) - } - if err = d.Set("related_url", relatedURL); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting related_url: %s", err)) - } - } - if err = d.Set("shared", apiNote.Shared); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting shared: %s", err)) - } - if apiNote.Finding != nil { - findingMap := resourceIBMSccSiNoteFindingTypeToMap(*apiNote.Finding) - if err = d.Set("finding", []map[string]interface{}{findingMap}); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting finding: %s", err)) - } - } - if apiNote.Kpi != nil { - kpiMap := resourceIBMSccSiNoteKpiTypeToMap(*apiNote.Kpi) - if err = d.Set("kpi", []map[string]interface{}{kpiMap}); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting kpi: %s", err)) - } - } - if apiNote.Card != nil { - cardIntf := d.Get("card") - cardMap := resourceIBMSccSiNoteCardToMap(*apiNote.Card, cardIntf) - if err = d.Set("card", []map[string]interface{}{cardMap}); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting card: %s", err)) - } - } - if apiNote.Section != nil { - sectionMap := resourceIBMSccSiNoteSectionToMap(*apiNote.Section) - if err = d.Set("section", []map[string]interface{}{sectionMap}); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting section: %s", err)) - } - } - if err = d.Set("create_time", flex.DateTimeToString(apiNote.CreateTime)); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting create_time: %s", err)) - } - if err = d.Set("update_time", flex.DateTimeToString(apiNote.UpdateTime)); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting update_time: %s", err)) - } - - return nil -} - -func resourceIBMSccSiNoteReporterToMap(reporter findingsv1.Reporter) map[string]interface{} { - reporterMap := map[string]interface{}{} - - reporterMap["id"] = reporter.ID - reporterMap["title"] = reporter.Title - if reporter.URL != nil { - reporterMap["url"] = reporter.URL - } - - return reporterMap -} - -func resourceIBMSccSiNoteAPINoteRelatedURLToMap(apiNoteRelatedURL findingsv1.APINoteRelatedURL) map[string]interface{} { - apiNoteRelatedURLMap := map[string]interface{}{} - - apiNoteRelatedURLMap["label"] = apiNoteRelatedURL.Label - apiNoteRelatedURLMap["url"] = apiNoteRelatedURL.URL - - return apiNoteRelatedURLMap -} - -func resourceIBMSccSiNoteFindingTypeToMap(findingType findingsv1.FindingType) map[string]interface{} { - findingTypeMap := map[string]interface{}{} - - findingTypeMap["severity"] = findingType.Severity - if findingType.NextSteps != nil { - nextSteps := []map[string]interface{}{} - for _, nextStepsItem := range findingType.NextSteps { - nextStepsItemMap := resourceIBMSccSiNoteRemediationStepToMap(nextStepsItem) - nextSteps = append(nextSteps, nextStepsItemMap) - // TODO: handle NextSteps of type TypeList -- list of non-primitive, not model items - } - findingTypeMap["next_steps"] = nextSteps - } - - return findingTypeMap -} - -func resourceIBMSccSiNoteRemediationStepToMap(remediationStep findingsv1.RemediationStep) map[string]interface{} { - remediationStepMap := map[string]interface{}{} - - if remediationStep.Title != nil { - remediationStepMap["title"] = remediationStep.Title - } - if remediationStep.URL != nil { - remediationStepMap["url"] = remediationStep.URL - } - - return remediationStepMap -} - -func resourceIBMSccSiNoteKpiTypeToMap(kpiType findingsv1.KpiType) map[string]interface{} { - kpiTypeMap := map[string]interface{}{} - - kpiTypeMap["aggregation_type"] = kpiType.AggregationType - - return kpiTypeMap -} - -func resourceIBMSccSiNoteCardToMap(card findingsv1.Card, cardIntf interface{}) map[string]interface{} { - cardMap := map[string]interface{}{} - - cardMap["section"] = card.Section - cardMap["title"] = card.Title - cardMap["subtitle"] = card.Subtitle - if card.Order != nil { - order := flex.IntValue(card.Order) - if order != 0 { - cardMap["order"] = flex.IntValue(card.Order) - } - } - cardMap["finding_note_names"] = card.FindingNoteNames - if card.RequiresConfiguration != nil { - cardMap["requires_configuration"] = card.RequiresConfiguration - } - if card.BadgeText != nil { - cardMap["badge_text"] = card.BadgeText - } - if card.BadgeImage != nil { - cardMap["badge_image"] = card.BadgeImage - } - elements := []map[string]interface{}{} - for i, elementsItem := range card.Elements { - var elemResource interface{} - if cardIntf != nil && len(cardIntf.([]interface{})) > 0 { - elemResource = cardIntf.([]interface{})[0].(map[string]interface{})["elements"].([]interface{})[i] - } - elementsItemMap := resourceIBMSccSiNoteCardElementToMap(elementsItem, elemResource) - elements = append(elements, elementsItemMap) - // TODO: handle Elements of type TypeList -- list of non-primitive, not model items - } - cardMap["elements"] = elements - - return cardMap -} - -func resourceIBMSccSiNoteCardElementToMap(cardElement findingsv1.CardElementIntf, elemResource interface{}) map[string]interface{} { - cardElementMap := map[string]interface{}{} - - switch v := cardElement.(type) { - case *findingsv1.CardElementNumericCardElement: - cardElementMap = resourceIBMSccSiNoteCardElementNumericCardElementToMap(*v, elemResource) - case *findingsv1.CardElementBreakdownCardElement: - cardElementMap = resourceIBMSccSiNoteCardElementBreakdownCardElementToMap(*v, elemResource) - case *findingsv1.CardElementTimeSeriesCardElement: - cardElementMap = resourceIBMSccSiNoteCardElementTimeSeriesCardElementToMap(*v, elemResource) - default: - log.Printf("[DEBUG] Unknown card element type") - } - - return cardElementMap -} - -func resourceIBMSccSiNoteNumericCardElementValueTypeToMap(numericCardElementValueType findingsv1.NumericCardElementValueType, elemResource interface{}) map[string]interface{} { - numericCardElementValueTypeMap := map[string]interface{}{} - - if numericCardElementValueType.Kind != nil { - numericCardElementValueTypeMap["kind"] = numericCardElementValueType.Kind - } - - if numericCardElementValueType.KpiNoteName != nil { - numericCardElementValueTypeMap["kpi_note_name"] = numericCardElementValueType.KpiNoteName - if elemResource != nil { - findingNoteNamesMap := make([]string, 0) - findingNoteNames := elemResource.(map[string]interface{})["finding_note_names"] - if findingNoteNames != nil { - for _, findingNoteName := range findingNoteNames.([]interface{}) { - findingNoteNamesMap = append(findingNoteNamesMap, findingNoteName.(string)) - } - numericCardElementValueTypeMap["finding_note_names"] = findingNoteNamesMap - } - } - } - - if numericCardElementValueType.FindingNoteNames != nil { - numericCardElementValueTypeMap["finding_note_names"] = numericCardElementValueType.FindingNoteNames - if elemResource != nil { - kpiNoteName := elemResource.(map[string]interface{})["kpi_note_name"] - if kpiNoteName != nil { - numericCardElementValueTypeMap["kpi_note_name"] = kpiNoteName - } - } - } - - if numericCardElementValueType.Text != nil { - numericCardElementValueTypeMap["text"] = numericCardElementValueType.Text - } - - return numericCardElementValueTypeMap -} - -func resourceIBMSccSiNoteValueTypeToMap(valueType findingsv1.ValueTypeIntf, elemResource interface{}) map[string]interface{} { - valueTypeMap := map[string]interface{}{} - - switch v := valueType.(type) { - - case *findingsv1.ValueTypeFindingCountValueType: - valueTypeMap["kind"] = v.Kind - valueTypeMap["finding_note_names"] = v.FindingNoteNames - valueTypeMap["text"] = v.Text - kpiNoteName := elemResource.(map[string]interface{})["kpi_note_name"] - if kpiNoteName == nil { - valueTypeMap["kpi_note_name"] = "" - } else { - valueTypeMap["kpi_note_name"] = kpiNoteName - } - case *findingsv1.ValueTypeKpiValueType: - valueTypeMap["kind"] = v.Kind - valueTypeMap["kpi_note_name"] = v.KpiNoteName - valueTypeMap["text"] = v.Text - findingNoteNames := elemResource.(map[string]interface{})["finding_note_names"] - if findingNoteNames == nil { - valueTypeMap["finding_note_names"] = []string{} - } else { - findingNoteNamesMap := make([]string, 0) - for _, findingNoteName := range findingNoteNames.([]interface{}) { - findingNoteNamesMap = append(findingNoteNamesMap, findingNoteName.(string)) - } - valueTypeMap["finding_note_names"] = findingNoteNamesMap - } - default: - log.Printf("[DEBUG] Unknown card element value_type type") - } - - return valueTypeMap -} - -func resourceIBMSccSiNoteValueTypeFindingCountValueTypeToMap(valueTypeFindingCountValueType findingsv1.ValueTypeFindingCountValueType) map[string]interface{} { - valueTypeFindingCountValueTypeMap := map[string]interface{}{} - - valueTypeFindingCountValueTypeMap["kind"] = valueTypeFindingCountValueType.Kind - valueTypeFindingCountValueTypeMap["finding_note_names"] = valueTypeFindingCountValueType.FindingNoteNames - valueTypeFindingCountValueTypeMap["text"] = valueTypeFindingCountValueType.Text - - return valueTypeFindingCountValueTypeMap -} - -func resourceIBMSccSiNoteValueTypeKpiValueTypeToMap(valueTypeKpiValueType findingsv1.ValueTypeKpiValueType) map[string]interface{} { - valueTypeKpiValueTypeMap := map[string]interface{}{} - - valueTypeKpiValueTypeMap["kind"] = valueTypeKpiValueType.Kind - valueTypeKpiValueTypeMap["kpi_note_name"] = valueTypeKpiValueType.KpiNoteName - valueTypeKpiValueTypeMap["text"] = valueTypeKpiValueType.Text - - return valueTypeKpiValueTypeMap -} - -func resourceIBMSccSiNoteCardElementTimeSeriesCardElementToMap(cardElementTimeSeriesCardElement findingsv1.CardElementTimeSeriesCardElement, elemResource interface{}) map[string]interface{} { - cardElementTimeSeriesCardElementMap := map[string]interface{}{} - - cardElementTimeSeriesCardElementMap["text"] = cardElementTimeSeriesCardElement.Text - if cardElementTimeSeriesCardElement.DefaultInterval != nil { - cardElementTimeSeriesCardElementMap["default_interval"] = cardElementTimeSeriesCardElement.DefaultInterval - } - cardElementTimeSeriesCardElementMap["kind"] = cardElementTimeSeriesCardElement.Kind - if cardElementTimeSeriesCardElement.DefaultTimeRange != nil { - cardElementTimeSeriesCardElementMap["default_time_range"] = cardElementTimeSeriesCardElement.DefaultTimeRange - } - valueTypes := []map[string]interface{}{} - for _, valueTypesItem := range cardElementTimeSeriesCardElement.ValueTypes { - valueTypesItemMap := resourceIBMSccSiNoteValueTypeToMap(valueTypesItem, elemResource) - valueTypes = append(valueTypes, valueTypesItemMap) - // TODO: handle ValueTypes of type TypeList -- list of non-primitive, not model items - } - cardElementTimeSeriesCardElementMap["value_types"] = valueTypes - - return cardElementTimeSeriesCardElementMap -} - -func resourceIBMSccSiNoteCardElementBreakdownCardElementToMap(cardElementBreakdownCardElement findingsv1.CardElementBreakdownCardElement, elemResource interface{}) map[string]interface{} { - cardElementBreakdownCardElementMap := map[string]interface{}{} - - cardElementBreakdownCardElementMap["text"] = cardElementBreakdownCardElement.Text - cardElementBreakdownCardElementMap["kind"] = cardElementBreakdownCardElement.Kind - if cardElementBreakdownCardElement.DefaultTimeRange != nil { - cardElementBreakdownCardElementMap["default_time_range"] = cardElementBreakdownCardElement.DefaultTimeRange - } - valueTypes := []map[string]interface{}{} - for i, valueTypesItem := range cardElementBreakdownCardElement.ValueTypes { - valueType := elemResource.(map[string]interface{})["value_types"].([]interface{})[i] - valueTypesItemMap := resourceIBMSccSiNoteValueTypeToMap(valueTypesItem, valueType) - valueTypes = append(valueTypes, valueTypesItemMap) - // TODO: handle ValueTypes of type TypeList -- list of non-primitive, not model items - } - cardElementBreakdownCardElementMap["value_types"] = valueTypes - - if elemResource != nil { - if elemResource.(map[string]interface{})["default_interval"] != nil { - cardElementBreakdownCardElementMap["default_interval"] = elemResource.(map[string]interface{})["default_interval"].(string) - } - } - - return cardElementBreakdownCardElementMap -} - -func resourceIBMSccSiNoteCardElementNumericCardElementToMap(cardElementNumericCardElement findingsv1.CardElementNumericCardElement, elemResource interface{}) map[string]interface{} { - cardElementNumericCardElementMap := map[string]interface{}{} - - cardElementNumericCardElementMap["text"] = cardElementNumericCardElement.Text - cardElementNumericCardElementMap["kind"] = cardElementNumericCardElement.Kind - if cardElementNumericCardElement.DefaultTimeRange != nil { - cardElementNumericCardElementMap["default_time_range"] = cardElementNumericCardElement.DefaultTimeRange - } - ValueTypeMap := resourceIBMSccSiNoteNumericCardElementValueTypeToMap(*cardElementNumericCardElement.ValueType, elemResource) - cardElementNumericCardElementMap["value_type"] = []map[string]interface{}{ValueTypeMap} - - if elemResource != nil { - if elemResource.(map[string]interface{})["default_interval"] != nil { - cardElementNumericCardElementMap["default_interval"] = elemResource.(map[string]interface{})["default_interval"].(string) - } - } - - return cardElementNumericCardElementMap -} - -func resourceIBMSccSiNoteSectionToMap(section findingsv1.Section) map[string]interface{} { - sectionMap := map[string]interface{}{} - - sectionMap["title"] = section.Title - sectionMap["image"] = section.Image - - return sectionMap -} - -func resourceIBMSccSiNoteUpdate(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - findingsClient, err := meta.(conns.ClientSession).FindingsV1() - if err != nil { - return diag.FromErr(err) - } - - updateNoteOptions := &findingsv1.UpdateNoteOptions{} - - parts, err := flex.SepIdParts(d.Id(), "/") - if err != nil { - return diag.FromErr(err) - } - - findingsClient.AccountID = &parts[0] - - updateNoteOptions.SetProviderID(parts[1]) - updateNoteOptions.SetNoteID(parts[2]) - updateNoteOptions.SetProviderID(d.Get("provider_id").(string)) - updateNoteOptions.SetShortDescription(d.Get("short_description").(string)) - updateNoteOptions.SetLongDescription(d.Get("long_description").(string)) - updateNoteOptions.SetKind(d.Get("kind").(string)) - updateNoteOptions.SetID(d.Get("note_id").(string)) - reportedBy := resourceIBMSccSiNoteMapToReporter(d.Get("reported_by.0").(map[string]interface{})) - updateNoteOptions.SetReportedBy(&reportedBy) - if _, ok := d.GetOk("related_url"); ok { - var relatedURL []findingsv1.APINoteRelatedURL - for _, e := range d.Get("related_url").([]interface{}) { - value := e.(map[string]interface{}) - relatedURLItem := resourceIBMSccSiNoteMapToAPINoteRelatedURL(value) - relatedURL = append(relatedURL, relatedURLItem) - } - updateNoteOptions.SetRelatedURL(relatedURL) - } - if _, ok := d.GetOk("shared"); ok { - updateNoteOptions.SetShared(d.Get("shared").(bool)) - } - if _, ok := d.GetOk("finding"); ok { - finding := resourceIBMSccSiNoteMapToFindingType(d.Get("finding.0").(map[string]interface{})) - updateNoteOptions.SetFinding(&finding) - } - if _, ok := d.GetOk("kpi"); ok { - kpi := resourceIBMSccSiNoteMapToKpiType(d.Get("kpi.0").(map[string]interface{})) - updateNoteOptions.SetKpi(&kpi) - } - if _, ok := d.GetOk("card"); ok { - card := resourceIBMSccSiNoteMapToCard(d.Get("card.0").(map[string]interface{})) - updateNoteOptions.SetCard(&card) - } - if _, ok := d.GetOk("section"); ok { - section := resourceIBMSccSiNoteMapToSection(d.Get("section.0").(map[string]interface{})) - updateNoteOptions.SetSection(§ion) - } - - _, response, err := findingsClient.UpdateNoteWithContext(context, updateNoteOptions) - if err != nil { - log.Printf("[DEBUG] UpdateNoteWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("UpdateNoteWithContext failed %s\n%s", err, response)) - } - - return resourceIBMSccSiNoteRead(context, d, meta) -} - -func resourceIBMSccSiNoteDelete(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - findingsClient, err := meta.(conns.ClientSession).FindingsV1() - if err != nil { - return diag.FromErr(err) - } - - deleteNoteOptions := &findingsv1.DeleteNoteOptions{} - - parts, err := flex.SepIdParts(d.Id(), "/") - if err != nil { - return diag.FromErr(err) - } - - findingsClient.AccountID = &parts[0] - - deleteNoteOptions.SetProviderID(parts[1]) - deleteNoteOptions.SetNoteID(parts[2]) - - response, err := findingsClient.DeleteNoteWithContext(context, deleteNoteOptions) - if err != nil { - log.Printf("[DEBUG] DeleteNoteWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("DeleteNoteWithContext failed %s\n%s", err, response)) - } - - d.SetId("") - - return nil -} diff --git a/ibm/service/scc/resource_ibm_scc_si_note_test.go b/ibm/service/scc/resource_ibm_scc_si_note_test.go deleted file mode 100644 index 0dd2019002..0000000000 --- a/ibm/service/scc/resource_ibm_scc_si_note_test.go +++ /dev/null @@ -1,573 +0,0 @@ -// Copyright IBM Corp. 2021 All Rights Reserved. -// Licensed under the Mozilla Public License v2.0 - -package scc_test - -import ( - "fmt" - "regexp" - "testing" - - acc "github.com/IBM-Cloud/terraform-provider-ibm/ibm/acctest" - "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" - "github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex" - - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" - - "github.com/IBM/scc-go-sdk/findingsv1" -) - -func TestAccIBMSccSiNoteCardNumeric(t *testing.T) { - var conf findingsv1.APINote - providerID := fmt.Sprintf("tf_provider_id_%d", acctest.RandIntRange(10, 100)) - shortDescription := fmt.Sprintf("tf_short_description_%d", acctest.RandIntRange(10, 100)) - longDescription := fmt.Sprintf("tf_long_description_%d", acctest.RandIntRange(10, 100)) - kind := "CARD" - noteID := fmt.Sprintf("tf_note_id_%d", acctest.RandIntRange(10, 100)) - - resource.Test(t, resource.TestCase{ - PreCheck: func() { acc.TestAccPreCheck(t) }, - Providers: acc.TestAccProviders, - CheckDestroy: testAccCheckIBMSccSiNoteDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCheckIBMSccSiNoteCardNumericBasic(acc.Scc_si_account, providerID, shortDescription, longDescription, kind, noteID), - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckIBMSccSiNoteExists("ibm_scc_si_note.scc_si_note", conf), - resource.TestCheckResourceAttr("ibm_scc_si_note.scc_si_note", "provider_id", providerID), - resource.TestCheckResourceAttr("ibm_scc_si_note.scc_si_note", "short_description", shortDescription), - resource.TestCheckResourceAttr("ibm_scc_si_note.scc_si_note", "long_description", longDescription), - resource.TestCheckResourceAttr("ibm_scc_si_note.scc_si_note", "kind", kind), - resource.TestCheckResourceAttr("ibm_scc_si_note.scc_si_note", "note_id", noteID), - resource.TestCheckResourceAttr("ibm_scc_si_note.scc_si_note", "card.0.section", "section"), - resource.TestCheckResourceAttr("ibm_scc_si_note.scc_si_note", "card.0.title", "title"), - resource.TestCheckResourceAttr("ibm_scc_si_note.scc_si_note", "card.0.subtitle", "subtitle"), - resource.TestCheckResourceAttr("ibm_scc_si_note.scc_si_note", "card.0.elements.0.kind", "NUMERIC"), - resource.TestCheckResourceAttr("ibm_scc_si_note.scc_si_note", "card.0.elements.0.value_type.0.kind", "FINDING_COUNT"), - resource.TestCheckResourceAttr("ibm_scc_si_note.scc_si_note", "card.0.elements.0.value_type.0.finding_note_names.0", fmt.Sprintf("providers/%s/notes/note123", providerID)), - ), - }, - }, - }) -} - -func TestAccIBMSccSiNoteCardBreakdown(t *testing.T) { - var conf findingsv1.APINote - providerID := fmt.Sprintf("tf_provider_id_%d", acctest.RandIntRange(10, 100)) - shortDescription := fmt.Sprintf("tf_short_description_%d", acctest.RandIntRange(10, 100)) - longDescription := fmt.Sprintf("tf_long_description_%d", acctest.RandIntRange(10, 100)) - kind := "CARD" - noteID := fmt.Sprintf("tf_note_id_%d", acctest.RandIntRange(10, 100)) - - resource.Test(t, resource.TestCase{ - PreCheck: func() { acc.TestAccPreCheck(t) }, - Providers: acc.TestAccProviders, - CheckDestroy: testAccCheckIBMSccSiNoteDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCheckIBMSccSiNoteCardBreakdownBasic(acc.Scc_si_account, providerID, shortDescription, longDescription, kind, noteID), - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckIBMSccSiNoteExists("ibm_scc_si_note.scc_si_note", conf), - resource.TestCheckResourceAttr("ibm_scc_si_note.scc_si_note", "provider_id", providerID), - resource.TestCheckResourceAttr("ibm_scc_si_note.scc_si_note", "short_description", shortDescription), - resource.TestCheckResourceAttr("ibm_scc_si_note.scc_si_note", "long_description", longDescription), - resource.TestCheckResourceAttr("ibm_scc_si_note.scc_si_note", "kind", kind), - resource.TestCheckResourceAttr("ibm_scc_si_note.scc_si_note", "note_id", noteID), - resource.TestCheckResourceAttr("ibm_scc_si_note.scc_si_note", "card.0.section", "section"), - resource.TestCheckResourceAttr("ibm_scc_si_note.scc_si_note", "card.0.title", "title"), - resource.TestCheckResourceAttr("ibm_scc_si_note.scc_si_note", "card.0.subtitle", "subtitle"), - resource.TestCheckResourceAttr("ibm_scc_si_note.scc_si_note", "card.0.elements.0.kind", "BREAKDOWN"), - resource.TestCheckResourceAttr("ibm_scc_si_note.scc_si_note", "card.0.elements.0.value_types.0.kind", "FINDING_COUNT"), - resource.TestCheckResourceAttr("ibm_scc_si_note.scc_si_note", "card.0.elements.0.value_types.0.finding_note_names.0", fmt.Sprintf("providers/%s/notes/note123", providerID)), - ), - }, - }, - }) -} - -func TestAccIBMSccSiNoteCardTimeSeries(t *testing.T) { - var conf findingsv1.APINote - providerID := fmt.Sprintf("tf_provider_id_%d", acctest.RandIntRange(10, 100)) - shortDescription := fmt.Sprintf("tf_short_description_%d", acctest.RandIntRange(10, 100)) - longDescription := fmt.Sprintf("tf_long_description_%d", acctest.RandIntRange(10, 100)) - kind := "CARD" - noteID := fmt.Sprintf("tf_note_id_%d", acctest.RandIntRange(10, 100)) - - resource.Test(t, resource.TestCase{ - PreCheck: func() { acc.TestAccPreCheck(t) }, - Providers: acc.TestAccProviders, - CheckDestroy: testAccCheckIBMSccSiNoteDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCheckIBMSccSiNoteCardTimeSeriesBasic(acc.Scc_si_account, providerID, shortDescription, longDescription, kind, noteID), - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckIBMSccSiNoteExists("ibm_scc_si_note.scc_si_note", conf), - resource.TestCheckResourceAttr("ibm_scc_si_note.scc_si_note", "provider_id", providerID), - resource.TestCheckResourceAttr("ibm_scc_si_note.scc_si_note", "short_description", shortDescription), - resource.TestCheckResourceAttr("ibm_scc_si_note.scc_si_note", "long_description", longDescription), - resource.TestCheckResourceAttr("ibm_scc_si_note.scc_si_note", "kind", kind), - resource.TestCheckResourceAttr("ibm_scc_si_note.scc_si_note", "note_id", noteID), - resource.TestCheckResourceAttr("ibm_scc_si_note.scc_si_note", "card.0.section", "section"), - resource.TestCheckResourceAttr("ibm_scc_si_note.scc_si_note", "card.0.title", "title"), - resource.TestCheckResourceAttr("ibm_scc_si_note.scc_si_note", "card.0.subtitle", "subtitle"), - resource.TestCheckResourceAttr("ibm_scc_si_note.scc_si_note", "card.0.elements.0.kind", "TIME_SERIES"), - resource.TestCheckResourceAttr("ibm_scc_si_note.scc_si_note", "card.0.elements.0.value_types.0.kind", "FINDING_COUNT"), - resource.TestCheckResourceAttr("ibm_scc_si_note.scc_si_note", "card.0.elements.0.value_types.0.finding_note_names.0", fmt.Sprintf("providers/%s/notes/note123", providerID)), - ), - }, - }, - }) -} - -func TestAccIBMSccSiNoteBasic(t *testing.T) { - var conf findingsv1.APINote - providerID := fmt.Sprintf("tf_provider_id_%d", acctest.RandIntRange(10, 100)) - shortDescription := fmt.Sprintf("tf_short_description_%d", acctest.RandIntRange(10, 100)) - longDescription := fmt.Sprintf("tf_long_description_%d", acctest.RandIntRange(10, 100)) - kind := "FINDING" - noteID := fmt.Sprintf("tf_note_id_%d", acctest.RandIntRange(10, 100)) - shortDescriptionUpdate := fmt.Sprintf("tf_short_description_%d", acctest.RandIntRange(10, 100)) - longDescriptionUpdate := fmt.Sprintf("tf_long_description_%d", acctest.RandIntRange(10, 100)) - kindUpdate := "FINDING" - noteIDUpdate := noteID - - resource.Test(t, resource.TestCase{ - PreCheck: func() { acc.TestAccPreCheck(t) }, - Providers: acc.TestAccProviders, - CheckDestroy: testAccCheckIBMSccSiNoteDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCheckIBMSccSiNoteConfigBasic(acc.Scc_si_account, providerID, shortDescription, longDescription, kind, noteID), - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckIBMSccSiNoteExists("ibm_scc_si_note.scc_si_note", conf), - resource.TestCheckResourceAttr("ibm_scc_si_note.scc_si_note", "provider_id", providerID), - resource.TestCheckResourceAttr("ibm_scc_si_note.scc_si_note", "short_description", shortDescription), - resource.TestCheckResourceAttr("ibm_scc_si_note.scc_si_note", "long_description", longDescription), - resource.TestCheckResourceAttr("ibm_scc_si_note.scc_si_note", "kind", kind), - resource.TestCheckResourceAttr("ibm_scc_si_note.scc_si_note", "note_id", noteID), - ), - }, - { - Config: testAccCheckIBMSccSiNoteConfigBasic(acc.Scc_si_account, providerID, shortDescriptionUpdate, longDescriptionUpdate, kindUpdate, noteIDUpdate), - Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr("ibm_scc_si_note.scc_si_note", "provider_id", providerID), - resource.TestCheckResourceAttr("ibm_scc_si_note.scc_si_note", "short_description", shortDescriptionUpdate), - resource.TestCheckResourceAttr("ibm_scc_si_note.scc_si_note", "long_description", longDescriptionUpdate), - resource.TestCheckResourceAttr("ibm_scc_si_note.scc_si_note", "kind", kindUpdate), - resource.TestCheckResourceAttr("ibm_scc_si_note.scc_si_note", "note_id", noteIDUpdate), - ), - }, - }, - }) -} - -func TestAccIBMSccSiNoteAllArgs(t *testing.T) { - var conf findingsv1.APINote - providerID := fmt.Sprintf("tf_provider_id_%d", acctest.RandIntRange(10, 100)) - shortDescription := fmt.Sprintf("tf_short_description_%d", acctest.RandIntRange(10, 100)) - longDescription := fmt.Sprintf("tf_long_description_%d", acctest.RandIntRange(10, 100)) - kind := "FINDING" - noteID := fmt.Sprintf("tf_note_id_%d", acctest.RandIntRange(10, 100)) - shared := "true" - shortDescriptionUpdate := fmt.Sprintf("tf_short_description_%d", acctest.RandIntRange(10, 100)) - longDescriptionUpdate := fmt.Sprintf("tf_long_description_%d", acctest.RandIntRange(10, 100)) - kindUpdate := "FINDING" - noteIDUpdate := noteID - sharedUpdate := "false" - - resource.Test(t, resource.TestCase{ - PreCheck: func() { acc.TestAccPreCheck(t) }, - Providers: acc.TestAccProviders, - CheckDestroy: testAccCheckIBMSccSiNoteDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCheckIBMSccSiNoteConfig(acc.Scc_si_account, providerID, shortDescription, longDescription, kind, noteID, shared), - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckIBMSccSiNoteExists("ibm_scc_si_note.scc_si_note", conf), - resource.TestCheckResourceAttr("ibm_scc_si_note.scc_si_note", "provider_id", providerID), - resource.TestCheckResourceAttr("ibm_scc_si_note.scc_si_note", "short_description", shortDescription), - resource.TestCheckResourceAttr("ibm_scc_si_note.scc_si_note", "long_description", longDescription), - resource.TestCheckResourceAttr("ibm_scc_si_note.scc_si_note", "kind", kind), - resource.TestCheckResourceAttr("ibm_scc_si_note.scc_si_note", "note_id", noteID), - resource.TestCheckResourceAttr("ibm_scc_si_note.scc_si_note", "shared", shared), - ), - }, - { - Config: testAccCheckIBMSccSiNoteConfig(acc.Scc_si_account, providerID, shortDescriptionUpdate, longDescriptionUpdate, kindUpdate, noteIDUpdate, sharedUpdate), - Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr("ibm_scc_si_note.scc_si_note", "provider_id", providerID), - resource.TestCheckResourceAttr("ibm_scc_si_note.scc_si_note", "short_description", shortDescriptionUpdate), - resource.TestCheckResourceAttr("ibm_scc_si_note.scc_si_note", "long_description", longDescriptionUpdate), - resource.TestCheckResourceAttr("ibm_scc_si_note.scc_si_note", "kind", kindUpdate), - resource.TestCheckResourceAttr("ibm_scc_si_note.scc_si_note", "note_id", noteIDUpdate), - resource.TestCheckResourceAttr("ibm_scc_si_note.scc_si_note", "shared", sharedUpdate), - ), - }, - { - ResourceName: "ibm_scc_si_note.scc_si_note", - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func TestAccIBMSccSiNoteInvalid(t *testing.T) { - providerID := fmt.Sprintf("tf_provider_id_%d", acctest.RandIntRange(10, 100)) - shortDescription := fmt.Sprintf("tf_short_description_%d", acctest.RandIntRange(10, 100)) - longDescription := fmt.Sprintf("tf_long_description_%d", acctest.RandIntRange(10, 100)) - kind := "FINDING" - noteID := fmt.Sprintf("tf_note_id_%d", acctest.RandIntRange(10, 100)) - - resource.Test(t, resource.TestCase{ - PreCheck: func() { acc.TestAccPreCheck(t) }, - Providers: acc.TestAccProviders, - CheckDestroy: testAccCheckIBMSccSiNoteDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCheckIBMSccSiNoteConfigInvalid(acc.Scc_si_account, providerID, shortDescription, longDescription, kind, noteID), - ExpectError: regexp.MustCompile("Invalid combination of arguments"), - }, - }, - }) -} - -func TestAccIBMSccSiNoteEmpty(t *testing.T) { - providerID := fmt.Sprintf("tf_provider_id_%d", acctest.RandIntRange(10, 100)) - shortDescription := fmt.Sprintf("tf_short_description_%d", acctest.RandIntRange(10, 100)) - longDescription := fmt.Sprintf("tf_long_description_%d", acctest.RandIntRange(10, 100)) - kind := "FINDING" - noteID := fmt.Sprintf("tf_note_id_%d", acctest.RandIntRange(10, 100)) - - resource.Test(t, resource.TestCase{ - PreCheck: func() { acc.TestAccPreCheck(t) }, - Providers: acc.TestAccProviders, - CheckDestroy: testAccCheckIBMSccSiNoteDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCheckIBMSccSiNoteConfigEmpty(acc.Scc_si_account, providerID, shortDescription, longDescription, kind, noteID), - ExpectError: regexp.MustCompile("Invalid combination of arguments"), - }, - }, - }) -} - -func testAccCheckIBMSccSiNoteCardNumericBasic(accountID string, providerID string, shortDescription string, longDescription string, kind string, noteID string) string { - return fmt.Sprintf(` - - resource "ibm_scc_si_note" "scc_si_note" { - account_id = "%s" - provider_id = "%s" - short_description = "%s" - long_description = "%s" - kind = "%s" - note_id = "%s" - reported_by { - id = "id" - title = "title" - url = "url" - } - card { - section = "section" - title = "title" - subtitle = "subtitle" - finding_note_names = ["providers/%s/notes/note123"] - elements { - kind = "NUMERIC" - text = "text" - value_type { - finding_note_names = ["providers/%s/notes/note123"] - kind = "FINDING_COUNT" - } - } - } - } - `, accountID, providerID, shortDescription, longDescription, kind, noteID, providerID, providerID) -} - -func testAccCheckIBMSccSiNoteCardBreakdownBasic(accountID string, providerID string, shortDescription string, longDescription string, kind string, noteID string) string { - return fmt.Sprintf(` - - resource "ibm_scc_si_note" "scc_si_note" { - account_id = "%s" - provider_id = "%s" - short_description = "%s" - long_description = "%s" - kind = "%s" - note_id = "%s" - reported_by { - id = "id" - title = "title" - url = "url" - } - card { - section = "section" - title = "title" - subtitle = "subtitle" - finding_note_names = ["providers/%s/notes/note123"] - elements { - kind = "BREAKDOWN" - text = "text" - default_time_range = "3d" - value_types { - finding_note_names = ["providers/%s/notes/note123"] - kind = "FINDING_COUNT" - text = "text" - } - } - } - } - `, accountID, providerID, shortDescription, longDescription, kind, noteID, providerID, providerID) -} - -func testAccCheckIBMSccSiNoteCardTimeSeriesBasic(accountID string, providerID string, shortDescription string, longDescription string, kind string, noteID string) string { - return fmt.Sprintf(` - - resource "ibm_scc_si_note" "scc_si_note" { - account_id = "%s" - provider_id = "%s" - short_description = "%s" - long_description = "%s" - kind = "%s" - note_id = "%s" - reported_by { - id = "id" - title = "title" - url = "url" - } - card { - section = "section" - title = "title" - subtitle = "subtitle" - finding_note_names = ["providers/%s/notes/note123"] - elements { - kind = "TIME_SERIES" - text = "text" - default_interval = "3d" - default_time_range = "3d" - value_types { - finding_note_names = ["providers/%s/notes/note123"] - kind = "FINDING_COUNT" - text = "text" - } - } - } - } - `, accountID, providerID, shortDescription, longDescription, kind, noteID, providerID, providerID) -} - -func testAccCheckIBMSccSiNoteConfigBasic(accountID string, providerID string, shortDescription string, longDescription string, kind string, noteID string) string { - return fmt.Sprintf(` - - resource "ibm_scc_si_note" "scc_si_note" { - account_id = "%s" - provider_id = "%s" - short_description = "%s" - long_description = "%s" - kind = "%s" - note_id = "%s" - reported_by { - id = "id" - title = "title" - url = "url" - } - finding { - severity = "LOW" - next_steps { - title = "title" - url = "url" - } - } - } - `, accountID, providerID, shortDescription, longDescription, kind, noteID) -} - -func testAccCheckIBMSccSiNoteConfig(accountID string, providerID string, shortDescription string, longDescription string, kind string, noteID string, shared string) string { - return fmt.Sprintf(` - - resource "ibm_scc_si_note" "scc_si_note" { - account_id = "%s" - provider_id = "%s" - short_description = "%s" - long_description = "%s" - kind = "%s" - note_id = "%s" - reported_by { - id = "id" - title = "title" - url = "url" - } - related_url { - label = "label" - url = "url" - } - shared = %s - finding { - severity = "LOW" - next_steps { - title = "title" - url = "url" - } - } - } - `, accountID, providerID, shortDescription, longDescription, kind, noteID, shared) -} - -func testAccCheckIBMSccSiNoteConfigInvalid(accountID string, providerID string, shortDescription string, longDescription string, kind string, noteID string) string { - return fmt.Sprintf(` - - resource "ibm_scc_si_note" "scc_si_note" { - account_id = "%s" - provider_id = "%s" - short_description = "%s" - long_description = "%s" - kind = "%s" - note_id = "%s" - reported_by { - id = "id" - title = "title" - url = "url" - } - related_url { - label = "label" - url = "url" - } - finding { - severity = "LOW" - next_steps { - title = "title" - url = "url" - } - } - kpi { - aggregation_type = "SUM" - } - card { - section = "section" - title = "title" - subtitle = "subtitle" - order = 1 - finding_note_names = [ "finding_note_names" ] - badge_text = "badge_text" - badge_image = "badge_image" - elements { - text = "text" - kind = "NUMERIC" - default_time_range = "1d" - value_type { - kind = "KPI" - kpi_note_name = "kpi_note_name" - text = "text" - finding_note_names = [ "finding_note_names" ] - } - value_types { - kind = "KPI" - kpi_note_name = "kpi_note_name" - text = "text" - finding_note_names = [ "finding_note_names" ] - } - default_interval = "default_interval" - } - } - section { - title = "title" - image = "image" - } - } - `, accountID, providerID, shortDescription, longDescription, kind, noteID) -} - -func testAccCheckIBMSccSiNoteConfigEmpty(accountID string, providerID string, shortDescription string, longDescription string, kind string, noteID string) string { - return fmt.Sprintf(` - - resource "ibm_scc_si_note" "scc_si_note" { - account_id = "%s" - provider_id = "%s" - short_description = "%s" - long_description = "%s" - kind = "%s" - note_id = "%s" - reported_by { - id = "id" - title = "title" - url = "url" - } - related_url { - label = "label" - url = "url" - } - } - `, accountID, providerID, shortDescription, longDescription, kind, noteID) -} - -func testAccCheckIBMSccSiNoteExists(n string, obj findingsv1.APINote) resource.TestCheckFunc { - - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[n] - if !ok { - return fmt.Errorf("Not found: %s", n) - } - - findingsClient, err := acc.TestAccProvider.Meta().(conns.ClientSession).FindingsV1() - if err != nil { - return err - } - - getNoteOptions := &findingsv1.GetNoteOptions{} - - parts, err := flex.SepIdParts(rs.Primary.ID, "/") - if err != nil { - return err - } - - findingsClient.AccountID = &parts[0] - - getNoteOptions.SetProviderID(parts[1]) - getNoteOptions.SetNoteID(parts[2]) - - apiNote, _, err := findingsClient.GetNote(getNoteOptions) - if err != nil { - return err - } - - obj = *apiNote - return nil - } -} - -func testAccCheckIBMSccSiNoteDestroy(s *terraform.State) error { - findingsClient, err := acc.TestAccProvider.Meta().(conns.ClientSession).FindingsV1() - if err != nil { - return err - } - for _, rs := range s.RootModule().Resources { - if rs.Type != "ibm_scc_si_note" { - continue - } - - getNoteOptions := &findingsv1.GetNoteOptions{} - - parts, err := flex.SepIdParts(rs.Primary.ID, "/") - if err != nil { - return err - } - - findingsClient.AccountID = &parts[0] - - getNoteOptions.SetProviderID(parts[1]) - getNoteOptions.SetNoteID(parts[2]) - - // Try to find the key - _, response, err := findingsClient.GetNote(getNoteOptions) - - if err == nil { - return fmt.Errorf("scc_si_note still exists: %s", rs.Primary.ID) - } else if response.StatusCode != 404 { - return fmt.Errorf("[ERROR] Error checking for scc_si_note (%s) has been destroyed: %s", rs.Primary.ID, err) - } - } - - return nil -} diff --git a/ibm/service/scc/resource_ibm_scc_si_occurrence.go b/ibm/service/scc/resource_ibm_scc_si_occurrence.go deleted file mode 100644 index bdbd5703b4..0000000000 --- a/ibm/service/scc/resource_ibm_scc_si_occurrence.go +++ /dev/null @@ -1,819 +0,0 @@ -// Copyright IBM Corp. 2021 All Rights Reserved. -// Licensed under the Mozilla Public License v2.0 - -package scc - -import ( - "context" - "fmt" - "log" - - "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" - "github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex" - "github.com/IBM-Cloud/terraform-provider-ibm/ibm/validate" - "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - - "github.com/IBM/go-sdk-core/v5/core" - "github.com/IBM/scc-go-sdk/findingsv1" -) - -func ResourceIBMSccSiOccurrence() *schema.Resource { - return &schema.Resource{ - CreateContext: resourceIBMSccSiOccurrenceCreate, - ReadContext: resourceIBMSccSiOccurrenceRead, - UpdateContext: resourceIBMSccSiOccurrenceUpdate, - DeleteContext: resourceIBMSccSiOccurrenceDelete, - Importer: &schema.ResourceImporter{}, - - Schema: map[string]*schema.Schema{ - "account_id": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, - Computed: true, - }, - "provider_id": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - Description: "Part of the parent. This field contains the provider ID. For example: providers/{provider_id}.", - }, - "note_name": { - Type: schema.TypeString, - Required: true, - Description: "An analysis note associated with this image, in the form \"{account_id}/providers/{provider_id}/notes/{note_id}\" This field can be used as a filter in list requests.", - }, - "kind": { - Type: schema.TypeString, - Required: true, - ValidateFunc: validate.InvokeValidator("ibm_scc_si_occurrence", "kind"), - Description: "The type of note. Use this field to filter notes and occurences by kind. - FINDING: The note and occurrence represent a finding. - KPI: The note and occurrence represent a KPI value. - CARD: The note represents a card showing findings and related metric values. - CARD_CONFIGURED: The note represents a card configured for a user account. - SECTION: The note represents a section in a dashboard.", - }, - "occurrence_id": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - Description: "The id of the occurrence.", - }, - "resource_url": { - Type: schema.TypeString, - Optional: true, - Description: "The unique URL of the resource, image or the container, for which the `Occurrence` applies. For example, https://gcr.io/provider/image@sha256:foo. This field can be used as a filter in list requests.", - }, - "remediation": { - Type: schema.TypeString, - Optional: true, - Description: "A description of actions that can be taken to remedy the `Note`.", - }, - "create_time": { - Type: schema.TypeString, - Computed: true, - Description: "Output only. The time this `Occurrence` was created.", - }, - "update_time": { - Type: schema.TypeString, - Computed: true, - Description: "Output only. The time this `Occurrence` was last updated.", - }, - "context": { - Type: schema.TypeList, - MaxItems: 1, - Optional: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "region": { - Type: schema.TypeString, - Optional: true, - Description: "The IBM Cloud region.", - }, - "resource_crn": { - Type: schema.TypeString, - Optional: true, - Description: "The resource CRN (e.g. certificate CRN, image CRN).", - }, - "resource_id": { - Type: schema.TypeString, - Optional: true, - Description: "The resource ID, in case the CRN is not available.", - }, - "resource_name": { - Type: schema.TypeString, - Optional: true, - Description: "The user-friendly resource name.", - }, - "resource_type": { - Type: schema.TypeString, - Optional: true, - Description: "The resource type name (e.g. Pod, Cluster, Certificate, Image).", - }, - "service_crn": { - Type: schema.TypeString, - Optional: true, - Description: "The service CRN (e.g. CertMgr Instance CRN).", - }, - "service_name": { - Type: schema.TypeString, - Optional: true, - Description: "The service name (e.g. CertMgr).", - }, - "environment_name": { - Type: schema.TypeString, - Optional: true, - Description: "The name of the environment the occurrence applies to.", - }, - "component_name": { - Type: schema.TypeString, - Optional: true, - Description: "The name of the component the occurrence applies to.", - }, - "toolchain_id": { - Type: schema.TypeString, - Optional: true, - Description: "The id of the toolchain the occurrence applies to.", - }, - }, - }, - }, - "finding": { - Type: schema.TypeList, - MaxItems: 1, - Optional: true, - Description: "Finding provides details about a finding occurrence.", - ExactlyOneOf: []string{"finding", "kpi"}, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "severity": { - Type: schema.TypeString, - Optional: true, - Description: "Note provider-assigned severity/impact ranking- LOW: Low Impact- MEDIUM: Medium Impact- HIGH: High Impact- CRITICAL: Critical Impact.", - }, - "certainty": { - Type: schema.TypeString, - Optional: true, - Description: "Note provider-assigned confidence on the validity of an occurrence- LOW: Low Certainty- MEDIUM: Medium Certainty- HIGH: High Certainty.", - }, - "next_steps": { - Type: schema.TypeList, - Optional: true, - Description: "Remediation steps for the issues reported in this finding. They override the note's next steps.", - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "title": { - Type: schema.TypeString, - Optional: true, - Description: "Title of this next step.", - }, - "url": { - Type: schema.TypeString, - Optional: true, - Description: "The URL associated to this next steps.", - }, - }, - }, - }, - "network_connection": { - Type: schema.TypeList, - MaxItems: 1, - Optional: true, - Description: "It provides details about a network connection.", - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "direction": { - Type: schema.TypeString, - Optional: true, - Description: "The direction of this network connection.", - }, - "protocol": { - Type: schema.TypeString, - Optional: true, - Description: "The protocol of this network connection.", - }, - "client": { - Type: schema.TypeList, - MaxItems: 1, - Optional: true, - Description: "It provides details about a socket address.", - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "address": { - Type: schema.TypeString, - Required: true, - Description: "The IP address of this socket address.", - }, - "port": { - Type: schema.TypeInt, - Optional: true, - Description: "The port number of this socket address.", - }, - }, - }, - }, - "server": { - Type: schema.TypeList, - MaxItems: 1, - Optional: true, - Description: "It provides details about a socket address.", - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "address": { - Type: schema.TypeString, - Required: true, - Description: "The IP address of this socket address.", - }, - "port": { - Type: schema.TypeInt, - Optional: true, - Description: "The port number of this socket address.", - }, - }, - }, - }, - }, - }, - }, - "data_transferred": { - Type: schema.TypeList, - MaxItems: 1, - Optional: true, - Description: "It provides details about data transferred between clients and servers.", - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "client_bytes": { - Type: schema.TypeInt, - Optional: true, - Description: "The number of client bytes transferred.", - }, - "server_bytes": { - Type: schema.TypeInt, - Optional: true, - Description: "The number of server bytes transferred.", - }, - "client_packets": { - Type: schema.TypeInt, - Optional: true, - Description: "The number of client packets transferred.", - }, - "server_packets": { - Type: schema.TypeInt, - Optional: true, - Description: "The number of server packets transferred.", - }, - }, - }, - }, - }, - }, - }, - "kpi": { - Type: schema.TypeList, - MaxItems: 1, - Optional: true, - Description: "Kpi provides details about a KPI occurrence.", - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "value": { - Type: schema.TypeFloat, - Required: true, - Description: "The value of this KPI.", - }, - "total": { - Type: schema.TypeFloat, - Optional: true, - Description: "The total value of this KPI.", - }, - }, - }, - }, - "replace_if_exists": { - Type: schema.TypeBool, - Optional: true, - Default: false, - Description: "When set to true, an existing occurrence is replaced rather than duplicated.", - }, - }, - } -} - -func ResourceIBMSccSiOccurrenceValidator() *validate.ResourceValidator { - validateSchema := make([]validate.ValidateSchema, 0) - validateSchema = append(validateSchema, - validate.ValidateSchema{ - Identifier: "kind", - ValidateFunctionIdentifier: validate.ValidateAllowedStringValue, - Type: validate.TypeString, - Required: true, - AllowedValues: "FINDING, KPI", - }, - ) - - resourceValidator := validate.ResourceValidator{ResourceName: "ibm_scc_si_occurrence", Schema: validateSchema} - return &resourceValidator -} - -func resourceIBMSccSiOccurrenceCreate(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - findingsClient, err := meta.(conns.ClientSession).FindingsV1() - if err != nil { - return diag.FromErr(err) - } - - userDetails, err := meta.(conns.ClientSession).BluemixUserDetails() - if err != nil { - return diag.FromErr(err) - } - - accountID := d.Get("account_id").(string) - log.Println(fmt.Sprintf("[DEBUG] using specified AccountID %s", accountID)) - if accountID == "" { - accountID = userDetails.UserAccount - log.Println(fmt.Sprintf("[DEBUG] AccountID not spedified, using %s", accountID)) - } - findingsClient.AccountID = &accountID - - createOccurrenceOptions := &findingsv1.CreateOccurrenceOptions{} - - createOccurrenceOptions.SetProviderID(d.Get("provider_id").(string)) - createOccurrenceOptions.SetNoteName(d.Get("note_name").(string)) - createOccurrenceOptions.SetKind(d.Get("kind").(string)) - createOccurrenceOptions.SetID(d.Get("occurrence_id").(string)) - if _, ok := d.GetOk("resource_url"); ok { - createOccurrenceOptions.SetResourceURL(d.Get("resource_url").(string)) - } - if _, ok := d.GetOk("remediation"); ok { - createOccurrenceOptions.SetRemediation(d.Get("remediation").(string)) - } - if _, ok := d.GetOk("context"); ok { - context := resourceIBMSccSiOccurrenceMapToContext(d.Get("context.0").(map[string]interface{})) - createOccurrenceOptions.SetContext(&context) - } - if _, ok := d.GetOk("finding"); ok { - finding := resourceIBMSccSiOccurrenceMapToFinding(d.Get("finding.0").(map[string]interface{})) - createOccurrenceOptions.SetFinding(&finding) - } - if _, ok := d.GetOk("kpi"); ok { - kpi := resourceIBMSccSiOccurrenceMapToKpi(d.Get("kpi.0").(map[string]interface{})) - createOccurrenceOptions.SetKpi(&kpi) - } - if _, ok := d.GetOk("replace_if_exists"); ok { - createOccurrenceOptions.SetReplaceIfExists(d.Get("replace_if_exists").(bool)) - } - - apiOccurrence, response, err := findingsClient.CreateOccurrenceWithContext(context, createOccurrenceOptions) - if err != nil { - log.Printf("[DEBUG] CreateOccurrenceWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("CreateOccurrenceWithContext failed %s\n%s", err, response)) - } - - d.SetId(fmt.Sprintf("%s/%s/%s", *findingsClient.AccountID, *createOccurrenceOptions.ProviderID, *apiOccurrence.ID)) - - return resourceIBMSccSiOccurrenceRead(context, d, meta) -} - -func resourceIBMSccSiOccurrenceMapToContext(contextMap map[string]interface{}) findingsv1.Context { - context := findingsv1.Context{} - - if contextMap["region"] != nil { - context.Region = core.StringPtr(contextMap["region"].(string)) - } - if contextMap["resource_crn"] != nil { - context.ResourceCRN = core.StringPtr(contextMap["resource_crn"].(string)) - } - if contextMap["resource_id"] != nil { - context.ResourceID = core.StringPtr(contextMap["resource_id"].(string)) - } - if contextMap["resource_name"] != nil { - context.ResourceName = core.StringPtr(contextMap["resource_name"].(string)) - } - if contextMap["resource_type"] != nil { - context.ResourceType = core.StringPtr(contextMap["resource_type"].(string)) - } - if contextMap["service_crn"] != nil { - context.ServiceCRN = core.StringPtr(contextMap["service_crn"].(string)) - } - if contextMap["service_name"] != nil { - context.ServiceName = core.StringPtr(contextMap["service_name"].(string)) - } - if contextMap["environment_name"] != nil { - context.EnvironmentName = core.StringPtr(contextMap["environment_name"].(string)) - } - if contextMap["component_name"] != nil { - context.ComponentName = core.StringPtr(contextMap["component_name"].(string)) - } - if contextMap["toolchain_id"] != nil { - context.ToolchainID = core.StringPtr(contextMap["toolchain_id"].(string)) - } - - return context -} - -func resourceIBMSccSiOccurrenceMapToFinding(findingMap map[string]interface{}) findingsv1.Finding { - finding := findingsv1.Finding{} - - if findingMap["severity"] != nil { - finding.Severity = core.StringPtr(findingMap["severity"].(string)) - } - if findingMap["certainty"] != nil { - finding.Certainty = core.StringPtr(findingMap["certainty"].(string)) - } - if findingMap["next_steps"] != nil { - nextSteps := []findingsv1.RemediationStep{} - for _, nextStepsItem := range findingMap["next_steps"].([]interface{}) { - nextStepsItemModel := resourceIBMSccSiOccurrenceMapToRemediationStep(nextStepsItem.(map[string]interface{})) - nextSteps = append(nextSteps, nextStepsItemModel) - } - finding.NextSteps = nextSteps - } - if findingMap["network_connection"] != nil { - if len(findingMap["network_connection"].([]interface{})) > 0 { - networkConnection := resourceIBMSccSiOccurrenceMapToNetworkConnection(findingMap["network_connection"].([]interface{})[0].(map[string]interface{})) - finding.NetworkConnection = &networkConnection - } - } - if findingMap["data_transferred"] != nil { - if len(findingMap["data_transferred"].([]interface{})) > 0 { - dataTransferred := resourceIBMSccSiOccurrenceMapToDataTransferred(findingMap["data_transferred"].([]interface{})[0].(map[string]interface{})) - finding.DataTransferred = &dataTransferred - } - } - - return finding -} - -func resourceIBMSccSiOccurrenceMapToRemediationStep(remediationStepMap map[string]interface{}) findingsv1.RemediationStep { - remediationStep := findingsv1.RemediationStep{} - - if remediationStepMap["title"] != nil { - remediationStep.Title = core.StringPtr(remediationStepMap["title"].(string)) - } - if remediationStepMap["url"] != nil { - remediationStep.URL = core.StringPtr(remediationStepMap["url"].(string)) - } - - return remediationStep -} - -func resourceIBMSccSiOccurrenceMapToNetworkConnection(networkConnectionMap map[string]interface{}) findingsv1.NetworkConnection { - networkConnection := findingsv1.NetworkConnection{} - - if networkConnectionMap["direction"] != nil { - networkConnection.Direction = core.StringPtr(networkConnectionMap["direction"].(string)) - } - if networkConnectionMap["protocol"] != nil { - networkConnection.Protocol = core.StringPtr(networkConnectionMap["protocol"].(string)) - } - if networkConnectionMap["client"] != nil { - client := resourceIBMSccSiOccurrenceMapToSocketAddress(networkConnectionMap["client"].([]interface{})[0].(map[string]interface{})) - networkConnection.Client = &client - } - if networkConnectionMap["server"] != nil { - server := resourceIBMSccSiOccurrenceMapToSocketAddress(networkConnectionMap["server"].([]interface{})[0].(map[string]interface{})) - networkConnection.Server = &server - } - - return networkConnection -} - -func resourceIBMSccSiOccurrenceMapToSocketAddress(socketAddressMap map[string]interface{}) findingsv1.SocketAddress { - socketAddress := findingsv1.SocketAddress{} - - socketAddress.Address = core.StringPtr(socketAddressMap["address"].(string)) - if socketAddressMap["port"] != nil { - socketAddress.Port = core.Int64Ptr(int64(socketAddressMap["port"].(int))) - } - - return socketAddress -} - -func resourceIBMSccSiOccurrenceMapToDataTransferred(dataTransferredMap map[string]interface{}) findingsv1.DataTransferred { - dataTransferred := findingsv1.DataTransferred{} - - if dataTransferredMap["client_bytes"] != nil { - dataTransferred.ClientBytes = core.Int64Ptr(int64(dataTransferredMap["client_bytes"].(int))) - } - if dataTransferredMap["server_bytes"] != nil { - dataTransferred.ServerBytes = core.Int64Ptr(int64(dataTransferredMap["server_bytes"].(int))) - } - if dataTransferredMap["client_packets"] != nil { - dataTransferred.ClientPackets = core.Int64Ptr(int64(dataTransferredMap["client_packets"].(int))) - } - if dataTransferredMap["server_packets"] != nil { - dataTransferred.ServerPackets = core.Int64Ptr(int64(dataTransferredMap["server_packets"].(int))) - } - - return dataTransferred -} - -func resourceIBMSccSiOccurrenceMapToKpi(kpiMap map[string]interface{}) findingsv1.Kpi { - kpi := findingsv1.Kpi{} - - kpi.Value = core.Float64Ptr(kpiMap["value"].(float64)) - if kpiMap["total"] != nil { - kpi.Total = core.Float64Ptr(kpiMap["total"].(float64)) - } - - return kpi -} - -func resourceIBMSccSiOccurrenceRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - findingsClient, err := meta.(conns.ClientSession).FindingsV1() - if err != nil { - return diag.FromErr(err) - } - - getOccurrenceOptions := &findingsv1.GetOccurrenceOptions{} - - parts, err := flex.SepIdParts(d.Id(), "/") - if err != nil { - return diag.FromErr(err) - } - - findingsClient.AccountID = &parts[0] - - d.Set("account_id", &parts[0]) - - getOccurrenceOptions.SetProviderID(parts[1]) - getOccurrenceOptions.SetOccurrenceID(parts[2]) - - apiOccurrence, response, err := findingsClient.GetOccurrenceWithContext(context, getOccurrenceOptions) - if err != nil { - if response != nil && response.StatusCode == 404 { - d.SetId("") - return nil - } - log.Printf("[DEBUG] GetOccurrenceWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("GetOccurrenceWithContext failed %s\n%s", err, response)) - } - - if err = d.Set("provider_id", getOccurrenceOptions.ProviderID); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting provider_id: %s", err)) - } - // TODO: handle argument of type bool - if err = d.Set("note_name", apiOccurrence.NoteName); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting note_name: %s", err)) - } - if err = d.Set("kind", apiOccurrence.Kind); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting kind: %s", err)) - } - if err = d.Set("occurrence_id", apiOccurrence.ID); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting occurrence_id: %s", err)) - } - if err = d.Set("resource_url", apiOccurrence.ResourceURL); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting resource_url: %s", err)) - } - if err = d.Set("remediation", apiOccurrence.Remediation); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting remediation: %s", err)) - } - if err = d.Set("create_time", flex.DateTimeToString(apiOccurrence.CreateTime)); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting create_time: %s", err)) - } - if err = d.Set("update_time", flex.DateTimeToString(apiOccurrence.UpdateTime)); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting update_time: %s", err)) - } - if apiOccurrence.Context != nil { - contextMap := resourceIBMSccSiOccurrenceContextToMap(*apiOccurrence.Context) - if len(contextMap) > 0 { - if err = d.Set("context", []map[string]interface{}{contextMap}); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting context: %s", err)) - } - } - } - if apiOccurrence.Finding != nil { - findingMap := resourceIBMSccSiOccurrenceFindingToMap(*apiOccurrence.Finding) - if err = d.Set("finding", []map[string]interface{}{findingMap}); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting finding: %s", err)) - } - } - if apiOccurrence.Kpi != nil { - kpiMap := resourceIBMSccSiOccurrenceKpiToMap(*apiOccurrence.Kpi) - if err = d.Set("kpi", []map[string]interface{}{kpiMap}); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting kpi: %s", err)) - } - } - if _, ok := d.GetOk("replace_if_exists"); ok { - replaceIfExists := d.Get("replace_if_exists").(bool) - d.Set("replace_if_exists", replaceIfExists) - } - - return nil -} - -func resourceIBMSccSiOccurrenceContextToMap(context findingsv1.Context) map[string]interface{} { - contextMap := map[string]interface{}{} - - if context.Region != nil { - contextMap["region"] = context.Region - } - if context.ResourceCRN != nil { - contextMap["resource_crn"] = context.ResourceCRN - } - if context.ResourceID != nil { - contextMap["resource_id"] = context.ResourceID - } - if context.ResourceName != nil { - contextMap["resource_name"] = context.ResourceName - } - if context.ResourceType != nil { - contextMap["resource_type"] = context.ResourceType - } - if context.ServiceCRN != nil { - contextMap["service_crn"] = context.ServiceCRN - } - if context.ServiceName != nil { - contextMap["service_name"] = context.ServiceName - } - if context.EnvironmentName != nil { - contextMap["environment_name"] = context.EnvironmentName - } - if context.ComponentName != nil { - contextMap["component_name"] = context.ComponentName - } - if context.ToolchainID != nil { - contextMap["toolchain_id"] = context.ToolchainID - } - - return contextMap -} - -func resourceIBMSccSiOccurrenceFindingToMap(finding findingsv1.Finding) map[string]interface{} { - findingMap := map[string]interface{}{} - - if finding.Severity != nil { - findingMap["severity"] = finding.Severity - } - if finding.Certainty != nil { - findingMap["certainty"] = finding.Certainty - } - if finding.NextSteps != nil { - nextSteps := []map[string]interface{}{} - for _, nextStepsItem := range finding.NextSteps { - nextStepsItemMap := resourceIBMSccSiOccurrenceRemediationStepToMap(nextStepsItem) - nextSteps = append(nextSteps, nextStepsItemMap) - // TODO: handle NextSteps of type TypeList -- list of non-primitive, not model items - } - findingMap["next_steps"] = nextSteps - } - if finding.NetworkConnection != nil { - NetworkConnectionMap := resourceIBMSccSiOccurrenceNetworkConnectionToMap(*finding.NetworkConnection) - findingMap["network_connection"] = []map[string]interface{}{NetworkConnectionMap} - } - if finding.DataTransferred != nil { - DataTransferredMap := resourceIBMSccSiOccurrenceDataTransferredToMap(*finding.DataTransferred) - findingMap["data_transferred"] = []map[string]interface{}{DataTransferredMap} - } - - return findingMap -} - -func resourceIBMSccSiOccurrenceRemediationStepToMap(remediationStep findingsv1.RemediationStep) map[string]interface{} { - remediationStepMap := map[string]interface{}{} - - if remediationStep.Title != nil { - remediationStepMap["title"] = remediationStep.Title - } - if remediationStep.URL != nil { - remediationStepMap["url"] = remediationStep.URL - } - - return remediationStepMap -} - -func resourceIBMSccSiOccurrenceNetworkConnectionToMap(networkConnection findingsv1.NetworkConnection) map[string]interface{} { - networkConnectionMap := map[string]interface{}{} - - if networkConnection.Direction != nil { - networkConnectionMap["direction"] = networkConnection.Direction - } - if networkConnection.Protocol != nil { - networkConnectionMap["protocol"] = networkConnection.Protocol - } - if networkConnection.Client != nil { - ClientMap := resourceIBMSccSiOccurrenceSocketAddressToMap(*networkConnection.Client) - networkConnectionMap["client"] = []map[string]interface{}{ClientMap} - } - if networkConnection.Server != nil { - ServerMap := resourceIBMSccSiOccurrenceSocketAddressToMap(*networkConnection.Server) - networkConnectionMap["server"] = []map[string]interface{}{ServerMap} - } - - return networkConnectionMap -} - -func resourceIBMSccSiOccurrenceSocketAddressToMap(socketAddress findingsv1.SocketAddress) map[string]interface{} { - socketAddressMap := map[string]interface{}{} - - socketAddressMap["address"] = socketAddress.Address - if socketAddress.Port != nil { - socketAddressMap["port"] = flex.IntValue(socketAddress.Port) - } - - return socketAddressMap -} - -func resourceIBMSccSiOccurrenceDataTransferredToMap(dataTransferred findingsv1.DataTransferred) map[string]interface{} { - dataTransferredMap := map[string]interface{}{} - - if dataTransferred.ClientBytes != nil { - dataTransferredMap["client_bytes"] = flex.IntValue(dataTransferred.ClientBytes) - } - if dataTransferred.ServerBytes != nil { - dataTransferredMap["server_bytes"] = flex.IntValue(dataTransferred.ServerBytes) - } - if dataTransferred.ClientPackets != nil { - dataTransferredMap["client_packets"] = flex.IntValue(dataTransferred.ClientPackets) - } - if dataTransferred.ServerPackets != nil { - dataTransferredMap["server_packets"] = flex.IntValue(dataTransferred.ServerPackets) - } - - return dataTransferredMap -} - -func resourceIBMSccSiOccurrenceKpiToMap(kpi findingsv1.Kpi) map[string]interface{} { - kpiMap := map[string]interface{}{} - - kpiMap["value"] = kpi.Value - if kpi.Total != nil { - kpiMap["total"] = kpi.Total - } - - return kpiMap -} - -func resourceIBMSccSiOccurrenceUpdate(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - findingsClient, err := meta.(conns.ClientSession).FindingsV1() - if err != nil { - return diag.FromErr(err) - } - - updateOccurrenceOptions := &findingsv1.UpdateOccurrenceOptions{} - - parts, err := flex.SepIdParts(d.Id(), "/") - if err != nil { - return diag.FromErr(err) - } - - findingsClient.AccountID = &parts[0] - - d.Set("account_id", parts[0]) - - updateOccurrenceOptions.SetProviderID(parts[1]) - updateOccurrenceOptions.SetOccurrenceID(parts[2]) - updateOccurrenceOptions.SetProviderID(d.Get("provider_id").(string)) - updateOccurrenceOptions.SetNoteName(d.Get("note_name").(string)) - updateOccurrenceOptions.SetKind(d.Get("kind").(string)) - updateOccurrenceOptions.SetID(d.Get("occurrence_id").(string)) - if _, ok := d.GetOk("resource_url"); ok { - updateOccurrenceOptions.SetResourceURL(d.Get("resource_url").(string)) - } - if _, ok := d.GetOk("remediation"); ok { - updateOccurrenceOptions.SetRemediation(d.Get("remediation").(string)) - } - if _, ok := d.GetOk("context"); ok { - context := resourceIBMSccSiOccurrenceMapToContext(d.Get("context.0").(map[string]interface{})) - updateOccurrenceOptions.SetContext(&context) - } - if _, ok := d.GetOk("finding"); ok { - finding := resourceIBMSccSiOccurrenceMapToFinding(d.Get("finding.0").(map[string]interface{})) - updateOccurrenceOptions.SetFinding(&finding) - } - if _, ok := d.GetOk("kpi"); ok { - kpi := resourceIBMSccSiOccurrenceMapToKpi(d.Get("kpi.0").(map[string]interface{})) - updateOccurrenceOptions.SetKpi(&kpi) - } - _, response, err := findingsClient.UpdateOccurrenceWithContext(context, updateOccurrenceOptions) - if err != nil { - log.Printf("[DEBUG] UpdateOccurrenceWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("UpdateOccurrenceWithContext failed %s\n%s", err, response)) - } - - return resourceIBMSccSiOccurrenceRead(context, d, meta) -} - -func resourceIBMSccSiOccurrenceDelete(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - findingsClient, err := meta.(conns.ClientSession).FindingsV1() - if err != nil { - return diag.FromErr(err) - } - - deleteOccurrenceOptions := &findingsv1.DeleteOccurrenceOptions{} - - parts, err := flex.SepIdParts(d.Id(), "/") - if err != nil { - return diag.FromErr(err) - } - - findingsClient.AccountID = &parts[0] - - deleteOccurrenceOptions.SetProviderID(parts[1]) - deleteOccurrenceOptions.SetOccurrenceID(parts[2]) - - response, err := findingsClient.DeleteOccurrenceWithContext(context, deleteOccurrenceOptions) - if err != nil { - log.Printf("[DEBUG] DeleteOccurrenceWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("DeleteOccurrenceWithContext failed %s\n%s", err, response)) - } - - d.SetId("") - - return nil -} diff --git a/ibm/service/scc/resource_ibm_scc_si_occurrence_test.go b/ibm/service/scc/resource_ibm_scc_si_occurrence_test.go deleted file mode 100644 index c8fef19796..0000000000 --- a/ibm/service/scc/resource_ibm_scc_si_occurrence_test.go +++ /dev/null @@ -1,662 +0,0 @@ -// Copyright IBM Corp. 2021 All Rights Reserved. -// Licensed under the Mozilla Public License v2.0 - -package scc_test - -import ( - "fmt" - "regexp" - "testing" - - acc "github.com/IBM-Cloud/terraform-provider-ibm/ibm/acctest" - "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" - "github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex" - - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" - - "github.com/IBM/scc-go-sdk/findingsv1" -) - -func TestAccIBMSccSiOccurrenceBasic(t *testing.T) { - var conf findingsv1.APIOccurrence - kind := "FINDING" - occurrenceID := fmt.Sprintf("tf_occurrence_id_%d", acctest.RandIntRange(10, 100)) - - kindUpdate := kind - providerID := fmt.Sprintf("tf_provider_id_%d", acctest.RandIntRange(10, 100)) - noteID := fmt.Sprintf("tf_note_id_%d", acctest.RandIntRange(10, 100)) - noteIdUpdate := noteID - occurrenceIDUpdate := occurrenceID - accountID := acc.Scc_si_account - - noteName := fmt.Sprintf("%s/providers/%s/notes/%s", accountID, providerID, noteID) - - resource.Test(t, resource.TestCase{ - PreCheck: func() { acc.TestAccPreCheck(t) }, - Providers: acc.TestAccProviders, - CheckDestroy: testAccCheckIBMSccSiOccurrenceDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCheckIBMSccSiOccurrenceConfigBasic(providerID, noteID, accountID, kind, occurrenceID), - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckIBMSccSiOccurrenceExists("ibm_scc_si_occurrence.scc_si_occurrence", conf), - resource.TestCheckResourceAttr("ibm_scc_si_occurrence.scc_si_occurrence", "provider_id", providerID), - resource.TestCheckResourceAttr("ibm_scc_si_occurrence.scc_si_occurrence", "note_name", noteName), - resource.TestCheckResourceAttr("ibm_scc_si_occurrence.scc_si_occurrence", "kind", kind), - resource.TestCheckResourceAttr("ibm_scc_si_occurrence.scc_si_occurrence", "occurrence_id", occurrenceID), - ), - }, - { - Config: testAccCheckIBMSccSiOccurrenceConfigBasic(providerID, noteIdUpdate, accountID, kindUpdate, occurrenceIDUpdate), - Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr("ibm_scc_si_occurrence.scc_si_occurrence", "provider_id", providerID), - resource.TestCheckResourceAttr("ibm_scc_si_occurrence.scc_si_occurrence", "note_name", noteName), - resource.TestCheckResourceAttr("ibm_scc_si_occurrence.scc_si_occurrence", "kind", kindUpdate), - resource.TestCheckResourceAttr("ibm_scc_si_occurrence.scc_si_occurrence", "occurrence_id", occurrenceIDUpdate), - ), - }, - }, - }) -} - -func TestAccIBMSccSiOccurrenceKpiBasic(t *testing.T) { - var conf findingsv1.APIOccurrence - kind := "KPI" - occurrenceID := fmt.Sprintf("tf_occurrence_id_%d", acctest.RandIntRange(10, 100)) - - kindUpdate := kind - providerID := fmt.Sprintf("tf_provider_id_%d", acctest.RandIntRange(10, 100)) - noteID := fmt.Sprintf("tf_note_id_%d", acctest.RandIntRange(10, 100)) - noteIdUpdate := noteID - occurrenceIDUpdate := occurrenceID - accountID := acc.Scc_si_account - - noteName := fmt.Sprintf("%s/providers/%s/notes/%s", accountID, providerID, noteID) - - resource.Test(t, resource.TestCase{ - PreCheck: func() { acc.TestAccPreCheck(t) }, - Providers: acc.TestAccProviders, - CheckDestroy: testAccCheckIBMSccSiOccurrenceDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCheckIBMSccSiOccurrenceConfigKpiBasic(providerID, noteID, accountID, kind, occurrenceID), - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckIBMSccSiOccurrenceExists("ibm_scc_si_occurrence.scc_si_occurrence", conf), - resource.TestCheckResourceAttr("ibm_scc_si_occurrence.scc_si_occurrence", "provider_id", providerID), - resource.TestCheckResourceAttr("ibm_scc_si_occurrence.scc_si_occurrence", "note_name", noteName), - resource.TestCheckResourceAttr("ibm_scc_si_occurrence.scc_si_occurrence", "kind", kind), - resource.TestCheckResourceAttr("ibm_scc_si_occurrence.scc_si_occurrence", "occurrence_id", occurrenceID), - ), - }, - { - Config: testAccCheckIBMSccSiOccurrenceConfigKpiBasic(providerID, noteIdUpdate, accountID, kindUpdate, occurrenceIDUpdate), - Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr("ibm_scc_si_occurrence.scc_si_occurrence", "provider_id", providerID), - resource.TestCheckResourceAttr("ibm_scc_si_occurrence.scc_si_occurrence", "note_name", noteName), - resource.TestCheckResourceAttr("ibm_scc_si_occurrence.scc_si_occurrence", "kind", kindUpdate), - resource.TestCheckResourceAttr("ibm_scc_si_occurrence.scc_si_occurrence", "occurrence_id", occurrenceIDUpdate), - ), - }, - }, - }) -} - -func TestAccIBMSccSiOccurrenceFindingNoteOccurrenceKPI(t *testing.T) { - kind := "FINDING" - occurrenceID := fmt.Sprintf("tf_occurrence_id_%d", acctest.RandIntRange(10, 100)) - - providerID := fmt.Sprintf("tf_provider_id_%d", acctest.RandIntRange(10, 100)) - noteID := fmt.Sprintf("tf_note_id_%d", acctest.RandIntRange(10, 100)) - - accountID := acc.Scc_si_account - - resource.Test(t, resource.TestCase{ - PreCheck: func() { acc.TestAccPreCheck(t) }, - Providers: acc.TestAccProviders, - CheckDestroy: testAccCheckIBMSccSiOccurrenceDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCheckIBMSccSiOccurrenceConfigFindingNoteOccurrenceKPI(providerID, noteID, accountID, kind, occurrenceID), - ExpectError: regexp.MustCompile("Missing field 'finding' for kind 'FINDING"), - }, - }, - }) -} - -func TestAccIBMSccSiOccurrenceKPINoteOccurrenceFinding(t *testing.T) { - kind := "KPI" - occurrenceID := fmt.Sprintf("tf_occurrence_id_%d", acctest.RandIntRange(10, 100)) - - providerID := fmt.Sprintf("tf_provider_id_%d", acctest.RandIntRange(10, 100)) - noteID := fmt.Sprintf("tf_note_id_%d", acctest.RandIntRange(10, 100)) - - accountID := acc.Scc_si_account - - resource.Test(t, resource.TestCase{ - PreCheck: func() { acc.TestAccPreCheck(t) }, - Providers: acc.TestAccProviders, - CheckDestroy: testAccCheckIBMSccSiOccurrenceDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCheckIBMSccSiOccurrenceConfigKPINoteOccurrenceFinding(providerID, noteID, accountID, kind, occurrenceID), - ExpectError: regexp.MustCompile("Missing field 'kpi' for kind 'KPI'"), - }, - }, - }) -} - -func TestAccIBMSccSiOccurrenceValidNoteNoOccurrence(t *testing.T) { - kind := "KPI" - occurrenceID := fmt.Sprintf("tf_occurrence_id_%d", acctest.RandIntRange(10, 100)) - - providerID := fmt.Sprintf("tf_provider_id_%d", acctest.RandIntRange(10, 100)) - noteID := fmt.Sprintf("tf_note_id_%d", acctest.RandIntRange(10, 100)) - - accountID := acc.Scc_si_account - - resource.Test(t, resource.TestCase{ - PreCheck: func() { acc.TestAccPreCheck(t) }, - Providers: acc.TestAccProviders, - CheckDestroy: testAccCheckIBMSccSiOccurrenceDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCheckIBMSccSiOccurrenceConfigValidNoteNoOccurrence(providerID, noteID, accountID, kind, occurrenceID), - ExpectError: regexp.MustCompile("one of `finding,kpi` must be specified"), - }, - }, - }) -} - -func TestAccIBMSccSiOccurrenceValidNoteKpiFindingOccurrence(t *testing.T) { - kind := "KPI" - occurrenceID := fmt.Sprintf("tf_occurrence_id_%d", acctest.RandIntRange(10, 100)) - - providerID := fmt.Sprintf("tf_provider_id_%d", acctest.RandIntRange(10, 100)) - noteID := fmt.Sprintf("tf_note_id_%d", acctest.RandIntRange(10, 100)) - - accountID := acc.Scc_si_account - - resource.Test(t, resource.TestCase{ - PreCheck: func() { acc.TestAccPreCheck(t) }, - Providers: acc.TestAccProviders, - CheckDestroy: testAccCheckIBMSccSiOccurrenceDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCheckIBMSccSiOccurrenceConfigValidNoteKpiFindingOccurrence(providerID, noteID, accountID, kind, occurrenceID), - ExpectError: regexp.MustCompile("only one of `finding,kpi` can be specified"), - }, - }, - }) -} -func TestAccIBMSccSiOccurrenceAllArgs(t *testing.T) { - var conf findingsv1.APIOccurrence - providerID := fmt.Sprintf("tf_provider_id_%d", acctest.RandIntRange(10, 100)) - noteID := fmt.Sprintf("tf_note_id_%d", acctest.RandIntRange(10, 100)) - kind := "FINDING" - occurrenceID := fmt.Sprintf("tf_occurrence_id_%d", acctest.RandIntRange(10, 100)) - resourceURL := fmt.Sprintf("tf_resource_url_%d", acctest.RandIntRange(10, 100)) - remediation := fmt.Sprintf("tf_remediation_%d", acctest.RandIntRange(10, 100)) - replaceIfExists := "false" - noteIdUpdate := noteID - kindUpdate := kind - occurrenceIDUpdate := occurrenceID - resourceURLUpdate := fmt.Sprintf("tf_resource_url_%d", acctest.RandIntRange(10, 100)) - remediationUpdate := fmt.Sprintf("tf_remediation_%d", acctest.RandIntRange(10, 100)) - replaceIfExistsUpdate := "true" - accountID := acc.Scc_si_account - - noteName := fmt.Sprintf("%s/providers/%s/notes/%s", accountID, providerID, noteID) - - resource.Test(t, resource.TestCase{ - PreCheck: func() { acc.TestAccPreCheck(t) }, - Providers: acc.TestAccProviders, - CheckDestroy: testAccCheckIBMSccSiOccurrenceDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCheckIBMSccSiOccurrenceConfig(accountID, providerID, noteID, kind, occurrenceID, resourceURL, remediation, replaceIfExists), - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckIBMSccSiOccurrenceExists("ibm_scc_si_occurrence.scc_si_occurrence", conf), - resource.TestCheckResourceAttr("ibm_scc_si_occurrence.scc_si_occurrence", "provider_id", providerID), - resource.TestCheckResourceAttr("ibm_scc_si_occurrence.scc_si_occurrence", "note_name", noteName), - resource.TestCheckResourceAttr("ibm_scc_si_occurrence.scc_si_occurrence", "kind", kind), - resource.TestCheckResourceAttr("ibm_scc_si_occurrence.scc_si_occurrence", "occurrence_id", occurrenceID), - resource.TestCheckResourceAttr("ibm_scc_si_occurrence.scc_si_occurrence", "resource_url", resourceURL), - resource.TestCheckResourceAttr("ibm_scc_si_occurrence.scc_si_occurrence", "remediation", remediation), - ), - }, - { - Config: testAccCheckIBMSccSiOccurrenceConfig(accountID, providerID, noteIdUpdate, kindUpdate, occurrenceIDUpdate, resourceURLUpdate, remediationUpdate, replaceIfExistsUpdate), - Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr("ibm_scc_si_occurrence.scc_si_occurrence", "provider_id", providerID), - resource.TestCheckResourceAttr("ibm_scc_si_occurrence.scc_si_occurrence", "note_name", noteName), - resource.TestCheckResourceAttr("ibm_scc_si_occurrence.scc_si_occurrence", "kind", kindUpdate), - resource.TestCheckResourceAttr("ibm_scc_si_occurrence.scc_si_occurrence", "occurrence_id", occurrenceIDUpdate), - resource.TestCheckResourceAttr("ibm_scc_si_occurrence.scc_si_occurrence", "resource_url", resourceURLUpdate), - resource.TestCheckResourceAttr("ibm_scc_si_occurrence.scc_si_occurrence", "remediation", remediationUpdate), - ), - }, - { - ResourceName: "ibm_scc_si_occurrence.scc_si_occurrence", - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "replace_if_exists", - }, - }, - }, - }) -} - -func testAccCheckIBMSccSiOccurrenceConfigFindingNoteOccurrenceKPI(providerID string, noteID string, accountID string, kind string, occurrenceID string) string { - return fmt.Sprintf(` - - resource "ibm_scc_si_note" "finding" { - account_id = "%s" - provider_id = "%s" - short_description = "Security Threat" - long_description = "Security Threat found in your account" - kind = "FINDING" - note_id = "%s" - reported_by { - id = "scc-si-terraform" - title = "SCC SI Terraform" - url = "https://cloud.ibm.com" - } - finding { - severity = "LOW" - next_steps { - title = "Security Threat" - url = "https://cloud.ibm.com/security-compliance/findings" - } - } - } - - resource "ibm_scc_si_occurrence" "scc_si_occurrence" { - provider_id = "${ibm_scc_si_note.finding.provider_id}" - note_name = "%s/providers/${ibm_scc_si_note.finding.provider_id}/notes/${ibm_scc_si_note.finding.note_id}" - kind = "%s" - occurrence_id = "%s" - kpi { - value = 1.0 - total = 1.0 - } - } - `, accountID, providerID, noteID, accountID, kind, occurrenceID) -} - -func testAccCheckIBMSccSiOccurrenceConfigKPINoteOccurrenceFinding(providerID string, noteID string, accountID string, kind string, occurrenceID string) string { - return fmt.Sprintf(` - - resource "ibm_scc_si_note" "finding" { - account_id = "%s" - provider_id = "%s" - short_description = "Security Threat" - long_description = "Security Threat found in your account" - kind = "KPI" - note_id = "%s" - reported_by { - id = "scc-si-terraform" - title = "SCC SI Terraform" - url = "https://cloud.ibm.com" - } - kpi { - aggregation_type = "SUM" - } - } - - resource "ibm_scc_si_occurrence" "scc_si_occurrence" { - provider_id = "${ibm_scc_si_note.finding.provider_id}" - note_name = "%s/providers/${ibm_scc_si_note.finding.provider_id}/notes/${ibm_scc_si_note.finding.note_id}" - kind = "%s" - occurrence_id = "%s" - finding { - severity = "LOW" - certainty = "LOW" - next_steps { - title = "title" - url = "url" - } - network_connection { - direction = "direction" - protocol = "protocol" - client { - address = "address" - port = 1 - } - server { - address = "address" - port = 1 - } - } - data_transferred { - client_bytes = 1 - server_bytes = 1 - client_packets = 1 - server_packets = 1 - } - } - } - `, accountID, providerID, noteID, accountID, kind, occurrenceID) -} - -func testAccCheckIBMSccSiOccurrenceConfigValidNoteNoOccurrence(providerID string, noteID string, accountID string, kind string, occurrenceID string) string { - return fmt.Sprintf(` - - resource "ibm_scc_si_note" "finding" { - account_id = "%s" - provider_id = "%s" - short_description = "Security Threat" - long_description = "Security Threat found in your account" - kind = "KPI" - note_id = "%s" - reported_by { - id = "scc-si-terraform" - title = "SCC SI Terraform" - url = "https://cloud.ibm.com" - } - kpi { - aggregation_type = "SUM" - } - } - - resource "ibm_scc_si_occurrence" "scc_si_occurrence" { - provider_id = "${ibm_scc_si_note.finding.provider_id}" - note_name = "%s/providers/${ibm_scc_si_note.finding.provider_id}/notes/${ibm_scc_si_note.finding.note_id}" - kind = "%s" - occurrence_id = "%s" - } - `, accountID, providerID, noteID, accountID, kind, occurrenceID) -} - -func testAccCheckIBMSccSiOccurrenceConfigValidNoteKpiFindingOccurrence(providerID string, noteID string, accountID string, kind string, occurrenceID string) string { - return fmt.Sprintf(` - - resource "ibm_scc_si_note" "finding" { - account_id = "%s" - provider_id = "%s" - short_description = "Security Threat" - long_description = "Security Threat found in your account" - kind = "KPI" - note_id = "%s" - reported_by { - id = "scc-si-terraform" - title = "SCC SI Terraform" - url = "https://cloud.ibm.com" - } - kpi { - aggregation_type = "SUM" - } - } - - resource "ibm_scc_si_occurrence" "scc_si_occurrence" { - provider_id = "${ibm_scc_si_note.finding.provider_id}" - note_name = "%s/providers/${ibm_scc_si_note.finding.provider_id}/notes/${ibm_scc_si_note.finding.note_id}" - kind = "%s" - occurrence_id = "%s" - kpi { - value = 1.0 - total = 1.0 - } - finding { - severity = "LOW" - certainty = "LOW" - next_steps { - title = "title" - url = "url" - } - network_connection { - direction = "direction" - protocol = "protocol" - client { - address = "address" - port = 1 - } - server { - address = "address" - port = 1 - } - } - data_transferred { - client_bytes = 1 - server_bytes = 1 - client_packets = 1 - server_packets = 1 - } - } - } - `, accountID, providerID, noteID, accountID, kind, occurrenceID) -} - -func testAccCheckIBMSccSiOccurrenceConfigKpiBasic(providerID string, noteID string, accountID string, kind string, occurrenceID string) string { - return fmt.Sprintf(` - - resource "ibm_scc_si_note" "finding" { - account_id = "%s" - provider_id = "%s" - short_description = "Security Threat" - long_description = "Security Threat found in your account" - kind = "KPI" - note_id = "%s" - reported_by { - id = "scc-si-terraform" - title = "SCC SI Terraform" - url = "https://cloud.ibm.com" - } - kpi { - aggregation_type = "SUM" - } - } - - resource "ibm_scc_si_occurrence" "scc_si_occurrence" { - provider_id = "${ibm_scc_si_note.finding.provider_id}" - note_name = "%s/providers/${ibm_scc_si_note.finding.provider_id}/notes/${ibm_scc_si_note.finding.note_id}" - kind = "%s" - occurrence_id = "%s" - kpi { - value = 1.0 - total = 1.0 - } - } - `, accountID, providerID, noteID, accountID, kind, occurrenceID) -} - -func testAccCheckIBMSccSiOccurrenceConfigBasic(providerID string, noteID string, accountID string, kind string, occurrenceID string) string { - return fmt.Sprintf(` - - resource "ibm_scc_si_note" "finding" { - account_id = "%s" - provider_id = "%s" - short_description = "Security Threat" - long_description = "Security Threat found in your account" - kind = "FINDING" - note_id = "%s" - reported_by { - id = "scc-si-terraform" - title = "SCC SI Terraform" - url = "https://cloud.ibm.com" - } - finding { - severity = "LOW" - next_steps { - title = "Security Threat" - url = "https://cloud.ibm.com/security-compliance/findings" - } - } - } - - resource "ibm_scc_si_occurrence" "scc_si_occurrence" { - provider_id = "${ibm_scc_si_note.finding.provider_id}" - note_name = "%s/providers/${ibm_scc_si_note.finding.provider_id}/notes/${ibm_scc_si_note.finding.note_id}" - kind = "%s" - occurrence_id = "%s" - finding { - severity = "LOW" - certainty = "LOW" - next_steps { - title = "title" - url = "url" - } - network_connection { - direction = "direction" - protocol = "protocol" - client { - address = "address" - port = 1 - } - server { - address = "address" - port = 1 - } - } - data_transferred { - client_bytes = 1 - server_bytes = 1 - client_packets = 1 - server_packets = 1 - } - } - } - `, accountID, providerID, noteID, accountID, kind, occurrenceID) -} - -func testAccCheckIBMSccSiOccurrenceConfig(accountID string, providerID string, noteID string, kind string, occurrenceID string, resourceURL string, remediation string, replaceIfExists string) string { - return fmt.Sprintf(` - - resource "ibm_scc_si_note" "finding" { - account_id = "%s" - provider_id = "%s" - short_description = "Security Threat" - long_description = "Security Threat found in your account" - kind = "FINDING" - note_id = "%s" - reported_by { - id = "scc-si-terraform" - title = "SCC SI Terraform" - url = "https://cloud.ibm.com" - } - finding { - severity = "LOW" - next_steps { - title = "Security Threat" - url = "https://cloud.ibm.com/security-compliance/findings" - } - } - } - - resource "ibm_scc_si_occurrence" "scc_si_occurrence" { - provider_id = "${ibm_scc_si_note.finding.provider_id}" - note_name = "%s/providers/${ibm_scc_si_note.finding.provider_id}/notes/${ibm_scc_si_note.finding.note_id}" - kind = "%s" - occurrence_id = "%s" - resource_url = "%s" - remediation = "%s" - context { - region = "region" - resource_crn = "resource_crn" - resource_id = "resource_id" - resource_name = "resource_name" - resource_type = "resource_type" - service_crn = "service_crn" - service_name = "service_name" - environment_name = "environment_name" - component_name = "component_name" - toolchain_id = "toolchain_id" - } - finding { - severity = "LOW" - certainty = "LOW" - next_steps { - title = "title" - url = "url" - } - network_connection { - direction = "direction" - protocol = "protocol" - client { - address = "address" - port = 1 - } - server { - address = "address" - port = 1 - } - } - data_transferred { - client_bytes = 1 - server_bytes = 1 - client_packets = 1 - server_packets = 1 - } - } - replace_if_exists = %s - } - `, accountID, providerID, noteID, accountID, kind, occurrenceID, resourceURL, remediation, replaceIfExists) -} - -func testAccCheckIBMSccSiOccurrenceExists(n string, obj findingsv1.APIOccurrence) resource.TestCheckFunc { - - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[n] - if !ok { - return fmt.Errorf("Not found: %s", n) - } - - findingsClient, err := acc.TestAccProvider.Meta().(conns.ClientSession).FindingsV1() - if err != nil { - return err - } - - getOccurrenceOptions := &findingsv1.GetOccurrenceOptions{} - - parts, err := flex.SepIdParts(rs.Primary.ID, "/") - if err != nil { - return err - } - findingsClient.AccountID = &parts[0] - getOccurrenceOptions.SetProviderID(parts[1]) - getOccurrenceOptions.SetOccurrenceID(parts[2]) - - apiOccurrence, _, err := findingsClient.GetOccurrence(getOccurrenceOptions) - if err != nil { - return err - } - - obj = *apiOccurrence - return nil - } -} - -func testAccCheckIBMSccSiOccurrenceDestroy(s *terraform.State) error { - findingsClient, err := acc.TestAccProvider.Meta().(conns.ClientSession).FindingsV1() - if err != nil { - return err - } - for _, rs := range s.RootModule().Resources { - if rs.Type != "ibm_scc_si_occurrence" { - continue - } - - getOccurrenceOptions := &findingsv1.GetOccurrenceOptions{} - - parts, err := flex.SepIdParts(rs.Primary.ID, "/") - if err != nil { - return err - } - findingsClient.AccountID = &parts[0] - getOccurrenceOptions.SetProviderID(parts[1]) - getOccurrenceOptions.SetOccurrenceID(parts[2]) - - // Try to find the key - _, response, err := findingsClient.GetOccurrence(getOccurrenceOptions) - - if err == nil { - return fmt.Errorf("scc_si_occurrence still exists: %s", rs.Primary.ID) - } else if response.StatusCode != 404 { - return fmt.Errorf("[ERROR] Error checking for scc_si_occurrence (%s) has been destroyed: %s", rs.Primary.ID, err) - } - } - - return nil -} diff --git a/website/docs/d/scc_account_location.html.markdown b/website/docs/d/scc_account_location.html.markdown index 7de7f63bcc..1bfb155f57 100644 --- a/website/docs/d/scc_account_location.html.markdown +++ b/website/docs/d/scc_account_location.html.markdown @@ -45,8 +45,6 @@ In addition to all argument references listed, you can access the following attr * `results_endpoint_url` - (Optional, String) The endpoint that is used to get the results for the Configuration Governance component. -* `si_endpoint_url` - (Optional, String) The endpoint that is used to call the Security Insights APIs. - * `regions` - (Optional, List) Nested scheme for **regions**: * `id` - (Required, String) The programatic ID of the available regions. * Constraints: Allowable values are: `us`, `eu`, `uk`. \ No newline at end of file diff --git a/website/docs/d/scc_account_locations.html.markdown b/website/docs/d/scc_account_locations.html.markdown index abeebf5317..27addeafba 100644 --- a/website/docs/d/scc_account_locations.html.markdown +++ b/website/docs/d/scc_account_locations.html.markdown @@ -36,4 +36,3 @@ Nested scheme for **locations**: * `id` - (String) The programatic ID of the available regions. * Constraints: Allowable values are: `us`, `eu`, `uk`. * `results_endpoint_url` - (String) The endpoint that is used to get the results for the Configuration Governance component. - * `si_endpoint_url` - (String) The endpoint that is used to call the Security Insights APIs. diff --git a/website/docs/d/scc_si_note.html.markdown b/website/docs/d/scc_si_note.html.markdown index ec2fad16dc..0812f599e3 100644 --- a/website/docs/d/scc_si_note.html.markdown +++ b/website/docs/d/scc_si_note.html.markdown @@ -6,6 +6,9 @@ description: |- Get information about scc_si_note --- +# DEPRECATED +Security and Compliance Center - Security Insights has now deprecated, backend services are no longer available. The docs will be removed in next release. + # ibm_scc_si_note Provides a read-only data source for scc_si_note. You can then reference the fields of the data source in other resources within the same configuration using interpolation syntax. diff --git a/website/docs/d/scc_si_notes.html.markdown b/website/docs/d/scc_si_notes.html.markdown index 12d1f253d5..72056ffd05 100644 --- a/website/docs/d/scc_si_notes.html.markdown +++ b/website/docs/d/scc_si_notes.html.markdown @@ -6,6 +6,9 @@ description: |- Get information about scc_si_notes --- +# DEPRECATED +Security and Compliance Center - Security Insights has now deprecated, backend services are no longer available. The docs will be removed in next release. + # ibm_scc_si_notes Provides a read-only data source for scc_si_notes. You can then reference the fields of the data source in other resources within the same configuration using interpolation syntax. diff --git a/website/docs/d/scc_si_occurrence.html.markdown b/website/docs/d/scc_si_occurrence.html.markdown index cf2cd5d686..f5061caa23 100644 --- a/website/docs/d/scc_si_occurrence.html.markdown +++ b/website/docs/d/scc_si_occurrence.html.markdown @@ -6,6 +6,9 @@ description: |- Get information about Security and Compliance Center --- +# DEPRECATED +Security and Compliance Center - Security Insights has now deprecated, backend services are no longer available. The docs will be removed in next release. + # ibm_scc_si_occurence Retrieve information about a Security and Compliance Center occurrence. For more information, about Security and Compliance Center, see [getting started with Security and Compliance Center](https://cloud.ibm.com/docs/security-compliance?topic=security-compliance-getting-started). diff --git a/website/docs/d/scc_si_occurrences.html.markdown b/website/docs/d/scc_si_occurrences.html.markdown index 900600ecf7..cff8e82712 100644 --- a/website/docs/d/scc_si_occurrences.html.markdown +++ b/website/docs/d/scc_si_occurrences.html.markdown @@ -6,6 +6,9 @@ description: |- Get information about Security and Compliance Center --- +# DEPRECATED +Security and Compliance Center - Security Insights has now deprecated, backend services are no longer available. The docs will be removed in next release. + # ibm_scc_si_occurences Retrieve information about a Security and Compliance Center occurrences. For more information, about Security and Compliance Center, see [custom findings](https://cloud.ibm.com/docs/security-compliance?topic=security-compliance-setup_custom). diff --git a/website/docs/d/scc_si_providers.html.markdown b/website/docs/d/scc_si_providers.html.markdown index c138b88bd9..a46a8d5e5e 100644 --- a/website/docs/d/scc_si_providers.html.markdown +++ b/website/docs/d/scc_si_providers.html.markdown @@ -6,6 +6,9 @@ description: |- Get information about scc_si_providers --- +# DEPRECATED +Security and Compliance Center - Security Insights has now deprecated, backend services are no longer available. The docs will be removed in next release. + # ibm_scc_si_providers Provides a read-only data source for scc_si_providers. You can then reference the fields of the data source in other resources within the same configuration using interpolation syntax. diff --git a/website/docs/guides/custom-service-endpoints.html.md b/website/docs/guides/custom-service-endpoints.html.md index 7dd91d4154..ce3b9fde3b 100644 --- a/website/docs/guides/custom-service-endpoints.html.md +++ b/website/docs/guides/custom-service-endpoints.html.md @@ -72,7 +72,6 @@ provider "ibm" { |Global Catalog|IBMCLOUD_RESOURCE_CATALOG_API_ENDPOINT| |Satellite|IBMCLOUD_SATELLITE_API_ENDPOINT| |Satellite Link|IBMCLOUD_SATELLITE_LINK_API_ENDPOINT| -|Security and Compliance Center Findings|IBMCLOUD_SCC_FINDINGS_API_ENDPOINT| |Schematics|IBMCLOUD_SCHEMATICS_API_ENDPOINT| |Secrets Manager|IBMCLOUD_SECRETS_MANAGER_API_ENDPOINT| |Transit Gateway|IBMCLOUD_TG_API_ENDPOINT| diff --git a/website/docs/r/pi_dhcp.html.markdown b/website/docs/r/pi_dhcp.html.markdown index c7725c50a4..b39b0b9c83 100644 --- a/website/docs/r/pi_dhcp.html.markdown +++ b/website/docs/r/pi_dhcp.html.markdown @@ -23,15 +23,19 @@ resource "ibm_pi_dhcp" "example" { Review the argument references that you can specify for your resource. +- `pi_cidr` - (Optional, String) The CIDR for the DHCP private network. +- `pi_cloud_connection_id` - (Optional, String) The Cloud Connection UUID to connect with the DHCP private network. - `pi_cloud_instance_id` - (Required, String) The GUID of the service instance associated with an account. -- `pi_cloud_connection_id` - (Optional, String) The Cloud Connection UUID to connect with DHCP private network. +- `pi_dhcp_name` - (Optional, String) The name of the DHCP Service that will be prefixed by the DHCP identifier. +- `pi_dhcp_snat_enabled` - (Optional, Bool) Indicates if SNAT will be enabled for the DHCP service. The default value is **true**. +- `pi_dns_server` - (Optional, String) The DNS Server for the DHCP service. ## Attribute reference In addition to all argument reference list, you can access the following attribute reference after your resource is created. -- `id` - (String) The unique identifier of the DHCP Server. The ID is composed of `/`. - `dhcp_id` - (String) The ID of the DHCP Server. +- `id` - (String) The unique identifier of the DHCP Server. The ID is composed of `/`. - `leases` - (List) The list of DHCP Server PVM Instance leases. Nested scheme for `leases`: - `instance_ip` - (String) The IP of the PVM Instance. diff --git a/website/docs/r/scc_si_note.html.markdown b/website/docs/r/scc_si_note.html.markdown index 3b3e1a6117..c246f5b379 100644 --- a/website/docs/r/scc_si_note.html.markdown +++ b/website/docs/r/scc_si_note.html.markdown @@ -6,6 +6,9 @@ description: |- Manages scc_si_note. --- +# DEPRECATED +Security and Compliance Center - Security Insights has now deprecated, backend services are no longer available. The docs will be removed in next release. + # ibm_scc_si_note Provides a resource for scc_si_note. This allows scc_si_note to be created, updated and deleted. diff --git a/website/docs/r/scc_si_occurrence.html.markdown b/website/docs/r/scc_si_occurrence.html.markdown index 5123a52571..c211cbb86d 100644 --- a/website/docs/r/scc_si_occurrence.html.markdown +++ b/website/docs/r/scc_si_occurrence.html.markdown @@ -6,6 +6,9 @@ description: |- Manages Security and Compliance Center occurrence. --- +# DEPRECATED +Security and Compliance Center - Security Insights has now deprecated, backend services are no longer available. The docs will be removed in next release. + # ibm_scc_si_occurrence Create, update, or delete for a Security and Compliance Center occurrence. For more information, about Security and Compliance Center, see [getting started with Security and Compliance Center](https://cloud.ibm.com/docs/security-compliance?topic=security-compliance-getting-started).