From 568cc3acbfd65abd20b12ed3d8d90761bb18e9a5 Mon Sep 17 00:00:00 2001 From: Brian Gleeson Date: Fri, 18 Oct 2024 10:11:38 +0100 Subject: [PATCH] Tekton pipeline re-generated with latest SDK generator (#5715) * feat(tekton): add support for fork feature * fix(tekton): data source tekton test fix * feat(tekton): re-gen with 3.95.2 sdk-gen * fix(tekton): fix acceptance tests for tekton pipeline * chore: bump CD Go SDK * fix(tekton): boolean value issue --- go.mod | 2 +- go.sum | 4 +- .../data_source_ibm_cd_tekton_pipeline.go | 370 ++++---- ...ource_ibm_cd_tekton_pipeline_definition.go | 57 +- ..._ibm_cd_tekton_pipeline_definition_test.go | 114 ++- ..._source_ibm_cd_tekton_pipeline_property.go | 59 +- ...ce_ibm_cd_tekton_pipeline_property_test.go | 64 +- ...data_source_ibm_cd_tekton_pipeline_test.go | 882 +++++++++++++++++- ...a_source_ibm_cd_tekton_pipeline_trigger.go | 236 +++-- ...ibm_cd_tekton_pipeline_trigger_property.go | 57 +- ...d_tekton_pipeline_trigger_property_test.go | 80 +- ...rce_ibm_cd_tekton_pipeline_trigger_test.go | 249 ++++- .../resource_ibm_cd_tekton_pipeline.go | 577 +++++++----- ...ource_ibm_cd_tekton_pipeline_definition.go | 114 ++- ..._ibm_cd_tekton_pipeline_definition_test.go | 196 +++- ...esource_ibm_cd_tekton_pipeline_property.go | 125 ++- ...ce_ibm_cd_tekton_pipeline_property_test.go | 55 +- .../resource_ibm_cd_tekton_pipeline_test.go | 821 +++++++++++++++- ...resource_ibm_cd_tekton_pipeline_trigger.go | 580 ++++++++---- ...ibm_cd_tekton_pipeline_trigger_property.go | 133 +-- ...d_tekton_pipeline_trigger_property_test.go | 75 +- ...rce_ibm_cd_tekton_pipeline_trigger_test.go | 394 ++++++-- .../docs/d/cd_tekton_pipeline.html.markdown | 20 +- ...d_tekton_pipeline_definition.html.markdown | 10 +- .../cd_tekton_pipeline_property.html.markdown | 14 +- .../cd_tekton_pipeline_trigger.html.markdown | 23 +- ...on_pipeline_trigger_property.html.markdown | 16 +- .../docs/r/cd_tekton_pipeline.html.markdown | 32 +- ...d_tekton_pipeline_definition.html.markdown | 14 +- .../cd_tekton_pipeline_property.html.markdown | 21 +- .../cd_tekton_pipeline_trigger.html.markdown | 37 +- ...on_pipeline_trigger_property.html.markdown | 21 +- 32 files changed, 4078 insertions(+), 1374 deletions(-) diff --git a/go.mod b/go.mod index a118a16872..3f03f02e0d 100644 --- a/go.mod +++ b/go.mod @@ -16,7 +16,7 @@ require ( github.com/IBM/code-engine-go-sdk v0.0.0-20240808131715-b9d168602dac github.com/IBM/configuration-aggregator-go-sdk v0.0.1 github.com/IBM/container-registry-go-sdk v1.1.0 - github.com/IBM/continuous-delivery-go-sdk v1.8.1 + github.com/IBM/continuous-delivery-go-sdk v1.8.2 github.com/IBM/event-notifications-go-admin-sdk v0.9.0 github.com/IBM/eventstreams-go-sdk v1.4.0 github.com/IBM/go-sdk-core v1.1.0 diff --git a/go.sum b/go.sum index 925cfefd5a..e4f293b846 100644 --- a/go.sum +++ b/go.sum @@ -140,8 +140,8 @@ github.com/IBM/configuration-aggregator-go-sdk v0.0.1 h1:bgJqfd39hzKqtLxgrmOZ7Ug github.com/IBM/configuration-aggregator-go-sdk v0.0.1/go.mod h1:iMQUJgo42cbRk1XW06lmeHzm9/Nfk5/laBscGdPnSqY= github.com/IBM/container-registry-go-sdk v1.1.0 h1:sYyknIod8R4RJZQqAheiduP6wbSTphE9Ag8ho28yXjc= github.com/IBM/container-registry-go-sdk v1.1.0/go.mod h1:4TwsCnQtVfZ4Vkapy/KPvQBKFc3VOyUZYkwRU4FTPrs= -github.com/IBM/continuous-delivery-go-sdk v1.8.1 h1:BWmp58XODXqAe3DRQE3I0Lnrwewf8HzXH1FVCBYlAa0= -github.com/IBM/continuous-delivery-go-sdk v1.8.1/go.mod h1:5umVUaXEoTP2ULARgXRBPcR3vWDCmKD66P6XgNqpzZk= +github.com/IBM/continuous-delivery-go-sdk v1.8.2 h1:L2hyoJSxgCa0/HKviHKtut1z4Mn2qGz1gnJZ43LV0o0= +github.com/IBM/continuous-delivery-go-sdk v1.8.2/go.mod h1:5umVUaXEoTP2ULARgXRBPcR3vWDCmKD66P6XgNqpzZk= github.com/IBM/event-notifications-go-admin-sdk v0.9.0 h1:eaCd+GkxhNyot+8rA9WkAQdlVYrRD20LYiXjEytFO6M= github.com/IBM/event-notifications-go-admin-sdk v0.9.0/go.mod h1:OByvqfrNVxs7G6ggv8pwQCEVw10/TBJCLh7NM3z707w= github.com/IBM/eventstreams-go-sdk v1.4.0 h1:yS/Ns29sBOe8W2tynQmz9HTKqQZ0ckse4Py5Oy/F2rM= diff --git a/ibm/service/cdtektonpipeline/data_source_ibm_cd_tekton_pipeline.go b/ibm/service/cdtektonpipeline/data_source_ibm_cd_tekton_pipeline.go index 776e12043e..61797149e5 100644 --- a/ibm/service/cdtektonpipeline/data_source_ibm_cd_tekton_pipeline.go +++ b/ibm/service/cdtektonpipeline/data_source_ibm_cd_tekton_pipeline.go @@ -1,6 +1,10 @@ // Copyright IBM Corp. 2024 All Rights Reserved. // Licensed under the Mozilla Public License v2.0 +/* + * IBM OpenAPI Terraform Generator Version: 3.95.2-120e65bc-20240924-152329 + */ + package cdtektonpipeline import ( @@ -14,6 +18,7 @@ import ( "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" "github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex" "github.com/IBM/continuous-delivery-go-sdk/cdtektonpipelinev2" + "github.com/IBM/go-sdk-core/v5/core" ) func DataSourceIBMCdTektonPipeline() *schema.Resource { @@ -59,7 +64,7 @@ func DataSourceIBMCdTektonPipeline() *schema.Resource { "id": &schema.Schema{ Type: schema.TypeString, Computed: true, - Description: "UUID.", + Description: "Universally Unique Identifier.", }, "crn": &schema.Schema{ Type: schema.TypeString, @@ -525,179 +530,176 @@ func DataSourceIBMCdTektonPipeline() *schema.Resource { func dataSourceIBMCdTektonPipelineRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { cdTektonPipelineClient, err := meta.(conns.ClientSession).CdTektonPipelineV2() if err != nil { - return diag.FromErr(err) + tfErr := flex.DiscriminatedTerraformErrorf(err, err.Error(), "(Data) ibm_cd_tekton_pipeline", "read", "initialize-client") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } getTektonPipelineOptions := &cdtektonpipelinev2.GetTektonPipelineOptions{} getTektonPipelineOptions.SetID(d.Get("pipeline_id").(string)) - tektonPipeline, response, err := cdTektonPipelineClient.GetTektonPipelineWithContext(context, getTektonPipelineOptions) + tektonPipeline, _, err := cdTektonPipelineClient.GetTektonPipelineWithContext(context, getTektonPipelineOptions) if err != nil { - log.Printf("[DEBUG] GetTektonPipelineWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("GetTektonPipelineWithContext failed %s\n%s", err, response)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("GetTektonPipelineWithContext failed: %s", err.Error()), "(Data) ibm_cd_tekton_pipeline", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } - d.SetId(fmt.Sprintf("%s", *getTektonPipelineOptions.ID)) + d.SetId(*getTektonPipelineOptions.ID) if err = d.Set("name", tektonPipeline.Name); err != nil { - return diag.FromErr(fmt.Errorf("Error setting name: %s", err)) + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting name: %s", err), "(Data) ibm_cd_tekton_pipeline", "read", "set-name").GetDiag() } if err = d.Set("status", tektonPipeline.Status); err != nil { - return diag.FromErr(fmt.Errorf("Error setting status: %s", err)) + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting status: %s", err), "(Data) ibm_cd_tekton_pipeline", "read", "set-status").GetDiag() } resourceGroup := []map[string]interface{}{} - if tektonPipeline.ResourceGroup != nil { - modelMap, err := dataSourceIBMCdTektonPipelineResourceGroupReferenceToMap(tektonPipeline.ResourceGroup) - if err != nil { - return diag.FromErr(err) - } - resourceGroup = append(resourceGroup, modelMap) + resourceGroupMap, err := DataSourceIBMCdTektonPipelineResourceGroupReferenceToMap(tektonPipeline.ResourceGroup) + if err != nil { + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "(Data) ibm_cd_tekton_pipeline", "read", "resource_group-to-map").GetDiag() } + resourceGroup = append(resourceGroup, resourceGroupMap) if err = d.Set("resource_group", resourceGroup); err != nil { - return diag.FromErr(fmt.Errorf("Error setting resource_group %s", err)) + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting resource_group: %s", err), "(Data) ibm_cd_tekton_pipeline", "read", "set-resource_group").GetDiag() } toolchain := []map[string]interface{}{} - if tektonPipeline.Toolchain != nil { - modelMap, err := dataSourceIBMCdTektonPipelineToolchainReferenceToMap(tektonPipeline.Toolchain) - if err != nil { - return diag.FromErr(err) - } - toolchain = append(toolchain, modelMap) + toolchainMap, err := DataSourceIBMCdTektonPipelineToolchainReferenceToMap(tektonPipeline.Toolchain) + if err != nil { + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "(Data) ibm_cd_tekton_pipeline", "read", "toolchain-to-map").GetDiag() } + toolchain = append(toolchain, toolchainMap) if err = d.Set("toolchain", toolchain); err != nil { - return diag.FromErr(fmt.Errorf("Error setting toolchain %s", err)) + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting toolchain: %s", err), "(Data) ibm_cd_tekton_pipeline", "read", "set-toolchain").GetDiag() } definitions := []map[string]interface{}{} - if tektonPipeline.Definitions != nil { - for _, modelItem := range tektonPipeline.Definitions { - modelMap, err := dataSourceIBMCdTektonPipelineDefinitionToMap(&modelItem) - if err != nil { - return diag.FromErr(err) - } - definitions = append(definitions, modelMap) + for _, definitionsItem := range tektonPipeline.Definitions { + definitionsItemMap, err := DataSourceIBMCdTektonPipelineDefinitionToMap(&definitionsItem) // #nosec G601 + if err != nil { + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "(Data) ibm_cd_tekton_pipeline", "read", "definitions-to-map").GetDiag() } + definitions = append(definitions, definitionsItemMap) } if err = d.Set("definitions", definitions); err != nil { - return diag.FromErr(fmt.Errorf("Error setting definitions %s", err)) + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting definitions: %s", err), "(Data) ibm_cd_tekton_pipeline", "read", "set-definitions").GetDiag() } properties := []map[string]interface{}{} - if tektonPipeline.Properties != nil { - for _, modelItem := range tektonPipeline.Properties { - modelMap, err := dataSourceIBMCdTektonPipelinePropertyToMap(&modelItem) - if err != nil { - return diag.FromErr(err) - } - properties = append(properties, modelMap) + for _, propertiesItem := range tektonPipeline.Properties { + propertiesItemMap, err := DataSourceIBMCdTektonPipelinePropertyToMap(&propertiesItem) // #nosec G601 + if err != nil { + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "(Data) ibm_cd_tekton_pipeline", "read", "properties-to-map").GetDiag() } + properties = append(properties, propertiesItemMap) } if err = d.Set("properties", properties); err != nil { - return diag.FromErr(fmt.Errorf("Error setting properties %s", err)) + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting properties: %s", err), "(Data) ibm_cd_tekton_pipeline", "read", "set-properties").GetDiag() } if err = d.Set("updated_at", flex.DateTimeToString(tektonPipeline.UpdatedAt)); err != nil { - return diag.FromErr(fmt.Errorf("Error setting updated_at: %s", err)) + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting updated_at: %s", err), "(Data) ibm_cd_tekton_pipeline", "read", "set-updated_at").GetDiag() } if err = d.Set("created_at", flex.DateTimeToString(tektonPipeline.CreatedAt)); err != nil { - return diag.FromErr(fmt.Errorf("Error setting created_at: %s", err)) + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting created_at: %s", err), "(Data) ibm_cd_tekton_pipeline", "read", "set-created_at").GetDiag() } triggers := []map[string]interface{}{} if tektonPipeline.Triggers != nil { - for _, modelItem := range tektonPipeline.Triggers { - modelMap, err := dataSourceIBMCdTektonPipelineTriggerToMap(modelItem) + for _, triggersItem := range tektonPipeline.Triggers { + triggersItemMap, err := DataSourceIBMCdTektonPipelineTriggerToMap(triggersItem) // #nosec G601 if err != nil { - return diag.FromErr(err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "(Data) ibm_cd_tekton_pipeline", "read", "triggers-to-map").GetDiag() } - triggers = append(triggers, modelMap) + triggers = append(triggers, triggersItemMap) } } if err = d.Set("triggers", triggers); err != nil { - return diag.FromErr(fmt.Errorf("Error setting triggers %s", err)) + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting triggers: %s", err), "(Data) ibm_cd_tekton_pipeline", "read", "set-triggers").GetDiag() } worker := []map[string]interface{}{} - if tektonPipeline.Worker != nil { - modelMap, err := dataSourceIBMCdTektonPipelineWorkerToMap(tektonPipeline.Worker) - if err != nil { - return diag.FromErr(err) - } - worker = append(worker, modelMap) + workerMap, err := DataSourceIBMCdTektonPipelineWorkerToMap(tektonPipeline.Worker) + if err != nil { + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "(Data) ibm_cd_tekton_pipeline", "read", "worker-to-map").GetDiag() } + worker = append(worker, workerMap) if err = d.Set("worker", worker); err != nil { - return diag.FromErr(fmt.Errorf("Error setting worker %s", err)) + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting worker: %s", err), "(Data) ibm_cd_tekton_pipeline", "read", "set-worker").GetDiag() } if err = d.Set("runs_url", tektonPipeline.RunsURL); err != nil { - return diag.FromErr(fmt.Errorf("Error setting runs_url: %s", err)) + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting runs_url: %s", err), "(Data) ibm_cd_tekton_pipeline", "read", "set-runs_url").GetDiag() } - if err = d.Set("href", tektonPipeline.Href); err != nil { - return diag.FromErr(fmt.Errorf("Error setting href: %s", err)) + if !core.IsNil(tektonPipeline.Href) { + if err = d.Set("href", tektonPipeline.Href); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting href: %s", err), "(Data) ibm_cd_tekton_pipeline", "read", "set-href").GetDiag() + } } if err = d.Set("build_number", flex.IntValue(tektonPipeline.BuildNumber)); err != nil { - return diag.FromErr(fmt.Errorf("Error setting build_number: %s", err)) + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting build_number: %s", err), "(Data) ibm_cd_tekton_pipeline", "read", "set-build_number").GetDiag() } - if err = d.Set("next_build_number", flex.IntValue(tektonPipeline.NextBuildNumber)); err != nil { - return diag.FromErr(fmt.Errorf("Error setting next_build_number: %s", err)) + if !core.IsNil(tektonPipeline.NextBuildNumber) { + if err = d.Set("next_build_number", flex.IntValue(tektonPipeline.NextBuildNumber)); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting next_build_number: %s", err), "(Data) ibm_cd_tekton_pipeline", "read", "set-next_build_number").GetDiag() + } } if err = d.Set("enable_notifications", tektonPipeline.EnableNotifications); err != nil { - return diag.FromErr(fmt.Errorf("Error setting enable_notifications: %s", err)) + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting enable_notifications: %s", err), "(Data) ibm_cd_tekton_pipeline", "read", "set-enable_notifications").GetDiag() } if err = d.Set("enable_partial_cloning", tektonPipeline.EnablePartialCloning); err != nil { - return diag.FromErr(fmt.Errorf("Error setting enable_partial_cloning: %s", err)) + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting enable_partial_cloning: %s", err), "(Data) ibm_cd_tekton_pipeline", "read", "set-enable_partial_cloning").GetDiag() } if err = d.Set("enabled", tektonPipeline.Enabled); err != nil { - return diag.FromErr(fmt.Errorf("Error setting enabled: %s", err)) + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting enabled: %s", err), "(Data) ibm_cd_tekton_pipeline", "read", "set-enabled").GetDiag() } return nil } -func dataSourceIBMCdTektonPipelineResourceGroupReferenceToMap(model *cdtektonpipelinev2.ResourceGroupReference) (map[string]interface{}, error) { +func DataSourceIBMCdTektonPipelineResourceGroupReferenceToMap(model *cdtektonpipelinev2.ResourceGroupReference) (map[string]interface{}, error) { modelMap := make(map[string]interface{}) if model.ID != nil { - modelMap["id"] = model.ID + modelMap["id"] = *model.ID } return modelMap, nil } -func dataSourceIBMCdTektonPipelineToolchainReferenceToMap(model *cdtektonpipelinev2.ToolchainReference) (map[string]interface{}, error) { +func DataSourceIBMCdTektonPipelineToolchainReferenceToMap(model *cdtektonpipelinev2.ToolchainReference) (map[string]interface{}, error) { modelMap := make(map[string]interface{}) - modelMap["id"] = model.ID - modelMap["crn"] = model.CRN + modelMap["id"] = *model.ID + modelMap["crn"] = *model.CRN return modelMap, nil } -func dataSourceIBMCdTektonPipelineDefinitionToMap(model *cdtektonpipelinev2.Definition) (map[string]interface{}, error) { +func DataSourceIBMCdTektonPipelineDefinitionToMap(model *cdtektonpipelinev2.Definition) (map[string]interface{}, error) { modelMap := make(map[string]interface{}) - sourceMap, err := dataSourceIBMCdTektonPipelineDefinitionSourceToMap(model.Source) + sourceMap, err := DataSourceIBMCdTektonPipelineDefinitionSourceToMap(model.Source) if err != nil { return modelMap, err } modelMap["source"] = []map[string]interface{}{sourceMap} if model.Href != nil { - modelMap["href"] = model.Href + modelMap["href"] = *model.Href } - modelMap["id"] = model.ID + modelMap["id"] = *model.ID return modelMap, nil } -func dataSourceIBMCdTektonPipelineDefinitionSourceToMap(model *cdtektonpipelinev2.DefinitionSource) (map[string]interface{}, error) { +func DataSourceIBMCdTektonPipelineDefinitionSourceToMap(model *cdtektonpipelinev2.DefinitionSource) (map[string]interface{}, error) { modelMap := make(map[string]interface{}) - modelMap["type"] = model.Type - propertiesMap, err := dataSourceIBMCdTektonPipelineDefinitionSourcePropertiesToMap(model.Properties) + modelMap["type"] = *model.Type + propertiesMap, err := DataSourceIBMCdTektonPipelineDefinitionSourcePropertiesToMap(model.Properties) if err != nil { return modelMap, err } @@ -705,18 +707,18 @@ func dataSourceIBMCdTektonPipelineDefinitionSourceToMap(model *cdtektonpipelinev return modelMap, nil } -func dataSourceIBMCdTektonPipelineDefinitionSourcePropertiesToMap(model *cdtektonpipelinev2.DefinitionSourceProperties) (map[string]interface{}, error) { +func DataSourceIBMCdTektonPipelineDefinitionSourcePropertiesToMap(model *cdtektonpipelinev2.DefinitionSourceProperties) (map[string]interface{}, error) { modelMap := make(map[string]interface{}) - modelMap["url"] = model.URL + modelMap["url"] = *model.URL if model.Branch != nil { - modelMap["branch"] = model.Branch + modelMap["branch"] = *model.Branch } if model.Tag != nil { - modelMap["tag"] = model.Tag + modelMap["tag"] = *model.Tag } - modelMap["path"] = model.Path + modelMap["path"] = *model.Path if model.Tool != nil { - toolMap, err := dataSourceIBMCdTektonPipelineToolToMap(model.Tool) + toolMap, err := DataSourceIBMCdTektonPipelineToolToMap(model.Tool) if err != nil { return modelMap, err } @@ -725,65 +727,65 @@ func dataSourceIBMCdTektonPipelineDefinitionSourcePropertiesToMap(model *cdtekto return modelMap, nil } -func dataSourceIBMCdTektonPipelineToolToMap(model *cdtektonpipelinev2.Tool) (map[string]interface{}, error) { +func DataSourceIBMCdTektonPipelineToolToMap(model *cdtektonpipelinev2.Tool) (map[string]interface{}, error) { modelMap := make(map[string]interface{}) - modelMap["id"] = model.ID + modelMap["id"] = *model.ID return modelMap, nil } -func dataSourceIBMCdTektonPipelinePropertyToMap(model *cdtektonpipelinev2.Property) (map[string]interface{}, error) { +func DataSourceIBMCdTektonPipelinePropertyToMap(model *cdtektonpipelinev2.Property) (map[string]interface{}, error) { modelMap := make(map[string]interface{}) - modelMap["name"] = model.Name + modelMap["name"] = *model.Name if model.Value != nil { - modelMap["value"] = model.Value + modelMap["value"] = *model.Value } if model.Href != nil { - modelMap["href"] = model.Href + modelMap["href"] = *model.Href } if model.Enum != nil { modelMap["enum"] = model.Enum } - modelMap["type"] = model.Type + modelMap["type"] = *model.Type if model.Locked != nil { - modelMap["locked"] = model.Locked + modelMap["locked"] = *model.Locked } if model.Path != nil { - modelMap["path"] = model.Path + modelMap["path"] = *model.Path } return modelMap, nil } -func dataSourceIBMCdTektonPipelineTriggerToMap(model cdtektonpipelinev2.TriggerIntf) (map[string]interface{}, error) { +func DataSourceIBMCdTektonPipelineTriggerToMap(model cdtektonpipelinev2.TriggerIntf) (map[string]interface{}, error) { if _, ok := model.(*cdtektonpipelinev2.TriggerManualTrigger); ok { - return dataSourceIBMCdTektonPipelineTriggerManualTriggerToMap(model.(*cdtektonpipelinev2.TriggerManualTrigger)) + return DataSourceIBMCdTektonPipelineTriggerManualTriggerToMap(model.(*cdtektonpipelinev2.TriggerManualTrigger)) } else if _, ok := model.(*cdtektonpipelinev2.TriggerScmTrigger); ok { - return dataSourceIBMCdTektonPipelineTriggerScmTriggerToMap(model.(*cdtektonpipelinev2.TriggerScmTrigger)) + return DataSourceIBMCdTektonPipelineTriggerScmTriggerToMap(model.(*cdtektonpipelinev2.TriggerScmTrigger)) } else if _, ok := model.(*cdtektonpipelinev2.TriggerTimerTrigger); ok { - return dataSourceIBMCdTektonPipelineTriggerTimerTriggerToMap(model.(*cdtektonpipelinev2.TriggerTimerTrigger)) + return DataSourceIBMCdTektonPipelineTriggerTimerTriggerToMap(model.(*cdtektonpipelinev2.TriggerTimerTrigger)) } else if _, ok := model.(*cdtektonpipelinev2.TriggerGenericTrigger); ok { - return dataSourceIBMCdTektonPipelineTriggerGenericTriggerToMap(model.(*cdtektonpipelinev2.TriggerGenericTrigger)) + return DataSourceIBMCdTektonPipelineTriggerGenericTriggerToMap(model.(*cdtektonpipelinev2.TriggerGenericTrigger)) } else if _, ok := model.(*cdtektonpipelinev2.Trigger); ok { modelMap := make(map[string]interface{}) model := model.(*cdtektonpipelinev2.Trigger) if model.Type != nil { - modelMap["type"] = model.Type + modelMap["type"] = *model.Type } if model.Name != nil { - modelMap["name"] = model.Name + modelMap["name"] = *model.Name } if model.Href != nil { - modelMap["href"] = model.Href + modelMap["href"] = *model.Href } if model.EventListener != nil { - modelMap["event_listener"] = model.EventListener + modelMap["event_listener"] = *model.EventListener } if model.ID != nil { - modelMap["id"] = model.ID + modelMap["id"] = *model.ID } if model.Properties != nil { properties := []map[string]interface{}{} for _, propertiesItem := range model.Properties { - propertiesItemMap, err := dataSourceIBMCdTektonPipelineTriggerPropertyToMap(&propertiesItem) + propertiesItemMap, err := DataSourceIBMCdTektonPipelineTriggerPropertyToMap(&propertiesItem) // #nosec G601 if err != nil { return modelMap, err } @@ -795,7 +797,7 @@ func dataSourceIBMCdTektonPipelineTriggerToMap(model cdtektonpipelinev2.TriggerI modelMap["tags"] = model.Tags } if model.Worker != nil { - workerMap, err := dataSourceIBMCdTektonPipelineWorkerToMap(model.Worker) + workerMap, err := DataSourceIBMCdTektonPipelineWorkerToMap(model.Worker) if err != nil { return modelMap, err } @@ -805,16 +807,16 @@ func dataSourceIBMCdTektonPipelineTriggerToMap(model cdtektonpipelinev2.TriggerI modelMap["max_concurrent_runs"] = flex.IntValue(model.MaxConcurrentRuns) } if model.Enabled != nil { - modelMap["enabled"] = model.Enabled + modelMap["enabled"] = *model.Enabled } if model.Favorite != nil { - modelMap["favorite"] = model.Favorite + modelMap["favorite"] = *model.Favorite } if model.EnableEventsFromForks != nil { - modelMap["enable_events_from_forks"] = model.EnableEventsFromForks + modelMap["enable_events_from_forks"] = *model.EnableEventsFromForks } if model.Source != nil { - sourceMap, err := dataSourceIBMCdTektonPipelineTriggerSourceToMap(model.Source) + sourceMap, err := DataSourceIBMCdTektonPipelineTriggerSourceToMap(model.Source) if err != nil { return modelMap, err } @@ -824,23 +826,23 @@ func dataSourceIBMCdTektonPipelineTriggerToMap(model cdtektonpipelinev2.TriggerI modelMap["events"] = model.Events } if model.Filter != nil { - modelMap["filter"] = model.Filter + modelMap["filter"] = *model.Filter } if model.Cron != nil { - modelMap["cron"] = model.Cron + modelMap["cron"] = *model.Cron } if model.Timezone != nil { - modelMap["timezone"] = model.Timezone + modelMap["timezone"] = *model.Timezone } if model.Secret != nil { - secretMap, err := dataSourceIBMCdTektonPipelineGenericSecretToMap(model.Secret) + secretMap, err := DataSourceIBMCdTektonPipelineGenericSecretToMap(model.Secret) if err != nil { return modelMap, err } modelMap["secret"] = []map[string]interface{}{secretMap} } if model.WebhookURL != nil { - modelMap["webhook_url"] = model.WebhookURL + modelMap["webhook_url"] = *model.WebhookURL } return modelMap, nil } else { @@ -848,44 +850,44 @@ func dataSourceIBMCdTektonPipelineTriggerToMap(model cdtektonpipelinev2.TriggerI } } -func dataSourceIBMCdTektonPipelineTriggerPropertyToMap(model *cdtektonpipelinev2.TriggerProperty) (map[string]interface{}, error) { +func DataSourceIBMCdTektonPipelineTriggerPropertyToMap(model *cdtektonpipelinev2.TriggerProperty) (map[string]interface{}, error) { modelMap := make(map[string]interface{}) - modelMap["name"] = model.Name + modelMap["name"] = *model.Name if model.Value != nil { - modelMap["value"] = model.Value + modelMap["value"] = *model.Value } if model.Href != nil { - modelMap["href"] = model.Href + modelMap["href"] = *model.Href } if model.Enum != nil { modelMap["enum"] = model.Enum } - modelMap["type"] = model.Type + modelMap["type"] = *model.Type if model.Path != nil { - modelMap["path"] = model.Path + modelMap["path"] = *model.Path } if model.Locked != nil { - modelMap["locked"] = model.Locked + modelMap["locked"] = *model.Locked } return modelMap, nil } -func dataSourceIBMCdTektonPipelineWorkerToMap(model *cdtektonpipelinev2.Worker) (map[string]interface{}, error) { +func DataSourceIBMCdTektonPipelineWorkerToMap(model *cdtektonpipelinev2.Worker) (map[string]interface{}, error) { modelMap := make(map[string]interface{}) if model.Name != nil { - modelMap["name"] = model.Name + modelMap["name"] = *model.Name } if model.Type != nil { - modelMap["type"] = model.Type + modelMap["type"] = *model.Type } - modelMap["id"] = model.ID + modelMap["id"] = *model.ID return modelMap, nil } -func dataSourceIBMCdTektonPipelineTriggerSourceToMap(model *cdtektonpipelinev2.TriggerSource) (map[string]interface{}, error) { +func DataSourceIBMCdTektonPipelineTriggerSourceToMap(model *cdtektonpipelinev2.TriggerSource) (map[string]interface{}, error) { modelMap := make(map[string]interface{}) - modelMap["type"] = model.Type - propertiesMap, err := dataSourceIBMCdTektonPipelineTriggerSourcePropertiesToMap(model.Properties) + modelMap["type"] = *model.Type + propertiesMap, err := DataSourceIBMCdTektonPipelineTriggerSourcePropertiesToMap(model.Properties) if err != nil { return modelMap, err } @@ -893,20 +895,20 @@ func dataSourceIBMCdTektonPipelineTriggerSourceToMap(model *cdtektonpipelinev2.T return modelMap, nil } -func dataSourceIBMCdTektonPipelineTriggerSourcePropertiesToMap(model *cdtektonpipelinev2.TriggerSourceProperties) (map[string]interface{}, error) { +func DataSourceIBMCdTektonPipelineTriggerSourcePropertiesToMap(model *cdtektonpipelinev2.TriggerSourceProperties) (map[string]interface{}, error) { modelMap := make(map[string]interface{}) - modelMap["url"] = model.URL + modelMap["url"] = *model.URL if model.Branch != nil { - modelMap["branch"] = model.Branch + modelMap["branch"] = *model.Branch } if model.Pattern != nil { - modelMap["pattern"] = model.Pattern + modelMap["pattern"] = *model.Pattern } - modelMap["blind_connection"] = model.BlindConnection + modelMap["blind_connection"] = *model.BlindConnection if model.HookID != nil { - modelMap["hook_id"] = model.HookID + modelMap["hook_id"] = *model.HookID } - toolMap, err := dataSourceIBMCdTektonPipelineToolToMap(model.Tool) + toolMap, err := DataSourceIBMCdTektonPipelineToolToMap(model.Tool) if err != nil { return modelMap, err } @@ -914,39 +916,39 @@ func dataSourceIBMCdTektonPipelineTriggerSourcePropertiesToMap(model *cdtektonpi return modelMap, nil } -func dataSourceIBMCdTektonPipelineGenericSecretToMap(model *cdtektonpipelinev2.GenericSecret) (map[string]interface{}, error) { +func DataSourceIBMCdTektonPipelineGenericSecretToMap(model *cdtektonpipelinev2.GenericSecret) (map[string]interface{}, error) { modelMap := make(map[string]interface{}) if model.Type != nil { - modelMap["type"] = model.Type + modelMap["type"] = *model.Type } if model.Value != nil { - modelMap["value"] = model.Value + modelMap["value"] = *model.Value } if model.Source != nil { - modelMap["source"] = model.Source + modelMap["source"] = *model.Source } if model.KeyName != nil { - modelMap["key_name"] = model.KeyName + modelMap["key_name"] = *model.KeyName } if model.Algorithm != nil { - modelMap["algorithm"] = model.Algorithm + modelMap["algorithm"] = *model.Algorithm } return modelMap, nil } -func dataSourceIBMCdTektonPipelineTriggerManualTriggerToMap(model *cdtektonpipelinev2.TriggerManualTrigger) (map[string]interface{}, error) { +func DataSourceIBMCdTektonPipelineTriggerManualTriggerToMap(model *cdtektonpipelinev2.TriggerManualTrigger) (map[string]interface{}, error) { modelMap := make(map[string]interface{}) - modelMap["type"] = model.Type - modelMap["name"] = model.Name + modelMap["type"] = *model.Type + modelMap["name"] = *model.Name if model.Href != nil { - modelMap["href"] = model.Href + modelMap["href"] = *model.Href } - modelMap["event_listener"] = model.EventListener - modelMap["id"] = model.ID + modelMap["event_listener"] = *model.EventListener + modelMap["id"] = *model.ID if model.Properties != nil { properties := []map[string]interface{}{} for _, propertiesItem := range model.Properties { - propertiesItemMap, err := dataSourceIBMCdTektonPipelineTriggerPropertyToMap(&propertiesItem) + propertiesItemMap, err := DataSourceIBMCdTektonPipelineTriggerPropertyToMap(&propertiesItem) // #nosec G601 if err != nil { return modelMap, err } @@ -958,7 +960,7 @@ func dataSourceIBMCdTektonPipelineTriggerManualTriggerToMap(model *cdtektonpipel modelMap["tags"] = model.Tags } if model.Worker != nil { - workerMap, err := dataSourceIBMCdTektonPipelineWorkerToMap(model.Worker) + workerMap, err := DataSourceIBMCdTektonPipelineWorkerToMap(model.Worker) if err != nil { return modelMap, err } @@ -967,26 +969,26 @@ func dataSourceIBMCdTektonPipelineTriggerManualTriggerToMap(model *cdtektonpipel if model.MaxConcurrentRuns != nil { modelMap["max_concurrent_runs"] = flex.IntValue(model.MaxConcurrentRuns) } - modelMap["enabled"] = model.Enabled + modelMap["enabled"] = *model.Enabled if model.Favorite != nil { - modelMap["favorite"] = model.Favorite + modelMap["favorite"] = *model.Favorite } return modelMap, nil } -func dataSourceIBMCdTektonPipelineTriggerScmTriggerToMap(model *cdtektonpipelinev2.TriggerScmTrigger) (map[string]interface{}, error) { +func DataSourceIBMCdTektonPipelineTriggerScmTriggerToMap(model *cdtektonpipelinev2.TriggerScmTrigger) (map[string]interface{}, error) { modelMap := make(map[string]interface{}) - modelMap["type"] = model.Type - modelMap["name"] = model.Name + modelMap["type"] = *model.Type + modelMap["name"] = *model.Name if model.Href != nil { - modelMap["href"] = model.Href + modelMap["href"] = *model.Href } - modelMap["event_listener"] = model.EventListener - modelMap["id"] = model.ID + modelMap["event_listener"] = *model.EventListener + modelMap["id"] = *model.ID if model.Properties != nil { properties := []map[string]interface{}{} for _, propertiesItem := range model.Properties { - propertiesItemMap, err := dataSourceIBMCdTektonPipelineTriggerPropertyToMap(&propertiesItem) + propertiesItemMap, err := DataSourceIBMCdTektonPipelineTriggerPropertyToMap(&propertiesItem) // #nosec G601 if err != nil { return modelMap, err } @@ -998,7 +1000,7 @@ func dataSourceIBMCdTektonPipelineTriggerScmTriggerToMap(model *cdtektonpipeline modelMap["tags"] = model.Tags } if model.Worker != nil { - workerMap, err := dataSourceIBMCdTektonPipelineWorkerToMap(model.Worker) + workerMap, err := DataSourceIBMCdTektonPipelineWorkerToMap(model.Worker) if err != nil { return modelMap, err } @@ -1007,15 +1009,15 @@ func dataSourceIBMCdTektonPipelineTriggerScmTriggerToMap(model *cdtektonpipeline if model.MaxConcurrentRuns != nil { modelMap["max_concurrent_runs"] = flex.IntValue(model.MaxConcurrentRuns) } - modelMap["enabled"] = model.Enabled + modelMap["enabled"] = *model.Enabled if model.Favorite != nil { - modelMap["favorite"] = model.Favorite + modelMap["favorite"] = *model.Favorite } if model.EnableEventsFromForks != nil { - modelMap["enable_events_from_forks"] = model.EnableEventsFromForks + modelMap["enable_events_from_forks"] = *model.EnableEventsFromForks } if model.Source != nil { - sourceMap, err := dataSourceIBMCdTektonPipelineTriggerSourceToMap(model.Source) + sourceMap, err := DataSourceIBMCdTektonPipelineTriggerSourceToMap(model.Source) if err != nil { return modelMap, err } @@ -1025,24 +1027,24 @@ func dataSourceIBMCdTektonPipelineTriggerScmTriggerToMap(model *cdtektonpipeline modelMap["events"] = model.Events } if model.Filter != nil { - modelMap["filter"] = model.Filter + modelMap["filter"] = *model.Filter } return modelMap, nil } -func dataSourceIBMCdTektonPipelineTriggerTimerTriggerToMap(model *cdtektonpipelinev2.TriggerTimerTrigger) (map[string]interface{}, error) { +func DataSourceIBMCdTektonPipelineTriggerTimerTriggerToMap(model *cdtektonpipelinev2.TriggerTimerTrigger) (map[string]interface{}, error) { modelMap := make(map[string]interface{}) - modelMap["type"] = model.Type - modelMap["name"] = model.Name + modelMap["type"] = *model.Type + modelMap["name"] = *model.Name if model.Href != nil { - modelMap["href"] = model.Href + modelMap["href"] = *model.Href } - modelMap["event_listener"] = model.EventListener - modelMap["id"] = model.ID + modelMap["event_listener"] = *model.EventListener + modelMap["id"] = *model.ID if model.Properties != nil { properties := []map[string]interface{}{} for _, propertiesItem := range model.Properties { - propertiesItemMap, err := dataSourceIBMCdTektonPipelineTriggerPropertyToMap(&propertiesItem) + propertiesItemMap, err := DataSourceIBMCdTektonPipelineTriggerPropertyToMap(&propertiesItem) // #nosec G601 if err != nil { return modelMap, err } @@ -1054,7 +1056,7 @@ func dataSourceIBMCdTektonPipelineTriggerTimerTriggerToMap(model *cdtektonpipeli modelMap["tags"] = model.Tags } if model.Worker != nil { - workerMap, err := dataSourceIBMCdTektonPipelineWorkerToMap(model.Worker) + workerMap, err := DataSourceIBMCdTektonPipelineWorkerToMap(model.Worker) if err != nil { return modelMap, err } @@ -1063,32 +1065,32 @@ func dataSourceIBMCdTektonPipelineTriggerTimerTriggerToMap(model *cdtektonpipeli if model.MaxConcurrentRuns != nil { modelMap["max_concurrent_runs"] = flex.IntValue(model.MaxConcurrentRuns) } - modelMap["enabled"] = model.Enabled + modelMap["enabled"] = *model.Enabled if model.Favorite != nil { - modelMap["favorite"] = model.Favorite + modelMap["favorite"] = *model.Favorite } if model.Cron != nil { - modelMap["cron"] = model.Cron + modelMap["cron"] = *model.Cron } if model.Timezone != nil { - modelMap["timezone"] = model.Timezone + modelMap["timezone"] = *model.Timezone } return modelMap, nil } -func dataSourceIBMCdTektonPipelineTriggerGenericTriggerToMap(model *cdtektonpipelinev2.TriggerGenericTrigger) (map[string]interface{}, error) { +func DataSourceIBMCdTektonPipelineTriggerGenericTriggerToMap(model *cdtektonpipelinev2.TriggerGenericTrigger) (map[string]interface{}, error) { modelMap := make(map[string]interface{}) - modelMap["type"] = model.Type - modelMap["name"] = model.Name + modelMap["type"] = *model.Type + modelMap["name"] = *model.Name if model.Href != nil { - modelMap["href"] = model.Href + modelMap["href"] = *model.Href } - modelMap["event_listener"] = model.EventListener - modelMap["id"] = model.ID + modelMap["event_listener"] = *model.EventListener + modelMap["id"] = *model.ID if model.Properties != nil { properties := []map[string]interface{}{} for _, propertiesItem := range model.Properties { - propertiesItemMap, err := dataSourceIBMCdTektonPipelineTriggerPropertyToMap(&propertiesItem) + propertiesItemMap, err := DataSourceIBMCdTektonPipelineTriggerPropertyToMap(&propertiesItem) // #nosec G601 if err != nil { return modelMap, err } @@ -1100,7 +1102,7 @@ func dataSourceIBMCdTektonPipelineTriggerGenericTriggerToMap(model *cdtektonpipe modelMap["tags"] = model.Tags } if model.Worker != nil { - workerMap, err := dataSourceIBMCdTektonPipelineWorkerToMap(model.Worker) + workerMap, err := DataSourceIBMCdTektonPipelineWorkerToMap(model.Worker) if err != nil { return modelMap, err } @@ -1109,22 +1111,22 @@ func dataSourceIBMCdTektonPipelineTriggerGenericTriggerToMap(model *cdtektonpipe if model.MaxConcurrentRuns != nil { modelMap["max_concurrent_runs"] = flex.IntValue(model.MaxConcurrentRuns) } - modelMap["enabled"] = model.Enabled + modelMap["enabled"] = *model.Enabled if model.Favorite != nil { - modelMap["favorite"] = model.Favorite + modelMap["favorite"] = *model.Favorite } if model.Secret != nil { - secretMap, err := dataSourceIBMCdTektonPipelineGenericSecretToMap(model.Secret) + secretMap, err := DataSourceIBMCdTektonPipelineGenericSecretToMap(model.Secret) if err != nil { return modelMap, err } modelMap["secret"] = []map[string]interface{}{secretMap} } if model.WebhookURL != nil { - modelMap["webhook_url"] = model.WebhookURL + modelMap["webhook_url"] = *model.WebhookURL } if model.Filter != nil { - modelMap["filter"] = model.Filter + modelMap["filter"] = *model.Filter } return modelMap, nil } diff --git a/ibm/service/cdtektonpipeline/data_source_ibm_cd_tekton_pipeline_definition.go b/ibm/service/cdtektonpipeline/data_source_ibm_cd_tekton_pipeline_definition.go index 5e7ec4cf81..712f6b937f 100644 --- a/ibm/service/cdtektonpipeline/data_source_ibm_cd_tekton_pipeline_definition.go +++ b/ibm/service/cdtektonpipeline/data_source_ibm_cd_tekton_pipeline_definition.go @@ -1,6 +1,10 @@ // Copyright IBM Corp. 2024 All Rights Reserved. // Licensed under the Mozilla Public License v2.0 +/* + * IBM OpenAPI Terraform Generator Version: 3.95.2-120e65bc-20240924-152329 + */ + package cdtektonpipeline import ( @@ -12,7 +16,9 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" + "github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex" "github.com/IBM/continuous-delivery-go-sdk/cdtektonpipelinev2" + "github.com/IBM/go-sdk-core/v5/core" ) func DataSourceIBMCdTektonPipelineDefinition() *schema.Resource { @@ -99,7 +105,9 @@ func DataSourceIBMCdTektonPipelineDefinition() *schema.Resource { func dataSourceIBMCdTektonPipelineDefinitionRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { cdTektonPipelineClient, err := meta.(conns.ClientSession).CdTektonPipelineV2() if err != nil { - return diag.FromErr(err) + tfErr := flex.DiscriminatedTerraformErrorf(err, err.Error(), "(Data) ibm_cd_tekton_pipeline_definition", "read", "initialize-client") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } getTektonPipelineDefinitionOptions := &cdtektonpipelinev2.GetTektonPipelineDefinitionOptions{} @@ -107,37 +115,38 @@ func dataSourceIBMCdTektonPipelineDefinitionRead(context context.Context, d *sch getTektonPipelineDefinitionOptions.SetPipelineID(d.Get("pipeline_id").(string)) getTektonPipelineDefinitionOptions.SetDefinitionID(d.Get("definition_id").(string)) - definition, response, err := cdTektonPipelineClient.GetTektonPipelineDefinitionWithContext(context, getTektonPipelineDefinitionOptions) + definition, _, err := cdTektonPipelineClient.GetTektonPipelineDefinitionWithContext(context, getTektonPipelineDefinitionOptions) if err != nil { - log.Printf("[DEBUG] GetTektonPipelineDefinitionWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("GetTektonPipelineDefinitionWithContext failed %s\n%s", err, response)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("GetTektonPipelineDefinitionWithContext failed: %s", err.Error()), "(Data) ibm_cd_tekton_pipeline_definition", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } d.SetId(fmt.Sprintf("%s/%s", *getTektonPipelineDefinitionOptions.PipelineID, *getTektonPipelineDefinitionOptions.DefinitionID)) source := []map[string]interface{}{} - if definition.Source != nil { - modelMap, err := dataSourceIBMCdTektonPipelineDefinitionDefinitionSourceToMap(definition.Source) - if err != nil { - return diag.FromErr(err) - } - source = append(source, modelMap) + sourceMap, err := DataSourceIBMCdTektonPipelineDefinitionDefinitionSourceToMap(definition.Source) + if err != nil { + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "(Data) ibm_cd_tekton_pipeline_definition", "read", "source-to-map").GetDiag() } + source = append(source, sourceMap) if err = d.Set("source", source); err != nil { - return diag.FromErr(fmt.Errorf("Error setting source %s", err)) + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting source: %s", err), "(Data) ibm_cd_tekton_pipeline_definition", "read", "set-source").GetDiag() } - if err = d.Set("href", definition.Href); err != nil { - return diag.FromErr(fmt.Errorf("Error setting href: %s", err)) + if !core.IsNil(definition.Href) { + if err = d.Set("href", definition.Href); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting href: %s", err), "(Data) ibm_cd_tekton_pipeline_definition", "read", "set-href").GetDiag() + } } return nil } -func dataSourceIBMCdTektonPipelineDefinitionDefinitionSourceToMap(model *cdtektonpipelinev2.DefinitionSource) (map[string]interface{}, error) { +func DataSourceIBMCdTektonPipelineDefinitionDefinitionSourceToMap(model *cdtektonpipelinev2.DefinitionSource) (map[string]interface{}, error) { modelMap := make(map[string]interface{}) - modelMap["type"] = model.Type - propertiesMap, err := dataSourceIBMCdTektonPipelineDefinitionDefinitionSourcePropertiesToMap(model.Properties) + modelMap["type"] = *model.Type + propertiesMap, err := DataSourceIBMCdTektonPipelineDefinitionDefinitionSourcePropertiesToMap(model.Properties) if err != nil { return modelMap, err } @@ -145,18 +154,18 @@ func dataSourceIBMCdTektonPipelineDefinitionDefinitionSourceToMap(model *cdtekto return modelMap, nil } -func dataSourceIBMCdTektonPipelineDefinitionDefinitionSourcePropertiesToMap(model *cdtektonpipelinev2.DefinitionSourceProperties) (map[string]interface{}, error) { +func DataSourceIBMCdTektonPipelineDefinitionDefinitionSourcePropertiesToMap(model *cdtektonpipelinev2.DefinitionSourceProperties) (map[string]interface{}, error) { modelMap := make(map[string]interface{}) - modelMap["url"] = model.URL + modelMap["url"] = *model.URL if model.Branch != nil { - modelMap["branch"] = model.Branch + modelMap["branch"] = *model.Branch } if model.Tag != nil { - modelMap["tag"] = model.Tag + modelMap["tag"] = *model.Tag } - modelMap["path"] = model.Path + modelMap["path"] = *model.Path if model.Tool != nil { - toolMap, err := dataSourceIBMCdTektonPipelineDefinitionToolToMap(model.Tool) + toolMap, err := DataSourceIBMCdTektonPipelineDefinitionToolToMap(model.Tool) if err != nil { return modelMap, err } @@ -165,8 +174,8 @@ func dataSourceIBMCdTektonPipelineDefinitionDefinitionSourcePropertiesToMap(mode return modelMap, nil } -func dataSourceIBMCdTektonPipelineDefinitionToolToMap(model *cdtektonpipelinev2.Tool) (map[string]interface{}, error) { +func DataSourceIBMCdTektonPipelineDefinitionToolToMap(model *cdtektonpipelinev2.Tool) (map[string]interface{}, error) { modelMap := make(map[string]interface{}) - modelMap["id"] = model.ID + modelMap["id"] = *model.ID return modelMap, nil } diff --git a/ibm/service/cdtektonpipeline/data_source_ibm_cd_tekton_pipeline_definition_test.go b/ibm/service/cdtektonpipeline/data_source_ibm_cd_tekton_pipeline_definition_test.go index 892422d78d..6c3942add5 100644 --- a/ibm/service/cdtektonpipeline/data_source_ibm_cd_tekton_pipeline_definition_test.go +++ b/ibm/service/cdtektonpipeline/data_source_ibm_cd_tekton_pipeline_definition_test.go @@ -1,6 +1,10 @@ // Copyright IBM Corp. 2024 All Rights Reserved. // Licensed under the Mozilla Public License v2.0 +/* + * IBM OpenAPI Terraform Generator Version: 3.95.2-120e65bc-20240924-152329 + */ + package cdtektonpipeline_test import ( @@ -11,6 +15,10 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" acc "github.com/IBM-Cloud/terraform-provider-ibm/ibm/acctest" + "github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/cdtektonpipeline" + "github.com/IBM/continuous-delivery-go-sdk/cdtektonpipelinev2" + "github.com/IBM/go-sdk-core/v5/core" + "github.com/stretchr/testify/assert" ) func TestAccIBMCdTektonPipelineDefinitionDataSourceBasic(t *testing.T) { @@ -22,10 +30,10 @@ func TestAccIBMCdTektonPipelineDefinitionDataSourceBasic(t *testing.T) { resource.TestStep{ Config: testAccCheckIBMCdTektonPipelineDefinitionDataSourceConfigBasic(""), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_definition.cd_tekton_pipeline_definition", "id"), - resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_definition.cd_tekton_pipeline_definition", "pipeline_id"), - resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_definition.cd_tekton_pipeline_definition", "definition_id"), - resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_definition.cd_tekton_pipeline_definition", "source.#"), + resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_definition.cd_tekton_pipeline_definition_instance", "id"), + resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_definition.cd_tekton_pipeline_definition_instance", "pipeline_id"), + resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_definition.cd_tekton_pipeline_definition_instance", "definition_id"), + resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_definition.cd_tekton_pipeline_definition_instance", "source.#"), ), }, }, @@ -49,7 +57,7 @@ func testAccCheckIBMCdTektonPipelineDefinitionDataSourceConfigBasic(definitionPi name = "pipeline-name" } } - resource "ibm_cd_tekton_pipeline" "cd_tekton_pipeline" { + resource "ibm_cd_tekton_pipeline" "cd_tekton_pipeline_instance" { pipeline_id = ibm_cd_toolchain_tool_pipeline.ibm_cd_toolchain_tool_pipeline.tool_id next_build_number = 5 worker { @@ -68,8 +76,8 @@ func testAccCheckIBMCdTektonPipelineDefinitionDataSourceConfigBasic(definitionPi } parameters {} } - resource "ibm_cd_tekton_pipeline_definition" "cd_tekton_pipeline_definition" { - pipeline_id = ibm_cd_tekton_pipeline.cd_tekton_pipeline.pipeline_id + resource "ibm_cd_tekton_pipeline_definition" "cd_tekton_pipeline_definition_instance" { + pipeline_id = ibm_cd_tekton_pipeline.cd_tekton_pipeline_instance.pipeline_id source { type = "git" properties { @@ -79,12 +87,96 @@ func testAccCheckIBMCdTektonPipelineDefinitionDataSourceConfigBasic(definitionPi } } depends_on = [ - ibm_cd_tekton_pipeline.cd_tekton_pipeline + ibm_cd_tekton_pipeline.cd_tekton_pipeline_instance ] } - data "ibm_cd_tekton_pipeline_definition" "cd_tekton_pipeline_definition" { - pipeline_id = ibm_cd_tekton_pipeline_definition.cd_tekton_pipeline_definition.pipeline_id - definition_id = ibm_cd_tekton_pipeline_definition.cd_tekton_pipeline_definition.definition_id + data "ibm_cd_tekton_pipeline_definition" "cd_tekton_pipeline_definition_instance" { + pipeline_id = ibm_cd_tekton_pipeline_definition.cd_tekton_pipeline_definition_instance.pipeline_id + definition_id = ibm_cd_tekton_pipeline_definition.cd_tekton_pipeline_definition_instance.definition_id } `, rgName, tcName) } + +func TestDataSourceIBMCdTektonPipelineDefinitionDefinitionSourceToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + toolModel := make(map[string]interface{}) + toolModel["id"] = "testString" + + definitionSourcePropertiesModel := make(map[string]interface{}) + definitionSourcePropertiesModel["url"] = "testString" + definitionSourcePropertiesModel["branch"] = "testString" + definitionSourcePropertiesModel["tag"] = "testString" + definitionSourcePropertiesModel["path"] = "testString" + definitionSourcePropertiesModel["tool"] = []map[string]interface{}{toolModel} + + model := make(map[string]interface{}) + model["type"] = "testString" + model["properties"] = []map[string]interface{}{definitionSourcePropertiesModel} + + assert.Equal(t, result, model) + } + + toolModel := new(cdtektonpipelinev2.Tool) + toolModel.ID = core.StringPtr("testString") + + definitionSourcePropertiesModel := new(cdtektonpipelinev2.DefinitionSourceProperties) + definitionSourcePropertiesModel.URL = core.StringPtr("testString") + definitionSourcePropertiesModel.Branch = core.StringPtr("testString") + definitionSourcePropertiesModel.Tag = core.StringPtr("testString") + definitionSourcePropertiesModel.Path = core.StringPtr("testString") + definitionSourcePropertiesModel.Tool = toolModel + + model := new(cdtektonpipelinev2.DefinitionSource) + model.Type = core.StringPtr("testString") + model.Properties = definitionSourcePropertiesModel + + result, err := cdtektonpipeline.DataSourceIBMCdTektonPipelineDefinitionDefinitionSourceToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestDataSourceIBMCdTektonPipelineDefinitionDefinitionSourcePropertiesToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + toolModel := make(map[string]interface{}) + toolModel["id"] = "testString" + + model := make(map[string]interface{}) + model["url"] = "testString" + model["branch"] = "testString" + model["tag"] = "testString" + model["path"] = "testString" + model["tool"] = []map[string]interface{}{toolModel} + + assert.Equal(t, result, model) + } + + toolModel := new(cdtektonpipelinev2.Tool) + toolModel.ID = core.StringPtr("testString") + + model := new(cdtektonpipelinev2.DefinitionSourceProperties) + model.URL = core.StringPtr("testString") + model.Branch = core.StringPtr("testString") + model.Tag = core.StringPtr("testString") + model.Path = core.StringPtr("testString") + model.Tool = toolModel + + result, err := cdtektonpipeline.DataSourceIBMCdTektonPipelineDefinitionDefinitionSourcePropertiesToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestDataSourceIBMCdTektonPipelineDefinitionToolToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + model := make(map[string]interface{}) + model["id"] = "testString" + + assert.Equal(t, result, model) + } + + model := new(cdtektonpipelinev2.Tool) + model.ID = core.StringPtr("testString") + + result, err := cdtektonpipeline.DataSourceIBMCdTektonPipelineDefinitionToolToMap(model) + assert.Nil(t, err) + checkResult(result) +} diff --git a/ibm/service/cdtektonpipeline/data_source_ibm_cd_tekton_pipeline_property.go b/ibm/service/cdtektonpipeline/data_source_ibm_cd_tekton_pipeline_property.go index 5d1b739bd4..0b83e85ed7 100644 --- a/ibm/service/cdtektonpipeline/data_source_ibm_cd_tekton_pipeline_property.go +++ b/ibm/service/cdtektonpipeline/data_source_ibm_cd_tekton_pipeline_property.go @@ -1,6 +1,10 @@ // Copyright IBM Corp. 2024 All Rights Reserved. // Licensed under the Mozilla Public License v2.0 +/* + * IBM OpenAPI Terraform Generator Version: 3.95.2-120e65bc-20240924-152329 + */ + package cdtektonpipeline import ( @@ -12,7 +16,9 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" + "github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex" "github.com/IBM/continuous-delivery-go-sdk/cdtektonpipelinev2" + "github.com/IBM/go-sdk-core/v5/core" ) func DataSourceIBMCdTektonPipelineProperty() *schema.Resource { @@ -75,7 +81,9 @@ func DataSourceIBMCdTektonPipelineProperty() *schema.Resource { func dataSourceIBMCdTektonPipelinePropertyRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { cdTektonPipelineClient, err := meta.(conns.ClientSession).CdTektonPipelineV2() if err != nil { - return diag.FromErr(err) + tfErr := flex.DiscriminatedTerraformErrorf(err, err.Error(), "(Data) ibm_cd_tekton_pipeline_property", "read", "initialize-client") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } getTektonPipelinePropertyOptions := &cdtektonpipelinev2.GetTektonPipelinePropertyOptions{} @@ -83,41 +91,60 @@ func dataSourceIBMCdTektonPipelinePropertyRead(context context.Context, d *schem getTektonPipelinePropertyOptions.SetPipelineID(d.Get("pipeline_id").(string)) getTektonPipelinePropertyOptions.SetPropertyName(d.Get("property_name").(string)) - property, response, err := cdTektonPipelineClient.GetTektonPipelinePropertyWithContext(context, getTektonPipelinePropertyOptions) + property, _, err := cdTektonPipelineClient.GetTektonPipelinePropertyWithContext(context, getTektonPipelinePropertyOptions) if err != nil { - log.Printf("[DEBUG] GetTektonPipelinePropertyWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("GetTektonPipelinePropertyWithContext failed %s\n%s", err, response)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("GetTektonPipelinePropertyWithContext failed: %s", err.Error()), "(Data) ibm_cd_tekton_pipeline_property", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } d.SetId(fmt.Sprintf("%s/%s", *getTektonPipelinePropertyOptions.PipelineID, *getTektonPipelinePropertyOptions.PropertyName)) if err = d.Set("name", property.Name); err != nil { - return diag.FromErr(fmt.Errorf("Error setting name: %s", err)) + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting name: %s", err), "(Data) ibm_cd_tekton_pipeline_property", "read", "set-name").GetDiag() } - if err = d.Set("value", property.Value); err != nil { - return diag.FromErr(fmt.Errorf("Error setting value: %s", err)) + if !core.IsNil(property.Value) { + if err = d.Set("value", property.Value); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting value: %s", err), "(Data) ibm_cd_tekton_pipeline_property", "read", "set-value").GetDiag() + } } - if err = d.Set("href", property.Href); err != nil { - return diag.FromErr(fmt.Errorf("Error setting href: %s", err)) + if !core.IsNil(property.Href) { + if err = d.Set("href", property.Href); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting href: %s", err), "(Data) ibm_cd_tekton_pipeline_property", "read", "set-href").GetDiag() + } + } + + if !core.IsNil(property.Enum) { + enum := []interface{}{} + for _, enumItem := range property.Enum { + enum = append(enum, enumItem) + } + if err = d.Set("enum", enum); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting enum: %s", err), "(Data) ibm_cd_tekton_pipeline_property", "read", "set-enum").GetDiag() + } } if err = d.Set("type", property.Type); err != nil { - return diag.FromErr(fmt.Errorf("Error setting type: %s", err)) + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting type: %s", err), "(Data) ibm_cd_tekton_pipeline_property", "read", "set-type").GetDiag() } - if err = d.Set("locked", property.Locked); err != nil { - return diag.FromErr(fmt.Errorf("Error setting locked: %s", err)) + if !core.IsNil(property.Locked) { + if err = d.Set("locked", property.Locked); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting locked: %s", err), "(Data) ibm_cd_tekton_pipeline_property", "read", "set-locked").GetDiag() + } } - if err = d.Set("path", property.Path); err != nil { - return diag.FromErr(fmt.Errorf("Error setting path: %s", err)) + if !core.IsNil(property.Path) { + if err = d.Set("path", property.Path); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting path: %s", err), "(Data) ibm_cd_tekton_pipeline_property", "read", "set-path").GetDiag() + } } - if property.Enum != nil { + if !core.IsNil(property.Enum) { if err = d.Set("enum", property.Enum); err != nil { - return diag.FromErr(fmt.Errorf("Error setting enum: %s", err)) + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting enum: %s", err), "(Data) ibm_cd_tekton_pipeline_property", "read", "set-enum").GetDiag() } } diff --git a/ibm/service/cdtektonpipeline/data_source_ibm_cd_tekton_pipeline_property_test.go b/ibm/service/cdtektonpipeline/data_source_ibm_cd_tekton_pipeline_property_test.go index c29ce37471..3a5ead5682 100644 --- a/ibm/service/cdtektonpipeline/data_source_ibm_cd_tekton_pipeline_property_test.go +++ b/ibm/service/cdtektonpipeline/data_source_ibm_cd_tekton_pipeline_property_test.go @@ -1,6 +1,10 @@ // Copyright IBM Corp. 2024 All Rights Reserved. // Licensed under the Mozilla Public License v2.0 +/* + * IBM OpenAPI Terraform Generator Version: 3.95.2-120e65bc-20240924-152329 + */ + package cdtektonpipeline_test import ( @@ -24,11 +28,11 @@ func TestAccIBMCdTektonPipelinePropertyDataSourceBasic(t *testing.T) { resource.TestStep{ Config: testAccCheckIBMCdTektonPipelinePropertyDataSourceConfigBasic("", propertyName, propertyType), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_property.cd_tekton_pipeline_property", "id"), - resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_property.cd_tekton_pipeline_property", "pipeline_id"), - resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_property.cd_tekton_pipeline_property", "property_name"), - resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_property.cd_tekton_pipeline_property", "name"), - resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_property.cd_tekton_pipeline_property", "type"), + resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_property.cd_tekton_pipeline_property_instance", "id"), + resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_property.cd_tekton_pipeline_property_instance", "pipeline_id"), + resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_property.cd_tekton_pipeline_property_instance", "property_name"), + resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_property.cd_tekton_pipeline_property_instance", "name"), + resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_property.cd_tekton_pipeline_property_instance", "type"), ), }, }, @@ -37,8 +41,8 @@ func TestAccIBMCdTektonPipelinePropertyDataSourceBasic(t *testing.T) { func TestAccIBMCdTektonPipelinePropertyDataSourceAllArgs(t *testing.T) { propertyName := fmt.Sprintf("tf_name_%d", acctest.RandIntRange(10, 100)) - propertyType := "text" propertyValue := fmt.Sprintf("tf_value_%d", acctest.RandIntRange(10, 100)) + propertyType := "text" propertyLocked := "true" propertyPath := fmt.Sprintf("tf_path_%d", acctest.RandIntRange(10, 100)) @@ -47,16 +51,16 @@ func TestAccIBMCdTektonPipelinePropertyDataSourceAllArgs(t *testing.T) { Providers: acc.TestAccProviders, Steps: []resource.TestStep{ resource.TestStep{ - Config: testAccCheckIBMCdTektonPipelinePropertyDataSourceConfig("", propertyName, propertyType, propertyValue, propertyLocked, propertyPath), + Config: testAccCheckIBMCdTektonPipelinePropertyDataSourceConfig("", propertyName, propertyValue, propertyType, propertyLocked, propertyPath), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_property.cd_tekton_pipeline_property", "id"), - resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_property.cd_tekton_pipeline_property", "pipeline_id"), - resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_property.cd_tekton_pipeline_property", "property_name"), - resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_property.cd_tekton_pipeline_property", "name"), - resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_property.cd_tekton_pipeline_property", "value"), - resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_property.cd_tekton_pipeline_property", "href"), - resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_property.cd_tekton_pipeline_property", "type"), - resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_property.cd_tekton_pipeline_property", "locked"), + resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_property.cd_tekton_pipeline_property_instance", "id"), + resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_property.cd_tekton_pipeline_property_instance", "pipeline_id"), + resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_property.cd_tekton_pipeline_property_instance", "property_name"), + resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_property.cd_tekton_pipeline_property_instance", "name"), + resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_property.cd_tekton_pipeline_property_instance", "value"), + resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_property.cd_tekton_pipeline_property_instance", "href"), + resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_property.cd_tekton_pipeline_property_instance", "type"), + resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_property.cd_tekton_pipeline_property_instance", "locked"), ), }, }, @@ -80,7 +84,7 @@ func testAccCheckIBMCdTektonPipelinePropertyDataSourceConfigBasic(propertyPipeli name = "pipeline-name" } } - resource "ibm_cd_tekton_pipeline" "cd_tekton_pipeline" { + resource "ibm_cd_tekton_pipeline" "cd_tekton_pipeline_instance" { pipeline_id = ibm_cd_toolchain_tool_pipeline.ibm_cd_toolchain_tool_pipeline.tool_id next_build_number = 5 worker { @@ -90,23 +94,23 @@ func testAccCheckIBMCdTektonPipelinePropertyDataSourceConfigBasic(propertyPipeli ibm_cd_toolchain_tool_pipeline.ibm_cd_toolchain_tool_pipeline ] } - resource "ibm_cd_tekton_pipeline_property" "cd_tekton_pipeline_property" { - pipeline_id = ibm_cd_tekton_pipeline.cd_tekton_pipeline.pipeline_id + resource "ibm_cd_tekton_pipeline_property" "cd_tekton_pipeline_property_instance" { + pipeline_id = ibm_cd_tekton_pipeline.cd_tekton_pipeline_instance.pipeline_id name = "property1" type = "text" value = "prop1" depends_on = [ - ibm_cd_tekton_pipeline.cd_tekton_pipeline + ibm_cd_tekton_pipeline.cd_tekton_pipeline_instance ] } - data "ibm_cd_tekton_pipeline_property" "cd_tekton_pipeline_property" { - pipeline_id = ibm_cd_tekton_pipeline.cd_tekton_pipeline.pipeline_id - property_name = ibm_cd_tekton_pipeline_property.cd_tekton_pipeline_property.name + data "ibm_cd_tekton_pipeline_property" "cd_tekton_pipeline_property_instance" { + pipeline_id = ibm_cd_tekton_pipeline.cd_tekton_pipeline_instance.pipeline_id + property_name = ibm_cd_tekton_pipeline_property.cd_tekton_pipeline_property_instance.name } `, rgName, tcName) } -func testAccCheckIBMCdTektonPipelinePropertyDataSourceConfig(propertyPipelineID string, propertyName string, propertyType string, propertyValue string, propertyLocked string, propertyPath string) string { +func testAccCheckIBMCdTektonPipelinePropertyDataSourceConfig(propertyPipelineID string, propertyName string, propertyValue string, propertyType string, propertyLocked string, propertyPath string) string { rgName := acc.CdResourceGroupName tcName := fmt.Sprintf("tf_name_%d", acctest.RandIntRange(10, 100)) return fmt.Sprintf(` @@ -123,7 +127,7 @@ func testAccCheckIBMCdTektonPipelinePropertyDataSourceConfig(propertyPipelineID name = "pipeline-name" } } - resource "ibm_cd_tekton_pipeline" "cd_tekton_pipeline" { + resource "ibm_cd_tekton_pipeline" "cd_tekton_pipeline_instance" { pipeline_id = ibm_cd_toolchain_tool_pipeline.ibm_cd_toolchain_tool_pipeline.tool_id next_build_number = 5 worker { @@ -133,19 +137,19 @@ func testAccCheckIBMCdTektonPipelinePropertyDataSourceConfig(propertyPipelineID ibm_cd_toolchain_tool_pipeline.ibm_cd_toolchain_tool_pipeline ] } - resource "ibm_cd_tekton_pipeline_property" "cd_tekton_pipeline_property" { - pipeline_id = ibm_cd_tekton_pipeline.cd_tekton_pipeline.pipeline_id + resource "ibm_cd_tekton_pipeline_property" "cd_tekton_pipeline_property_instance" { + pipeline_id = ibm_cd_tekton_pipeline.cd_tekton_pipeline_instance.pipeline_id name = "%s" type = "text" value = "%s" locked = "%s" depends_on = [ - ibm_cd_tekton_pipeline.cd_tekton_pipeline + ibm_cd_tekton_pipeline.cd_tekton_pipeline_instance ] } - data "ibm_cd_tekton_pipeline_property" "cd_tekton_pipeline_property" { - pipeline_id = ibm_cd_tekton_pipeline.cd_tekton_pipeline.pipeline_id - property_name = ibm_cd_tekton_pipeline_property.cd_tekton_pipeline_property.name + data "ibm_cd_tekton_pipeline_property" "cd_tekton_pipeline_property_instance" { + pipeline_id = ibm_cd_tekton_pipeline.cd_tekton_pipeline_instance.pipeline_id + property_name = ibm_cd_tekton_pipeline_property.cd_tekton_pipeline_property_instance.name } `, rgName, tcName, propertyName, propertyValue, propertyLocked) } diff --git a/ibm/service/cdtektonpipeline/data_source_ibm_cd_tekton_pipeline_test.go b/ibm/service/cdtektonpipeline/data_source_ibm_cd_tekton_pipeline_test.go index 17d29c8447..55152a819b 100644 --- a/ibm/service/cdtektonpipeline/data_source_ibm_cd_tekton_pipeline_test.go +++ b/ibm/service/cdtektonpipeline/data_source_ibm_cd_tekton_pipeline_test.go @@ -1,6 +1,10 @@ // Copyright IBM Corp. 2024 All Rights Reserved. // Licensed under the Mozilla Public License v2.0 +/* + * IBM OpenAPI Terraform Generator Version: 3.95.2-120e65bc-20240924-152329 + */ + package cdtektonpipeline_test import ( @@ -11,6 +15,10 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" acc "github.com/IBM-Cloud/terraform-provider-ibm/ibm/acctest" + "github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/cdtektonpipeline" + "github.com/IBM/continuous-delivery-go-sdk/cdtektonpipelinev2" + "github.com/IBM/go-sdk-core/v5/core" + "github.com/stretchr/testify/assert" ) func TestAccIBMCdTektonPipelineDataSourceBasic(t *testing.T) { @@ -21,23 +29,22 @@ func TestAccIBMCdTektonPipelineDataSourceBasic(t *testing.T) { resource.TestStep{ Config: testAccCheckIBMCdTektonPipelineDataSourceConfigBasic(), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline.cd_tekton_pipeline", "id"), - resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline.cd_tekton_pipeline", "id"), - resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline.cd_tekton_pipeline", "name"), - resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline.cd_tekton_pipeline", "status"), - resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline.cd_tekton_pipeline", "resource_group.#"), - resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline.cd_tekton_pipeline", "toolchain.#"), - resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline.cd_tekton_pipeline", "definitions.#"), - resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline.cd_tekton_pipeline", "properties.#"), - resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline.cd_tekton_pipeline", "updated_at"), - resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline.cd_tekton_pipeline", "created_at"), - resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline.cd_tekton_pipeline", "triggers.#"), - resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline.cd_tekton_pipeline", "worker.#"), - resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline.cd_tekton_pipeline", "runs_url"), - resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline.cd_tekton_pipeline", "build_number"), - resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline.cd_tekton_pipeline", "enable_notifications"), - resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline.cd_tekton_pipeline", "enable_partial_cloning"), - resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline.cd_tekton_pipeline", "enabled"), + resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline.cd_tekton_pipeline_instance", "id"), + resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline.cd_tekton_pipeline_instance", "name"), + resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline.cd_tekton_pipeline_instance", "status"), + resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline.cd_tekton_pipeline_instance", "resource_group.#"), + resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline.cd_tekton_pipeline_instance", "toolchain.#"), + resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline.cd_tekton_pipeline_instance", "definitions.#"), + resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline.cd_tekton_pipeline_instance", "properties.#"), + resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline.cd_tekton_pipeline_instance", "updated_at"), + resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline.cd_tekton_pipeline_instance", "created_at"), + resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline.cd_tekton_pipeline_instance", "triggers.#"), + resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline.cd_tekton_pipeline_instance", "worker.#"), + resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline.cd_tekton_pipeline_instance", "runs_url"), + resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline.cd_tekton_pipeline_instance", "build_number"), + resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline.cd_tekton_pipeline_instance", "enable_notifications"), + resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline.cd_tekton_pipeline_instance", "enable_partial_cloning"), + resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline.cd_tekton_pipeline_instance", "enabled"), ), }, }, @@ -56,25 +63,24 @@ func TestAccIBMCdTektonPipelineDataSourceAllArgs(t *testing.T) { resource.TestStep{ Config: testAccCheckIBMCdTektonPipelineDataSourceConfig(tektonPipelineNextBuildNumber, tektonPipelineEnableNotifications, tektonPipelineEnablePartialCloning), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline.cd_tekton_pipeline", "id"), - resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline.cd_tekton_pipeline", "id"), - resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline.cd_tekton_pipeline", "name"), - resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline.cd_tekton_pipeline", "status"), - resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline.cd_tekton_pipeline", "resource_group.#"), - resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline.cd_tekton_pipeline", "toolchain.#"), - resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline.cd_tekton_pipeline", "definitions.#"), - resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline.cd_tekton_pipeline", "properties.#"), - resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline.cd_tekton_pipeline", "updated_at"), - resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline.cd_tekton_pipeline", "created_at"), - resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline.cd_tekton_pipeline", "triggers.#"), - resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline.cd_tekton_pipeline", "worker.#"), - resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline.cd_tekton_pipeline", "runs_url"), - resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline.cd_tekton_pipeline", "href"), - resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline.cd_tekton_pipeline", "build_number"), - resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline.cd_tekton_pipeline", "next_build_number"), - resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline.cd_tekton_pipeline", "enable_notifications"), - resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline.cd_tekton_pipeline", "enable_partial_cloning"), - resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline.cd_tekton_pipeline", "enabled"), + resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline.cd_tekton_pipeline_instance", "id"), + resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline.cd_tekton_pipeline_instance", "name"), + resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline.cd_tekton_pipeline_instance", "status"), + resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline.cd_tekton_pipeline_instance", "resource_group.#"), + resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline.cd_tekton_pipeline_instance", "toolchain.#"), + resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline.cd_tekton_pipeline_instance", "definitions.#"), + resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline.cd_tekton_pipeline_instance", "properties.#"), + resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline.cd_tekton_pipeline_instance", "updated_at"), + resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline.cd_tekton_pipeline_instance", "created_at"), + resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline.cd_tekton_pipeline_instance", "triggers.#"), + resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline.cd_tekton_pipeline_instance", "worker.#"), + resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline.cd_tekton_pipeline_instance", "runs_url"), + resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline.cd_tekton_pipeline_instance", "href"), + resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline.cd_tekton_pipeline_instance", "build_number"), + resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline.cd_tekton_pipeline_instance", "next_build_number"), + resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline.cd_tekton_pipeline_instance", "enable_notifications"), + resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline.cd_tekton_pipeline_instance", "enable_partial_cloning"), + resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline.cd_tekton_pipeline_instance", "enabled"), ), }, }, @@ -98,7 +104,7 @@ func testAccCheckIBMCdTektonPipelineDataSourceConfigBasic() string { name = "pipeline-name" } } - resource "ibm_cd_tekton_pipeline" "cd_tekton_pipeline" { + resource "ibm_cd_tekton_pipeline" "cd_tekton_pipeline_instance" { pipeline_id = ibm_cd_toolchain_tool_pipeline.ibm_cd_toolchain_tool_pipeline.tool_id next_build_number = 5 worker { @@ -108,8 +114,8 @@ func testAccCheckIBMCdTektonPipelineDataSourceConfigBasic() string { ibm_cd_toolchain_tool_pipeline.ibm_cd_toolchain_tool_pipeline ] } - data "ibm_cd_tekton_pipeline" "cd_tekton_pipeline" { - pipeline_id = ibm_cd_tekton_pipeline.cd_tekton_pipeline.pipeline_id + data "ibm_cd_tekton_pipeline" "cd_tekton_pipeline_instance" { + pipeline_id = ibm_cd_tekton_pipeline.cd_tekton_pipeline_instance.pipeline_id } `, rgName, tcName) } @@ -131,7 +137,7 @@ func testAccCheckIBMCdTektonPipelineDataSourceConfig(tektonPipelineNextBuildNumb name = "pipeline-name" } } - resource "ibm_cd_tekton_pipeline" "cd_tekton_pipeline" { + resource "ibm_cd_tekton_pipeline" "cd_tekton_pipeline_instance" { pipeline_id = ibm_cd_toolchain_tool_pipeline.ibm_cd_toolchain_tool_pipeline.tool_id next_build_number = %s enable_notifications = %s @@ -152,8 +158,8 @@ func testAccCheckIBMCdTektonPipelineDataSourceConfig(tektonPipelineNextBuildNumb } parameters {} } - resource "ibm_cd_tekton_pipeline_definition" "cd_tekton_pipeline_definition" { - pipeline_id = ibm_cd_tekton_pipeline.cd_tekton_pipeline.pipeline_id + resource "ibm_cd_tekton_pipeline_definition" "cd_tekton_pipeline_definition_instance" { + pipeline_id = ibm_cd_tekton_pipeline.cd_tekton_pipeline_instance.pipeline_id source { type = "git" properties { @@ -163,20 +169,800 @@ func testAccCheckIBMCdTektonPipelineDataSourceConfig(tektonPipelineNextBuildNumb } } depends_on = [ - ibm_cd_tekton_pipeline.cd_tekton_pipeline + ibm_cd_tekton_pipeline.cd_tekton_pipeline_instance ] } - resource "ibm_cd_tekton_pipeline_property" "cd_tekton_pipeline_property" { - pipeline_id = ibm_cd_tekton_pipeline.cd_tekton_pipeline.pipeline_id + resource "ibm_cd_tekton_pipeline_property" "cd_tekton_pipeline_property_instance" { + pipeline_id = ibm_cd_tekton_pipeline.cd_tekton_pipeline_instance.pipeline_id name = "property1" type = "text" value = "prop1" depends_on = [ - ibm_cd_tekton_pipeline.cd_tekton_pipeline + ibm_cd_tekton_pipeline.cd_tekton_pipeline_instance ] } - data "ibm_cd_tekton_pipeline" "cd_tekton_pipeline" { - pipeline_id = ibm_cd_tekton_pipeline.cd_tekton_pipeline.pipeline_id + data "ibm_cd_tekton_pipeline" "cd_tekton_pipeline_instance" { + pipeline_id = ibm_cd_tekton_pipeline.cd_tekton_pipeline_instance.pipeline_id } `, rgName, tcName, tektonPipelineNextBuildNumber, tektonPipelineEnableNotifications, tektonPipelineEnablePartialCloning) } + +func TestDataSourceIBMCdTektonPipelineResourceGroupReferenceToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + model := make(map[string]interface{}) + model["id"] = "testString" + + assert.Equal(t, result, model) + } + + model := new(cdtektonpipelinev2.ResourceGroupReference) + model.ID = core.StringPtr("testString") + + result, err := cdtektonpipeline.DataSourceIBMCdTektonPipelineResourceGroupReferenceToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestDataSourceIBMCdTektonPipelineToolchainReferenceToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + model := make(map[string]interface{}) + model["id"] = "testString" + model["crn"] = "crn:v1:staging:public:toolchain:us-south:a/0ba224679d6c697f9baee5e14ade83ac:bf5fa00f-ddef-4298-b87b-aa8b6da0e1a6::" + + assert.Equal(t, result, model) + } + + model := new(cdtektonpipelinev2.ToolchainReference) + model.ID = core.StringPtr("testString") + model.CRN = core.StringPtr("crn:v1:staging:public:toolchain:us-south:a/0ba224679d6c697f9baee5e14ade83ac:bf5fa00f-ddef-4298-b87b-aa8b6da0e1a6::") + + result, err := cdtektonpipeline.DataSourceIBMCdTektonPipelineToolchainReferenceToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestDataSourceIBMCdTektonPipelineDefinitionToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + toolModel := make(map[string]interface{}) + toolModel["id"] = "testString" + + definitionSourcePropertiesModel := make(map[string]interface{}) + definitionSourcePropertiesModel["url"] = "testString" + definitionSourcePropertiesModel["branch"] = "testString" + definitionSourcePropertiesModel["tag"] = "testString" + definitionSourcePropertiesModel["path"] = "testString" + definitionSourcePropertiesModel["tool"] = []map[string]interface{}{toolModel} + + definitionSourceModel := make(map[string]interface{}) + definitionSourceModel["type"] = "testString" + definitionSourceModel["properties"] = []map[string]interface{}{definitionSourcePropertiesModel} + + model := make(map[string]interface{}) + model["source"] = []map[string]interface{}{definitionSourceModel} + model["href"] = "testString" + model["id"] = "testString" + + assert.Equal(t, result, model) + } + + toolModel := new(cdtektonpipelinev2.Tool) + toolModel.ID = core.StringPtr("testString") + + definitionSourcePropertiesModel := new(cdtektonpipelinev2.DefinitionSourceProperties) + definitionSourcePropertiesModel.URL = core.StringPtr("testString") + definitionSourcePropertiesModel.Branch = core.StringPtr("testString") + definitionSourcePropertiesModel.Tag = core.StringPtr("testString") + definitionSourcePropertiesModel.Path = core.StringPtr("testString") + definitionSourcePropertiesModel.Tool = toolModel + + definitionSourceModel := new(cdtektonpipelinev2.DefinitionSource) + definitionSourceModel.Type = core.StringPtr("testString") + definitionSourceModel.Properties = definitionSourcePropertiesModel + + model := new(cdtektonpipelinev2.Definition) + model.Source = definitionSourceModel + model.Href = core.StringPtr("testString") + model.ID = core.StringPtr("testString") + + result, err := cdtektonpipeline.DataSourceIBMCdTektonPipelineDefinitionToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestDataSourceIBMCdTektonPipelineDefinitionSourceToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + toolModel := make(map[string]interface{}) + toolModel["id"] = "testString" + + definitionSourcePropertiesModel := make(map[string]interface{}) + definitionSourcePropertiesModel["url"] = "testString" + definitionSourcePropertiesModel["branch"] = "testString" + definitionSourcePropertiesModel["tag"] = "testString" + definitionSourcePropertiesModel["path"] = "testString" + definitionSourcePropertiesModel["tool"] = []map[string]interface{}{toolModel} + + model := make(map[string]interface{}) + model["type"] = "testString" + model["properties"] = []map[string]interface{}{definitionSourcePropertiesModel} + + assert.Equal(t, result, model) + } + + toolModel := new(cdtektonpipelinev2.Tool) + toolModel.ID = core.StringPtr("testString") + + definitionSourcePropertiesModel := new(cdtektonpipelinev2.DefinitionSourceProperties) + definitionSourcePropertiesModel.URL = core.StringPtr("testString") + definitionSourcePropertiesModel.Branch = core.StringPtr("testString") + definitionSourcePropertiesModel.Tag = core.StringPtr("testString") + definitionSourcePropertiesModel.Path = core.StringPtr("testString") + definitionSourcePropertiesModel.Tool = toolModel + + model := new(cdtektonpipelinev2.DefinitionSource) + model.Type = core.StringPtr("testString") + model.Properties = definitionSourcePropertiesModel + + result, err := cdtektonpipeline.DataSourceIBMCdTektonPipelineDefinitionSourceToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestDataSourceIBMCdTektonPipelineDefinitionSourcePropertiesToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + toolModel := make(map[string]interface{}) + toolModel["id"] = "testString" + + model := make(map[string]interface{}) + model["url"] = "testString" + model["branch"] = "testString" + model["tag"] = "testString" + model["path"] = "testString" + model["tool"] = []map[string]interface{}{toolModel} + + assert.Equal(t, result, model) + } + + toolModel := new(cdtektonpipelinev2.Tool) + toolModel.ID = core.StringPtr("testString") + + model := new(cdtektonpipelinev2.DefinitionSourceProperties) + model.URL = core.StringPtr("testString") + model.Branch = core.StringPtr("testString") + model.Tag = core.StringPtr("testString") + model.Path = core.StringPtr("testString") + model.Tool = toolModel + + result, err := cdtektonpipeline.DataSourceIBMCdTektonPipelineDefinitionSourcePropertiesToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestDataSourceIBMCdTektonPipelineToolToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + model := make(map[string]interface{}) + model["id"] = "testString" + + assert.Equal(t, result, model) + } + + model := new(cdtektonpipelinev2.Tool) + model.ID = core.StringPtr("testString") + + result, err := cdtektonpipeline.DataSourceIBMCdTektonPipelineToolToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestDataSourceIBMCdTektonPipelinePropertyToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + model := make(map[string]interface{}) + model["name"] = "testString" + model["value"] = "testString" + model["href"] = "testString" + model["enum"] = []string{"testString"} + model["type"] = "secure" + model["locked"] = true + model["path"] = "testString" + + assert.Equal(t, result, model) + } + + model := new(cdtektonpipelinev2.Property) + model.Name = core.StringPtr("testString") + model.Value = core.StringPtr("testString") + model.Href = core.StringPtr("testString") + model.Enum = []string{"testString"} + model.Type = core.StringPtr("secure") + model.Locked = core.BoolPtr(true) + model.Path = core.StringPtr("testString") + + result, err := cdtektonpipeline.DataSourceIBMCdTektonPipelinePropertyToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestDataSourceIBMCdTektonPipelineTriggerToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + triggerPropertyModel := make(map[string]interface{}) + triggerPropertyModel["name"] = "testString" + triggerPropertyModel["value"] = "testString" + triggerPropertyModel["href"] = "testString" + triggerPropertyModel["enum"] = []string{"testString"} + triggerPropertyModel["type"] = "secure" + triggerPropertyModel["path"] = "testString" + triggerPropertyModel["locked"] = true + + workerModel := make(map[string]interface{}) + workerModel["name"] = "testString" + workerModel["type"] = "testString" + workerModel["id"] = "testString" + + toolModel := make(map[string]interface{}) + toolModel["id"] = "testString" + + triggerSourcePropertiesModel := make(map[string]interface{}) + triggerSourcePropertiesModel["url"] = "testString" + triggerSourcePropertiesModel["branch"] = "testString" + triggerSourcePropertiesModel["pattern"] = "testString" + triggerSourcePropertiesModel["blind_connection"] = true + triggerSourcePropertiesModel["hook_id"] = "testString" + triggerSourcePropertiesModel["tool"] = []map[string]interface{}{toolModel} + + triggerSourceModel := make(map[string]interface{}) + triggerSourceModel["type"] = "testString" + triggerSourceModel["properties"] = []map[string]interface{}{triggerSourcePropertiesModel} + + genericSecretModel := make(map[string]interface{}) + genericSecretModel["type"] = "token_matches" + genericSecretModel["value"] = "testString" + genericSecretModel["source"] = "header" + genericSecretModel["key_name"] = "testString" + genericSecretModel["algorithm"] = "md4" + + model := make(map[string]interface{}) + model["type"] = "testString" + model["name"] = "start-deploy" + model["href"] = "testString" + model["event_listener"] = "testString" + model["id"] = "testString" + model["properties"] = []map[string]interface{}{triggerPropertyModel} + model["tags"] = []string{"testString"} + model["worker"] = []map[string]interface{}{workerModel} + model["max_concurrent_runs"] = int(4) + model["enabled"] = true + model["favorite"] = false + model["enable_events_from_forks"] = false + model["source"] = []map[string]interface{}{triggerSourceModel} + model["events"] = []string{"push", "pull_request"} + model["filter"] = "header['x-github-event'] == 'push' && body.ref == 'refs/heads/main'" + model["cron"] = "testString" + model["timezone"] = "America/Los_Angeles, CET, Europe/London, GMT, US/Eastern, or UTC" + model["secret"] = []map[string]interface{}{genericSecretModel} + model["webhook_url"] = "testString" + + assert.Equal(t, result, model) + } + + triggerPropertyModel := new(cdtektonpipelinev2.TriggerProperty) + triggerPropertyModel.Name = core.StringPtr("testString") + triggerPropertyModel.Value = core.StringPtr("testString") + triggerPropertyModel.Href = core.StringPtr("testString") + triggerPropertyModel.Enum = []string{"testString"} + triggerPropertyModel.Type = core.StringPtr("secure") + triggerPropertyModel.Path = core.StringPtr("testString") + triggerPropertyModel.Locked = core.BoolPtr(true) + + workerModel := new(cdtektonpipelinev2.Worker) + workerModel.Name = core.StringPtr("testString") + workerModel.Type = core.StringPtr("testString") + workerModel.ID = core.StringPtr("testString") + + toolModel := new(cdtektonpipelinev2.Tool) + toolModel.ID = core.StringPtr("testString") + + triggerSourcePropertiesModel := new(cdtektonpipelinev2.TriggerSourceProperties) + triggerSourcePropertiesModel.URL = core.StringPtr("testString") + triggerSourcePropertiesModel.Branch = core.StringPtr("testString") + triggerSourcePropertiesModel.Pattern = core.StringPtr("testString") + triggerSourcePropertiesModel.BlindConnection = core.BoolPtr(true) + triggerSourcePropertiesModel.HookID = core.StringPtr("testString") + triggerSourcePropertiesModel.Tool = toolModel + + triggerSourceModel := new(cdtektonpipelinev2.TriggerSource) + triggerSourceModel.Type = core.StringPtr("testString") + triggerSourceModel.Properties = triggerSourcePropertiesModel + + genericSecretModel := new(cdtektonpipelinev2.GenericSecret) + genericSecretModel.Type = core.StringPtr("token_matches") + genericSecretModel.Value = core.StringPtr("testString") + genericSecretModel.Source = core.StringPtr("header") + genericSecretModel.KeyName = core.StringPtr("testString") + genericSecretModel.Algorithm = core.StringPtr("md4") + + model := new(cdtektonpipelinev2.Trigger) + model.Type = core.StringPtr("testString") + model.Name = core.StringPtr("start-deploy") + model.Href = core.StringPtr("testString") + model.EventListener = core.StringPtr("testString") + model.ID = core.StringPtr("testString") + model.Properties = []cdtektonpipelinev2.TriggerProperty{*triggerPropertyModel} + model.Tags = []string{"testString"} + model.Worker = workerModel + model.MaxConcurrentRuns = core.Int64Ptr(int64(4)) + model.Enabled = core.BoolPtr(true) + model.Favorite = core.BoolPtr(false) + model.EnableEventsFromForks = core.BoolPtr(false) + model.Source = triggerSourceModel + model.Events = []string{"push", "pull_request"} + model.Filter = core.StringPtr("header['x-github-event'] == 'push' && body.ref == 'refs/heads/main'") + model.Cron = core.StringPtr("testString") + model.Timezone = core.StringPtr("America/Los_Angeles, CET, Europe/London, GMT, US/Eastern, or UTC") + model.Secret = genericSecretModel + model.WebhookURL = core.StringPtr("testString") + + result, err := cdtektonpipeline.DataSourceIBMCdTektonPipelineTriggerToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestDataSourceIBMCdTektonPipelineTriggerPropertyToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + model := make(map[string]interface{}) + model["name"] = "testString" + model["value"] = "testString" + model["href"] = "testString" + model["enum"] = []string{"testString"} + model["type"] = "secure" + model["path"] = "testString" + model["locked"] = true + + assert.Equal(t, result, model) + } + + model := new(cdtektonpipelinev2.TriggerProperty) + model.Name = core.StringPtr("testString") + model.Value = core.StringPtr("testString") + model.Href = core.StringPtr("testString") + model.Enum = []string{"testString"} + model.Type = core.StringPtr("secure") + model.Path = core.StringPtr("testString") + model.Locked = core.BoolPtr(true) + + result, err := cdtektonpipeline.DataSourceIBMCdTektonPipelineTriggerPropertyToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestDataSourceIBMCdTektonPipelineWorkerToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + model := make(map[string]interface{}) + model["name"] = "testString" + model["type"] = "testString" + model["id"] = "testString" + + assert.Equal(t, result, model) + } + + model := new(cdtektonpipelinev2.Worker) + model.Name = core.StringPtr("testString") + model.Type = core.StringPtr("testString") + model.ID = core.StringPtr("testString") + + result, err := cdtektonpipeline.DataSourceIBMCdTektonPipelineWorkerToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestDataSourceIBMCdTektonPipelineTriggerSourceToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + toolModel := make(map[string]interface{}) + toolModel["id"] = "testString" + + triggerSourcePropertiesModel := make(map[string]interface{}) + triggerSourcePropertiesModel["url"] = "testString" + triggerSourcePropertiesModel["branch"] = "testString" + triggerSourcePropertiesModel["pattern"] = "testString" + triggerSourcePropertiesModel["blind_connection"] = true + triggerSourcePropertiesModel["hook_id"] = "testString" + triggerSourcePropertiesModel["tool"] = []map[string]interface{}{toolModel} + + model := make(map[string]interface{}) + model["type"] = "testString" + model["properties"] = []map[string]interface{}{triggerSourcePropertiesModel} + + assert.Equal(t, result, model) + } + + toolModel := new(cdtektonpipelinev2.Tool) + toolModel.ID = core.StringPtr("testString") + + triggerSourcePropertiesModel := new(cdtektonpipelinev2.TriggerSourceProperties) + triggerSourcePropertiesModel.URL = core.StringPtr("testString") + triggerSourcePropertiesModel.Branch = core.StringPtr("testString") + triggerSourcePropertiesModel.Pattern = core.StringPtr("testString") + triggerSourcePropertiesModel.BlindConnection = core.BoolPtr(true) + triggerSourcePropertiesModel.HookID = core.StringPtr("testString") + triggerSourcePropertiesModel.Tool = toolModel + + model := new(cdtektonpipelinev2.TriggerSource) + model.Type = core.StringPtr("testString") + model.Properties = triggerSourcePropertiesModel + + result, err := cdtektonpipeline.DataSourceIBMCdTektonPipelineTriggerSourceToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestDataSourceIBMCdTektonPipelineTriggerSourcePropertiesToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + toolModel := make(map[string]interface{}) + toolModel["id"] = "testString" + + model := make(map[string]interface{}) + model["url"] = "testString" + model["branch"] = "testString" + model["pattern"] = "testString" + model["blind_connection"] = true + model["hook_id"] = "testString" + model["tool"] = []map[string]interface{}{toolModel} + + assert.Equal(t, result, model) + } + + toolModel := new(cdtektonpipelinev2.Tool) + toolModel.ID = core.StringPtr("testString") + + model := new(cdtektonpipelinev2.TriggerSourceProperties) + model.URL = core.StringPtr("testString") + model.Branch = core.StringPtr("testString") + model.Pattern = core.StringPtr("testString") + model.BlindConnection = core.BoolPtr(true) + model.HookID = core.StringPtr("testString") + model.Tool = toolModel + + result, err := cdtektonpipeline.DataSourceIBMCdTektonPipelineTriggerSourcePropertiesToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestDataSourceIBMCdTektonPipelineGenericSecretToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + model := make(map[string]interface{}) + model["type"] = "token_matches" + model["value"] = "testString" + model["source"] = "header" + model["key_name"] = "testString" + model["algorithm"] = "md4" + + assert.Equal(t, result, model) + } + + model := new(cdtektonpipelinev2.GenericSecret) + model.Type = core.StringPtr("token_matches") + model.Value = core.StringPtr("testString") + model.Source = core.StringPtr("header") + model.KeyName = core.StringPtr("testString") + model.Algorithm = core.StringPtr("md4") + + result, err := cdtektonpipeline.DataSourceIBMCdTektonPipelineGenericSecretToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestDataSourceIBMCdTektonPipelineTriggerManualTriggerToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + triggerPropertyModel := make(map[string]interface{}) + triggerPropertyModel["name"] = "testString" + triggerPropertyModel["value"] = "testString" + triggerPropertyModel["href"] = "testString" + triggerPropertyModel["enum"] = []string{"testString"} + triggerPropertyModel["type"] = "secure" + triggerPropertyModel["path"] = "testString" + triggerPropertyModel["locked"] = true + + workerModel := make(map[string]interface{}) + workerModel["name"] = "testString" + workerModel["type"] = "testString" + workerModel["id"] = "testString" + + model := make(map[string]interface{}) + model["type"] = "testString" + model["name"] = "start-deploy" + model["href"] = "testString" + model["event_listener"] = "testString" + model["id"] = "testString" + model["properties"] = []map[string]interface{}{triggerPropertyModel} + model["tags"] = []string{"testString"} + model["worker"] = []map[string]interface{}{workerModel} + model["max_concurrent_runs"] = int(4) + model["enabled"] = true + model["favorite"] = false + + assert.Equal(t, result, model) + } + + triggerPropertyModel := new(cdtektonpipelinev2.TriggerProperty) + triggerPropertyModel.Name = core.StringPtr("testString") + triggerPropertyModel.Value = core.StringPtr("testString") + triggerPropertyModel.Href = core.StringPtr("testString") + triggerPropertyModel.Enum = []string{"testString"} + triggerPropertyModel.Type = core.StringPtr("secure") + triggerPropertyModel.Path = core.StringPtr("testString") + triggerPropertyModel.Locked = core.BoolPtr(true) + + workerModel := new(cdtektonpipelinev2.Worker) + workerModel.Name = core.StringPtr("testString") + workerModel.Type = core.StringPtr("testString") + workerModel.ID = core.StringPtr("testString") + + model := new(cdtektonpipelinev2.TriggerManualTrigger) + model.Type = core.StringPtr("testString") + model.Name = core.StringPtr("start-deploy") + model.Href = core.StringPtr("testString") + model.EventListener = core.StringPtr("testString") + model.ID = core.StringPtr("testString") + model.Properties = []cdtektonpipelinev2.TriggerProperty{*triggerPropertyModel} + model.Tags = []string{"testString"} + model.Worker = workerModel + model.MaxConcurrentRuns = core.Int64Ptr(int64(4)) + model.Enabled = core.BoolPtr(true) + model.Favorite = core.BoolPtr(false) + + result, err := cdtektonpipeline.DataSourceIBMCdTektonPipelineTriggerManualTriggerToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestDataSourceIBMCdTektonPipelineTriggerScmTriggerToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + triggerPropertyModel := make(map[string]interface{}) + triggerPropertyModel["name"] = "testString" + triggerPropertyModel["value"] = "testString" + triggerPropertyModel["href"] = "testString" + triggerPropertyModel["enum"] = []string{"testString"} + triggerPropertyModel["type"] = "secure" + triggerPropertyModel["path"] = "testString" + triggerPropertyModel["locked"] = true + + workerModel := make(map[string]interface{}) + workerModel["name"] = "testString" + workerModel["type"] = "testString" + workerModel["id"] = "testString" + + toolModel := make(map[string]interface{}) + toolModel["id"] = "testString" + + triggerSourcePropertiesModel := make(map[string]interface{}) + triggerSourcePropertiesModel["url"] = "testString" + triggerSourcePropertiesModel["branch"] = "testString" + triggerSourcePropertiesModel["pattern"] = "testString" + triggerSourcePropertiesModel["blind_connection"] = true + triggerSourcePropertiesModel["hook_id"] = "testString" + triggerSourcePropertiesModel["tool"] = []map[string]interface{}{toolModel} + + triggerSourceModel := make(map[string]interface{}) + triggerSourceModel["type"] = "testString" + triggerSourceModel["properties"] = []map[string]interface{}{triggerSourcePropertiesModel} + + model := make(map[string]interface{}) + model["type"] = "testString" + model["name"] = "start-deploy" + model["href"] = "testString" + model["event_listener"] = "testString" + model["id"] = "testString" + model["properties"] = []map[string]interface{}{triggerPropertyModel} + model["tags"] = []string{"testString"} + model["worker"] = []map[string]interface{}{workerModel} + model["max_concurrent_runs"] = int(4) + model["enabled"] = true + model["favorite"] = false + model["enable_events_from_forks"] = false + model["source"] = []map[string]interface{}{triggerSourceModel} + model["events"] = []string{"push", "pull_request"} + model["filter"] = "header['x-github-event'] == 'push' && body.ref == 'refs/heads/main'" + + assert.Equal(t, result, model) + } + + triggerPropertyModel := new(cdtektonpipelinev2.TriggerProperty) + triggerPropertyModel.Name = core.StringPtr("testString") + triggerPropertyModel.Value = core.StringPtr("testString") + triggerPropertyModel.Href = core.StringPtr("testString") + triggerPropertyModel.Enum = []string{"testString"} + triggerPropertyModel.Type = core.StringPtr("secure") + triggerPropertyModel.Path = core.StringPtr("testString") + triggerPropertyModel.Locked = core.BoolPtr(true) + + workerModel := new(cdtektonpipelinev2.Worker) + workerModel.Name = core.StringPtr("testString") + workerModel.Type = core.StringPtr("testString") + workerModel.ID = core.StringPtr("testString") + + toolModel := new(cdtektonpipelinev2.Tool) + toolModel.ID = core.StringPtr("testString") + + triggerSourcePropertiesModel := new(cdtektonpipelinev2.TriggerSourceProperties) + triggerSourcePropertiesModel.URL = core.StringPtr("testString") + triggerSourcePropertiesModel.Branch = core.StringPtr("testString") + triggerSourcePropertiesModel.Pattern = core.StringPtr("testString") + triggerSourcePropertiesModel.BlindConnection = core.BoolPtr(true) + triggerSourcePropertiesModel.HookID = core.StringPtr("testString") + triggerSourcePropertiesModel.Tool = toolModel + + triggerSourceModel := new(cdtektonpipelinev2.TriggerSource) + triggerSourceModel.Type = core.StringPtr("testString") + triggerSourceModel.Properties = triggerSourcePropertiesModel + + model := new(cdtektonpipelinev2.TriggerScmTrigger) + model.Type = core.StringPtr("testString") + model.Name = core.StringPtr("start-deploy") + model.Href = core.StringPtr("testString") + model.EventListener = core.StringPtr("testString") + model.ID = core.StringPtr("testString") + model.Properties = []cdtektonpipelinev2.TriggerProperty{*triggerPropertyModel} + model.Tags = []string{"testString"} + model.Worker = workerModel + model.MaxConcurrentRuns = core.Int64Ptr(int64(4)) + model.Enabled = core.BoolPtr(true) + model.Favorite = core.BoolPtr(false) + model.EnableEventsFromForks = core.BoolPtr(false) + model.Source = triggerSourceModel + model.Events = []string{"push", "pull_request"} + model.Filter = core.StringPtr("header['x-github-event'] == 'push' && body.ref == 'refs/heads/main'") + + result, err := cdtektonpipeline.DataSourceIBMCdTektonPipelineTriggerScmTriggerToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestDataSourceIBMCdTektonPipelineTriggerTimerTriggerToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + triggerPropertyModel := make(map[string]interface{}) + triggerPropertyModel["name"] = "testString" + triggerPropertyModel["value"] = "testString" + triggerPropertyModel["href"] = "testString" + triggerPropertyModel["enum"] = []string{"testString"} + triggerPropertyModel["type"] = "secure" + triggerPropertyModel["path"] = "testString" + triggerPropertyModel["locked"] = true + + workerModel := make(map[string]interface{}) + workerModel["name"] = "testString" + workerModel["type"] = "testString" + workerModel["id"] = "testString" + + model := make(map[string]interface{}) + model["type"] = "testString" + model["name"] = "start-deploy" + model["href"] = "testString" + model["event_listener"] = "testString" + model["id"] = "testString" + model["properties"] = []map[string]interface{}{triggerPropertyModel} + model["tags"] = []string{"testString"} + model["worker"] = []map[string]interface{}{workerModel} + model["max_concurrent_runs"] = int(4) + model["enabled"] = true + model["favorite"] = false + model["cron"] = "testString" + model["timezone"] = "America/Los_Angeles, CET, Europe/London, GMT, US/Eastern, or UTC" + + assert.Equal(t, result, model) + } + + triggerPropertyModel := new(cdtektonpipelinev2.TriggerProperty) + triggerPropertyModel.Name = core.StringPtr("testString") + triggerPropertyModel.Value = core.StringPtr("testString") + triggerPropertyModel.Href = core.StringPtr("testString") + triggerPropertyModel.Enum = []string{"testString"} + triggerPropertyModel.Type = core.StringPtr("secure") + triggerPropertyModel.Path = core.StringPtr("testString") + triggerPropertyModel.Locked = core.BoolPtr(true) + + workerModel := new(cdtektonpipelinev2.Worker) + workerModel.Name = core.StringPtr("testString") + workerModel.Type = core.StringPtr("testString") + workerModel.ID = core.StringPtr("testString") + + model := new(cdtektonpipelinev2.TriggerTimerTrigger) + model.Type = core.StringPtr("testString") + model.Name = core.StringPtr("start-deploy") + model.Href = core.StringPtr("testString") + model.EventListener = core.StringPtr("testString") + model.ID = core.StringPtr("testString") + model.Properties = []cdtektonpipelinev2.TriggerProperty{*triggerPropertyModel} + model.Tags = []string{"testString"} + model.Worker = workerModel + model.MaxConcurrentRuns = core.Int64Ptr(int64(4)) + model.Enabled = core.BoolPtr(true) + model.Favorite = core.BoolPtr(false) + model.Cron = core.StringPtr("testString") + model.Timezone = core.StringPtr("America/Los_Angeles, CET, Europe/London, GMT, US/Eastern, or UTC") + + result, err := cdtektonpipeline.DataSourceIBMCdTektonPipelineTriggerTimerTriggerToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestDataSourceIBMCdTektonPipelineTriggerGenericTriggerToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + triggerPropertyModel := make(map[string]interface{}) + triggerPropertyModel["name"] = "testString" + triggerPropertyModel["value"] = "testString" + triggerPropertyModel["href"] = "testString" + triggerPropertyModel["enum"] = []string{"testString"} + triggerPropertyModel["type"] = "secure" + triggerPropertyModel["path"] = "testString" + triggerPropertyModel["locked"] = true + + workerModel := make(map[string]interface{}) + workerModel["name"] = "testString" + workerModel["type"] = "testString" + workerModel["id"] = "testString" + + genericSecretModel := make(map[string]interface{}) + genericSecretModel["type"] = "token_matches" + genericSecretModel["value"] = "testString" + genericSecretModel["source"] = "header" + genericSecretModel["key_name"] = "testString" + genericSecretModel["algorithm"] = "md4" + + model := make(map[string]interface{}) + model["type"] = "testString" + model["name"] = "start-deploy" + model["href"] = "testString" + model["event_listener"] = "testString" + model["id"] = "testString" + model["properties"] = []map[string]interface{}{triggerPropertyModel} + model["tags"] = []string{"testString"} + model["worker"] = []map[string]interface{}{workerModel} + model["max_concurrent_runs"] = int(4) + model["enabled"] = true + model["favorite"] = false + model["secret"] = []map[string]interface{}{genericSecretModel} + model["webhook_url"] = "testString" + model["filter"] = "event.type == 'message' && event.text.contains('urgent')" + + assert.Equal(t, result, model) + } + + triggerPropertyModel := new(cdtektonpipelinev2.TriggerProperty) + triggerPropertyModel.Name = core.StringPtr("testString") + triggerPropertyModel.Value = core.StringPtr("testString") + triggerPropertyModel.Href = core.StringPtr("testString") + triggerPropertyModel.Enum = []string{"testString"} + triggerPropertyModel.Type = core.StringPtr("secure") + triggerPropertyModel.Path = core.StringPtr("testString") + triggerPropertyModel.Locked = core.BoolPtr(true) + + workerModel := new(cdtektonpipelinev2.Worker) + workerModel.Name = core.StringPtr("testString") + workerModel.Type = core.StringPtr("testString") + workerModel.ID = core.StringPtr("testString") + + genericSecretModel := new(cdtektonpipelinev2.GenericSecret) + genericSecretModel.Type = core.StringPtr("token_matches") + genericSecretModel.Value = core.StringPtr("testString") + genericSecretModel.Source = core.StringPtr("header") + genericSecretModel.KeyName = core.StringPtr("testString") + genericSecretModel.Algorithm = core.StringPtr("md4") + + model := new(cdtektonpipelinev2.TriggerGenericTrigger) + model.Type = core.StringPtr("testString") + model.Name = core.StringPtr("start-deploy") + model.Href = core.StringPtr("testString") + model.EventListener = core.StringPtr("testString") + model.ID = core.StringPtr("testString") + model.Properties = []cdtektonpipelinev2.TriggerProperty{*triggerPropertyModel} + model.Tags = []string{"testString"} + model.Worker = workerModel + model.MaxConcurrentRuns = core.Int64Ptr(int64(4)) + model.Enabled = core.BoolPtr(true) + model.Favorite = core.BoolPtr(false) + model.Secret = genericSecretModel + model.WebhookURL = core.StringPtr("testString") + model.Filter = core.StringPtr("event.type == 'message' && event.text.contains('urgent')") + + result, err := cdtektonpipeline.DataSourceIBMCdTektonPipelineTriggerGenericTriggerToMap(model) + assert.Nil(t, err) + checkResult(result) +} diff --git a/ibm/service/cdtektonpipeline/data_source_ibm_cd_tekton_pipeline_trigger.go b/ibm/service/cdtektonpipeline/data_source_ibm_cd_tekton_pipeline_trigger.go index bb69e29b60..4adf746658 100644 --- a/ibm/service/cdtektonpipeline/data_source_ibm_cd_tekton_pipeline_trigger.go +++ b/ibm/service/cdtektonpipeline/data_source_ibm_cd_tekton_pipeline_trigger.go @@ -1,6 +1,10 @@ // Copyright IBM Corp. 2024 All Rights Reserved. // Licensed under the Mozilla Public License v2.0 +/* + * IBM OpenAPI Terraform Generator Version: 3.95.2-120e65bc-20240924-152329 + */ + package cdtektonpipeline import ( @@ -14,6 +18,7 @@ import ( "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" "github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex" "github.com/IBM/continuous-delivery-go-sdk/cdtektonpipelinev2" + "github.com/IBM/go-sdk-core/v5/core" ) func DataSourceIBMCdTektonPipelineTrigger() *schema.Resource { @@ -281,7 +286,9 @@ func DataSourceIBMCdTektonPipelineTrigger() *schema.Resource { func dataSourceIBMCdTektonPipelineTriggerRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { cdTektonPipelineClient, err := meta.(conns.ClientSession).CdTektonPipelineV2() if err != nil { - return diag.FromErr(err) + tfErr := flex.DiscriminatedTerraformErrorf(err, err.Error(), "(Data) ibm_cd_tekton_pipeline_trigger", "read", "initialize-client") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } getTektonPipelineTriggerOptions := &cdtektonpipelinev2.GetTektonPipelineTriggerOptions{} @@ -289,166 +296,199 @@ func dataSourceIBMCdTektonPipelineTriggerRead(context context.Context, d *schema getTektonPipelineTriggerOptions.SetPipelineID(d.Get("pipeline_id").(string)) getTektonPipelineTriggerOptions.SetTriggerID(d.Get("trigger_id").(string)) - TriggerIntf, response, err := cdTektonPipelineClient.GetTektonPipelineTriggerWithContext(context, getTektonPipelineTriggerOptions) + triggerIntf, _, err := cdTektonPipelineClient.GetTektonPipelineTriggerWithContext(context, getTektonPipelineTriggerOptions) if err != nil { - log.Printf("[DEBUG] GetTektonPipelineTriggerWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("GetTektonPipelineTriggerWithContext failed %s\n%s", err, response)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("GetTektonPipelineTriggerWithContext failed: %s", err.Error()), "(Data) ibm_cd_tekton_pipeline_trigger", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } - trigger := TriggerIntf.(*cdtektonpipelinev2.Trigger) + trigger := triggerIntf.(*cdtektonpipelinev2.Trigger) d.SetId(fmt.Sprintf("%s/%s", *getTektonPipelineTriggerOptions.PipelineID, *getTektonPipelineTriggerOptions.TriggerID)) - if err = d.Set("type", trigger.Type); err != nil { - return diag.FromErr(fmt.Errorf("Error setting type: %s", err)) - } - - if err = d.Set("name", trigger.Name); err != nil { - return diag.FromErr(fmt.Errorf("Error setting name: %s", err)) + if !core.IsNil(trigger.Type) { + if err = d.Set("type", trigger.Type); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting type: %s", err), "(Data) ibm_cd_tekton_pipeline_trigger", "read", "set-type").GetDiag() + } } - if err = d.Set("href", trigger.Href); err != nil { - return diag.FromErr(fmt.Errorf("Error setting href: %s", err)) + if !core.IsNil(trigger.Name) { + if err = d.Set("name", trigger.Name); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting name: %s", err), "(Data) ibm_cd_tekton_pipeline_trigger", "read", "set-name").GetDiag() + } } - if err = d.Set("event_listener", trigger.EventListener); err != nil { - return diag.FromErr(fmt.Errorf("Error setting event_listener: %s", err)) + if !core.IsNil(trigger.Href) { + if err = d.Set("href", trigger.Href); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting href: %s", err), "(Data) ibm_cd_tekton_pipeline_trigger", "read", "set-href").GetDiag() + } } - if trigger.Tags != nil { - if err = d.Set("tags", trigger.Tags); err != nil { - return diag.FromErr(fmt.Errorf("Error setting tags: %s", err)) + if !core.IsNil(trigger.EventListener) { + if err = d.Set("event_listener", trigger.EventListener); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting event_listener: %s", err), "(Data) ibm_cd_tekton_pipeline_trigger", "read", "set-event_listener").GetDiag() } } - properties := []map[string]interface{}{} - if trigger.Properties != nil { - for _, modelItem := range trigger.Properties { - modelMap, err := dataSourceIBMCdTektonPipelineTriggerTriggerPropertyToMap(&modelItem) + if !core.IsNil(trigger.Properties) { + properties := []map[string]interface{}{} + for _, propertiesItem := range trigger.Properties { + propertiesItemMap, err := DataSourceIBMCdTektonPipelineTriggerTriggerPropertyToMap(&propertiesItem) // #nosec G601 if err != nil { - return diag.FromErr(err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "(Data) ibm_cd_tekton_pipeline_trigger", "read", "properties-to-map").GetDiag() } - properties = append(properties, modelMap) + properties = append(properties, propertiesItemMap) + } + if err = d.Set("properties", properties); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting properties: %s", err), "(Data) ibm_cd_tekton_pipeline_trigger", "read", "set-properties").GetDiag() } - } - if err = d.Set("properties", properties); err != nil { - return diag.FromErr(fmt.Errorf("Error setting properties %s", err)) } - if trigger.Events != nil { - if err = d.Set("events", trigger.Events); err != nil { - return diag.FromErr(fmt.Errorf("Error setting events: %s", err)) + if !core.IsNil(trigger.Tags) { + tags := []interface{}{} + for _, tagsItem := range trigger.Tags { + tags = append(tags, tagsItem) + } + if err = d.Set("tags", tags); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting tags: %s", err), "(Data) ibm_cd_tekton_pipeline_trigger", "read", "set-tags").GetDiag() } } - worker := []map[string]interface{}{} - if trigger.Worker != nil { - modelMap, err := dataSourceIBMCdTektonPipelineTriggerWorkerToMap(trigger.Worker) + if !core.IsNil(trigger.Worker) { + worker := []map[string]interface{}{} + workerMap, err := DataSourceIBMCdTektonPipelineTriggerWorkerToMap(trigger.Worker) if err != nil { - return diag.FromErr(err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "(Data) ibm_cd_tekton_pipeline_trigger", "read", "worker-to-map").GetDiag() + } + worker = append(worker, workerMap) + if err = d.Set("worker", worker); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting worker: %s", err), "(Data) ibm_cd_tekton_pipeline_trigger", "read", "set-worker").GetDiag() } - worker = append(worker, modelMap) - } - if err = d.Set("worker", worker); err != nil { - return diag.FromErr(fmt.Errorf("Error setting worker %s", err)) } - if err = d.Set("max_concurrent_runs", flex.IntValue(trigger.MaxConcurrentRuns)); err != nil { - return diag.FromErr(fmt.Errorf("Error setting max_concurrent_runs: %s", err)) + if !core.IsNil(trigger.MaxConcurrentRuns) { + if err = d.Set("max_concurrent_runs", flex.IntValue(trigger.MaxConcurrentRuns)); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting max_concurrent_runs: %s", err), "(Data) ibm_cd_tekton_pipeline_trigger", "read", "set-max_concurrent_runs").GetDiag() + } } - if err = d.Set("enabled", trigger.Enabled); err != nil { - return diag.FromErr(fmt.Errorf("Error setting enabled: %s", err)) + if !core.IsNil(trigger.Enabled) { + if err = d.Set("enabled", trigger.Enabled); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting enabled: %s", err), "(Data) ibm_cd_tekton_pipeline_trigger", "read", "set-enabled").GetDiag() + } } - if err = d.Set("favorite", trigger.Favorite); err != nil { - return diag.FromErr(fmt.Errorf("Error setting favorite: %s", err)) + if !core.IsNil(trigger.Favorite) { + if err = d.Set("favorite", trigger.Favorite); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting favorite: %s", err), "(Data) ibm_cd_tekton_pipeline_trigger", "read", "set-favorite").GetDiag() + } } - if err = d.Set("enable_events_from_forks", trigger.EnableEventsFromForks); err != nil { - return diag.FromErr(fmt.Errorf("Error setting enable_events_from_forks: %s", err)) + if !core.IsNil(trigger.EnableEventsFromForks) { + if err = d.Set("enable_events_from_forks", trigger.EnableEventsFromForks); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting enable_events_from_forks: %s", err), "(Data) ibm_cd_tekton_pipeline_trigger", "read", "set-enable_events_from_forks").GetDiag() + } } - source := []map[string]interface{}{} - if trigger.Source != nil { - modelMap, err := dataSourceIBMCdTektonPipelineTriggerTriggerSourceToMap(trigger.Source) + if !core.IsNil(trigger.Source) { + source := []map[string]interface{}{} + sourceMap, err := DataSourceIBMCdTektonPipelineTriggerTriggerSourceToMap(trigger.Source) if err != nil { - return diag.FromErr(err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "(Data) ibm_cd_tekton_pipeline_trigger", "read", "source-to-map").GetDiag() + } + source = append(source, sourceMap) + if err = d.Set("source", source); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting source: %s", err), "(Data) ibm_cd_tekton_pipeline_trigger", "read", "set-source").GetDiag() } - source = append(source, modelMap) } - if err = d.Set("source", source); err != nil { - return diag.FromErr(fmt.Errorf("Error setting source %s", err)) + + if !core.IsNil(trigger.Events) { + events := []interface{}{} + for _, eventsItem := range trigger.Events { + events = append(events, eventsItem) + } + if err = d.Set("events", events); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting events: %s", err), "(Data) ibm_cd_tekton_pipeline_trigger", "read", "set-events").GetDiag() + } } - if err = d.Set("filter", trigger.Filter); err != nil { - return diag.FromErr(fmt.Errorf("Error setting filter: %s", err)) + if !core.IsNil(trigger.Filter) { + if err = d.Set("filter", trigger.Filter); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting filter: %s", err), "(Data) ibm_cd_tekton_pipeline_trigger", "read", "set-filter").GetDiag() + } } - if err = d.Set("cron", trigger.Cron); err != nil { - return diag.FromErr(fmt.Errorf("Error setting cron: %s", err)) + if !core.IsNil(trigger.Cron) { + if err = d.Set("cron", trigger.Cron); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting cron: %s", err), "(Data) ibm_cd_tekton_pipeline_trigger", "read", "set-cron").GetDiag() + } } - if err = d.Set("timezone", trigger.Timezone); err != nil { - return diag.FromErr(fmt.Errorf("Error setting timezone: %s", err)) + if !core.IsNil(trigger.Timezone) { + if err = d.Set("timezone", trigger.Timezone); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting timezone: %s", err), "(Data) ibm_cd_tekton_pipeline_trigger", "read", "set-timezone").GetDiag() + } } - secret := []map[string]interface{}{} - if trigger.Secret != nil { - modelMap, err := dataSourceIBMCdTektonPipelineTriggerGenericSecretToMap(trigger.Secret) + if !core.IsNil(trigger.Secret) { + secret := []map[string]interface{}{} + secretMap, err := DataSourceIBMCdTektonPipelineTriggerGenericSecretToMap(trigger.Secret) if err != nil { - return diag.FromErr(err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "(Data) ibm_cd_tekton_pipeline_trigger", "read", "secret-to-map").GetDiag() + } + secret = append(secret, secretMap) + if err = d.Set("secret", secret); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting secret: %s", err), "(Data) ibm_cd_tekton_pipeline_trigger", "read", "set-secret").GetDiag() } - secret = append(secret, modelMap) - } - if err = d.Set("secret", secret); err != nil { - return diag.FromErr(fmt.Errorf("Error setting secret %s", err)) } - if err = d.Set("webhook_url", trigger.WebhookURL); err != nil { - return diag.FromErr(fmt.Errorf("Error setting webhook_url: %s", err)) + if !core.IsNil(trigger.WebhookURL) { + if err = d.Set("webhook_url", trigger.WebhookURL); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting webhook_url: %s", err), "(Data) ibm_cd_tekton_pipeline_trigger", "read", "set-webhook_url").GetDiag() + } } return nil } -func dataSourceIBMCdTektonPipelineTriggerTriggerPropertyToMap(model *cdtektonpipelinev2.TriggerProperty) (map[string]interface{}, error) { +func DataSourceIBMCdTektonPipelineTriggerTriggerPropertyToMap(model *cdtektonpipelinev2.TriggerProperty) (map[string]interface{}, error) { modelMap := make(map[string]interface{}) - modelMap["name"] = model.Name + modelMap["name"] = *model.Name if model.Value != nil { - modelMap["value"] = model.Value + modelMap["value"] = *model.Value } if model.Href != nil { - modelMap["href"] = model.Href + modelMap["href"] = *model.Href } if model.Enum != nil { modelMap["enum"] = model.Enum } - modelMap["type"] = model.Type + modelMap["type"] = *model.Type if model.Path != nil { - modelMap["path"] = model.Path + modelMap["path"] = *model.Path } if model.Locked != nil { - modelMap["locked"] = model.Locked + modelMap["locked"] = *model.Locked } return modelMap, nil } -func dataSourceIBMCdTektonPipelineTriggerWorkerToMap(model *cdtektonpipelinev2.Worker) (map[string]interface{}, error) { +func DataSourceIBMCdTektonPipelineTriggerWorkerToMap(model *cdtektonpipelinev2.Worker) (map[string]interface{}, error) { modelMap := make(map[string]interface{}) if model.Name != nil { - modelMap["name"] = model.Name + modelMap["name"] = *model.Name } if model.Type != nil { - modelMap["type"] = model.Type + modelMap["type"] = *model.Type } - modelMap["id"] = model.ID + modelMap["id"] = *model.ID return modelMap, nil } -func dataSourceIBMCdTektonPipelineTriggerTriggerSourceToMap(model *cdtektonpipelinev2.TriggerSource) (map[string]interface{}, error) { +func DataSourceIBMCdTektonPipelineTriggerTriggerSourceToMap(model *cdtektonpipelinev2.TriggerSource) (map[string]interface{}, error) { modelMap := make(map[string]interface{}) - modelMap["type"] = model.Type - propertiesMap, err := dataSourceIBMCdTektonPipelineTriggerTriggerSourcePropertiesToMap(model.Properties) + modelMap["type"] = *model.Type + propertiesMap, err := DataSourceIBMCdTektonPipelineTriggerTriggerSourcePropertiesToMap(model.Properties) if err != nil { return modelMap, err } @@ -456,20 +496,20 @@ func dataSourceIBMCdTektonPipelineTriggerTriggerSourceToMap(model *cdtektonpipel return modelMap, nil } -func dataSourceIBMCdTektonPipelineTriggerTriggerSourcePropertiesToMap(model *cdtektonpipelinev2.TriggerSourceProperties) (map[string]interface{}, error) { +func DataSourceIBMCdTektonPipelineTriggerTriggerSourcePropertiesToMap(model *cdtektonpipelinev2.TriggerSourceProperties) (map[string]interface{}, error) { modelMap := make(map[string]interface{}) - modelMap["url"] = model.URL + modelMap["url"] = *model.URL if model.Branch != nil { - modelMap["branch"] = model.Branch + modelMap["branch"] = *model.Branch } if model.Pattern != nil { - modelMap["pattern"] = model.Pattern + modelMap["pattern"] = *model.Pattern } - modelMap["blind_connection"] = model.BlindConnection + modelMap["blind_connection"] = *model.BlindConnection if model.HookID != nil { - modelMap["hook_id"] = model.HookID + modelMap["hook_id"] = *model.HookID } - toolMap, err := dataSourceIBMCdTektonPipelineTriggerToolToMap(model.Tool) + toolMap, err := DataSourceIBMCdTektonPipelineTriggerToolToMap(model.Tool) if err != nil { return modelMap, err } @@ -477,28 +517,28 @@ func dataSourceIBMCdTektonPipelineTriggerTriggerSourcePropertiesToMap(model *cdt return modelMap, nil } -func dataSourceIBMCdTektonPipelineTriggerToolToMap(model *cdtektonpipelinev2.Tool) (map[string]interface{}, error) { +func DataSourceIBMCdTektonPipelineTriggerToolToMap(model *cdtektonpipelinev2.Tool) (map[string]interface{}, error) { modelMap := make(map[string]interface{}) - modelMap["id"] = model.ID + modelMap["id"] = *model.ID return modelMap, nil } -func dataSourceIBMCdTektonPipelineTriggerGenericSecretToMap(model *cdtektonpipelinev2.GenericSecret) (map[string]interface{}, error) { +func DataSourceIBMCdTektonPipelineTriggerGenericSecretToMap(model *cdtektonpipelinev2.GenericSecret) (map[string]interface{}, error) { modelMap := make(map[string]interface{}) if model.Type != nil { - modelMap["type"] = model.Type + modelMap["type"] = *model.Type } if model.Value != nil { - modelMap["value"] = model.Value + modelMap["value"] = *model.Value } if model.Source != nil { - modelMap["source"] = model.Source + modelMap["source"] = *model.Source } if model.KeyName != nil { - modelMap["key_name"] = model.KeyName + modelMap["key_name"] = *model.KeyName } if model.Algorithm != nil { - modelMap["algorithm"] = model.Algorithm + modelMap["algorithm"] = *model.Algorithm } return modelMap, nil } diff --git a/ibm/service/cdtektonpipeline/data_source_ibm_cd_tekton_pipeline_trigger_property.go b/ibm/service/cdtektonpipeline/data_source_ibm_cd_tekton_pipeline_trigger_property.go index fe5ed84978..07e89a50b7 100644 --- a/ibm/service/cdtektonpipeline/data_source_ibm_cd_tekton_pipeline_trigger_property.go +++ b/ibm/service/cdtektonpipeline/data_source_ibm_cd_tekton_pipeline_trigger_property.go @@ -1,6 +1,10 @@ // Copyright IBM Corp. 2024 All Rights Reserved. // Licensed under the Mozilla Public License v2.0 +/* + * IBM OpenAPI Terraform Generator Version: 3.95.2-120e65bc-20240924-152329 + */ + package cdtektonpipeline import ( @@ -12,7 +16,9 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" + "github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex" "github.com/IBM/continuous-delivery-go-sdk/cdtektonpipelinev2" + "github.com/IBM/go-sdk-core/v5/core" ) func DataSourceIBMCdTektonPipelineTriggerProperty() *schema.Resource { @@ -80,7 +86,9 @@ func DataSourceIBMCdTektonPipelineTriggerProperty() *schema.Resource { func dataSourceIBMCdTektonPipelineTriggerPropertyRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { cdTektonPipelineClient, err := meta.(conns.ClientSession).CdTektonPipelineV2() if err != nil { - return diag.FromErr(err) + tfErr := flex.DiscriminatedTerraformErrorf(err, err.Error(), "(Data) ibm_cd_tekton_pipeline_trigger_property", "read", "initialize-client") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } getTektonPipelineTriggerPropertyOptions := &cdtektonpipelinev2.GetTektonPipelineTriggerPropertyOptions{} @@ -89,41 +97,54 @@ func dataSourceIBMCdTektonPipelineTriggerPropertyRead(context context.Context, d getTektonPipelineTriggerPropertyOptions.SetTriggerID(d.Get("trigger_id").(string)) getTektonPipelineTriggerPropertyOptions.SetPropertyName(d.Get("property_name").(string)) - triggerProperty, response, err := cdTektonPipelineClient.GetTektonPipelineTriggerPropertyWithContext(context, getTektonPipelineTriggerPropertyOptions) + triggerProperty, _, err := cdTektonPipelineClient.GetTektonPipelineTriggerPropertyWithContext(context, getTektonPipelineTriggerPropertyOptions) if err != nil { - log.Printf("[DEBUG] GetTektonPipelineTriggerPropertyWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("GetTektonPipelineTriggerPropertyWithContext failed %s\n%s", err, response)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("GetTektonPipelineTriggerPropertyWithContext failed: %s", err.Error()), "(Data) ibm_cd_tekton_pipeline_trigger_property", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } d.SetId(fmt.Sprintf("%s/%s/%s", *getTektonPipelineTriggerPropertyOptions.PipelineID, *getTektonPipelineTriggerPropertyOptions.TriggerID, *getTektonPipelineTriggerPropertyOptions.PropertyName)) if err = d.Set("name", triggerProperty.Name); err != nil { - return diag.FromErr(fmt.Errorf("Error setting name: %s", err)) + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting name: %s", err), "(Data) ibm_cd_tekton_pipeline_trigger_property", "read", "set-name").GetDiag() } - if err = d.Set("value", triggerProperty.Value); err != nil { - return diag.FromErr(fmt.Errorf("Error setting value: %s", err)) + if !core.IsNil(triggerProperty.Value) { + if err = d.Set("value", triggerProperty.Value); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting value: %s", err), "(Data) ibm_cd_tekton_pipeline_trigger_property", "read", "set-value").GetDiag() + } } - if err = d.Set("href", triggerProperty.Href); err != nil { - return diag.FromErr(fmt.Errorf("Error setting href: %s", err)) + if !core.IsNil(triggerProperty.Href) { + if err = d.Set("href", triggerProperty.Href); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting href: %s", err), "(Data) ibm_cd_tekton_pipeline_trigger_property", "read", "set-href").GetDiag() + } } - if err = d.Set("type", triggerProperty.Type); err != nil { - return diag.FromErr(fmt.Errorf("Error setting type: %s", err)) + if !core.IsNil(triggerProperty.Enum) { + enum := []interface{}{} + for _, enumItem := range triggerProperty.Enum { + enum = append(enum, enumItem) + } + if err = d.Set("enum", enum); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting enum: %s", err), "(Data) ibm_cd_tekton_pipeline_trigger_property", "read", "set-enum").GetDiag() + } } - if err = d.Set("path", triggerProperty.Path); err != nil { - return diag.FromErr(fmt.Errorf("Error setting path: %s", err)) + if err = d.Set("type", triggerProperty.Type); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting type: %s", err), "(Data) ibm_cd_tekton_pipeline_trigger_property", "read", "set-type").GetDiag() } - if err = d.Set("locked", triggerProperty.Locked); err != nil { - return diag.FromErr(fmt.Errorf("Error setting locked: %s", err)) + if !core.IsNil(triggerProperty.Path) { + if err = d.Set("path", triggerProperty.Path); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting path: %s", err), "(Data) ibm_cd_tekton_pipeline_trigger_property", "read", "set-path").GetDiag() + } } - if triggerProperty.Enum != nil { - if err = d.Set("enum", triggerProperty.Enum); err != nil { - return diag.FromErr(fmt.Errorf("Error setting enum: %s", err)) + if !core.IsNil(triggerProperty.Locked) { + if err = d.Set("locked", triggerProperty.Locked); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting locked: %s", err), "(Data) ibm_cd_tekton_pipeline_trigger_property", "read", "set-locked").GetDiag() } } diff --git a/ibm/service/cdtektonpipeline/data_source_ibm_cd_tekton_pipeline_trigger_property_test.go b/ibm/service/cdtektonpipeline/data_source_ibm_cd_tekton_pipeline_trigger_property_test.go index 7e547027c8..e933ce643c 100644 --- a/ibm/service/cdtektonpipeline/data_source_ibm_cd_tekton_pipeline_trigger_property_test.go +++ b/ibm/service/cdtektonpipeline/data_source_ibm_cd_tekton_pipeline_trigger_property_test.go @@ -1,6 +1,10 @@ // Copyright IBM Corp. 2024 All Rights Reserved. // Licensed under the Mozilla Public License v2.0 +/* + * IBM OpenAPI Terraform Generator Version: 3.95.2-120e65bc-20240924-152329 + */ + package cdtektonpipeline_test import ( @@ -24,10 +28,10 @@ func TestAccIBMCdTektonPipelineTriggerPropertyDataSourceBasic(t *testing.T) { resource.TestStep{ Config: testAccCheckIBMCdTektonPipelineTriggerPropertyDataSourceConfigBasic("", "", triggerPropertyName, triggerPropertyType), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_trigger_property.cd_tekton_pipeline_trigger_property", "id"), - resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_trigger_property.cd_tekton_pipeline_trigger_property", "property_name"), - resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_trigger_property.cd_tekton_pipeline_trigger_property", "name"), - resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_trigger_property.cd_tekton_pipeline_trigger_property", "type"), + resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_trigger_property.cd_tekton_pipeline_trigger_property_instance", "id"), + resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_trigger_property.cd_tekton_pipeline_trigger_property_instance", "property_name"), + resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_trigger_property.cd_tekton_pipeline_trigger_property_instance", "name"), + resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_trigger_property.cd_tekton_pipeline_trigger_property_instance", "type"), ), }, }, @@ -36,8 +40,8 @@ func TestAccIBMCdTektonPipelineTriggerPropertyDataSourceBasic(t *testing.T) { func TestAccIBMCdTektonPipelineTriggerPropertyDataSourceAllArgs(t *testing.T) { triggerPropertyName := fmt.Sprintf("tf_name_%d", acctest.RandIntRange(10, 100)) - triggerPropertyType := "text" triggerPropertyValue := fmt.Sprintf("tf_value_%d", acctest.RandIntRange(10, 100)) + triggerPropertyType := "text" triggerPropertyPath := fmt.Sprintf("tf_path_%d", acctest.RandIntRange(10, 100)) triggerPropertyLocked := "true" @@ -46,15 +50,15 @@ func TestAccIBMCdTektonPipelineTriggerPropertyDataSourceAllArgs(t *testing.T) { Providers: acc.TestAccProviders, Steps: []resource.TestStep{ resource.TestStep{ - Config: testAccCheckIBMCdTektonPipelineTriggerPropertyDataSourceConfig("", "", triggerPropertyName, triggerPropertyType, triggerPropertyValue, triggerPropertyPath, triggerPropertyLocked), + Config: testAccCheckIBMCdTektonPipelineTriggerPropertyDataSourceConfig("", "", triggerPropertyName, triggerPropertyValue, triggerPropertyType, triggerPropertyPath, triggerPropertyLocked), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_trigger_property.cd_tekton_pipeline_trigger_property", "id"), - resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_trigger_property.cd_tekton_pipeline_trigger_property", "property_name"), - resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_trigger_property.cd_tekton_pipeline_trigger_property", "name"), - resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_trigger_property.cd_tekton_pipeline_trigger_property", "value"), - resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_trigger_property.cd_tekton_pipeline_trigger_property", "href"), - resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_trigger_property.cd_tekton_pipeline_trigger_property", "type"), - resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_trigger_property.cd_tekton_pipeline_trigger_property", "locked"), + resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_trigger_property.cd_tekton_pipeline_trigger_property_instance", "id"), + resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_trigger_property.cd_tekton_pipeline_trigger_property_instance", "property_name"), + resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_trigger_property.cd_tekton_pipeline_trigger_property_instance", "name"), + resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_trigger_property.cd_tekton_pipeline_trigger_property_instance", "value"), + resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_trigger_property.cd_tekton_pipeline_trigger_property_instance", "href"), + resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_trigger_property.cd_tekton_pipeline_trigger_property_instance", "type"), + resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_trigger_property.cd_tekton_pipeline_trigger_property_instance", "locked"), ), }, }, @@ -78,7 +82,7 @@ func testAccCheckIBMCdTektonPipelineTriggerPropertyDataSourceConfigBasic(trigger name = "pipeline-name" } } - resource "ibm_cd_tekton_pipeline" "cd_tekton_pipeline" { + resource "ibm_cd_tekton_pipeline" "cd_tekton_pipeline_instance" { pipeline_id = ibm_cd_toolchain_tool_pipeline.ibm_cd_toolchain_tool_pipeline.tool_id next_build_number = 5 worker { @@ -97,8 +101,8 @@ func testAccCheckIBMCdTektonPipelineTriggerPropertyDataSourceConfigBasic(trigger } parameters {} } - resource "ibm_cd_tekton_pipeline_definition" "cd_tekton_pipeline_definition" { - pipeline_id = ibm_cd_tekton_pipeline.cd_tekton_pipeline.pipeline_id + resource "ibm_cd_tekton_pipeline_definition" "cd_tekton_pipeline_definition_instance" { + pipeline_id = ibm_cd_tekton_pipeline.cd_tekton_pipeline_instance.pipeline_id source { type = "git" properties { @@ -108,34 +112,34 @@ func testAccCheckIBMCdTektonPipelineTriggerPropertyDataSourceConfigBasic(trigger } } depends_on = [ - ibm_cd_tekton_pipeline.cd_tekton_pipeline + ibm_cd_tekton_pipeline.cd_tekton_pipeline_instance ] } - resource "ibm_cd_tekton_pipeline_trigger" "cd_tekton_pipeline_trigger" { + resource "ibm_cd_tekton_pipeline_trigger" "cd_tekton_pipeline_trigger_instance" { pipeline_id = ibm_cd_toolchain_tool_pipeline.ibm_cd_toolchain_tool_pipeline.tool_id depends_on = [ - ibm_cd_tekton_pipeline_definition.cd_tekton_pipeline_definition + ibm_cd_tekton_pipeline_definition.cd_tekton_pipeline_definition_instance ] name = "trigger" type = "manual" event_listener = "listener" } - resource "ibm_cd_tekton_pipeline_trigger_property" "cd_tekton_pipeline_trigger_property" { - pipeline_id = ibm_cd_tekton_pipeline.cd_tekton_pipeline.pipeline_id - trigger_id = ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger.trigger_id + resource "ibm_cd_tekton_pipeline_trigger_property" "cd_tekton_pipeline_trigger_property_instance" { + pipeline_id = ibm_cd_tekton_pipeline.cd_tekton_pipeline_instance.pipeline_id + trigger_id = ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger_instance.trigger_id type = "text" name = "trig-prop-1" value = "trig-prop-value-1" } - data "ibm_cd_tekton_pipeline_trigger_property" "cd_tekton_pipeline_trigger_property" { - pipeline_id = ibm_cd_tekton_pipeline_trigger_property.cd_tekton_pipeline_trigger_property.pipeline_id - trigger_id = ibm_cd_tekton_pipeline_trigger_property.cd_tekton_pipeline_trigger_property.trigger_id + data "ibm_cd_tekton_pipeline_trigger_property" "cd_tekton_pipeline_trigger_property_instance" { + pipeline_id = ibm_cd_tekton_pipeline_trigger_property.cd_tekton_pipeline_trigger_property_instance.pipeline_id + trigger_id = ibm_cd_tekton_pipeline_trigger_property.cd_tekton_pipeline_trigger_property_instance.trigger_id property_name = "trig-prop-1" } `, rgName, tcName) } -func testAccCheckIBMCdTektonPipelineTriggerPropertyDataSourceConfig(triggerPropertyPipelineID string, triggerPropertyTriggerID string, triggerPropertyName string, triggerPropertyType string, triggerPropertyValue string, triggerPropertyPath string, triggerPropertyLocked string) string { +func testAccCheckIBMCdTektonPipelineTriggerPropertyDataSourceConfig(triggerPropertyPipelineID string, triggerPropertyTriggerID string, triggerPropertyName string, triggerPropertyValue string, triggerPropertyType string, triggerPropertyPath string, triggerPropertyLocked string) string { rgName := acc.CdResourceGroupName tcName := fmt.Sprintf("tf_name_%d", acctest.RandIntRange(10, 100)) return fmt.Sprintf(` @@ -152,7 +156,7 @@ func testAccCheckIBMCdTektonPipelineTriggerPropertyDataSourceConfig(triggerPrope name = "pipeline-name" } } - resource "ibm_cd_tekton_pipeline" "cd_tekton_pipeline" { + resource "ibm_cd_tekton_pipeline" "cd_tekton_pipeline_instance" { pipeline_id = ibm_cd_toolchain_tool_pipeline.ibm_cd_toolchain_tool_pipeline.tool_id next_build_number = 5 worker { @@ -171,8 +175,8 @@ func testAccCheckIBMCdTektonPipelineTriggerPropertyDataSourceConfig(triggerPrope } parameters {} } - resource "ibm_cd_tekton_pipeline_definition" "cd_tekton_pipeline_definition" { - pipeline_id = ibm_cd_tekton_pipeline.cd_tekton_pipeline.pipeline_id + resource "ibm_cd_tekton_pipeline_definition" "cd_tekton_pipeline_definition_instance" { + pipeline_id = ibm_cd_tekton_pipeline.cd_tekton_pipeline_instance.pipeline_id source { type = "git" properties { @@ -182,29 +186,29 @@ func testAccCheckIBMCdTektonPipelineTriggerPropertyDataSourceConfig(triggerPrope } } depends_on = [ - ibm_cd_tekton_pipeline.cd_tekton_pipeline + ibm_cd_tekton_pipeline.cd_tekton_pipeline_instance ] } - resource "ibm_cd_tekton_pipeline_trigger" "cd_tekton_pipeline_trigger" { + resource "ibm_cd_tekton_pipeline_trigger" "cd_tekton_pipeline_trigger_instance" { pipeline_id = ibm_cd_toolchain_tool_pipeline.ibm_cd_toolchain_tool_pipeline.tool_id depends_on = [ - ibm_cd_tekton_pipeline_definition.cd_tekton_pipeline_definition + ibm_cd_tekton_pipeline_definition.cd_tekton_pipeline_definition_instance ] name = "trigger" type = "manual" event_listener = "listener" } - resource "ibm_cd_tekton_pipeline_trigger_property" "cd_tekton_pipeline_trigger_property" { - pipeline_id = ibm_cd_tekton_pipeline.cd_tekton_pipeline.pipeline_id - trigger_id = ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger.trigger_id + resource "ibm_cd_tekton_pipeline_trigger_property" "cd_tekton_pipeline_trigger_property_instance" { + pipeline_id = ibm_cd_tekton_pipeline.cd_tekton_pipeline_instance.pipeline_id + trigger_id = ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger_instance.trigger_id name = "%s" type = "%s" value = "%s" locked = "%s" } - data "ibm_cd_tekton_pipeline_trigger_property" "cd_tekton_pipeline_trigger_property" { - pipeline_id = ibm_cd_tekton_pipeline_trigger_property.cd_tekton_pipeline_trigger_property.pipeline_id - trigger_id = ibm_cd_tekton_pipeline_trigger_property.cd_tekton_pipeline_trigger_property.trigger_id + data "ibm_cd_tekton_pipeline_trigger_property" "cd_tekton_pipeline_trigger_property_instance" { + pipeline_id = ibm_cd_tekton_pipeline_trigger_property.cd_tekton_pipeline_trigger_property_instance.pipeline_id + trigger_id = ibm_cd_tekton_pipeline_trigger_property.cd_tekton_pipeline_trigger_property_instance.trigger_id property_name = "%s" } `, rgName, tcName, triggerPropertyName, triggerPropertyType, triggerPropertyValue, triggerPropertyLocked, triggerPropertyName) diff --git a/ibm/service/cdtektonpipeline/data_source_ibm_cd_tekton_pipeline_trigger_test.go b/ibm/service/cdtektonpipeline/data_source_ibm_cd_tekton_pipeline_trigger_test.go index 3c60c56c33..751b1941d6 100644 --- a/ibm/service/cdtektonpipeline/data_source_ibm_cd_tekton_pipeline_trigger_test.go +++ b/ibm/service/cdtektonpipeline/data_source_ibm_cd_tekton_pipeline_trigger_test.go @@ -1,6 +1,10 @@ // Copyright IBM Corp. 2024 All Rights Reserved. // Licensed under the Mozilla Public License v2.0 +/* + * IBM OpenAPI Terraform Generator Version: 3.95.2-120e65bc-20240924-152329 + */ + package cdtektonpipeline_test import ( @@ -11,6 +15,10 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" acc "github.com/IBM-Cloud/terraform-provider-ibm/ibm/acctest" + "github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/cdtektonpipeline" + "github.com/IBM/continuous-delivery-go-sdk/cdtektonpipelinev2" + "github.com/IBM/go-sdk-core/v5/core" + "github.com/stretchr/testify/assert" ) func TestAccIBMCdTektonPipelineTriggerDataSourceBasic(t *testing.T) { @@ -26,9 +34,9 @@ func TestAccIBMCdTektonPipelineTriggerDataSourceBasic(t *testing.T) { resource.TestStep{ Config: testAccCheckIBMCdTektonPipelineTriggerDataSourceConfigBasic(triggerPipelineID, triggerType, triggerName, triggerEventListener), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger", "id"), - resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger", "pipeline_id"), - resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger", "trigger_id"), + resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger_instance", "id"), + resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger_instance", "pipeline_id"), + resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger_instance", "trigger_id"), ), }, }, @@ -42,34 +50,30 @@ func TestAccIBMCdTektonPipelineTriggerDataSourceAllArgs(t *testing.T) { triggerEventListener := fmt.Sprintf("tf_event_listener_%d", acctest.RandIntRange(10, 100)) triggerMaxConcurrentRuns := fmt.Sprintf("%d", acctest.RandIntRange(10, 100)) triggerEnabled := "false" - triggerCron := fmt.Sprintf("tf_cron_%d", acctest.RandIntRange(10, 100)) - triggerTimezone := fmt.Sprintf("tf_timezone_%d", acctest.RandIntRange(10, 100)) - triggerFilter := fmt.Sprintf("tf_filter_%d", acctest.RandIntRange(10, 100)) triggerFavorite := "true" triggerEnableEventsFromForks := "true" + triggerFilter := fmt.Sprintf("tf_filter_%d", acctest.RandIntRange(10, 100)) + triggerCron := fmt.Sprintf("tf_cron_%d", acctest.RandIntRange(10, 100)) + triggerTimezone := fmt.Sprintf("tf_timezone_%d", acctest.RandIntRange(10, 100)) resource.Test(t, resource.TestCase{ PreCheck: func() { acc.TestAccPreCheck(t) }, Providers: acc.TestAccProviders, Steps: []resource.TestStep{ resource.TestStep{ - Config: testAccCheckIBMCdTektonPipelineTriggerDataSourceConfig(triggerPipelineID, triggerType, triggerName, triggerEventListener, triggerMaxConcurrentRuns, triggerEnabled, triggerCron, triggerTimezone, triggerFilter, triggerFavorite, triggerEnableEventsFromForks), + Config: testAccCheckIBMCdTektonPipelineTriggerDataSourceConfig(triggerPipelineID, triggerType, triggerName, triggerEventListener, triggerMaxConcurrentRuns, triggerEnabled, triggerFavorite, triggerEnableEventsFromForks, triggerFilter, triggerCron, triggerTimezone), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger", "id"), - resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger", "pipeline_id"), - resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger", "trigger_id"), - resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger", "type"), - resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger", "name"), - resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger", "href"), - resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger", "event_listener"), - resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger", "properties.#"), - resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger", "worker.#"), - resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger", "max_concurrent_runs"), - resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger", "enabled"), - resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger", "favorite"), - resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger", "enable_events_from_forks"), - resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger", "source.#"), - resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger", "secret.#"), + resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger_instance", "id"), + resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger_instance", "pipeline_id"), + resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger_instance", "trigger_id"), + resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger_instance", "type"), + resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger_instance", "name"), + resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger_instance", "href"), + resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger_instance", "event_listener"), + resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger_instance", "properties.#"), + resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger_instance", "max_concurrent_runs"), + resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger_instance", "enabled"), + resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger_instance", "favorite"), ), }, }, @@ -93,7 +97,7 @@ func testAccCheckIBMCdTektonPipelineTriggerDataSourceConfigBasic(triggerPipeline name = "pipeline-name" } } - resource "ibm_cd_tekton_pipeline" "cd_tekton_pipeline" { + resource "ibm_cd_tekton_pipeline" "cd_tekton_pipeline_instance" { pipeline_id = ibm_cd_toolchain_tool_pipeline.ibm_cd_toolchain_tool_pipeline.tool_id next_build_number = 5 worker { @@ -112,8 +116,8 @@ func testAccCheckIBMCdTektonPipelineTriggerDataSourceConfigBasic(triggerPipeline } parameters {} } - resource "ibm_cd_tekton_pipeline_definition" "cd_tekton_pipeline_definition" { - pipeline_id = ibm_cd_tekton_pipeline.cd_tekton_pipeline.pipeline_id + resource "ibm_cd_tekton_pipeline_definition" "cd_tekton_pipeline_definition_instance" { + pipeline_id = ibm_cd_tekton_pipeline.cd_tekton_pipeline_instance.pipeline_id source { type = "git" properties { @@ -123,27 +127,27 @@ func testAccCheckIBMCdTektonPipelineTriggerDataSourceConfigBasic(triggerPipeline } } depends_on = [ - ibm_cd_tekton_pipeline.cd_tekton_pipeline + ibm_cd_tekton_pipeline.cd_tekton_pipeline_instance ] } - resource "ibm_cd_tekton_pipeline_trigger" "cd_tekton_pipeline_trigger" { + resource "ibm_cd_tekton_pipeline_trigger" "cd_tekton_pipeline_trigger_instance" { pipeline_id = ibm_cd_toolchain_tool_pipeline.ibm_cd_toolchain_tool_pipeline.tool_id depends_on = [ - ibm_cd_tekton_pipeline_definition.cd_tekton_pipeline_definition + ibm_cd_tekton_pipeline_definition.cd_tekton_pipeline_definition_instance ] type = "%s" name = "%s" event_listener = "%s" } - data "ibm_cd_tekton_pipeline_trigger" "cd_tekton_pipeline_trigger" { - pipeline_id = ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger.pipeline_id - trigger_id = ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger.trigger_id + data "ibm_cd_tekton_pipeline_trigger" "cd_tekton_pipeline_trigger_instance" { + pipeline_id = ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger_instance.pipeline_id + trigger_id = ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger_instance.trigger_id } `, rgName, tcName, triggerType, triggerName, triggerEventListener) } -func testAccCheckIBMCdTektonPipelineTriggerDataSourceConfig(triggerPipelineID string, triggerType string, triggerName string, triggerEventListener string, triggerMaxConcurrentRuns string, triggerEnabled string, triggerCron string, triggerTimezone string, triggerFilter string, triggerFavorite string, triggerEnableEventsFromForks string) string { +func testAccCheckIBMCdTektonPipelineTriggerDataSourceConfig(triggerPipelineID string, triggerType string, triggerName string, triggerEventListener string, triggerMaxConcurrentRuns string, triggerEnabled string, triggerFavorite string, triggerEnableEventsFromForks string, triggerFilter string, triggerCron string, triggerTimezone string) string { rgName := acc.CdResourceGroupName tcName := fmt.Sprintf("tf_name_%d", acctest.RandIntRange(10, 100)) return fmt.Sprintf(` @@ -160,7 +164,7 @@ func testAccCheckIBMCdTektonPipelineTriggerDataSourceConfig(triggerPipelineID st name = "pipeline-name" } } - resource "ibm_cd_tekton_pipeline" "cd_tekton_pipeline" { + resource "ibm_cd_tekton_pipeline" "cd_tekton_pipeline_instance" { pipeline_id = ibm_cd_toolchain_tool_pipeline.ibm_cd_toolchain_tool_pipeline.tool_id next_build_number = 5 worker { @@ -179,8 +183,8 @@ func testAccCheckIBMCdTektonPipelineTriggerDataSourceConfig(triggerPipelineID st } parameters {} } - resource "ibm_cd_tekton_pipeline_definition" "cd_tekton_pipeline_definition" { - pipeline_id = ibm_cd_tekton_pipeline.cd_tekton_pipeline.pipeline_id + resource "ibm_cd_tekton_pipeline_definition" "cd_tekton_pipeline_definition_instance" { + pipeline_id = ibm_cd_tekton_pipeline.cd_tekton_pipeline_instance.pipeline_id source { type = "git" properties { @@ -190,24 +194,185 @@ func testAccCheckIBMCdTektonPipelineTriggerDataSourceConfig(triggerPipelineID st } } depends_on = [ - ibm_cd_tekton_pipeline.cd_tekton_pipeline + ibm_cd_tekton_pipeline.cd_tekton_pipeline_instance ] } - resource "ibm_cd_tekton_pipeline_trigger" "cd_tekton_pipeline_trigger" { + resource "ibm_cd_tekton_pipeline_trigger" "cd_tekton_pipeline_trigger_instance" { pipeline_id = ibm_cd_toolchain_tool_pipeline.ibm_cd_toolchain_tool_pipeline.tool_id depends_on = [ - ibm_cd_tekton_pipeline_definition.cd_tekton_pipeline_definition + ibm_cd_tekton_pipeline_definition.cd_tekton_pipeline_definition_instance ] type = "%s" name = "%s" event_listener = "%s" max_concurrent_runs = %s enabled = %s + favorite = %s } - data "ibm_cd_tekton_pipeline_trigger" "cd_tekton_pipeline_trigger" { - pipeline_id = ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger.pipeline_id - trigger_id = ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger.trigger_id + data "ibm_cd_tekton_pipeline_trigger" "cd_tekton_pipeline_trigger_instance" { + pipeline_id = ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger_instance.pipeline_id + trigger_id = ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger_instance.trigger_id } - `, rgName, tcName, triggerType, triggerName, triggerEventListener, triggerMaxConcurrentRuns, triggerEnabled) + `, rgName, tcName, triggerType, triggerName, triggerEventListener, triggerMaxConcurrentRuns, triggerEnabled, triggerFavorite) +} + +func TestDataSourceIBMCdTektonPipelineTriggerTriggerPropertyToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + model := make(map[string]interface{}) + model["name"] = "testString" + model["value"] = "testString" + model["href"] = "testString" + model["enum"] = []string{"testString"} + model["type"] = "secure" + model["path"] = "testString" + model["locked"] = true + + assert.Equal(t, result, model) + } + + model := new(cdtektonpipelinev2.TriggerProperty) + model.Name = core.StringPtr("testString") + model.Value = core.StringPtr("testString") + model.Href = core.StringPtr("testString") + model.Enum = []string{"testString"} + model.Type = core.StringPtr("secure") + model.Path = core.StringPtr("testString") + model.Locked = core.BoolPtr(true) + + result, err := cdtektonpipeline.DataSourceIBMCdTektonPipelineTriggerTriggerPropertyToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestDataSourceIBMCdTektonPipelineTriggerWorkerToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + model := make(map[string]interface{}) + model["name"] = "testString" + model["type"] = "testString" + model["id"] = "testString" + + assert.Equal(t, result, model) + } + + model := new(cdtektonpipelinev2.Worker) + model.Name = core.StringPtr("testString") + model.Type = core.StringPtr("testString") + model.ID = core.StringPtr("testString") + + result, err := cdtektonpipeline.DataSourceIBMCdTektonPipelineTriggerWorkerToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestDataSourceIBMCdTektonPipelineTriggerTriggerSourceToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + toolModel := make(map[string]interface{}) + toolModel["id"] = "testString" + + triggerSourcePropertiesModel := make(map[string]interface{}) + triggerSourcePropertiesModel["url"] = "testString" + triggerSourcePropertiesModel["branch"] = "testString" + triggerSourcePropertiesModel["pattern"] = "testString" + triggerSourcePropertiesModel["blind_connection"] = true + triggerSourcePropertiesModel["hook_id"] = "testString" + triggerSourcePropertiesModel["tool"] = []map[string]interface{}{toolModel} + + model := make(map[string]interface{}) + model["type"] = "testString" + model["properties"] = []map[string]interface{}{triggerSourcePropertiesModel} + + assert.Equal(t, result, model) + } + + toolModel := new(cdtektonpipelinev2.Tool) + toolModel.ID = core.StringPtr("testString") + + triggerSourcePropertiesModel := new(cdtektonpipelinev2.TriggerSourceProperties) + triggerSourcePropertiesModel.URL = core.StringPtr("testString") + triggerSourcePropertiesModel.Branch = core.StringPtr("testString") + triggerSourcePropertiesModel.Pattern = core.StringPtr("testString") + triggerSourcePropertiesModel.BlindConnection = core.BoolPtr(true) + triggerSourcePropertiesModel.HookID = core.StringPtr("testString") + triggerSourcePropertiesModel.Tool = toolModel + + model := new(cdtektonpipelinev2.TriggerSource) + model.Type = core.StringPtr("testString") + model.Properties = triggerSourcePropertiesModel + + result, err := cdtektonpipeline.DataSourceIBMCdTektonPipelineTriggerTriggerSourceToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestDataSourceIBMCdTektonPipelineTriggerTriggerSourcePropertiesToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + toolModel := make(map[string]interface{}) + toolModel["id"] = "testString" + + model := make(map[string]interface{}) + model["url"] = "testString" + model["branch"] = "testString" + model["pattern"] = "testString" + model["blind_connection"] = true + model["hook_id"] = "testString" + model["tool"] = []map[string]interface{}{toolModel} + + assert.Equal(t, result, model) + } + + toolModel := new(cdtektonpipelinev2.Tool) + toolModel.ID = core.StringPtr("testString") + + model := new(cdtektonpipelinev2.TriggerSourceProperties) + model.URL = core.StringPtr("testString") + model.Branch = core.StringPtr("testString") + model.Pattern = core.StringPtr("testString") + model.BlindConnection = core.BoolPtr(true) + model.HookID = core.StringPtr("testString") + model.Tool = toolModel + + result, err := cdtektonpipeline.DataSourceIBMCdTektonPipelineTriggerTriggerSourcePropertiesToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestDataSourceIBMCdTektonPipelineTriggerToolToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + model := make(map[string]interface{}) + model["id"] = "testString" + + assert.Equal(t, result, model) + } + + model := new(cdtektonpipelinev2.Tool) + model.ID = core.StringPtr("testString") + + result, err := cdtektonpipeline.DataSourceIBMCdTektonPipelineTriggerToolToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestDataSourceIBMCdTektonPipelineTriggerGenericSecretToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + model := make(map[string]interface{}) + model["type"] = "token_matches" + model["value"] = "testString" + model["source"] = "header" + model["key_name"] = "testString" + model["algorithm"] = "md4" + + assert.Equal(t, result, model) + } + + model := new(cdtektonpipelinev2.GenericSecret) + model.Type = core.StringPtr("token_matches") + model.Value = core.StringPtr("testString") + model.Source = core.StringPtr("header") + model.KeyName = core.StringPtr("testString") + model.Algorithm = core.StringPtr("md4") + + result, err := cdtektonpipeline.DataSourceIBMCdTektonPipelineTriggerGenericSecretToMap(model) + assert.Nil(t, err) + checkResult(result) } diff --git a/ibm/service/cdtektonpipeline/resource_ibm_cd_tekton_pipeline.go b/ibm/service/cdtektonpipeline/resource_ibm_cd_tekton_pipeline.go index 4d5b9abd67..8e7da3babc 100644 --- a/ibm/service/cdtektonpipeline/resource_ibm_cd_tekton_pipeline.go +++ b/ibm/service/cdtektonpipeline/resource_ibm_cd_tekton_pipeline.go @@ -1,6 +1,10 @@ // Copyright IBM Corp. 2024 All Rights Reserved. // Licensed under the Mozilla Public License v2.0 +/* + * IBM OpenAPI Terraform Generator Version: 3.95.2-120e65bc-20240924-152329 + */ + package cdtektonpipeline import ( @@ -27,30 +31,23 @@ func ResourceIBMCdTektonPipeline() *schema.Resource { Importer: &schema.ResourceImporter{}, Schema: map[string]*schema.Schema{ - "next_build_number": &schema.Schema{ - Type: schema.TypeInt, - Optional: true, - Description: "Specify the build number that will be used for the next pipeline run. Build numbers can be any positive whole number between 0 and 100000000000000.", - }, - "enable_notifications": &schema.Schema{ - Type: schema.TypeBool, - Optional: true, - Default: false, - Description: "Flag to enable notifications for this pipeline. If enabled, the Tekton pipeline run events will be published to all the destinations specified by the Slack and Event Notifications integrations in the parent toolchain.", - }, - "enable_partial_cloning": &schema.Schema{ - Type: schema.TypeBool, - Optional: true, - Default: false, - Description: "Flag to enable partial cloning for this pipeline. When partial clone is enabled, only the files contained within the paths specified in definition repositories are read and cloned, this means that symbolic links might not work.", - }, "worker": &schema.Schema{ Type: schema.TypeList, MaxItems: 1, Optional: true, - Description: "Specify the worker that is to be used to run the trigger, indicated by a worker object with only the worker ID. If not specified or set as `worker: { id: 'public' }`, the IBM Managed shared workers are used.", + Description: "Details of the worker used to run the pipeline.", Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ + "name": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Name of the worker. Computed based on the worker ID.", + }, + "type": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Type of the worker. Computed based on the worker ID.", + }, "id": &schema.Schema{ Type: schema.TypeString, Required: true, @@ -59,6 +56,23 @@ func ResourceIBMCdTektonPipeline() *schema.Resource { }, }, }, + "next_build_number": &schema.Schema{ + Type: schema.TypeInt, + Optional: true, + Description: "The build number that will be used for the next pipeline run.", + }, + "enable_notifications": &schema.Schema{ + Type: schema.TypeBool, + Optional: true, + Default: false, + Description: "Flag to enable notifications for this pipeline. If enabled, the Tekton pipeline run events will be published to all the destinations specified by the Slack and Event Notifications integrations in the parent toolchain. If omitted, this feature is disabled by default.", + }, + "enable_partial_cloning": &schema.Schema{ + Type: schema.TypeBool, + Optional: true, + Default: false, + Description: "Flag to enable partial cloning for this pipeline. When partial clone is enabled, only the files contained within the paths specified in definition repositories are read and cloned, this means that symbolic links might not work. If omitted, this feature is disabled by default.", + }, "pipeline_id": &schema.Schema{ Type: schema.TypeString, Required: true, @@ -84,6 +98,7 @@ func ResourceIBMCdTektonPipeline() *schema.Resource { "id": &schema.Schema{ Type: schema.TypeString, Optional: true, + Computed: true, Description: "ID.", }, }, @@ -97,12 +112,12 @@ func ResourceIBMCdTektonPipeline() *schema.Resource { Schema: map[string]*schema.Schema{ "id": &schema.Schema{ Type: schema.TypeString, - Required: true, - Description: "UUID.", + Computed: true, + Description: "Universally Unique Identifier.", }, "crn": &schema.Schema{ Type: schema.TypeString, - Required: true, + Computed: true, Description: "The CRN for the toolchain that contains the Tekton pipeline.", }, }, @@ -116,48 +131,47 @@ func ResourceIBMCdTektonPipeline() *schema.Resource { Schema: map[string]*schema.Schema{ "source": &schema.Schema{ Type: schema.TypeList, - MinItems: 1, - MaxItems: 1, - Required: true, + Computed: true, Description: "Source repository containing the Tekton pipeline definition.", Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "type": &schema.Schema{ Type: schema.TypeString, - Required: true, + Computed: true, Description: "The only supported source type is \"git\", indicating that the source is a git repository.", }, "properties": &schema.Schema{ Type: schema.TypeList, - MinItems: 1, - MaxItems: 1, - Required: true, + Computed: true, Description: "Properties of the source, which define the URL of the repository and a branch or tag.", Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "url": &schema.Schema{ Type: schema.TypeString, - Required: true, + Computed: true, ForceNew: true, Description: "URL of the definition repository.", }, "branch": &schema.Schema{ Type: schema.TypeString, Optional: true, + Computed: true, Description: "A branch from the repo, specify one of branch or tag only.", }, "tag": &schema.Schema{ Type: schema.TypeString, Optional: true, + Computed: true, Description: "A tag from the repo, specify one of branch or tag only.", }, "path": &schema.Schema{ Type: schema.TypeString, - Required: true, + Computed: true, Description: "The path to the definition's YAML files.", }, "tool": &schema.Schema{ Type: schema.TypeList, + Optional: true, Computed: true, Description: "Reference to the repository tool in the parent toolchain.", Elem: &schema.Resource{ @@ -178,6 +192,7 @@ func ResourceIBMCdTektonPipeline() *schema.Resource { }, "href": &schema.Schema{ Type: schema.TypeString, + Optional: true, Computed: true, Description: "API URL for interacting with the definition.", }, @@ -197,41 +212,46 @@ func ResourceIBMCdTektonPipeline() *schema.Resource { Schema: map[string]*schema.Schema{ "name": &schema.Schema{ Type: schema.TypeString, - Required: true, + Computed: true, ForceNew: true, Description: "Property name.", }, "value": &schema.Schema{ Type: schema.TypeString, Optional: true, + Computed: true, DiffSuppressFunc: flex.SuppressPipelinePropertyRawSecret, Description: "Property value. Any string value is valid.", }, "href": &schema.Schema{ Type: schema.TypeString, + Optional: true, Computed: true, Description: "API URL for interacting with the property.", }, "enum": &schema.Schema{ Type: schema.TypeList, Optional: true, + Computed: true, Description: "Options for `single_select` property type. Only needed when using `single_select` property type.", Elem: &schema.Schema{Type: schema.TypeString}, }, "type": &schema.Schema{ Type: schema.TypeString, - Required: true, + Computed: true, ForceNew: true, Description: "Property type.", }, "locked": &schema.Schema{ Type: schema.TypeBool, Optional: true, + Computed: true, Description: "When true, this property cannot be overridden by a trigger property or at runtime. Attempting to override it will result in run requests being rejected. The default is false.", }, "path": &schema.Schema{ Type: schema.TypeString, Optional: true, + Computed: true, Description: "A dot notation path for `integration` type properties only, that selects a value from the tool integration. If left blank the full tool integration data will be used.", }, }, @@ -255,72 +275,83 @@ func ResourceIBMCdTektonPipeline() *schema.Resource { Schema: map[string]*schema.Schema{ "type": &schema.Schema{ Type: schema.TypeString, - Required: true, + Optional: true, + Computed: true, Description: "Trigger type.", }, "name": &schema.Schema{ Type: schema.TypeString, - Required: true, + Optional: true, + Computed: true, Description: "Trigger name.", }, "href": &schema.Schema{ Type: schema.TypeString, + Optional: true, Computed: true, Description: "API URL for interacting with the trigger. Only included when fetching the list of pipeline triggers.", }, "event_listener": &schema.Schema{ Type: schema.TypeString, - Required: true, + Optional: true, + Computed: true, Description: "Event listener name. The name of the event listener to which the trigger is associated. The event listeners are defined in the definition repositories of the Tekton pipeline.", }, "id": &schema.Schema{ Type: schema.TypeString, + Optional: true, Computed: true, Description: "The Trigger ID.", }, "properties": &schema.Schema{ Type: schema.TypeList, Optional: true, + Computed: true, Description: "Optional trigger properties are used to override or supplement the pipeline properties when triggering a pipeline run.", Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "name": &schema.Schema{ Type: schema.TypeString, - Required: true, + Computed: true, ForceNew: true, Description: "Property name.", }, "value": &schema.Schema{ Type: schema.TypeString, Optional: true, + Computed: true, DiffSuppressFunc: flex.SuppressTriggerPropertyRawSecret, Description: "Property value. Any string value is valid.", }, "href": &schema.Schema{ Type: schema.TypeString, + Optional: true, Computed: true, Description: "API URL for interacting with the trigger property.", }, "enum": &schema.Schema{ Type: schema.TypeList, Optional: true, + Computed: true, Description: "Options for `single_select` property type. Only needed for `single_select` property type.", Elem: &schema.Schema{Type: schema.TypeString}, }, "type": &schema.Schema{ Type: schema.TypeString, - Required: true, + Computed: true, ForceNew: true, Description: "Property type.", }, "path": &schema.Schema{ Type: schema.TypeString, Optional: true, + Computed: true, Description: "A dot notation path for `integration` type properties only, that selects a value from the tool integration. If left blank the full tool integration data will be used.", }, "locked": &schema.Schema{ Type: schema.TypeBool, Optional: true, + Computed: true, Description: "When true, this property cannot be overridden at runtime. Attempting to override it will result in run requests being rejected. The default is false.", }, }, @@ -329,13 +360,14 @@ func ResourceIBMCdTektonPipeline() *schema.Resource { "tags": &schema.Schema{ Type: schema.TypeList, Optional: true, + Computed: true, Description: "Optional trigger tags array.", Elem: &schema.Schema{Type: schema.TypeString}, }, "worker": &schema.Schema{ Type: schema.TypeList, - MaxItems: 1, Optional: true, + Computed: true, Description: "Details of the worker used to run the trigger.", Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ @@ -351,7 +383,7 @@ func ResourceIBMCdTektonPipeline() *schema.Resource { }, "id": &schema.Schema{ Type: schema.TypeString, - Required: true, + Computed: true, Description: "ID of the worker.", }, }, @@ -360,60 +392,61 @@ func ResourceIBMCdTektonPipeline() *schema.Resource { "max_concurrent_runs": &schema.Schema{ Type: schema.TypeInt, Optional: true, + Computed: true, Description: "Defines the maximum number of concurrent runs for this trigger. If omitted then the concurrency limit is disabled for this trigger.", }, "enabled": &schema.Schema{ Type: schema.TypeBool, Optional: true, - Default: true, + Computed: true, Description: "Flag to check if the trigger is enabled.", }, "favorite": &schema.Schema{ Type: schema.TypeBool, Optional: true, - Default: false, + Computed: true, Description: "Mark the trigger as a favorite.", }, "enable_events_from_forks": &schema.Schema{ Type: schema.TypeBool, Optional: true, - Default: false, + Computed: true, Description: "When enabled, pull request events from forks of the selected repository will trigger a pipeline run.", }, "source": &schema.Schema{ Type: schema.TypeList, - MaxItems: 1, Optional: true, + Computed: true, Description: "Source repository for a Git trigger. Only required for Git triggers. The referenced repository URL must match the URL of a repository tool integration in the parent toolchain. Obtain the list of integrations from the toolchain API https://cloud.ibm.com/apidocs/toolchain#list-tools.", Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "type": &schema.Schema{ Type: schema.TypeString, - Required: true, + Computed: true, Description: "The only supported source type is \"git\", indicating that the source is a git repository.", }, "properties": &schema.Schema{ Type: schema.TypeList, - MinItems: 1, - MaxItems: 1, - Required: true, + Computed: true, Description: "Properties of the source, which define the URL of the repository and a branch or pattern.", Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "url": &schema.Schema{ Type: schema.TypeString, - Required: true, + Computed: true, ForceNew: true, Description: "URL of the repository to which the trigger is listening.", }, "branch": &schema.Schema{ Type: schema.TypeString, Optional: true, + Computed: true, Description: "Name of a branch from the repo. Only one of branch, pattern, or filter should be specified.", }, "pattern": &schema.Schema{ Type: schema.TypeString, Optional: true, + Computed: true, Description: "The pattern of Git branch or tag. You can specify a glob pattern such as '!test' or '*master' to match against multiple tags or branches in the repository.The glob pattern used must conform to Bash 4.3 specifications, see bash documentation for more info: https://www.gnu.org/software/bash/manual/bash.html#Pattern-Matching. Only one of branch, pattern, or filter should be specified.", }, "blind_connection": &schema.Schema{ @@ -449,6 +482,7 @@ func ResourceIBMCdTektonPipeline() *schema.Resource { "events": &schema.Schema{ Type: schema.TypeList, Optional: true, + Computed: true, DiffSuppressFunc: flex.SuppressTriggerEvents, Description: "Either 'events' or 'filter' is required specifically for Git triggers. Stores a list of events that a Git trigger listens to. Choose one or more from 'push', 'pull_request', and 'pull_request_closed'. If SCM repositories use the 'merge request' term, they correspond to the generic term i.e. 'pull request'.", Elem: &schema.Schema{Type: schema.TypeString}, @@ -456,49 +490,57 @@ func ResourceIBMCdTektonPipeline() *schema.Resource { "filter": &schema.Schema{ Type: schema.TypeString, Optional: true, + Computed: true, Description: "Either 'events' or 'filter' can be used. Stores the CEL (Common Expression Language) expression value which is used for event filtering against the Git webhook payloads.", }, "cron": &schema.Schema{ Type: schema.TypeString, Optional: true, + Computed: true, Description: "Only needed for timer triggers. CRON expression that indicates when this trigger will activate. Maximum frequency is every 5 minutes. The string is based on UNIX crontab syntax: minute, hour, day of month, month, day of week. Example: The CRON expression 0 *_/2 * * * - translates to - every 2 hours.", }, "timezone": &schema.Schema{ Type: schema.TypeString, Optional: true, + Computed: true, Description: "Only used for timer triggers. Specify the timezone used for this timer trigger, which will ensure the CRON activates this trigger relative to the specified timezone. If no timezone is specified, the default timezone used is UTC. Valid timezones are those listed in the IANA timezone database, https://www.iana.org/time-zones.", }, "secret": &schema.Schema{ Type: schema.TypeList, - MaxItems: 1, Optional: true, + Computed: true, Description: "Only needed for Generic Webhook trigger type. The secret is used to start the Generic Webhook trigger.", Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "type": &schema.Schema{ Type: schema.TypeString, Optional: true, + Computed: true, Description: "Secret type.", }, "value": &schema.Schema{ Type: schema.TypeString, Optional: true, + Computed: true, DiffSuppressFunc: flex.SuppressGenericWebhookRawSecret, Description: "Secret value, not needed if secret type is `internal_validation`.", }, "source": &schema.Schema{ Type: schema.TypeString, Optional: true, + Computed: true, Description: "Secret location, not needed if secret type is `internal_validation`.", }, "key_name": &schema.Schema{ Type: schema.TypeString, Optional: true, + Computed: true, Description: "Secret name, not needed if type is `internal_validation`.", }, "algorithm": &schema.Schema{ Type: schema.TypeString, Optional: true, + Computed: true, Description: "Algorithm used for `digest_matches` secret type. Only needed for `digest_matches` secret type.", }, }, @@ -506,6 +548,7 @@ func ResourceIBMCdTektonPipeline() *schema.Resource { }, "webhook_url": &schema.Schema{ Type: schema.TypeString, + Optional: true, Computed: true, Description: "Webhook URL that can be used to trigger pipeline runs.", }, @@ -556,7 +599,9 @@ func ResourceIBMCdTektonPipelineValidator() *validate.ResourceValidator { func resourceIBMCdTektonPipelineCreate(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { cdTektonPipelineClient, err := meta.(conns.ClientSession).CdTektonPipelineV2() if err != nil { - return diag.FromErr(err) + tfErr := flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline", "create", "initialize-client") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } createTektonPipelineOptions := &cdtektonpipelinev2.CreateTektonPipelineOptions{} @@ -564,16 +609,16 @@ func resourceIBMCdTektonPipelineCreate(context context.Context, d *schema.Resour if _, ok := d.GetOk("next_build_number"); ok { createTektonPipelineOptions.SetNextBuildNumber(int64(d.Get("next_build_number").(int))) } - if _, ok := d.GetOkExists("enable_notifications"); ok { + if _, ok := d.GetOk("enable_notifications"); ok { createTektonPipelineOptions.SetEnableNotifications(d.Get("enable_notifications").(bool)) } - if _, ok := d.GetOkExists("enable_partial_cloning"); ok { + if _, ok := d.GetOk("enable_partial_cloning"); ok { createTektonPipelineOptions.SetEnablePartialCloning(d.Get("enable_partial_cloning").(bool)) } if _, ok := d.GetOk("worker"); ok { - workerModel, err := resourceIBMCdTektonPipelineMapToWorkerIdentity(d.Get("worker.0").(map[string]interface{})) + workerModel, err := ResourceIBMCdTektonPipelineMapToWorkerIdentity(d.Get("worker.0").(map[string]interface{})) if err != nil { - return diag.FromErr(err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline", "create", "parse-worker").GetDiag() } createTektonPipelineOptions.SetWorker(workerModel) } @@ -581,10 +626,11 @@ func resourceIBMCdTektonPipelineCreate(context context.Context, d *schema.Resour if _, ok := d.GetOk("pipeline_id"); ok { createTektonPipelineOptions.SetID(d.Get("pipeline_id").(string)) } - tektonPipeline, response, err := cdTektonPipelineClient.CreateTektonPipelineWithContext(context, createTektonPipelineOptions) + tektonPipeline, _, err := cdTektonPipelineClient.CreateTektonPipelineWithContext(context, createTektonPipelineOptions) if err != nil { - log.Printf("[DEBUG] CreateTektonPipelineWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("CreateTektonPipelineWithContext failed %s\n%s", err, response)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("CreateTektonPipelineWithContext failed: %s", err.Error()), "ibm_cd_tekton_pipeline", "create") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } d.SetId(*tektonPipeline.ID) @@ -595,7 +641,9 @@ func resourceIBMCdTektonPipelineCreate(context context.Context, d *schema.Resour func resourceIBMCdTektonPipelineRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { cdTektonPipelineClient, err := meta.(conns.ClientSession).CdTektonPipelineV2() if err != nil { - return diag.FromErr(err) + tfErr := flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline", "read", "initialize-client") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } getTektonPipelineOptions := &cdtektonpipelinev2.GetTektonPipelineOptions{} @@ -608,109 +656,128 @@ func resourceIBMCdTektonPipelineRead(context context.Context, d *schema.Resource d.SetId("") return nil } - log.Printf("[DEBUG] GetTektonPipelineWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("GetTektonPipelineWithContext failed %s\n%s", err, response)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("GetTektonPipelineWithContext failed: %s", err.Error()), "ibm_cd_tekton_pipeline", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } + if !core.IsNil(tektonPipeline.Worker) { + workerMap, err := ResourceIBMCdTektonPipelineWorkerToMap(tektonPipeline.Worker) + if err != nil { + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline", "read", "worker-to-map").GetDiag() + } + if err = d.Set("worker", []map[string]interface{}{workerMap}); err != nil { + err = fmt.Errorf("Error setting worker: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline", "read", "set-worker").GetDiag() + } + } if !core.IsNil(tektonPipeline.NextBuildNumber) { if err = d.Set("next_build_number", flex.IntValue(tektonPipeline.NextBuildNumber)); err != nil { - return diag.FromErr(fmt.Errorf("Error setting next_build_number: %s", err)) + err = fmt.Errorf("Error setting next_build_number: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline", "read", "set-next_build_number").GetDiag() } } if !core.IsNil(tektonPipeline.EnableNotifications) { if err = d.Set("enable_notifications", tektonPipeline.EnableNotifications); err != nil { - return diag.FromErr(fmt.Errorf("Error setting enable_notifications: %s", err)) + err = fmt.Errorf("Error setting enable_notifications: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline", "read", "set-enable_notifications").GetDiag() } } if !core.IsNil(tektonPipeline.EnablePartialCloning) { if err = d.Set("enable_partial_cloning", tektonPipeline.EnablePartialCloning); err != nil { - return diag.FromErr(fmt.Errorf("Error setting enable_partial_cloning: %s", err)) - } - } - if !core.IsNil(tektonPipeline.Worker) { - workerMap, err := resourceIBMCdTektonPipelineWorkerIdentityToMap(tektonPipeline.Worker) - if err != nil { - return diag.FromErr(err) - } - if err = d.Set("worker", []map[string]interface{}{workerMap}); err != nil { - return diag.FromErr(fmt.Errorf("Error setting worker: %s", err)) + err = fmt.Errorf("Error setting enable_partial_cloning: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline", "read", "set-enable_partial_cloning").GetDiag() } } if err = d.Set("pipeline_id", tektonPipeline.ID); err != nil { - return diag.FromErr(fmt.Errorf("Error setting pipeline_id: %s", err)) + err = fmt.Errorf("Error setting pipeline_id: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline", "read", "set-pipeline_id").GetDiag() } if err = d.Set("name", tektonPipeline.Name); err != nil { - return diag.FromErr(fmt.Errorf("Error setting name: %s", err)) + err = fmt.Errorf("Error setting name: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline", "read", "set-name").GetDiag() } if err = d.Set("status", tektonPipeline.Status); err != nil { - return diag.FromErr(fmt.Errorf("Error setting status: %s", err)) + err = fmt.Errorf("Error setting status: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline", "read", "set-status").GetDiag() } - resourceGroupMap, err := resourceIBMCdTektonPipelineResourceGroupReferenceToMap(tektonPipeline.ResourceGroup) + resourceGroupMap, err := ResourceIBMCdTektonPipelineResourceGroupReferenceToMap(tektonPipeline.ResourceGroup) if err != nil { - return diag.FromErr(err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline", "read", "resource_group-to-map").GetDiag() } if err = d.Set("resource_group", []map[string]interface{}{resourceGroupMap}); err != nil { - return diag.FromErr(fmt.Errorf("Error setting resource_group: %s", err)) + err = fmt.Errorf("Error setting resource_group: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline", "read", "set-resource_group").GetDiag() } - toolchainMap, err := resourceIBMCdTektonPipelineToolchainReferenceToMap(tektonPipeline.Toolchain) + toolchainMap, err := ResourceIBMCdTektonPipelineToolchainReferenceToMap(tektonPipeline.Toolchain) if err != nil { - return diag.FromErr(err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline", "read", "toolchain-to-map").GetDiag() } if err = d.Set("toolchain", []map[string]interface{}{toolchainMap}); err != nil { - return diag.FromErr(fmt.Errorf("Error setting toolchain: %s", err)) + err = fmt.Errorf("Error setting toolchain: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline", "read", "set-toolchain").GetDiag() } definitions := []map[string]interface{}{} for _, definitionsItem := range tektonPipeline.Definitions { - definitionsItemMap, err := resourceIBMCdTektonPipelineDefinitionToMap(&definitionsItem) + definitionsItemMap, err := ResourceIBMCdTektonPipelineDefinitionToMap(&definitionsItem) // #nosec G601 if err != nil { - return diag.FromErr(err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline", "read", "definitions-to-map").GetDiag() } definitions = append(definitions, definitionsItemMap) } if err = d.Set("definitions", definitions); err != nil { - return diag.FromErr(fmt.Errorf("Error setting definitions: %s", err)) + err = fmt.Errorf("Error setting definitions: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline", "read", "set-definitions").GetDiag() } properties := []map[string]interface{}{} for _, propertiesItem := range tektonPipeline.Properties { - propertiesItemMap, err := resourceIBMCdTektonPipelinePropertyToMap(&propertiesItem) + propertiesItemMap, err := ResourceIBMCdTektonPipelinePropertyToMap(&propertiesItem) // #nosec G601 if err != nil { - return diag.FromErr(err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline", "read", "properties-to-map").GetDiag() } properties = append(properties, propertiesItemMap) } if err = d.Set("properties", properties); err != nil { - return diag.FromErr(fmt.Errorf("Error setting properties: %s", err)) + err = fmt.Errorf("Error setting properties: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline", "read", "set-properties").GetDiag() } if err = d.Set("updated_at", flex.DateTimeToString(tektonPipeline.UpdatedAt)); err != nil { - return diag.FromErr(fmt.Errorf("Error setting updated_at: %s", err)) + err = fmt.Errorf("Error setting updated_at: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline", "read", "set-updated_at").GetDiag() } if err = d.Set("created_at", flex.DateTimeToString(tektonPipeline.CreatedAt)); err != nil { - return diag.FromErr(fmt.Errorf("Error setting created_at: %s", err)) + err = fmt.Errorf("Error setting created_at: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline", "read", "set-created_at").GetDiag() } triggers := []map[string]interface{}{} for _, triggersItem := range tektonPipeline.Triggers { - triggersItemMap, err := resourceIBMCdTektonPipelineTriggerToMap(triggersItem) + triggersItemMap, err := ResourceIBMCdTektonPipelineTriggerToMap(triggersItem) if err != nil { - return diag.FromErr(err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline", "read", "triggers-to-map").GetDiag() } triggers = append(triggers, triggersItemMap) } if err = d.Set("triggers", triggers); err != nil { - return diag.FromErr(fmt.Errorf("Error setting triggers: %s", err)) + err = fmt.Errorf("Error setting triggers: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline", "read", "set-triggers").GetDiag() } if err = d.Set("runs_url", tektonPipeline.RunsURL); err != nil { - return diag.FromErr(fmt.Errorf("Error setting runs_url: %s", err)) + err = fmt.Errorf("Error setting runs_url: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline", "read", "set-runs_url").GetDiag() } if !core.IsNil(tektonPipeline.Href) { if err = d.Set("href", tektonPipeline.Href); err != nil { - return diag.FromErr(fmt.Errorf("Error setting href: %s", err)) + err = fmt.Errorf("Error setting href: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline", "read", "set-href").GetDiag() } } if err = d.Set("build_number", flex.IntValue(tektonPipeline.BuildNumber)); err != nil { - return diag.FromErr(fmt.Errorf("Error setting build_number: %s", err)) + err = fmt.Errorf("Error setting build_number: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline", "read", "set-build_number").GetDiag() } if err = d.Set("enabled", tektonPipeline.Enabled); err != nil { - return diag.FromErr(fmt.Errorf("Error setting enabled: %s", err)) + err = fmt.Errorf("Error setting enabled: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline", "read", "set-enabled").GetDiag() } return nil @@ -719,7 +786,9 @@ func resourceIBMCdTektonPipelineRead(context context.Context, d *schema.Resource func resourceIBMCdTektonPipelineUpdate(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { cdTektonPipelineClient, err := meta.(conns.ClientSession).CdTektonPipelineV2() if err != nil { - return diag.FromErr(err) + tfErr := flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline", "update", "initialize-client") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } updateTektonPipelineOptions := &cdtektonpipelinev2.UpdateTektonPipelineOptions{} @@ -745,20 +814,25 @@ func resourceIBMCdTektonPipelineUpdate(context context.Context, d *schema.Resour hasChange = true } if d.HasChange("worker") { - worker, err := resourceIBMCdTektonPipelineMapToWorkerIdentity(d.Get("worker.0").(map[string]interface{})) + worker, err := ResourceIBMCdTektonPipelineMapToWorkerIdentity(d.Get("worker.0").(map[string]interface{})) if err != nil { - return diag.FromErr(err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline", "update", "parse-worker").GetDiag() } patchVals.Worker = worker hasChange = true } if hasChange { - updateTektonPipelineOptions.TektonPipelinePatch, _ = patchVals.AsPatch() - _, response, err := cdTektonPipelineClient.UpdateTektonPipelineWithContext(context, updateTektonPipelineOptions) + // Fields with `nil` values are omitted from the generic map, + // so we need to re-add them to support removing arguments + // in merge-patch operations sent to the service. + updateTektonPipelineOptions.TektonPipelinePatch = ResourceIBMCdTektonPipelineTektonPipelinePatchAsPatch(patchVals, d) + + _, _, err = cdTektonPipelineClient.UpdateTektonPipelineWithContext(context, updateTektonPipelineOptions) if err != nil { - log.Printf("[DEBUG] UpdateTektonPipelineWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("UpdateTektonPipelineWithContext failed %s\n%s", err, response)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("UpdateTektonPipelineWithContext failed: %s", err.Error()), "ibm_cd_tekton_pipeline", "update") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } @@ -768,17 +842,20 @@ func resourceIBMCdTektonPipelineUpdate(context context.Context, d *schema.Resour func resourceIBMCdTektonPipelineDelete(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { cdTektonPipelineClient, err := meta.(conns.ClientSession).CdTektonPipelineV2() if err != nil { - return diag.FromErr(err) + tfErr := flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline", "delete", "initialize-client") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } deleteTektonPipelineOptions := &cdtektonpipelinev2.DeleteTektonPipelineOptions{} deleteTektonPipelineOptions.SetID(d.Id()) - response, err := cdTektonPipelineClient.DeleteTektonPipelineWithContext(context, deleteTektonPipelineOptions) + _, err = cdTektonPipelineClient.DeleteTektonPipelineWithContext(context, deleteTektonPipelineOptions) if err != nil { - log.Printf("[DEBUG] DeleteTektonPipelineWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("DeleteTektonPipelineWithContext failed %s\n%s", err, response)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("DeleteTektonPipelineWithContext failed: %s", err.Error()), "ibm_cd_tekton_pipeline", "delete") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } d.SetId("") @@ -786,51 +863,57 @@ func resourceIBMCdTektonPipelineDelete(context context.Context, d *schema.Resour return nil } -func resourceIBMCdTektonPipelineMapToWorkerIdentity(modelMap map[string]interface{}) (*cdtektonpipelinev2.WorkerIdentity, error) { +func ResourceIBMCdTektonPipelineMapToWorkerIdentity(modelMap map[string]interface{}) (*cdtektonpipelinev2.WorkerIdentity, error) { model := &cdtektonpipelinev2.WorkerIdentity{} model.ID = core.StringPtr(modelMap["id"].(string)) return model, nil } -func resourceIBMCdTektonPipelineWorkerIdentityToMap(model *cdtektonpipelinev2.Worker) (map[string]interface{}, error) { +func ResourceIBMCdTektonPipelineWorkerToMap(model *cdtektonpipelinev2.Worker) (map[string]interface{}, error) { modelMap := make(map[string]interface{}) - modelMap["id"] = model.ID + if model.Name != nil { + modelMap["name"] = *model.Name + } + if model.Type != nil { + modelMap["type"] = *model.Type + } + modelMap["id"] = *model.ID return modelMap, nil } -func resourceIBMCdTektonPipelineResourceGroupReferenceToMap(model *cdtektonpipelinev2.ResourceGroupReference) (map[string]interface{}, error) { +func ResourceIBMCdTektonPipelineResourceGroupReferenceToMap(model *cdtektonpipelinev2.ResourceGroupReference) (map[string]interface{}, error) { modelMap := make(map[string]interface{}) if model.ID != nil { - modelMap["id"] = model.ID + modelMap["id"] = *model.ID } return modelMap, nil } -func resourceIBMCdTektonPipelineToolchainReferenceToMap(model *cdtektonpipelinev2.ToolchainReference) (map[string]interface{}, error) { +func ResourceIBMCdTektonPipelineToolchainReferenceToMap(model *cdtektonpipelinev2.ToolchainReference) (map[string]interface{}, error) { modelMap := make(map[string]interface{}) - modelMap["id"] = model.ID - modelMap["crn"] = model.CRN + modelMap["id"] = *model.ID + modelMap["crn"] = *model.CRN return modelMap, nil } -func resourceIBMCdTektonPipelineDefinitionToMap(model *cdtektonpipelinev2.Definition) (map[string]interface{}, error) { +func ResourceIBMCdTektonPipelineDefinitionToMap(model *cdtektonpipelinev2.Definition) (map[string]interface{}, error) { modelMap := make(map[string]interface{}) - sourceMap, err := resourceIBMCdTektonPipelineDefinitionSourceToMap(model.Source) + sourceMap, err := ResourceIBMCdTektonPipelineDefinitionSourceToMap(model.Source) if err != nil { return modelMap, err } modelMap["source"] = []map[string]interface{}{sourceMap} if model.Href != nil { - modelMap["href"] = model.Href + modelMap["href"] = *model.Href } - modelMap["id"] = model.ID + modelMap["id"] = *model.ID return modelMap, nil } -func resourceIBMCdTektonPipelineDefinitionSourceToMap(model *cdtektonpipelinev2.DefinitionSource) (map[string]interface{}, error) { +func ResourceIBMCdTektonPipelineDefinitionSourceToMap(model *cdtektonpipelinev2.DefinitionSource) (map[string]interface{}, error) { modelMap := make(map[string]interface{}) - modelMap["type"] = model.Type - propertiesMap, err := resourceIBMCdTektonPipelineDefinitionSourcePropertiesToMap(model.Properties) + modelMap["type"] = *model.Type + propertiesMap, err := ResourceIBMCdTektonPipelineDefinitionSourcePropertiesToMap(model.Properties) if err != nil { return modelMap, err } @@ -838,18 +921,18 @@ func resourceIBMCdTektonPipelineDefinitionSourceToMap(model *cdtektonpipelinev2. return modelMap, nil } -func resourceIBMCdTektonPipelineDefinitionSourcePropertiesToMap(model *cdtektonpipelinev2.DefinitionSourceProperties) (map[string]interface{}, error) { +func ResourceIBMCdTektonPipelineDefinitionSourcePropertiesToMap(model *cdtektonpipelinev2.DefinitionSourceProperties) (map[string]interface{}, error) { modelMap := make(map[string]interface{}) - modelMap["url"] = model.URL + modelMap["url"] = *model.URL if model.Branch != nil { - modelMap["branch"] = model.Branch + modelMap["branch"] = *model.Branch } if model.Tag != nil { - modelMap["tag"] = model.Tag + modelMap["tag"] = *model.Tag } - modelMap["path"] = model.Path + modelMap["path"] = *model.Path if model.Tool != nil { - toolMap, err := resourceIBMCdTektonPipelineToolToMap(model.Tool) + toolMap, err := ResourceIBMCdTektonPipelineToolToMap(model.Tool) if err != nil { return modelMap, err } @@ -858,65 +941,65 @@ func resourceIBMCdTektonPipelineDefinitionSourcePropertiesToMap(model *cdtektonp return modelMap, nil } -func resourceIBMCdTektonPipelineToolToMap(model *cdtektonpipelinev2.Tool) (map[string]interface{}, error) { +func ResourceIBMCdTektonPipelineToolToMap(model *cdtektonpipelinev2.Tool) (map[string]interface{}, error) { modelMap := make(map[string]interface{}) - modelMap["id"] = model.ID + modelMap["id"] = *model.ID return modelMap, nil } -func resourceIBMCdTektonPipelinePropertyToMap(model *cdtektonpipelinev2.Property) (map[string]interface{}, error) { +func ResourceIBMCdTektonPipelinePropertyToMap(model *cdtektonpipelinev2.Property) (map[string]interface{}, error) { modelMap := make(map[string]interface{}) - modelMap["name"] = model.Name + modelMap["name"] = *model.Name if model.Value != nil { - modelMap["value"] = model.Value + modelMap["value"] = *model.Value } if model.Href != nil { - modelMap["href"] = model.Href + modelMap["href"] = *model.Href } if model.Enum != nil { modelMap["enum"] = model.Enum } - modelMap["type"] = model.Type + modelMap["type"] = *model.Type if model.Locked != nil { - modelMap["locked"] = model.Locked + modelMap["locked"] = *model.Locked } if model.Path != nil { - modelMap["path"] = model.Path + modelMap["path"] = *model.Path } return modelMap, nil } -func resourceIBMCdTektonPipelineTriggerToMap(model cdtektonpipelinev2.TriggerIntf) (map[string]interface{}, error) { +func ResourceIBMCdTektonPipelineTriggerToMap(model cdtektonpipelinev2.TriggerIntf) (map[string]interface{}, error) { if _, ok := model.(*cdtektonpipelinev2.TriggerManualTrigger); ok { - return resourceIBMCdTektonPipelineTriggerManualTriggerToMap(model.(*cdtektonpipelinev2.TriggerManualTrigger)) + return ResourceIBMCdTektonPipelineTriggerManualTriggerToMap(model.(*cdtektonpipelinev2.TriggerManualTrigger)) } else if _, ok := model.(*cdtektonpipelinev2.TriggerScmTrigger); ok { - return resourceIBMCdTektonPipelineTriggerScmTriggerToMap(model.(*cdtektonpipelinev2.TriggerScmTrigger)) + return ResourceIBMCdTektonPipelineTriggerScmTriggerToMap(model.(*cdtektonpipelinev2.TriggerScmTrigger)) } else if _, ok := model.(*cdtektonpipelinev2.TriggerTimerTrigger); ok { - return resourceIBMCdTektonPipelineTriggerTimerTriggerToMap(model.(*cdtektonpipelinev2.TriggerTimerTrigger)) + return ResourceIBMCdTektonPipelineTriggerTimerTriggerToMap(model.(*cdtektonpipelinev2.TriggerTimerTrigger)) } else if _, ok := model.(*cdtektonpipelinev2.TriggerGenericTrigger); ok { - return resourceIBMCdTektonPipelineTriggerGenericTriggerToMap(model.(*cdtektonpipelinev2.TriggerGenericTrigger)) + return ResourceIBMCdTektonPipelineTriggerGenericTriggerToMap(model.(*cdtektonpipelinev2.TriggerGenericTrigger)) } else if _, ok := model.(*cdtektonpipelinev2.Trigger); ok { modelMap := make(map[string]interface{}) model := model.(*cdtektonpipelinev2.Trigger) if model.Type != nil { - modelMap["type"] = model.Type + modelMap["type"] = *model.Type } if model.Name != nil { - modelMap["name"] = model.Name + modelMap["name"] = *model.Name } if model.Href != nil { - modelMap["href"] = model.Href + modelMap["href"] = *model.Href } if model.EventListener != nil { - modelMap["event_listener"] = model.EventListener + modelMap["event_listener"] = *model.EventListener } if model.ID != nil { - modelMap["id"] = model.ID + modelMap["id"] = *model.ID } if model.Properties != nil { properties := []map[string]interface{}{} for _, propertiesItem := range model.Properties { - propertiesItemMap, err := resourceIBMCdTektonPipelineTriggerPropertyToMap(&propertiesItem) + propertiesItemMap, err := ResourceIBMCdTektonPipelineTriggerPropertyToMap(&propertiesItem) // #nosec G601 if err != nil { return modelMap, err } @@ -928,7 +1011,7 @@ func resourceIBMCdTektonPipelineTriggerToMap(model cdtektonpipelinev2.TriggerInt modelMap["tags"] = model.Tags } if model.Worker != nil { - workerMap, err := resourceIBMCdTektonPipelineWorkerToMap(model.Worker) + workerMap, err := ResourceIBMCdTektonPipelineWorkerToMap(model.Worker) if err != nil { return modelMap, err } @@ -938,16 +1021,16 @@ func resourceIBMCdTektonPipelineTriggerToMap(model cdtektonpipelinev2.TriggerInt modelMap["max_concurrent_runs"] = flex.IntValue(model.MaxConcurrentRuns) } if model.Enabled != nil { - modelMap["enabled"] = model.Enabled + modelMap["enabled"] = *model.Enabled } if model.Favorite != nil { - modelMap["favorite"] = model.Favorite + modelMap["favorite"] = *model.Favorite } if model.EnableEventsFromForks != nil { - modelMap["enable_events_from_forks"] = model.EnableEventsFromForks + modelMap["enable_events_from_forks"] = *model.EnableEventsFromForks } if model.Source != nil { - sourceMap, err := resourceIBMCdTektonPipelineTriggerSourceToMap(model.Source) + sourceMap, err := ResourceIBMCdTektonPipelineTriggerSourceToMap(model.Source) if err != nil { return modelMap, err } @@ -957,23 +1040,23 @@ func resourceIBMCdTektonPipelineTriggerToMap(model cdtektonpipelinev2.TriggerInt modelMap["events"] = model.Events } if model.Filter != nil { - modelMap["filter"] = model.Filter + modelMap["filter"] = *model.Filter } if model.Cron != nil { - modelMap["cron"] = model.Cron + modelMap["cron"] = *model.Cron } if model.Timezone != nil { - modelMap["timezone"] = model.Timezone + modelMap["timezone"] = *model.Timezone } if model.Secret != nil { - secretMap, err := resourceIBMCdTektonPipelineGenericSecretToMap(model.Secret) + secretMap, err := ResourceIBMCdTektonPipelineGenericSecretToMap(model.Secret) if err != nil { return modelMap, err } modelMap["secret"] = []map[string]interface{}{secretMap} } if model.WebhookURL != nil { - modelMap["webhook_url"] = model.WebhookURL + modelMap["webhook_url"] = *model.WebhookURL } return modelMap, nil } else { @@ -981,44 +1064,32 @@ func resourceIBMCdTektonPipelineTriggerToMap(model cdtektonpipelinev2.TriggerInt } } -func resourceIBMCdTektonPipelineTriggerPropertyToMap(model *cdtektonpipelinev2.TriggerProperty) (map[string]interface{}, error) { +func ResourceIBMCdTektonPipelineTriggerPropertyToMap(model *cdtektonpipelinev2.TriggerProperty) (map[string]interface{}, error) { modelMap := make(map[string]interface{}) - modelMap["name"] = model.Name + modelMap["name"] = *model.Name if model.Value != nil { - modelMap["value"] = model.Value + modelMap["value"] = *model.Value } if model.Href != nil { - modelMap["href"] = model.Href + modelMap["href"] = *model.Href } if model.Enum != nil { modelMap["enum"] = model.Enum } - modelMap["type"] = model.Type + modelMap["type"] = *model.Type if model.Path != nil { - modelMap["path"] = model.Path + modelMap["path"] = *model.Path } if model.Locked != nil { - modelMap["locked"] = model.Locked + modelMap["locked"] = *model.Locked } return modelMap, nil } -func resourceIBMCdTektonPipelineWorkerToMap(model *cdtektonpipelinev2.Worker) (map[string]interface{}, error) { +func ResourceIBMCdTektonPipelineTriggerSourceToMap(model *cdtektonpipelinev2.TriggerSource) (map[string]interface{}, error) { modelMap := make(map[string]interface{}) - if model.Name != nil { - modelMap["name"] = model.Name - } - if model.Type != nil { - modelMap["type"] = model.Type - } - modelMap["id"] = model.ID - return modelMap, nil -} - -func resourceIBMCdTektonPipelineTriggerSourceToMap(model *cdtektonpipelinev2.TriggerSource) (map[string]interface{}, error) { - modelMap := make(map[string]interface{}) - modelMap["type"] = model.Type - propertiesMap, err := resourceIBMCdTektonPipelineTriggerSourcePropertiesToMap(model.Properties) + modelMap["type"] = *model.Type + propertiesMap, err := ResourceIBMCdTektonPipelineTriggerSourcePropertiesToMap(model.Properties) if err != nil { return modelMap, err } @@ -1026,20 +1097,20 @@ func resourceIBMCdTektonPipelineTriggerSourceToMap(model *cdtektonpipelinev2.Tri return modelMap, nil } -func resourceIBMCdTektonPipelineTriggerSourcePropertiesToMap(model *cdtektonpipelinev2.TriggerSourceProperties) (map[string]interface{}, error) { +func ResourceIBMCdTektonPipelineTriggerSourcePropertiesToMap(model *cdtektonpipelinev2.TriggerSourceProperties) (map[string]interface{}, error) { modelMap := make(map[string]interface{}) - modelMap["url"] = model.URL + modelMap["url"] = *model.URL if model.Branch != nil { - modelMap["branch"] = model.Branch + modelMap["branch"] = *model.Branch } if model.Pattern != nil { - modelMap["pattern"] = model.Pattern + modelMap["pattern"] = *model.Pattern } - modelMap["blind_connection"] = model.BlindConnection + modelMap["blind_connection"] = *model.BlindConnection if model.HookID != nil { - modelMap["hook_id"] = model.HookID + modelMap["hook_id"] = *model.HookID } - toolMap, err := resourceIBMCdTektonPipelineToolToMap(model.Tool) + toolMap, err := ResourceIBMCdTektonPipelineToolToMap(model.Tool) if err != nil { return modelMap, err } @@ -1047,39 +1118,39 @@ func resourceIBMCdTektonPipelineTriggerSourcePropertiesToMap(model *cdtektonpipe return modelMap, nil } -func resourceIBMCdTektonPipelineGenericSecretToMap(model *cdtektonpipelinev2.GenericSecret) (map[string]interface{}, error) { +func ResourceIBMCdTektonPipelineGenericSecretToMap(model *cdtektonpipelinev2.GenericSecret) (map[string]interface{}, error) { modelMap := make(map[string]interface{}) if model.Type != nil { - modelMap["type"] = model.Type + modelMap["type"] = *model.Type } if model.Value != nil { - modelMap["value"] = model.Value + modelMap["value"] = *model.Value } if model.Source != nil { - modelMap["source"] = model.Source + modelMap["source"] = *model.Source } if model.KeyName != nil { - modelMap["key_name"] = model.KeyName + modelMap["key_name"] = *model.KeyName } if model.Algorithm != nil { - modelMap["algorithm"] = model.Algorithm + modelMap["algorithm"] = *model.Algorithm } return modelMap, nil } -func resourceIBMCdTektonPipelineTriggerManualTriggerToMap(model *cdtektonpipelinev2.TriggerManualTrigger) (map[string]interface{}, error) { +func ResourceIBMCdTektonPipelineTriggerManualTriggerToMap(model *cdtektonpipelinev2.TriggerManualTrigger) (map[string]interface{}, error) { modelMap := make(map[string]interface{}) - modelMap["type"] = model.Type - modelMap["name"] = model.Name + modelMap["type"] = *model.Type + modelMap["name"] = *model.Name if model.Href != nil { - modelMap["href"] = model.Href + modelMap["href"] = *model.Href } - modelMap["event_listener"] = model.EventListener - modelMap["id"] = model.ID + modelMap["event_listener"] = *model.EventListener + modelMap["id"] = *model.ID if model.Properties != nil { properties := []map[string]interface{}{} for _, propertiesItem := range model.Properties { - propertiesItemMap, err := resourceIBMCdTektonPipelineTriggerPropertyToMap(&propertiesItem) + propertiesItemMap, err := ResourceIBMCdTektonPipelineTriggerPropertyToMap(&propertiesItem) // #nosec G601 if err != nil { return modelMap, err } @@ -1091,7 +1162,7 @@ func resourceIBMCdTektonPipelineTriggerManualTriggerToMap(model *cdtektonpipelin modelMap["tags"] = model.Tags } if model.Worker != nil { - workerMap, err := resourceIBMCdTektonPipelineWorkerToMap(model.Worker) + workerMap, err := ResourceIBMCdTektonPipelineWorkerToMap(model.Worker) if err != nil { return modelMap, err } @@ -1100,26 +1171,26 @@ func resourceIBMCdTektonPipelineTriggerManualTriggerToMap(model *cdtektonpipelin if model.MaxConcurrentRuns != nil { modelMap["max_concurrent_runs"] = flex.IntValue(model.MaxConcurrentRuns) } - modelMap["enabled"] = model.Enabled + modelMap["enabled"] = *model.Enabled if model.Favorite != nil { - modelMap["favorite"] = model.Favorite + modelMap["favorite"] = *model.Favorite } return modelMap, nil } -func resourceIBMCdTektonPipelineTriggerScmTriggerToMap(model *cdtektonpipelinev2.TriggerScmTrigger) (map[string]interface{}, error) { +func ResourceIBMCdTektonPipelineTriggerScmTriggerToMap(model *cdtektonpipelinev2.TriggerScmTrigger) (map[string]interface{}, error) { modelMap := make(map[string]interface{}) - modelMap["type"] = model.Type - modelMap["name"] = model.Name + modelMap["type"] = *model.Type + modelMap["name"] = *model.Name if model.Href != nil { - modelMap["href"] = model.Href + modelMap["href"] = *model.Href } - modelMap["event_listener"] = model.EventListener - modelMap["id"] = model.ID + modelMap["event_listener"] = *model.EventListener + modelMap["id"] = *model.ID if model.Properties != nil { properties := []map[string]interface{}{} for _, propertiesItem := range model.Properties { - propertiesItemMap, err := resourceIBMCdTektonPipelineTriggerPropertyToMap(&propertiesItem) + propertiesItemMap, err := ResourceIBMCdTektonPipelineTriggerPropertyToMap(&propertiesItem) // #nosec G601 if err != nil { return modelMap, err } @@ -1131,7 +1202,7 @@ func resourceIBMCdTektonPipelineTriggerScmTriggerToMap(model *cdtektonpipelinev2 modelMap["tags"] = model.Tags } if model.Worker != nil { - workerMap, err := resourceIBMCdTektonPipelineWorkerToMap(model.Worker) + workerMap, err := ResourceIBMCdTektonPipelineWorkerToMap(model.Worker) if err != nil { return modelMap, err } @@ -1140,15 +1211,15 @@ func resourceIBMCdTektonPipelineTriggerScmTriggerToMap(model *cdtektonpipelinev2 if model.MaxConcurrentRuns != nil { modelMap["max_concurrent_runs"] = flex.IntValue(model.MaxConcurrentRuns) } - modelMap["enabled"] = model.Enabled + modelMap["enabled"] = *model.Enabled if model.Favorite != nil { - modelMap["favorite"] = model.Favorite + modelMap["favorite"] = *model.Favorite } if model.EnableEventsFromForks != nil { - modelMap["enable_events_from_forks"] = model.EnableEventsFromForks + modelMap["enable_events_from_forks"] = *model.EnableEventsFromForks } if model.Source != nil { - sourceMap, err := resourceIBMCdTektonPipelineTriggerSourceToMap(model.Source) + sourceMap, err := ResourceIBMCdTektonPipelineTriggerSourceToMap(model.Source) if err != nil { return modelMap, err } @@ -1158,24 +1229,24 @@ func resourceIBMCdTektonPipelineTriggerScmTriggerToMap(model *cdtektonpipelinev2 modelMap["events"] = model.Events } if model.Filter != nil { - modelMap["filter"] = model.Filter + modelMap["filter"] = *model.Filter } return modelMap, nil } -func resourceIBMCdTektonPipelineTriggerTimerTriggerToMap(model *cdtektonpipelinev2.TriggerTimerTrigger) (map[string]interface{}, error) { +func ResourceIBMCdTektonPipelineTriggerTimerTriggerToMap(model *cdtektonpipelinev2.TriggerTimerTrigger) (map[string]interface{}, error) { modelMap := make(map[string]interface{}) - modelMap["type"] = model.Type - modelMap["name"] = model.Name + modelMap["type"] = *model.Type + modelMap["name"] = *model.Name if model.Href != nil { - modelMap["href"] = model.Href + modelMap["href"] = *model.Href } - modelMap["event_listener"] = model.EventListener - modelMap["id"] = model.ID + modelMap["event_listener"] = *model.EventListener + modelMap["id"] = *model.ID if model.Properties != nil { properties := []map[string]interface{}{} for _, propertiesItem := range model.Properties { - propertiesItemMap, err := resourceIBMCdTektonPipelineTriggerPropertyToMap(&propertiesItem) + propertiesItemMap, err := ResourceIBMCdTektonPipelineTriggerPropertyToMap(&propertiesItem) // #nosec G601 if err != nil { return modelMap, err } @@ -1187,7 +1258,7 @@ func resourceIBMCdTektonPipelineTriggerTimerTriggerToMap(model *cdtektonpipeline modelMap["tags"] = model.Tags } if model.Worker != nil { - workerMap, err := resourceIBMCdTektonPipelineWorkerToMap(model.Worker) + workerMap, err := ResourceIBMCdTektonPipelineWorkerToMap(model.Worker) if err != nil { return modelMap, err } @@ -1196,32 +1267,32 @@ func resourceIBMCdTektonPipelineTriggerTimerTriggerToMap(model *cdtektonpipeline if model.MaxConcurrentRuns != nil { modelMap["max_concurrent_runs"] = flex.IntValue(model.MaxConcurrentRuns) } - modelMap["enabled"] = model.Enabled + modelMap["enabled"] = *model.Enabled if model.Favorite != nil { - modelMap["favorite"] = model.Favorite + modelMap["favorite"] = *model.Favorite } if model.Cron != nil { - modelMap["cron"] = model.Cron + modelMap["cron"] = *model.Cron } if model.Timezone != nil { - modelMap["timezone"] = model.Timezone + modelMap["timezone"] = *model.Timezone } return modelMap, nil } -func resourceIBMCdTektonPipelineTriggerGenericTriggerToMap(model *cdtektonpipelinev2.TriggerGenericTrigger) (map[string]interface{}, error) { +func ResourceIBMCdTektonPipelineTriggerGenericTriggerToMap(model *cdtektonpipelinev2.TriggerGenericTrigger) (map[string]interface{}, error) { modelMap := make(map[string]interface{}) - modelMap["type"] = model.Type - modelMap["name"] = model.Name + modelMap["type"] = *model.Type + modelMap["name"] = *model.Name if model.Href != nil { - modelMap["href"] = model.Href + modelMap["href"] = *model.Href } - modelMap["event_listener"] = model.EventListener - modelMap["id"] = model.ID + modelMap["event_listener"] = *model.EventListener + modelMap["id"] = *model.ID if model.Properties != nil { properties := []map[string]interface{}{} for _, propertiesItem := range model.Properties { - propertiesItemMap, err := resourceIBMCdTektonPipelineTriggerPropertyToMap(&propertiesItem) + propertiesItemMap, err := ResourceIBMCdTektonPipelineTriggerPropertyToMap(&propertiesItem) // #nosec G601 if err != nil { return modelMap, err } @@ -1233,7 +1304,7 @@ func resourceIBMCdTektonPipelineTriggerGenericTriggerToMap(model *cdtektonpipeli modelMap["tags"] = model.Tags } if model.Worker != nil { - workerMap, err := resourceIBMCdTektonPipelineWorkerToMap(model.Worker) + workerMap, err := ResourceIBMCdTektonPipelineWorkerToMap(model.Worker) if err != nil { return modelMap, err } @@ -1242,22 +1313,46 @@ func resourceIBMCdTektonPipelineTriggerGenericTriggerToMap(model *cdtektonpipeli if model.MaxConcurrentRuns != nil { modelMap["max_concurrent_runs"] = flex.IntValue(model.MaxConcurrentRuns) } - modelMap["enabled"] = model.Enabled + modelMap["enabled"] = *model.Enabled if model.Favorite != nil { - modelMap["favorite"] = model.Favorite + modelMap["favorite"] = *model.Favorite } if model.Secret != nil { - secretMap, err := resourceIBMCdTektonPipelineGenericSecretToMap(model.Secret) + secretMap, err := ResourceIBMCdTektonPipelineGenericSecretToMap(model.Secret) if err != nil { return modelMap, err } modelMap["secret"] = []map[string]interface{}{secretMap} } if model.WebhookURL != nil { - modelMap["webhook_url"] = model.WebhookURL + modelMap["webhook_url"] = *model.WebhookURL } if model.Filter != nil { - modelMap["filter"] = model.Filter + modelMap["filter"] = *model.Filter } return modelMap, nil } + +func ResourceIBMCdTektonPipelineTektonPipelinePatchAsPatch(patchVals *cdtektonpipelinev2.TektonPipelinePatch, d *schema.ResourceData) map[string]interface{} { + patch, _ := patchVals.AsPatch() + var path string + + path = "next_build_number" + if _, exists := d.GetOk(path); d.HasChange(path) && !exists { + patch["next_build_number"] = nil + } + path = "enable_notifications" + if _, exists := d.GetOkExists(path); d.HasChange(path) && !exists { + patch["enable_notifications"] = nil + } + path = "enable_partial_cloning" + if _, exists := d.GetOkExists(path); d.HasChange(path) && !exists { + patch["enable_partial_cloning"] = nil + } + path = "worker" + if _, exists := d.GetOk(path); d.HasChange(path) && !exists { + patch["worker"] = nil + } + + return patch +} diff --git a/ibm/service/cdtektonpipeline/resource_ibm_cd_tekton_pipeline_definition.go b/ibm/service/cdtektonpipeline/resource_ibm_cd_tekton_pipeline_definition.go index 516c935aa1..c1237d1d80 100644 --- a/ibm/service/cdtektonpipeline/resource_ibm_cd_tekton_pipeline_definition.go +++ b/ibm/service/cdtektonpipeline/resource_ibm_cd_tekton_pipeline_definition.go @@ -1,6 +1,10 @@ // Copyright IBM Corp. 2024 All Rights Reserved. // Licensed under the Mozilla Public License v2.0 +/* + * IBM OpenAPI Terraform Generator Version: 3.95.2-120e65bc-20240924-152329 + */ + package cdtektonpipeline import ( @@ -78,6 +82,7 @@ func ResourceIBMCdTektonPipelineDefinition() *schema.Resource { }, "tool": &schema.Schema{ Type: schema.TypeList, + Optional: true, Computed: true, Description: "Reference to the repository tool in the parent toolchain.", Elem: &schema.Resource{ @@ -131,22 +136,25 @@ func ResourceIBMCdTektonPipelineDefinitionValidator() *validate.ResourceValidato func resourceIBMCdTektonPipelineDefinitionCreate(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { cdTektonPipelineClient, err := meta.(conns.ClientSession).CdTektonPipelineV2() if err != nil { - return diag.FromErr(err) + tfErr := flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline_definition", "create", "initialize-client") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } createTektonPipelineDefinitionOptions := &cdtektonpipelinev2.CreateTektonPipelineDefinitionOptions{} createTektonPipelineDefinitionOptions.SetPipelineID(d.Get("pipeline_id").(string)) - sourceModel, err := resourceIBMCdTektonPipelineDefinitionMapToDefinitionSource(d.Get("source.0").(map[string]interface{})) + sourceModel, err := ResourceIBMCdTektonPipelineDefinitionMapToDefinitionSource(d.Get("source.0").(map[string]interface{})) if err != nil { - return diag.FromErr(err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline_definition", "create", "parse-source").GetDiag() } createTektonPipelineDefinitionOptions.SetSource(sourceModel) - definition, response, err := cdTektonPipelineClient.CreateTektonPipelineDefinitionWithContext(context, createTektonPipelineDefinitionOptions) + definition, _, err := cdTektonPipelineClient.CreateTektonPipelineDefinitionWithContext(context, createTektonPipelineDefinitionOptions) if err != nil { - log.Printf("[DEBUG] CreateTektonPipelineDefinitionWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("CreateTektonPipelineDefinitionWithContext failed %s\n%s", err, response)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("CreateTektonPipelineDefinitionWithContext failed: %s", err.Error()), "ibm_cd_tekton_pipeline_definition", "create") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } d.SetId(fmt.Sprintf("%s/%s", *createTektonPipelineDefinitionOptions.PipelineID, *definition.ID)) @@ -157,14 +165,16 @@ func resourceIBMCdTektonPipelineDefinitionCreate(context context.Context, d *sch func resourceIBMCdTektonPipelineDefinitionRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { cdTektonPipelineClient, err := meta.(conns.ClientSession).CdTektonPipelineV2() if err != nil { - return diag.FromErr(err) + tfErr := flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline_definition", "read", "initialize-client") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } getTektonPipelineDefinitionOptions := &cdtektonpipelinev2.GetTektonPipelineDefinitionOptions{} parts, err := flex.SepIdParts(d.Id(), "/") if err != nil { - return diag.FromErr(err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline_definition", "read", "sep-id-parts").GetDiag() } getTektonPipelineDefinitionOptions.SetPipelineID(parts[0]) @@ -176,27 +186,28 @@ func resourceIBMCdTektonPipelineDefinitionRead(context context.Context, d *schem d.SetId("") return nil } - log.Printf("[DEBUG] GetTektonPipelineDefinitionWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("GetTektonPipelineDefinitionWithContext failed %s\n%s", err, response)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("GetTektonPipelineDefinitionWithContext failed: %s", err.Error()), "ibm_cd_tekton_pipeline_definition", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } - if err = d.Set("pipeline_id", getTektonPipelineDefinitionOptions.PipelineID); err != nil { - return diag.FromErr(fmt.Errorf("Error setting pipeline_id: %s", err)) - } - sourceMap, err := resourceIBMCdTektonPipelineDefinitionDefinitionSourceToMap(definition.Source) + sourceMap, err := ResourceIBMCdTektonPipelineDefinitionDefinitionSourceToMap(definition.Source) if err != nil { - return diag.FromErr(err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline_definition", "read", "source-to-map").GetDiag() } if err = d.Set("source", []map[string]interface{}{sourceMap}); err != nil { - return diag.FromErr(fmt.Errorf("Error setting source: %s", err)) + err = fmt.Errorf("Error setting source: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline_definition", "read", "set-source").GetDiag() } if !core.IsNil(definition.Href) { if err = d.Set("href", definition.Href); err != nil { - return diag.FromErr(fmt.Errorf("Error setting href: %s", err)) + err = fmt.Errorf("Error setting href: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline_definition", "read", "set-href").GetDiag() } } if err = d.Set("definition_id", definition.ID); err != nil { - return diag.FromErr(fmt.Errorf("Error setting definition_id: %s", err)) + err = fmt.Errorf("Error setting definition_id: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline_definition", "read", "set-definition_id").GetDiag() } return nil @@ -205,14 +216,16 @@ func resourceIBMCdTektonPipelineDefinitionRead(context context.Context, d *schem func resourceIBMCdTektonPipelineDefinitionUpdate(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { cdTektonPipelineClient, err := meta.(conns.ClientSession).CdTektonPipelineV2() if err != nil { - return diag.FromErr(err) + tfErr := flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline_definition", "update", "initialize-client") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } replaceTektonPipelineDefinitionOptions := &cdtektonpipelinev2.ReplaceTektonPipelineDefinitionOptions{} parts, err := flex.SepIdParts(d.Id(), "/") if err != nil { - return diag.FromErr(err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline_definition", "update", "sep-id-parts").GetDiag() } replaceTektonPipelineDefinitionOptions.SetPipelineID(parts[0]) @@ -221,23 +234,25 @@ func resourceIBMCdTektonPipelineDefinitionUpdate(context context.Context, d *sch hasChange := false if d.HasChange("pipeline_id") { - return diag.FromErr(fmt.Errorf("Cannot update resource property \"%s\" with the ForceNew annotation."+ - " The resource must be re-created to update this property.", "pipeline_id")) + errMsg := fmt.Sprintf("Cannot update resource property \"%s\" with the ForceNew annotation."+ + " The resource must be re-created to update this property.", "pipeline_id") + return flex.DiscriminatedTerraformErrorf(nil, errMsg, "ibm_cd_tekton_pipeline_definition", "update", "pipeline_id-forces-new").GetDiag() } if d.HasChange("source") { - source, err := resourceIBMCdTektonPipelineDefinitionMapToDefinitionSource(d.Get("source.0").(map[string]interface{})) + source, err := ResourceIBMCdTektonPipelineDefinitionMapToDefinitionSource(d.Get("source.0").(map[string]interface{})) if err != nil { - return diag.FromErr(err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline_definition", "update", "parse-source").GetDiag() } replaceTektonPipelineDefinitionOptions.SetSource(source) hasChange = true } if hasChange { - _, response, err := cdTektonPipelineClient.ReplaceTektonPipelineDefinitionWithContext(context, replaceTektonPipelineDefinitionOptions) + _, _, err = cdTektonPipelineClient.ReplaceTektonPipelineDefinitionWithContext(context, replaceTektonPipelineDefinitionOptions) if err != nil { - log.Printf("[DEBUG] ReplaceTektonPipelineDefinitionWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("ReplaceTektonPipelineDefinitionWithContext failed %s\n%s", err, response)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("ReplaceTektonPipelineDefinitionWithContext failed: %s", err.Error()), "ibm_cd_tekton_pipeline_definition", "update") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } @@ -247,23 +262,26 @@ func resourceIBMCdTektonPipelineDefinitionUpdate(context context.Context, d *sch func resourceIBMCdTektonPipelineDefinitionDelete(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { cdTektonPipelineClient, err := meta.(conns.ClientSession).CdTektonPipelineV2() if err != nil { - return diag.FromErr(err) + tfErr := flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline_definition", "delete", "initialize-client") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } deleteTektonPipelineDefinitionOptions := &cdtektonpipelinev2.DeleteTektonPipelineDefinitionOptions{} parts, err := flex.SepIdParts(d.Id(), "/") if err != nil { - return diag.FromErr(err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline_definition", "delete", "sep-id-parts").GetDiag() } deleteTektonPipelineDefinitionOptions.SetPipelineID(parts[0]) deleteTektonPipelineDefinitionOptions.SetDefinitionID(parts[1]) - response, err := cdTektonPipelineClient.DeleteTektonPipelineDefinitionWithContext(context, deleteTektonPipelineDefinitionOptions) + _, err = cdTektonPipelineClient.DeleteTektonPipelineDefinitionWithContext(context, deleteTektonPipelineDefinitionOptions) if err != nil { - log.Printf("[DEBUG] DeleteTektonPipelineDefinitionWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("DeleteTektonPipelineDefinitionWithContext failed %s\n%s", err, response)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("DeleteTektonPipelineDefinitionWithContext failed: %s", err.Error()), "ibm_cd_tekton_pipeline_definition", "delete") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } d.SetId("") @@ -271,10 +289,10 @@ func resourceIBMCdTektonPipelineDefinitionDelete(context context.Context, d *sch return nil } -func resourceIBMCdTektonPipelineDefinitionMapToDefinitionSource(modelMap map[string]interface{}) (*cdtektonpipelinev2.DefinitionSource, error) { +func ResourceIBMCdTektonPipelineDefinitionMapToDefinitionSource(modelMap map[string]interface{}) (*cdtektonpipelinev2.DefinitionSource, error) { model := &cdtektonpipelinev2.DefinitionSource{} model.Type = core.StringPtr(modelMap["type"].(string)) - PropertiesModel, err := resourceIBMCdTektonPipelineDefinitionMapToDefinitionSourceProperties(modelMap["properties"].([]interface{})[0].(map[string]interface{})) + PropertiesModel, err := ResourceIBMCdTektonPipelineDefinitionMapToDefinitionSourceProperties(modelMap["properties"].([]interface{})[0].(map[string]interface{})) if err != nil { return model, err } @@ -282,7 +300,7 @@ func resourceIBMCdTektonPipelineDefinitionMapToDefinitionSource(modelMap map[str return model, nil } -func resourceIBMCdTektonPipelineDefinitionMapToDefinitionSourceProperties(modelMap map[string]interface{}) (*cdtektonpipelinev2.DefinitionSourceProperties, error) { +func ResourceIBMCdTektonPipelineDefinitionMapToDefinitionSourceProperties(modelMap map[string]interface{}) (*cdtektonpipelinev2.DefinitionSourceProperties, error) { model := &cdtektonpipelinev2.DefinitionSourceProperties{} model.URL = core.StringPtr(modelMap["url"].(string)) if modelMap["branch"] != nil && modelMap["branch"].(string) != "" { @@ -293,7 +311,7 @@ func resourceIBMCdTektonPipelineDefinitionMapToDefinitionSourceProperties(modelM } model.Path = core.StringPtr(modelMap["path"].(string)) if modelMap["tool"] != nil && len(modelMap["tool"].([]interface{})) > 0 { - ToolModel, err := resourceIBMCdTektonPipelineDefinitionMapToTool(modelMap["tool"].([]interface{})[0].(map[string]interface{})) + ToolModel, err := ResourceIBMCdTektonPipelineDefinitionMapToTool(modelMap["tool"].([]interface{})[0].(map[string]interface{})) if err != nil { return model, err } @@ -302,16 +320,16 @@ func resourceIBMCdTektonPipelineDefinitionMapToDefinitionSourceProperties(modelM return model, nil } -func resourceIBMCdTektonPipelineDefinitionMapToTool(modelMap map[string]interface{}) (*cdtektonpipelinev2.Tool, error) { +func ResourceIBMCdTektonPipelineDefinitionMapToTool(modelMap map[string]interface{}) (*cdtektonpipelinev2.Tool, error) { model := &cdtektonpipelinev2.Tool{} model.ID = core.StringPtr(modelMap["id"].(string)) return model, nil } -func resourceIBMCdTektonPipelineDefinitionDefinitionSourceToMap(model *cdtektonpipelinev2.DefinitionSource) (map[string]interface{}, error) { +func ResourceIBMCdTektonPipelineDefinitionDefinitionSourceToMap(model *cdtektonpipelinev2.DefinitionSource) (map[string]interface{}, error) { modelMap := make(map[string]interface{}) - modelMap["type"] = model.Type - propertiesMap, err := resourceIBMCdTektonPipelineDefinitionDefinitionSourcePropertiesToMap(model.Properties) + modelMap["type"] = *model.Type + propertiesMap, err := ResourceIBMCdTektonPipelineDefinitionDefinitionSourcePropertiesToMap(model.Properties) if err != nil { return modelMap, err } @@ -319,18 +337,18 @@ func resourceIBMCdTektonPipelineDefinitionDefinitionSourceToMap(model *cdtektonp return modelMap, nil } -func resourceIBMCdTektonPipelineDefinitionDefinitionSourcePropertiesToMap(model *cdtektonpipelinev2.DefinitionSourceProperties) (map[string]interface{}, error) { +func ResourceIBMCdTektonPipelineDefinitionDefinitionSourcePropertiesToMap(model *cdtektonpipelinev2.DefinitionSourceProperties) (map[string]interface{}, error) { modelMap := make(map[string]interface{}) - modelMap["url"] = model.URL + modelMap["url"] = *model.URL if model.Branch != nil { - modelMap["branch"] = model.Branch + modelMap["branch"] = *model.Branch } if model.Tag != nil { - modelMap["tag"] = model.Tag + modelMap["tag"] = *model.Tag } - modelMap["path"] = model.Path + modelMap["path"] = *model.Path if model.Tool != nil { - toolMap, err := resourceIBMCdTektonPipelineDefinitionToolToMap(model.Tool) + toolMap, err := ResourceIBMCdTektonPipelineDefinitionToolToMap(model.Tool) if err != nil { return modelMap, err } @@ -339,8 +357,8 @@ func resourceIBMCdTektonPipelineDefinitionDefinitionSourcePropertiesToMap(model return modelMap, nil } -func resourceIBMCdTektonPipelineDefinitionToolToMap(model *cdtektonpipelinev2.Tool) (map[string]interface{}, error) { +func ResourceIBMCdTektonPipelineDefinitionToolToMap(model *cdtektonpipelinev2.Tool) (map[string]interface{}, error) { modelMap := make(map[string]interface{}) - modelMap["id"] = model.ID + modelMap["id"] = *model.ID return modelMap, nil } diff --git a/ibm/service/cdtektonpipeline/resource_ibm_cd_tekton_pipeline_definition_test.go b/ibm/service/cdtektonpipeline/resource_ibm_cd_tekton_pipeline_definition_test.go index ea4ffb111f..dfbf008421 100644 --- a/ibm/service/cdtektonpipeline/resource_ibm_cd_tekton_pipeline_definition_test.go +++ b/ibm/service/cdtektonpipeline/resource_ibm_cd_tekton_pipeline_definition_test.go @@ -14,7 +14,10 @@ import ( 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/IBM-Cloud/terraform-provider-ibm/ibm/service/cdtektonpipeline" "github.com/IBM/continuous-delivery-go-sdk/cdtektonpipelinev2" + "github.com/IBM/go-sdk-core/v5/core" + "github.com/stretchr/testify/assert" ) func TestAccIBMCdTektonPipelineDefinitionBasic(t *testing.T) { @@ -28,17 +31,18 @@ func TestAccIBMCdTektonPipelineDefinitionBasic(t *testing.T) { resource.TestStep{ Config: testAccCheckIBMCdTektonPipelineDefinitionConfigBasic(""), Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckIBMCdTektonPipelineDefinitionExists("ibm_cd_tekton_pipeline_definition.cd_tekton_pipeline_definition", conf), - resource.TestCheckResourceAttrSet("ibm_cd_tekton_pipeline_definition.cd_tekton_pipeline_definition", "id"), - resource.TestCheckResourceAttrSet("ibm_cd_tekton_pipeline_definition.cd_tekton_pipeline_definition", "definition_id"), - resource.TestCheckResourceAttrSet("ibm_cd_tekton_pipeline_definition.cd_tekton_pipeline_definition", "pipeline_id"), - resource.TestCheckResourceAttrSet("ibm_cd_tekton_pipeline_definition.cd_tekton_pipeline_definition", "source.#"), + testAccCheckIBMCdTektonPipelineDefinitionExists("ibm_cd_tekton_pipeline_definition.cd_tekton_pipeline_definition_instance", conf), + resource.TestCheckResourceAttrSet("ibm_cd_tekton_pipeline_definition.cd_tekton_pipeline_definition_instance", "id"), + resource.TestCheckResourceAttrSet("ibm_cd_tekton_pipeline_definition.cd_tekton_pipeline_definition_instance", "definition_id"), + resource.TestCheckResourceAttrSet("ibm_cd_tekton_pipeline_definition.cd_tekton_pipeline_definition_instance", "pipeline_id"), + resource.TestCheckResourceAttrSet("ibm_cd_tekton_pipeline_definition.cd_tekton_pipeline_definition_instance", "source.#"), ), }, resource.TestStep{ - ResourceName: "ibm_cd_tekton_pipeline_definition.cd_tekton_pipeline_definition", - ImportState: true, - ImportStateVerify: true, + ResourceName: "ibm_cd_tekton_pipeline_definition.cd_tekton_pipeline_definition_instance", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"pipeline_id"}, }, }, }) @@ -61,7 +65,7 @@ func testAccCheckIBMCdTektonPipelineDefinitionConfigBasic(pipelineID string) str name = "pipeline-name" } } - resource "ibm_cd_tekton_pipeline" "cd_tekton_pipeline" { + resource "ibm_cd_tekton_pipeline" "cd_tekton_pipeline_instance" { pipeline_id = ibm_cd_toolchain_tool_pipeline.ibm_cd_toolchain_tool_pipeline.tool_id next_build_number = 5 worker { @@ -80,8 +84,8 @@ func testAccCheckIBMCdTektonPipelineDefinitionConfigBasic(pipelineID string) str } parameters {} } - resource "ibm_cd_tekton_pipeline_definition" "cd_tekton_pipeline_definition" { - pipeline_id = ibm_cd_tekton_pipeline.cd_tekton_pipeline.pipeline_id + resource "ibm_cd_tekton_pipeline_definition" "cd_tekton_pipeline_definition_instance" { + pipeline_id = ibm_cd_tekton_pipeline.cd_tekton_pipeline_instance.pipeline_id source { type = "git" properties { @@ -91,7 +95,7 @@ func testAccCheckIBMCdTektonPipelineDefinitionConfigBasic(pipelineID string) str } } depends_on = [ - ibm_cd_tekton_pipeline.cd_tekton_pipeline + ibm_cd_tekton_pipeline.cd_tekton_pipeline_instance ] } `, rgName, tcName) @@ -162,3 +166,171 @@ func testAccCheckIBMCdTektonPipelineDefinitionDestroy(s *terraform.State) error return nil } + +func TestResourceIBMCdTektonPipelineDefinitionDefinitionSourceToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + toolModel := make(map[string]interface{}) + toolModel["id"] = "testString" + + definitionSourcePropertiesModel := make(map[string]interface{}) + definitionSourcePropertiesModel["url"] = "testString" + definitionSourcePropertiesModel["branch"] = "testString" + definitionSourcePropertiesModel["tag"] = "testString" + definitionSourcePropertiesModel["path"] = "testString" + definitionSourcePropertiesModel["tool"] = []map[string]interface{}{toolModel} + + model := make(map[string]interface{}) + model["type"] = "testString" + model["properties"] = []map[string]interface{}{definitionSourcePropertiesModel} + + assert.Equal(t, result, model) + } + + toolModel := new(cdtektonpipelinev2.Tool) + toolModel.ID = core.StringPtr("testString") + + definitionSourcePropertiesModel := new(cdtektonpipelinev2.DefinitionSourceProperties) + definitionSourcePropertiesModel.URL = core.StringPtr("testString") + definitionSourcePropertiesModel.Branch = core.StringPtr("testString") + definitionSourcePropertiesModel.Tag = core.StringPtr("testString") + definitionSourcePropertiesModel.Path = core.StringPtr("testString") + definitionSourcePropertiesModel.Tool = toolModel + + model := new(cdtektonpipelinev2.DefinitionSource) + model.Type = core.StringPtr("testString") + model.Properties = definitionSourcePropertiesModel + + result, err := cdtektonpipeline.ResourceIBMCdTektonPipelineDefinitionDefinitionSourceToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestResourceIBMCdTektonPipelineDefinitionDefinitionSourcePropertiesToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + toolModel := make(map[string]interface{}) + toolModel["id"] = "testString" + + model := make(map[string]interface{}) + model["url"] = "testString" + model["branch"] = "testString" + model["tag"] = "testString" + model["path"] = "testString" + model["tool"] = []map[string]interface{}{toolModel} + + assert.Equal(t, result, model) + } + + toolModel := new(cdtektonpipelinev2.Tool) + toolModel.ID = core.StringPtr("testString") + + model := new(cdtektonpipelinev2.DefinitionSourceProperties) + model.URL = core.StringPtr("testString") + model.Branch = core.StringPtr("testString") + model.Tag = core.StringPtr("testString") + model.Path = core.StringPtr("testString") + model.Tool = toolModel + + result, err := cdtektonpipeline.ResourceIBMCdTektonPipelineDefinitionDefinitionSourcePropertiesToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestResourceIBMCdTektonPipelineDefinitionToolToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + model := make(map[string]interface{}) + model["id"] = "testString" + + assert.Equal(t, result, model) + } + + model := new(cdtektonpipelinev2.Tool) + model.ID = core.StringPtr("testString") + + result, err := cdtektonpipeline.ResourceIBMCdTektonPipelineDefinitionToolToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestResourceIBMCdTektonPipelineDefinitionMapToDefinitionSource(t *testing.T) { + checkResult := func(result *cdtektonpipelinev2.DefinitionSource) { + toolModel := new(cdtektonpipelinev2.Tool) + toolModel.ID = core.StringPtr("testString") + + definitionSourcePropertiesModel := new(cdtektonpipelinev2.DefinitionSourceProperties) + definitionSourcePropertiesModel.URL = core.StringPtr("testString") + definitionSourcePropertiesModel.Branch = core.StringPtr("testString") + definitionSourcePropertiesModel.Tag = core.StringPtr("testString") + definitionSourcePropertiesModel.Path = core.StringPtr("testString") + definitionSourcePropertiesModel.Tool = toolModel + + model := new(cdtektonpipelinev2.DefinitionSource) + model.Type = core.StringPtr("testString") + model.Properties = definitionSourcePropertiesModel + + assert.Equal(t, result, model) + } + + toolModel := make(map[string]interface{}) + toolModel["id"] = "testString" + + definitionSourcePropertiesModel := make(map[string]interface{}) + definitionSourcePropertiesModel["url"] = "testString" + definitionSourcePropertiesModel["branch"] = "testString" + definitionSourcePropertiesModel["tag"] = "testString" + definitionSourcePropertiesModel["path"] = "testString" + definitionSourcePropertiesModel["tool"] = []interface{}{toolModel} + + model := make(map[string]interface{}) + model["type"] = "testString" + model["properties"] = []interface{}{definitionSourcePropertiesModel} + + result, err := cdtektonpipeline.ResourceIBMCdTektonPipelineDefinitionMapToDefinitionSource(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestResourceIBMCdTektonPipelineDefinitionMapToDefinitionSourceProperties(t *testing.T) { + checkResult := func(result *cdtektonpipelinev2.DefinitionSourceProperties) { + toolModel := new(cdtektonpipelinev2.Tool) + toolModel.ID = core.StringPtr("testString") + + model := new(cdtektonpipelinev2.DefinitionSourceProperties) + model.URL = core.StringPtr("testString") + model.Branch = core.StringPtr("testString") + model.Tag = core.StringPtr("testString") + model.Path = core.StringPtr("testString") + model.Tool = toolModel + + assert.Equal(t, result, model) + } + + toolModel := make(map[string]interface{}) + toolModel["id"] = "testString" + + model := make(map[string]interface{}) + model["url"] = "testString" + model["branch"] = "testString" + model["tag"] = "testString" + model["path"] = "testString" + model["tool"] = []interface{}{toolModel} + + result, err := cdtektonpipeline.ResourceIBMCdTektonPipelineDefinitionMapToDefinitionSourceProperties(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestResourceIBMCdTektonPipelineDefinitionMapToTool(t *testing.T) { + checkResult := func(result *cdtektonpipelinev2.Tool) { + model := new(cdtektonpipelinev2.Tool) + model.ID = core.StringPtr("testString") + + assert.Equal(t, result, model) + } + + model := make(map[string]interface{}) + model["id"] = "testString" + + result, err := cdtektonpipeline.ResourceIBMCdTektonPipelineDefinitionMapToTool(model) + assert.Nil(t, err) + checkResult(result) +} diff --git a/ibm/service/cdtektonpipeline/resource_ibm_cd_tekton_pipeline_property.go b/ibm/service/cdtektonpipeline/resource_ibm_cd_tekton_pipeline_property.go index dfddc9844f..7b1fb15eeb 100644 --- a/ibm/service/cdtektonpipeline/resource_ibm_cd_tekton_pipeline_property.go +++ b/ibm/service/cdtektonpipeline/resource_ibm_cd_tekton_pipeline_property.go @@ -1,6 +1,10 @@ // Copyright IBM Corp. 2024 All Rights Reserved. // Licensed under the Mozilla Public License v2.0 +/* + * IBM OpenAPI Terraform Generator Version: 3.95.2-120e65bc-20240924-152329 + */ + package cdtektonpipeline import ( @@ -41,13 +45,6 @@ func ResourceIBMCdTektonPipelineProperty() *schema.Resource { ValidateFunc: validate.InvokeValidator("ibm_cd_tekton_pipeline_property", "name"), Description: "Property name.", }, - "type": &schema.Schema{ - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: validate.InvokeValidator("ibm_cd_tekton_pipeline_property", "type"), - Description: "Property type.", - }, "value": &schema.Schema{ Type: schema.TypeString, Optional: true, @@ -61,6 +58,13 @@ func ResourceIBMCdTektonPipelineProperty() *schema.Resource { Description: "Options for `single_select` property type. Only needed when using `single_select` property type.", Elem: &schema.Schema{Type: schema.TypeString}, }, + "type": &schema.Schema{ + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validate.InvokeValidator("ibm_cd_tekton_pipeline_property", "type"), + Description: "Property type.", + }, "locked": &schema.Schema{ Type: schema.TypeBool, Optional: true, @@ -71,7 +75,7 @@ func ResourceIBMCdTektonPipelineProperty() *schema.Resource { Type: schema.TypeString, Optional: true, ValidateFunc: validate.InvokeValidator("ibm_cd_tekton_pipeline_property", "path"), - Description: "A dot notation path for `integration` type properties only, to select a value from the tool integration. If left blank the full tool integration data will be used.", + Description: "A dot notation path for `integration` type properties only, that selects a value from the tool integration. If left blank the full tool integration data will be used.", }, "href": &schema.Schema{ Type: schema.TypeString, @@ -103,13 +107,6 @@ func ResourceIBMCdTektonPipelinePropertyValidator() *validate.ResourceValidator MinValueLength: 1, MaxValueLength: 253, }, - validate.ValidateSchema{ - Identifier: "type", - ValidateFunctionIdentifier: validate.ValidateAllowedStringValue, - Type: validate.TypeString, - Required: true, - AllowedValues: "appconfig, integration, secure, single_select, text", - }, validate.ValidateSchema{ Identifier: "value", ValidateFunctionIdentifier: validate.ValidateRegexpLen, @@ -119,6 +116,13 @@ func ResourceIBMCdTektonPipelinePropertyValidator() *validate.ResourceValidator MinValueLength: 0, MaxValueLength: 4096, }, + validate.ValidateSchema{ + Identifier: "type", + ValidateFunctionIdentifier: validate.ValidateAllowedStringValue, + Type: validate.TypeString, + Required: true, + AllowedValues: "appconfig, integration, secure, single_select, text", + }, validate.ValidateSchema{ Identifier: "path", ValidateFunctionIdentifier: validate.ValidateRegexpLen, @@ -137,7 +141,9 @@ func ResourceIBMCdTektonPipelinePropertyValidator() *validate.ResourceValidator func resourceIBMCdTektonPipelinePropertyCreate(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { cdTektonPipelineClient, err := meta.(conns.ClientSession).CdTektonPipelineV2() if err != nil { - return diag.FromErr(err) + tfErr := flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline_property", "create", "initialize-client") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } createTektonPipelinePropertiesOptions := &cdtektonpipelinev2.CreateTektonPipelinePropertiesOptions{} @@ -163,10 +169,11 @@ func resourceIBMCdTektonPipelinePropertyCreate(context context.Context, d *schem createTektonPipelinePropertiesOptions.SetPath(d.Get("path").(string)) } - property, response, err := cdTektonPipelineClient.CreateTektonPipelinePropertiesWithContext(context, createTektonPipelinePropertiesOptions) + property, _, err := cdTektonPipelineClient.CreateTektonPipelinePropertiesWithContext(context, createTektonPipelinePropertiesOptions) if err != nil { - log.Printf("[DEBUG] CreateTektonPipelinePropertiesWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("CreateTektonPipelinePropertiesWithContext failed %s\n%s", err, response)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("CreateTektonPipelinePropertiesWithContext failed: %s", err.Error()), "ibm_cd_tekton_pipeline_property", "create") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } d.SetId(fmt.Sprintf("%s/%s", *createTektonPipelinePropertiesOptions.PipelineID, *property.Name)) @@ -177,14 +184,16 @@ func resourceIBMCdTektonPipelinePropertyCreate(context context.Context, d *schem func resourceIBMCdTektonPipelinePropertyRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { cdTektonPipelineClient, err := meta.(conns.ClientSession).CdTektonPipelineV2() if err != nil { - return diag.FromErr(err) + tfErr := flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline_property", "read", "initialize-client") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } getTektonPipelinePropertyOptions := &cdtektonpipelinev2.GetTektonPipelinePropertyOptions{} parts, err := flex.SepIdParts(d.Id(), "/") if err != nil { - return diag.FromErr(err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline_property", "read", "sep-id-parts").GetDiag() } getTektonPipelinePropertyOptions.SetPipelineID(parts[0]) @@ -196,42 +205,47 @@ func resourceIBMCdTektonPipelinePropertyRead(context context.Context, d *schema. d.SetId("") return nil } - log.Printf("[DEBUG] GetTektonPipelinePropertyWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("GetTektonPipelinePropertyWithContext failed %s\n%s", err, response)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("GetTektonPipelinePropertyWithContext failed: %s", err.Error()), "ibm_cd_tekton_pipeline_property", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } - if err = d.Set("pipeline_id", getTektonPipelinePropertyOptions.PipelineID); err != nil { - return diag.FromErr(fmt.Errorf("Error setting pipeline_id: %s", err)) - } if err = d.Set("name", property.Name); err != nil { - return diag.FromErr(fmt.Errorf("Error setting name: %s", err)) - } - if err = d.Set("type", property.Type); err != nil { - return diag.FromErr(fmt.Errorf("Error setting type: %s", err)) + err = fmt.Errorf("Error setting name: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline_property", "read", "set-name").GetDiag() } if !core.IsNil(property.Value) { if err = d.Set("value", property.Value); err != nil { - return diag.FromErr(fmt.Errorf("Error setting value: %s", err)) + err = fmt.Errorf("Error setting value: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline_property", "read", "set-value").GetDiag() } } if !core.IsNil(property.Enum) { if err = d.Set("enum", property.Enum); err != nil { - return diag.FromErr(fmt.Errorf("Error setting enum: %s", err)) + err = fmt.Errorf("Error setting enum: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline_property", "read", "set-enum").GetDiag() } } + if err = d.Set("type", property.Type); err != nil { + err = fmt.Errorf("Error setting type: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline_property", "read", "set-type").GetDiag() + } if !core.IsNil(property.Locked) { if err = d.Set("locked", property.Locked); err != nil { - return diag.FromErr(fmt.Errorf("Error setting locked: %s", err)) + err = fmt.Errorf("Error setting locked: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline_property", "read", "set-locked").GetDiag() } } if !core.IsNil(property.Path) { if err = d.Set("path", property.Path); err != nil { - return diag.FromErr(fmt.Errorf("Error setting path: %s", err)) + err = fmt.Errorf("Error setting path: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline_property", "read", "set-path").GetDiag() } } if !core.IsNil(property.Href) { if err = d.Set("href", property.Href); err != nil { - return diag.FromErr(fmt.Errorf("Error setting href: %s", err)) + err = fmt.Errorf("Error setting href: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline_property", "read", "set-href").GetDiag() } } @@ -241,14 +255,16 @@ func resourceIBMCdTektonPipelinePropertyRead(context context.Context, d *schema. func resourceIBMCdTektonPipelinePropertyUpdate(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { cdTektonPipelineClient, err := meta.(conns.ClientSession).CdTektonPipelineV2() if err != nil { - return diag.FromErr(err) + tfErr := flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline_property", "update", "initialize-client") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } replaceTektonPipelinePropertyOptions := &cdtektonpipelinev2.ReplaceTektonPipelinePropertyOptions{} parts, err := flex.SepIdParts(d.Id(), "/") if err != nil { - return diag.FromErr(err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline_property", "update", "sep-id-parts").GetDiag() } replaceTektonPipelinePropertyOptions.SetPipelineID(parts[0]) @@ -259,16 +275,19 @@ func resourceIBMCdTektonPipelinePropertyUpdate(context context.Context, d *schem hasChange := false if d.HasChange("pipeline_id") { - return diag.FromErr(fmt.Errorf("Cannot update resource property \"%s\" with the ForceNew annotation."+ - " The resource must be re-created to update this property.", "pipeline_id")) + errMsg := fmt.Sprintf("Cannot update resource property \"%s\" with the ForceNew annotation."+ + " The resource must be re-created to update this property.", "pipeline_id") + return flex.DiscriminatedTerraformErrorf(nil, errMsg, "ibm_cd_tekton_pipeline_property", "update", "pipeline_id-forces-new").GetDiag() } if d.HasChange("name") { - return diag.FromErr(fmt.Errorf("Cannot update resource property \"%s\" with the ForceNew annotation."+ - " The resource must be re-created to update this property.", "name")) + errMsg := fmt.Sprintf("Cannot update resource property \"%s\" with the ForceNew annotation."+ + " The resource must be re-created to update this property.", "name") + return flex.DiscriminatedTerraformErrorf(nil, errMsg, "ibm_cd_tekton_pipeline_property", "update", "name-forces-new").GetDiag() } if d.HasChange("type") { - return diag.FromErr(fmt.Errorf("Cannot update resource property \"%s\" with the ForceNew annotation."+ - " The resource must be re-created to update this property.", "type")) + errMsg := fmt.Sprintf("Cannot update resource property \"%s\" with the ForceNew annotation."+ + " The resource must be re-created to update this property.", "type") + return flex.DiscriminatedTerraformErrorf(nil, errMsg, "ibm_cd_tekton_pipeline_property", "update", "type-forces-new").GetDiag() } if d.HasChange("locked") { replaceTektonPipelinePropertyOptions.SetLocked(d.Get("locked").(bool)) @@ -299,10 +318,11 @@ func resourceIBMCdTektonPipelinePropertyUpdate(context context.Context, d *schem } if hasChange { - _, response, err := cdTektonPipelineClient.ReplaceTektonPipelinePropertyWithContext(context, replaceTektonPipelinePropertyOptions) + _, _, err = cdTektonPipelineClient.ReplaceTektonPipelinePropertyWithContext(context, replaceTektonPipelinePropertyOptions) if err != nil { - log.Printf("[DEBUG] ReplaceTektonPipelinePropertyWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("ReplaceTektonPipelinePropertyWithContext failed %s\n%s", err, response)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("ReplaceTektonPipelinePropertyWithContext failed: %s", err.Error()), "ibm_cd_tekton_pipeline_property", "update") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } @@ -312,23 +332,26 @@ func resourceIBMCdTektonPipelinePropertyUpdate(context context.Context, d *schem func resourceIBMCdTektonPipelinePropertyDelete(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { cdTektonPipelineClient, err := meta.(conns.ClientSession).CdTektonPipelineV2() if err != nil { - return diag.FromErr(err) + tfErr := flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline_property", "delete", "initialize-client") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } deleteTektonPipelinePropertyOptions := &cdtektonpipelinev2.DeleteTektonPipelinePropertyOptions{} parts, err := flex.SepIdParts(d.Id(), "/") if err != nil { - return diag.FromErr(err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline_property", "delete", "sep-id-parts").GetDiag() } deleteTektonPipelinePropertyOptions.SetPipelineID(parts[0]) deleteTektonPipelinePropertyOptions.SetPropertyName(parts[1]) - response, err := cdTektonPipelineClient.DeleteTektonPipelinePropertyWithContext(context, deleteTektonPipelinePropertyOptions) + _, err = cdTektonPipelineClient.DeleteTektonPipelinePropertyWithContext(context, deleteTektonPipelinePropertyOptions) if err != nil { - log.Printf("[DEBUG] DeleteTektonPipelinePropertyWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("DeleteTektonPipelinePropertyWithContext failed %s\n%s", err, response)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("DeleteTektonPipelinePropertyWithContext failed: %s", err.Error()), "ibm_cd_tekton_pipeline_property", "delete") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } d.SetId("") diff --git a/ibm/service/cdtektonpipeline/resource_ibm_cd_tekton_pipeline_property_test.go b/ibm/service/cdtektonpipeline/resource_ibm_cd_tekton_pipeline_property_test.go index 74171f47ec..b4a23f38c3 100644 --- a/ibm/service/cdtektonpipeline/resource_ibm_cd_tekton_pipeline_property_test.go +++ b/ibm/service/cdtektonpipeline/resource_ibm_cd_tekton_pipeline_property_test.go @@ -29,9 +29,9 @@ func TestAccIBMCdTektonPipelinePropertyBasic(t *testing.T) { resource.TestStep{ Config: testAccCheckIBMCdTektonPipelinePropertyConfigBasic("", name, typeVar), Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckIBMCdTektonPipelinePropertyExists("ibm_cd_tekton_pipeline_property.cd_tekton_pipeline_property", conf), - resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_property.cd_tekton_pipeline_property", "name", name), - resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_property.cd_tekton_pipeline_property", "type", typeVar), + testAccCheckIBMCdTektonPipelinePropertyExists("ibm_cd_tekton_pipeline_property.cd_tekton_pipeline_property_instance", conf), + resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_property.cd_tekton_pipeline_property_instance", "name", name), + resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_property.cd_tekton_pipeline_property_instance", "type", typeVar), ), }, }, @@ -41,8 +41,8 @@ func TestAccIBMCdTektonPipelinePropertyBasic(t *testing.T) { func TestAccIBMCdTektonPipelinePropertyAllArgs(t *testing.T) { var conf cdtektonpipelinev2.Property name := fmt.Sprintf("tf_name_%d", acctest.RandIntRange(10, 100)) - typeVar := "text" value := fmt.Sprintf("tf_value_%d", acctest.RandIntRange(10, 100)) + typeVar := "text" locked := "true" path := fmt.Sprintf("tf_path_%d", acctest.RandIntRange(10, 100)) valueUpdate := fmt.Sprintf("tf_value_%d", acctest.RandIntRange(10, 100)) @@ -55,28 +55,29 @@ func TestAccIBMCdTektonPipelinePropertyAllArgs(t *testing.T) { CheckDestroy: testAccCheckIBMCdTektonPipelinePropertyDestroy, Steps: []resource.TestStep{ resource.TestStep{ - Config: testAccCheckIBMCdTektonPipelinePropertyConfig("", name, typeVar, value, locked, path), + Config: testAccCheckIBMCdTektonPipelinePropertyConfig("", name, value, typeVar, locked, path), Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckIBMCdTektonPipelinePropertyExists("ibm_cd_tekton_pipeline_property.cd_tekton_pipeline_property", conf), - resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_property.cd_tekton_pipeline_property", "name", name), - resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_property.cd_tekton_pipeline_property", "type", typeVar), - resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_property.cd_tekton_pipeline_property", "value", value), - resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_property.cd_tekton_pipeline_property", "locked", locked), + testAccCheckIBMCdTektonPipelinePropertyExists("ibm_cd_tekton_pipeline_property.cd_tekton_pipeline_property_instance", conf), + resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_property.cd_tekton_pipeline_property_instance", "name", name), + resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_property.cd_tekton_pipeline_property_instance", "value", value), + resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_property.cd_tekton_pipeline_property_instance", "type", typeVar), + resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_property.cd_tekton_pipeline_property_instance", "locked", locked), ), }, resource.TestStep{ - Config: testAccCheckIBMCdTektonPipelinePropertyConfig("", name, typeVar, valueUpdate, lockedUpdate, pathUpdate), + Config: testAccCheckIBMCdTektonPipelinePropertyConfig("", name, valueUpdate, typeVar, lockedUpdate, pathUpdate), Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_property.cd_tekton_pipeline_property", "name", name), - resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_property.cd_tekton_pipeline_property", "type", typeVar), - resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_property.cd_tekton_pipeline_property", "value", valueUpdate), - resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_property.cd_tekton_pipeline_property", "locked", lockedUpdate), + resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_property.cd_tekton_pipeline_property_instance", "name", name), + resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_property.cd_tekton_pipeline_property_instance", "value", valueUpdate), + resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_property.cd_tekton_pipeline_property_instance", "type", typeVar), + resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_property.cd_tekton_pipeline_property_instance", "locked", lockedUpdate), ), }, resource.TestStep{ - ResourceName: "ibm_cd_tekton_pipeline_property.cd_tekton_pipeline_property", - ImportState: true, - ImportStateVerify: true, + ResourceName: "ibm_cd_tekton_pipeline_property.cd_tekton_pipeline_property_instance", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"pipeline_id"}, }, }, }) @@ -99,7 +100,7 @@ func testAccCheckIBMCdTektonPipelinePropertyConfigBasic(pipelineID string, name name = "pipeline-name" } } - resource "ibm_cd_tekton_pipeline" "cd_tekton_pipeline" { + resource "ibm_cd_tekton_pipeline" "cd_tekton_pipeline_instance" { pipeline_id = ibm_cd_toolchain_tool_pipeline.ibm_cd_toolchain_tool_pipeline.tool_id next_build_number = 5 worker { @@ -109,19 +110,19 @@ func testAccCheckIBMCdTektonPipelinePropertyConfigBasic(pipelineID string, name ibm_cd_toolchain_tool_pipeline.ibm_cd_toolchain_tool_pipeline ] } - resource "ibm_cd_tekton_pipeline_property" "cd_tekton_pipeline_property" { - pipeline_id = ibm_cd_tekton_pipeline.cd_tekton_pipeline.pipeline_id + resource "ibm_cd_tekton_pipeline_property" "cd_tekton_pipeline_property_instance" { + pipeline_id = ibm_cd_tekton_pipeline.cd_tekton_pipeline_instance.pipeline_id name = "property1" type = "text" value = "prop1" depends_on = [ - ibm_cd_tekton_pipeline.cd_tekton_pipeline + ibm_cd_tekton_pipeline.cd_tekton_pipeline_instance ] } `, rgName, tcName) } -func testAccCheckIBMCdTektonPipelinePropertyConfig(pipelineID string, name string, typeVar string, value string, locked string, path string) string { +func testAccCheckIBMCdTektonPipelinePropertyConfig(pipelineID string, name string, value string, typeVar string, locked string, path string) string { rgName := acc.CdResourceGroupName tcName := fmt.Sprintf("tf_name_%d", acctest.RandIntRange(10, 100)) return fmt.Sprintf(` @@ -138,7 +139,7 @@ func testAccCheckIBMCdTektonPipelinePropertyConfig(pipelineID string, name strin name = "pipeline-name" } } - resource "ibm_cd_tekton_pipeline" "cd_tekton_pipeline" { + resource "ibm_cd_tekton_pipeline" "cd_tekton_pipeline_instance" { pipeline_id = ibm_cd_toolchain_tool_pipeline.ibm_cd_toolchain_tool_pipeline.tool_id next_build_number = 5 worker { @@ -148,14 +149,14 @@ func testAccCheckIBMCdTektonPipelinePropertyConfig(pipelineID string, name strin ibm_cd_toolchain_tool_pipeline.ibm_cd_toolchain_tool_pipeline ] } - resource "ibm_cd_tekton_pipeline_property" "cd_tekton_pipeline_property" { - pipeline_id = ibm_cd_tekton_pipeline.cd_tekton_pipeline.pipeline_id + resource "ibm_cd_tekton_pipeline_property" "cd_tekton_pipeline_property_instance" { + pipeline_id = ibm_cd_tekton_pipeline.cd_tekton_pipeline_instance.pipeline_id name = "%s" type = "text" value = "%s" locked = "%s" depends_on = [ - ibm_cd_tekton_pipeline.cd_tekton_pipeline + ibm_cd_tekton_pipeline.cd_tekton_pipeline_instance ] } `, rgName, tcName, name, value, locked) diff --git a/ibm/service/cdtektonpipeline/resource_ibm_cd_tekton_pipeline_test.go b/ibm/service/cdtektonpipeline/resource_ibm_cd_tekton_pipeline_test.go index 3469a2cc5a..028a4b6bd3 100644 --- a/ibm/service/cdtektonpipeline/resource_ibm_cd_tekton_pipeline_test.go +++ b/ibm/service/cdtektonpipeline/resource_ibm_cd_tekton_pipeline_test.go @@ -13,7 +13,10 @@ import ( 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/service/cdtektonpipeline" "github.com/IBM/continuous-delivery-go-sdk/cdtektonpipelinev2" + "github.com/IBM/go-sdk-core/v5/core" + "github.com/stretchr/testify/assert" ) func TestAccIBMCdTektonPipelineBasic(t *testing.T) { @@ -27,7 +30,7 @@ func TestAccIBMCdTektonPipelineBasic(t *testing.T) { resource.TestStep{ Config: testAccCheckIBMCdTektonPipelineConfigBasic(), Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckIBMCdTektonPipelineExists("ibm_cd_tekton_pipeline.cd_tekton_pipeline", conf), + testAccCheckIBMCdTektonPipelineExists("ibm_cd_tekton_pipeline.cd_tekton_pipeline_instance", conf), ), }, }, @@ -51,22 +54,22 @@ func TestAccIBMCdTektonPipelineAllArgs(t *testing.T) { resource.TestStep{ Config: testAccCheckIBMCdTektonPipelineConfig(nextBuildNumber, enableNotifications, enablePartialCloning), Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckIBMCdTektonPipelineExists("ibm_cd_tekton_pipeline.cd_tekton_pipeline", conf), - resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline.cd_tekton_pipeline", "next_build_number", nextBuildNumber), - resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline.cd_tekton_pipeline", "enable_notifications", enableNotifications), - resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline.cd_tekton_pipeline", "enable_partial_cloning", enablePartialCloning), + testAccCheckIBMCdTektonPipelineExists("ibm_cd_tekton_pipeline.cd_tekton_pipeline_instance", conf), + resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline.cd_tekton_pipeline_instance", "next_build_number", nextBuildNumber), + resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline.cd_tekton_pipeline_instance", "enable_notifications", enableNotifications), + resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline.cd_tekton_pipeline_instance", "enable_partial_cloning", enablePartialCloning), ), }, resource.TestStep{ Config: testAccCheckIBMCdTektonPipelineConfig(nextBuildNumberUpdate, enableNotificationsUpdate, enablePartialCloningUpdate), Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline.cd_tekton_pipeline", "next_build_number", nextBuildNumberUpdate), - resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline.cd_tekton_pipeline", "enable_notifications", enableNotificationsUpdate), - resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline.cd_tekton_pipeline", "enable_partial_cloning", enablePartialCloningUpdate), + resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline.cd_tekton_pipeline_instance", "next_build_number", nextBuildNumberUpdate), + resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline.cd_tekton_pipeline_instance", "enable_notifications", enableNotificationsUpdate), + resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline.cd_tekton_pipeline_instance", "enable_partial_cloning", enablePartialCloningUpdate), ), }, resource.TestStep{ - ResourceName: "ibm_cd_tekton_pipeline.cd_tekton_pipeline", + ResourceName: "ibm_cd_tekton_pipeline.cd_tekton_pipeline_instance", ImportState: true, ImportStateVerify: true, }, @@ -91,7 +94,7 @@ func testAccCheckIBMCdTektonPipelineConfigBasic() string { name = "pipeline-name" } } - resource "ibm_cd_tekton_pipeline" "cd_tekton_pipeline" { + resource "ibm_cd_tekton_pipeline" "cd_tekton_pipeline_instance" { pipeline_id = ibm_cd_toolchain_tool_pipeline.ibm_cd_toolchain_tool_pipeline.tool_id next_build_number = 5 worker { @@ -121,7 +124,7 @@ func testAccCheckIBMCdTektonPipelineConfig(nextBuildNumber string, enableNotific name = "pipeline-name" } } - resource "ibm_cd_tekton_pipeline" "cd_tekton_pipeline" { + resource "ibm_cd_tekton_pipeline" "cd_tekton_pipeline_instance" { pipeline_id = ibm_cd_toolchain_tool_pipeline.ibm_cd_toolchain_tool_pipeline.tool_id next_build_number = %s enable_notifications = %s @@ -189,3 +192,799 @@ func testAccCheckIBMCdTektonPipelineDestroy(s *terraform.State) error { return nil } + +func TestResourceIBMCdTektonPipelineWorkerToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + model := make(map[string]interface{}) + model["name"] = "testString" + model["type"] = "testString" + model["id"] = "testString" + + assert.Equal(t, result, model) + } + + model := new(cdtektonpipelinev2.Worker) + model.Name = core.StringPtr("testString") + model.Type = core.StringPtr("testString") + model.ID = core.StringPtr("testString") + + result, err := cdtektonpipeline.ResourceIBMCdTektonPipelineWorkerToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestResourceIBMCdTektonPipelineResourceGroupReferenceToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + model := make(map[string]interface{}) + model["id"] = "testString" + + assert.Equal(t, result, model) + } + + model := new(cdtektonpipelinev2.ResourceGroupReference) + model.ID = core.StringPtr("testString") + + result, err := cdtektonpipeline.ResourceIBMCdTektonPipelineResourceGroupReferenceToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestResourceIBMCdTektonPipelineToolchainReferenceToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + model := make(map[string]interface{}) + model["id"] = "testString" + model["crn"] = "crn:v1:staging:public:toolchain:us-south:a/0ba224679d6c697f9baee5e14ade83ac:bf5fa00f-ddef-4298-b87b-aa8b6da0e1a6::" + + assert.Equal(t, result, model) + } + + model := new(cdtektonpipelinev2.ToolchainReference) + model.ID = core.StringPtr("testString") + model.CRN = core.StringPtr("crn:v1:staging:public:toolchain:us-south:a/0ba224679d6c697f9baee5e14ade83ac:bf5fa00f-ddef-4298-b87b-aa8b6da0e1a6::") + + result, err := cdtektonpipeline.ResourceIBMCdTektonPipelineToolchainReferenceToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestResourceIBMCdTektonPipelineDefinitionToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + toolModel := make(map[string]interface{}) + toolModel["id"] = "testString" + + definitionSourcePropertiesModel := make(map[string]interface{}) + definitionSourcePropertiesModel["url"] = "testString" + definitionSourcePropertiesModel["branch"] = "testString" + definitionSourcePropertiesModel["tag"] = "testString" + definitionSourcePropertiesModel["path"] = "testString" + definitionSourcePropertiesModel["tool"] = []map[string]interface{}{toolModel} + + definitionSourceModel := make(map[string]interface{}) + definitionSourceModel["type"] = "testString" + definitionSourceModel["properties"] = []map[string]interface{}{definitionSourcePropertiesModel} + + model := make(map[string]interface{}) + model["source"] = []map[string]interface{}{definitionSourceModel} + model["href"] = "testString" + model["id"] = "testString" + + assert.Equal(t, result, model) + } + + toolModel := new(cdtektonpipelinev2.Tool) + toolModel.ID = core.StringPtr("testString") + + definitionSourcePropertiesModel := new(cdtektonpipelinev2.DefinitionSourceProperties) + definitionSourcePropertiesModel.URL = core.StringPtr("testString") + definitionSourcePropertiesModel.Branch = core.StringPtr("testString") + definitionSourcePropertiesModel.Tag = core.StringPtr("testString") + definitionSourcePropertiesModel.Path = core.StringPtr("testString") + definitionSourcePropertiesModel.Tool = toolModel + + definitionSourceModel := new(cdtektonpipelinev2.DefinitionSource) + definitionSourceModel.Type = core.StringPtr("testString") + definitionSourceModel.Properties = definitionSourcePropertiesModel + + model := new(cdtektonpipelinev2.Definition) + model.Source = definitionSourceModel + model.Href = core.StringPtr("testString") + model.ID = core.StringPtr("testString") + + result, err := cdtektonpipeline.ResourceIBMCdTektonPipelineDefinitionToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestResourceIBMCdTektonPipelineDefinitionSourceToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + toolModel := make(map[string]interface{}) + toolModel["id"] = "testString" + + definitionSourcePropertiesModel := make(map[string]interface{}) + definitionSourcePropertiesModel["url"] = "testString" + definitionSourcePropertiesModel["branch"] = "testString" + definitionSourcePropertiesModel["tag"] = "testString" + definitionSourcePropertiesModel["path"] = "testString" + definitionSourcePropertiesModel["tool"] = []map[string]interface{}{toolModel} + + model := make(map[string]interface{}) + model["type"] = "testString" + model["properties"] = []map[string]interface{}{definitionSourcePropertiesModel} + + assert.Equal(t, result, model) + } + + toolModel := new(cdtektonpipelinev2.Tool) + toolModel.ID = core.StringPtr("testString") + + definitionSourcePropertiesModel := new(cdtektonpipelinev2.DefinitionSourceProperties) + definitionSourcePropertiesModel.URL = core.StringPtr("testString") + definitionSourcePropertiesModel.Branch = core.StringPtr("testString") + definitionSourcePropertiesModel.Tag = core.StringPtr("testString") + definitionSourcePropertiesModel.Path = core.StringPtr("testString") + definitionSourcePropertiesModel.Tool = toolModel + + model := new(cdtektonpipelinev2.DefinitionSource) + model.Type = core.StringPtr("testString") + model.Properties = definitionSourcePropertiesModel + + result, err := cdtektonpipeline.ResourceIBMCdTektonPipelineDefinitionSourceToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestResourceIBMCdTektonPipelineDefinitionSourcePropertiesToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + toolModel := make(map[string]interface{}) + toolModel["id"] = "testString" + + model := make(map[string]interface{}) + model["url"] = "testString" + model["branch"] = "testString" + model["tag"] = "testString" + model["path"] = "testString" + model["tool"] = []map[string]interface{}{toolModel} + + assert.Equal(t, result, model) + } + + toolModel := new(cdtektonpipelinev2.Tool) + toolModel.ID = core.StringPtr("testString") + + model := new(cdtektonpipelinev2.DefinitionSourceProperties) + model.URL = core.StringPtr("testString") + model.Branch = core.StringPtr("testString") + model.Tag = core.StringPtr("testString") + model.Path = core.StringPtr("testString") + model.Tool = toolModel + + result, err := cdtektonpipeline.ResourceIBMCdTektonPipelineDefinitionSourcePropertiesToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestResourceIBMCdTektonPipelineToolToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + model := make(map[string]interface{}) + model["id"] = "testString" + + assert.Equal(t, result, model) + } + + model := new(cdtektonpipelinev2.Tool) + model.ID = core.StringPtr("testString") + + result, err := cdtektonpipeline.ResourceIBMCdTektonPipelineToolToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestResourceIBMCdTektonPipelinePropertyToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + model := make(map[string]interface{}) + model["name"] = "testString" + model["value"] = "testString" + model["href"] = "testString" + model["enum"] = []string{"testString"} + model["type"] = "secure" + model["locked"] = true + model["path"] = "testString" + + assert.Equal(t, result, model) + } + + model := new(cdtektonpipelinev2.Property) + model.Name = core.StringPtr("testString") + model.Value = core.StringPtr("testString") + model.Href = core.StringPtr("testString") + model.Enum = []string{"testString"} + model.Type = core.StringPtr("secure") + model.Locked = core.BoolPtr(true) + model.Path = core.StringPtr("testString") + + result, err := cdtektonpipeline.ResourceIBMCdTektonPipelinePropertyToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestResourceIBMCdTektonPipelineTriggerToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + triggerPropertyModel := make(map[string]interface{}) + triggerPropertyModel["name"] = "testString" + triggerPropertyModel["value"] = "testString" + triggerPropertyModel["href"] = "testString" + triggerPropertyModel["enum"] = []string{"testString"} + triggerPropertyModel["type"] = "secure" + triggerPropertyModel["path"] = "testString" + triggerPropertyModel["locked"] = true + + workerModel := make(map[string]interface{}) + workerModel["name"] = "testString" + workerModel["type"] = "testString" + workerModel["id"] = "testString" + + toolModel := make(map[string]interface{}) + toolModel["id"] = "testString" + + triggerSourcePropertiesModel := make(map[string]interface{}) + triggerSourcePropertiesModel["url"] = "testString" + triggerSourcePropertiesModel["branch"] = "testString" + triggerSourcePropertiesModel["pattern"] = "testString" + triggerSourcePropertiesModel["blind_connection"] = true + triggerSourcePropertiesModel["hook_id"] = "testString" + triggerSourcePropertiesModel["tool"] = []map[string]interface{}{toolModel} + + triggerSourceModel := make(map[string]interface{}) + triggerSourceModel["type"] = "testString" + triggerSourceModel["properties"] = []map[string]interface{}{triggerSourcePropertiesModel} + + genericSecretModel := make(map[string]interface{}) + genericSecretModel["type"] = "token_matches" + genericSecretModel["value"] = "testString" + genericSecretModel["source"] = "header" + genericSecretModel["key_name"] = "testString" + genericSecretModel["algorithm"] = "md4" + + model := make(map[string]interface{}) + model["type"] = "testString" + model["name"] = "start-deploy" + model["href"] = "testString" + model["event_listener"] = "testString" + model["id"] = "testString" + model["properties"] = []map[string]interface{}{triggerPropertyModel} + model["tags"] = []string{"testString"} + model["worker"] = []map[string]interface{}{workerModel} + model["max_concurrent_runs"] = int(4) + model["enabled"] = true + model["favorite"] = false + model["enable_events_from_forks"] = false + model["source"] = []map[string]interface{}{triggerSourceModel} + model["events"] = []string{"push", "pull_request"} + model["filter"] = "header['x-github-event'] == 'push' && body.ref == 'refs/heads/main'" + model["cron"] = "testString" + model["timezone"] = "America/Los_Angeles, CET, Europe/London, GMT, US/Eastern, or UTC" + model["secret"] = []map[string]interface{}{genericSecretModel} + model["webhook_url"] = "testString" + + assert.Equal(t, result, model) + } + + triggerPropertyModel := new(cdtektonpipelinev2.TriggerProperty) + triggerPropertyModel.Name = core.StringPtr("testString") + triggerPropertyModel.Value = core.StringPtr("testString") + triggerPropertyModel.Href = core.StringPtr("testString") + triggerPropertyModel.Enum = []string{"testString"} + triggerPropertyModel.Type = core.StringPtr("secure") + triggerPropertyModel.Path = core.StringPtr("testString") + triggerPropertyModel.Locked = core.BoolPtr(true) + + workerModel := new(cdtektonpipelinev2.Worker) + workerModel.Name = core.StringPtr("testString") + workerModel.Type = core.StringPtr("testString") + workerModel.ID = core.StringPtr("testString") + + toolModel := new(cdtektonpipelinev2.Tool) + toolModel.ID = core.StringPtr("testString") + + triggerSourcePropertiesModel := new(cdtektonpipelinev2.TriggerSourceProperties) + triggerSourcePropertiesModel.URL = core.StringPtr("testString") + triggerSourcePropertiesModel.Branch = core.StringPtr("testString") + triggerSourcePropertiesModel.Pattern = core.StringPtr("testString") + triggerSourcePropertiesModel.BlindConnection = core.BoolPtr(true) + triggerSourcePropertiesModel.HookID = core.StringPtr("testString") + triggerSourcePropertiesModel.Tool = toolModel + + triggerSourceModel := new(cdtektonpipelinev2.TriggerSource) + triggerSourceModel.Type = core.StringPtr("testString") + triggerSourceModel.Properties = triggerSourcePropertiesModel + + genericSecretModel := new(cdtektonpipelinev2.GenericSecret) + genericSecretModel.Type = core.StringPtr("token_matches") + genericSecretModel.Value = core.StringPtr("testString") + genericSecretModel.Source = core.StringPtr("header") + genericSecretModel.KeyName = core.StringPtr("testString") + genericSecretModel.Algorithm = core.StringPtr("md4") + + model := new(cdtektonpipelinev2.Trigger) + model.Type = core.StringPtr("testString") + model.Name = core.StringPtr("start-deploy") + model.Href = core.StringPtr("testString") + model.EventListener = core.StringPtr("testString") + model.ID = core.StringPtr("testString") + model.Properties = []cdtektonpipelinev2.TriggerProperty{*triggerPropertyModel} + model.Tags = []string{"testString"} + model.Worker = workerModel + model.MaxConcurrentRuns = core.Int64Ptr(int64(4)) + model.Enabled = core.BoolPtr(true) + model.Favorite = core.BoolPtr(false) + model.EnableEventsFromForks = core.BoolPtr(false) + model.Source = triggerSourceModel + model.Events = []string{"push", "pull_request"} + model.Filter = core.StringPtr("header['x-github-event'] == 'push' && body.ref == 'refs/heads/main'") + model.Cron = core.StringPtr("testString") + model.Timezone = core.StringPtr("America/Los_Angeles, CET, Europe/London, GMT, US/Eastern, or UTC") + model.Secret = genericSecretModel + model.WebhookURL = core.StringPtr("testString") + + result, err := cdtektonpipeline.ResourceIBMCdTektonPipelineTriggerToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestResourceIBMCdTektonPipelineTriggerPropertyToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + model := make(map[string]interface{}) + model["name"] = "testString" + model["value"] = "testString" + model["href"] = "testString" + model["enum"] = []string{"testString"} + model["type"] = "secure" + model["path"] = "testString" + model["locked"] = true + + assert.Equal(t, result, model) + } + + model := new(cdtektonpipelinev2.TriggerProperty) + model.Name = core.StringPtr("testString") + model.Value = core.StringPtr("testString") + model.Href = core.StringPtr("testString") + model.Enum = []string{"testString"} + model.Type = core.StringPtr("secure") + model.Path = core.StringPtr("testString") + model.Locked = core.BoolPtr(true) + + result, err := cdtektonpipeline.ResourceIBMCdTektonPipelineTriggerPropertyToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestResourceIBMCdTektonPipelineTriggerSourceToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + toolModel := make(map[string]interface{}) + toolModel["id"] = "testString" + + triggerSourcePropertiesModel := make(map[string]interface{}) + triggerSourcePropertiesModel["url"] = "testString" + triggerSourcePropertiesModel["branch"] = "testString" + triggerSourcePropertiesModel["pattern"] = "testString" + triggerSourcePropertiesModel["blind_connection"] = true + triggerSourcePropertiesModel["hook_id"] = "testString" + triggerSourcePropertiesModel["tool"] = []map[string]interface{}{toolModel} + + model := make(map[string]interface{}) + model["type"] = "testString" + model["properties"] = []map[string]interface{}{triggerSourcePropertiesModel} + + assert.Equal(t, result, model) + } + + toolModel := new(cdtektonpipelinev2.Tool) + toolModel.ID = core.StringPtr("testString") + + triggerSourcePropertiesModel := new(cdtektonpipelinev2.TriggerSourceProperties) + triggerSourcePropertiesModel.URL = core.StringPtr("testString") + triggerSourcePropertiesModel.Branch = core.StringPtr("testString") + triggerSourcePropertiesModel.Pattern = core.StringPtr("testString") + triggerSourcePropertiesModel.BlindConnection = core.BoolPtr(true) + triggerSourcePropertiesModel.HookID = core.StringPtr("testString") + triggerSourcePropertiesModel.Tool = toolModel + + model := new(cdtektonpipelinev2.TriggerSource) + model.Type = core.StringPtr("testString") + model.Properties = triggerSourcePropertiesModel + + result, err := cdtektonpipeline.ResourceIBMCdTektonPipelineTriggerSourceToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestResourceIBMCdTektonPipelineTriggerSourcePropertiesToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + toolModel := make(map[string]interface{}) + toolModel["id"] = "testString" + + model := make(map[string]interface{}) + model["url"] = "testString" + model["branch"] = "testString" + model["pattern"] = "testString" + model["blind_connection"] = true + model["hook_id"] = "testString" + model["tool"] = []map[string]interface{}{toolModel} + + assert.Equal(t, result, model) + } + + toolModel := new(cdtektonpipelinev2.Tool) + toolModel.ID = core.StringPtr("testString") + + model := new(cdtektonpipelinev2.TriggerSourceProperties) + model.URL = core.StringPtr("testString") + model.Branch = core.StringPtr("testString") + model.Pattern = core.StringPtr("testString") + model.BlindConnection = core.BoolPtr(true) + model.HookID = core.StringPtr("testString") + model.Tool = toolModel + + result, err := cdtektonpipeline.ResourceIBMCdTektonPipelineTriggerSourcePropertiesToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestResourceIBMCdTektonPipelineGenericSecretToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + model := make(map[string]interface{}) + model["type"] = "token_matches" + model["value"] = "testString" + model["source"] = "header" + model["key_name"] = "testString" + model["algorithm"] = "md4" + + assert.Equal(t, result, model) + } + + model := new(cdtektonpipelinev2.GenericSecret) + model.Type = core.StringPtr("token_matches") + model.Value = core.StringPtr("testString") + model.Source = core.StringPtr("header") + model.KeyName = core.StringPtr("testString") + model.Algorithm = core.StringPtr("md4") + + result, err := cdtektonpipeline.ResourceIBMCdTektonPipelineGenericSecretToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestResourceIBMCdTektonPipelineTriggerManualTriggerToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + triggerPropertyModel := make(map[string]interface{}) + triggerPropertyModel["name"] = "testString" + triggerPropertyModel["value"] = "testString" + triggerPropertyModel["href"] = "testString" + triggerPropertyModel["enum"] = []string{"testString"} + triggerPropertyModel["type"] = "secure" + triggerPropertyModel["path"] = "testString" + triggerPropertyModel["locked"] = true + + workerModel := make(map[string]interface{}) + workerModel["name"] = "testString" + workerModel["type"] = "testString" + workerModel["id"] = "testString" + + model := make(map[string]interface{}) + model["type"] = "testString" + model["name"] = "start-deploy" + model["href"] = "testString" + model["event_listener"] = "testString" + model["id"] = "testString" + model["properties"] = []map[string]interface{}{triggerPropertyModel} + model["tags"] = []string{"testString"} + model["worker"] = []map[string]interface{}{workerModel} + model["max_concurrent_runs"] = int(4) + model["enabled"] = true + model["favorite"] = false + + assert.Equal(t, result, model) + } + + triggerPropertyModel := new(cdtektonpipelinev2.TriggerProperty) + triggerPropertyModel.Name = core.StringPtr("testString") + triggerPropertyModel.Value = core.StringPtr("testString") + triggerPropertyModel.Href = core.StringPtr("testString") + triggerPropertyModel.Enum = []string{"testString"} + triggerPropertyModel.Type = core.StringPtr("secure") + triggerPropertyModel.Path = core.StringPtr("testString") + triggerPropertyModel.Locked = core.BoolPtr(true) + + workerModel := new(cdtektonpipelinev2.Worker) + workerModel.Name = core.StringPtr("testString") + workerModel.Type = core.StringPtr("testString") + workerModel.ID = core.StringPtr("testString") + + model := new(cdtektonpipelinev2.TriggerManualTrigger) + model.Type = core.StringPtr("testString") + model.Name = core.StringPtr("start-deploy") + model.Href = core.StringPtr("testString") + model.EventListener = core.StringPtr("testString") + model.ID = core.StringPtr("testString") + model.Properties = []cdtektonpipelinev2.TriggerProperty{*triggerPropertyModel} + model.Tags = []string{"testString"} + model.Worker = workerModel + model.MaxConcurrentRuns = core.Int64Ptr(int64(4)) + model.Enabled = core.BoolPtr(true) + model.Favorite = core.BoolPtr(false) + + result, err := cdtektonpipeline.ResourceIBMCdTektonPipelineTriggerManualTriggerToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestResourceIBMCdTektonPipelineTriggerScmTriggerToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + triggerPropertyModel := make(map[string]interface{}) + triggerPropertyModel["name"] = "testString" + triggerPropertyModel["value"] = "testString" + triggerPropertyModel["href"] = "testString" + triggerPropertyModel["enum"] = []string{"testString"} + triggerPropertyModel["type"] = "secure" + triggerPropertyModel["path"] = "testString" + triggerPropertyModel["locked"] = true + + workerModel := make(map[string]interface{}) + workerModel["name"] = "testString" + workerModel["type"] = "testString" + workerModel["id"] = "testString" + + toolModel := make(map[string]interface{}) + toolModel["id"] = "testString" + + triggerSourcePropertiesModel := make(map[string]interface{}) + triggerSourcePropertiesModel["url"] = "testString" + triggerSourcePropertiesModel["branch"] = "testString" + triggerSourcePropertiesModel["pattern"] = "testString" + triggerSourcePropertiesModel["blind_connection"] = true + triggerSourcePropertiesModel["hook_id"] = "testString" + triggerSourcePropertiesModel["tool"] = []map[string]interface{}{toolModel} + + triggerSourceModel := make(map[string]interface{}) + triggerSourceModel["type"] = "testString" + triggerSourceModel["properties"] = []map[string]interface{}{triggerSourcePropertiesModel} + + model := make(map[string]interface{}) + model["type"] = "testString" + model["name"] = "start-deploy" + model["href"] = "testString" + model["event_listener"] = "testString" + model["id"] = "testString" + model["properties"] = []map[string]interface{}{triggerPropertyModel} + model["tags"] = []string{"testString"} + model["worker"] = []map[string]interface{}{workerModel} + model["max_concurrent_runs"] = int(4) + model["enabled"] = true + model["favorite"] = false + model["enable_events_from_forks"] = false + model["source"] = []map[string]interface{}{triggerSourceModel} + model["events"] = []string{"push", "pull_request"} + model["filter"] = "header['x-github-event'] == 'push' && body.ref == 'refs/heads/main'" + + assert.Equal(t, result, model) + } + + triggerPropertyModel := new(cdtektonpipelinev2.TriggerProperty) + triggerPropertyModel.Name = core.StringPtr("testString") + triggerPropertyModel.Value = core.StringPtr("testString") + triggerPropertyModel.Href = core.StringPtr("testString") + triggerPropertyModel.Enum = []string{"testString"} + triggerPropertyModel.Type = core.StringPtr("secure") + triggerPropertyModel.Path = core.StringPtr("testString") + triggerPropertyModel.Locked = core.BoolPtr(true) + + workerModel := new(cdtektonpipelinev2.Worker) + workerModel.Name = core.StringPtr("testString") + workerModel.Type = core.StringPtr("testString") + workerModel.ID = core.StringPtr("testString") + + toolModel := new(cdtektonpipelinev2.Tool) + toolModel.ID = core.StringPtr("testString") + + triggerSourcePropertiesModel := new(cdtektonpipelinev2.TriggerSourceProperties) + triggerSourcePropertiesModel.URL = core.StringPtr("testString") + triggerSourcePropertiesModel.Branch = core.StringPtr("testString") + triggerSourcePropertiesModel.Pattern = core.StringPtr("testString") + triggerSourcePropertiesModel.BlindConnection = core.BoolPtr(true) + triggerSourcePropertiesModel.HookID = core.StringPtr("testString") + triggerSourcePropertiesModel.Tool = toolModel + + triggerSourceModel := new(cdtektonpipelinev2.TriggerSource) + triggerSourceModel.Type = core.StringPtr("testString") + triggerSourceModel.Properties = triggerSourcePropertiesModel + + model := new(cdtektonpipelinev2.TriggerScmTrigger) + model.Type = core.StringPtr("testString") + model.Name = core.StringPtr("start-deploy") + model.Href = core.StringPtr("testString") + model.EventListener = core.StringPtr("testString") + model.ID = core.StringPtr("testString") + model.Properties = []cdtektonpipelinev2.TriggerProperty{*triggerPropertyModel} + model.Tags = []string{"testString"} + model.Worker = workerModel + model.MaxConcurrentRuns = core.Int64Ptr(int64(4)) + model.Enabled = core.BoolPtr(true) + model.Favorite = core.BoolPtr(false) + model.EnableEventsFromForks = core.BoolPtr(false) + model.Source = triggerSourceModel + model.Events = []string{"push", "pull_request"} + model.Filter = core.StringPtr("header['x-github-event'] == 'push' && body.ref == 'refs/heads/main'") + + result, err := cdtektonpipeline.ResourceIBMCdTektonPipelineTriggerScmTriggerToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestResourceIBMCdTektonPipelineTriggerTimerTriggerToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + triggerPropertyModel := make(map[string]interface{}) + triggerPropertyModel["name"] = "testString" + triggerPropertyModel["value"] = "testString" + triggerPropertyModel["href"] = "testString" + triggerPropertyModel["enum"] = []string{"testString"} + triggerPropertyModel["type"] = "secure" + triggerPropertyModel["path"] = "testString" + triggerPropertyModel["locked"] = true + + workerModel := make(map[string]interface{}) + workerModel["name"] = "testString" + workerModel["type"] = "testString" + workerModel["id"] = "testString" + + model := make(map[string]interface{}) + model["type"] = "testString" + model["name"] = "start-deploy" + model["href"] = "testString" + model["event_listener"] = "testString" + model["id"] = "testString" + model["properties"] = []map[string]interface{}{triggerPropertyModel} + model["tags"] = []string{"testString"} + model["worker"] = []map[string]interface{}{workerModel} + model["max_concurrent_runs"] = int(4) + model["enabled"] = true + model["favorite"] = false + model["cron"] = "testString" + model["timezone"] = "America/Los_Angeles, CET, Europe/London, GMT, US/Eastern, or UTC" + + assert.Equal(t, result, model) + } + + triggerPropertyModel := new(cdtektonpipelinev2.TriggerProperty) + triggerPropertyModel.Name = core.StringPtr("testString") + triggerPropertyModel.Value = core.StringPtr("testString") + triggerPropertyModel.Href = core.StringPtr("testString") + triggerPropertyModel.Enum = []string{"testString"} + triggerPropertyModel.Type = core.StringPtr("secure") + triggerPropertyModel.Path = core.StringPtr("testString") + triggerPropertyModel.Locked = core.BoolPtr(true) + + workerModel := new(cdtektonpipelinev2.Worker) + workerModel.Name = core.StringPtr("testString") + workerModel.Type = core.StringPtr("testString") + workerModel.ID = core.StringPtr("testString") + + model := new(cdtektonpipelinev2.TriggerTimerTrigger) + model.Type = core.StringPtr("testString") + model.Name = core.StringPtr("start-deploy") + model.Href = core.StringPtr("testString") + model.EventListener = core.StringPtr("testString") + model.ID = core.StringPtr("testString") + model.Properties = []cdtektonpipelinev2.TriggerProperty{*triggerPropertyModel} + model.Tags = []string{"testString"} + model.Worker = workerModel + model.MaxConcurrentRuns = core.Int64Ptr(int64(4)) + model.Enabled = core.BoolPtr(true) + model.Favorite = core.BoolPtr(false) + model.Cron = core.StringPtr("testString") + model.Timezone = core.StringPtr("America/Los_Angeles, CET, Europe/London, GMT, US/Eastern, or UTC") + + result, err := cdtektonpipeline.ResourceIBMCdTektonPipelineTriggerTimerTriggerToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestResourceIBMCdTektonPipelineTriggerGenericTriggerToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + triggerPropertyModel := make(map[string]interface{}) + triggerPropertyModel["name"] = "testString" + triggerPropertyModel["value"] = "testString" + triggerPropertyModel["href"] = "testString" + triggerPropertyModel["enum"] = []string{"testString"} + triggerPropertyModel["type"] = "secure" + triggerPropertyModel["path"] = "testString" + triggerPropertyModel["locked"] = true + + workerModel := make(map[string]interface{}) + workerModel["name"] = "testString" + workerModel["type"] = "testString" + workerModel["id"] = "testString" + + genericSecretModel := make(map[string]interface{}) + genericSecretModel["type"] = "token_matches" + genericSecretModel["value"] = "testString" + genericSecretModel["source"] = "header" + genericSecretModel["key_name"] = "testString" + genericSecretModel["algorithm"] = "md4" + + model := make(map[string]interface{}) + model["type"] = "testString" + model["name"] = "start-deploy" + model["href"] = "testString" + model["event_listener"] = "testString" + model["id"] = "testString" + model["properties"] = []map[string]interface{}{triggerPropertyModel} + model["tags"] = []string{"testString"} + model["worker"] = []map[string]interface{}{workerModel} + model["max_concurrent_runs"] = int(4) + model["enabled"] = true + model["favorite"] = false + model["secret"] = []map[string]interface{}{genericSecretModel} + model["webhook_url"] = "testString" + model["filter"] = "event.type == 'message' && event.text.contains('urgent')" + + assert.Equal(t, result, model) + } + + triggerPropertyModel := new(cdtektonpipelinev2.TriggerProperty) + triggerPropertyModel.Name = core.StringPtr("testString") + triggerPropertyModel.Value = core.StringPtr("testString") + triggerPropertyModel.Href = core.StringPtr("testString") + triggerPropertyModel.Enum = []string{"testString"} + triggerPropertyModel.Type = core.StringPtr("secure") + triggerPropertyModel.Path = core.StringPtr("testString") + triggerPropertyModel.Locked = core.BoolPtr(true) + + workerModel := new(cdtektonpipelinev2.Worker) + workerModel.Name = core.StringPtr("testString") + workerModel.Type = core.StringPtr("testString") + workerModel.ID = core.StringPtr("testString") + + genericSecretModel := new(cdtektonpipelinev2.GenericSecret) + genericSecretModel.Type = core.StringPtr("token_matches") + genericSecretModel.Value = core.StringPtr("testString") + genericSecretModel.Source = core.StringPtr("header") + genericSecretModel.KeyName = core.StringPtr("testString") + genericSecretModel.Algorithm = core.StringPtr("md4") + + model := new(cdtektonpipelinev2.TriggerGenericTrigger) + model.Type = core.StringPtr("testString") + model.Name = core.StringPtr("start-deploy") + model.Href = core.StringPtr("testString") + model.EventListener = core.StringPtr("testString") + model.ID = core.StringPtr("testString") + model.Properties = []cdtektonpipelinev2.TriggerProperty{*triggerPropertyModel} + model.Tags = []string{"testString"} + model.Worker = workerModel + model.MaxConcurrentRuns = core.Int64Ptr(int64(4)) + model.Enabled = core.BoolPtr(true) + model.Favorite = core.BoolPtr(false) + model.Secret = genericSecretModel + model.WebhookURL = core.StringPtr("testString") + model.Filter = core.StringPtr("event.type == 'message' && event.text.contains('urgent')") + + result, err := cdtektonpipeline.ResourceIBMCdTektonPipelineTriggerGenericTriggerToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestResourceIBMCdTektonPipelineMapToWorkerIdentity(t *testing.T) { + checkResult := func(result *cdtektonpipelinev2.WorkerIdentity) { + model := new(cdtektonpipelinev2.WorkerIdentity) + model.ID = core.StringPtr("testString") + + assert.Equal(t, result, model) + } + + model := make(map[string]interface{}) + model["id"] = "testString" + + result, err := cdtektonpipeline.ResourceIBMCdTektonPipelineMapToWorkerIdentity(model) + assert.Nil(t, err) + checkResult(result) +} diff --git a/ibm/service/cdtektonpipeline/resource_ibm_cd_tekton_pipeline_trigger.go b/ibm/service/cdtektonpipeline/resource_ibm_cd_tekton_pipeline_trigger.go index feb3f492c1..c3da6ccc31 100644 --- a/ibm/service/cdtektonpipeline/resource_ibm_cd_tekton_pipeline_trigger.go +++ b/ibm/service/cdtektonpipeline/resource_ibm_cd_tekton_pipeline_trigger.go @@ -1,6 +1,10 @@ // Copyright IBM Corp. 2024 All Rights Reserved. // Licensed under the Mozilla Public License v2.0 +/* + * IBM OpenAPI Terraform Generator Version: 3.95.2-120e65bc-20240924-152329 + */ + package cdtektonpipeline import ( @@ -56,16 +60,26 @@ func ResourceIBMCdTektonPipelineTrigger() *schema.Resource { "tags": &schema.Schema{ Type: schema.TypeList, Optional: true, - Description: "Trigger tags array.", + Description: "Optional trigger tags array.", Elem: &schema.Schema{Type: schema.TypeString}, }, "worker": &schema.Schema{ Type: schema.TypeList, MaxItems: 1, Optional: true, - Description: "Specify the worker used to run the trigger. Use `worker: { id: 'public' }` to use the IBM Managed workers. The default is to inherit the worker set in the pipeline settings, which can also be explicitly set using `worker: { id: 'inherit' }`.", + Description: "Details of the worker used to run the trigger.", Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ + "name": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Name of the worker. Computed based on the worker ID.", + }, + "type": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Type of the worker. Computed based on the worker ID.", + }, "id": &schema.Schema{ Type: schema.TypeString, Required: true, @@ -83,55 +97,19 @@ func ResourceIBMCdTektonPipelineTrigger() *schema.Resource { Type: schema.TypeBool, Optional: true, Default: true, - Description: "Flag to check if the trigger is enabled. If omitted the trigger is enabled by default.", + Description: "Flag to check if the trigger is enabled.", }, - "secret": &schema.Schema{ - Type: schema.TypeList, - MaxItems: 1, + "favorite": &schema.Schema{ + Type: schema.TypeBool, Optional: true, - Description: "Only needed for Generic Webhook trigger type. The secret is used to start the Generic Webhook trigger.", - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "type": &schema.Schema{ - Type: schema.TypeString, - Required: true, - Description: "Secret type.", - }, - "value": &schema.Schema{ - Type: schema.TypeString, - Optional: true, - DiffSuppressFunc: flex.SuppressGenericWebhookRawSecret, - Description: "Secret value, not needed if secret type is `internal_validation`.", - }, - "source": &schema.Schema{ - Type: schema.TypeString, - Optional: true, - Description: "Secret location, not needed if secret type is `internal_validation`.", - }, - "key_name": &schema.Schema{ - Type: schema.TypeString, - Optional: true, - Description: "Secret name, not needed if type is `internal_validation`.", - }, - "algorithm": &schema.Schema{ - Type: schema.TypeString, - Optional: true, - Description: "Algorithm used for `digest_matches` secret type. Only needed for `digest_matches` secret type.", - }, - }, - }, - }, - "cron": &schema.Schema{ - Type: schema.TypeString, - Optional: true, - ValidateFunc: validate.InvokeValidator("ibm_cd_tekton_pipeline_trigger", "cron"), - Description: "Only needed for timer triggers. CRON expression that indicates when this trigger will activate. Maximum frequency is every 5 minutes. The string is based on UNIX crontab syntax: minute, hour, day of month, month, day of week. Example: The CRON expression 0 *_/2 * * * - translates to - every 2 hours.", + Default: false, + Description: "Mark the trigger as a favorite.", }, - "timezone": &schema.Schema{ - Type: schema.TypeString, - Optional: true, - ValidateFunc: validate.InvokeValidator("ibm_cd_tekton_pipeline_trigger", "timezone"), - Description: "Only used for timer triggers. Specify the timezone used for this timer trigger, which will ensure the CRON activates this trigger relative to the specified timezone. If no timezone is specified, the default timezone used is UTC. Valid timezones are those listed in the IANA timezone database, https://www.iana.org/time-zones.", + "enable_events_from_forks": &schema.Schema{ + Type: schema.TypeBool, + Optional: true, + Default: false, + Description: "When enabled, pull request events from forks of the selected repository will trigger a pipeline run.", }, "source": &schema.Schema{ Type: schema.TypeList, @@ -169,6 +147,30 @@ func ResourceIBMCdTektonPipelineTrigger() *schema.Resource { Optional: true, Description: "The pattern of Git branch or tag. You can specify a glob pattern such as '!test' or '*master' to match against multiple tags or branches in the repository.The glob pattern used must conform to Bash 4.3 specifications, see bash documentation for more info: https://www.gnu.org/software/bash/manual/bash.html#Pattern-Matching. Only one of branch, pattern, or filter should be specified.", }, + "blind_connection": &schema.Schema{ + Type: schema.TypeBool, + Computed: true, + Description: "True if the repository server is not addressable on the public internet. IBM Cloud will not be able to validate the connection details you provide.", + }, + "hook_id": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Repository webhook ID. It is generated upon trigger creation.", + }, + "tool": &schema.Schema{ + Type: schema.TypeList, + Computed: true, + Description: "Reference to the repository tool in the parent toolchain.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "id": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "ID of the repository tool instance in the parent toolchain.", + }, + }, + }, + }, }, }, }, @@ -188,17 +190,53 @@ func ResourceIBMCdTektonPipelineTrigger() *schema.Resource { ValidateFunc: validate.InvokeValidator("ibm_cd_tekton_pipeline_trigger", "filter"), Description: "Either 'events' or 'filter' can be used. Stores the CEL (Common Expression Language) expression value which is used for event filtering against the Git webhook payloads.", }, - "favorite": &schema.Schema{ - Type: schema.TypeBool, - Optional: true, - Default: false, - Description: "Mark the trigger as a favorite.", + "cron": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + ValidateFunc: validate.InvokeValidator("ibm_cd_tekton_pipeline_trigger", "cron"), + Description: "Only needed for timer triggers. CRON expression that indicates when this trigger will activate. Maximum frequency is every 5 minutes. The string is based on UNIX crontab syntax: minute, hour, day of month, month, day of week. Example: The CRON expression 0 *_/2 * * * - translates to - every 2 hours.", }, - "enable_events_from_forks": &schema.Schema{ - Type: schema.TypeBool, + "timezone": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + ValidateFunc: validate.InvokeValidator("ibm_cd_tekton_pipeline_trigger", "timezone"), + Description: "Only used for timer triggers. Specify the timezone used for this timer trigger, which will ensure the CRON activates this trigger relative to the specified timezone. If no timezone is specified, the default timezone used is UTC. Valid timezones are those listed in the IANA timezone database, https://www.iana.org/time-zones.", + }, + "secret": &schema.Schema{ + Type: schema.TypeList, + MaxItems: 1, Optional: true, - Default: false, - Description: "Only used for SCM triggers. When enabled, pull request events from forks of the selected repository will trigger a pipeline run.", + Description: "Only needed for Generic Webhook trigger type. The secret is used to start the Generic Webhook trigger.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "type": &schema.Schema{ + Type: schema.TypeString, + Required: true, + Description: "Secret type.", + }, + "value": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + DiffSuppressFunc: flex.SuppressGenericWebhookRawSecret, + Description: "Secret value, not needed if secret type is `internal_validation`.", + }, + "source": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + Description: "Secret location, not needed if secret type is `internal_validation`.", + }, + "key_name": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + Description: "Secret name, not needed if type is `internal_validation`.", + }, + "algorithm": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + Description: "Algorithm used for `digest_matches` secret type. Only needed for `digest_matches` secret type.", + }, + }, + }, }, "href": &schema.Schema{ Type: schema.TypeString, @@ -213,41 +251,46 @@ func ResourceIBMCdTektonPipelineTrigger() *schema.Resource { Schema: map[string]*schema.Schema{ "name": &schema.Schema{ Type: schema.TypeString, - Required: true, + Computed: true, ForceNew: true, Description: "Property name.", }, "value": &schema.Schema{ Type: schema.TypeString, Optional: true, + Computed: true, DiffSuppressFunc: flex.SuppressTriggerPropertyRawSecret, Description: "Property value. Any string value is valid.", }, "href": &schema.Schema{ Type: schema.TypeString, + Optional: true, Computed: true, Description: "API URL for interacting with the trigger property.", }, "enum": &schema.Schema{ Type: schema.TypeList, Optional: true, + Computed: true, Description: "Options for `single_select` property type. Only needed for `single_select` property type.", Elem: &schema.Schema{Type: schema.TypeString}, }, "type": &schema.Schema{ Type: schema.TypeString, - Required: true, + Computed: true, ForceNew: true, Description: "Property type.", }, "path": &schema.Schema{ Type: schema.TypeString, Optional: true, + Computed: true, Description: "A dot notation path for `integration` type properties only, that selects a value from the tool integration. If left blank the full tool integration data will be used.", }, "locked": &schema.Schema{ Type: schema.TypeBool, Optional: true, + Computed: true, Description: "When true, this property cannot be overridden at runtime. Attempting to override it will result in run requests being rejected. The default is false.", }, }, @@ -304,6 +347,15 @@ func ResourceIBMCdTektonPipelineTriggerValidator() *validate.ResourceValidator { MinValueLength: 1, MaxValueLength: 253, }, + validate.ValidateSchema{ + Identifier: "filter", + ValidateFunctionIdentifier: validate.ValidateRegexpLen, + Type: validate.TypeString, + Optional: true, + Regexp: `^.*$`, + MinValueLength: 1, + MaxValueLength: 4096, + }, validate.ValidateSchema{ Identifier: "cron", ValidateFunctionIdentifier: validate.ValidateRegexpLen, @@ -322,15 +374,6 @@ func ResourceIBMCdTektonPipelineTriggerValidator() *validate.ResourceValidator { MinValueLength: 1, MaxValueLength: 253, }, - validate.ValidateSchema{ - Identifier: "filter", - ValidateFunctionIdentifier: validate.ValidateRegexpLen, - Type: validate.TypeString, - Optional: true, - Regexp: `^.*$`, - MinValueLength: 1, - MaxValueLength: 4096, - }, ) resourceValidator := validate.ResourceValidator{ResourceName: "ibm_cd_tekton_pipeline_trigger", Schema: validateSchema} @@ -340,7 +383,9 @@ func ResourceIBMCdTektonPipelineTriggerValidator() *validate.ResourceValidator { func resourceIBMCdTektonPipelineTriggerCreate(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { cdTektonPipelineClient, err := meta.(conns.ClientSession).CdTektonPipelineV2() if err != nil { - return diag.FromErr(err) + tfErr := flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline_trigger", "create", "initialize-client") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } createTektonPipelineTriggerOptions := &cdtektonpipelinev2.CreateTektonPipelineTriggerOptions{} @@ -350,16 +395,17 @@ func resourceIBMCdTektonPipelineTriggerCreate(context context.Context, d *schema createTektonPipelineTriggerOptions.SetName(d.Get("name").(string)) createTektonPipelineTriggerOptions.SetEventListener(d.Get("event_listener").(string)) if _, ok := d.GetOk("tags"); ok { - tags := []string{} - for _, tagsItem := range d.Get("tags").([]interface{}) { - tags = append(tags, tagsItem.(string)) + var tags []string + for _, v := range d.Get("tags").([]interface{}) { + tagsItem := v.(string) + tags = append(tags, tagsItem) } createTektonPipelineTriggerOptions.SetTags(tags) } if _, ok := d.GetOk("worker"); ok { - workerModel, err := resourceIBMCdTektonPipelineTriggerMapToWorkerIdentity(d.Get("worker.0").(map[string]interface{})) + workerModel, err := ResourceIBMCdTektonPipelineTriggerMapToWorkerIdentity(d.Get("worker.0").(map[string]interface{})) if err != nil { - return diag.FromErr(err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline_trigger", "create", "parse-worker").GetDiag() } createTektonPipelineTriggerOptions.SetWorker(workerModel) } @@ -370,9 +416,9 @@ func resourceIBMCdTektonPipelineTriggerCreate(context context.Context, d *schema createTektonPipelineTriggerOptions.SetEnabled(d.Get("enabled").(bool)) } if _, ok := d.GetOk("secret"); ok { - secretModel, err := resourceIBMCdTektonPipelineTriggerMapToGenericSecret(d.Get("secret.0").(map[string]interface{})) + secretModel, err := ResourceIBMCdTektonPipelineTriggerMapToGenericSecret(d.Get("secret.0").(map[string]interface{})) if err != nil { - return diag.FromErr(err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline_trigger", "create", "parse-secret").GetDiag() } createTektonPipelineTriggerOptions.SetSecret(secretModel) } @@ -383,9 +429,9 @@ func resourceIBMCdTektonPipelineTriggerCreate(context context.Context, d *schema createTektonPipelineTriggerOptions.SetTimezone(d.Get("timezone").(string)) } if _, ok := d.GetOk("source"); ok { - sourceModel, err := resourceIBMCdTektonPipelineTriggerMapToTriggerSourcePrototype(d.Get("source.0").(map[string]interface{})) + sourceModel, err := ResourceIBMCdTektonPipelineTriggerMapToTriggerSourcePrototype(d.Get("source.0").(map[string]interface{})) if err != nil { - return diag.FromErr(err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline_trigger", "create", "parse-source").GetDiag() } createTektonPipelineTriggerOptions.SetSource(sourceModel) } @@ -408,10 +454,11 @@ func resourceIBMCdTektonPipelineTriggerCreate(context context.Context, d *schema createTektonPipelineTriggerOptions.SetEnableEventsFromForks(d.Get("enable_events_from_forks").(bool)) } - triggerIntf, response, err := cdTektonPipelineClient.CreateTektonPipelineTriggerWithContext(context, createTektonPipelineTriggerOptions) + triggerIntf, _, err := cdTektonPipelineClient.CreateTektonPipelineTriggerWithContext(context, createTektonPipelineTriggerOptions) if err != nil { - log.Printf("[DEBUG] CreateTektonPipelineTriggerWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("CreateTektonPipelineTriggerWithContext failed %s\n%s", err, response)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("CreateTektonPipelineTriggerWithContext failed: %s", err.Error()), "ibm_cd_tekton_pipeline_trigger", "create") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } trigger := triggerIntf.(*cdtektonpipelinev2.Trigger) @@ -423,14 +470,16 @@ func resourceIBMCdTektonPipelineTriggerCreate(context context.Context, d *schema func resourceIBMCdTektonPipelineTriggerRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { cdTektonPipelineClient, err := meta.(conns.ClientSession).CdTektonPipelineV2() if err != nil { - return diag.FromErr(err) + tfErr := flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline_trigger", "read", "initialize-client") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } getTektonPipelineTriggerOptions := &cdtektonpipelinev2.GetTektonPipelineTriggerOptions{} parts, err := flex.SepIdParts(d.Id(), "/") if err != nil { - return diag.FromErr(err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline_trigger", "read", "sep-id-parts").GetDiag() } getTektonPipelineTriggerOptions.SetPipelineID(parts[0]) @@ -442,121 +491,138 @@ func resourceIBMCdTektonPipelineTriggerRead(context context.Context, d *schema.R d.SetId("") return nil } - log.Printf("[DEBUG] GetTektonPipelineTriggerWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("GetTektonPipelineTriggerWithContext failed %s\n%s", err, response)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("GetTektonPipelineTriggerWithContext failed: %s", err.Error()), "ibm_cd_tekton_pipeline_trigger", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } trigger := triggerIntf.(*cdtektonpipelinev2.Trigger) - if err = d.Set("pipeline_id", getTektonPipelineTriggerOptions.PipelineID); err != nil { - return diag.FromErr(fmt.Errorf("Error setting pipeline_id: %s", err)) - } if err = d.Set("type", trigger.Type); err != nil { - return diag.FromErr(fmt.Errorf("Error setting type: %s", err)) + err = fmt.Errorf("Error setting type: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline_trigger", "read", "set-type").GetDiag() } if err = d.Set("name", trigger.Name); err != nil { - return diag.FromErr(fmt.Errorf("Error setting name: %s", err)) + err = fmt.Errorf("Error setting name: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline_trigger", "read", "set-name").GetDiag() } if err = d.Set("event_listener", trigger.EventListener); err != nil { - return diag.FromErr(fmt.Errorf("Error setting event_listener: %s", err)) + err = fmt.Errorf("Error setting event_listener: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline_trigger", "read", "set-event_listener").GetDiag() } if !core.IsNil(trigger.Tags) { if err = d.Set("tags", trigger.Tags); err != nil { - return diag.FromErr(fmt.Errorf("Error setting tags: %s", err)) + err = fmt.Errorf("Error setting tags: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline_trigger", "read", "set-tags").GetDiag() } } if !core.IsNil(trigger.Worker) { - workerMap, err := resourceIBMCdTektonPipelineTriggerWorkerIdentityToMap(trigger.Worker) + workerMap, err := ResourceIBMCdTektonPipelineTriggerWorkerToMap(trigger.Worker) if err != nil { - return diag.FromErr(err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline_trigger", "read", "worker-to-map").GetDiag() } if err = d.Set("worker", []map[string]interface{}{workerMap}); err != nil { - return diag.FromErr(fmt.Errorf("Error setting worker: %s", err)) + err = fmt.Errorf("Error setting worker: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline_trigger", "read", "set-worker").GetDiag() } } if !core.IsNil(trigger.MaxConcurrentRuns) { if err = d.Set("max_concurrent_runs", flex.IntValue(trigger.MaxConcurrentRuns)); err != nil { - return diag.FromErr(fmt.Errorf("Error setting max_concurrent_runs: %s", err)) + err = fmt.Errorf("Error setting max_concurrent_runs: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline_trigger", "read", "set-max_concurrent_runs").GetDiag() } } if !core.IsNil(trigger.Enabled) { if err = d.Set("enabled", trigger.Enabled); err != nil { - return diag.FromErr(fmt.Errorf("Error setting enabled: %s", err)) - } - } - if !core.IsNil(trigger.Secret) { - secretMap, err := resourceIBMCdTektonPipelineTriggerGenericSecretToMap(trigger.Secret) - if err != nil { - return diag.FromErr(err) - } - if err = d.Set("secret", []map[string]interface{}{secretMap}); err != nil { - return diag.FromErr(fmt.Errorf("Error setting secret: %s", err)) + err = fmt.Errorf("Error setting enabled: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline_trigger", "read", "set-enabled").GetDiag() } } - if !core.IsNil(trigger.Cron) { - if err = d.Set("cron", trigger.Cron); err != nil { - return diag.FromErr(fmt.Errorf("Error setting cron: %s", err)) + if !core.IsNil(trigger.Favorite) { + if err = d.Set("favorite", trigger.Favorite); err != nil { + err = fmt.Errorf("Error setting favorite: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline_trigger", "read", "set-favorite").GetDiag() } } - if !core.IsNil(trigger.Timezone) { - if err = d.Set("timezone", trigger.Timezone); err != nil { - return diag.FromErr(fmt.Errorf("Error setting timezone: %s", err)) + if !core.IsNil(trigger.EnableEventsFromForks) { + if err = d.Set("enable_events_from_forks", trigger.EnableEventsFromForks); err != nil { + err = fmt.Errorf("Error setting enable_events_from_forks: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline_trigger", "read", "set-enable_events_from_forks").GetDiag() } } if !core.IsNil(trigger.Source) { - sourceMap, err := resourceIBMCdTektonPipelineTriggerTriggerSourcePrototypeToMap(trigger.Source) + sourceMap, err := ResourceIBMCdTektonPipelineTriggerTriggerSourceToMap(trigger.Source) if err != nil { - return diag.FromErr(err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline_trigger", "read", "source-to-map").GetDiag() } if err = d.Set("source", []map[string]interface{}{sourceMap}); err != nil { - return diag.FromErr(fmt.Errorf("Error setting source: %s", err)) + err = fmt.Errorf("Error setting source: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline_trigger", "read", "set-source").GetDiag() } } if !core.IsNil(trigger.Events) { if err = d.Set("events", trigger.Events); err != nil { - return diag.FromErr(fmt.Errorf("Error setting events: %s", err)) + err = fmt.Errorf("Error setting events: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline_trigger", "read", "set-events").GetDiag() } } if !core.IsNil(trigger.Filter) { if err = d.Set("filter", trigger.Filter); err != nil { - return diag.FromErr(fmt.Errorf("Error setting filter: %s", err)) + err = fmt.Errorf("Error setting filter: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline_trigger", "read", "set-filter").GetDiag() } } - if !core.IsNil(trigger.Favorite) { - if err = d.Set("favorite", trigger.Favorite); err != nil { - return diag.FromErr(fmt.Errorf("Error setting favorite: %s", err)) + if !core.IsNil(trigger.Cron) { + if err = d.Set("cron", trigger.Cron); err != nil { + err = fmt.Errorf("Error setting cron: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline_trigger", "read", "set-cron").GetDiag() } } - if !core.IsNil(trigger.EnableEventsFromForks) { - if err = d.Set("enable_events_from_forks", trigger.EnableEventsFromForks); err != nil { - return diag.FromErr(fmt.Errorf("Error setting enable_events_from_forks: %s", err)) + if !core.IsNil(trigger.Timezone) { + if err = d.Set("timezone", trigger.Timezone); err != nil { + err = fmt.Errorf("Error setting timezone: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline_trigger", "read", "set-timezone").GetDiag() + } + } + if !core.IsNil(trigger.Secret) { + secretMap, err := ResourceIBMCdTektonPipelineTriggerGenericSecretToMap(trigger.Secret) + if err != nil { + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline_trigger", "read", "secret-to-map").GetDiag() + } + if err = d.Set("secret", []map[string]interface{}{secretMap}); err != nil { + err = fmt.Errorf("Error setting secret: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline_trigger", "read", "set-secret").GetDiag() } } if !core.IsNil(trigger.Href) { if err = d.Set("href", trigger.Href); err != nil { - return diag.FromErr(fmt.Errorf("Error setting href: %s", err)) + err = fmt.Errorf("Error setting href: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline_trigger", "read", "set-href").GetDiag() } } if !core.IsNil(trigger.Properties) { properties := []map[string]interface{}{} for _, propertiesItem := range trigger.Properties { - propertiesItemMap, err := resourceIBMCdTektonPipelineTriggerTriggerPropertyToMap(&propertiesItem) + propertiesItemMap, err := ResourceIBMCdTektonPipelineTriggerTriggerPropertyToMap(&propertiesItem) // #nosec G601 if err != nil { - return diag.FromErr(err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline_trigger", "read", "properties-to-map").GetDiag() } properties = append(properties, propertiesItemMap) } if err = d.Set("properties", properties); err != nil { - return diag.FromErr(fmt.Errorf("Error setting properties: %s", err)) + err = fmt.Errorf("Error setting properties: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline_trigger", "read", "set-properties").GetDiag() } } if !core.IsNil(trigger.WebhookURL) { if err = d.Set("webhook_url", trigger.WebhookURL); err != nil { - return diag.FromErr(fmt.Errorf("Error setting webhook_url: %s", err)) + err = fmt.Errorf("Error setting webhook_url: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline_trigger", "read", "set-webhook_url").GetDiag() } } if !core.IsNil(trigger.ID) { if err = d.Set("trigger_id", trigger.ID); err != nil { - return diag.FromErr(fmt.Errorf("Error setting trigger_id: %s", err)) + err = fmt.Errorf("Error setting trigger_id: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline_trigger", "read", "set-trigger_id").GetDiag() } } @@ -566,14 +632,16 @@ func resourceIBMCdTektonPipelineTriggerRead(context context.Context, d *schema.R func resourceIBMCdTektonPipelineTriggerUpdate(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { cdTektonPipelineClient, err := meta.(conns.ClientSession).CdTektonPipelineV2() if err != nil { - return diag.FromErr(err) + tfErr := flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline_trigger", "update", "initialize-client") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } updateTektonPipelineTriggerOptions := &cdtektonpipelinev2.UpdateTektonPipelineTriggerOptions{} parts, err := flex.SepIdParts(d.Id(), "/") if err != nil { - return diag.FromErr(err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline_trigger", "update", "sep-id-parts").GetDiag() } updateTektonPipelineTriggerOptions.SetPipelineID(parts[0]) @@ -583,30 +651,38 @@ func resourceIBMCdTektonPipelineTriggerUpdate(context context.Context, d *schema patchVals := &cdtektonpipelinev2.TriggerPatch{} if d.HasChange("pipeline_id") { - return diag.FromErr(fmt.Errorf("Cannot update resource property \"%s\" with the ForceNew annotation."+ - " The resource must be re-created to update this property.", "pipeline_id")) + errMsg := fmt.Sprintf("Cannot update resource property \"%s\" with the ForceNew annotation."+ + " The resource must be re-created to update this property.", "pipeline_id") + return flex.DiscriminatedTerraformErrorf(nil, errMsg, "ibm_cd_tekton_pipeline_trigger", "update", "pipeline_id-forces-new").GetDiag() } - if d.HasChange("type") || d.HasChange("name") || d.HasChange("event_listener") { + if d.HasChange("type") { newType := d.Get("type").(string) patchVals.Type = &newType + hasChange = true + } + if d.HasChange("name") { newName := d.Get("name").(string) patchVals.Name = &newName + hasChange = true + } + if d.HasChange("event_listener") { newEventListener := d.Get("event_listener").(string) patchVals.EventListener = &newEventListener hasChange = true } if d.HasChange("tags") { - tags := []string{} - for _, tagsItem := range d.Get("tags").([]interface{}) { - tags = append(tags, tagsItem.(string)) + var tags []string + for _, v := range d.Get("tags").([]interface{}) { + tagsItem := v.(string) + tags = append(tags, tagsItem) } patchVals.Tags = tags hasChange = true } if d.HasChange("worker") { - worker, err := resourceIBMCdTektonPipelineTriggerMapToWorkerIdentity(d.Get("worker.0").(map[string]interface{})) + worker, err := ResourceIBMCdTektonPipelineTriggerMapToWorkerIdentity(d.Get("worker.0").(map[string]interface{})) if err != nil { - return diag.FromErr(err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline_trigger", "update", "parse-worker").GetDiag() } patchVals.Worker = worker hasChange = true @@ -622,9 +698,9 @@ func resourceIBMCdTektonPipelineTriggerUpdate(context context.Context, d *schema hasChange = true } if d.HasChange("secret") { - secret, err := resourceIBMCdTektonPipelineTriggerMapToGenericSecret(d.Get("secret.0").(map[string]interface{})) + secret, err := ResourceIBMCdTektonPipelineTriggerMapToGenericSecret(d.Get("secret.0").(map[string]interface{})) if err != nil { - return diag.FromErr(err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline_trigger", "update", "parse-secret").GetDiag() } patchVals.Secret = secret hasChange = true @@ -640,9 +716,9 @@ func resourceIBMCdTektonPipelineTriggerUpdate(context context.Context, d *schema hasChange = true } if d.HasChange("source") { - source, err := resourceIBMCdTektonPipelineTriggerMapToTriggerSourcePrototype(d.Get("source.0").(map[string]interface{})) + source, err := ResourceIBMCdTektonPipelineTriggerMapToTriggerSourcePrototype(d.Get("source.0").(map[string]interface{})) if err != nil { - return diag.FromErr(err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline_trigger", "update", "parse-source").GetDiag() } patchVals.Source = source hasChange = true @@ -675,11 +751,16 @@ func resourceIBMCdTektonPipelineTriggerUpdate(context context.Context, d *schema } if hasChange { - updateTektonPipelineTriggerOptions.TriggerPatch, _ = patchVals.AsPatch() - _, response, err := cdTektonPipelineClient.UpdateTektonPipelineTriggerWithContext(context, updateTektonPipelineTriggerOptions) + // Fields with `nil` values are omitted from the generic map, + // so we need to re-add them to support removing arguments + // in merge-patch operations sent to the service. + updateTektonPipelineTriggerOptions.TriggerPatch = ResourceIBMCdTektonPipelineTriggerTriggerPatchAsPatch(patchVals, d) + + _, _, err = cdTektonPipelineClient.UpdateTektonPipelineTriggerWithContext(context, updateTektonPipelineTriggerOptions) if err != nil { - log.Printf("[DEBUG] UpdateTektonPipelineTriggerWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("UpdateTektonPipelineTriggerWithContext failed %s\n%s", err, response)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("UpdateTektonPipelineTriggerWithContext failed: %s", err.Error()), "ibm_cd_tekton_pipeline_trigger", "update") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } @@ -689,23 +770,26 @@ func resourceIBMCdTektonPipelineTriggerUpdate(context context.Context, d *schema func resourceIBMCdTektonPipelineTriggerDelete(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { cdTektonPipelineClient, err := meta.(conns.ClientSession).CdTektonPipelineV2() if err != nil { - return diag.FromErr(err) + tfErr := flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline_trigger", "delete", "initialize-client") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } deleteTektonPipelineTriggerOptions := &cdtektonpipelinev2.DeleteTektonPipelineTriggerOptions{} parts, err := flex.SepIdParts(d.Id(), "/") if err != nil { - return diag.FromErr(err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline_trigger", "delete", "sep-id-parts").GetDiag() } deleteTektonPipelineTriggerOptions.SetPipelineID(parts[0]) deleteTektonPipelineTriggerOptions.SetTriggerID(parts[1]) - response, err := cdTektonPipelineClient.DeleteTektonPipelineTriggerWithContext(context, deleteTektonPipelineTriggerOptions) + _, err = cdTektonPipelineClient.DeleteTektonPipelineTriggerWithContext(context, deleteTektonPipelineTriggerOptions) if err != nil { - log.Printf("[DEBUG] DeleteTektonPipelineTriggerWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("DeleteTektonPipelineTriggerWithContext failed %s\n%s", err, response)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("DeleteTektonPipelineTriggerWithContext failed: %s", err.Error()), "ibm_cd_tekton_pipeline_trigger", "delete") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } d.SetId("") @@ -713,13 +797,13 @@ func resourceIBMCdTektonPipelineTriggerDelete(context context.Context, d *schema return nil } -func resourceIBMCdTektonPipelineTriggerMapToWorkerIdentity(modelMap map[string]interface{}) (*cdtektonpipelinev2.WorkerIdentity, error) { +func ResourceIBMCdTektonPipelineTriggerMapToWorkerIdentity(modelMap map[string]interface{}) (*cdtektonpipelinev2.WorkerIdentity, error) { model := &cdtektonpipelinev2.WorkerIdentity{} model.ID = core.StringPtr(modelMap["id"].(string)) return model, nil } -func resourceIBMCdTektonPipelineTriggerMapToGenericSecret(modelMap map[string]interface{}) (*cdtektonpipelinev2.GenericSecret, error) { +func ResourceIBMCdTektonPipelineTriggerMapToGenericSecret(modelMap map[string]interface{}) (*cdtektonpipelinev2.GenericSecret, error) { model := &cdtektonpipelinev2.GenericSecret{} if modelMap["type"] != nil && modelMap["type"].(string) != "" { model.Type = core.StringPtr(modelMap["type"].(string)) @@ -739,10 +823,10 @@ func resourceIBMCdTektonPipelineTriggerMapToGenericSecret(modelMap map[string]in return model, nil } -func resourceIBMCdTektonPipelineTriggerMapToTriggerSourcePrototype(modelMap map[string]interface{}) (*cdtektonpipelinev2.TriggerSourcePrototype, error) { +func ResourceIBMCdTektonPipelineTriggerMapToTriggerSourcePrototype(modelMap map[string]interface{}) (*cdtektonpipelinev2.TriggerSourcePrototype, error) { model := &cdtektonpipelinev2.TriggerSourcePrototype{} model.Type = core.StringPtr(modelMap["type"].(string)) - PropertiesModel, err := resourceIBMCdTektonPipelineTriggerMapToTriggerSourcePropertiesPrototype(modelMap["properties"].([]interface{})[0].(map[string]interface{})) + PropertiesModel, err := ResourceIBMCdTektonPipelineTriggerMapToTriggerSourcePropertiesPrototype(modelMap["properties"].([]interface{})[0].(map[string]interface{})) if err != nil { return model, err } @@ -750,7 +834,7 @@ func resourceIBMCdTektonPipelineTriggerMapToTriggerSourcePrototype(modelMap map[ return model, nil } -func resourceIBMCdTektonPipelineTriggerMapToTriggerSourcePropertiesPrototype(modelMap map[string]interface{}) (*cdtektonpipelinev2.TriggerSourcePropertiesPrototype, error) { +func ResourceIBMCdTektonPipelineTriggerMapToTriggerSourcePropertiesPrototype(modelMap map[string]interface{}) (*cdtektonpipelinev2.TriggerSourcePropertiesPrototype, error) { model := &cdtektonpipelinev2.TriggerSourcePropertiesPrototype{} model.URL = core.StringPtr(modelMap["url"].(string)) if modelMap["branch"] != nil && modelMap["branch"].(string) != "" { @@ -762,73 +846,189 @@ func resourceIBMCdTektonPipelineTriggerMapToTriggerSourcePropertiesPrototype(mod return model, nil } -func resourceIBMCdTektonPipelineTriggerWorkerIdentityToMap(model *cdtektonpipelinev2.Worker) (map[string]interface{}, error) { +func ResourceIBMCdTektonPipelineTriggerWorkerToMap(model *cdtektonpipelinev2.Worker) (map[string]interface{}, error) { modelMap := make(map[string]interface{}) - modelMap["id"] = model.ID + if model.Name != nil { + modelMap["name"] = *model.Name + } + if model.Type != nil { + modelMap["type"] = *model.Type + } + modelMap["id"] = *model.ID return modelMap, nil } -func resourceIBMCdTektonPipelineTriggerGenericSecretToMap(model *cdtektonpipelinev2.GenericSecret) (map[string]interface{}, error) { +func ResourceIBMCdTektonPipelineTriggerTriggerSourceToMap(model *cdtektonpipelinev2.TriggerSource) (map[string]interface{}, error) { modelMap := make(map[string]interface{}) - if model.Type != nil { - modelMap["type"] = model.Type + modelMap["type"] = *model.Type + propertiesMap, err := ResourceIBMCdTektonPipelineTriggerTriggerSourcePropertiesToMap(model.Properties) + if err != nil { + return modelMap, err } - if model.Value != nil { - modelMap["value"] = model.Value + modelMap["properties"] = []map[string]interface{}{propertiesMap} + return modelMap, nil +} + +func ResourceIBMCdTektonPipelineTriggerTriggerSourcePropertiesToMap(model *cdtektonpipelinev2.TriggerSourceProperties) (map[string]interface{}, error) { + modelMap := make(map[string]interface{}) + modelMap["url"] = *model.URL + if model.Branch != nil { + modelMap["branch"] = *model.Branch } - if model.Source != nil { - modelMap["source"] = model.Source + if model.Pattern != nil { + modelMap["pattern"] = *model.Pattern } - if model.KeyName != nil { - modelMap["key_name"] = model.KeyName + modelMap["blind_connection"] = *model.BlindConnection + if model.HookID != nil { + modelMap["hook_id"] = *model.HookID } - if model.Algorithm != nil { - modelMap["algorithm"] = model.Algorithm + toolMap, err := ResourceIBMCdTektonPipelineTriggerToolToMap(model.Tool) + if err != nil { + return modelMap, err } + modelMap["tool"] = []map[string]interface{}{toolMap} return modelMap, nil } -func resourceIBMCdTektonPipelineTriggerTriggerSourcePrototypeToMap(model *cdtektonpipelinev2.TriggerSource) (map[string]interface{}, error) { +func ResourceIBMCdTektonPipelineTriggerToolToMap(model *cdtektonpipelinev2.Tool) (map[string]interface{}, error) { modelMap := make(map[string]interface{}) - modelMap["type"] = model.Type - propertiesMap, err := resourceIBMCdTektonPipelineTriggerTriggerSourcePropertiesPrototypeToMap(model.Properties) - if err != nil { - return modelMap, err - } - modelMap["properties"] = []map[string]interface{}{propertiesMap} + modelMap["id"] = *model.ID return modelMap, nil } -func resourceIBMCdTektonPipelineTriggerTriggerSourcePropertiesPrototypeToMap(model *cdtektonpipelinev2.TriggerSourceProperties) (map[string]interface{}, error) { +func ResourceIBMCdTektonPipelineTriggerGenericSecretToMap(model *cdtektonpipelinev2.GenericSecret) (map[string]interface{}, error) { modelMap := make(map[string]interface{}) - modelMap["url"] = model.URL - if model.Branch != nil { - modelMap["branch"] = model.Branch + if model.Type != nil { + modelMap["type"] = *model.Type } - if model.Pattern != nil { - modelMap["pattern"] = model.Pattern + if model.Value != nil { + modelMap["value"] = *model.Value + } + if model.Source != nil { + modelMap["source"] = *model.Source + } + if model.KeyName != nil { + modelMap["key_name"] = *model.KeyName + } + if model.Algorithm != nil { + modelMap["algorithm"] = *model.Algorithm } return modelMap, nil } -func resourceIBMCdTektonPipelineTriggerTriggerPropertyToMap(model *cdtektonpipelinev2.TriggerProperty) (map[string]interface{}, error) { +func ResourceIBMCdTektonPipelineTriggerTriggerPropertyToMap(model *cdtektonpipelinev2.TriggerProperty) (map[string]interface{}, error) { modelMap := make(map[string]interface{}) - modelMap["name"] = model.Name + modelMap["name"] = *model.Name if model.Value != nil { - modelMap["value"] = model.Value + modelMap["value"] = *model.Value } if model.Href != nil { - modelMap["href"] = model.Href + modelMap["href"] = *model.Href } if model.Enum != nil { modelMap["enum"] = model.Enum } - modelMap["type"] = model.Type + modelMap["type"] = *model.Type if model.Path != nil { - modelMap["path"] = model.Path + modelMap["path"] = *model.Path } if model.Locked != nil { - modelMap["locked"] = model.Locked + modelMap["locked"] = *model.Locked } return modelMap, nil } + +func ResourceIBMCdTektonPipelineTriggerTriggerPatchAsPatch(patchVals *cdtektonpipelinev2.TriggerPatch, d *schema.ResourceData) map[string]interface{} { + patch, _ := patchVals.AsPatch() + var path string + + path = "type" + if _, exists := d.GetOk(path); d.HasChange(path) && !exists { + patch["type"] = nil + } + path = "name" + if _, exists := d.GetOk(path); d.HasChange(path) && !exists { + patch["name"] = nil + } + path = "event_listener" + if _, exists := d.GetOk(path); d.HasChange(path) && !exists { + patch["event_listener"] = nil + } + path = "tags" + if _, exists := d.GetOk(path); d.HasChange(path) && !exists { + patch["tags"] = nil + } + path = "worker" + if _, exists := d.GetOk(path); d.HasChange(path) && !exists { + patch["worker"] = nil + } + path = "max_concurrent_runs" + if _, exists := d.GetOk(path); d.HasChange(path) && !exists { + patch["max_concurrent_runs"] = nil + } + path = "enabled" + if _, exists := d.GetOk(path); d.HasChange(path) && !exists { + patch["enabled"] = nil + } + path = "secret" + if _, exists := d.GetOk(path); d.HasChange(path) && !exists { + patch["secret"] = nil + } else if exists && patch["secret"] != nil { + ResourceIBMCdTektonPipelineTriggerGenericSecretAsPatch(patch["secret"].(map[string]interface{}), d) + } + path = "cron" + if _, exists := d.GetOk(path); d.HasChange(path) && !exists { + patch["cron"] = nil + } + path = "timezone" + if _, exists := d.GetOk(path); d.HasChange(path) && !exists { + patch["timezone"] = nil + } + path = "source" + if _, exists := d.GetOk(path); d.HasChange(path) && !exists { + patch["source"] = nil + } + path = "events" + if _, exists := d.GetOk(path); d.HasChange(path) && !exists { + patch["events"] = nil + } + path = "filter" + if _, exists := d.GetOk(path); d.HasChange(path) && !exists { + patch["filter"] = nil + } + path = "favorite" + if _, exists := d.GetOk(path); d.HasChange(path) && !exists { + patch["favorite"] = nil + } + path = "enable_events_from_forks" + if _, exists := d.GetOkExists(path); d.HasChange(path) && !exists { + patch["enable_events_from_forks"] = nil + } + + return patch +} + +func ResourceIBMCdTektonPipelineTriggerGenericSecretAsPatch(patch map[string]interface{}, d *schema.ResourceData) { + var path string + + path = "secret.0.type" + if _, exists := d.GetOk(path); d.HasChange(path) && !exists { + patch["type"] = nil + } + path = "secret.0.value" + if _, exists := d.GetOk(path); d.HasChange(path) && !exists { + patch["value"] = nil + } + path = "secret.0.source" + if _, exists := d.GetOk(path); d.HasChange(path) && !exists { + patch["source"] = nil + } + path = "secret.0.key_name" + if _, exists := d.GetOk(path); d.HasChange(path) && !exists { + patch["key_name"] = nil + } + path = "secret.0.algorithm" + if _, exists := d.GetOk(path); d.HasChange(path) && !exists { + patch["algorithm"] = nil + } +} diff --git a/ibm/service/cdtektonpipeline/resource_ibm_cd_tekton_pipeline_trigger_property.go b/ibm/service/cdtektonpipeline/resource_ibm_cd_tekton_pipeline_trigger_property.go index 871b7e30a1..46e8a6641e 100644 --- a/ibm/service/cdtektonpipeline/resource_ibm_cd_tekton_pipeline_trigger_property.go +++ b/ibm/service/cdtektonpipeline/resource_ibm_cd_tekton_pipeline_trigger_property.go @@ -1,6 +1,10 @@ // Copyright IBM Corp. 2024 All Rights Reserved. // Licensed under the Mozilla Public License v2.0 +/* + * IBM OpenAPI Terraform Generator Version: 3.95.2-120e65bc-20240924-152329 + */ + package cdtektonpipeline import ( @@ -48,13 +52,6 @@ func ResourceIBMCdTektonPipelineTriggerProperty() *schema.Resource { ValidateFunc: validate.InvokeValidator("ibm_cd_tekton_pipeline_trigger_property", "name"), Description: "Property name.", }, - "type": &schema.Schema{ - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: validate.InvokeValidator("ibm_cd_tekton_pipeline_trigger_property", "type"), - Description: "Property type.", - }, "value": &schema.Schema{ Type: schema.TypeString, Optional: true, @@ -68,11 +65,18 @@ func ResourceIBMCdTektonPipelineTriggerProperty() *schema.Resource { Description: "Options for `single_select` property type. Only needed for `single_select` property type.", Elem: &schema.Schema{Type: schema.TypeString}, }, + "type": &schema.Schema{ + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validate.InvokeValidator("ibm_cd_tekton_pipeline_trigger_property", "type"), + Description: "Property type.", + }, "path": &schema.Schema{ Type: schema.TypeString, Optional: true, ValidateFunc: validate.InvokeValidator("ibm_cd_tekton_pipeline_trigger_property", "path"), - Description: "A dot notation path for `integration` type properties only, to select a value from the tool integration. If left blank the full tool integration data will be used.", + Description: "A dot notation path for `integration` type properties only, that selects a value from the tool integration. If left blank the full tool integration data will be used.", }, "locked": &schema.Schema{ Type: schema.TypeBool, @@ -119,13 +123,6 @@ func ResourceIBMCdTektonPipelineTriggerPropertyValidator() *validate.ResourceVal MinValueLength: 1, MaxValueLength: 253, }, - validate.ValidateSchema{ - Identifier: "type", - ValidateFunctionIdentifier: validate.ValidateAllowedStringValue, - Type: validate.TypeString, - Required: true, - AllowedValues: "appconfig, integration, secure, single_select, text", - }, validate.ValidateSchema{ Identifier: "value", ValidateFunctionIdentifier: validate.ValidateRegexpLen, @@ -135,6 +132,13 @@ func ResourceIBMCdTektonPipelineTriggerPropertyValidator() *validate.ResourceVal MinValueLength: 0, MaxValueLength: 4096, }, + validate.ValidateSchema{ + Identifier: "type", + ValidateFunctionIdentifier: validate.ValidateAllowedStringValue, + Type: validate.TypeString, + Required: true, + AllowedValues: "appconfig, integration, secure, single_select, text", + }, validate.ValidateSchema{ Identifier: "path", ValidateFunctionIdentifier: validate.ValidateRegexpLen, @@ -153,7 +157,9 @@ func ResourceIBMCdTektonPipelineTriggerPropertyValidator() *validate.ResourceVal func resourceIBMCdTektonPipelineTriggerPropertyCreate(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { cdTektonPipelineClient, err := meta.(conns.ClientSession).CdTektonPipelineV2() if err != nil { - return diag.FromErr(err) + tfErr := flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline_trigger_property", "create", "initialize-client") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } createTektonPipelineTriggerPropertiesOptions := &cdtektonpipelinev2.CreateTektonPipelineTriggerPropertiesOptions{} @@ -180,10 +186,11 @@ func resourceIBMCdTektonPipelineTriggerPropertyCreate(context context.Context, d createTektonPipelineTriggerPropertiesOptions.SetLocked(d.Get("locked").(bool)) } - triggerProperty, response, err := cdTektonPipelineClient.CreateTektonPipelineTriggerPropertiesWithContext(context, createTektonPipelineTriggerPropertiesOptions) + triggerProperty, _, err := cdTektonPipelineClient.CreateTektonPipelineTriggerPropertiesWithContext(context, createTektonPipelineTriggerPropertiesOptions) if err != nil { - log.Printf("[DEBUG] CreateTektonPipelineTriggerPropertiesWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("CreateTektonPipelineTriggerPropertiesWithContext failed %s\n%s", err, response)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("CreateTektonPipelineTriggerPropertiesWithContext failed: %s", err.Error()), "ibm_cd_tekton_pipeline_trigger_property", "create") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } d.SetId(fmt.Sprintf("%s/%s/%s", *createTektonPipelineTriggerPropertiesOptions.PipelineID, *createTektonPipelineTriggerPropertiesOptions.TriggerID, *triggerProperty.Name)) @@ -194,14 +201,16 @@ func resourceIBMCdTektonPipelineTriggerPropertyCreate(context context.Context, d func resourceIBMCdTektonPipelineTriggerPropertyRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { cdTektonPipelineClient, err := meta.(conns.ClientSession).CdTektonPipelineV2() if err != nil { - return diag.FromErr(err) + tfErr := flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline_trigger_property", "read", "initialize-client") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } getTektonPipelineTriggerPropertyOptions := &cdtektonpipelinev2.GetTektonPipelineTriggerPropertyOptions{} parts, err := flex.SepIdParts(d.Id(), "/") if err != nil { - return diag.FromErr(err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline_trigger_property", "read", "sep-id-parts").GetDiag() } getTektonPipelineTriggerPropertyOptions.SetPipelineID(parts[0]) @@ -214,45 +223,47 @@ func resourceIBMCdTektonPipelineTriggerPropertyRead(context context.Context, d * d.SetId("") return nil } - log.Printf("[DEBUG] GetTektonPipelineTriggerPropertyWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("GetTektonPipelineTriggerPropertyWithContext failed %s\n%s", err, response)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("GetTektonPipelineTriggerPropertyWithContext failed: %s", err.Error()), "ibm_cd_tekton_pipeline_trigger_property", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } - if err = d.Set("pipeline_id", getTektonPipelineTriggerPropertyOptions.PipelineID); err != nil { - return diag.FromErr(fmt.Errorf("Error setting pipeline_id: %s", err)) - } - if err = d.Set("trigger_id", getTektonPipelineTriggerPropertyOptions.TriggerID); err != nil { - return diag.FromErr(fmt.Errorf("Error setting trigger_id: %s", err)) - } if err = d.Set("name", triggerProperty.Name); err != nil { - return diag.FromErr(fmt.Errorf("Error setting name: %s", err)) - } - if err = d.Set("type", triggerProperty.Type); err != nil { - return diag.FromErr(fmt.Errorf("Error setting type: %s", err)) + err = fmt.Errorf("Error setting name: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline_trigger_property", "read", "set-name").GetDiag() } if !core.IsNil(triggerProperty.Value) { if err = d.Set("value", triggerProperty.Value); err != nil { - return diag.FromErr(fmt.Errorf("Error setting value: %s", err)) + err = fmt.Errorf("Error setting value: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline_trigger_property", "read", "set-value").GetDiag() } } if !core.IsNil(triggerProperty.Enum) { if err = d.Set("enum", triggerProperty.Enum); err != nil { - return diag.FromErr(fmt.Errorf("Error setting enum: %s", err)) + err = fmt.Errorf("Error setting enum: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline_trigger_property", "read", "set-enum").GetDiag() } } + if err = d.Set("type", triggerProperty.Type); err != nil { + err = fmt.Errorf("Error setting type: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline_trigger_property", "read", "set-type").GetDiag() + } if !core.IsNil(triggerProperty.Path) { if err = d.Set("path", triggerProperty.Path); err != nil { - return diag.FromErr(fmt.Errorf("Error setting path: %s", err)) + err = fmt.Errorf("Error setting path: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline_trigger_property", "read", "set-path").GetDiag() } } if !core.IsNil(triggerProperty.Locked) { if err = d.Set("locked", triggerProperty.Locked); err != nil { - return diag.FromErr(fmt.Errorf("Error setting locked: %s", err)) + err = fmt.Errorf("Error setting locked: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline_trigger_property", "read", "set-locked").GetDiag() } } if !core.IsNil(triggerProperty.Href) { if err = d.Set("href", triggerProperty.Href); err != nil { - return diag.FromErr(fmt.Errorf("Error setting href: %s", err)) + err = fmt.Errorf("Error setting href: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline_trigger_property", "read", "set-href").GetDiag() } } @@ -262,14 +273,16 @@ func resourceIBMCdTektonPipelineTriggerPropertyRead(context context.Context, d * func resourceIBMCdTektonPipelineTriggerPropertyUpdate(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { cdTektonPipelineClient, err := meta.(conns.ClientSession).CdTektonPipelineV2() if err != nil { - return diag.FromErr(err) + tfErr := flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline_trigger_property", "update", "initialize-client") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } replaceTektonPipelineTriggerPropertyOptions := &cdtektonpipelinev2.ReplaceTektonPipelineTriggerPropertyOptions{} parts, err := flex.SepIdParts(d.Id(), "/") if err != nil { - return diag.FromErr(err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline_trigger_property", "update", "sep-id-parts").GetDiag() } replaceTektonPipelineTriggerPropertyOptions.SetPipelineID(parts[0]) @@ -281,20 +294,24 @@ func resourceIBMCdTektonPipelineTriggerPropertyUpdate(context context.Context, d hasChange := false if d.HasChange("pipeline_id") { - return diag.FromErr(fmt.Errorf("Cannot update resource property \"%s\" with the ForceNew annotation."+ - " The resource must be re-created to update this property.", "pipeline_id")) + errMsg := fmt.Sprintf("Cannot update resource property \"%s\" with the ForceNew annotation."+ + " The resource must be re-created to update this property.", "pipeline_id") + return flex.DiscriminatedTerraformErrorf(nil, errMsg, "ibm_cd_tekton_pipeline_trigger_property", "update", "pipeline_id-forces-new").GetDiag() } if d.HasChange("trigger_id") { - return diag.FromErr(fmt.Errorf("Cannot update resource property \"%s\" with the ForceNew annotation."+ - " The resource must be re-created to update this property.", "trigger_id")) + errMsg := fmt.Sprintf("Cannot update resource property \"%s\" with the ForceNew annotation."+ + " The resource must be re-created to update this property.", "trigger_id") + return flex.DiscriminatedTerraformErrorf(nil, errMsg, "ibm_cd_tekton_pipeline_trigger_property", "update", "trigger_id-forces-new").GetDiag() } if d.HasChange("name") { - return diag.FromErr(fmt.Errorf("Cannot update resource property \"%s\" with the ForceNew annotation."+ - " The resource must be re-created to update this property.", "name")) + errMsg := fmt.Sprintf("Cannot update resource property \"%s\" with the ForceNew annotation."+ + " The resource must be re-created to update this property.", "name") + return flex.DiscriminatedTerraformErrorf(nil, errMsg, "ibm_cd_tekton_pipeline_trigger_property", "update", "name-forces-new").GetDiag() } if d.HasChange("type") { - return diag.FromErr(fmt.Errorf("Cannot update resource property \"%s\" with the ForceNew annotation."+ - " The resource must be re-created to update this property.", "type")) + errMsg := fmt.Sprintf("Cannot update resource property \"%s\" with the ForceNew annotation."+ + " The resource must be re-created to update this property.", "type") + return flex.DiscriminatedTerraformErrorf(nil, errMsg, "ibm_cd_tekton_pipeline_trigger_property", "update", "type-forces-new").GetDiag() } if d.HasChange("locked") { replaceTektonPipelineTriggerPropertyOptions.SetLocked(d.Get("locked").(bool)) @@ -325,10 +342,11 @@ func resourceIBMCdTektonPipelineTriggerPropertyUpdate(context context.Context, d } if hasChange { - _, response, err := cdTektonPipelineClient.ReplaceTektonPipelineTriggerPropertyWithContext(context, replaceTektonPipelineTriggerPropertyOptions) + _, _, err = cdTektonPipelineClient.ReplaceTektonPipelineTriggerPropertyWithContext(context, replaceTektonPipelineTriggerPropertyOptions) if err != nil { - log.Printf("[DEBUG] ReplaceTektonPipelineTriggerPropertyWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("ReplaceTektonPipelineTriggerPropertyWithContext failed %s\n%s", err, response)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("ReplaceTektonPipelineTriggerPropertyWithContext failed: %s", err.Error()), "ibm_cd_tekton_pipeline_trigger_property", "update") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } @@ -338,24 +356,27 @@ func resourceIBMCdTektonPipelineTriggerPropertyUpdate(context context.Context, d func resourceIBMCdTektonPipelineTriggerPropertyDelete(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { cdTektonPipelineClient, err := meta.(conns.ClientSession).CdTektonPipelineV2() if err != nil { - return diag.FromErr(err) + tfErr := flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline_trigger_property", "delete", "initialize-client") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } deleteTektonPipelineTriggerPropertyOptions := &cdtektonpipelinev2.DeleteTektonPipelineTriggerPropertyOptions{} parts, err := flex.SepIdParts(d.Id(), "/") if err != nil { - return diag.FromErr(err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cd_tekton_pipeline_trigger_property", "delete", "sep-id-parts").GetDiag() } deleteTektonPipelineTriggerPropertyOptions.SetPipelineID(parts[0]) deleteTektonPipelineTriggerPropertyOptions.SetTriggerID(parts[1]) deleteTektonPipelineTriggerPropertyOptions.SetPropertyName(parts[2]) - response, err := cdTektonPipelineClient.DeleteTektonPipelineTriggerPropertyWithContext(context, deleteTektonPipelineTriggerPropertyOptions) + _, err = cdTektonPipelineClient.DeleteTektonPipelineTriggerPropertyWithContext(context, deleteTektonPipelineTriggerPropertyOptions) if err != nil { - log.Printf("[DEBUG] DeleteTektonPipelineTriggerPropertyWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("DeleteTektonPipelineTriggerPropertyWithContext failed %s\n%s", err, response)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("DeleteTektonPipelineTriggerPropertyWithContext failed: %s", err.Error()), "ibm_cd_tekton_pipeline_trigger_property", "delete") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } d.SetId("") diff --git a/ibm/service/cdtektonpipeline/resource_ibm_cd_tekton_pipeline_trigger_property_test.go b/ibm/service/cdtektonpipeline/resource_ibm_cd_tekton_pipeline_trigger_property_test.go index fe5bcbf629..d837c2dd5a 100644 --- a/ibm/service/cdtektonpipeline/resource_ibm_cd_tekton_pipeline_trigger_property_test.go +++ b/ibm/service/cdtektonpipeline/resource_ibm_cd_tekton_pipeline_trigger_property_test.go @@ -29,9 +29,9 @@ func TestAccIBMCdTektonPipelineTriggerPropertyBasic(t *testing.T) { resource.TestStep{ Config: testAccCheckIBMCdTektonPipelineTriggerPropertyConfigBasic("", "", name, typeVar), Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckIBMCdTektonPipelineTriggerPropertyExists("ibm_cd_tekton_pipeline_trigger_property.cd_tekton_pipeline_trigger_property", conf), - resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_trigger_property.cd_tekton_pipeline_trigger_property", "name", name), - resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_trigger_property.cd_tekton_pipeline_trigger_property", "type", typeVar), + testAccCheckIBMCdTektonPipelineTriggerPropertyExists("ibm_cd_tekton_pipeline_trigger_property.cd_tekton_pipeline_trigger_property_instance", conf), + resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_trigger_property.cd_tekton_pipeline_trigger_property_instance", "name", name), + resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_trigger_property.cd_tekton_pipeline_trigger_property_instance", "type", typeVar), ), }, }, @@ -41,8 +41,8 @@ func TestAccIBMCdTektonPipelineTriggerPropertyBasic(t *testing.T) { func TestAccIBMCdTektonPipelineTriggerPropertyAllArgs(t *testing.T) { var conf cdtektonpipelinev2.TriggerProperty name := fmt.Sprintf("tf_name_%d", acctest.RandIntRange(10, 100)) - typeVar := "text" value := fmt.Sprintf("tf_value_%d", acctest.RandIntRange(10, 100)) + typeVar := "text" path := fmt.Sprintf("tf_path_%d", acctest.RandIntRange(10, 100)) locked := "true" valueUpdate := fmt.Sprintf("tf_value_%d", acctest.RandIntRange(10, 100)) @@ -55,28 +55,29 @@ func TestAccIBMCdTektonPipelineTriggerPropertyAllArgs(t *testing.T) { CheckDestroy: testAccCheckIBMCdTektonPipelineTriggerPropertyDestroy, Steps: []resource.TestStep{ resource.TestStep{ - Config: testAccCheckIBMCdTektonPipelineTriggerPropertyConfig("", "", name, typeVar, value, path, locked), + Config: testAccCheckIBMCdTektonPipelineTriggerPropertyConfig("", "", name, value, typeVar, path, locked), Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckIBMCdTektonPipelineTriggerPropertyExists("ibm_cd_tekton_pipeline_trigger_property.cd_tekton_pipeline_trigger_property", conf), - resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_trigger_property.cd_tekton_pipeline_trigger_property", "name", name), - resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_trigger_property.cd_tekton_pipeline_trigger_property", "type", typeVar), - resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_trigger_property.cd_tekton_pipeline_trigger_property", "value", value), - resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_trigger_property.cd_tekton_pipeline_trigger_property", "locked", locked), + testAccCheckIBMCdTektonPipelineTriggerPropertyExists("ibm_cd_tekton_pipeline_trigger_property.cd_tekton_pipeline_trigger_property_instance", conf), + resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_trigger_property.cd_tekton_pipeline_trigger_property_instance", "name", name), + resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_trigger_property.cd_tekton_pipeline_trigger_property_instance", "value", value), + resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_trigger_property.cd_tekton_pipeline_trigger_property_instance", "type", typeVar), + resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_trigger_property.cd_tekton_pipeline_trigger_property_instance", "locked", locked), ), }, resource.TestStep{ - Config: testAccCheckIBMCdTektonPipelineTriggerPropertyConfig("", "", name, typeVar, valueUpdate, pathUpdate, lockedUpdate), + Config: testAccCheckIBMCdTektonPipelineTriggerPropertyConfig("", "", name, valueUpdate, typeVar, pathUpdate, lockedUpdate), Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_trigger_property.cd_tekton_pipeline_trigger_property", "name", name), - resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_trigger_property.cd_tekton_pipeline_trigger_property", "type", typeVar), - resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_trigger_property.cd_tekton_pipeline_trigger_property", "value", valueUpdate), - resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_trigger_property.cd_tekton_pipeline_trigger_property", "locked", lockedUpdate), + resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_trigger_property.cd_tekton_pipeline_trigger_property_instance", "name", name), + resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_trigger_property.cd_tekton_pipeline_trigger_property_instance", "value", valueUpdate), + resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_trigger_property.cd_tekton_pipeline_trigger_property_instance", "type", typeVar), + resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_trigger_property.cd_tekton_pipeline_trigger_property_instance", "locked", lockedUpdate), ), }, resource.TestStep{ - ResourceName: "ibm_cd_tekton_pipeline_trigger_property.cd_tekton_pipeline_trigger_property", - ImportState: true, - ImportStateVerify: true, + ResourceName: "ibm_cd_tekton_pipeline_trigger_property.cd_tekton_pipeline_trigger_property_instance", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"pipeline_id", "trigger_id"}, }, }, }) @@ -99,7 +100,7 @@ func testAccCheckIBMCdTektonPipelineTriggerPropertyConfigBasic(pipelineID string name = "pipeline-name" } } - resource "ibm_cd_tekton_pipeline" "cd_tekton_pipeline" { + resource "ibm_cd_tekton_pipeline" "cd_tekton_pipeline_instance" { pipeline_id = ibm_cd_toolchain_tool_pipeline.ibm_cd_toolchain_tool_pipeline.tool_id next_build_number = 5 worker { @@ -118,8 +119,8 @@ func testAccCheckIBMCdTektonPipelineTriggerPropertyConfigBasic(pipelineID string } parameters {} } - resource "ibm_cd_tekton_pipeline_definition" "cd_tekton_pipeline_definition" { - pipeline_id = ibm_cd_tekton_pipeline.cd_tekton_pipeline.pipeline_id + resource "ibm_cd_tekton_pipeline_definition" "cd_tekton_pipeline_definition_instance" { + pipeline_id = ibm_cd_tekton_pipeline.cd_tekton_pipeline_instance.pipeline_id source { type = "git" properties { @@ -129,21 +130,21 @@ func testAccCheckIBMCdTektonPipelineTriggerPropertyConfigBasic(pipelineID string } } depends_on = [ - ibm_cd_tekton_pipeline.cd_tekton_pipeline + ibm_cd_tekton_pipeline.cd_tekton_pipeline_instance ] } - resource "ibm_cd_tekton_pipeline_trigger" "cd_tekton_pipeline_trigger" { + resource "ibm_cd_tekton_pipeline_trigger" "cd_tekton_pipeline_trigger_instance" { pipeline_id = ibm_cd_toolchain_tool_pipeline.ibm_cd_toolchain_tool_pipeline.tool_id depends_on = [ - ibm_cd_tekton_pipeline_definition.cd_tekton_pipeline_definition + ibm_cd_tekton_pipeline_definition.cd_tekton_pipeline_definition_instance ] name = "trigger" type = "manual" event_listener = "listener" } - resource "ibm_cd_tekton_pipeline_trigger_property" "cd_tekton_pipeline_trigger_property" { - pipeline_id = ibm_cd_tekton_pipeline.cd_tekton_pipeline.pipeline_id - trigger_id = ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger.trigger_id + resource "ibm_cd_tekton_pipeline_trigger_property" "cd_tekton_pipeline_trigger_property_instance" { + pipeline_id = ibm_cd_tekton_pipeline.cd_tekton_pipeline_instance.pipeline_id + trigger_id = ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger_instance.trigger_id type = "text" name = "trig-prop-1" value = "trig-prop-value-1" @@ -151,7 +152,7 @@ func testAccCheckIBMCdTektonPipelineTriggerPropertyConfigBasic(pipelineID string `, rgName, tcName) } -func testAccCheckIBMCdTektonPipelineTriggerPropertyConfig(pipelineID string, triggerID string, name string, typeVar string, value string, path string, locked string) string { +func testAccCheckIBMCdTektonPipelineTriggerPropertyConfig(pipelineID string, triggerID string, name string, value string, typeVar string, path string, locked string) string { rgName := acc.CdResourceGroupName tcName := fmt.Sprintf("tf_name_%d", acctest.RandIntRange(10, 100)) return fmt.Sprintf(` @@ -168,7 +169,7 @@ func testAccCheckIBMCdTektonPipelineTriggerPropertyConfig(pipelineID string, tri name = "pipeline-name" } } - resource "ibm_cd_tekton_pipeline" "cd_tekton_pipeline" { + resource "ibm_cd_tekton_pipeline" "cd_tekton_pipeline_instance" { pipeline_id = ibm_cd_toolchain_tool_pipeline.ibm_cd_toolchain_tool_pipeline.tool_id next_build_number = 5 worker { @@ -187,8 +188,8 @@ func testAccCheckIBMCdTektonPipelineTriggerPropertyConfig(pipelineID string, tri } parameters {} } - resource "ibm_cd_tekton_pipeline_definition" "cd_tekton_pipeline_definition" { - pipeline_id = ibm_cd_tekton_pipeline.cd_tekton_pipeline.pipeline_id + resource "ibm_cd_tekton_pipeline_definition" "cd_tekton_pipeline_definition_instance" { + pipeline_id = ibm_cd_tekton_pipeline.cd_tekton_pipeline_instance.pipeline_id source { type = "git" properties { @@ -198,21 +199,21 @@ func testAccCheckIBMCdTektonPipelineTriggerPropertyConfig(pipelineID string, tri } } depends_on = [ - ibm_cd_tekton_pipeline.cd_tekton_pipeline + ibm_cd_tekton_pipeline.cd_tekton_pipeline_instance ] } - resource "ibm_cd_tekton_pipeline_trigger" "cd_tekton_pipeline_trigger" { + resource "ibm_cd_tekton_pipeline_trigger" "cd_tekton_pipeline_trigger_instance" { pipeline_id = ibm_cd_toolchain_tool_pipeline.ibm_cd_toolchain_tool_pipeline.tool_id depends_on = [ - ibm_cd_tekton_pipeline_definition.cd_tekton_pipeline_definition + ibm_cd_tekton_pipeline_definition.cd_tekton_pipeline_definition_instance ] name = "trigger" type = "manual" event_listener = "listener" } - resource "ibm_cd_tekton_pipeline_trigger_property" "cd_tekton_pipeline_trigger_property" { - pipeline_id = ibm_cd_tekton_pipeline.cd_tekton_pipeline.pipeline_id - trigger_id = ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger.trigger_id + resource "ibm_cd_tekton_pipeline_trigger_property" "cd_tekton_pipeline_trigger_property_instance" { + pipeline_id = ibm_cd_tekton_pipeline.cd_tekton_pipeline_instance.pipeline_id + trigger_id = ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger_instance.trigger_id name = "%s" type = "%s" value = "%s" diff --git a/ibm/service/cdtektonpipeline/resource_ibm_cd_tekton_pipeline_trigger_test.go b/ibm/service/cdtektonpipeline/resource_ibm_cd_tekton_pipeline_trigger_test.go index 7c327c2a5a..39329b80eb 100644 --- a/ibm/service/cdtektonpipeline/resource_ibm_cd_tekton_pipeline_trigger_test.go +++ b/ibm/service/cdtektonpipeline/resource_ibm_cd_tekton_pipeline_trigger_test.go @@ -14,7 +14,10 @@ import ( 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/IBM-Cloud/terraform-provider-ibm/ibm/service/cdtektonpipeline" "github.com/IBM/continuous-delivery-go-sdk/cdtektonpipelinev2" + "github.com/IBM/go-sdk-core/v5/core" + "github.com/stretchr/testify/assert" ) func TestAccIBMCdTektonPipelineTriggerBasic(t *testing.T) { @@ -34,20 +37,20 @@ func TestAccIBMCdTektonPipelineTriggerBasic(t *testing.T) { resource.TestStep{ Config: testAccCheckIBMCdTektonPipelineTriggerConfigBasic("", typeVar, name, eventListener), Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckIBMCdTektonPipelineTriggerExists("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger", conf), - resource.TestCheckResourceAttrSet("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger", "id"), - resource.TestCheckResourceAttrSet("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger", "pipeline_id"), - resource.TestCheckResourceAttrSet("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger", "trigger_id"), - resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger", "type", typeVar), - resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger", "name", name), - resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger", "event_listener", eventListener), + testAccCheckIBMCdTektonPipelineTriggerExists("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger_instance", conf), + resource.TestCheckResourceAttrSet("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger_instance", "id"), + resource.TestCheckResourceAttrSet("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger_instance", "pipeline_id"), + resource.TestCheckResourceAttrSet("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger_instance", "trigger_id"), + resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger_instance", "type", typeVar), + resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger_instance", "name", name), + resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger_instance", "event_listener", eventListener), ), }, resource.TestStep{ Config: testAccCheckIBMCdTektonPipelineTriggerConfigBasic("", typeVarUpdate, nameUpdate, eventListenerUpdate), Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger", "name", nameUpdate), - resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger", "event_listener", eventListenerUpdate), + resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger_instance", "name", nameUpdate), + resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger_instance", "event_listener", eventListenerUpdate), ), }, }, @@ -84,60 +87,59 @@ func TestAccIBMCdTektonPipelineTriggerAllArgs(t *testing.T) { CheckDestroy: testAccCheckIBMCdTektonPipelineTriggerDestroy, Steps: []resource.TestStep{ resource.TestStep{ - Config: testAccCheckIBMCdTektonPipelineTriggerConfig(pipelineID, typeVar, name, eventListener, maxConcurrentRuns, enabled, cron, timezone, filter, favorite, enableEventsFromForks), + Config: testAccCheckIBMCdTektonPipelineTriggerConfig(pipelineID, typeVar, name, eventListener, maxConcurrentRuns, enabled, favorite, enableEventsFromForks, filter, cron, timezone), Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckIBMCdTektonPipelineTriggerExists("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger", conf), - testAccCheckIBMCdTektonPipelineTriggerExists("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger2", conf), - testAccCheckIBMCdTektonPipelineTriggerExists("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger3", conf), - resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger", "name", name), - resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger", "max_concurrent_runs", maxConcurrentRuns), - resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger", "enabled", enabled), - resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger2", "cron", cron), - resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger2", "timezone", timezone), - resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger", "filter", filter), - resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger", "favorite", favorite), - resource.TestCheckResourceAttrSet("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger", "pipeline_id"), - resource.TestCheckResourceAttrSet("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger", "trigger_id"), - resource.TestCheckResourceAttrSet("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger2", "pipeline_id"), - resource.TestCheckResourceAttrSet("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger2", "trigger_id"), - resource.TestCheckResourceAttrSet("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger3", "pipeline_id"), - resource.TestCheckResourceAttrSet("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger3", "trigger_id"), - resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger", "type", "manual"), - resource.TestCheckResourceAttrSet("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger", "tags.#"), - resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger2", "type", "timer"), - resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger3", "type", "generic"), - resource.TestCheckResourceAttrSet("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger3", "secret.#"), - resource.TestCheckResourceAttrSet("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger3", "webhook_url"), + testAccCheckIBMCdTektonPipelineTriggerExists("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger_instance", conf), + testAccCheckIBMCdTektonPipelineTriggerExists("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger2_instance", conf), + testAccCheckIBMCdTektonPipelineTriggerExists("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger3_instance", conf), + resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger_instance", "name", name), + resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger_instance", "max_concurrent_runs", maxConcurrentRuns), + resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger_instance", "enabled", enabled), + resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger2_instance", "cron", cron), + resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger2_instance", "timezone", timezone), + resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger_instance", "favorite", favorite), + resource.TestCheckResourceAttrSet("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger_instance", "pipeline_id"), + resource.TestCheckResourceAttrSet("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger_instance", "trigger_id"), + resource.TestCheckResourceAttrSet("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger2_instance", "pipeline_id"), + resource.TestCheckResourceAttrSet("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger2_instance", "trigger_id"), + resource.TestCheckResourceAttrSet("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger3_instance", "pipeline_id"), + resource.TestCheckResourceAttrSet("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger3_instance", "trigger_id"), + resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger_instance", "type", "manual"), + resource.TestCheckResourceAttrSet("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger_instance", "tags.#"), + resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger2_instance", "type", "timer"), + resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger3_instance", "type", "generic"), + resource.TestCheckResourceAttrSet("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger3_instance", "secret.#"), + resource.TestCheckResourceAttrSet("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger3_instance", "webhook_url"), ), }, resource.TestStep{ - Config: testAccCheckIBMCdTektonPipelineTriggerConfig(pipelineID, typeVarUpdate, nameUpdate, eventListenerUpdate, maxConcurrentRunsUpdate, enabledUpdate, cronUpdate, timezoneUpdate, filterUpdate, favoriteUpdate, enableEventsFromForksUpdate), + Config: testAccCheckIBMCdTektonPipelineTriggerConfig(pipelineID, typeVarUpdate, nameUpdate, eventListenerUpdate, maxConcurrentRunsUpdate, enabledUpdate, favoriteUpdate, enableEventsFromForksUpdate, filterUpdate, cronUpdate, timezoneUpdate), Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger", "name", nameUpdate), - resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger", "max_concurrent_runs", maxConcurrentRunsUpdate), - resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger", "enabled", enabledUpdate), - resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger2", "cron", cronUpdate), - resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger2", "timezone", timezoneUpdate), - resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger", "filter", filterUpdate), - resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger", "favorite", favoriteUpdate), - resource.TestCheckResourceAttrSet("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger", "pipeline_id"), - resource.TestCheckResourceAttrSet("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger", "trigger_id"), - resource.TestCheckResourceAttrSet("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger2", "pipeline_id"), - resource.TestCheckResourceAttrSet("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger2", "trigger_id"), - resource.TestCheckResourceAttrSet("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger3", "pipeline_id"), - resource.TestCheckResourceAttrSet("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger3", "trigger_id"), - resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger", "type", "manual"), - resource.TestCheckResourceAttrSet("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger", "tags.#"), - resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger2", "type", "timer"), - resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger3", "type", "generic"), - resource.TestCheckResourceAttrSet("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger3", "secret.#"), - resource.TestCheckResourceAttrSet("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger3", "webhook_url"), + resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger_instance", "name", nameUpdate), + resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger_instance", "max_concurrent_runs", maxConcurrentRunsUpdate), + resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger_instance", "enabled", enabledUpdate), + resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger2_instance", "cron", cronUpdate), + resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger2_instance", "timezone", timezoneUpdate), + resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger_instance", "favorite", favoriteUpdate), + resource.TestCheckResourceAttrSet("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger_instance", "pipeline_id"), + resource.TestCheckResourceAttrSet("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger_instance", "trigger_id"), + resource.TestCheckResourceAttrSet("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger2_instance", "pipeline_id"), + resource.TestCheckResourceAttrSet("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger2_instance", "trigger_id"), + resource.TestCheckResourceAttrSet("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger3_instance", "pipeline_id"), + resource.TestCheckResourceAttrSet("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger3_instance", "trigger_id"), + resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger_instance", "type", "manual"), + resource.TestCheckResourceAttrSet("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger_instance", "tags.#"), + resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger2_instance", "type", "timer"), + resource.TestCheckResourceAttr("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger3_instance", "type", "generic"), + resource.TestCheckResourceAttrSet("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger3_instance", "secret.#"), + resource.TestCheckResourceAttrSet("ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger3_instance", "webhook_url"), ), }, resource.TestStep{ - ResourceName: "ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger", - ImportState: true, - ImportStateVerify: true, + ResourceName: "ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger_instance", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"pipeline_id", "enable_events_from_forks"}, }, }, }) @@ -160,7 +162,7 @@ func testAccCheckIBMCdTektonPipelineTriggerConfigBasic(pipelineID string, typeVa name = "pipeline-name" } } - resource "ibm_cd_tekton_pipeline" "cd_tekton_pipeline" { + resource "ibm_cd_tekton_pipeline" "cd_tekton_pipeline_instance" { pipeline_id = ibm_cd_toolchain_tool_pipeline.ibm_cd_toolchain_tool_pipeline.tool_id next_build_number = 5 worker { @@ -179,8 +181,8 @@ func testAccCheckIBMCdTektonPipelineTriggerConfigBasic(pipelineID string, typeVa } parameters {} } - resource "ibm_cd_tekton_pipeline_definition" "cd_tekton_pipeline_definition" { - pipeline_id = ibm_cd_tekton_pipeline.cd_tekton_pipeline.pipeline_id + resource "ibm_cd_tekton_pipeline_definition" "cd_tekton_pipeline_definition_instance" { + pipeline_id = ibm_cd_tekton_pipeline.cd_tekton_pipeline_instance.pipeline_id source { type = "git" properties { @@ -190,13 +192,13 @@ func testAccCheckIBMCdTektonPipelineTriggerConfigBasic(pipelineID string, typeVa } } depends_on = [ - ibm_cd_tekton_pipeline.cd_tekton_pipeline + ibm_cd_tekton_pipeline.cd_tekton_pipeline_instance ] } - resource "ibm_cd_tekton_pipeline_trigger" "cd_tekton_pipeline_trigger" { + resource "ibm_cd_tekton_pipeline_trigger" "cd_tekton_pipeline_trigger_instance" { pipeline_id = ibm_cd_toolchain_tool_pipeline.ibm_cd_toolchain_tool_pipeline.tool_id depends_on = [ - ibm_cd_tekton_pipeline_definition.cd_tekton_pipeline_definition + ibm_cd_tekton_pipeline_definition.cd_tekton_pipeline_definition_instance ] type = "%s" name = "%s" @@ -205,7 +207,7 @@ func testAccCheckIBMCdTektonPipelineTriggerConfigBasic(pipelineID string, typeVa `, rgName, tcName, typeVar, name, eventListener) } -func testAccCheckIBMCdTektonPipelineTriggerConfig(pipelineID string, typeVar string, name string, eventListener string, maxConcurrentRuns string, enabled string, cron string, timezone string, filter string, favorite string, enableEventsFromForks string) string { +func testAccCheckIBMCdTektonPipelineTriggerConfig(pipelineID string, typeVar string, name string, eventListener string, maxConcurrentRuns string, enabled string, favorite string, enableEventsFromForks string, filter string, cron string, timezone string) string { rgName := acc.CdResourceGroupName tcName := fmt.Sprintf("tf_name_%d", acctest.RandIntRange(10, 100)) return fmt.Sprintf(` @@ -222,7 +224,7 @@ func testAccCheckIBMCdTektonPipelineTriggerConfig(pipelineID string, typeVar str name = "pipeline-name" } } - resource "ibm_cd_tekton_pipeline" "cd_tekton_pipeline" { + resource "ibm_cd_tekton_pipeline" "cd_tekton_pipeline_instance" { pipeline_id = ibm_cd_toolchain_tool_pipeline.ibm_cd_toolchain_tool_pipeline.tool_id next_build_number = 5 worker { @@ -241,8 +243,8 @@ func testAccCheckIBMCdTektonPipelineTriggerConfig(pipelineID string, typeVar str } parameters {} } - resource "ibm_cd_tekton_pipeline_definition" "cd_tekton_pipeline_definition" { - pipeline_id = ibm_cd_tekton_pipeline.cd_tekton_pipeline.pipeline_id + resource "ibm_cd_tekton_pipeline_definition" "cd_tekton_pipeline_definition_instance" { + pipeline_id = ibm_cd_tekton_pipeline.cd_tekton_pipeline_instance.pipeline_id source { type = "git" properties { @@ -252,13 +254,13 @@ func testAccCheckIBMCdTektonPipelineTriggerConfig(pipelineID string, typeVar str } } depends_on = [ - ibm_cd_tekton_pipeline.cd_tekton_pipeline + ibm_cd_tekton_pipeline.cd_tekton_pipeline_instance ] } - resource "ibm_cd_tekton_pipeline_trigger" "cd_tekton_pipeline_trigger" { + resource "ibm_cd_tekton_pipeline_trigger" "cd_tekton_pipeline_trigger_instance" { pipeline_id = ibm_cd_toolchain_tool_pipeline.ibm_cd_toolchain_tool_pipeline.tool_id depends_on = [ - ibm_cd_tekton_pipeline_definition.cd_tekton_pipeline_definition + ibm_cd_tekton_pipeline_definition.cd_tekton_pipeline_definition_instance ] type = "manual" event_listener = "listener" @@ -268,10 +270,10 @@ func testAccCheckIBMCdTektonPipelineTriggerConfig(pipelineID string, typeVar str enabled = %s favorite = %s } - resource "ibm_cd_tekton_pipeline_trigger" "cd_tekton_pipeline_trigger2" { + resource "ibm_cd_tekton_pipeline_trigger" "cd_tekton_pipeline_trigger2_instance" { pipeline_id = ibm_cd_toolchain_tool_pipeline.ibm_cd_toolchain_tool_pipeline.tool_id depends_on = [ - ibm_cd_tekton_pipeline_definition.cd_tekton_pipeline_definition + ibm_cd_tekton_pipeline_definition.cd_tekton_pipeline_definition_instance ] type = "timer" name = "timer1" @@ -279,10 +281,10 @@ func testAccCheckIBMCdTektonPipelineTriggerConfig(pipelineID string, typeVar str cron = "%s" timezone = "%s" } - resource "ibm_cd_tekton_pipeline_trigger" "cd_tekton_pipeline_trigger3" { + resource "ibm_cd_tekton_pipeline_trigger" "cd_tekton_pipeline_trigger3_instance" { pipeline_id = ibm_cd_toolchain_tool_pipeline.ibm_cd_toolchain_tool_pipeline.tool_id depends_on = [ - ibm_cd_tekton_pipeline_definition.cd_tekton_pipeline_definition + ibm_cd_tekton_pipeline_definition.cd_tekton_pipeline_definition_instance ] type = "generic" name = "generic1" @@ -364,3 +366,251 @@ func testAccCheckIBMCdTektonPipelineTriggerDestroy(s *terraform.State) error { return nil } + +func TestResourceIBMCdTektonPipelineTriggerWorkerToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + model := make(map[string]interface{}) + model["name"] = "testString" + model["type"] = "testString" + model["id"] = "testString" + + assert.Equal(t, result, model) + } + + model := new(cdtektonpipelinev2.Worker) + model.Name = core.StringPtr("testString") + model.Type = core.StringPtr("testString") + model.ID = core.StringPtr("testString") + + result, err := cdtektonpipeline.ResourceIBMCdTektonPipelineTriggerWorkerToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestResourceIBMCdTektonPipelineTriggerTriggerSourceToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + toolModel := make(map[string]interface{}) + toolModel["id"] = "testString" + + triggerSourcePropertiesModel := make(map[string]interface{}) + triggerSourcePropertiesModel["url"] = "testString" + triggerSourcePropertiesModel["branch"] = "testString" + triggerSourcePropertiesModel["pattern"] = "testString" + triggerSourcePropertiesModel["blind_connection"] = true + triggerSourcePropertiesModel["hook_id"] = "testString" + triggerSourcePropertiesModel["tool"] = []map[string]interface{}{toolModel} + + model := make(map[string]interface{}) + model["type"] = "testString" + model["properties"] = []map[string]interface{}{triggerSourcePropertiesModel} + + assert.Equal(t, result, model) + } + + toolModel := new(cdtektonpipelinev2.Tool) + toolModel.ID = core.StringPtr("testString") + + triggerSourcePropertiesModel := new(cdtektonpipelinev2.TriggerSourceProperties) + triggerSourcePropertiesModel.URL = core.StringPtr("testString") + triggerSourcePropertiesModel.Branch = core.StringPtr("testString") + triggerSourcePropertiesModel.Pattern = core.StringPtr("testString") + triggerSourcePropertiesModel.BlindConnection = core.BoolPtr(true) + triggerSourcePropertiesModel.HookID = core.StringPtr("testString") + triggerSourcePropertiesModel.Tool = toolModel + + model := new(cdtektonpipelinev2.TriggerSource) + model.Type = core.StringPtr("testString") + model.Properties = triggerSourcePropertiesModel + + result, err := cdtektonpipeline.ResourceIBMCdTektonPipelineTriggerTriggerSourceToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestResourceIBMCdTektonPipelineTriggerTriggerSourcePropertiesToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + toolModel := make(map[string]interface{}) + toolModel["id"] = "testString" + + model := make(map[string]interface{}) + model["url"] = "testString" + model["branch"] = "testString" + model["pattern"] = "testString" + model["blind_connection"] = true + model["hook_id"] = "testString" + model["tool"] = []map[string]interface{}{toolModel} + + assert.Equal(t, result, model) + } + + toolModel := new(cdtektonpipelinev2.Tool) + toolModel.ID = core.StringPtr("testString") + + model := new(cdtektonpipelinev2.TriggerSourceProperties) + model.URL = core.StringPtr("testString") + model.Branch = core.StringPtr("testString") + model.Pattern = core.StringPtr("testString") + model.BlindConnection = core.BoolPtr(true) + model.HookID = core.StringPtr("testString") + model.Tool = toolModel + + result, err := cdtektonpipeline.ResourceIBMCdTektonPipelineTriggerTriggerSourcePropertiesToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestResourceIBMCdTektonPipelineTriggerToolToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + model := make(map[string]interface{}) + model["id"] = "testString" + + assert.Equal(t, result, model) + } + + model := new(cdtektonpipelinev2.Tool) + model.ID = core.StringPtr("testString") + + result, err := cdtektonpipeline.ResourceIBMCdTektonPipelineTriggerToolToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestResourceIBMCdTektonPipelineTriggerGenericSecretToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + model := make(map[string]interface{}) + model["type"] = "token_matches" + model["value"] = "testString" + model["source"] = "header" + model["key_name"] = "testString" + model["algorithm"] = "md4" + + assert.Equal(t, result, model) + } + + model := new(cdtektonpipelinev2.GenericSecret) + model.Type = core.StringPtr("token_matches") + model.Value = core.StringPtr("testString") + model.Source = core.StringPtr("header") + model.KeyName = core.StringPtr("testString") + model.Algorithm = core.StringPtr("md4") + + result, err := cdtektonpipeline.ResourceIBMCdTektonPipelineTriggerGenericSecretToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestResourceIBMCdTektonPipelineTriggerTriggerPropertyToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + model := make(map[string]interface{}) + model["name"] = "testString" + model["value"] = "testString" + model["href"] = "testString" + model["enum"] = []string{"testString"} + model["type"] = "secure" + model["path"] = "testString" + model["locked"] = true + + assert.Equal(t, result, model) + } + + model := new(cdtektonpipelinev2.TriggerProperty) + model.Name = core.StringPtr("testString") + model.Value = core.StringPtr("testString") + model.Href = core.StringPtr("testString") + model.Enum = []string{"testString"} + model.Type = core.StringPtr("secure") + model.Path = core.StringPtr("testString") + model.Locked = core.BoolPtr(true) + + result, err := cdtektonpipeline.ResourceIBMCdTektonPipelineTriggerTriggerPropertyToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestResourceIBMCdTektonPipelineTriggerMapToWorkerIdentity(t *testing.T) { + checkResult := func(result *cdtektonpipelinev2.WorkerIdentity) { + model := new(cdtektonpipelinev2.WorkerIdentity) + model.ID = core.StringPtr("testString") + + assert.Equal(t, result, model) + } + + model := make(map[string]interface{}) + model["id"] = "testString" + + result, err := cdtektonpipeline.ResourceIBMCdTektonPipelineTriggerMapToWorkerIdentity(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestResourceIBMCdTektonPipelineTriggerMapToGenericSecret(t *testing.T) { + checkResult := func(result *cdtektonpipelinev2.GenericSecret) { + model := new(cdtektonpipelinev2.GenericSecret) + model.Type = core.StringPtr("token_matches") + model.Value = core.StringPtr("testString") + model.Source = core.StringPtr("header") + model.KeyName = core.StringPtr("testString") + model.Algorithm = core.StringPtr("md4") + + assert.Equal(t, result, model) + } + + model := make(map[string]interface{}) + model["type"] = "token_matches" + model["value"] = "testString" + model["source"] = "header" + model["key_name"] = "testString" + model["algorithm"] = "md4" + + result, err := cdtektonpipeline.ResourceIBMCdTektonPipelineTriggerMapToGenericSecret(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestResourceIBMCdTektonPipelineTriggerMapToTriggerSourcePrototype(t *testing.T) { + checkResult := func(result *cdtektonpipelinev2.TriggerSourcePrototype) { + triggerSourcePropertiesPrototypeModel := new(cdtektonpipelinev2.TriggerSourcePropertiesPrototype) + triggerSourcePropertiesPrototypeModel.URL = core.StringPtr("testString") + triggerSourcePropertiesPrototypeModel.Branch = core.StringPtr("testString") + triggerSourcePropertiesPrototypeModel.Pattern = core.StringPtr("testString") + + model := new(cdtektonpipelinev2.TriggerSourcePrototype) + model.Type = core.StringPtr("testString") + model.Properties = triggerSourcePropertiesPrototypeModel + + assert.Equal(t, result, model) + } + + triggerSourcePropertiesPrototypeModel := make(map[string]interface{}) + triggerSourcePropertiesPrototypeModel["url"] = "testString" + triggerSourcePropertiesPrototypeModel["branch"] = "testString" + triggerSourcePropertiesPrototypeModel["pattern"] = "testString" + + model := make(map[string]interface{}) + model["type"] = "testString" + model["properties"] = []interface{}{triggerSourcePropertiesPrototypeModel} + + result, err := cdtektonpipeline.ResourceIBMCdTektonPipelineTriggerMapToTriggerSourcePrototype(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestResourceIBMCdTektonPipelineTriggerMapToTriggerSourcePropertiesPrototype(t *testing.T) { + checkResult := func(result *cdtektonpipelinev2.TriggerSourcePropertiesPrototype) { + model := new(cdtektonpipelinev2.TriggerSourcePropertiesPrototype) + model.URL = core.StringPtr("testString") + model.Branch = core.StringPtr("testString") + model.Pattern = core.StringPtr("testString") + + assert.Equal(t, result, model) + } + + model := make(map[string]interface{}) + model["url"] = "testString" + model["branch"] = "testString" + model["pattern"] = "testString" + + result, err := cdtektonpipeline.ResourceIBMCdTektonPipelineTriggerMapToTriggerSourcePropertiesPrototype(model) + assert.Nil(t, err) + checkResult(result) +} diff --git a/website/docs/d/cd_tekton_pipeline.html.markdown b/website/docs/d/cd_tekton_pipeline.html.markdown index 7d6b0f15bc..69624caef9 100644 --- a/website/docs/d/cd_tekton_pipeline.html.markdown +++ b/website/docs/d/cd_tekton_pipeline.html.markdown @@ -8,7 +8,7 @@ subcategory: "Continuous Delivery" # ibm_cd_tekton_pipeline -Provides a read-only data source for cd_tekton_pipeline. You can then reference the fields of the data source in other resources within the same configuration using interpolation syntax. +Provides a read-only data source to retrieve information about a cd_tekton_pipeline. You can then reference the fields of the data source in other resources within the same configuration by using interpolation syntax. ## Example Usage @@ -20,21 +20,19 @@ data "ibm_cd_tekton_pipeline" "cd_tekton_pipeline" { ## Argument Reference -Review the argument reference that you can specify for your data source. +You can specify the following arguments for this data source. * `pipeline_id` - (Required, Forces new resource, String) ID of current instance. * Constraints: The maximum length is `36` characters. The minimum length is `36` characters. The value must match regular expression `/^[-0-9a-z]+$/`. ## Attribute Reference -In addition to all argument references listed, you can access the following attribute references after your data source is created. +After your data source is created, you can read values from the following attributes. * `id` - The unique identifier of the cd_tekton_pipeline. * `build_number` - (Integer) The latest pipeline run build number. If this property is absent, the pipeline hasn't had any pipeline runs. * Constraints: The minimum value is `1`. - * `created_at` - (String) Standard RFC 3339 Date Time String. - * `definitions` - (List) Definition list. * Constraints: The maximum length is `128` items. The minimum length is `0` items. Nested schema for **definitions**: @@ -60,23 +58,16 @@ Nested schema for **definitions**: * Constraints: The maximum length is `2048` characters. The minimum length is `10` characters. The value must match regular expression `/^http(s)?:\/\/([^\/?#]*)([^?#]*)(\\?([^#]*))?(#(.*))?$/`. * `type` - (String) The only supported source type is "git", indicating that the source is a git repository. * Constraints: The maximum length is `253` characters. The minimum length is `1` character. The value must match regular expression `/^git$/`. - * `enable_notifications` - (Boolean) Flag to enable notifications for this pipeline. If enabled, the Tekton pipeline run events will be published to all the destinations specified by the Slack and Event Notifications integrations in the parent toolchain. If omitted, this feature is disabled by default. - * `enable_partial_cloning` - (Boolean) Flag to enable partial cloning for this pipeline. When partial clone is enabled, only the files contained within the paths specified in definition repositories are read and cloned, this means that symbolic links might not work. If omitted, this feature is disabled by default. - * `enabled` - (Boolean) Flag to check if the trigger is enabled. * Constraints: The default value is `true`. - * `href` - (String) API URL for interacting with the pipeline. * Constraints: The maximum length is `2048` characters. The minimum length is `10` characters. The value must match regular expression `/^http(s)?:\/\/([^\/?#]*)([^?#]*)(\\?([^#]*))?(#(.*))?$/`. - * `name` - (String) String. * Constraints: The maximum length is `253` characters. The minimum length is `1` character. The value must match regular expression `/^[a-zA-Z0-9][-0-9a-zA-Z_. ]{1,251}[a-zA-Z0-9]$/`. - * `next_build_number` - (Integer) The build number that will be used for the next pipeline run. * Constraints: The maximum value is `99999999999999`. The minimum value is `1`. - * `properties` - (List) Tekton pipeline's environment properties. * Constraints: The maximum length is `1024` items. The minimum length is `0` items. Nested schema for **properties**: @@ -99,16 +90,14 @@ Nested schema for **resource_group**: * Constraints: The maximum length is `64` characters. The minimum length is `1` character. The value must match regular expression `/^[-0-9a-zA-Z_]+$/`. * `runs_url` - (String) URL for this pipeline showing the list of pipeline runs. * Constraints: The maximum length is `2048` characters. The minimum length is `10` characters. The value must match regular expression `/^http(s)?:\/\/([^\/?#]*)([^?#]*)(\\?([^#]*))?(#(.*))?$/`. - * `status` - (String) Pipeline status. * Constraints: Allowable values are: `configured`, `configuring`. * `toolchain` - (List) Toolchain object containing references to the parent toolchain. Nested schema for **toolchain**: * `crn` - (String) The CRN for the toolchain that contains the Tekton pipeline. * Constraints: The maximum length is `512` characters. The minimum length is `9` characters. The value must match regular expression `/^crn:v[0-9](:([A-Za-z0-9-._~!$&'()*+,;=@\/]|%[0-9A-Z]{2})*){8}$/`. - * `id` - (String) UUID. + * `id` - (String) Universally Unique Identifier. * Constraints: The maximum length is `36` characters. The minimum length is `36` characters. The value must match regular expression `/^[-0-9a-z]+$/`. - * `triggers` - (List) Tekton pipeline triggers list. * Constraints: The maximum length is `1024` items. The minimum length is `0` items. Nested schema for **triggers**: @@ -196,7 +185,6 @@ Nested schema for **triggers**: * Constraints: The maximum length is `253` characters. The minimum length is `1` character. The value must match regular expression `/^[-0-9a-zA-Z_. \\(\\)\\[\\]]{1,253}$/`. * `type` - (String) Type of the worker. Computed based on the worker ID. * Constraints: The maximum length is `253` characters. The minimum length is `1` character. The value must match regular expression `/^[-0-9a-zA-Z_.]{1,253}$/`. - * `updated_at` - (String) Standard RFC 3339 Date Time String. * `worker` - (List) Details of the worker used to run the pipeline. Nested schema for **worker**: diff --git a/website/docs/d/cd_tekton_pipeline_definition.html.markdown b/website/docs/d/cd_tekton_pipeline_definition.html.markdown index 1348def3eb..f375310174 100644 --- a/website/docs/d/cd_tekton_pipeline_definition.html.markdown +++ b/website/docs/d/cd_tekton_pipeline_definition.html.markdown @@ -8,20 +8,20 @@ subcategory: "Continuous Delivery" # ibm_cd_tekton_pipeline_definition -Provides a read-only data source for cd_tekton_pipeline_definition. You can then reference the fields of the data source in other resources within the same configuration using interpolation syntax. +Provides a read-only data source to retrieve information about a cd_tekton_pipeline_definition. You can then reference the fields of the data source in other resources within the same configuration by using interpolation syntax. ## Example Usage ```hcl data "ibm_cd_tekton_pipeline_definition" "cd_tekton_pipeline_definition" { - definition_id = ibm_cd_tekton_pipeline_definition.cd_tekton_pipeline_definition.definition_id - pipeline_id = ibm_cd_tekton_pipeline_definition.cd_tekton_pipeline_definition.pipeline_id + definition_id = ibm_cd_tekton_pipeline_definition.cd_tekton_pipeline_definition_instance.definition_id + pipeline_id = ibm_cd_tekton_pipeline_definition.cd_tekton_pipeline_definition_instance.pipeline_id } ``` ## Argument Reference -Review the argument reference that you can specify for your data source. +You can specify the following arguments for this data source. * `definition_id` - (Required, Forces new resource, String) The definition ID. * Constraints: The maximum length is `36` characters. The minimum length is `36` characters. The value must match regular expression `/^[-0-9a-z]+$/`. @@ -30,7 +30,7 @@ Review the argument reference that you can specify for your data source. ## Attribute Reference -In addition to all argument references listed, you can access the following attribute references after your data source is created. +After your data source is created, you can read values from the following attributes. * `id` - The unique identifier of the cd_tekton_pipeline_definition. * `href` - (String) API URL for interacting with the definition. diff --git a/website/docs/d/cd_tekton_pipeline_property.html.markdown b/website/docs/d/cd_tekton_pipeline_property.html.markdown index 2316b7e8af..d835cf35a8 100644 --- a/website/docs/d/cd_tekton_pipeline_property.html.markdown +++ b/website/docs/d/cd_tekton_pipeline_property.html.markdown @@ -8,20 +8,20 @@ subcategory: "Continuous Delivery" # ibm_cd_tekton_pipeline_property -Provides a read-only data source for cd_tekton_pipeline_property. You can then reference the fields of the data source in other resources within the same configuration using interpolation syntax. +Provides a read-only data source to retrieve information about a cd_tekton_pipeline_property. You can then reference the fields of the data source in other resources within the same configuration by using interpolation syntax. ## Example Usage ```hcl data "ibm_cd_tekton_pipeline_property" "cd_tekton_pipeline_property" { - pipeline_id = ibm_cd_tekton_pipeline_property.cd_tekton_pipeline_property.pipeline_id + pipeline_id = ibm_cd_tekton_pipeline_property.cd_tekton_pipeline_property_instance.pipeline_id property_name = "debug-pipeline" } ``` ## Argument Reference -Review the argument reference that you can specify for your data source. +You can specify the following arguments for this data source. * `pipeline_id` - (Required, Forces new resource, String) The Tekton pipeline ID. * Constraints: The maximum length is `36` characters. The minimum length is `36` characters. The value must match regular expression `/^[-0-9a-z]+$/`. @@ -30,26 +30,20 @@ Review the argument reference that you can specify for your data source. ## Attribute Reference -In addition to all argument references listed, you can access the following attribute references after your data source is created. +After your data source is created, you can read values from the following attributes. * `id` - The unique identifier of the cd_tekton_pipeline_property. * `enum` - (List) Options for `single_select` property type. Only needed when using `single_select` property type. * Constraints: The list items must match regular expression `/^[-0-9a-zA-Z_.]{1,253}$/`. The maximum length is `256` items. The minimum length is `0` items. - * `href` - (String) API URL for interacting with the property. * Constraints: The maximum length is `2048` characters. The minimum length is `10` characters. The value must match regular expression `/^http(s)?:\/\/([^\/?#]*)([^?#]*)(\\?([^#]*))?(#(.*))?$/`. - * `locked` - (Boolean) When true, this property cannot be overridden by a trigger property or at runtime. Attempting to override it will result in run requests being rejected. The default is false. - * `name` - (Forces new resource, String) Property name. * Constraints: The maximum length is `253` characters. The minimum length is `1` character. The value must match regular expression `/^[-0-9a-zA-Z_.]{1,253}$/`. - * `path` - (String) A dot notation path for `integration` type properties only, that selects a value from the tool integration. If left blank the full tool integration data will be used. * Constraints: The maximum length is `4096` characters. The minimum length is `0` characters. The value must match regular expression `/^[-0-9a-zA-Z_.]*$/`. - * `type` - (Forces new resource, String) Property type. * Constraints: Allowable values are: `secure`, `text`, `integration`, `single_select`, `appconfig`. - * `value` - (String) Property value. Any string value is valid. * Constraints: The maximum length is `4096` characters. The minimum length is `0` characters. The value must match regular expression `/^.*$/`. diff --git a/website/docs/d/cd_tekton_pipeline_trigger.html.markdown b/website/docs/d/cd_tekton_pipeline_trigger.html.markdown index 4ad6e433cf..00ccf5ac2f 100644 --- a/website/docs/d/cd_tekton_pipeline_trigger.html.markdown +++ b/website/docs/d/cd_tekton_pipeline_trigger.html.markdown @@ -8,20 +8,20 @@ subcategory: "Continuous Delivery" # ibm_cd_tekton_pipeline_trigger -Provides a read-only data source for cd_tekton_pipeline_trigger. You can then reference the fields of the data source in other resources within the same configuration using interpolation syntax. +Provides a read-only data source to retrieve information about a cd_tekton_pipeline_trigger. You can then reference the fields of the data source in other resources within the same configuration by using interpolation syntax. ## Example Usage ```hcl data "ibm_cd_tekton_pipeline_trigger" "cd_tekton_pipeline_trigger" { - pipeline_id = ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger.pipeline_id - trigger_id = ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger.trigger_id + pipeline_id = ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger_instance.pipeline_id + trigger_id = ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger_instance.trigger_id } ``` ## Argument Reference -Review the argument reference that you can specify for your data source. +You can specify the following arguments for this data source. * `pipeline_id` - (Required, Forces new resource, String) The Tekton pipeline ID. * Constraints: The maximum length is `36` characters. The minimum length is `36` characters. The value must match regular expression `/^[-0-9a-z]+$/`. @@ -30,35 +30,26 @@ Review the argument reference that you can specify for your data source. ## Attribute Reference -In addition to all argument references listed, you can access the following attribute references after your data source is created. +After your data source is created, you can read values from the following attributes. * `id` - The unique identifier of the cd_tekton_pipeline_trigger. * `cron` - (String) Only needed for timer triggers. CRON expression that indicates when this trigger will activate. Maximum frequency is every 5 minutes. The string is based on UNIX crontab syntax: minute, hour, day of month, month, day of week. Example: The CRON expression 0 *_/2 * * * - translates to - every 2 hours. * Constraints: The maximum length is `253` characters. The minimum length is `5` characters. The value must match regular expression `/^[-0-9a-zA-Z,\\*\/ ]{5,253}$/`. - * `enable_events_from_forks` - (Boolean) When enabled, pull request events from forks of the selected repository will trigger a pipeline run. * Constraints: The default value is `false`. - * `enabled` - (Boolean) Flag to check if the trigger is enabled. * Constraints: The default value is `true`. - * `event_listener` - (String) Event listener name. The name of the event listener to which the trigger is associated. The event listeners are defined in the definition repositories of the Tekton pipeline. * Constraints: The maximum length is `253` characters. The minimum length is `1` character. The value must match regular expression `/^[-0-9a-zA-Z_.]{1,253}$/`. - * `events` - (List) Either 'events' or 'filter' is required specifically for Git triggers. Stores a list of events that a Git trigger listens to. Choose one or more from 'push', 'pull_request', and 'pull_request_closed'. If SCM repositories use the 'merge request' term, they correspond to the generic term i.e. 'pull request'. * Constraints: Allowable list items are: `push`, `pull_request`, `pull_request_closed`. The maximum length is `3` items. The minimum length is `0` items. - * `favorite` - (Boolean) Mark the trigger as a favorite. * Constraints: The default value is `false`. - * `filter` - (String) Either 'events' or 'filter' can be used. Stores the CEL (Common Expression Language) expression value which is used for event filtering against the Git webhook payloads. * Constraints: The maximum length is `4096` characters. The minimum length is `1` character. The value must match regular expression `/^.*$/`. - * `href` - (String) API URL for interacting with the trigger. Only included when fetching the list of pipeline triggers. * Constraints: The maximum length is `2048` characters. The minimum length is `10` characters. The value must match regular expression `/^http(s)?:\/\/([^\/?#]*)([^?#]*)(\\?([^#]*))?(#(.*))?$/`. - * `max_concurrent_runs` - (Integer) Defines the maximum number of concurrent runs for this trigger. If omitted then the concurrency limit is disabled for this trigger. - * `name` - (String) Trigger name. * Constraints: The maximum length is `253` characters. The minimum length is `1` character. The value must match regular expression `/^([a-zA-Z0-9]{1,2}|[a-zA-Z0-9][0-9a-zA-Z-_.: \/\\(\\)\\[\\]]{1,251}[a-zA-Z0-9])$/`. * `properties` - (List) Optional trigger properties are used to override or supplement the pipeline properties when triggering a pipeline run. @@ -108,16 +99,12 @@ Nested schema for **source**: * Constraints: The maximum length is `2048` characters. The minimum length is `10` characters. The value must match regular expression `/^http(s)?:\/\/([^\/?#]*)([^?#]*)(\\?([^#]*))?(#(.*))?$/`. * `type` - (String) The only supported source type is "git", indicating that the source is a git repository. * Constraints: The maximum length is `253` characters. The minimum length is `1` character. The value must match regular expression `/^git$/`. - * `tags` - (List) Optional trigger tags array. * Constraints: The list items must match regular expression `/^[-0-9a-zA-Z_.]{1,253}$/`. The maximum length is `128` items. The minimum length is `0` items. - * `timezone` - (String) Only used for timer triggers. Specify the timezone used for this timer trigger, which will ensure the CRON activates this trigger relative to the specified timezone. If no timezone is specified, the default timezone used is UTC. Valid timezones are those listed in the IANA timezone database, https://www.iana.org/time-zones. * Constraints: The maximum length is `253` characters. The minimum length is `1` character. The value must match regular expression `/^[-0-9a-zA-Z+_., \/]{1,253}$/`. - * `type` - (String) Trigger type. * Constraints: Allowable values are: `manual`, `scm`, `timer`, `generic`. - * `webhook_url` - (String) Webhook URL that can be used to trigger pipeline runs. * Constraints: The maximum length is `2048` characters. The minimum length is `10` characters. The value must match regular expression `/^http(s)?:\/\/([^\/?#]*)([^?#]*)(\\?([^#]*))?(#(.*))?$/`. * `worker` - (List) Details of the worker used to run the trigger. diff --git a/website/docs/d/cd_tekton_pipeline_trigger_property.html.markdown b/website/docs/d/cd_tekton_pipeline_trigger_property.html.markdown index fcdfffa3e9..bda05caaaa 100644 --- a/website/docs/d/cd_tekton_pipeline_trigger_property.html.markdown +++ b/website/docs/d/cd_tekton_pipeline_trigger_property.html.markdown @@ -8,21 +8,21 @@ subcategory: "Continuous Delivery" # ibm_cd_tekton_pipeline_trigger_property -Provides a read-only data source for cd_tekton_pipeline_trigger_property. You can then reference the fields of the data source in other resources within the same configuration using interpolation syntax. +Provides a read-only data source to retrieve information about a cd_tekton_pipeline_trigger_property. You can then reference the fields of the data source in other resources within the same configuration by using interpolation syntax. ## Example Usage ```hcl data "ibm_cd_tekton_pipeline_trigger_property" "cd_tekton_pipeline_trigger_property" { - pipeline_id = ibm_cd_tekton_pipeline_trigger_property.cd_tekton_pipeline_trigger_property.pipeline_id + pipeline_id = ibm_cd_tekton_pipeline_trigger_property.cd_tekton_pipeline_trigger_property_instance.pipeline_id property_name = "debug-pipeline" - trigger_id = ibm_cd_tekton_pipeline_trigger_property.cd_tekton_pipeline_trigger_property.trigger_id + trigger_id = ibm_cd_tekton_pipeline_trigger_property.cd_tekton_pipeline_trigger_property_instance.trigger_id } ``` ## Argument Reference -Review the argument reference that you can specify for your data source. +You can specify the following arguments for this data source. * `pipeline_id` - (Required, Forces new resource, String) The Tekton pipeline ID. * Constraints: The maximum length is `36` characters. The minimum length is `36` characters. The value must match regular expression `/^[-0-9a-z]+$/`. @@ -33,26 +33,20 @@ Review the argument reference that you can specify for your data source. ## Attribute Reference -In addition to all argument references listed, you can access the following attribute references after your data source is created. +After your data source is created, you can read values from the following attributes. * `id` - The unique identifier of the cd_tekton_pipeline_trigger_property. * `enum` - (List) Options for `single_select` property type. Only needed for `single_select` property type. * Constraints: The list items must match regular expression `/^[-0-9a-zA-Z_.]{1,253}$/`. The maximum length is `256` items. The minimum length is `0` items. - * `href` - (String) API URL for interacting with the trigger property. * Constraints: The maximum length is `2048` characters. The minimum length is `10` characters. The value must match regular expression `/^http(s)?:\/\/([^\/?#]*)([^?#]*)(\\?([^#]*))?(#(.*))?$/`. - * `locked` - (Boolean) When true, this property cannot be overridden at runtime. Attempting to override it will result in run requests being rejected. The default is false. - * `name` - (Forces new resource, String) Property name. * Constraints: The maximum length is `253` characters. The minimum length is `1` character. The value must match regular expression `/^[-0-9a-zA-Z_.]{1,253}$/`. - * `path` - (String) A dot notation path for `integration` type properties only, that selects a value from the tool integration. If left blank the full tool integration data will be used. * Constraints: The maximum length is `4096` characters. The minimum length is `0` characters. The value must match regular expression `/^[-0-9a-zA-Z_.]*$/`. - * `type` - (Forces new resource, String) Property type. * Constraints: Allowable values are: `secure`, `text`, `integration`, `single_select`, `appconfig`. - * `value` - (String) Property value. Any string value is valid. * Constraints: The maximum length is `4096` characters. The minimum length is `0` characters. The value must match regular expression `/^.*$/`. diff --git a/website/docs/r/cd_tekton_pipeline.html.markdown b/website/docs/r/cd_tekton_pipeline.html.markdown index d590c73d07..06df3abfe3 100644 --- a/website/docs/r/cd_tekton_pipeline.html.markdown +++ b/website/docs/r/cd_tekton_pipeline.html.markdown @@ -8,7 +8,7 @@ subcategory: "Continuous Delivery" # ibm_cd_tekton_pipeline -Provides a resource for cd_tekton_pipeline. This allows cd_tekton_pipeline to be created, updated and deleted. +Create, update, and delete cd_tekton_pipelines with this resource. ## Example Usage @@ -23,24 +23,26 @@ resource "ibm_cd_tekton_pipeline" "cd_tekton_pipeline_instance" { ## Argument Reference -Review the argument reference that you can specify for your resource. +You can specify the following arguments for this resource. * `pipeline_id` - (Required, String) ID of the pipeline tool in your toolchain. Can be referenced from your `ibm_cd_toolchain_tool_pipeline` resource, e.g. `pipeline_id = ibm_cd_toolchain_tool_pipeline.my_pipeline.tool_id` * Constraints: The maximum length is `36` characters. The minimum length is `36` characters. The value must match regular expression `/^[-0-9a-z]+$/`. -* `enable_notifications` - (Optional, Boolean) Flag to enable notifications for this pipeline. If enabled, the Tekton pipeline run events will be published to all the destinations specified by the Slack and Event Notifications integrations in the parent toolchain. - * Constraints: The default value is `false`. -* `enable_partial_cloning` - (Optional, Boolean) Flag to enable partial cloning for this pipeline. When partial clone is enabled, only the files contained within the paths specified in definition repositories are read and cloned, this means that symbolic links might not work. - * Constraints: The default value is `false`. -* `next_build_number` - (Optional, Integer) Specify the build number that will be used for the next pipeline run. Build numbers can be any positive whole number between 0 and 100000000000000. +* `enable_notifications` - (Optional, Boolean) Flag to enable notifications for this pipeline. If enabled, the Tekton pipeline run events will be published to all the destinations specified by the Slack and Event Notifications integrations in the parent toolchain. If omitted, this feature is disabled by default. +* `enable_partial_cloning` - (Optional, Boolean) Flag to enable partial cloning for this pipeline. When partial clone is enabled, only the files contained within the paths specified in definition repositories are read and cloned, this means that symbolic links might not work. If omitted, this feature is disabled by default. +* `next_build_number` - (Optional, Integer) The build number that will be used for the next pipeline run. * Constraints: The maximum value is `99999999999999`. The minimum value is `1`. -* `worker` - (Optional, List) Specify the worker that is to be used to run the trigger, indicated by a worker object with only the worker ID. If not specified or set as `worker: { id: 'public' }`, the IBM Managed shared workers are used. +* `worker` - (Optional, List) Details of the worker used to run the pipeline. Nested schema for **worker**: * `id` - (Required, String) ID of the worker. - * Constraints: The maximum length is `253` characters. The minimum length is `1` character. The value must match regular expression `/^[-0-9a-zA-Z]{1,253}$/`. + * Constraints: The maximum length is `36` characters. The minimum length is `1` character. The value must match regular expression `/^[-0-9a-zA-Z]{1,36}$/`. + * `name` - (Computed, String) Name of the worker. Computed based on the worker ID. + * Constraints: The maximum length is `253` characters. The minimum length is `1` character. The value must match regular expression `/^[-0-9a-zA-Z_. \\(\\)\\[\\]]{1,253}$/`. + * `type` - (Computed, String) Type of the worker. Computed based on the worker ID. + * Constraints: The maximum length is `253` characters. The minimum length is `1` character. The value must match regular expression `/^[-0-9a-zA-Z_.]{1,253}$/`. ## Attribute Reference -In addition to all argument references listed, you can access the following attribute references after your resource is created. +After your resource is created, you can read values from the listed arguments and the following attributes. * `id` - The unique identifier of the cd_tekton_pipeline. * `build_number` - (Integer) The latest pipeline run build number. If this property is absent, the pipeline hasn't had any pipeline runs. @@ -105,7 +107,7 @@ Nested schema for **resource_group**: Nested schema for **toolchain**: * `crn` - (String) The CRN for the toolchain that contains the Tekton pipeline. * Constraints: The maximum length is `512` characters. The minimum length is `9` characters. The value must match regular expression `/^crn:v[0-9](:([A-Za-z0-9-._~!$&'()*+,;=@\/]|%[0-9A-Z]{2})*){8}$/`. - * `id` - (String) UUID. + * `id` - (String) Universally Unique Identifier. * Constraints: The maximum length is `36` characters. The minimum length is `36` characters. The value must match regular expression `/^[-0-9a-z]+$/`. * `triggers` - (List) Tekton pipeline triggers list. * Constraints: The maximum length is `1024` items. The minimum length is `0` items. @@ -199,9 +201,9 @@ Nested schema for **triggers**: ## Import -You can import the `ibm_cd_tekton_pipeline` resource by using `id`. UUID. +You can import the `ibm_cd_tekton_pipeline` resource by using `id`. Universally Unique Identifier. # Syntax -``` -$ terraform import ibm_cd_tekton_pipeline.cd_tekton_pipeline -``` +
+$ terraform import ibm_cd_tekton_pipeline.cd_tekton_pipeline <id>
+
diff --git a/website/docs/r/cd_tekton_pipeline_definition.html.markdown b/website/docs/r/cd_tekton_pipeline_definition.html.markdown index 12d0be686d..8d3d9bc0d4 100644 --- a/website/docs/r/cd_tekton_pipeline_definition.html.markdown +++ b/website/docs/r/cd_tekton_pipeline_definition.html.markdown @@ -8,7 +8,7 @@ subcategory: "Continuous Delivery" # ibm_cd_tekton_pipeline_definition -Provides a resource for cd_tekton_pipeline_definition. This allows cd_tekton_pipeline_definition to be created, updated and deleted. +Create, update, and delete cd_tekton_pipeline_definitions with this resource. ## Example Usage @@ -32,7 +32,7 @@ resource "ibm_cd_tekton_pipeline_definition" "cd_tekton_pipeline_definition_inst ## Argument Reference -Review the argument reference that you can specify for your resource. +You can specify the following arguments for this resource. * `pipeline_id` - (Required, Forces new resource, String) The Tekton pipeline ID. * Constraints: The maximum length is `36` characters. The minimum length is `36` characters. The value must match regular expression `/^[-0-9a-z]+$/`. @@ -57,7 +57,7 @@ Nested schema for **source**: ## Attribute Reference -In addition to all argument references listed, you can access the following attribute references after your resource is created. +After your resource is created, you can read values from the listed arguments and the following attributes. * `id` - The unique identifier of the cd_tekton_pipeline_definition. * `definition_id` - (String) The aggregated definition ID. @@ -75,9 +75,9 @@ The `id` property can be formed from `pipeline_id`, and `definition_id` in the f <pipeline_id>/<definition_id> * `pipeline_id`: A string in the format `94619026-912b-4d92-8f51-6c74f0692d90`. The Tekton pipeline ID. -* `definition_id`: A string in the format `94299034-d45f-4e9a-8ed5-6bd5c7bb7ada`. The definition ID. +* `definition_id`: A string. The aggregated definition ID. # Syntax -``` -$ terraform import ibm_cd_tekton_pipeline_definition.cd_tekton_pipeline_definition / -``` +
+$ terraform import ibm_cd_tekton_pipeline_definition.cd_tekton_pipeline_definition <pipeline_id>/<definition_id>
+
diff --git a/website/docs/r/cd_tekton_pipeline_property.html.markdown b/website/docs/r/cd_tekton_pipeline_property.html.markdown index fbc85ec9d0..41372a07fc 100644 --- a/website/docs/r/cd_tekton_pipeline_property.html.markdown +++ b/website/docs/r/cd_tekton_pipeline_property.html.markdown @@ -8,7 +8,7 @@ subcategory: "Continuous Delivery" # ibm_cd_tekton_pipeline_property -Provides a resource for cd_tekton_pipeline_property. This allows cd_tekton_pipeline_property to be created, updated and deleted. +Create, update, and delete cd_tekton_pipeline_propertys with this resource. ## Example Usage @@ -23,15 +23,14 @@ resource "ibm_cd_tekton_pipeline_property" "cd_tekton_pipeline_property_instance ## Argument Reference -Review the argument reference that you can specify for your resource. +You can specify the following arguments for this resource. * `enum` - (Optional, List) Options for `single_select` property type. Only needed when using `single_select` property type. * Constraints: The list items must match regular expression `/^[-0-9a-zA-Z_.]{1,253}$/`. The maximum length is `256` items. The minimum length is `0` items. * `locked` - (Optional, Boolean) When true, this property cannot be overridden by a trigger property or at runtime. Attempting to override it will result in run requests being rejected. The default is false. - * Constraints: The default value is `false`. * `name` - (Required, Forces new resource, String) Property name. * Constraints: The maximum length is `253` characters. The minimum length is `1` character. The value must match regular expression `/^[-0-9a-zA-Z_.]{1,253}$/`. -* `path` - (Optional, String) A dot notation path for `integration` type properties only, to select a value from the tool integration. If left blank the full tool integration data will be used. +* `path` - (Optional, String) A dot notation path for `integration` type properties only, that selects a value from the tool integration. If left blank the full tool integration data will be used. * Constraints: The maximum length is `4096` characters. The minimum length is `0` characters. The value must match regular expression `/^[-0-9a-zA-Z_.]*$/`. * `pipeline_id` - (Required, Forces new resource, String) The Tekton pipeline ID. * Constraints: The maximum length is `36` characters. The minimum length is `36` characters. The value must match regular expression `/^[-0-9a-z]+$/`. @@ -42,7 +41,7 @@ Review the argument reference that you can specify for your resource. ## Attribute Reference -In addition to all argument references listed, you can access the following attribute references after your resource is created. +After your resource is created, you can read values from the listed arguments and the following attributes. * `id` - The unique identifier of the cd_tekton_pipeline_property. * `href` - (String) API URL for interacting with the property. @@ -52,15 +51,15 @@ In addition to all argument references listed, you can access the following attr ## Import You can import the `ibm_cd_tekton_pipeline_property` resource by using `name`. -The `name` property can be formed from `pipeline_id`, and `property_name` in the following format: +The `name` property can be formed from `pipeline_id`, and `name` in the following format:
-<pipeline_id>/<property_name>
+<pipeline_id>/<name>
 
* `pipeline_id`: A string in the format `94619026-912b-4d92-8f51-6c74f0692d90`. The Tekton pipeline ID. -* `property_name`: A string in the format `debug-pipeline`. The property name. +* `name`: A string in the format `prop1`. Property name. # Syntax -``` -$ terraform import ibm_cd_tekton_pipeline_property.cd_tekton_pipeline_property / -``` +
+$ terraform import ibm_cd_tekton_pipeline_property.cd_tekton_pipeline_property <pipeline_id>/<name>
+
diff --git a/website/docs/r/cd_tekton_pipeline_trigger.html.markdown b/website/docs/r/cd_tekton_pipeline_trigger.html.markdown index 433e285537..1a907a2eff 100644 --- a/website/docs/r/cd_tekton_pipeline_trigger.html.markdown +++ b/website/docs/r/cd_tekton_pipeline_trigger.html.markdown @@ -8,7 +8,7 @@ subcategory: "Continuous Delivery" # ibm_cd_tekton_pipeline_trigger -Provides a resource for cd_tekton_pipeline_trigger. This allows cd_tekton_pipeline_trigger to be created, updated and deleted. +Create, update, and delete cd_tekton_pipeline_triggers with this resource. ## Example Usage @@ -27,13 +27,13 @@ resource "ibm_cd_tekton_pipeline_trigger" "cd_tekton_pipeline_trigger_instance" ## Argument Reference -Review the argument reference that you can specify for your resource. +You can specify the following arguments for this resource. * `cron` - (Optional, String) Only needed for timer triggers. CRON expression that indicates when this trigger will activate. Maximum frequency is every 5 minutes. The string is based on UNIX crontab syntax: minute, hour, day of month, month, day of week. Example: The CRON expression 0 *_/2 * * * - translates to - every 2 hours. * Constraints: The maximum length is `253` characters. The minimum length is `5` characters. The value must match regular expression `/^[-0-9a-zA-Z,\\*\/ ]{5,253}$/`. -* `enable_events_from_forks` - (Optional, Boolean) Only used for SCM triggers. When enabled, pull request events from forks of the selected repository will trigger a pipeline run. +* `enable_events_from_forks` - (Optional, Boolean) When enabled, pull request events from forks of the selected repository will trigger a pipeline run. * Constraints: The default value is `false`. -* `enabled` - (Optional, Boolean) Flag to check if the trigger is enabled. If omitted the trigger is enabled by default. +* `enabled` - (Optional, Boolean) Flag to check if the trigger is enabled. * Constraints: The default value is `true`. * `event_listener` - (Required, String) Event listener name. The name of the event listener to which the trigger is associated. The event listeners are defined in the definition repositories of the Tekton pipeline. * Constraints: The maximum length is `253` characters. The minimum length is `1` character. The value must match regular expression `/^[-0-9a-zA-Z_.]{1,253}$/`. @@ -64,28 +64,39 @@ Nested schema for **secret**: Nested schema for **source**: * `properties` - (Required, List) Properties of the source, which define the URL of the repository and a branch or pattern. Nested schema for **properties**: + * `blind_connection` - (Computed, Boolean) True if the repository server is not addressable on the public internet. IBM Cloud will not be able to validate the connection details you provide. * `branch` - (Optional, String) Name of a branch from the repo. Only one of branch, pattern, or filter should be specified. * Constraints: The maximum length is `253` characters. The minimum length is `1` character. The value must match regular expression `/^[-0-9a-zA-Z_.]{1,253}$/`. + * `hook_id` - (Computed, String) Repository webhook ID. It is generated upon trigger creation. + * Constraints: The maximum length is `253` characters. The minimum length is `1` character. The value must match regular expression `/^[-0-9a-zA-Z_.]{1,253}$/`. * `pattern` - (Optional, String) The pattern of Git branch or tag. You can specify a glob pattern such as '!test' or '*master' to match against multiple tags or branches in the repository.The glob pattern used must conform to Bash 4.3 specifications, see bash documentation for more info: https://www.gnu.org/software/bash/manual/bash.html#Pattern-Matching. Only one of branch, pattern, or filter should be specified. * Constraints: The maximum length is `253` characters. The minimum length is `1` character. The value must match regular expression `/^[-0-9a-zA-Z_.:@=$&^\/\\?\\!\\*\\+\\[\\]\\(\\)\\{\\}\\|\\\\]*$/`. + * `tool` - (Required, List) Reference to the repository tool in the parent toolchain. + Nested schema for **tool**: + * `id` - (Computed, String) ID of the repository tool instance in the parent toolchain. + * Constraints: The maximum length is `36` characters. The minimum length is `36` characters. The value must match regular expression `/^[-0-9a-z]+$/`. * `url` - (Required, Forces new resource, String) URL of the repository to which the trigger is listening. * Constraints: The maximum length is `2048` characters. The minimum length is `10` characters. The value must match regular expression `/^http(s)?:\/\/([^\/?#]*)([^?#]*)(\\?([^#]*))?(#(.*))?$/`. * `type` - (Required, String) The only supported source type is "git", indicating that the source is a git repository. * Constraints: The maximum length is `253` characters. The minimum length is `1` character. The value must match regular expression `/^git$/`. -* `tags` - (Optional, List) Trigger tags array. +* `tags` - (Optional, List) Optional trigger tags array. * Constraints: The list items must match regular expression `/^[-0-9a-zA-Z_.]{1,253}$/`. The maximum length is `128` items. The minimum length is `0` items. * `timezone` - (Optional, String) Only used for timer triggers. Specify the timezone used for this timer trigger, which will ensure the CRON activates this trigger relative to the specified timezone. If no timezone is specified, the default timezone used is UTC. Valid timezones are those listed in the IANA timezone database, https://www.iana.org/time-zones. * Constraints: The maximum length is `253` characters. The minimum length is `1` character. The value must match regular expression `/^[-0-9a-zA-Z+_., \/]{1,253}$/`. * `type` - (Required, String) Trigger type. - * Constraints: Allowable values are: `manual`, `scm`, `timer`, `generic`. -* `worker` - (Optional, List) Specify the worker used to run the trigger. Use `worker: { id: 'public' }` to use the IBM Managed workers. The default is to inherit the worker set in the pipeline settings, which can also be explicitly set using `worker: { id: 'inherit' }`. + * Constraints: Allowable values are: . +* `worker` - (Optional, List) Details of the worker used to run the trigger. Nested schema for **worker**: * `id` - (Required, String) ID of the worker. - * Constraints: The maximum length is `253` characters. The minimum length is `1` character. The value must match regular expression `/^[-0-9a-zA-Z]{1,253}$/`. + * Constraints: The maximum length is `36` characters. The minimum length is `1` character. The value must match regular expression `/^[-0-9a-zA-Z]{1,36}$/`. + * `name` - (Computed, String) Name of the worker. Computed based on the worker ID. + * Constraints: The maximum length is `253` characters. The minimum length is `1` character. The value must match regular expression `/^[-0-9a-zA-Z_. \\(\\)\\[\\]]{1,253}$/`. + * `type` - (Computed, String) Type of the worker. Computed based on the worker ID. + * Constraints: The maximum length is `253` characters. The minimum length is `1` character. The value must match regular expression `/^[-0-9a-zA-Z_.]{1,253}$/`. ## Attribute Reference -In addition to all argument references listed, you can access the following attribute references after your resource is created. +After your resource is created, you can read values from the listed arguments and the following attributes. * `id` - The unique identifier of the cd_tekton_pipeline_trigger. * `href` - (String) API URL for interacting with the trigger. Only included when fetching the list of pipeline triggers. @@ -121,9 +132,9 @@ The `id` property can be formed from `pipeline_id`, and `trigger_id` in the foll <pipeline_id>/<trigger_id> * `pipeline_id`: A string in the format `94619026-912b-4d92-8f51-6c74f0692d90`. The Tekton pipeline ID. -* `trigger_id`: A string in the format `1bb892a1-2e04-4768-a369-b1159eace147`. The trigger ID. +* `trigger_id`: A string. The Trigger ID. # Syntax -``` -$ terraform import ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger / -``` +
+$ terraform import ibm_cd_tekton_pipeline_trigger.cd_tekton_pipeline_trigger <pipeline_id>/<trigger_id>
+
diff --git a/website/docs/r/cd_tekton_pipeline_trigger_property.html.markdown b/website/docs/r/cd_tekton_pipeline_trigger_property.html.markdown index 0947a3d79b..4d99239b73 100644 --- a/website/docs/r/cd_tekton_pipeline_trigger_property.html.markdown +++ b/website/docs/r/cd_tekton_pipeline_trigger_property.html.markdown @@ -8,7 +8,7 @@ subcategory: "Continuous Delivery" # ibm_cd_tekton_pipeline_trigger_property -Provides a resource for cd_tekton_pipeline_trigger_property. This allows cd_tekton_pipeline_trigger_property to be created, updated and deleted. +Create, update, and delete cd_tekton_pipeline_trigger_propertys with this resource. ## Example Usage @@ -24,15 +24,14 @@ resource "ibm_cd_tekton_pipeline_trigger_property" "cd_tekton_pipeline_trigger_p ## Argument Reference -Review the argument reference that you can specify for your resource. +You can specify the following arguments for this resource. * `enum` - (Optional, List) Options for `single_select` property type. Only needed for `single_select` property type. * Constraints: The list items must match regular expression `/^[-0-9a-zA-Z_.]{1,253}$/`. The maximum length is `256` items. The minimum length is `0` items. * `locked` - (Optional, Boolean) When true, this property cannot be overridden at runtime. Attempting to override it will result in run requests being rejected. The default is false. - * Constraints: The default value is `false`. * `name` - (Required, Forces new resource, String) Property name. * Constraints: The maximum length is `253` characters. The minimum length is `1` character. The value must match regular expression `/^[-0-9a-zA-Z_.]{1,253}$/`. -* `path` - (Optional, String) A dot notation path for `integration` type properties only, to select a value from the tool integration. If left blank the full tool integration data will be used. +* `path` - (Optional, String) A dot notation path for `integration` type properties only, that selects a value from the tool integration. If left blank the full tool integration data will be used. * Constraints: The maximum length is `4096` characters. The minimum length is `0` characters. The value must match regular expression `/^[-0-9a-zA-Z_.]*$/`. * `pipeline_id` - (Required, Forces new resource, String) The Tekton pipeline ID. * Constraints: The maximum length is `36` characters. The minimum length is `36` characters. The value must match regular expression `/^[-0-9a-z]+$/`. @@ -45,7 +44,7 @@ Review the argument reference that you can specify for your resource. ## Attribute Reference -In addition to all argument references listed, you can access the following attribute references after your resource is created. +After your resource is created, you can read values from the listed arguments and the following attributes. * `id` - The unique identifier of the cd_tekton_pipeline_trigger_property. * `href` - (String) API URL for interacting with the trigger property. @@ -55,16 +54,16 @@ In addition to all argument references listed, you can access the following attr ## Import You can import the `ibm_cd_tekton_pipeline_trigger_property` resource by using `name`. -The `name` property can be formed from `pipeline_id`, `trigger_id`, and `property_name` in the following format: +The `name` property can be formed from `pipeline_id`, `trigger_id`, and `name` in the following format:
-<pipeline_id>/<trigger_id>/<property_name>
+<pipeline_id>/<trigger_id>/<name>
 
* `pipeline_id`: A string in the format `94619026-912b-4d92-8f51-6c74f0692d90`. The Tekton pipeline ID. * `trigger_id`: A string in the format `1bb892a1-2e04-4768-a369-b1159eace147`. The trigger ID. -* `property_name`: A string in the format `debug-pipeline`. The property name. +* `name`: A string in the format `prop1`. Property name. # Syntax -``` -$ terraform import ibm_cd_tekton_pipeline_trigger_property.cd_tekton_pipeline_trigger_property // -``` +
+$ terraform import ibm_cd_tekton_pipeline_trigger_property.cd_tekton_pipeline_trigger_property <pipeline_id>/<trigger_id>/<name>
+