Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

IBM Cloud Shell: re-gen provider for adopting the new error toolchain #5904

Merged
merged 2 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .secrets.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"files": "go.mod|go.sum|.*.map|^.secrets.baseline$",
"lines": null
},
"generated_at": "2025-01-06T04:50:55Z",
"generated_at": "2025-01-08T04:55:16Z",
"plugins_used": [
{
"name": "AWSKeyDetector"
Expand Down Expand Up @@ -926,15 +926,15 @@
"hashed_secret": "c8b6f5ef11b9223ac35a5663975a466ebe7ebba9",
"is_secret": false,
"is_verified": false,
"line_number": 2352,
"line_number": 2355,
"type": "Secret Keyword",
"verified_result": null
},
{
"hashed_secret": "8abf4899c01104241510ba87685ad4de76b0c437",
"is_secret": false,
"is_verified": false,
"line_number": 2358,
"line_number": 2361,
"type": "Secret Keyword",
"verified_result": null
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ require (
github.com/IBM/logs-router-go-sdk v1.0.5
github.com/IBM/mqcloud-go-sdk v0.2.0
github.com/IBM/networking-go-sdk v0.49.0
github.com/IBM/platform-services-go-sdk v0.71.1
github.com/IBM/platform-services-go-sdk v0.72.0
github.com/IBM/project-go-sdk v0.3.5
github.com/IBM/push-notifications-go-sdk v0.0.0-20210310100607-5790b96c47f5
github.com/IBM/sarama v1.41.2
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ github.com/IBM/mqcloud-go-sdk v0.2.0 h1:QOWk8ZGk0QfIL0MOGTKzNdM3Qe0Hk+ifAFtNSFQo
github.com/IBM/mqcloud-go-sdk v0.2.0/go.mod h1:VZQKMtqmcdXKhmLhLiPuS/UHMs/5yo2tA/nD83cQt9E=
github.com/IBM/networking-go-sdk v0.49.0 h1:lPS34u3C0JVrbxH+Ulua76Nwl6Frv8BEfq6LRkyvOv0=
github.com/IBM/networking-go-sdk v0.49.0/go.mod h1:G9CKbmPE8gSLjN+ABh4hIZ1bMx076enl5Eekvj6zQnA=
github.com/IBM/platform-services-go-sdk v0.71.1 h1:EyqSctlLVqj092yU6K9hyTyx7JIpzhE192n6eG+Daac=
github.com/IBM/platform-services-go-sdk v0.71.1/go.mod h1:ApFkvqw7NaluWJ5Uq+afdM/2jQqo5ILc0SzKSVobYNw=
github.com/IBM/platform-services-go-sdk v0.72.0 h1:AfJe6bgqmTQU4ff/2URu3wkRLZD0XIzojn7SLf2yIns=
github.com/IBM/platform-services-go-sdk v0.72.0/go.mod h1:ApFkvqw7NaluWJ5Uq+afdM/2jQqo5ILc0SzKSVobYNw=
github.com/IBM/project-go-sdk v0.3.5 h1:L+YClFUa14foS0B/hOOY9n7sIdsT5/XQicnXOyJSpyM=
github.com/IBM/project-go-sdk v0.3.5/go.mod h1:FOJM9ihQV3EEAY6YigcWiTNfVCThtdY8bLC/nhQHFvo=
github.com/IBM/push-notifications-go-sdk v0.0.0-20210310100607-5790b96c47f5 h1:NPUhkoOCRuv3OFWt19PmwjXGGTKlvmbuPg9fUrBUNe4=
Expand Down
3 changes: 3 additions & 0 deletions ibm/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -1939,6 +1939,9 @@ func Validator() validate.ValidatorDict {
"ibm_hpcs_vault": hpcs.ResourceIbmVaultValidator(),
"ibm_config_aggregator_settings": configurationaggregator.ResourceIbmConfigAggregatorSettingsValidator(),

// Cloudshell
"ibm_cloud_shell_account_settings": cloudshell.ResourceIBMCloudShellAccountSettingsValidator(),

// MQ on Cloud
"ibm_mqcloud_queue_manager": mqcloud.ResourceIbmMqcloudQueueManagerValidator(),
"ibm_mqcloud_application": mqcloud.ResourceIbmMqcloudApplicationValidator(),
Expand Down
199 changes: 114 additions & 85 deletions ibm/service/cloudshell/data_source_ibm_cloud_shell_account_settings.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
// Copyright IBM Corp. 2021 All Rights Reserved.
// Copyright IBM Corp. 2024 All Rights Reserved.
// Licensed under the Mozilla Public License v2.0

/*
* IBM OpenAPI Terraform Generator Version: 3.98.0-8be2046a-20241205-162752
*/

package cloudshell

import (
"context"
"fmt"
"log"

"github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns"
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

"github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns"
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex"
"github.com/IBM/go-sdk-core/v5/core"
"github.com/IBM/platform-services-go-sdk/ibmcloudshellv1"
)

Expand All @@ -21,90 +26,90 @@ func DataSourceIBMCloudShellAccountSettings() *schema.Resource {
ReadContext: dataSourceIBMCloudShellAccountSettingsRead,

Schema: map[string]*schema.Schema{
"account_id": {
"account_id": &schema.Schema{
Type: schema.TypeString,
Required: true,
Description: "The account ID in which the account settings belong to.",
},
"rev": {
"rev": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "Unique revision number for the settings object.",
},
"created_at": {
"created_at": &schema.Schema{
Type: schema.TypeInt,
Computed: true,
Description: "Creation timestamp in Unix epoch time.",
},
"created_by": {
"created_by": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "IAM ID of creator.",
},
"default_enable_new_features": {
"default_enable_new_features": &schema.Schema{
Type: schema.TypeBool,
Computed: true,
Description: "You can choose which Cloud Shell features are available in the account and whether any new features are enabled as they become available. The feature settings apply only to the enabled Cloud Shell locations.",
},
"default_enable_new_regions": {
"default_enable_new_regions": &schema.Schema{
Type: schema.TypeBool,
Computed: true,
Description: "Set whether Cloud Shell is enabled in a specific location for the account. The location determines where user and session data are stored. By default, users are routed to the nearest available location.",
},
"enabled": {
"enabled": &schema.Schema{
Type: schema.TypeBool,
Computed: true,
Description: "When enabled, Cloud Shell is available to all users in the account.",
},
"features": {
"features": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Description: "List of Cloud Shell features.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"enabled": {
"enabled": &schema.Schema{
Type: schema.TypeBool,
Computed: true,
Description: "State of the feature.",
},
"key": {
"key": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "Name of the feature.",
},
},
},
},
"regions": {
"regions": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Description: "List of Cloud Shell region settings.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"enabled": {
"enabled": &schema.Schema{
Type: schema.TypeBool,
Computed: true,
Description: "State of the region.",
},
"key": {
"key": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "Name of the region.",
},
},
},
},
"type": {
"type": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "Type of api response object.",
},
"updated_at": {
"updated_at": &schema.Schema{
Type: schema.TypeInt,
Computed: true,
Description: "Timestamp of last update in Unix epoch time.",
},
"updated_by": {
"updated_by": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "IAM ID of last updater.",
Expand All @@ -116,103 +121,127 @@ func DataSourceIBMCloudShellAccountSettings() *schema.Resource {
func dataSourceIBMCloudShellAccountSettingsRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
ibmCloudShellClient, err := meta.(conns.ClientSession).IBMCloudShellV1()
if err != nil {
return diag.FromErr(err)
tfErr := flex.DiscriminatedTerraformErrorf(err, err.Error(), "(Data) ibm_cloud_shell_account_settings", "read", "initialize-client")
log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage())
return tfErr.GetDiag()
}

getAccountSettingsOptions := &ibmcloudshellv1.GetAccountSettingsOptions{}

getAccountSettingsOptions.SetAccountID(d.Get("account_id").(string))

accountSettings, response, err := ibmCloudShellClient.GetAccountSettingsWithContext(context, getAccountSettingsOptions)
if err != nil || accountSettings == nil {
log.Printf("[DEBUG] GetAccountSettingsWithContext failed %s\n%s", err, response)
return diag.FromErr(fmt.Errorf("GetAccountSettingsWithContext failed %s\n%s", err, response))
accountSettings, _, err := ibmCloudShellClient.GetAccountSettingsWithContext(context, getAccountSettingsOptions)
if err != nil {
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("GetAccountSettingsWithContext failed: %s", err.Error()), "(Data) ibm_cloud_shell_account_settings", "read")
log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage())
return tfErr.GetDiag()
}

d.SetId(*accountSettings.AccountID)
if err = d.Set("rev", accountSettings.Rev); err != nil {
return diag.FromErr(fmt.Errorf("[ERROR] Error setting rev: %s", err))
}
if err = d.Set("created_at", flex.IntValue(accountSettings.CreatedAt)); err != nil {
return diag.FromErr(fmt.Errorf("[ERROR] Error setting created_at: %s", err))
}
if err = d.Set("created_by", accountSettings.CreatedBy); err != nil {
return diag.FromErr(fmt.Errorf("[ERROR] Error setting created_by: %s", err))
}
if err = d.Set("default_enable_new_features", accountSettings.DefaultEnableNewFeatures); err != nil {
return diag.FromErr(fmt.Errorf("[ERROR] Error setting default_enable_new_features: %s", err))
}
if err = d.Set("default_enable_new_regions", accountSettings.DefaultEnableNewRegions); err != nil {
return diag.FromErr(fmt.Errorf("[ERROR] Error setting default_enable_new_regions: %s", err))
}
if err = d.Set("enabled", accountSettings.Enabled); err != nil {
return diag.FromErr(fmt.Errorf("[ERROR] Error setting enabled: %s", err))
}
d.SetId(*getAccountSettingsOptions.AccountID)

if accountSettings.Features != nil {
err = d.Set("features", dataSourceAccountSettingsFlattenFeatures(accountSettings.Features))
if err != nil {
return diag.FromErr(fmt.Errorf("[ERROR] Error setting features %s", err))
if !core.IsNil(accountSettings.Rev) {
if err = d.Set("rev", accountSettings.Rev); err != nil {
return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting rev: %s", err), "(Data) ibm_cloud_shell_account_settings", "read", "set-rev").GetDiag()
}
}

if accountSettings.Regions != nil {
err = d.Set("regions", dataSourceAccountSettingsFlattenRegions(accountSettings.Regions))
if err != nil {
return diag.FromErr(fmt.Errorf("[ERROR] Error setting regions %s", err))
if !core.IsNil(accountSettings.CreatedAt) {
if err = d.Set("created_at", flex.IntValue(accountSettings.CreatedAt)); err != nil {
return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting created_at: %s", err), "(Data) ibm_cloud_shell_account_settings", "read", "set-created_at").GetDiag()
}
}
if err = d.Set("type", accountSettings.Type); err != nil {
return diag.FromErr(fmt.Errorf("[ERROR] Error setting type: %s", err))

if !core.IsNil(accountSettings.CreatedBy) {
if err = d.Set("created_by", accountSettings.CreatedBy); err != nil {
return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting created_by: %s", err), "(Data) ibm_cloud_shell_account_settings", "read", "set-created_by").GetDiag()
}
}
if err = d.Set("updated_at", flex.IntValue(accountSettings.UpdatedAt)); err != nil {
return diag.FromErr(fmt.Errorf("[ERROR] Error setting updated_at: %s", err))

if !core.IsNil(accountSettings.DefaultEnableNewFeatures) {
if err = d.Set("default_enable_new_features", accountSettings.DefaultEnableNewFeatures); err != nil {
return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting default_enable_new_features: %s", err), "(Data) ibm_cloud_shell_account_settings", "read", "set-default_enable_new_features").GetDiag()
}
}
if err = d.Set("updated_by", accountSettings.UpdatedBy); err != nil {
return diag.FromErr(fmt.Errorf("[ERROR] Error setting updated_by: %s", err))

if !core.IsNil(accountSettings.DefaultEnableNewRegions) {
if err = d.Set("default_enable_new_regions", accountSettings.DefaultEnableNewRegions); err != nil {
return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting default_enable_new_regions: %s", err), "(Data) ibm_cloud_shell_account_settings", "read", "set-default_enable_new_regions").GetDiag()
}
}

return nil
}
if !core.IsNil(accountSettings.Enabled) {
if err = d.Set("enabled", accountSettings.Enabled); err != nil {
return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting enabled: %s", err), "(Data) ibm_cloud_shell_account_settings", "read", "set-enabled").GetDiag()
}
}

func dataSourceAccountSettingsFlattenFeatures(result []ibmcloudshellv1.Feature) (features []map[string]interface{}) {
for _, featuresItem := range result {
features = append(features, dataSourceAccountSettingsFeaturesToMap(featuresItem))
if !core.IsNil(accountSettings.Features) {
features := []map[string]interface{}{}
for _, featuresItem := range accountSettings.Features {
featuresItemMap, err := DataSourceIBMCloudShellAccountSettingsFeatureToMap(&featuresItem) // #nosec G601
if err != nil {
return flex.DiscriminatedTerraformErrorf(err, err.Error(), "(Data) ibm_cloud_shell_account_settings", "read", "features-to-map").GetDiag()
}
features = append(features, featuresItemMap)
}
if err = d.Set("features", features); err != nil {
return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting features: %s", err), "(Data) ibm_cloud_shell_account_settings", "read", "set-features").GetDiag()
}
}

return features
}
if !core.IsNil(accountSettings.Regions) {
regions := []map[string]interface{}{}
for _, regionsItem := range accountSettings.Regions {
regionsItemMap, err := DataSourceIBMCloudShellAccountSettingsRegionSettingToMap(&regionsItem) // #nosec G601
if err != nil {
return flex.DiscriminatedTerraformErrorf(err, err.Error(), "(Data) ibm_cloud_shell_account_settings", "read", "regions-to-map").GetDiag()
}
regions = append(regions, regionsItemMap)
}
if err = d.Set("regions", regions); err != nil {
return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting regions: %s", err), "(Data) ibm_cloud_shell_account_settings", "read", "set-regions").GetDiag()
}
}

func dataSourceAccountSettingsFeaturesToMap(featuresItem ibmcloudshellv1.Feature) (featuresMap map[string]interface{}) {
featuresMap = map[string]interface{}{}
if !core.IsNil(accountSettings.Type) {
if err = d.Set("type", accountSettings.Type); err != nil {
return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting type: %s", err), "(Data) ibm_cloud_shell_account_settings", "read", "set-type").GetDiag()
}
}

if featuresItem.Enabled != nil {
featuresMap["enabled"] = featuresItem.Enabled
if !core.IsNil(accountSettings.UpdatedAt) {
if err = d.Set("updated_at", flex.IntValue(accountSettings.UpdatedAt)); err != nil {
return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting updated_at: %s", err), "(Data) ibm_cloud_shell_account_settings", "read", "set-updated_at").GetDiag()
}
}
if featuresItem.Key != nil {
featuresMap["key"] = featuresItem.Key

if !core.IsNil(accountSettings.UpdatedBy) {
if err = d.Set("updated_by", accountSettings.UpdatedBy); err != nil {
return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting updated_by: %s", err), "(Data) ibm_cloud_shell_account_settings", "read", "set-updated_by").GetDiag()
}
}

return featuresMap
return nil
}

func dataSourceAccountSettingsFlattenRegions(result []ibmcloudshellv1.RegionSetting) (regions []map[string]interface{}) {
for _, regionsItem := range result {
regions = append(regions, dataSourceAccountSettingsRegionsToMap(regionsItem))
func DataSourceIBMCloudShellAccountSettingsFeatureToMap(model *ibmcloudshellv1.Feature) (map[string]interface{}, error) {
modelMap := make(map[string]interface{})
if model.Enabled != nil {
modelMap["enabled"] = *model.Enabled
}

return regions
if model.Key != nil {
modelMap["key"] = *model.Key
}
return modelMap, nil
}

func dataSourceAccountSettingsRegionsToMap(regionsItem ibmcloudshellv1.RegionSetting) (regionsMap map[string]interface{}) {
regionsMap = map[string]interface{}{}

if regionsItem.Enabled != nil {
regionsMap["enabled"] = regionsItem.Enabled
func DataSourceIBMCloudShellAccountSettingsRegionSettingToMap(model *ibmcloudshellv1.RegionSetting) (map[string]interface{}, error) {
modelMap := make(map[string]interface{})
if model.Enabled != nil {
modelMap["enabled"] = *model.Enabled
}
if regionsItem.Key != nil {
regionsMap["key"] = regionsItem.Key
if model.Key != nil {
modelMap["key"] = *model.Key
}

return regionsMap
return modelMap, nil
}
Loading
Loading