Skip to content

Commit

Permalink
Tekton pipeline re-generated with latest SDK generator (IBM-Cloud#5715)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
briangleeson authored Oct 18, 2024
1 parent 2b5fc0f commit 568cc3a
Show file tree
Hide file tree
Showing 32 changed files with 4,078 additions and 1,374 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
370 changes: 186 additions & 184 deletions ibm/service/cdtektonpipeline/data_source_ibm_cd_tekton_pipeline.go

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -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 (
Expand All @@ -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 {
Expand Down Expand Up @@ -99,64 +105,67 @@ 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{}

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
}
modelMap["properties"] = []map[string]interface{}{propertiesMap}
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
}
Expand All @@ -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
}
Original file line number Diff line number Diff line change
@@ -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 (
Expand All @@ -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) {
Expand All @@ -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.#"),
),
},
},
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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)
}
Loading

0 comments on commit 568cc3a

Please sign in to comment.