Skip to content

Commit

Permalink
new resource azurerm_spring_cloud_builder
Browse files Browse the repository at this point in the history
  • Loading branch information
ms-henglu committed Mar 25, 2022
1 parent 132d4bd commit 61183b2
Show file tree
Hide file tree
Showing 10 changed files with 913 additions and 18 deletions.
81 changes: 63 additions & 18 deletions internal/services/springcloud/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,54 +6,99 @@ import (
)

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

func NewClient(o *common.ClientOptions) *Client {
apiPortalClient := appplatform.NewAPIPortalsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&apiPortalClient.Client, o.ResourceManagerAuthorizer)

apiPortalCustomDomainClient := appplatform.NewAPIPortalCustomDomainsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&apiPortalCustomDomainClient.Client, o.ResourceManagerAuthorizer)

appsClient := appplatform.NewAppsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&appsClient.Client, o.ResourceManagerAuthorizer)

bindingsClient := appplatform.NewBindingsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&bindingsClient.Client, o.ResourceManagerAuthorizer)

buildpackBindingClient := appplatform.NewBuildpackBindingClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&buildpackBindingClient.Client, o.ResourceManagerAuthorizer)

buildServiceBuilderClient := appplatform.NewBuildServiceBuilderClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&buildServiceBuilderClient.Client, o.ResourceManagerAuthorizer)

certificatesClient := appplatform.NewCertificatesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&certificatesClient.Client, o.ResourceManagerAuthorizer)

configServersClient := appplatform.NewConfigServersClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&configServersClient.Client, o.ResourceManagerAuthorizer)

configurationServiceClient := appplatform.NewConfigurationServicesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&configurationServiceClient.Client, o.ResourceManagerAuthorizer)

customDomainsClient := appplatform.NewCustomDomainsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&customDomainsClient.Client, o.ResourceManagerAuthorizer)

deploymentsClient := appplatform.NewDeploymentsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&deploymentsClient.Client, o.ResourceManagerAuthorizer)

gatewayClient := appplatform.NewGatewaysClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&gatewayClient.Client, o.ResourceManagerAuthorizer)

gatewayRouteConfigClient := appplatform.NewGatewayRouteConfigsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&gatewayRouteConfigClient.Client, o.ResourceManagerAuthorizer)

gatewayCustomDomainClient := appplatform.NewGatewayCustomDomainsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&gatewayCustomDomainClient.Client, o.ResourceManagerAuthorizer)

monitoringSettingsClient := appplatform.NewMonitoringSettingsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&monitoringSettingsClient.Client, o.ResourceManagerAuthorizer)

servicesClient := appplatform.NewServicesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&servicesClient.Client, o.ResourceManagerAuthorizer)

serviceRegistryClient := appplatform.NewServiceRegistriesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&serviceRegistryClient.Client, o.ResourceManagerAuthorizer)

storageClient := appplatform.NewStoragesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&storageClient.Client, o.ResourceManagerAuthorizer)

