Skip to content

Commit

Permalink
azurerm_spring_cloud_service - build_agent_pool_size (#16841)
Browse files Browse the repository at this point in the history
Co-authored-by: kt <kt@katbyte.me>
  • Loading branch information
ms-henglu and katbyte authored May 26, 2022
1 parent 37e390a commit f017aac
Show file tree
Hide file tree
Showing 4 changed files with 156 additions and 35 deletions.
73 changes: 39 additions & 34 deletions internal/services/springcloud/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,24 @@ import (
)

type Client struct {
APIPortalClient *appplatform.APIPortalsClient
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
GatewayCustomDomainClient *appplatform.GatewayCustomDomainsClient
GatewayRouteConfigClient *appplatform.GatewayRouteConfigsClient
MonitoringSettingsClient *appplatform.MonitoringSettingsClient
DeploymentsClient *appplatform.DeploymentsClient
ServicesClient *appplatform.ServicesClient
ServiceRegistryClient *appplatform.ServiceRegistriesClient
StoragesClient *appplatform.StoragesClient
APIPortalClient *appplatform.APIPortalsClient
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 {
bindingsClient := appplatform.NewBindingsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&bindingsClient.Client, o.ResourceManagerAuthorizer)

buildServiceAgentPoolClient := appplatform.NewBuildServiceAgentPoolClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&buildServiceAgentPoolClient.Client, o.ResourceManagerAuthorizer)

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

Expand Down Expand Up @@ -78,22 +82,23 @@ func NewClient(o *common.ClientOptions) *Client {
o.ConfigureClient(&storageClient.Client, o.ResourceManagerAuthorizer)

return &Client{
APIPortalClient: &apiPortalClient,
AppsClient: &appsClient,
BindingsClient: &bindingsClient,
BuildPackBindingClient: &buildpackBindingClient,
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,
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,
}
}
60 changes: 60 additions & 0 deletions internal/services/springcloud/spring_cloud_service_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@ func resourceSpringCloudService() *pluginsdk.Resource {
}, false),
},

"build_agent_pool_size": {
Type: pluginsdk.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{
"S1",
"S2",
"S3",
"S4",
"S5",
}, false),
},

