diff --git a/internal/services/springcloud/client/client.go b/internal/services/springcloud/client/client.go index 317d553bf10d..293183becd20 100644 --- a/internal/services/springcloud/client/client.go +++ b/internal/services/springcloud/client/client.go @@ -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 { @@ -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) @@ -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, } } diff --git a/internal/services/springcloud/parse/spring_cloud_accelerator.go b/internal/services/springcloud/parse/spring_cloud_accelerator.go new file mode 100644 index 000000000000..6503746babf2 --- /dev/null +++ b/internal/services/springcloud/parse/spring_cloud_accelerator.go @@ -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 +} diff --git a/internal/services/springcloud/parse/spring_cloud_accelerator_test.go b/internal/services/springcloud/parse/spring_cloud_accelerator_test.go new file mode 100644 index 000000000000..323674cee9a8 --- /dev/null +++ b/internal/services/springcloud/parse/spring_cloud_accelerator_test.go @@ -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) + } + } +} diff --git a/internal/services/springcloud/registration.go b/internal/services/springcloud/registration.go index cbd250765f8d..5069187f0df6 100644 --- a/internal/services/springcloud/registration.go +++ b/internal/services/springcloud/registration.go @@ -68,6 +68,7 @@ func (r Registration) DataSources() []sdk.DataSource { func (r Registration) Resources() []sdk.Resource { return []sdk.Resource{ + SpringCloudAcceleratorResource{}, SpringCloudApplicationLiveViewResource{}, } } diff --git a/internal/services/springcloud/resourceids.go b/internal/services/springcloud/resourceids.go index a05c90454a48..225ea32dcf52 100644 --- a/internal/services/springcloud/resourceids.go +++ b/internal/services/springcloud/resourceids.go @@ -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 diff --git a/internal/services/springcloud/spring_cloud_accelerator_resource.go b/internal/services/springcloud/spring_cloud_accelerator_resource.go new file mode 100644 index 000000000000..4c5ce98b5bbb --- /dev/null +++ b/internal/services/springcloud/spring_cloud_accelerator_resource.go @@ -0,0 +1,155 @@ +package springcloud + +import ( + "context" + "fmt" + "time" + + "github.com/hashicorp/go-azure-helpers/lang/response" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-provider-azurerm/internal/sdk" + "github.com/hashicorp/terraform-provider-azurerm/internal/services/springcloud/parse" + "github.com/hashicorp/terraform-provider-azurerm/internal/services/springcloud/validate" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation" + "github.com/hashicorp/terraform-provider-azurerm/utils" + "github.com/tombuildsstuff/kermit/sdk/appplatform/2022-11-01-preview/appplatform" +) + +type SpringCloudAcceleratorModel struct { + Name string `tfschema:"name"` + SpringCloudServiceId string `tfschema:"spring_cloud_service_id"` +} + +type SpringCloudAcceleratorResource struct{} + +var _ sdk.Resource = SpringCloudAcceleratorResource{} + +func (s SpringCloudAcceleratorResource) ResourceType() string { + return "azurerm_spring_cloud_accelerator" +} + +func (s SpringCloudAcceleratorResource) ModelObject() interface{} { + return &SpringCloudAcceleratorModel{} +} + +func (s SpringCloudAcceleratorResource) IDValidationFunc() pluginsdk.SchemaValidateFunc { + return validate.SpringCloudAcceleratorID +} + +func (s SpringCloudAcceleratorResource) Arguments() map[string]*schema.Schema { + return map[string]*pluginsdk.Schema{ + "name": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validation.StringInSlice([]string{"default"}, false), + }, + + "spring_cloud_service_id": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validate.SpringCloudServiceID, + }, + } +} + +func (s SpringCloudAcceleratorResource) Attributes() map[string]*schema.Schema { + return map[string]*pluginsdk.Schema{} +} + +func (s SpringCloudAcceleratorResource) Create() sdk.ResourceFunc { + return sdk.ResourceFunc{ + Timeout: 30 * time.Minute, + Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { + var model SpringCloudAcceleratorModel + if err := metadata.Decode(&model); err != nil { + return fmt.Errorf("decoding: %+v", err) + } + + client := metadata.Client.AppPlatform.ApplicationAcceleratorClient + springId, err := parse.SpringCloudServiceID(model.SpringCloudServiceId) + if err != nil { + return fmt.Errorf("parsing spring service ID: %+v", err) + } + id := parse.NewSpringCloudAcceleratorID(springId.SubscriptionId, springId.ResourceGroup, springId.SpringName, model.Name) + + existing, err := client.Get(ctx, id.ResourceGroup, id.SpringName, id.ApplicationAcceleratorName) + if err != nil && !utils.ResponseWasNotFound(existing.Response) { + return fmt.Errorf("checking for existing %s: %+v", id, err) + } + if !utils.ResponseWasNotFound(existing.Response) { + return metadata.ResourceRequiresImport(s.ResourceType(), id) + } + + AcceleratorResource := appplatform.ApplicationAcceleratorResource{} + future, err := client.CreateOrUpdate(ctx, id.ResourceGroup, id.SpringName, id.ApplicationAcceleratorName, AcceleratorResource) + if err != nil { + return fmt.Errorf("creating %s: %+v", id, err) + } + + if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { + return fmt.Errorf("waiting for creation of %s: %+v", id, err) + } + + metadata.SetID(id) + return nil + }, + } +} + +func (s SpringCloudAcceleratorResource) Read() sdk.ResourceFunc { + return sdk.ResourceFunc{ + Timeout: 5 * time.Minute, + Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { + client := metadata.Client.AppPlatform.ApplicationAcceleratorClient + + id, err := parse.SpringCloudAcceleratorID(metadata.ResourceData.Id()) + if err != nil { + return err + } + + resp, err := client.Get(ctx, id.ResourceGroup, id.SpringName, id.ApplicationAcceleratorName) + if err != nil { + if utils.ResponseWasNotFound(resp.Response) { + return metadata.MarkAsGone(id) + } + + return fmt.Errorf("retrieving %s: %+v", *id, err) + } + state := SpringCloudAcceleratorModel{ + Name: id.ApplicationAcceleratorName, + SpringCloudServiceId: parse.NewSpringCloudServiceID(id.SubscriptionId, id.ResourceGroup, id.SpringName).ID(), + } + return metadata.Encode(&state) + }, + } +} + +func (s SpringCloudAcceleratorResource) Delete() sdk.ResourceFunc { + return sdk.ResourceFunc{ + Timeout: 30 * time.Minute, + Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { + client := metadata.Client.AppPlatform.ApplicationAcceleratorClient + + id, err := parse.SpringCloudAcceleratorID(metadata.ResourceData.Id()) + if err != nil { + return err + } + + future, err := client.Delete(ctx, id.ResourceGroup, id.SpringName, id.ApplicationAcceleratorName) + if err != nil { + return fmt.Errorf("deleting %s: %+v", *id, err) + } + + if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { + if !response.WasNotFound(future.Response()) { + return fmt.Errorf("waiting for deletion of %s: %+v", *id, err) + } + } + + return nil + }, + } +} diff --git a/internal/services/springcloud/spring_cloud_accelerator_resource_test.go b/internal/services/springcloud/spring_cloud_accelerator_resource_test.go new file mode 100644 index 000000000000..09c9b70b70fa --- /dev/null +++ b/internal/services/springcloud/spring_cloud_accelerator_resource_test.go @@ -0,0 +1,105 @@ +package springcloud_test + +import ( + "context" + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance" + "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check" + "github.com/hashicorp/terraform-provider-azurerm/internal/clients" + "github.com/hashicorp/terraform-provider-azurerm/internal/services/springcloud/parse" + "github.com/hashicorp/terraform-provider-azurerm/utils" +) + +type SpringCloudAcceleratorResource struct{} + +func TestAccSpringCloudAccelerator_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_spring_cloud_accelerator", "test") + r := SpringCloudAcceleratorResource{} + data.ResourceTest(t, r, []resource.TestStep{ + { + Config: r.basic(data), + Check: resource.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + +func TestAccSpringCloudAccelerator_requiresImport(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_spring_cloud_accelerator", "test") + r := SpringCloudAcceleratorResource{} + data.ResourceTest(t, r, []resource.TestStep{ + { + Config: r.basic(data), + Check: resource.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.RequiresImportErrorStep(r.requiresImport), + }) +} + +func (r SpringCloudAcceleratorResource) Exists(ctx context.Context, client *clients.Client, state *terraform.InstanceState) (*bool, error) { + id, err := parse.SpringCloudAcceleratorID(state.ID) + if err != nil { + return nil, err + } + resp, err := client.AppPlatform.ApplicationAcceleratorClient.Get(ctx, id.ResourceGroup, id.SpringName, id.ApplicationAcceleratorName) + if err != nil { + if utils.ResponseWasNotFound(resp.Response) { + return utils.Bool(false), nil + } + return nil, fmt.Errorf("retrieving %s: %+v", id, err) + } + return utils.Bool(true), nil +} + +func (r SpringCloudAcceleratorResource) template(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-spring-%[2]d" + location = "%[1]s" +} + +resource "azurerm_spring_cloud_service" "test" { + name = "acctest-sc-%[2]d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + sku_name = "E0" +} + +`, data.Locations.Primary, data.RandomInteger) +} + +func (r SpringCloudAcceleratorResource) basic(data acceptance.TestData) string { + template := r.template(data) + return fmt.Sprintf(` +%s + +resource "azurerm_spring_cloud_accelerator" "test" { + name = "default" + spring_cloud_service_id = azurerm_spring_cloud_service.test.id +} +`, template) +} + +func (r SpringCloudAcceleratorResource) requiresImport(data acceptance.TestData) string { + config := r.basic(data) + return fmt.Sprintf(` +%s + +resource "azurerm_spring_cloud_accelerator" "import" { + name = azurerm_spring_cloud_accelerator.test.name + spring_cloud_service_id = azurerm_spring_cloud_accelerator.test.spring_cloud_service_id +} +`, config) +} diff --git a/internal/services/springcloud/validate/spring_cloud_accelerator_id.go b/internal/services/springcloud/validate/spring_cloud_accelerator_id.go new file mode 100644 index 000000000000..4889e4fc5553 --- /dev/null +++ b/internal/services/springcloud/validate/spring_cloud_accelerator_id.go @@ -0,0 +1,23 @@ +package validate + +// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten + +import ( + "fmt" + + "github.com/hashicorp/terraform-provider-azurerm/internal/services/springcloud/parse" +) + +func SpringCloudAcceleratorID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := parse.SpringCloudAcceleratorID(v); err != nil { + errors = append(errors, err) + } + + return +} diff --git a/internal/services/springcloud/validate/spring_cloud_accelerator_id_test.go b/internal/services/springcloud/validate/spring_cloud_accelerator_id_test.go new file mode 100644 index 000000000000..03f2f691e8a9 --- /dev/null +++ b/internal/services/springcloud/validate/spring_cloud_accelerator_id_test.go @@ -0,0 +1,88 @@ +package validate + +// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten + +import "testing" + +func TestSpringCloudAcceleratorID(t *testing.T) { + cases := []struct { + Input string + Valid bool + }{ + + { + // empty + Input: "", + Valid: false, + }, + + { + // missing SubscriptionId + Input: "/", + Valid: false, + }, + + { + // missing value for SubscriptionId + Input: "/subscriptions/", + Valid: false, + }, + + { + // missing ResourceGroup + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/", + Valid: false, + }, + + { + // missing value for ResourceGroup + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/", + Valid: false, + }, + + { + // missing SpringName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/", + Valid: false, + }, + + { + // missing value for SpringName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/", + Valid: false, + }, + + { + // missing ApplicationAcceleratorName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1/", + Valid: false, + }, + + { + // missing value for ApplicationAcceleratorName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1/applicationAccelerators/", + Valid: false, + }, + + { + // valid + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1/applicationAccelerators/default", + Valid: true, + }, + + { + // upper-cased + Input: "/SUBSCRIPTIONS/12345678-1234-9876-4563-123456789012/RESOURCEGROUPS/RESGROUP1/PROVIDERS/MICROSOFT.APPPLATFORM/SPRING/SPRING1/APPLICATIONACCELERATORS/DEFAULT", + Valid: false, + }, + } + for _, tc := range cases { + t.Logf("[DEBUG] Testing Value %s", tc.Input) + _, errors := SpringCloudAcceleratorID(tc.Input, "test") + valid := len(errors) == 0 + + if tc.Valid != valid { + t.Fatalf("Expected %t but got %t", tc.Valid, valid) + } + } +} diff --git a/website/docs/r/spring_cloud_accelerator.html.markdown b/website/docs/r/spring_cloud_accelerator.html.markdown new file mode 100644 index 000000000000..ecad63461869 --- /dev/null +++ b/website/docs/r/spring_cloud_accelerator.html.markdown @@ -0,0 +1,69 @@ +--- +subcategory: "Spring Cloud" +layout: "azurerm" +page_title: "Azure Resource Manager: azurerm_spring_cloud_accelerator" +description: |- + Manages a Spring Cloud Accelerator. +--- + +# azurerm_spring_cloud_accelerator + +-> **NOTE:** This resource is applicable only for Spring Cloud Service with enterprise tier. + +Manages a Spring Cloud Accelerator. + +## Example Usage + +```hcl +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "example" { + name = "example" + location = "West Europe" +} + +resource "azurerm_spring_cloud_service" "example" { + name = "example" + location = azurerm_resource_group.example.location + resource_group_name = azurerm_resource_group.example.name + sku_name = "E0" +} + +resource "azurerm_spring_cloud_accelerator" "example" { + name = "default" + spring_cloud_service_id = azurerm_spring_cloud_service.example.id +} +``` + +## Arguments Reference + +The following arguments are supported: + +* `name` - (Required) The name which should be used for this Spring Cloud Accelerator. Changing this forces a new Spring Cloud Accelerator to be created. The only possible value is `default`. + +* `spring_cloud_service_id` - (Required) The ID of the Spring Cloud Service. Changing this forces a new Spring Cloud Accelerator to be created. + +## Attributes Reference + +In addition to the Arguments listed above - the following Attributes are exported: + +* `id` - The ID of the Spring Cloud Accelerator. + +## Timeouts + +The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/language/resources/syntax#operation-timeouts) for certain actions: + +* `create` - (Defaults to 30 minutes) Used when creating the Spring Cloud Accelerator. +* `read` - (Defaults to 5 minutes) Used when retrieving the Spring Cloud Accelerator. +* `update` - (Defaults to 30 minutes) Used when updating the Spring Cloud Accelerator. +* `delete` - (Defaults to 30 minutes) Used when deleting the Spring Cloud Accelerator. + +## Import + +Spring Cloud Accelerators can be imported using the `resource id`, e.g. + +```shell +terraform import azurerm_spring_cloud_accelerator.example /subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/applicationAccelerators/default +```