return &Client{
AppsClient: &appsClient,
BindingsClient: &bindingsClient,
CertificatesClient: &certificatesClient,
ConfigServersClient: &configServersClient,
CustomDomainsClient: &customDomainsClient,
DeploymentsClient: &deploymentsClient,
MonitoringSettingsClient: &monitoringSettingsClient,
ServicesClient: &servicesClient,
StoragesClient: &storageClient,
APIPortalClient: &apiPortalClient,
APIPortalCustomDomainClient: &apiPortalCustomDomainClient,
AppsClient: &appsClient,
BindingsClient: &bindingsClient,
BuildpackBindingClient: &buildpackBindingClient,
BuildServiceBuilderClient: &buildServiceBuilderClient,
CertificatesClient: &certificatesClient,
ConfigServersClient: &configServersClient,
ConfigurationServiceClient: &configurationServiceClient,
CustomDomainsClient: &customDomainsClient,
DeploymentsClient: &deploymentsClient,
GatewayClient: &gatewayClient,
GatewayRouteConfigClient: &gatewayRouteConfigClient,
GatewayCustomDomainClient: &gatewayCustomDomainClient,
MonitoringSettingsClient: &monitoringSettingsClient,
ServicesClient: &servicesClient,
ServiceRegistryClient: &serviceRegistryClient,
StoragesClient: &storageClient,
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
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 SpringCloudBuildServiceBuilderId struct {
SubscriptionId string
ResourceGroup string
SpringName string
BuildServiceName string
BuilderName string
}

func NewSpringCloudBuildServiceBuilderID(subscriptionId, resourceGroup, springName, buildServiceName, builderName string) SpringCloudBuildServiceBuilderId {
return SpringCloudBuildServiceBuilderId{
SubscriptionId: subscriptionId,
ResourceGroup: resourceGroup,
SpringName: springName,
BuildServiceName: buildServiceName,
BuilderName: builderName,
}
}

func (id SpringCloudBuildServiceBuilderId) String() string {
segments := []string{
fmt.Sprintf("Builder Name %q", id.BuilderName),
fmt.Sprintf("Build Service Name %q", id.BuildServiceName),
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 Build Service Builder", segmentsStr)
}

func (id SpringCloudBuildServiceBuilderId) ID() string {
fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.AppPlatform/Spring/%s/buildServices/%s/builders/%s"
return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup, id.SpringName, id.BuildServiceName, id.BuilderName)
}

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

resourceId := SpringCloudBuildServiceBuilderId{
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.BuildServiceName, err = id.PopSegment("buildServices"); err != nil {
return nil, err
}
if resourceId.BuilderName, err = id.PopSegment("builders"); err != nil {
return nil, err
}

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

return &resourceId, nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
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 = SpringCloudBuildServiceBuilderId{}

func TestSpringCloudBuildServiceBuilderIDFormatter(t *testing.T) {
actual := NewSpringCloudBuildServiceBuilderID("12345678-1234-9876-4563-123456789012", "resourceGroup1", "service1", "buildService1", "builder1").ID()
expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/buildServices/buildService1/builders/builder1"
if actual != expected {
t.Fatalf("Expected %q but got %q", expected, actual)
}
}

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

{
// 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/resourceGroup1/providers/Microsoft.AppPlatform/",
Error: true,
},

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

{
// missing BuildServiceName
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/",
Error: true,
},

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

{
// missing BuilderName
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/buildServices/buildService1/",
Error: true,
},

{
// missing value for BuilderName
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/buildServices/buildService1/builders/",
Error: true,
},

{
// valid
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/buildServices/buildService1/builders/builder1",
Expected: &SpringCloudBuildServiceBuilderId{
SubscriptionId: "12345678-1234-9876-4563-123456789012",
ResourceGroup: "resourceGroup1",
SpringName: "service1",
BuildServiceName: "buildService1",
BuilderName: "builder1",
},
},

{
// upper-cased
Input: "/SUBSCRIPTIONS/12345678-1234-9876-4563-123456789012/RESOURCEGROUPS/RESOURCEGROUP1/PROVIDERS/MICROSOFT.APPPLATFORM/SPRING/SERVICE1/BUILDSERVICES/BUILDSERVICE1/BUILDERS/BUILDER1",
Error: true,
},
}

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

actual, err := SpringCloudBuildServiceBuilderID(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.BuildServiceName != v.Expected.BuildServiceName {
t.Fatalf("Expected %q but got %q for BuildServiceName", v.Expected.BuildServiceName, actual.BuildServiceName)
}
if actual.BuilderName != v.Expected.BuilderName {
t.Fatalf("Expected %q but got %q for BuilderName", v.Expected.BuilderName, actual.BuilderName)
}
}
}
1 change: 1 addition & 0 deletions internal/services/springcloud/registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func (r Registration) SupportedResources() map[string]*pluginsdk.Resource {
"azurerm_spring_cloud_app_cosmosdb_association": resourceSpringCloudAppCosmosDBAssociation(),
"azurerm_spring_cloud_app_mysql_association": resourceSpringCloudAppMysqlAssociation(),
"azurerm_spring_cloud_app_redis_association": resourceSpringCloudAppRedisAssociation(),
"azurerm_spring_cloud_builder": resourceSpringCloudBuildServiceBuilder(),
"azurerm_spring_cloud_certificate": resourceSpringCloudCertificate(),
"azurerm_spring_cloud_custom_domain": resourceSpringCloudCustomDomain(),
"azurerm_spring_cloud_java_deployment": resourceSpringCloudJavaDeployment(),
Expand Down
1 change: 1 addition & 0 deletions internal/services/springcloud/resourceids.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package springcloud

//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
//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
//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=SpringCloudBuildServiceBuilder -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/buildServices/buildService1/builders/builder1
//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=SpringCloudDeployment -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1/apps/app1/deployments/deploy1
//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=SpringCloudCertificate -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1/certificates/cert1
//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=SpringCloudCustomDomain -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1/apps/app1/domains/domain.com
Expand Down
Loading

0 comments on commit 61183b2

Please sign in to comment.