"network": {
Type: pluginsdk.TypeList,
Optional: true,
Expand Down Expand Up @@ -291,6 +303,7 @@ func resourceSpringCloudServiceCreate(d *pluginsdk.ResourceData, meta interface{
configServersClient := meta.(*clients.Client).AppPlatform.ConfigServersClient
monitoringSettingsClient := meta.(*clients.Client).AppPlatform.MonitoringSettingsClient
serviceRegistryClient := meta.(*clients.Client).AppPlatform.ServiceRegistryClient
agentPoolClient := meta.(*clients.Client).AppPlatform.BuildServiceAgentPoolClient
subscriptionId := meta.(*clients.Client).Account.SubscriptionId
ctx, cancel := timeouts.ForCreate(meta.(*clients.Client).StopContext, d)
defer cancel()
Expand Down Expand Up @@ -368,6 +381,24 @@ func resourceSpringCloudServiceCreate(d *pluginsdk.ResourceData, meta interface{
}
}

if size := d.Get("build_agent_pool_size").(string); len(size) > 0 {
agentPoolResource := appplatform.BuildServiceAgentPoolResource{
Properties: &appplatform.BuildServiceAgentPoolProperties{
PoolSize: &appplatform.BuildServiceAgentPoolSizeProperties{
Name: utils.String(size),
},
},
}
future, err := agentPoolClient.UpdatePut(ctx, id.ResourceGroup, id.SpringName, "default", "default", agentPoolResource)
if err != nil {
return fmt.Errorf("creating default build agent of %s: %+v", id, err)
}

if err := future.WaitForCompletionRef(ctx, client.Client); err != nil {
return fmt.Errorf("waiting for creation default build agent of %s: %+v", id, err)
}
}

return resourceSpringCloudServiceRead(d, meta)
}

Expand All @@ -376,6 +407,7 @@ func resourceSpringCloudServiceUpdate(d *pluginsdk.ResourceData, meta interface{
configServersClient := meta.(*clients.Client).AppPlatform.ConfigServersClient
monitoringSettingsClient := meta.(*clients.Client).AppPlatform.MonitoringSettingsClient
serviceRegistryClient := meta.(*clients.Client).AppPlatform.ServiceRegistryClient
agentPoolClient := meta.(*clients.Client).AppPlatform.BuildServiceAgentPoolClient
ctx, cancel := timeouts.ForUpdate(meta.(*clients.Client).StopContext, d)
defer cancel()

Expand Down Expand Up @@ -452,6 +484,24 @@ func resourceSpringCloudServiceUpdate(d *pluginsdk.ResourceData, meta interface{
}
}

if size := d.Get("build_agent_pool_size").(string); len(size) > 0 {
agentPoolResource := appplatform.BuildServiceAgentPoolResource{
Properties: &appplatform.BuildServiceAgentPoolProperties{
PoolSize: &appplatform.BuildServiceAgentPoolSizeProperties{
Name: utils.String(size),
},
},
}
future, err := agentPoolClient.UpdatePut(ctx, id.ResourceGroup, id.SpringName, "default", "default", agentPoolResource)
if err != nil {
return fmt.Errorf("creating default build agent of %s: %+v", id, err)
}

if err := future.WaitForCompletionRef(ctx, client.Client); err != nil {
return fmt.Errorf("waiting for creation default build agent of %s: %+v", id, err)
}
}

return resourceSpringCloudServiceRead(d, meta)
}

Expand All @@ -460,6 +510,7 @@ func resourceSpringCloudServiceRead(d *pluginsdk.ResourceData, meta interface{})
configServersClient := meta.(*clients.Client).AppPlatform.ConfigServersClient
monitoringSettingsClient := meta.(*clients.Client).AppPlatform.MonitoringSettingsClient
serviceRegistryClient := meta.(*clients.Client).AppPlatform.ServiceRegistryClient
agentPoolClient := meta.(*clients.Client).AppPlatform.BuildServiceAgentPoolClient
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d)
defer cancel()

Expand Down Expand Up @@ -499,6 +550,15 @@ func resourceSpringCloudServiceRead(d *pluginsdk.ResourceData, meta interface{})
if utils.ResponseWasNotFound(serviceRegistry.Response) {
serviceRegistryEnabled = false
}
agentPool, err := agentPoolClient.Get(ctx, id.ResourceGroup, id.SpringName, "default", "default")
if err == nil && agentPool.Properties != nil && agentPool.Properties.PoolSize != nil {
d.Set("build_agent_pool_size", agentPool.Properties.PoolSize.Name)
} else {
if err != nil {
log.Printf("[WARN] error retrieving build agent pool of %q: %+v", id, err)
}
d.Set("build_agent_pool_size", "")
}

d.Set("name", id.SpringName)
d.Set("resource_group_name", id.ResourceGroup)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,35 @@ func TestAccSpringCloudService_serviceRegistry(t *testing.T) {
})
}

func TestAccSpringCloudService_buildAgentPool(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_spring_cloud_service", "test")
r := SpringCloudServiceResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.buildAgentPool(data, "S1"),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
{
Config: r.buildAgentPool(data, "S2"),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
{
Config: r.buildAgentPool(data, "S1"),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

func TestAccSpringCloudService_zoneRedundant(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_spring_cloud_service", "test")
r := SpringCloudServiceResource{}
Expand Down Expand Up @@ -263,6 +292,27 @@ resource "azurerm_spring_cloud_service" "test" {
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, enabled)
}

func (SpringCloudServiceResource) buildAgentPool(data acceptance.TestData, size string) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "test" {
name = "acctestRG-spring-%d"
location = "%s"
}
resource "azurerm_spring_cloud_service" "test" {
name = "acctest-sc-%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
sku_name = "E0"
build_agent_pool_size = "%s"
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, size)
}

func (SpringCloudServiceResource) singleGitRepo(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
Expand Down Expand Up @@ -389,7 +439,11 @@ resource "azurerm_spring_cloud_service" "test" {
func (SpringCloudServiceResource) virtualNetwork(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
features {
resource_group {
prevent_deletion_if_contains_resources = false
}
}
}
provider "azuread" {}
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/spring_cloud_service.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ The following arguments are supported:

-> **Note:** At this time Azure Spring Cloud Service is only supported in a subset of regions (including `East US`, `South East Asia`, `West Europe` and `West US 2`.

* `build_agent_pool_size` - (Optional) Specifies the size for this Spring Cloud Service's default build agent pool. Possible values are `S1`, `S2`, `S3`, `S4` and `S5`.

* `sku_name` - (Optional) Specifies the SKU Name for this Spring Cloud Service. Possible values are `B0`, `S0` and `E0`. Defaults to `S0`.

* `network` - (Optional) A `network` block as defined below. Changing this forces a new resource to be created.
Expand Down

0 comments on commit f017aac

Please sign in to comment.