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

Add PhysicalAddress and CapabilitiesManagedBySatellite to Terraform SatelliteLocation for both resource and data-source #5530

Merged
merged 47 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
f4065ba
Changes to add Address
shrinkell May 13, 2024
875bd8d
Merge branch 'IBM-Cloud:master' into add_address
FishAndFrog May 13, 2024
8e658cb
Changes to add Address in data_source_ibm_satellite_location.go
shrinkell May 13, 2024
03367c1
Merge branch 'add_address' into new_add_address
shrinkell May 16, 2024
81f2a7e
Merge branch 'IBM-Cloud:master' into new_add_address
FishAndFrog Jun 2, 2024
ad759ad
Add Address and Capabilities to Create-Satellite-Location
shrinkell Jun 3, 2024
82172bf
Add test for Address to Create-Satellite-Location tests
shrinkell Jun 3, 2024
1eb0133
Add Address and Capabilities to Get-Satellite-Location
shrinkell Jun 3, 2024
7488b92
Add Address Tests to Get-Satellite-Location tests
shrinkell Jun 3, 2024
4860cdc
Add new List-Satellite-Location functionality in ibm-terraform with A…
shrinkell Jun 3, 2024
171eb2d
Add tests for the new List-Satellite-Location functionality in ibm-te…
shrinkell Jun 3, 2024
ae0ffda
Add new List-Satellite-Location functionality in ibm-terraform with A…
shrinkell Jun 3, 2024
31c5a64
Merge branch 'IBM-Cloud:master' into add_satloc_address_and_capabilities
FishAndFrog Jun 10, 2024
b144a93
Replace container-SDK with own fork changes
shrinkell Jun 10, 2024
9b64dca
Merge branch 'IBM-Cloud:master' into add_satloc_address_and_capabilities
FishAndFrog Jun 25, 2024
3a08f97
Replaced Capabilities by CapabilitiesManagedBySatellite
shrinkell Jul 8, 2024
91fad75
Replaced Capabilities by CapabilitiesManagedBySatellite
shrinkell Jul 8, 2024
08f3554
fix compile errors
Jul 8, 2024
b48717e
Merge branch 'add_satloc_address_and_capabilities' of github.com:Fish…
Jul 9, 2024
5e3c134
Merge branch 'IBM-Cloud:master' into master
FishAndFrog Jul 9, 2024
214b837
Comment removal
shrinkell Jul 9, 2024
8423809
Add capabilities tests
shrinkell Jul 9, 2024
6907245
Add test for capabilities to create-satellite-location
shrinkell Jul 11, 2024
9398f10
Add test for capabilities for get data of satellite-location
shrinkell Jul 11, 2024
8cc311d
Merge pull request #3 from FishAndFrog/capabilities_tests_jul9
FishAndFrog Jul 11, 2024
5752a6c
Add capabilities to the tests in satloc_nlb_dns
shrinkell Jul 11, 2024
47e36bd
Merge pull request #4 from FishAndFrog/capabilities_tests_jul9
FishAndFrog Jul 11, 2024
1d31881
Merge branch 'IBM-Cloud:master' into master
FishAndFrog Jul 25, 2024
abc8869
Replace IBM-Cloud/container-services-go-sdk wit https://github.com/IB…
shrinkell Jul 25, 2024
c6a0bb2
Correct on-prem string
shrinkell Jul 25, 2024
28ccb51
Add test-place in test
shrinkell Jul 25, 2024
4f89308
Add test-place in test
shrinkell Jul 25, 2024
610ed0b
Add documentation for PhysicalAddress and Capabilities for Resource
shrinkell Jul 25, 2024
0a15585
Add documentation for PhysicalAddress and Capabilities for Data Source
shrinkell Jul 25, 2024
c6b5971
Merge pull request #5 from FishAndFrog/new_addr_cap_doku
FishAndFrog Jul 25, 2024
687d338
Correct format for capabilities
shrinkell Jul 25, 2024
87fc7c0
Correct the format for capabilities in resource_ibm_satellite_locatio…
shrinkell Jul 25, 2024
8f5a9be
Add capabilities test in resource_ibm_satellite_location_test.go
shrinkell Jul 26, 2024
1c0fbbc
Add capabilities test in data_source_ibm_satellite_location_test.go
shrinkell Jul 26, 2024
1f79391
Corrected indentation
shrinkell Jul 26, 2024
19c3094
Change FlattenSatelliteWorkerCapabilities to FlattenSatelliteCapabili…
shrinkell Jul 30, 2024
606c8b3
Change FlattenSatelliteWorkerCapabilities to FlattenSatelliteCapabili…
shrinkell Jul 30, 2024
7ed3cd1
Replace Optional with Computed in data_source_ibm_satellite_location.go
shrinkell Jul 30, 2024
00812d8
Add 'DiffSuppressFunc: flex.ApplyOnce' for physical_address and capab…
shrinkell Jul 30, 2024
25ee3a3
Add info about 'capabilitiesManagedBySatellite'
shrinkell Jul 30, 2024
4f940a4
Add info about 'capabilitiesManagedBySatellite'
shrinkell Jul 30, 2024
6380280
Add RequiredWith(physical_address) for capabilities
shrinkell Jul 30, 2024
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.22.4
toolchain go1.22.5

