Skip to content

Commit f4830c0

Browse files
Merge pull request #7531 from njuCZ/spring_cloud_update
add support for `sku_name` and `trace` for `azurerm_spring_cloud_service`
2 parents d3ab4a5 + c6f2c8c commit f4830c0

File tree

3 files changed

+120
-7
lines changed

3 files changed

+120
-7
lines changed

azurerm/internal/services/appplatform/spring_cloud_service_resource.go

+86-6
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,17 @@ func resourceArmSpringCloudService() *schema.Resource {
5353

5454
"resource_group_name": azure.SchemaResourceGroupName(),
5555

56+
"sku_name": {
57+
Type: schema.TypeString,
58+
Optional: true,
59+
Default: "S0",
60+
ForceNew: true,
61+
ValidateFunc: validation.StringInSlice([]string{
62+
"B0",
63+
"S0",
64+
}, false),
65+
},
66+
5667
"config_server_git_setting": {
5768
Type: schema.TypeList,
5869
Optional: true,
@@ -133,6 +144,20 @@ func resourceArmSpringCloudService() *schema.Resource {
133144
},
134145
},
135146

147+
"trace": {
148+
Type: schema.TypeList,
149+
Optional: true,
150+
MaxItems: 1,
151+
Elem: &schema.Resource{
152+
Schema: map[string]*schema.Schema{
153+
"instrumentation_key": {
154+
Type: schema.TypeString,
155+
Required: true,
156+
},
157+
},
158+
},
159+
},
160+
136161
"tags": tags.Schema(),
137162
},
138163
}
@@ -159,7 +184,13 @@ func resourceArmSpringCloudServiceCreate(d *schema.ResourceData, meta interface{
159184
location := azure.NormalizeLocation(d.Get("location").(string))
160185
resource := appplatform.ServiceResource{
161186
Location: utils.String(location),
162-
Tags: tags.Expand(d.Get("tags").(map[string]interface{})),
187+
Properties: &appplatform.ClusterResourceProperties{
188+
Trace: expandArmSpringCloudTrace(d.Get("trace").([]interface{})),
189+
},
190+
Sku: &appplatform.Sku{
191+
Name: utils.String(d.Get("sku_name").(string)),
192+
},
193+
Tags: tags.Expand(d.Get("tags").(map[string]interface{})),
163194
}
164195

165196
gitProperty, err := expandArmSpringCloudConfigServerGitProperty(d.Get("config_server_git_setting").([]interface{}))
@@ -233,6 +264,10 @@ func resourceArmSpringCloudServiceUpdate(d *schema.ResourceData, meta interface{
233264
GitProperty: gitProperty,
234265
},
235266
},
267+
Trace: expandArmSpringCloudTrace(d.Get("trace").([]interface{})),
268+
},
269+
Sku: &appplatform.Sku{
270+
Name: utils.String(d.Get("sku_name").(string)),
236271
},
237272
Tags: tags.Expand(d.Get("tags").(map[string]interface{})),
238273
}
@@ -283,11 +318,18 @@ func resourceArmSpringCloudServiceRead(d *schema.ResourceData, meta interface{})
283318
if location := resp.Location; location != nil {
284319
d.Set("location", azure.NormalizeLocation(*location))
285320
}
286-
287-
if resp.Properties != nil && resp.Properties.ConfigServerProperties != nil && resp.Properties.ConfigServerProperties.ConfigServer != nil {
288-
if props := resp.Properties.ConfigServerProperties.ConfigServer.GitProperty; props != nil {
289-
if err := d.Set("config_server_git_setting", flattenArmSpringCloudConfigServerGitProperty(props, d)); err != nil {
290-
return fmt.Errorf("failure setting AzureRM Spring Cloud Service error: %+v", err)
321+
if resp.Sku != nil {
322+
d.Set("sku_name", resp.Sku.Name)
323+
}
324+
if resp.Properties != nil {
325+
if err := d.Set("trace", flattenArmSpringCloudTrace(resp.Properties.Trace)); err != nil {
326+
return fmt.Errorf("failure setting `trace`: %+v", err)
327+
}
328+
if resp.Properties.ConfigServerProperties != nil && resp.Properties.ConfigServerProperties.ConfigServer != nil {
329+
if props := resp.Properties.ConfigServerProperties.ConfigServer.GitProperty; props != nil {
330+
if err := d.Set("config_server_git_setting", flattenArmSpringCloudConfigServerGitProperty(props, d)); err != nil {
331+
return fmt.Errorf("failure setting AzureRM Spring Cloud Service error: %+v", err)
332+
}
291333
}
292334
}
293335
}
@@ -422,6 +464,19 @@ func expandArmSpringCloudGitPatternRepository(input []interface{}) (*[]appplatfo
422464
return &results, nil
423465
}
424466

467+
func expandArmSpringCloudTrace(input []interface{}) *appplatform.TraceProperties {
468+
if len(input) == 0 || input[0] == nil {
469+
return &appplatform.TraceProperties{
470+
Enabled: utils.Bool(false),
471+
}
472+
}
473+
v := input[0].(map[string]interface{})
474+
return &appplatform.TraceProperties{
475+
Enabled: utils.Bool(true),
476+
AppInsightInstrumentationKey: utils.String(v["instrumentation_key"].(string)),
477+
}
478+
}
479+
425480
func flattenArmSpringCloudConfigServerGitProperty(input *appplatform.ConfigServerGitProperty, d *schema.ResourceData) []interface{} {
426481
if input == nil {
427482
return []interface{}{}
@@ -618,3 +673,28 @@ func flattenArmSpringCloudGitPatternRepository(input *[]appplatform.GitPatternRe
618673

619674
return results
620675
}
676+
677+
func flattenArmSpringCloudTrace(input *appplatform.TraceProperties) []interface{} {
678+
if input == nil {
679+
return []interface{}{}
680+
}
681+
682+
enabled := false
683+
instrumentationKey := ""
684+
if input.Enabled != nil {
685+
enabled = *input.Enabled
686+
}
687+
if input.AppInsightInstrumentationKey != nil {
688+
instrumentationKey = *input.AppInsightInstrumentationKey
689+
}
690+
691+
if !enabled {
692+
return []interface{}{}
693+
}
694+
695+
return []interface{}{
696+
map[string]interface{}{
697+
"instrumentation_key": instrumentationKey,
698+
},
699+
}
700+
}

azurerm/internal/services/appplatform/tests/spring_cloud_service_resource_test.go

+12-1
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,13 @@ resource "azurerm_resource_group" "test" {
197197
location = "%s"
198198
}
199199
200+
resource "azurerm_application_insights" "test" {
201+
name = "acctestai-%d"
202+
location = azurerm_resource_group.test.location
203+
resource_group_name = azurerm_resource_group.test.name
204+
application_type = "web"
205+
}
206+
200207
resource "azurerm_spring_cloud_service" "test" {
201208
name = "acctest-sc-%d"
202209
location = azurerm_resource_group.test.location
@@ -233,12 +240,16 @@ resource "azurerm_spring_cloud_service" "test" {
233240
}
234241
}
235242
243+
trace {
244+
instrumentation_key = azurerm_application_insights.test.instrumentation_key
245+
}
246+
236247
tags = {
237248
Env = "Test"
238249
version = "1"
239250
}
240251
}
241-
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger)
252+
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger)
242253
}
243254

244255
func testAccAzureRMSpringCloudService_requiresImport(data acceptance.TestData) string {

website/docs/r/spring_cloud_service.html.markdown

+22
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,29 @@ resource "azurerm_resource_group" "example" {
2222
location = "Southeast Asia"
2323
}
2424
25+
resource "azurerm_application_insights" "example" {
26+
name = "tf-test-appinsights"
27+
location = azurerm_resource_group.example.location
28+
resource_group_name = azurerm_resource_group.example.name
29+
application_type = "web"
30+
}
31+
2532
resource "azurerm_spring_cloud_service" "example" {
2633
name = "example-springcloud"
2734
resource_group_name = azurerm_resource_group.example.name
2835
location = azurerm_resource_group.example.location
36+
sku_name = "S0"
2937
3038
config_server_git_setting {
3139
uri = "https://github.com/Azure-Samples/piggymetrics"
3240
label = "config"
3341
search_paths = ["dir1", "dir2"]
3442
}
3543
44+
trace {
45+
instrumentation_key = azurerm_application_insights.example.instrumentation_key
46+
}
47+
3648
tags = {
3749
Env = "staging"
3850
}
@@ -51,8 +63,12 @@ The following arguments are supported:
5163

5264
-> **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`.
5365

66+
* `sku_name` - (Optional) Specifies the SKU Name for this Spring Cloud Service. Possible values are `B0` and `S0`. Defaults to `S0`.
67+
5468
* `config_server_git_setting` - (Optional) A `config_server_git_setting` block as defined below.
5569

70+
* `trace` - (Optional) A `trace` block as defined below.
71+
5672
* `tags` - (Optional) A mapping of tags to assign to the resource.
5773

5874
---
@@ -109,6 +125,12 @@ The `ssh_auth` block supports the following:
109125

110126
* `strict_host_key_checking_enabled` - (Optional) Indicates whether the Config Server instance will fail to start if the host_key does not match.
111127

128+
---
129+
130+
The `trace` block supports the following:
131+
132+
* `instrumentation_key` - (Required) The Instrumentation Key used for Application Insights.
133+
112134
## Attributes Reference
113135

114136
The following attributes are exported:

0 commit comments

Comments
 (0)