Skip to content

Commit

Permalink
Make resources use the sds_endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Dylan-Christopherson committed Jan 11, 2025
1 parent 107c3df commit b87313b
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 19 deletions.
6 changes: 5 additions & 1 deletion examples/ibm-sdsaas/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Run `terraform destroy` when you don't need these resources.

```hcl
resource "ibm_sds_volume" "sds_volume_instance" {
sds_endpoint = var.sds_endpoint
hostnqnstring = var.sds_volume_hostnqnstring
capacity = var.sds_volume_capacity
name = var.sds_volume_name
Expand All @@ -35,6 +36,7 @@ resource "ibm_sds_volume" "sds_volume_instance" {
| Name | Description | Type | Required |
|------|-------------|------|---------|
| ibmcloud\_api\_key | IBM Cloud API key | `string` | true |
| sds_endpoint | IBM Cloud Endpoint | `string` | false |
| hostnqnstring | The host nqn. | `string` | false |
| capacity | The capacity of the volume (in gigabytes). | `number` | true |
| name | The name of the volume. | `string` | false |
Expand All @@ -55,6 +57,7 @@ resource "ibm_sds_volume" "sds_volume_instance" {

```hcl
resource "ibm_sds_host" "sds_host_instance" {
sds_endpoint = var.sds_endpoint
name = var.sds_host_name
nqn = var.sds_host_nqn
volumes = var.sds_host_volumes
Expand All @@ -66,6 +69,7 @@ resource "ibm_sds_host" "sds_host_instance" {
| Name | Description | Type | Required |
|------|-------------|------|---------|
| ibmcloud\_api\_key | IBM Cloud API key | `string` | true |
| sds_endpoint | IBM Cloud Endpoint | `string` | false |
| name | The name for this host. The name must not be used by another host. If unspecified, the name will be a hyphenated list of randomly-selected words. | `string` | false |
| nqn | The NQN of the host configured in customer's environment. | `string` | true |
| volumes | The host-to-volume map. | `list()` | false |
Expand All @@ -79,7 +83,7 @@ resource "ibm_sds_host" "sds_host_instance" {

## Assumptions

The `IBMCLOUD_SDS_ENDPOINT` is required to be set by the user before running the terraform commands. This is the endpoint provided to customers to perform operations against their service.
The `IBMCLOUD_SDS_ENDPOINT` can optionally be set instead of setting `sds_endpoint` in each of the resources. This is the endpoint provided to customers to perform operations against their service.

## Requirements

Expand Down
5 changes: 5 additions & 0 deletions examples/ibm-sdsaas/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,25 @@ provider "ibm" {

// Provision sds_volume resource instance
resource "ibm_sds_volume" "sds_volume_instance_1" {
sds_endpoint = var.sds_endpoint

hostnqnstring = var.sds_volume_hostnqnstring
capacity = var.sds_volume_capacity
name = var.sds_volume_name_1
}

// Provision sds_volume resource instance
resource "ibm_sds_volume" "sds_volume_instance_2" {
sds_endpoint = var.sds_endpoint

hostnqnstring = var.sds_volume_hostnqnstring
capacity = var.sds_volume_capacity
name = var.sds_volume_name_2
}

// Provision sds_host resource instance
resource "ibm_sds_host" "sds_host_instance" {
sds_endpoint = var.sds_endpoint

name = var.sds_host_name
nqn = var.sds_host_nqn
Expand Down
6 changes: 6 additions & 0 deletions examples/ibm-sdsaas/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ variable "ibmcloud_api_key" {
type = string
}

variable "sds_endpoint" {
description = "IBM SDS Endpoint"
type = string
default = "<endpoint>"
}

variable "sds_volume_hostnqnstring" {
description = "The host nqn."
type = string
Expand Down
7 changes: 4 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/IBM-Cloud/terraform-provider-ibm

go 1.23.0
go 1.22.5

toolchain go1.23.2

Expand Down Expand Up @@ -29,7 +29,7 @@ require (
github.com/IBM/ibm-hpcs-tke-sdk v0.0.0-20211109141421-a4b61b05f7d1
github.com/IBM/ibm-hpcs-uko-sdk v0.0.20-beta
github.com/IBM/keyprotect-go-client v0.15.1
github.com/IBM/logs-go-sdk v0.3.0
github.com/IBM/logs-go-sdk v0.4.0
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
Expand All @@ -39,7 +39,7 @@ require (
github.com/IBM/sarama v1.41.2
github.com/IBM/scc-go-sdk/v5 v5.4.1
github.com/IBM/schematics-go-sdk v0.3.0
github.com/IBM/sds-go-sdk v0.0.3
github.com/IBM/sds-go-sdk v0.0.4
github.com/IBM/secrets-manager-go-sdk/v2 v2.0.7
github.com/IBM/vmware-go-sdk v0.1.2
github.com/IBM/vpc-beta-go-sdk v0.8.0
Expand Down Expand Up @@ -205,6 +205,7 @@ require (
go.opentelemetry.io/otel v1.28.0 // indirect
go.opentelemetry.io/otel/metric v1.28.0 // indirect
go.opentelemetry.io/otel/trace v1.28.0 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/ratelimit v0.2.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/mod v0.21.0 // indirect
Expand Down
11 changes: 6 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ github.com/IBM/ibm-hpcs-uko-sdk v0.0.20-beta/go.mod h1:MLVNHMYoKsvovJZ4v1gQCpIYt
github.com/IBM/keyprotect-go-client v0.5.1/go.mod h1:5TwDM/4FRJq1ZOlwQL1xFahLWQ3TveR88VmL1u3njyI=
github.com/IBM/keyprotect-go-client v0.15.1 h1:m4qzqF5zOumRxKZ8s7vtK7A/UV/D278L8xpRG+WgT0s=
github.com/IBM/keyprotect-go-client v0.15.1/go.mod h1:asXtHwL/4uCHA221Vd/7SkXEi2pcRHDzPyyksc1DthE=
github.com/IBM/logs-go-sdk v0.3.0 h1:FHzTCCMyp9DvQGXgkppzcOPywC4ggt7x8xu0MR5h8xI=
github.com/IBM/logs-go-sdk v0.3.0/go.mod h1:yv/GCXC4/p+MZEeXl4xjZAOMvDAVRwu61WyHZFKFXQM=
github.com/IBM/logs-go-sdk v0.4.0 h1:CyUjm19EUtcJjf4mxsj6Rc7gkZDT8JEY5rLUIz8Eoag=
github.com/IBM/logs-go-sdk v0.4.0/go.mod h1:yv/GCXC4/p+MZEeXl4xjZAOMvDAVRwu61WyHZFKFXQM=
github.com/IBM/logs-router-go-sdk v1.0.5 h1:r0kC1+HfmSeQCD6zQTUp4PDI/zp4Ueo1Zo19ipHuNlw=
github.com/IBM/logs-router-go-sdk v1.0.5/go.mod h1:tCN2vFgu5xG0ob9iJcxi5M4bJ6mWmu3nhmRPnvlwev0=
github.com/IBM/mqcloud-go-sdk v0.2.0 h1:QOWk8ZGk0QfIL0MOGTKzNdM3Qe0Hk+ifAFtNSFQo5HU=
Expand All @@ -168,8 +168,8 @@ github.com/IBM/scc-go-sdk/v5 v5.4.1 h1:RXIuxOo9/hxkWyHCI69ae+KIJgSbXcAkJwTEl+fO3
github.com/IBM/scc-go-sdk/v5 v5.4.1/go.mod h1:2xQTDgNXG5QMEfQxBDKB067z+5ha6OgcaKCTcdGDAo8=
github.com/IBM/schematics-go-sdk v0.3.0 h1:Vwxw85SONflakiBsNHAfViKLyp9zJiH5/hh6SewOP5Q=
github.com/IBM/schematics-go-sdk v0.3.0/go.mod h1:Tw2OSAPdpC69AxcwoyqcYYaGTTW6YpERF9uNEU+BFRQ=
github.com/IBM/sds-go-sdk v0.0.3 h1:AlC2SOFdiD8hPHei7DIcwNLNq2ami3jDvb0MxZLpIE0=
github.com/IBM/sds-go-sdk v0.0.3/go.mod h1:mUak/6lrP0H7Pr5XBoZfosPe92cmV4emWMI4amRvAhQ=
github.com/IBM/sds-go-sdk v0.0.4 h1:zkkqDzc+TgFYU/BK4Oknv8cMBXJ08WKUu7yKCyzslvE=
github.com/IBM/sds-go-sdk v0.0.4/go.mod h1:HcqZfsgKMqfFxbU1RcRfF934ls+vQY97oXPGPSoIWPg=
github.com/IBM/secrets-manager-go-sdk/v2 v2.0.7 h1:5lKt1rHuKaAaiZtbPfsF8dgiko/gGbVgreiut3zU128=
github.com/IBM/secrets-manager-go-sdk/v2 v2.0.7/go.mod h1:RglK3v6CPe3T1myRtQCD6z+nBygXvNJwufAon0qcZok=
github.com/IBM/vmware-go-sdk v0.1.2 h1:5lKWFyInWz9e2hwGsoFTEoLa1jYkD30SReN0fQ10w9M=
Expand Down Expand Up @@ -1290,8 +1290,9 @@ go.opentelemetry.io/otel/trace v1.28.0/go.mod h1:jPyXzNPg6da9+38HEwElrQiHlVMTnVf
go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI=
go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw=
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE=
go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
Expand Down
1 change: 0 additions & 1 deletion ibm/conns/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3611,7 +3611,6 @@ func (c *Config) ClientSession() (interface{}, error) {
if session.sdsaasClientErr == nil {
// Construct the service options.
sdsaasClientOptions := &sdsaasv1.SdsaasV1Options{
URL: EnvFallBack([]string{"IBMCLOUD_SDS_ENDPOINT"}, ""),
Authenticator: authenticator,
}

Expand Down
18 changes: 13 additions & 5 deletions ibm/service/sdsaas/resource_ibm_sds_host.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"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-Cloud/terraform-provider-ibm/ibm/validate"
"github.com/IBM/go-sdk-core/v5/core"
Expand All @@ -31,6 +30,11 @@ func ResourceIBMSdsHost() *schema.Resource {
Importer: &schema.ResourceImporter{},

Schema: map[string]*schema.Schema{
"sds_endpoint": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Description: "The endpoint to use for operations",
},
"name": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -148,7 +152,8 @@ func ResourceIBMSdsHostValidator() *validate.ResourceValidator {
}

func resourceIBMSdsHostCreate(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
sdsaasClient, err := meta.(conns.ClientSession).SdsaasV1()
endpoint := d.Get("sds_endpoint").(string)
sdsaasClient, err := getSDSConfigClient(meta, endpoint)
if err != nil {
tfErr := flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_sds_host", "create", "initialize-client")
log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage())
Expand Down Expand Up @@ -187,7 +192,8 @@ func resourceIBMSdsHostCreate(context context.Context, d *schema.ResourceData, m
}

func resourceIBMSdsHostRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
sdsaasClient, err := meta.(conns.ClientSession).SdsaasV1()
endpoint := d.Get("sds_endpoint").(string)
sdsaasClient, err := getSDSConfigClient(meta, endpoint)
if err != nil {
tfErr := flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_sds_host", "read", "initialize-client")
log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage())
Expand Down Expand Up @@ -244,7 +250,8 @@ func resourceIBMSdsHostRead(context context.Context, d *schema.ResourceData, met
}

func resourceIBMSdsHostUpdate(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
sdsaasClient, err := meta.(conns.ClientSession).SdsaasV1()
endpoint := d.Get("sds_endpoint").(string)
sdsaasClient, err := getSDSConfigClient(meta, endpoint)
if err != nil {
tfErr := flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_sds_host", "update", "initialize-client")
log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage())
Expand Down Expand Up @@ -282,7 +289,8 @@ func resourceIBMSdsHostUpdate(context context.Context, d *schema.ResourceData, m
}

func resourceIBMSdsHostDelete(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
sdsaasClient, err := meta.(conns.ClientSession).SdsaasV1()
endpoint := d.Get("sds_endpoint").(string)
sdsaasClient, err := getSDSConfigClient(meta, endpoint)
if err != nil {
tfErr := flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_sds_host", "delete", "initialize-client")
log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage())
Expand Down
27 changes: 23 additions & 4 deletions ibm/service/sdsaas/resource_ibm_sds_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ func ResourceIBMSdsVolume() *schema.Resource {
Importer: &schema.ResourceImporter{},

Schema: map[string]*schema.Schema{
"sds_endpoint": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Description: "The endpoint to use for operations",
},
"hostnqnstring": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -110,6 +115,16 @@ func ResourceIBMSdsVolume() *schema.Resource {
}
}

func getSDSConfigClient(meta interface{}, endpoint string) (*sdsaasv1.SdsaasV1, error) {
sdsconfigClient, err := meta.(conns.ClientSession).SdsaasV1()
if err != nil {
return nil, err
}
url := conns.EnvFallBack([]string{"IBMCLOUD_SDS_ENDPOINT"}, endpoint)
sdsconfigClient.Service.Options.URL = url
return sdsconfigClient, nil
}

func ResourceIBMSdsVolumeValidator() *validate.ResourceValidator {
validateSchema := make([]validate.ValidateSchema, 0)
validateSchema = append(validateSchema,
Expand Down Expand Up @@ -138,7 +153,8 @@ func ResourceIBMSdsVolumeValidator() *validate.ResourceValidator {
}

func resourceIBMSdsVolumeCreate(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
sdsaasClient, err := meta.(conns.ClientSession).SdsaasV1()
endpoint := d.Get("sds_endpoint").(string)
sdsaasClient, err := getSDSConfigClient(meta, endpoint)
if err != nil {
tfErr := flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_sds_volume", "create", "initialize-client")
log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage())
Expand Down Expand Up @@ -168,7 +184,8 @@ func resourceIBMSdsVolumeCreate(context context.Context, d *schema.ResourceData,
}

func resourceIBMSdsVolumeRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
sdsaasClient, err := meta.(conns.ClientSession).SdsaasV1()
endpoint := d.Get("sds_endpoint").(string)
sdsaasClient, err := getSDSConfigClient(meta, endpoint)
if err != nil {
tfErr := flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_sds_volume", "read", "initialize-client")
log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage())
Expand Down Expand Up @@ -255,7 +272,8 @@ func resourceIBMSdsVolumeRead(context context.Context, d *schema.ResourceData, m
}

func resourceIBMSdsVolumeUpdate(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
sdsaasClient, err := meta.(conns.ClientSession).SdsaasV1()
endpoint := d.Get("sds_endpoint").(string)
sdsaasClient, err := getSDSConfigClient(meta, endpoint)
if err != nil {
tfErr := flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_sds_volume", "update", "initialize-client")
log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage())
Expand Down Expand Up @@ -298,7 +316,8 @@ func resourceIBMSdsVolumeUpdate(context context.Context, d *schema.ResourceData,
}

func resourceIBMSdsVolumeDelete(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
sdsaasClient, err := meta.(conns.ClientSession).SdsaasV1()
endpoint := d.Get("sds_endpoint").(string)
sdsaasClient, err := getSDSConfigClient(meta, endpoint)
if err != nil {
tfErr := flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_sds_volume", "delete", "initialize-client")
log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage())
Expand Down

0 comments on commit b87313b

Please sign in to comment.