require (
github.com/IBM-Cloud/container-services-go-sdk v0.0.0-20240216115622-a311507b4b5b
github.com/IBM-Cloud/container-services-go-sdk v0.0.0-20240725064144-454a2ae23113
github.com/IBM-Cloud/power-go-client v1.7.0
github.com/IBM/apigateway-go-sdk v0.0.0-20210714141226-a5d5d49caaca
github.com/IBM/appconfiguration-go-admin-sdk v0.3.0
Expand Down
316 changes: 314 additions & 2 deletions go.sum

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions ibm/flex/structures.go
Original file line number Diff line number Diff line change
Expand Up @@ -4239,6 +4239,15 @@ func FlattenSatelliteHosts(hostList []kubernetesserviceapiv1.MultishiftQueueNode
return hosts
}

func FlattenSatelliteWorkerCapabilities(capabilities *schema.Set) []kubernetesserviceapiv1.CapabilityManagedBySatellite {
FishAndFrog marked this conversation as resolved.
Show resolved Hide resolved
result := make([]kubernetesserviceapiv1.CapabilityManagedBySatellite, capabilities.Len())
for i, v := range capabilities.List() {
result[i] = kubernetesserviceapiv1.CapabilityManagedBySatellite(v.(string))
}

return result
}

func FlattenWorkerPoolHostLabels(hostLabels map[string]string) *schema.Set {
mapped := make([]string, 0)
for k, v := range hostLabels {
Expand Down
27 changes: 24 additions & 3 deletions ibm/service/satellite/data_source_ibm_satellite_location.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright IBM Corp. 2017, 2021 All Rights Reserved.
// Copyright IBM Corp. 2017, 2024 All Rights Reserved.
// Licensed under the Mozilla Public License v2.0

package satellite
Expand All @@ -9,11 +9,12 @@ import (
"time"

"github.com/IBM-Cloud/container-services-go-sdk/kubernetesserviceapiv1"
"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/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"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"
)

func DataSourceIBMSatelliteLocation() *schema.Resource {
Expand All @@ -31,6 +32,18 @@ func DataSourceIBMSatelliteLocation() *schema.Resource {
Computed: true,
Description: "The IBM Cloud metro from which the Satellite location is managed",
},
"physical_address": {
Type: schema.TypeString,
Optional: true,
Description: "An optional physical address of the new Satellite location which is deployed on premise",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In datasource physical_address is computed n't optional where user can provide some input

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Done

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be

Suggested change
Optional: true,
Computed: true,

This is a data source and the physical address is not helping to retrieve the resource from the provider. This is meant to be a field that is "read" from the API.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Done

},
"capabilities": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString,
Description: "The satellite capabilities attached to the location",
},
"description": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -166,6 +179,8 @@ func dataSourceIBMSatelliteLocationRead(d *schema.ResourceData, meta interface{}

var instance *kubernetesserviceapiv1.MultishiftGetController
var response *core.DetailedResponse
// TO-DO: resource.Retry, resource.RetryError, resource.RetryableError and resource.NonRetryableError
// seem to be deprecated. This shall be replaced.
err = resource.Retry(1*time.Minute, func() *resource.RetryError {
instance, response, err = satClient.GetSatelliteLocation(getSatLocOptions)
if err != nil || instance == nil {
Expand All @@ -187,6 +202,12 @@ func dataSourceIBMSatelliteLocationRead(d *schema.ResourceData, meta interface{}
d.SetId(*instance.ID)
d.Set("location", location)
d.Set("description", *instance.Description)
if instance.PhysicalAddress != nil {
d.Set("physical_address", *instance.PhysicalAddress)
}
if instance.CapabilitiesManagedBySatellite != nil {
d.Set("capabilities", instance.CapabilitiesManagedBySatellite)
}
if instance.CoreosEnabled != nil {
d.Set("coreos_enabled", *instance.CoreosEnabled)
}
Expand Down
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better if we just not set the physical address and capabilities here, there is no need to test this change in every unrelated test

Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,25 @@ import (
"fmt"
"testing"

acc "github.com/IBM-Cloud/terraform-provider-ibm/ibm/acctest"

"github.com/IBM-Cloud/container-services-go-sdk/kubernetesserviceapiv1"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"

acc "github.com/IBM-Cloud/terraform-provider-ibm/ibm/acctest"
)

func TestAccIBMSatelliteLocationNLBDNSListBasic(t *testing.T) {
name := fmt.Sprintf("tf-satellitelocation-%d", acctest.RandIntRange(10, 100))
managed_from := "wdc04"
physical_address := "test location address"
capabilities := []kubernetesserviceapiv1.CapabilityManagedBySatellite{kubernetesserviceapiv1.OnPrem}

resource.Test(t, resource.TestCase{
PreCheck: func() { acc.TestAccPreCheck(t) },
Providers: acc.TestAccProviders,
Steps: []resource.TestStep{
{
Config: testAccCheckIBMSatelliteLocationNLBDNSListConfig(name, managed_from),
Config: testAccCheckIBMSatelliteLocationNLBDNSListConfig(name, managed_from, physical_address, capabilities),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("data.ibm_satellite_location_nlb_dns.dns_list", "id"),
),
Expand All @@ -30,8 +34,8 @@ func TestAccIBMSatelliteLocationNLBDNSListBasic(t *testing.T) {
})
}

func testAccCheckIBMSatelliteLocationNLBDNSListConfig(name, managed_from string) string {
return testAccCheckSatelliteLocationDataSource(name, managed_from) + `
func testAccCheckIBMSatelliteLocationNLBDNSListConfig(name, managed_from, physical_address string, capabilities []kubernetesserviceapiv1.CapabilityManagedBySatellite) string {
return testAccCheckSatelliteLocationDataSource(name, managed_from, physical_address, capabilities) + `
data ibm_satellite_location_nlb_dns dns_list {
location = ibm_satellite_location.location.id
}
Expand Down
20 changes: 14 additions & 6 deletions ibm/service/satellite/data_source_ibm_satellite_location_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright IBM Corp. 2017, 2021 All Rights Reserved.
// Copyright IBM Corp. 2017, 2024 All Rights Reserved.
// Licensed under the Mozilla Public License v2.0

package satellite_test
Expand All @@ -7,45 +7,53 @@ import (
"fmt"
"testing"

acc "github.com/IBM-Cloud/terraform-provider-ibm/ibm/acctest"

"github.com/IBM-Cloud/container-services-go-sdk/kubernetesserviceapiv1"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"

acc "github.com/IBM-Cloud/terraform-provider-ibm/ibm/acctest"
)

func TestAccSatelliteLocationDataSourceBasic(t *testing.T) {
name := fmt.Sprintf("tf-satellitelocation-%d", acctest.RandIntRange(10, 100))
managed_from := "wdc04"
physical_address := "test-road 10, 111 test-place, testcountry"
capabilities := []kubernetesserviceapiv1.CapabilityManagedBySatellite{kubernetesserviceapiv1.OnPrem}

resource.Test(t, resource.TestCase{
PreCheck: func() { acc.TestAccPreCheck(t) },
Providers: acc.TestAccProviders,
Steps: []resource.TestStep{

{
Config: testAccCheckSatelliteLocationDataSource(name, managed_from),
Config: testAccCheckSatelliteLocationDataSource(name, managed_from, physical_address, capabilities),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("ibm_satellite_location.location", "location", name),
resource.TestCheckResourceAttr("ibm_satellite_location.location", "managed_from", managed_from),
resource.TestCheckResourceAttr("ibm_satellite_location.location", "physical_address", physical_address),
resource.TestCheckResourceAttr("ibm_satellite_location.location", "capabilities.#", "1"),
resource.TestCheckResourceAttr("ibm_satellite_location.location", "capabilities.0", "on-prem"),
),
},
},
})
}

func testAccCheckSatelliteLocationDataSource(name, managed_from string) string {
func testAccCheckSatelliteLocationDataSource(name, managed_from string, physical_address string, capabilities []kubernetesserviceapiv1.CapabilityManagedBySatellite) string {
return fmt.Sprintf(`

resource "ibm_satellite_location" "location" {
location = "%s"
managed_from = "%s"
physical_address = "%s"
description = "satellite service"
zones = ["us-east-1", "us-east-2", "us-east-3"]
tags = ["env:dev"]
capabilities = %q
}

data "ibm_satellite_location" "test_location" {
location = ibm_satellite_location.location.id
}`, name, managed_from)
}`, name, managed_from, physical_address, capabilities)

}
58 changes: 53 additions & 5 deletions ibm/service/satellite/resource_ibm_satellite_location.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright IBM Corp. 2017, 2021 All Rights Reserved.
// Copyright IBM Corp. 2017, 2024 All Rights Reserved.
// Licensed under the Mozilla Public License v2.0

package satellite
Expand All @@ -11,13 +11,14 @@ import (
"time"

"github.com/IBM-Cloud/container-services-go-sdk/kubernetesserviceapiv1"
"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"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"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"
)

const (
Expand Down Expand Up @@ -93,6 +94,18 @@ func ResourceIBMSatelliteLocation() *schema.Resource {
},
Description: "The IBM Cloud metro from which the Satellite location is managed",
},
"physical_address": {
Type: schema.TypeString,
Optional: true,
Description: "An optional physical address of the new Satellite location which is deployed on premise",
},
"capabilities": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString,
Description: "The satellite capabilities attached to the location",
},
"description": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not familiar with the API, but in case these can be only set once during create time and not updated we need DiffSuppressFunc: flex.ApplyOnce

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you are right that physical_address and capabilites cannot be changed after creation.

Thanks. Done

Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -237,7 +250,24 @@ func ResourceIBMSatelliteLocationValidator() *validate.ResourceValidator {
Optional: true,
Regexp: `^[A-Za-z0-9:_ .-]+$`,
MinValueLength: 1,
MaxValueLength: 128})
MaxValueLength: 128,
},
validate.ValidateSchema{
Identifier: "physical_address",
ValidateFunctionIdentifier: validate.StringLenBetween,
Type: validate.TypeString,
Optional: true,
MinValueLength: 0,
MaxValueLength: 400,
},
validate.ValidateSchema{
Identifier: "capabilities",
ValidateFunctionIdentifier: validate.ValidateAllowedStringValue,
Type: validate.TypeString,
Optional: true,
AllowedValues: "on-prem",
},
)

ibmSatelliteLocationValidator := validate.ResourceValidator{ResourceName: "ibm_satellite_location", Schema: validateSchema}
return &ibmSatelliteLocationValidator
Expand Down Expand Up @@ -272,6 +302,16 @@ func resourceIBMSatelliteLocationCreate(d *schema.ResourceData, meta interface{}
createSatLocOptions.LoggingAccountID = &logAccID
}

if v, ok := d.GetOk("physical_address"); ok {
addr := v.(string)
createSatLocOptions.PhysicalAddress = &addr
}

if v, ok := d.GetOk("capabilities"); ok {
z := v.(*schema.Set)
createSatLocOptions.CapabilitiesManagedBySatellite = flex.FlattenSatelliteWorkerCapabilities(z)
}

if v, ok := d.GetOk("description"); ok {
desc := v.(string)
createSatLocOptions.Description = &desc
Expand Down Expand Up @@ -351,6 +391,14 @@ func resourceIBMSatelliteLocationRead(d *schema.ResourceData, meta interface{})
d.Set("description", *instance.Description)
}

if instance.PhysicalAddress != nil {
d.Set("physical_address", *instance.PhysicalAddress)
}

if instance.CapabilitiesManagedBySatellite != nil {
d.Set("capabilities", instance.CapabilitiesManagedBySatellite)
}

if instance.CoreosEnabled != nil {
d.Set("coreos_enabled", *instance.CoreosEnabled)
}
Expand Down
Loading
Loading