Skip to content

Commit

Permalink
vmware: refactoring the embedded sdk to include the api version
Browse files Browse the repository at this point in the history
  • Loading branch information
tombuildsstuff committed Aug 11, 2021
1 parent 8d1df04 commit cf6b7c6
Show file tree
Hide file tree
Showing 65 changed files with 55 additions and 53 deletions.
6 changes: 3 additions & 3 deletions internal/services/vmware/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package client

import (
"github.com/hashicorp/terraform-provider-azurerm/internal/common"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/vmware/sdk/authorizations"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/vmware/sdk/clusters"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/vmware/sdk/privateclouds"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/vmware/sdk/2020-03-20/authorizations"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/vmware/sdk/2020-03-20/clusters"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/vmware/sdk/2020-03-20/privateclouds"
)

type Client struct {
Expand Down
2 changes: 1 addition & 1 deletion internal/services/vmware/validate/cluster_id.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package validate
import (
"fmt"

"github.com/hashicorp/terraform-provider-azurerm/internal/services/vmware/sdk/clusters"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/vmware/sdk/2020-03-20/clusters"
)

func ClusterID(input interface{}, key string) (warnings []string, errors []error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package validate
import (
"fmt"

"github.com/hashicorp/terraform-provider-azurerm/internal/services/vmware/sdk/authorizations"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/vmware/sdk/2020-03-20/authorizations"
)

func ExpressRouteAuthorizationID(input interface{}, key string) (warnings []string, errors []error) {
Expand Down
2 changes: 1 addition & 1 deletion internal/services/vmware/validate/private_cloud_id.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package validate
import (
"fmt"

"github.com/hashicorp/terraform-provider-azurerm/internal/services/vmware/sdk/privateclouds"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/vmware/sdk/2020-03-20/privateclouds"
)

func PrivateCloudID(input interface{}, key string) (warnings []string, errors []error) {
Expand Down
24 changes: 12 additions & 12 deletions internal/services/vmware/vmware_cluster_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import (
"log"
"time"

"github.com/hashicorp/terraform-provider-azurerm/internal/services/vmware/sdk/privateclouds"
clusters2 "github.com/hashicorp/terraform-provider-azurerm/internal/services/vmware/sdk/2020-03-20/clusters"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/vmware/sdk/2020-03-20/privateclouds"

"github.com/hashicorp/go-azure-helpers/response"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/vmware/sdk/clusters"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/vmware/validate"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation"
Expand All @@ -33,7 +33,7 @@ func resourceVmwareCluster() *pluginsdk.Resource {
},

Importer: pluginsdk.ImporterValidatingResourceId(func(id string) error {
_, err := clusters.ParseClusterID(id)
_, err := clusters2.ParseClusterID(id)
return err
}),

Expand Down Expand Up @@ -97,7 +97,7 @@ func resourceVmwareClusterCreate(d *pluginsdk.ResourceData, meta interface{}) er
return err
}

id := clusters.NewClusterID(subscriptionId, privateCloudId.ResourceGroup, privateCloudId.Name, name)
id := clusters2.NewClusterID(subscriptionId, privateCloudId.ResourceGroup, privateCloudId.Name, name)
existing, err := client.Get(ctx, id)
if err != nil {
if !response.WasNotFound(existing.HttpResponse) {
Expand All @@ -108,11 +108,11 @@ func resourceVmwareClusterCreate(d *pluginsdk.ResourceData, meta interface{}) er
return tf.ImportAsExistsError("azurerm_vmware_cluster", id.ID())
}

cluster := clusters.Cluster{
Sku: clusters.Sku{
cluster := clusters2.Cluster{
Sku: clusters2.Sku{
Name: d.Get("sku_name").(string),
},
Properties: clusters.ClusterProperties{
Properties: clusters2.ClusterProperties{
ClusterSize: int64(d.Get("cluster_node_count").(int)),
},
}
Expand All @@ -130,7 +130,7 @@ func resourceVmwareClusterRead(d *pluginsdk.ResourceData, meta interface{}) erro
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d)
defer cancel()

id, err := clusters.ParseClusterID(d.Id())
id, err := clusters2.ParseClusterID(d.Id())
if err != nil {
return err
}
Expand Down Expand Up @@ -163,13 +163,13 @@ func resourceVmwareClusterUpdate(d *pluginsdk.ResourceData, meta interface{}) er
ctx, cancel := timeouts.ForUpdate(meta.(*clients.Client).StopContext, d)
defer cancel()

id, err := clusters.ParseClusterID(d.Id())
id, err := clusters2.ParseClusterID(d.Id())
if err != nil {
return err
}

clusterUpdate := clusters.ClusterUpdate{
Properties: &clusters.ClusterUpdateProperties{},
clusterUpdate := clusters2.ClusterUpdate{
Properties: &clusters2.ClusterUpdateProperties{},
}
if d.HasChange("cluster_node_count") {
clusterUpdate.Properties.ClusterSize = utils.Int64(int64(d.Get("cluster_node_count").(int)))
Expand All @@ -186,7 +186,7 @@ func resourceVmwareClusterDelete(d *pluginsdk.ResourceData, meta interface{}) er
ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d)
defer cancel()

id, err := clusters.ParseClusterID(d.Id())
id, err := clusters2.ParseClusterID(d.Id())
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion internal/services/vmware/vmware_cluster_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"testing"

"github.com/hashicorp/terraform-provider-azurerm/internal/services/vmware/sdk/clusters"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/vmware/sdk/2020-03-20/clusters"

"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import (
"log"
"time"

authorizations2 "github.com/hashicorp/terraform-provider-azurerm/internal/services/vmware/sdk/2020-03-20/authorizations"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/vmware/sdk/2020-03-20/privateclouds"

"github.com/hashicorp/go-azure-helpers/response"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/vmware/sdk/authorizations"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/vmware/sdk/privateclouds"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/vmware/validate"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation"
Expand All @@ -29,7 +30,7 @@ func resourceVmwareExpressRouteAuthorization() *pluginsdk.Resource {
},

Importer: pluginsdk.ImporterValidatingResourceId(func(id string) error {
_, err := authorizations.ParseAuthorizationID(id)
_, err := authorizations2.ParseAuthorizationID(id)
return err
}),

Expand Down Expand Up @@ -74,7 +75,7 @@ func resourceVmwareExpressRouteAuthorizationCreate(d *pluginsdk.ResourceData, me
return err
}

id := authorizations.NewAuthorizationID(subscriptionId, privateCloudId.ResourceGroup, privateCloudId.Name, name)
id := authorizations2.NewAuthorizationID(subscriptionId, privateCloudId.ResourceGroup, privateCloudId.Name, name)
existing, err := client.Get(ctx, id)
if err != nil {
if !response.WasNotFound(existing.HttpResponse) {
Expand All @@ -85,7 +86,7 @@ func resourceVmwareExpressRouteAuthorizationCreate(d *pluginsdk.ResourceData, me
return tf.ImportAsExistsError("azurerm_vmware_express_route_authorization", id.ID())
}

props := authorizations.ExpressRouteAuthorization{}
props := authorizations2.ExpressRouteAuthorization{}

if err := client.CreateOrUpdateThenPoll(ctx, id, props); err != nil {
return fmt.Errorf("creating %q: %+v", id, err)
Expand All @@ -101,7 +102,7 @@ func resourceVmwareExpressRouteAuthorizationRead(d *pluginsdk.ResourceData, meta
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d)
defer cancel()

id, err := authorizations.ParseAuthorizationID(d.Id())
id, err := authorizations2.ParseAuthorizationID(d.Id())
if err != nil {
return err
}
Expand Down Expand Up @@ -135,7 +136,7 @@ func resourceVmwareExpressRouteAuthorizationDelete(d *pluginsdk.ResourceData, me
ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d)
defer cancel()

id, err := authorizations.ParseAuthorizationID(d.Id())
id, err := authorizations2.ParseAuthorizationID(d.Id())
if err != nil {
return err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"testing"

"github.com/hashicorp/terraform-provider-azurerm/internal/services/vmware/sdk/authorizations"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/vmware/sdk/2020-03-20/authorizations"

"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check"
Expand Down
6 changes: 3 additions & 3 deletions internal/services/vmware/vmware_private_cloud.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package vmware

import (
"github.com/hashicorp/terraform-provider-azurerm/internal/services/vmware/sdk/privateclouds"
privateclouds2 "github.com/hashicorp/terraform-provider-azurerm/internal/services/vmware/sdk/2020-03-20/privateclouds"
"github.com/hashicorp/terraform-provider-azurerm/utils"
)

func flattenPrivateCloudManagementCluster(input privateclouds.ManagementCluster) []interface{} {
func flattenPrivateCloudManagementCluster(input privateclouds2.ManagementCluster) []interface{} {
return []interface{}{
map[string]interface{}{
"size": input.ClusterSize,
Expand All @@ -15,7 +15,7 @@ func flattenPrivateCloudManagementCluster(input privateclouds.ManagementCluster)
}
}

func flattenPrivateCloudCircuit(input *privateclouds.Circuit) []interface{} {
func flattenPrivateCloudCircuit(input *privateclouds2.Circuit) []interface{} {
if input == nil {
return make([]interface{}, 0)
}
Expand Down
8 changes: 4 additions & 4 deletions internal/services/vmware/vmware_private_cloud_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"fmt"
"time"

"github.com/hashicorp/go-azure-helpers/response"
privateclouds2 "github.com/hashicorp/terraform-provider-azurerm/internal/services/vmware/sdk/2020-03-20/privateclouds"

"github.com/hashicorp/terraform-provider-azurerm/internal/services/vmware/sdk/privateclouds"
"github.com/hashicorp/go-azure-helpers/response"

"github.com/hashicorp/terraform-provider-azurerm/helpers/azure"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
Expand Down Expand Up @@ -157,7 +157,7 @@ func dataSourceVmwarePrivateCloudRead(d *pluginsdk.ResourceData, meta interface{
name := d.Get("name").(string)
resourceGroup := d.Get("resource_group_name").(string)

id := privateclouds.NewPrivateCloudID(subscriptionId, resourceGroup, name)
id := privateclouds2.NewPrivateCloudID(subscriptionId, resourceGroup, name)
resp, err := client.Get(ctx, id)
if err != nil {
if response.WasNotFound(resp.HttpResponse) {
Expand All @@ -184,7 +184,7 @@ func dataSourceVmwarePrivateCloudRead(d *pluginsdk.ResourceData, meta interface{

internetConnectionEnabled := false
if props.Internet != nil {
internetConnectionEnabled = *props.Internet == privateclouds.InternetEnumEnabled
internetConnectionEnabled = *props.Internet == privateclouds2.InternetEnumEnabled
}

d.Set("internet_connection_enabled", internetConnectionEnabled)
Expand Down
37 changes: 19 additions & 18 deletions internal/services/vmware/vmware_private_cloud_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import (
"log"
"time"

privateclouds2 "github.com/hashicorp/terraform-provider-azurerm/internal/services/vmware/sdk/2020-03-20/privateclouds"

"github.com/hashicorp/go-azure-helpers/response"
"github.com/hashicorp/terraform-provider-azurerm/helpers/azure"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/location"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/vmware/sdk/privateclouds"
"github.com/hashicorp/terraform-provider-azurerm/internal/tags"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation"
Expand All @@ -33,7 +34,7 @@ func resourceVmwarePrivateCloud() *pluginsdk.Resource {
},

Importer: pluginsdk.ImporterValidatingResourceId(func(id string) error {
_, err := privateclouds.ParsePrivateCloudID(id)
_, err := privateclouds2.ParsePrivateCloudID(id)
return err
}),

Expand Down Expand Up @@ -196,7 +197,7 @@ func resourceVmwarePrivateCloudCreate(d *pluginsdk.ResourceData, meta interface{
ctx, cancel := timeouts.ForCreate(meta.(*clients.Client).StopContext, d)
defer cancel()

id := privateclouds.NewPrivateCloudID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string))
id := privateclouds2.NewPrivateCloudID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string))
existing, err := client.Get(ctx, id)
if err != nil {
if !response.WasNotFound(existing.HttpResponse) {
Expand All @@ -207,18 +208,18 @@ func resourceVmwarePrivateCloudCreate(d *pluginsdk.ResourceData, meta interface{
return tf.ImportAsExistsError("azurerm_vmware_private_cloud", id.ID())
}

internet := privateclouds.InternetEnumDisabled
internet := privateclouds2.InternetEnumDisabled
if d.Get("internet_connection_enabled").(bool) {
internet = privateclouds.InternetEnumEnabled
internet = privateclouds2.InternetEnumEnabled
}

privateCloud := privateclouds.PrivateCloud{
privateCloud := privateclouds2.PrivateCloud{
Location: location.Normalize(d.Get("location").(string)),
Sku: privateclouds.Sku{
Sku: privateclouds2.Sku{
Name: d.Get("sku_name").(string),
},
Properties: privateclouds.PrivateCloudProperties{
ManagementCluster: privateclouds.ManagementCluster{
Properties: privateclouds2.PrivateCloudProperties{
ManagementCluster: privateclouds2.ManagementCluster{
ClusterSize: int64(d.Get("management_cluster.0.size").(int)),
},
NetworkBlock: d.Get("network_subnet_cidr").(string),
Expand All @@ -242,7 +243,7 @@ func resourceVmwarePrivateCloudRead(d *pluginsdk.ResourceData, meta interface{})
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d)
defer cancel()

id, err := privateclouds.ParsePrivateCloudID(d.Id())
id, err := privateclouds2.ParsePrivateCloudID(d.Id())
if err != nil {
return err
}
Expand Down Expand Up @@ -274,7 +275,7 @@ func resourceVmwarePrivateCloudRead(d *pluginsdk.ResourceData, meta interface{})

internetConnectionEnabled := false
if props.Internet != nil {
internetConnectionEnabled = *props.Internet == privateclouds.InternetEnumEnabled
internetConnectionEnabled = *props.Internet == privateclouds2.InternetEnumEnabled
}
d.Set("internet_connection_enabled", internetConnectionEnabled)

Expand Down Expand Up @@ -302,29 +303,29 @@ func resourceVmwarePrivateCloudUpdate(d *pluginsdk.ResourceData, meta interface{
ctx, cancel := timeouts.ForUpdate(meta.(*clients.Client).StopContext, d)
defer cancel()

id, err := privateclouds.ParsePrivateCloudID(d.Id())
id, err := privateclouds2.ParsePrivateCloudID(d.Id())
if err != nil {
return err
}

privateCloudUpdate := privateclouds.PrivateCloudUpdate{
Properties: &privateclouds.PrivateCloudUpdateProperties{},
privateCloudUpdate := privateclouds2.PrivateCloudUpdate{
Properties: &privateclouds2.PrivateCloudUpdateProperties{},
}

if d.HasChange("management_cluster") && d.HasChange("internet_connection_enabled") {
return fmt.Errorf("`management_cluster.0.size` and `internet_connection_enabled` could not be changed together")
}

if d.HasChange("management_cluster") {
privateCloudUpdate.Properties.ManagementCluster = &privateclouds.ManagementCluster{
privateCloudUpdate.Properties.ManagementCluster = &privateclouds2.ManagementCluster{
ClusterSize: int64(d.Get("management_cluster.0.size").(int)),
}
}

if d.HasChange("internet_connection_enabled") {
internet := privateclouds.InternetEnumDisabled
internet := privateclouds2.InternetEnumDisabled
if d.Get("internet_connection_enabled").(bool) {
internet = privateclouds.InternetEnumEnabled
internet = privateclouds2.InternetEnumEnabled
}
privateCloudUpdate.Properties.Internet = &internet
}
Expand All @@ -345,7 +346,7 @@ func resourceVmwarePrivateCloudDelete(d *pluginsdk.ResourceData, meta interface{
ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d)
defer cancel()

id, err := privateclouds.ParsePrivateCloudID(d.Id())
id, err := privateclouds2.ParsePrivateCloudID(d.Id())
if err != nil {
return err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"testing"

"github.com/hashicorp/terraform-provider-azurerm/internal/services/vmware/sdk/privateclouds"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/vmware/sdk/2020-03-20/privateclouds"

"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check"
Expand Down

0 comments on commit cf6b7c6

Please sign in to comment.