Skip to content

Commit

Permalink
new resource: azurerm_spring_cloud_accelerator (hashicorp#19572)
Browse files Browse the repository at this point in the history
  • Loading branch information
ms-henglu authored and favoretti committed Jan 12, 2023
1 parent 664455f commit fdefa09
Show file tree
Hide file tree
Showing 10 changed files with 690 additions and 40 deletions.
85 changes: 45 additions & 40 deletions internal/services/springcloud/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,27 @@ import (
)

type Client struct {
APIPortalClient *appplatform.APIPortalsClient
APIPortalCustomDomainClient *appplatform.APIPortalCustomDomainsClient
ApplicationLiveViewsClient *appplatform.ApplicationLiveViewsClient
AppsClient *appplatform.AppsClient
BindingsClient *appplatform.BindingsClient
BuildPackBindingClient *appplatform.BuildpackBindingClient
BuildServiceAgentPoolClient *appplatform.BuildServiceAgentPoolClient
BuildServiceBuilderClient *appplatform.BuildServiceBuilderClient
CertificatesClient *appplatform.CertificatesClient
ConfigServersClient *appplatform.ConfigServersClient
ConfigurationServiceClient *appplatform.ConfigurationServicesClient
CustomDomainsClient *appplatform.CustomDomainsClient
GatewayClient *appplatform.GatewaysClient
GatewayCustomDomainClient *appplatform.GatewayCustomDomainsClient
GatewayRouteConfigClient *appplatform.GatewayRouteConfigsClient
MonitoringSettingsClient *appplatform.MonitoringSettingsClient
DeploymentsClient *appplatform.DeploymentsClient
ServicesClient *appplatform.ServicesClient
ServiceRegistryClient *appplatform.ServiceRegistriesClient
StoragesClient *appplatform.StoragesClient
APIPortalClient *appplatform.APIPortalsClient
APIPortalCustomDomainClient *appplatform.APIPortalCustomDomainsClient
ApplicationAcceleratorClient *appplatform.ApplicationAcceleratorsClient
ApplicationLiveViewsClient *appplatform.ApplicationLiveViewsClient
AppsClient *appplatform.AppsClient
BindingsClient *appplatform.BindingsClient
BuildPackBindingClient *appplatform.BuildpackBindingClient
BuildServiceAgentPoolClient *appplatform.BuildServiceAgentPoolClient
BuildServiceBuilderClient *appplatform.BuildServiceBuilderClient
CertificatesClient *appplatform.CertificatesClient
ConfigServersClient *appplatform.ConfigServersClient
ConfigurationServiceClient *appplatform.ConfigurationServicesClient
CustomDomainsClient *appplatform.CustomDomainsClient
GatewayClient *appplatform.GatewaysClient
GatewayCustomDomainClient *appplatform.GatewayCustomDomainsClient
GatewayRouteConfigClient *appplatform.GatewayRouteConfigsClient
MonitoringSettingsClient *appplatform.MonitoringSettingsClient
DeploymentsClient *appplatform.DeploymentsClient
ServicesClient *appplatform.ServicesClient
ServiceRegistryClient *appplatform.ServiceRegistriesClient
StoragesClient *appplatform.StoragesClient
}

func NewClient(o *common.ClientOptions) *Client {
Expand All @@ -35,6 +36,9 @@ func NewClient(o *common.ClientOptions) *Client {
apiPortalCustomDomainClient := appplatform.NewAPIPortalCustomDomainsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&apiPortalCustomDomainClient.Client, o.ResourceManagerAuthorizer)

applicationAcceleratorClient := appplatform.NewApplicationAcceleratorsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&applicationAcceleratorClient.Client, o.ResourceManagerAuthorizer)

applicationLiveViewsClient := appplatform.NewApplicationLiveViewsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&applicationLiveViewsClient.Client, o.ResourceManagerAuthorizer)

