Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SCC]: Updating Terraform with ACS update #5891

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion ibm/acctest/acctest.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,11 +301,12 @@ var Snapshot_date_from string
var Snapshot_date_to string
var Snapshot_month string

// Secuity and Complinace Center
// Security and Complinace Center
var (
SccApiEndpoint string
SccEventNotificationsCRN string
SccInstanceID string
SccAccountID string
SccObjectStorageCRN string
SccObjectStorageBucket string
SccProviderTypeAttributes string
Expand Down Expand Up @@ -1655,6 +1656,11 @@ func init() {
fmt.Println("[WARN] Set the environment variable IBMCLOUD_SCC_INSTANCE_ID with a VALID SCC INSTANCE ID")
}

SccAccountID = os.Getenv("IBMCLOUD_SCC_ACCOUNT_ID")
if SccAccountID == "" {
fmt.Println("[WARN] Set the environment variable IBMCLOUD_SCC_ACCOUNT_ID with a VALID IAM ACCOUNT ID")
}

SccApiEndpoint = os.Getenv("IBMCLOUD_SCC_API_ENDPOINT")
if SccApiEndpoint == "" {
fmt.Println("[WARN] Set the environment variable IBMCLOUD_SCC_API_ENDPOINT with a VALID SCC API ENDPOINT")
Expand Down Expand Up @@ -2279,6 +2285,10 @@ func TestAccPreCheckScc(t *testing.T) {
t.Fatal("IBMCLOUD_SCC_PROVIDER_TYPE_ID missing. Set the environment variable IBMCLOUD_SCC_PROVIDER_TYPE_ID with a VALID SCC provider_type ID")
}

if SccAccountID == "" {
t.Fatal("IBMCLOUD_SCC_ACCOUNT_ID missing. Set the environment variable IBMCLOUD_SCC_ACCOUNT_ID with a VALID IAM ACCOUNT ID")
}

if SccInstanceID == "" {
t.Fatal("IBMCLOUD_SCC_INSTANCE_ID missing. Set the environment variable IBMCLOUD_SCC_INSTANCE_ID with a VALID SCC INSTANCE ID")
}
Expand Down
2 changes: 1 addition & 1 deletion ibm/conns/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -1918,7 +1918,7 @@
}

// Construct the service client.
session.securityAndComplianceCenterClient, err = scc.NewSecurityAndComplianceCenterApiV3(sccApiClientOptions)
session.securityAndComplianceCenterClient, err = scc.NewSecurityAndComplianceCenterV3(sccApiClientOptions)
if err == nil {
// Enable retries for API calls
session.securityAndComplianceCenterClient.Service.EnableRetries(c.RetryCount, c.RetryDelay)
Expand Down Expand Up @@ -1977,7 +1977,7 @@
vpcclient.Service.EnableRetries(c.RetryCount, c.RetryDelay)
vpcclient.SetDefaultHeaders(gohttp.Header{
"X-Original-User-Agent": {fmt.Sprintf("terraform-provider-ibm/%s", version.Version)},
})

Check failure on line 1980 in ibm/conns/config.go

View workflow job for this annotation

GitHub Actions / Build

undefined: scc.NewSecurityAndComplianceCenterV3
}
session.vpcAPI = vpcclient

Expand Down
2 changes: 2 additions & 0 deletions ibm/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -1509,6 +1509,7 @@ func Provider() *schema.Provider {
"ibm_scc_profile": scc.ResourceIbmSccProfile(),
"ibm_scc_profile_attachment": scc.ResourceIbmSccProfileAttachment(),
"ibm_scc_provider_type_instance": scc.ResourceIbmSccProviderTypeInstance(),
"ibm_scc_scope": scc.ResourceIbmSccScope(),

// Security Services
"ibm_pag_instance": pag.ResourceIBMPag(),
Expand Down Expand Up @@ -2013,6 +2014,7 @@ func Validator() validate.ValidatorDict {
"ibm_scc_profile": scc.ResourceIbmSccProfileValidator(),
"ibm_scc_profile_attachment": scc.ResourceIbmSccProfileAttachmentValidator(),
"ibm_scc_provider_type_instance": scc.ResourceIbmSccProviderTypeInstanceValidator(),
"ibm_scc_scope": scc.ResourceIbmSccScopeValidator(),

// Added for Toolchains
"ibm_cd_toolchain": cdtoolchain.ResourceIBMCdToolchainValidator(),
Expand Down
2 changes: 1 addition & 1 deletion ibm/service/scc/data_source_ibm_scc_control_libraries.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func dataSourceIbmSccControlLibrariesRead(context context.Context, d *schema.Res
return nil
}

func dataSourceIbmSccControlLibraryToMap(controlLibrary *securityandcompliancecenterapiv3.ControlLibraryItem) (map[string]interface{}, error) {
func dataSourceIbmSccControlLibraryToMap(controlLibrary *securityandcompliancecenterapiv3.ControlLibrary) (map[string]interface{}, error) {
modelMap := make(map[string]interface{})
if controlLibrary.ID != nil {
modelMap["id"] = controlLibrary.ID
Expand Down
22 changes: 11 additions & 11 deletions ibm/service/scc/data_source_ibm_scc_control_library.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ func dataSourceIbmSccControlLibraryRead(context context.Context, d *schema.Resou

getControlLibraryOptions := &securityandcompliancecenterapiv3.GetControlLibraryOptions{}

getControlLibraryOptions.SetControlLibrariesID(d.Get("control_library_id").(string))
getControlLibraryOptions.SetControlLibraryID(d.Get("control_library_id").(string))
getControlLibraryOptions.SetInstanceID(d.Get("instance_id").(string))

controlLibrary, response, err := securityandcompliancecenterapiClient.GetControlLibraryWithContext(context, getControlLibraryOptions)
Expand All @@ -290,7 +290,7 @@ func dataSourceIbmSccControlLibraryRead(context context.Context, d *schema.Resou
return diag.FromErr(flex.FmtErrorf("GetControlLibraryWithContext failed %s\n%s", err, response))
}

d.SetId(fmt.Sprintf("%s", *getControlLibraryOptions.ControlLibrariesID))
d.SetId(fmt.Sprintf("%s", *getControlLibraryOptions.ControlLibraryID))

if err = d.Set("account_id", controlLibrary.AccountID); err != nil {
return diag.FromErr(flex.FmtErrorf("Error setting account_id: %s", err))
Expand Down Expand Up @@ -365,7 +365,7 @@ func dataSourceIbmSccControlLibraryRead(context context.Context, d *schema.Resou
return nil
}

func dataSourceIbmSccControlLibraryControlsInControlLibToMap(model *securityandcompliancecenterapiv3.ControlsInControlLib) (map[string]interface{}, error) {
func dataSourceIbmSccControlLibraryControlsInControlLibToMap(model *securityandcompliancecenterapiv3.Control) (map[string]interface{}, error) {
modelMap := make(map[string]interface{})
if model.ControlName != nil {
modelMap["control_name"] = model.ControlName
Expand Down Expand Up @@ -412,10 +412,10 @@ func dataSourceIbmSccControlLibraryControlsInControlLibToMap(model *securityandc
return modelMap, nil
}

func dataSourceIbmSccControlLibraryControlSpecificationsToMap(model *securityandcompliancecenterapiv3.ControlSpecifications) (map[string]interface{}, error) {
func dataSourceIbmSccControlLibraryControlSpecificationsToMap(model *securityandcompliancecenterapiv3.ControlSpecification) (map[string]interface{}, error) {
modelMap := make(map[string]interface{})
if model.ControlSpecificationID != nil {
modelMap["control_specification_id"] = model.ControlSpecificationID
if model.ID != nil {
modelMap["control_specification_id"] = model.ID
}
if model.Responsibility != nil {
modelMap["responsibility"] = model.Responsibility
Expand All @@ -429,8 +429,8 @@ func dataSourceIbmSccControlLibraryControlSpecificationsToMap(model *securityand
if model.Environment != nil {
modelMap["environment"] = model.Environment
}
if model.ControlSpecificationDescription != nil {
modelMap["control_specification_description"] = model.ControlSpecificationDescription
if model.Description != nil {
modelMap["control_specification_description"] = model.Description
}
if model.AssessmentsCount != nil {
modelMap["assessments_count"] = flex.IntValue(model.AssessmentsCount)
Expand All @@ -449,7 +449,7 @@ func dataSourceIbmSccControlLibraryControlSpecificationsToMap(model *securityand
return modelMap, nil
}

func dataSourceIbmSccControlLibraryImplementationToMap(model *securityandcompliancecenterapiv3.Implementation) (map[string]interface{}, error) {
func dataSourceIbmSccControlLibraryImplementationToMap(model *securityandcompliancecenterapiv3.Assessment) (map[string]interface{}, error) {
modelMap := make(map[string]interface{})
if model.AssessmentID != nil {
modelMap["assessment_id"] = model.AssessmentID
Expand Down Expand Up @@ -480,7 +480,7 @@ func dataSourceIbmSccControlLibraryImplementationToMap(model *securityandcomplia
return modelMap, nil
}

func dataSourceIbmSccControlLibraryParameterInfoToMap(model *securityandcompliancecenterapiv3.ParameterInfo) (map[string]interface{}, error) {
func dataSourceIbmSccControlLibraryParameterInfoToMap(model *securityandcompliancecenterapiv3.Parameter) (map[string]interface{}, error) {
modelMap := make(map[string]interface{})
if model.ParameterName != nil {
modelMap["parameter_name"] = model.ParameterName
Expand All @@ -494,7 +494,7 @@ func dataSourceIbmSccControlLibraryParameterInfoToMap(model *securityandcomplian
return modelMap, nil
}

func dataSourceIbmSccControlLibraryControlDocsToMap(model *securityandcompliancecenterapiv3.ControlDocs) (map[string]interface{}, error) {
func dataSourceIbmSccControlLibraryControlDocsToMap(model *securityandcompliancecenterapiv3.ControlDoc) (map[string]interface{}, error) {
modelMap := make(map[string]interface{})
if model.ControlDocsID != nil {
modelMap["control_docs_id"] = model.ControlDocsID
Expand Down
10 changes: 4 additions & 6 deletions ibm/service/scc/data_source_ibm_scc_control_library_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestAccIbmSccControlLibraryDataSourceAllArgs(t *testing.T) {
controlLibraryControlLibraryName := fmt.Sprintf("tf_control_library_name_%d", acctest.RandIntRange(10, 100))
controlLibraryControlLibraryDescription := fmt.Sprintf("tf_control_library_description_%d", acctest.RandIntRange(10, 100))
controlLibraryControlLibraryType := "custom"
controlLibraryVersionGroupLabel := fmt.Sprintf("d755830f-1d83-4fab-b5d5-1dfb2b0dad1%d", acctest.RandIntRange(1, 9))
// controlLibraryVersionGroupLabel := fmt.Sprintf("d755830f-1d83-4fab-b5d5-1dfb2b0dad1%d", acctest.RandIntRange(1, 9))
controlLibraryControlLibraryVersion := fmt.Sprintf("0.0.%d", acctest.RandIntRange(1, 100))
controlLibraryLatest := "true"

Expand All @@ -46,7 +46,7 @@ func TestAccIbmSccControlLibraryDataSourceAllArgs(t *testing.T) {
Providers: acc.TestAccProviders,
Steps: []resource.TestStep{
{
Config: testAccCheckIbmSccControlLibraryDataSourceConfig(acc.SccInstanceID, controlLibraryControlLibraryName, controlLibraryControlLibraryDescription, controlLibraryControlLibraryType, controlLibraryVersionGroupLabel, controlLibraryControlLibraryVersion, controlLibraryLatest),
Config: testAccCheckIbmSccControlLibraryDataSourceConfig(acc.SccInstanceID, controlLibraryControlLibraryName, controlLibraryControlLibraryDescription, controlLibraryControlLibraryType, controlLibraryControlLibraryVersion, controlLibraryLatest),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("data.ibm_scc_control_library.scc_control_library", "id"),
resource.TestCheckResourceAttrSet("data.ibm_scc_control_library.scc_control_library", "account_id"),
Expand Down Expand Up @@ -83,7 +83,6 @@ func testAccCheckIbmSccControlLibraryDataSourceConfigBasic(instanceID string, co
control_library_name = "%s"
control_library_description = "%s"
control_library_type = "%s"
version_group_label = "03354ab4-03be-41c0-a469-826fc0262e78"
latest = true
controls {
control_name = "control-name"
Expand Down Expand Up @@ -127,14 +126,13 @@ func testAccCheckIbmSccControlLibraryDataSourceConfigBasic(instanceID string, co
`, instanceID, controlLibraryControlLibraryName, controlLibraryControlLibraryDescription, controlLibraryControlLibraryType)
}

func testAccCheckIbmSccControlLibraryDataSourceConfig(instanceID string, controlLibraryControlLibraryName string, controlLibraryControlLibraryDescription string, controlLibraryControlLibraryType string, controlLibraryVersionGroupLabel string, controlLibraryControlLibraryVersion string, controlLibraryLatest string) string {
func testAccCheckIbmSccControlLibraryDataSourceConfig(instanceID string, controlLibraryControlLibraryName string, controlLibraryControlLibraryDescription string, controlLibraryControlLibraryType string, controlLibraryControlLibraryVersion string, controlLibraryLatest string) string {
return fmt.Sprintf(`
resource "ibm_scc_control_library" "scc_control_library_instance" {
instance_id = "%s"
control_library_name = "%s"
control_library_description = "%s"
control_library_type = "%s"
version_group_label = "%s"
control_library_version = "%s"
latest = %s
controls {
Expand Down Expand Up @@ -176,5 +174,5 @@ func testAccCheckIbmSccControlLibraryDataSourceConfig(instanceID string, control
control_library_id = ibm_scc_control_library.scc_control_library_instance.control_library_id
}

`, instanceID, controlLibraryControlLibraryName, controlLibraryControlLibraryDescription, controlLibraryControlLibraryType, controlLibraryVersionGroupLabel, controlLibraryControlLibraryVersion, controlLibraryLatest)
`, instanceID, controlLibraryControlLibraryName, controlLibraryControlLibraryDescription, controlLibraryControlLibraryType, controlLibraryControlLibraryVersion, controlLibraryLatest)
}
8 changes: 4 additions & 4 deletions ibm/service/scc/data_source_ibm_scc_instance_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ func dataSourceIbmSccInstanceSettingsRead(context context.Context, d *schema.Res

func dataSourceIbmSccInstanceSettingsEventNotificationsToMap(model *securityandcompliancecenterapiv3.EventNotifications) (map[string]interface{}, error) {
modelMap := make(map[string]interface{})
if model.InstanceCrn != nil {
modelMap["instance_crn"] = model.InstanceCrn
if model.InstanceCRN != nil {
modelMap["instance_crn"] = model.InstanceCRN
}
if model.UpdatedOn != nil {
modelMap["updated_on"] = model.UpdatedOn.String()
Expand All @@ -144,8 +144,8 @@ func dataSourceIbmSccInstanceSettingsEventNotificationsToMap(model *securityandc

func dataSourceIbmSccInstanceSettingsObjectStorageToMap(model *securityandcompliancecenterapiv3.ObjectStorage) (map[string]interface{}, error) {
modelMap := make(map[string]interface{})
if model.InstanceCrn != nil {
modelMap["instance_crn"] = model.InstanceCrn
if model.InstanceCRN != nil {
modelMap["instance_crn"] = model.InstanceCRN
}
if model.Bucket != nil {
modelMap["bucket"] = model.Bucket
Expand Down
38 changes: 25 additions & 13 deletions ibm/service/scc/data_source_ibm_scc_latest_reports.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package scc

import (
"context"
"fmt"
"log"
"time"

Expand Down Expand Up @@ -448,7 +449,7 @@ func dataSourceIbmSccLatestReportsReportToMap(model *securityandcompliancecenter
modelMap["group_id"] = model.GroupID
}
if model.CreatedOn != nil {
modelMap["created_on"] = model.CreatedOn
modelMap["created_on"] = model.CreatedOn.String()
}
if model.ScanTime != nil {
modelMap["scan_time"] = model.ScanTime
Expand Down Expand Up @@ -528,9 +529,9 @@ func dataSourceIbmSccLatestReportsAttachmentToMap(model *securityandcompliancece
if model.Schedule != nil {
modelMap["schedule"] = model.Schedule
}
if model.Scope != nil {
if model.Scopes != nil {
scope := []map[string]interface{}{}
for _, scopeItem := range model.Scope {
for _, scopeItem := range model.Scopes {
scopeItemMap, err := dataSourceIbmSccLatestReportsAttachmentScopeToMap(&scopeItem)
if err != nil {
return modelMap, err
Expand All @@ -542,7 +543,7 @@ func dataSourceIbmSccLatestReportsAttachmentToMap(model *securityandcompliancece
return modelMap, nil
}

func dataSourceIbmSccLatestReportsAttachmentScopeToMap(model *securityandcompliancecenterapiv3.AttachmentScope) (map[string]interface{}, error) {
func dataSourceIbmSccLatestReportsAttachmentScopeToMap(model *securityandcompliancecenterapiv3.Scope) (map[string]interface{}, error) {
modelMap := make(map[string]interface{})
if model.ID != nil {
modelMap["id"] = model.ID
Expand All @@ -553,7 +554,7 @@ func dataSourceIbmSccLatestReportsAttachmentScopeToMap(model *securityandcomplia
if model.Properties != nil {
properties := []map[string]interface{}{}
for _, propertiesItem := range model.Properties {
propertiesItemMap, err := dataSourceIbmSccLatestReportsScopePropertyToMap(&propertiesItem)
propertiesItemMap, err := dataSourceIbmSccLatestReportsScopePropertyToMap(propertiesItem)
if err != nil {
return modelMap, err
}
Expand All @@ -564,13 +565,24 @@ func dataSourceIbmSccLatestReportsAttachmentScopeToMap(model *securityandcomplia
return modelMap, nil
}

func dataSourceIbmSccLatestReportsScopePropertyToMap(model *securityandcompliancecenterapiv3.ScopeProperty) (map[string]interface{}, error) {
modelMap := make(map[string]interface{})
if model.Name != nil {
modelMap["name"] = model.Name
}
if model.Value != nil {
modelMap["value"] = model.Value
func dataSourceIbmSccLatestReportsScopePropertyToMap(model securityandcompliancecenterapiv3.ScopePropertyIntf) (map[string]interface{}, error) {
if _, ok := model.(*securityandcompliancecenterapiv3.ScopePropertyScopeID); ok {
return resourceIBMSccScopeScopePropertyScopeIDToMap(model.(*securityandcompliancecenterapiv3.ScopePropertyScopeID))
} else if _, ok := model.(*securityandcompliancecenterapiv3.ScopePropertyScopeType); ok {
return resourceIBMSccScopeScopePropertyScopeTypeToMap(model.(*securityandcompliancecenterapiv3.ScopePropertyScopeType))
} else if _, ok := model.(*securityandcompliancecenterapiv3.ScopePropertyExclusions); ok {
return resourceIBMSccScopeScopePropertyExclusionsToMap(model.(*securityandcompliancecenterapiv3.ScopePropertyExclusions))
} else if _, ok := model.(*securityandcompliancecenterapiv3.ScopeProperty); ok {
modelMap := make(map[string]interface{})
model := model.(*securityandcompliancecenterapiv3.ScopeProperty)
if model.Name != nil {
modelMap["name"] = model.Name
}
if model.Value != nil {
modelMap["value"] = model.Value
}
return modelMap, nil
} else {
return nil, fmt.Errorf("Unrecognized securityandcompliancecenterv3.ScopePropertyIntf subtype encountered")
}
return modelMap, nil
}
Loading
Loading