Skip to content

Commit 704d281

Browse files
authored
chore: add cos tool integration support (#6271)
1 parent e009569 commit 704d281

File tree

80 files changed

+1430
-245
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+1430
-245
lines changed

ibm/acctest/acctest.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ var (
134134
imageName string
135135
functionNamespace string
136136
HpcsInstanceID string
137+
ToolchainID string
137138
)
138139

139140
// MQ on Cloud
@@ -2104,6 +2105,11 @@ func init() {
21042105
if PcsIamServiceRegistrationId == "" {
21052106
fmt.Println("[WARN] Set the environment variable PCS_IAM_TEGISTRATION_ID for testing iam_onboarding resource else tests will fail if this is not set correctly")
21062107
}
2108+
2109+
ToolchainID = os.Getenv("TOOLCHAIN_ID")
2110+
if ToolchainID == "" {
2111+
fmt.Println("[WARN] Set the environment variable TOOLCHAIN_ID for testing the COS toolchain integration tool else tests will fail if this is not set correctly")
2112+
}
21072113
}
21082114

21092115
var (

ibm/provider/provider.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,6 +1015,7 @@ func Provider() *schema.Provider {
10151015
"ibm_cd_toolchain_tool_securitycompliance": cdtoolchain.DataSourceIBMCdToolchainToolSecuritycompliance(),
10161016
"ibm_cd_toolchain_tool_privateworker": cdtoolchain.DataSourceIBMCdToolchainToolPrivateworker(),
10171017
"ibm_cd_toolchain_tool_appconfig": cdtoolchain.DataSourceIBMCdToolchainToolAppconfig(),
1018+
"ibm_cd_toolchain_tool_cos": cdtoolchain.DataSourceIBMCdToolchainToolCos(),
10181019
"ibm_cd_toolchain_tool_jenkins": cdtoolchain.DataSourceIBMCdToolchainToolJenkins(),
10191020
"ibm_cd_toolchain_tool_nexus": cdtoolchain.DataSourceIBMCdToolchainToolNexus(),
10201021
"ibm_cd_toolchain_tool_pagerduty": cdtoolchain.DataSourceIBMCdToolchainToolPagerduty(),
@@ -1680,6 +1681,7 @@ func Provider() *schema.Provider {
16801681
"ibm_cd_toolchain_tool_securitycompliance": cdtoolchain.ResourceIBMCdToolchainToolSecuritycompliance(),
16811682
"ibm_cd_toolchain_tool_privateworker": cdtoolchain.ResourceIBMCdToolchainToolPrivateworker(),
16821683
"ibm_cd_toolchain_tool_appconfig": cdtoolchain.ResourceIBMCdToolchainToolAppconfig(),
1684+
"ibm_cd_toolchain_tool_cos": cdtoolchain.ResourceIBMCdToolchainToolCos(),
16831685
"ibm_cd_toolchain_tool_jenkins": cdtoolchain.ResourceIBMCdToolchainToolJenkins(),
16841686
"ibm_cd_toolchain_tool_nexus": cdtoolchain.ResourceIBMCdToolchainToolNexus(),
16851687
"ibm_cd_toolchain_tool_pagerduty": cdtoolchain.ResourceIBMCdToolchainToolPagerduty(),
@@ -2139,6 +2141,7 @@ func Validator() validate.ValidatorDict {
21392141
"ibm_cd_toolchain_tool_securitycompliance": cdtoolchain.ResourceIBMCdToolchainToolSecuritycomplianceValidator(),
21402142
"ibm_cd_toolchain_tool_privateworker": cdtoolchain.ResourceIBMCdToolchainToolPrivateworkerValidator(),
21412143
"ibm_cd_toolchain_tool_appconfig": cdtoolchain.ResourceIBMCdToolchainToolAppconfigValidator(),
2144+
"ibm_cd_toolchain_tool_cos": cdtoolchain.ResourceIBMCdToolchainToolCosValidator(),
21422145
"ibm_cd_toolchain_tool_jenkins": cdtoolchain.ResourceIBMCdToolchainToolJenkinsValidator(),
21432146
"ibm_cd_toolchain_tool_nexus": cdtoolchain.ResourceIBMCdToolchainToolNexusValidator(),
21442147
"ibm_cd_toolchain_tool_pagerduty": cdtoolchain.ResourceIBMCdToolchainToolPagerdutyValidator(),

ibm/service/cdtoolchain/data_source_ibm_cd_toolchain.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright IBM Corp. 2024 All Rights Reserved.
1+
// Copyright IBM Corp. 2025 All Rights Reserved.
22
// Licensed under the Mozilla Public License v2.0
33

44
/*

ibm/service/cdtoolchain/data_source_ibm_cd_toolchain_tool_appconfig.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright IBM Corp. 2024 All Rights Reserved.
1+
// Copyright IBM Corp. 2025 All Rights Reserved.
22
// Licensed under the Mozilla Public License v2.0
33

44
/*

ibm/service/cdtoolchain/data_source_ibm_cd_toolchain_tool_artifactory.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright IBM Corp. 2024 All Rights Reserved.
1+
// Copyright IBM Corp. 2025 All Rights Reserved.
22
// Licensed under the Mozilla Public License v2.0
33

44
/*

ibm/service/cdtoolchain/data_source_ibm_cd_toolchain_tool_bitbucketgit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright IBM Corp. 2024 All Rights Reserved.
1+
// Copyright IBM Corp. 2025 All Rights Reserved.
22
// Licensed under the Mozilla Public License v2.0
33

44
/*
Lines changed: 234 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,234 @@
1+
// Copyright IBM Corp. 2025 All Rights Reserved.
2+
// Licensed under the Mozilla Public License v2.0
3+
4+
/*
5+
* IBM OpenAPI Terraform Generator Version: 3.96.0-d6dec9d7-20241008-212902
6+
*/
7+
8+
package cdtoolchain
9+
10+
import (
11+
"context"
12+
"fmt"
13+
"log"
14+
15+
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
16+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
17+
18+
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns"
19+
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex"
20+
"github.com/IBM/continuous-delivery-go-sdk/v2/cdtoolchainv2"
21+
"github.com/IBM/go-sdk-core/v5/core"
22+
)
23+
24+
func DataSourceIBMCdToolchainToolCos() *schema.Resource {
25+
return &schema.Resource{
26+
ReadContext: dataSourceIBMCdToolchainToolCosRead,
27+
28+
Schema: map[string]*schema.Schema{
29+
"toolchain_id": &schema.Schema{
30+
Type: schema.TypeString,
31+
Required: true,
32+
Description: "ID of the toolchain.",
33+
},
34+
"tool_id": &schema.Schema{
35+
Type: schema.TypeString,
36+
Required: true,
37+
Description: "ID of the tool bound to the toolchain.",
38+
},
39+
"resource_group_id": &schema.Schema{
40+
Type: schema.TypeString,
41+
Computed: true,
42+
Description: "Resource group where the tool is located.",
43+
},
44+
"crn": &schema.Schema{
45+
Type: schema.TypeString,
46+
Computed: true,
47+
Description: "Tool CRN.",
48+
},
49+
"toolchain_crn": &schema.Schema{
50+
Type: schema.TypeString,
51+
Computed: true,
52+
Description: "CRN of toolchain which the tool is bound to.",
53+
},
54+
"href": &schema.Schema{
55+
Type: schema.TypeString,
56+
Computed: true,
57+
Description: "URI representing the tool.",
58+
},
59+
"referent": &schema.Schema{
60+
Type: schema.TypeList,
61+
Computed: true,
62+
Description: "Information on URIs to access this resource through the UI or API.",
63+
Elem: &schema.Resource{
64+
Schema: map[string]*schema.Schema{
65+
"ui_href": &schema.Schema{
66+
Type: schema.TypeString,
67+
Computed: true,
68+
Description: "URI representing this resource through the UI.",
69+
},
70+
"api_href": &schema.Schema{
71+
Type: schema.TypeString,
72+
Computed: true,
73+
Description: "URI representing this resource through an API.",
74+
},
75+
},
76+
},
77+
},
78+
"name": &schema.Schema{
79+
Type: schema.TypeString,
80+
Computed: true,
81+
Description: "Name of the tool.",
82+
},
83+
"updated_at": &schema.Schema{
84+
Type: schema.TypeString,
85+
Computed: true,
86+
Description: "Latest tool update timestamp.",
87+
},
88+
"parameters": &schema.Schema{
89+
Type: schema.TypeList,
90+
Computed: true,
91+
Description: "Unique key-value pairs representing parameters to be used to create the tool. A list of parameters for each tool integration can be found in the <a href=\"https://cloud.ibm.com/docs/ContinuousDelivery?topic=ContinuousDelivery-integrations\">Configuring tool integrations page</a>.",
92+
Elem: &schema.Resource{
93+
Schema: map[string]*schema.Schema{
94+
"name": &schema.Schema{
95+
Type: schema.TypeString,
96+
Computed: true,
97+
Description: "The name used to identify this tool integration.",
98+
},
99+
"auth_type": &schema.Schema{
100+
Type: schema.TypeString,
101+
Computed: true,
102+
Description: "The authentication type. Options are `apikey` IBM Cloud API Key or `hmac` HMAC (Hash Message Authentication Code). The default is `apikey`.",
103+
},
104+
"cos_api_key": &schema.Schema{
105+
Type: schema.TypeString,
106+
Computed: true,
107+
Sensitive: true,
108+
Description: "The IBM Cloud API key used to access the Cloud Object Storage service. Only relevant when using `apikey` as the `auth_type`.",
109+
},
110+
"instance_crn": &schema.Schema{
111+
Type: schema.TypeString,
112+
Computed: true,
113+
Description: "The CRN (Cloud Resource Name) of the IBM Cloud Object Storage service instance, only relevant when using `apikey` as the `auth_type`.",
114+
},
115+
"bucket_name": &schema.Schema{
116+
Type: schema.TypeString,
117+
Computed: true,
118+
Description: "The name of the Cloud Object Storage service bucket.",
119+
},
120+
"endpoint": &schema.Schema{
121+
Type: schema.TypeString,
122+
Computed: true,
123+
Description: "The [Cloud Object Storage endpoint](https://cloud.ibm.com/docs/cloud-object-storage?topic=cloud-object-storage-endpoints) in IBM Cloud or other endpoint. For example for IBM Cloud Object Storage: `s3.direct.us-south.cloud-object-storage.appdomain.cloud`.",
124+
},
125+
"hmac_access_key_id": &schema.Schema{
126+
Type: schema.TypeString,
127+
Computed: true,
128+
Sensitive: true,
129+
Description: "The HMAC Access Key ID which is part of an HMAC (Hash Message Authentication Code) credential set. HMAC is identified by a combination of an Access Key ID and a Secret Access Key. Only relevant when `auth_type` is set to `hmac`.",
130+
},
131+
"hmac_secret_access_key": &schema.Schema{
132+
Type: schema.TypeString,
133+
Computed: true,
134+
Sensitive: true,
135+
Description: "The HMAC Secret Access Key which is part of an HMAC (Hash Message Authentication Code) credential set. HMAC is identified by a combination of an Access Key ID and a Secret Access Key. Only relevant when `auth_type` is set to `hmac`.",
136+
},
137+
},
138+
},
139+
},
140+
"state": &schema.Schema{
141+
Type: schema.TypeString,
142+
Computed: true,
143+
Description: "Current configuration state of the tool.",
144+
},
145+
},
146+
}
147+
}
148+
149+
func dataSourceIBMCdToolchainToolCosRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
150+
cdToolchainClient, err := meta.(conns.ClientSession).CdToolchainV2()
151+
if err != nil {
152+
tfErr := flex.DiscriminatedTerraformErrorf(err, err.Error(), "(Data) ibm_cd_toolchain_tool_cos", "read", "initialize-client")
153+
log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage())
154+
return tfErr.GetDiag()
155+
}
156+
157+
getToolByIDOptions := &cdtoolchainv2.GetToolByIDOptions{}
158+
159+
getToolByIDOptions.SetToolchainID(d.Get("toolchain_id").(string))
160+
getToolByIDOptions.SetToolID(d.Get("tool_id").(string))
161+
162+
toolchainTool, _, err := cdToolchainClient.GetToolByIDWithContext(context, getToolByIDOptions)
163+
if err != nil {
164+
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("GetToolByIDWithContext failed: %s", err.Error()), "(Data) ibm_cd_toolchain_tool_cos", "read")
165+
log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage())
166+
return tfErr.GetDiag()
167+
}
168+
169+
if *toolchainTool.ToolTypeID != "cloudobjectstorage" {
170+
return flex.TerraformErrorf(err, fmt.Sprintf("Retrieved tool is not the correct type: %s", err), "(Data) ibm_cd_toolchain_tool", "read").GetDiag()
171+
}
172+
173+
d.SetId(fmt.Sprintf("%s/%s", *getToolByIDOptions.ToolchainID, *getToolByIDOptions.ToolID))
174+
175+
if err = d.Set("resource_group_id", toolchainTool.ResourceGroupID); err != nil {
176+
return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting resource_group_id: %s", err), "(Data) ibm_cd_toolchain_tool_cos", "read", "set-resource_group_id").GetDiag()
177+
}
178+
179+
if err = d.Set("crn", toolchainTool.CRN); err != nil {
180+
return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting crn: %s", err), "(Data) ibm_cd_toolchain_tool_cos", "read", "set-crn").GetDiag()
181+
}
182+
183+
if err = d.Set("toolchain_crn", toolchainTool.ToolchainCRN); err != nil {
184+
return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting toolchain_crn: %s", err), "(Data) ibm_cd_toolchain_tool_cos", "read", "set-toolchain_crn").GetDiag()
185+
}
186+
187+
if err = d.Set("href", toolchainTool.Href); err != nil {
188+
return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting href: %s", err), "(Data) ibm_cd_toolchain_tool_cos", "read", "set-href").GetDiag()
189+
}
190+
191+
referent := []map[string]interface{}{}
192+
referentMap, err := DataSourceIBMCdToolchainToolCosToolModelReferentToMap(toolchainTool.Referent)
193+
if err != nil {
194+
return flex.DiscriminatedTerraformErrorf(err, err.Error(), "(Data) ibm_cd_toolchain_tool_cos", "read", "referent-to-map").GetDiag()
195+
}
196+
referent = append(referent, referentMap)
197+
if err = d.Set("referent", referent); err != nil {
198+
return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting referent: %s", err), "(Data) ibm_cd_toolchain_tool_cos", "read", "set-referent").GetDiag()
199+
}
200+
201+
if !core.IsNil(toolchainTool.Name) {
202+
if err = d.Set("name", toolchainTool.Name); err != nil {
203+
return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting name: %s", err), "(Data) ibm_cd_toolchain_tool_cos", "read", "set-name").GetDiag()
204+
}
205+
}
206+
207+
if err = d.Set("updated_at", flex.DateTimeToString(toolchainTool.UpdatedAt)); err != nil {
208+
return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting updated_at: %s", err), "(Data) ibm_cd_toolchain_tool_cos", "read", "set-updated_at").GetDiag()
209+
}
210+
211+
parameters := []map[string]interface{}{}
212+
parametersMap := GetParametersFromRead(toolchainTool.Parameters, DataSourceIBMCdToolchainToolCos(), nil)
213+
parameters = append(parameters, parametersMap)
214+
if err = d.Set("parameters", parameters); err != nil {
215+
return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting parameters: %s", err), "(Data) ibm_cd_toolchain_tool_cos", "read", "set-parameters").GetDiag()
216+
}
217+
218+
if err = d.Set("state", toolchainTool.State); err != nil {
219+
return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting state: %s", err), "(Data) ibm_cd_toolchain_tool_cos", "read", "set-state").GetDiag()
220+
}
221+
222+
return nil
223+
}
224+
225+
func DataSourceIBMCdToolchainToolCosToolModelReferentToMap(model *cdtoolchainv2.ToolModelReferent) (map[string]interface{}, error) {
226+
modelMap := make(map[string]interface{})
227+
if model.UIHref != nil {
228+
modelMap["ui_href"] = *model.UIHref
229+
}
230+
if model.APIHref != nil {
231+
modelMap["api_href"] = *model.APIHref
232+
}
233+
return modelMap, nil
234+
}

0 commit comments

Comments
 (0)