Skip to content

Commit

Permalink
[core]: remove deprecated functions
Browse files Browse the repository at this point in the history
  • Loading branch information
kayrus committed Jul 19, 2024
1 parent 9e6b57d commit 1bee6c8
Show file tree
Hide file tree
Showing 23 changed files with 79 additions and 127 deletions.
3 changes: 0 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,6 @@ linters:

issues:
exclude-rules:
- linters:
- staticcheck
text: "SA1019:"
- linters:
- stylecheck
text: "ST1005:"
Expand Down
8 changes: 4 additions & 4 deletions ccloud/ccloud_arc_agent_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"net/http"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/sapcc/gophercloud-sapcc/v2/arc/v1/agents"

Expand Down Expand Up @@ -55,7 +55,7 @@ func arcCCloudArcAgentV1WaitForAgent(ctx context.Context, arcClient *gophercloud
// "timeout while waiting for state to become 'active'"
if timeout > 0 {
// Retryable case, when timeout is set
waitForAgent := &resource.StateChangeConf{
waitForAgent := &retry.StateChangeConf{
Target: []string{"active"},
Refresh: arcCCloudArcAgentV1GetAgent(ctx, arcClient, agentID, filter, timeout),
Timeout: timeout,
Expand All @@ -80,7 +80,7 @@ func arcCCloudArcAgentV1WaitForAgent(ctx context.Context, arcClient *gophercloud
return agent.(*agents.Agent), nil
}

func arcCCloudArcAgentV1GetAgent(ctx context.Context, arcClient *gophercloud.ServiceClient, agentID, filter string, timeout time.Duration) resource.StateRefreshFunc {
func arcCCloudArcAgentV1GetAgent(ctx context.Context, arcClient *gophercloud.ServiceClient, agentID, filter string, timeout time.Duration) retry.StateRefreshFunc {
return func() (interface{}, string, error) {
var agent *agents.Agent
var err error
Expand Down Expand Up @@ -186,7 +186,7 @@ func arcAgentV1ParseTimeout(raw interface{}) (time.Duration, error) {
return time.Duration(0), nil
}

func serverV2StateRefreshFunc(ctx context.Context, client *gophercloud.ServiceClient, instanceID string) resource.StateRefreshFunc {
func serverV2StateRefreshFunc(ctx context.Context, client *gophercloud.ServiceClient, instanceID string) retry.StateRefreshFunc {
return func() (interface{}, string, error) {
s, err := servers.Get(ctx, client, instanceID).Extract()
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions ccloud/ccloud_arc_job_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"log"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/sapcc/gophercloud-sapcc/v2/arc/v1/jobs"

Expand Down Expand Up @@ -314,7 +314,7 @@ func flattenArcJobUserV1(user jobs.User) []interface{} {
func waitForArcJobV1(ctx context.Context, arcClient *gophercloud.ServiceClient, id string, target []string, pending []string, timeout time.Duration) error {
log.Printf("[DEBUG] Waiting for %s job to become %v.", id, target)

stateConf := &resource.StateChangeConf{
stateConf := &retry.StateChangeConf{
Target: target,
Pending: pending,
Refresh: arcJobV1GetStatus(ctx, arcClient, id),
Expand All @@ -328,7 +328,7 @@ func waitForArcJobV1(ctx context.Context, arcClient *gophercloud.ServiceClient,
return err
}

func arcJobV1GetStatus(ctx context.Context, arcClient *gophercloud.ServiceClient, id string) resource.StateRefreshFunc {
func arcJobV1GetStatus(ctx context.Context, arcClient *gophercloud.ServiceClient, id string) retry.StateRefreshFunc {
return func() (interface{}, string, error) {
job, err := jobs.Get(ctx, arcClient, id).Extract()
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions ccloud/ccloud_billing_project_masterdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func billingProjectExpandCostObject(raw interface{}) projects.CostObject {
func replaceEmptyString(d *schema.ResourceData, field string, b string) string {
var v interface{}
var ok bool
if v, ok = d.GetOkExists(field); !ok {
if v, ok = getOkExists(d, field); !ok {
return b
}
return v.(string)
Expand All @@ -57,7 +57,7 @@ func replaceEmptyString(d *schema.ResourceData, field string, b string) string {
func replaceEmptyBool(d *schema.ResourceData, field string, b bool) bool {
var v interface{}
var ok bool
if v, ok = d.GetOkExists(field); !ok {
if v, ok = getOkExists(d, field); !ok {
return b
}
return v.(bool)
Expand Down
6 changes: 3 additions & 3 deletions ccloud/ccloud_kubernetes_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"strings"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
"github.com/sapcc/kubernikus/pkg/api/client/operations"
"github.com/sapcc/kubernikus/pkg/api/models"
clientcmdapi "k8s.io/client-go/tools/clientcmd/api/v1"
Expand Down Expand Up @@ -174,7 +174,7 @@ func kubernikusWaitForClusterV1(ctx context.Context, klient *kubernikus, name st
// Phase: "Pending","Creating","Running","Terminating","Upgrading"
log.Printf("[DEBUG] Waiting for %s cluster to become %s.", name, target)

stateConf := &resource.StateChangeConf{
stateConf := &retry.StateChangeConf{
Target: []string{target},
Pending: pending,
Refresh: kubernikusKlusterV1GetPhase(klient, target, name),
Expand All @@ -194,7 +194,7 @@ func kubernikusWaitForClusterV1(ctx context.Context, klient *kubernikus, name st
return err
}

func kubernikusKlusterV1GetPhase(klient *kubernikus, target string, name string) resource.StateRefreshFunc {
func kubernikusKlusterV1GetPhase(klient *kubernikus, target string, name string) retry.StateRefreshFunc {
return func() (interface{}, string, error) {
result, err := klient.ShowCluster(operations.NewShowClusterParams().WithName(name), klient.authFunc())
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion ccloud/data_source_ccloud_automation_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func dataSourceCCloudAutomationV1Read(ctx context.Context, d *schema.ResourceDat
var v interface{}
var debugExists, debug bool

if v, debugExists = d.GetOkExists("debug"); debugExists {
if v, debugExists = getOkExists(d, "debug"); debugExists {
debug = v.(bool)
}
name := d.Get("name").(string)
Expand Down
21 changes: 18 additions & 3 deletions ccloud/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package ccloud
import (
"context"
"os"
"runtime/debug"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/logging"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/meta"

"github.com/gophercloud/gophercloud/v2"
"github.com/gophercloud/utils/v2/terraform/auth"
Expand Down Expand Up @@ -373,6 +373,21 @@ func init() {
}
}

func getSDKVersion() string {
buildInfo, ok := debug.ReadBuildInfo()
if !ok {
return ""
}

for _, v := range buildInfo.Deps {
if v.Path == "github.com/hashicorp/terraform-plugin-sdk/v2" {
return v.Version
}
}

return ""
}

func configureProvider(ctx context.Context, d *schema.ResourceData, terraformVersion string) (interface{}, diag.Diagnostics) {
enableLogging := d.Get("enable_logging").(bool)
if !enableLogging {
Expand Down Expand Up @@ -420,13 +435,13 @@ func configureProvider(ctx context.Context, d *schema.ResourceData, terraformVer
MaxRetries: d.Get("max_retries").(int),
DisableNoCacheHeader: d.Get("disable_no_cache_header").(bool),
TerraformVersion: terraformVersion,
SDKVersion: meta.SDKVersionString(),
SDKVersion: getSDKVersion(),
MutexKV: mutexkv.NewMutexKV(),
EnableLogger: enableLogging,
},
}

v, ok := d.GetOkExists("insecure")
v, ok := getOkExists(d, "insecure")
if ok {
insecure := v.(bool)
config.Insecure = &insecure
Expand Down
4 changes: 2 additions & 2 deletions ccloud/resource_ccloud_arc_agent_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/sapcc/gophercloud-sapcc/v2/arc/v1/agents"
Expand Down Expand Up @@ -192,7 +192,7 @@ func resourceCCloudArcAgentV1Delete(ctx context.Context, d *schema.ResourceData,
return diag.Errorf("Error creating OpenStack compute client: %s", err)
}

stateConf := &resource.StateChangeConf{
stateConf := &retry.StateChangeConf{
Pending: []string{"ACTIVE", "SHUTOFF"},
Target: []string{"DELETED", "SOFT_DELETED"},
Refresh: serverV2StateRefreshFunc(ctx, computeClient, d.Id()),
Expand Down
4 changes: 2 additions & 2 deletions ccloud/resource_ccloud_arc_job_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,11 +318,11 @@ func resourceCCloudArcJobV1Create(ctx context.Context, d *schema.ResourceData, m

var agent, action, payload string

if v, ok := d.GetOkExists("execute"); ok {
if v, ok := getOkExists(d, "execute"); ok {
agent = "execute"
action, payload, err = arcCCloudArcJobV1BuildPayload(v.([]interface{}))
}
if v, ok := d.GetOkExists("chef"); ok {
if v, ok := getOkExists(d, "chef"); ok {
agent = "chef"
action, payload, err = arcCCloudArcJobV1BuildPayload(v.([]interface{}))
}
Expand Down
6 changes: 3 additions & 3 deletions ccloud/resource_ccloud_automation_run_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/sapcc/gophercloud-sapcc/v2/automation/v1/runs"
Expand Down Expand Up @@ -222,7 +222,7 @@ func flattenAutomationiOwnerV1(owner runs.Owner) []interface{} {
func waitForAutomationRunV1(ctx context.Context, automationClient *gophercloud.ServiceClient, id string, target []string, pending []string, timeout time.Duration) error {
log.Printf("[DEBUG] Waiting for %s run to become %v.", id, target)

stateConf := &resource.StateChangeConf{
stateConf := &retry.StateChangeConf{
Target: target,
Pending: pending,
Refresh: automationRunV1GetState(ctx, automationClient, id),
Expand All @@ -236,7 +236,7 @@ func waitForAutomationRunV1(ctx context.Context, automationClient *gophercloud.S
return err
}

func automationRunV1GetState(ctx context.Context, automationClient *gophercloud.ServiceClient, id string) resource.StateRefreshFunc {
func automationRunV1GetState(ctx context.Context, automationClient *gophercloud.ServiceClient, id string) retry.StateRefreshFunc {
return func() (interface{}, string, error) {
run, err := runs.Get(ctx, automationClient, id).Extract()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion ccloud/resource_ccloud_billing_project_masterdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ func resourceCCloudBillingProjectMasterdataCreateOrUpdate(ctx context.Context, d
opts.ContainsExternalCustomerData = replaceEmptyBool(d, "contains_external_customer_data", opts.ContainsExternalCustomerData)
opts.ExtCertification = billingProjectExpandExtCertificationV1(d.Get("ext_certification"))

if v, ok := d.GetOkExists("number_of_endusers"); ok {
if v, ok := getOkExists(d, "number_of_endusers"); ok {
opts.NumberOfEndusers = v.(int)
}

Expand Down
6 changes: 3 additions & 3 deletions ccloud/resource_ccloud_endpoint_accept_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/go-openapi/strfmt"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/sapcc/archer/client/service"
"github.com/sapcc/archer/models"
Expand Down Expand Up @@ -178,7 +178,7 @@ func resourceCCloudEndpointAcceptV1Delete(ctx context.Context, d *schema.Resourc
func archerWaitForServiceEndpointConsumer(ctx context.Context, c *archer, id, serviceID string, target, pending []string, timeout time.Duration) (*models.EndpointConsumer, error) {
log.Printf("[DEBUG] Waiting for %s endpoint to become %s.", id, target)

stateConf := &resource.StateChangeConf{
stateConf := &retry.StateChangeConf{
Target: target,
Pending: pending,
Refresh: archerGetServiceEndpointConsumerStatus(ctx, c, id, serviceID),
Expand All @@ -198,7 +198,7 @@ func archerWaitForServiceEndpointConsumer(ctx context.Context, c *archer, id, se
return ec.(*models.EndpointConsumer), nil
}

func archerGetServiceEndpointConsumerStatus(ctx context.Context, c *archer, id, serviceID string) resource.StateRefreshFunc {
func archerGetServiceEndpointConsumerStatus(ctx context.Context, c *archer, id, serviceID string) retry.StateRefreshFunc {
return func() (interface{}, string, error) {
ec, err := archerGetServiceEndpointConsumer(ctx, c, id, serviceID)
if err != nil {
Expand Down
10 changes: 5 additions & 5 deletions ccloud/resource_ccloud_endpoint_service_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/go-openapi/strfmt"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/sapcc/archer/client/service"
Expand Down Expand Up @@ -148,10 +148,10 @@ func resourceCCloudEndpointServiceV1Create(ctx context.Context, d *schema.Resour
Port: int32(d.Get("port").(int)),
IPAddresses: expandToStrFmtIPv4Slice(d.Get("ip_addresses").([]interface{})),
}
if v, ok := d.GetOkExists("proxy_protocol"); ok {
if v, ok := getOkExists(d, "proxy_protocol"); ok {
svc.ProxyProtocol = ptr(v.(bool))
}
if v, ok := d.GetOkExists("require_approval"); ok {
if v, ok := getOkExists(d, "require_approval"); ok {
svc.RequireApproval = ptr(v.(bool))
}
if v, ok := d.GetOk("availability_zone"); ok && v != "" {
Expand Down Expand Up @@ -323,7 +323,7 @@ func resourceCCloudEndpointServiceV1Delete(ctx context.Context, d *schema.Resour
func archerWaitForService(ctx context.Context, c *archer, id, target, pending string, timeout time.Duration) (*models.Service, error) {
log.Printf("[DEBUG] Waiting for %s service to become %s.", id, target)

stateConf := &resource.StateChangeConf{
stateConf := &retry.StateChangeConf{
Target: []string{target},
Pending: []string{pending},
Refresh: archerGetServiceStatus(ctx, c, id),
Expand All @@ -343,7 +343,7 @@ func archerWaitForService(ctx context.Context, c *archer, id, target, pending st
return svc.(*models.Service), nil
}

func archerGetServiceStatus(ctx context.Context, c *archer, id string) resource.StateRefreshFunc {
func archerGetServiceStatus(ctx context.Context, c *archer, id string) retry.StateRefreshFunc {
return func() (interface{}, string, error) {
service, err := archerGetService(ctx, c, id)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions ccloud/resource_ccloud_endpoint_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/go-openapi/strfmt"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/sapcc/archer/client/endpoint"
"github.com/sapcc/archer/models"
Expand Down Expand Up @@ -254,7 +254,7 @@ func resourceCCloudEndpointV1Delete(ctx context.Context, d *schema.ResourceData,
func archerWaitForEndpoint(ctx context.Context, c *archer, id string, target []string, pending string, timeout time.Duration) (*models.Endpoint, error) {
log.Printf("[DEBUG] Waiting for %s endpoint to become %s.", id, target)

stateConf := &resource.StateChangeConf{
stateConf := &retry.StateChangeConf{
Target: target,
Pending: []string{pending},
Refresh: archerGetEndpointStatus(ctx, c, id),
Expand All @@ -274,7 +274,7 @@ func archerWaitForEndpoint(ctx context.Context, c *archer, id string, target []s
return ept.(*models.Endpoint), nil
}

func archerGetEndpointStatus(ctx context.Context, c *archer, id string) resource.StateRefreshFunc {
func archerGetEndpointStatus(ctx context.Context, c *archer, id string) retry.StateRefreshFunc {
return func() (interface{}, string, error) {
endpoint, err := archerGetEndpoint(ctx, c, id)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions ccloud/resource_ccloud_gslb_datacenter_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/go-openapi/strfmt"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/sapcc/andromeda/client/datacenters"
Expand Down Expand Up @@ -324,7 +324,7 @@ func resourceCCloudGSLBDatacenterV1Delete(ctx context.Context, d *schema.Resourc
func andromedaWaitForDatacenter(ctx context.Context, client datacenters.ClientService, id, target, pending string, timeout time.Duration) (*models.Datacenter, error) {
log.Printf("[DEBUG] Waiting for %s datacenter to become %s.", id, target)

stateConf := &resource.StateChangeConf{
stateConf := &retry.StateChangeConf{
Target: []string{target},
Pending: []string{pending},
Refresh: andromedaGetDatacenterStatus(ctx, client, id),
Expand All @@ -344,7 +344,7 @@ func andromedaWaitForDatacenter(ctx context.Context, client datacenters.ClientSe
return datacenter.(*models.Datacenter), nil
}

func andromedaGetDatacenterStatus(ctx context.Context, client datacenters.ClientService, id string) resource.StateRefreshFunc {
func andromedaGetDatacenterStatus(ctx context.Context, client datacenters.ClientService, id string) retry.StateRefreshFunc {
return func() (interface{}, string, error) {
datacenter, err := andromedaGetDatacenter(ctx, client, id)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions ccloud/resource_ccloud_gslb_domain_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/go-openapi/strfmt"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/sapcc/andromeda/client/domains"
Expand Down Expand Up @@ -310,7 +310,7 @@ func resourceCCloudGSLBDomainV1Delete(ctx context.Context, d *schema.ResourceDat
func andromedaWaitForDomain(ctx context.Context, client domains.ClientService, id, target, pending string, timeout time.Duration) (*models.Domain, error) {
log.Printf("[DEBUG] Waiting for %s domain to become %s.", id, target)

stateConf := &resource.StateChangeConf{
stateConf := &retry.StateChangeConf{
Target: []string{target},
Pending: []string{pending},
Refresh: andromedaGetDomainStatus(ctx, client, id),
Expand All @@ -330,7 +330,7 @@ func andromedaWaitForDomain(ctx context.Context, client domains.ClientService, i
return domain.(*models.Domain), nil
}

func andromedaGetDomainStatus(ctx context.Context, client domains.ClientService, id string) resource.StateRefreshFunc {
func andromedaGetDomainStatus(ctx context.Context, client domains.ClientService, id string) retry.StateRefreshFunc {
return func() (interface{}, string, error) {
domain, err := andromedaGetDomain(ctx, client, id)
if err != nil {
Expand Down
Loading

0 comments on commit 1bee6c8

Please sign in to comment.