Expand Down Expand Up @@ -90,25 +94,26 @@ func NewClient(o *common.ClientOptions) *Client {
o.ConfigureClient(&storageClient.Client, o.ResourceManagerAuthorizer)

return &Client{
APIPortalClient: &apiPortalClient,
APIPortalCustomDomainClient: &apiPortalCustomDomainClient,
ApplicationLiveViewsClient: &applicationLiveViewsClient,
AppsClient: &appsClient,
BindingsClient: &bindingsClient,
BuildPackBindingClient: &buildpackBindingClient,
BuildServiceAgentPoolClient: &buildServiceAgentPoolClient,
BuildServiceBuilderClient: &buildServiceBuilderClient,
CertificatesClient: &certificatesClient,
ConfigServersClient: &configServersClient,
ConfigurationServiceClient: &configurationServiceClient,
CustomDomainsClient: &customDomainsClient,
DeploymentsClient: &deploymentsClient,
GatewayClient: &gatewayClient,
GatewayCustomDomainClient: &gatewayCustomDomainClient,
GatewayRouteConfigClient: &gatewayRouteConfigClient,
MonitoringSettingsClient: &monitoringSettingsClient,
ServicesClient: &servicesClient,
ServiceRegistryClient: &serviceRegistryClient,
StoragesClient: &storageClient,
APIPortalClient: &apiPortalClient,
APIPortalCustomDomainClient: &apiPortalCustomDomainClient,
ApplicationAcceleratorClient: &applicationAcceleratorClient,
ApplicationLiveViewsClient: &applicationLiveViewsClient,
AppsClient: &appsClient,
BindingsClient: &bindingsClient,
BuildPackBindingClient: &buildpackBindingClient,
BuildServiceAgentPoolClient: &buildServiceAgentPoolClient,
BuildServiceBuilderClient: &buildServiceBuilderClient,
CertificatesClient: &certificatesClient,
ConfigServersClient: &configServersClient,
ConfigurationServiceClient: &configurationServiceClient,
CustomDomainsClient: &customDomainsClient,
DeploymentsClient: &deploymentsClient,
GatewayClient: &gatewayClient,
GatewayCustomDomainClient: &gatewayCustomDomainClient,
GatewayRouteConfigClient: &gatewayRouteConfigClient,
MonitoringSettingsClient: &monitoringSettingsClient,
ServicesClient: &servicesClient,
ServiceRegistryClient: &serviceRegistryClient,
StoragesClient: &storageClient,
}
}
75 changes: 75 additions & 0 deletions internal/services/springcloud/parse/spring_cloud_accelerator.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package parse

// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten

import (
"fmt"
"strings"

"github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids"
)

type SpringCloudAcceleratorId struct {
SubscriptionId string
ResourceGroup string
SpringName string
ApplicationAcceleratorName string
}

func NewSpringCloudAcceleratorID(subscriptionId, resourceGroup, springName, applicationAcceleratorName string) SpringCloudAcceleratorId {
return SpringCloudAcceleratorId{
SubscriptionId: subscriptionId,
ResourceGroup: resourceGroup,
SpringName: springName,
ApplicationAcceleratorName: applicationAcceleratorName,
}
}

func (id SpringCloudAcceleratorId) String() string {
segments := []string{
fmt.Sprintf("Application Accelerator Name %q", id.ApplicationAcceleratorName),
fmt.Sprintf("Spring Name %q", id.SpringName),
fmt.Sprintf("Resource Group %q", id.ResourceGroup),
}
segmentsStr := strings.Join(segments, " / ")
return fmt.Sprintf("%s: (%s)", "Spring Cloud Accelerator", segmentsStr)
}

func (id SpringCloudAcceleratorId) ID() string {
fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.AppPlatform/Spring/%s/applicationAccelerators/%s"
return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup, id.SpringName, id.ApplicationAcceleratorName)
}

// SpringCloudAcceleratorID parses a SpringCloudAccelerator ID into an SpringCloudAcceleratorId struct
func SpringCloudAcceleratorID(input string) (*SpringCloudAcceleratorId, error) {
id, err := resourceids.ParseAzureResourceID(input)
if err != nil {
return nil, err
}

resourceId := SpringCloudAcceleratorId{
SubscriptionId: id.SubscriptionID,
ResourceGroup: id.ResourceGroup,
}

if resourceId.SubscriptionId == "" {
return nil, fmt.Errorf("ID was missing the 'subscriptions' element")
}

if resourceId.ResourceGroup == "" {
return nil, fmt.Errorf("ID was missing the 'resourceGroups' element")
}

if resourceId.SpringName, err = id.PopSegment("Spring"); err != nil {
return nil, err
}
if resourceId.ApplicationAcceleratorName, err = id.PopSegment("applicationAccelerators"); err != nil {
return nil, err
}

if err := id.ValidateNoEmptySegments(input); err != nil {
return nil, err
}

return &resourceId, nil
}
128 changes: 128 additions & 0 deletions internal/services/springcloud/parse/spring_cloud_accelerator_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
package parse

// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten

import (
"testing"

"github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids"
)

var _ resourceids.Id = SpringCloudAcceleratorId{}

func TestSpringCloudAcceleratorIDFormatter(t *testing.T) {
actual := NewSpringCloudAcceleratorID("12345678-1234-9876-4563-123456789012", "resGroup1", "spring1", "default").ID()
expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1/applicationAccelerators/default"
if actual != expected {
t.Fatalf("Expected %q but got %q", expected, actual)
}
}

func TestSpringCloudAcceleratorID(t *testing.T) {
testData := []struct {
Input string
Error bool
Expected *SpringCloudAcceleratorId
}{

{
// empty
Input: "",
Error: true,
},

{
// missing SubscriptionId
Input: "/",
Error: true,
},

{
// missing value for SubscriptionId
Input: "/subscriptions/",
Error: true,
},

{
// missing ResourceGroup
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/",
Error: true,
},

{
// missing value for ResourceGroup
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/",
Error: true,
},

{
// missing SpringName
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/",
Error: true,
},

{
// missing value for SpringName
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/",
Error: true,
},

{
// missing ApplicationAcceleratorName
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1/",
Error: true,
},

{
// missing value for ApplicationAcceleratorName
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1/applicationAccelerators/",
Error: true,
},

{
// valid
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1/applicationAccelerators/default",
Expected: &SpringCloudAcceleratorId{
SubscriptionId: "12345678-1234-9876-4563-123456789012",
ResourceGroup: "resGroup1",
SpringName: "spring1",
ApplicationAcceleratorName: "default",
},
},

{
// upper-cased
Input: "/SUBSCRIPTIONS/12345678-1234-9876-4563-123456789012/RESOURCEGROUPS/RESGROUP1/PROVIDERS/MICROSOFT.APPPLATFORM/SPRING/SPRING1/APPLICATIONACCELERATORS/DEFAULT",
Error: true,
},
}

for _, v := range testData {
t.Logf("[DEBUG] Testing %q", v.Input)

actual, err := SpringCloudAcceleratorID(v.Input)
if err != nil {
if v.Error {
continue
}

t.Fatalf("Expect a value but got an error: %s", err)
}
if v.Error {
t.Fatal("Expect an error but didn't get one")
}

if actual.SubscriptionId != v.Expected.SubscriptionId {
t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId)
}
if actual.ResourceGroup != v.Expected.ResourceGroup {
t.Fatalf("Expected %q but got %q for ResourceGroup", v.Expected.ResourceGroup, actual.ResourceGroup)
}
if actual.SpringName != v.Expected.SpringName {
t.Fatalf("Expected %q but got %q for SpringName", v.Expected.SpringName, actual.SpringName)
}
if actual.ApplicationAcceleratorName != v.Expected.ApplicationAcceleratorName {
t.Fatalf("Expected %q but got %q for ApplicationAcceleratorName", v.Expected.ApplicationAcceleratorName, actual.ApplicationAcceleratorName)
}
}
}
1 change: 1 addition & 0 deletions internal/services/springcloud/registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ func (r Registration) DataSources() []sdk.DataSource {

func (r Registration) Resources() []sdk.Resource {
return []sdk.Resource{
SpringCloudAcceleratorResource{},
SpringCloudApplicationLiveViewResource{},
}
}
1 change: 1 addition & 0 deletions internal/services/springcloud/resourceids.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package springcloud

//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=SpringCloudAccelerator -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1/applicationAccelerators/default
//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=SpringCloudApp -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/apps/app1 -rewrite=true
//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=SpringCloudAppAssociation -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/apps/app1/bindings/bind1 -rewrite=true
//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=SpringCloudAPIPortal -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/apiPortals/apiPortal1 -rewrite=true
Expand Down
Loading

0 comments on commit fdefa09

Please sign in to comment.