Skip to content

Commit 1800517

Browse files
Merge pull request #9261 from njuCZ/spring_cloud_support_IP
"azurerm_spring_cloud_service" - exporting `outbound_public_ip_addresses`
2 parents 4c2f347 + d9377b3 commit 1800517

7 files changed

+71
-28
lines changed

.teamcity/components/settings.kt

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ var runNightly = mapOf(
1919

2020
// specifies a list of services which should be run with a custom test configuration
2121
var serviceTestConfigurationOverrides = mapOf(
22+
// Spring Cloud only allows a max of 10 provisioned
23+
"appplatform" to testConfiguration(5, defaultStartHour),
24+
2225
// The AKS API has a low rate limit
2326
"containers" to testConfiguration(5, defaultStartHour),
2427

azurerm/internal/services/appplatform/spring_cloud_service_data_source.go

+16-5
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,14 @@ func dataSourceArmSpringCloudService() *schema.Resource {
102102
},
103103
},
104104

105+
"outbound_public_ip_addresses": {
106+
Type: schema.TypeList,
107+
Computed: true,
108+
Elem: &schema.Schema{
109+
Type: schema.TypeString,
110+
},
111+
},
112+
105113
"tags": tags.SchemaDataSource(),
106114
},
107115
}
@@ -132,11 +140,14 @@ func dataSourceArmSpringCloudServiceRead(d *schema.ResourceData, meta interface{
132140
d.Set("location", azure.NormalizeLocation(*location))
133141
}
134142

135-
if resp.Properties != nil && resp.Properties.ConfigServerProperties != nil && resp.Properties.ConfigServerProperties.ConfigServer != nil {
136-
if props := resp.Properties.ConfigServerProperties.ConfigServer.GitProperty; props != nil {
137-
if err := d.Set("config_server_git_setting", flattenArmSpringCloudConfigServerGitProperty(props, d)); err != nil {
138-
return fmt.Errorf("failure setting AzureRM Spring Cloud Service Config Server error: %+v", err)
139-
}
143+
if props := resp.Properties; props != nil {
144+
if err := d.Set("config_server_git_setting", flattenArmSpringCloudConfigServerGitProperty(props.ConfigServerProperties, d)); err != nil {
145+
return fmt.Errorf("setting `config_server_git_setting`: %+v", err)
146+
}
147+
148+
outboundPublicIPAddresses := flattenOutboundPublicIPAddresses(props.NetworkProfile)
149+
if err := d.Set("outbound_public_ip_addresses", outboundPublicIPAddresses); err != nil {
150+
return fmt.Errorf("setting `outbound_public_ip_addresses`: %+v", err)
140151
}
141152
}
142153

azurerm/internal/services/appplatform/spring_cloud_service_resource.go

+45-22
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,14 @@ func resourceArmSpringCloudService() *schema.Resource {
208208
},
209209
},
210210

211+
"outbound_public_ip_addresses": {
212+
Type: schema.TypeList,
213+
Computed: true,
214+
Elem: &schema.Schema{
215+
Type: schema.TypeString,
216+
},
217+
},
218+
211219
"tags": tags.Schema(),
212220
},
213221
}
@@ -372,19 +380,20 @@ func resourceArmSpringCloudServiceRead(d *schema.ResourceData, meta interface{})
372380
if resp.Sku != nil {
373381
d.Set("sku_name", resp.Sku.Name)
374382
}
375-
if resp.Properties != nil {
376-
if err := d.Set("trace", flattenArmSpringCloudTrace(resp.Properties.Trace)); err != nil {
383+
if props := resp.Properties; props != nil {
384+
if err := d.Set("trace", flattenArmSpringCloudTrace(props.Trace)); err != nil {
377385
return fmt.Errorf("failure setting `trace`: %+v", err)
378386
}
379-
if err := d.Set("network", flattenArmSpringCloudNetwork(resp.Properties.NetworkProfile)); err != nil {
387+
if err := d.Set("network", flattenArmSpringCloudNetwork(props.NetworkProfile)); err != nil {
380388
return fmt.Errorf("setting `network`: %+v", err)
381389
}
382-
if resp.Properties.ConfigServerProperties != nil && resp.Properties.ConfigServerProperties.ConfigServer != nil {
383-
if props := resp.Properties.ConfigServerProperties.ConfigServer.GitProperty; props != nil {
384-
if err := d.Set("config_server_git_setting", flattenArmSpringCloudConfigServerGitProperty(props, d)); err != nil {
385-
return fmt.Errorf("failure setting AzureRM Spring Cloud Service error: %+v", err)
386-
}
387-
}
390+
391+
outboundPublicIPAddresses := flattenOutboundPublicIPAddresses(props.NetworkProfile)
392+
if err := d.Set("outbound_public_ip_addresses", outboundPublicIPAddresses); err != nil {
393+
return fmt.Errorf("setting `outbound_public_ip_addresses`: %+v", err)
394+
}
395+
if err := d.Set("config_server_git_setting", flattenArmSpringCloudConfigServerGitProperty(props.ConfigServerProperties, d)); err != nil {
396+
return fmt.Errorf("setting `config_server_git_setting`: %+v", err)
388397
}
389398
}
390399

@@ -551,31 +560,33 @@ func expandArmSpringCloudTrace(input []interface{}) *appplatform.TraceProperties
551560
}
552561
}
553562

554-
func flattenArmSpringCloudConfigServerGitProperty(input *appplatform.ConfigServerGitProperty, d *schema.ResourceData) []interface{} {
555-
if input == nil {
563+
func flattenArmSpringCloudConfigServerGitProperty(input *appplatform.ConfigServerProperties, d *schema.ResourceData) []interface{} {
564+
if input == nil || input.ConfigServer == nil || input.ConfigServer.GitProperty == nil {
556565
return []interface{}{}
557566
}
558567

568+
gitProperty := input.ConfigServer.GitProperty
569+
559570
// prepare old state to find sensitive props not returned by API.
560571
oldGitSetting := make(map[string]interface{})
561572
if oldGitSettings := d.Get("config_server_git_setting").([]interface{}); len(oldGitSettings) > 0 {
562573
oldGitSetting = oldGitSettings[0].(map[string]interface{})
563574
}
564575

565576
uri := ""
566-
if input.URI != nil {
567-
uri = *input.URI
577+
if gitProperty.URI != nil {
578+
uri = *gitProperty.URI
568579
}
569580

570581
label := ""
571-
if input.Label != nil {
572-
label = *input.Label
582+
if gitProperty.Label != nil {
583+
label = *gitProperty.Label
573584
}
574585

575-
searchPaths := utils.FlattenStringSlice(input.SearchPaths)
586+
searchPaths := utils.FlattenStringSlice(gitProperty.SearchPaths)
576587

577-
httpBasicAuth := []interface{}{}
578-
if input.Username != nil && input.Password != nil {
588+
httpBasicAuth := make([]interface{}, 0)
589+
if gitProperty.Username != nil && gitProperty.Password != nil {
579590
// username and password returned by API are *
580591
// to avoid state diff, we get the props from old state
581592
username := ""
@@ -598,7 +609,7 @@ func flattenArmSpringCloudConfigServerGitProperty(input *appplatform.ConfigServe
598609
}
599610

600611
sshAuth := []interface{}{}
601-
if input.PrivateKey != nil {
612+
if gitProperty.PrivateKey != nil {
602613
// private_key, host_key and host_key_algorithm returned by API are *
603614
// to avoid state diff, we get the props from old state
604615
privateKey := ""
@@ -615,8 +626,8 @@ func flattenArmSpringCloudConfigServerGitProperty(input *appplatform.ConfigServe
615626
}
616627

617628
strictHostKeyChecking := false
618-
if input.StrictHostKeyChecking != nil {
619-
strictHostKeyChecking = *input.StrictHostKeyChecking
629+
if gitProperty.StrictHostKeyChecking != nil {
630+
strictHostKeyChecking = *gitProperty.StrictHostKeyChecking
620631
}
621632

622633
sshAuth = []interface{}{
@@ -636,7 +647,7 @@ func flattenArmSpringCloudConfigServerGitProperty(input *appplatform.ConfigServe
636647
"search_paths": searchPaths,
637648
"http_basic_auth": httpBasicAuth,
638649
"ssh_auth": sshAuth,
639-
"repository": flattenArmSpringCloudGitPatternRepository(input.Repositories, d),
650+
"repository": flattenArmSpringCloudGitPatternRepository(gitProperty.Repositories, d),
640651
},
641652
}
642653
}
@@ -797,6 +808,10 @@ func flattenArmSpringCloudNetwork(input *appplatform.NetworkProfile) []interface
797808
appNetworkResourceGroup = *input.AppNetworkResourceGroup
798809
}
799810

811+
if serviceRuntimeSubnetID == "" && appSubnetID == "" && serviceRuntimeNetworkResourceGroup == "" && appNetworkResourceGroup == "" && len(cidrRanges) == 0 {
812+
return []interface{}{}
813+
}
814+
800815
return []interface{}{
801816
map[string]interface{}{
802817
"app_subnet_id": appSubnetID,
@@ -807,3 +822,11 @@ func flattenArmSpringCloudNetwork(input *appplatform.NetworkProfile) []interface
807822
},
808823
}
809824
}
825+
826+
func flattenOutboundPublicIPAddresses(input *appplatform.NetworkProfile) []interface{} {
827+
if input == nil || input.OutboundIPs == nil {
828+
return []interface{}{}
829+
}
830+
831+
return utils.FlattenStringSlice(input.OutboundIPs.PublicIPs)
832+
}

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

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ func TestAccDataSourceAzureRMSpringCloudService_basic(t *testing.T) {
1919
Config: testAccDataSourceSpringCloudService_basic(data),
2020
Check: resource.ComposeTestCheckFunc(
2121
resource.TestCheckResourceAttrSet(data.ResourceName, "id"),
22+
resource.TestCheckResourceAttrSet(data.ResourceName, "outbound_public_ip_addresses.0"),
2223
),
2324
},
2425
},

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

+1
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ func TestAccAzureRMSpringCloudService_virtualNetwork(t *testing.T) {
112112
testCheckAzureRMSpringCloudServiceExists(data.ResourceName),
113113
resource.TestCheckResourceAttrSet(data.ResourceName, "network.0.service_runtime_network_resource_group"),
114114
resource.TestCheckResourceAttrSet(data.ResourceName, "network.0.app_network_resource_group"),
115+
resource.TestCheckResourceAttrSet(data.ResourceName, "outbound_public_ip_addresses.0"),
115116
),
116117
},
117118
data.ImportStep(

website/docs/d/spring_cloud_service.html.markdown

+3-1
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,11 @@ The following attributes are exported:
4141

4242
* `id` - The ID of Spring Cloud Service.
4343

44+
* `config_server_git_setting` - A `config_server_git_setting` block as defined below.
45+
4446
* `location` - The location of Spring Cloud Service.
4547

46-
* `config_server_git_setting` - A `config_server_git_setting` block as defined below.
48+
* `outbound_public_ip_addresses` - A list of the outbound Public IP Addresses used by this Spring Cloud Service.
4749

4850
* `tags` - A mapping of tags assigned to Spring Cloud Service.
4951

website/docs/r/spring_cloud_service.html.markdown

+2
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ The following attributes are exported:
153153

154154
* `id` - The ID of the Spring Cloud Service.
155155

156+
* `outbound_public_ip_addresses` - A list of the outbound Public IP Addresses used by this Spring Cloud Service.
157+
156158
## Timeouts
157159

158160
The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/docs/configuration/resources.html#timeouts) for certain actions:

0 commit comments

Comments
 (0)