Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"azurerm_spring_cloud_service" - exporting outbound_public_ip_addresses #9261

Merged
merged 8 commits into from
Nov 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .teamcity/components/settings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ var runNightly = mapOf(

// specifies a list of services which should be run with a custom test configuration
var serviceTestConfigurationOverrides = mapOf(
// Spring Cloud only allows a max of 10 provisioned
"appplatform" to testConfiguration(5, defaultStartHour),

// The AKS API has a low rate limit
"containers" to testConfiguration(5, defaultStartHour),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,14 @@ func dataSourceArmSpringCloudService() *schema.Resource {
},
},

"outbound_public_ip_addresses": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},

"tags": tags.SchemaDataSource(),
},
}
Expand Down Expand Up @@ -132,11 +140,14 @@ func dataSourceArmSpringCloudServiceRead(d *schema.ResourceData, meta interface{
d.Set("location", azure.NormalizeLocation(*location))
}

if resp.Properties != nil && resp.Properties.ConfigServerProperties != nil && resp.Properties.ConfigServerProperties.ConfigServer != nil {
if props := resp.Properties.ConfigServerProperties.ConfigServer.GitProperty; props != nil {
if err := d.Set("config_server_git_setting", flattenArmSpringCloudConfigServerGitProperty(props, d)); err != nil {
return fmt.Errorf("failure setting AzureRM Spring Cloud Service Config Server error: %+v", err)
}
if props := resp.Properties; props != nil {
if err := d.Set("config_server_git_setting", flattenArmSpringCloudConfigServerGitProperty(props.ConfigServerProperties, d)); err != nil {
return fmt.Errorf("setting `config_server_git_setting`: %+v", err)
}

outboundPublicIPAddresses := flattenOutboundPublicIPAddresses(props.NetworkProfile)
if err := d.Set("outbound_public_ip_addresses", outboundPublicIPAddresses); err != nil {
return fmt.Errorf("setting `outbound_public_ip_addresses`: %+v", err)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,14 @@ func resourceArmSpringCloudService() *schema.Resource {
},
},

"outbound_public_ip_addresses": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},

"tags": tags.Schema(),
},
}
Expand Down Expand Up @@ -372,19 +380,20 @@ func resourceArmSpringCloudServiceRead(d *schema.ResourceData, meta interface{})
if resp.Sku != nil {
d.Set("sku_name", resp.Sku.Name)
}
if resp.Properties != nil {
if err := d.Set("trace", flattenArmSpringCloudTrace(resp.Properties.Trace)); err != nil {
if props := resp.Properties; props != nil {
if err := d.Set("trace", flattenArmSpringCloudTrace(props.Trace)); err != nil {
return fmt.Errorf("failure setting `trace`: %+v", err)
}
if err := d.Set("network", flattenArmSpringCloudNetwork(resp.Properties.NetworkProfile)); err != nil {
if err := d.Set("network", flattenArmSpringCloudNetwork(props.NetworkProfile)); err != nil {
return fmt.Errorf("setting `network`: %+v", err)
}
if resp.Properties.ConfigServerProperties != nil && resp.Properties.ConfigServerProperties.ConfigServer != nil {
if props := resp.Properties.ConfigServerProperties.ConfigServer.GitProperty; props != nil {
if err := d.Set("config_server_git_setting", flattenArmSpringCloudConfigServerGitProperty(props, d)); err != nil {
return fmt.Errorf("failure setting AzureRM Spring Cloud Service error: %+v", err)
}
}

outboundPublicIPAddresses := flattenOutboundPublicIPAddresses(props.NetworkProfile)
if err := d.Set("outbound_public_ip_addresses", outboundPublicIPAddresses); err != nil {
return fmt.Errorf("setting `outbound_public_ip_addresses`: %+v", err)
}
if err := d.Set("config_server_git_setting", flattenArmSpringCloudConfigServerGitProperty(props.ConfigServerProperties, d)); err != nil {
return fmt.Errorf("setting `config_server_git_setting`: %+v", err)
}
}

Expand Down Expand Up @@ -551,31 +560,33 @@ func expandArmSpringCloudTrace(input []interface{}) *appplatform.TraceProperties
}
}

func flattenArmSpringCloudConfigServerGitProperty(input *appplatform.ConfigServerGitProperty, d *schema.ResourceData) []interface{} {
if input == nil {
func flattenArmSpringCloudConfigServerGitProperty(input *appplatform.ConfigServerProperties, d *schema.ResourceData) []interface{} {
if input == nil || input.ConfigServer == nil || input.ConfigServer.GitProperty == nil {
return []interface{}{}
}

gitProperty := input.ConfigServer.GitProperty

// prepare old state to find sensitive props not returned by API.
oldGitSetting := make(map[string]interface{})
if oldGitSettings := d.Get("config_server_git_setting").([]interface{}); len(oldGitSettings) > 0 {
oldGitSetting = oldGitSettings[0].(map[string]interface{})
}

uri := ""
if input.URI != nil {
uri = *input.URI
if gitProperty.URI != nil {
uri = *gitProperty.URI
}

label := ""
if input.Label != nil {
label = *input.Label
if gitProperty.Label != nil {
label = *gitProperty.Label
}

searchPaths := utils.FlattenStringSlice(input.SearchPaths)
searchPaths := utils.FlattenStringSlice(gitProperty.SearchPaths)

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

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

strictHostKeyChecking := false
if input.StrictHostKeyChecking != nil {
strictHostKeyChecking = *input.StrictHostKeyChecking
if gitProperty.StrictHostKeyChecking != nil {
strictHostKeyChecking = *gitProperty.StrictHostKeyChecking
}

sshAuth = []interface{}{
Expand All @@ -636,7 +647,7 @@ func flattenArmSpringCloudConfigServerGitProperty(input *appplatform.ConfigServe
"search_paths": searchPaths,
"http_basic_auth": httpBasicAuth,
"ssh_auth": sshAuth,
"repository": flattenArmSpringCloudGitPatternRepository(input.Repositories, d),
"repository": flattenArmSpringCloudGitPatternRepository(gitProperty.Repositories, d),
},
}
}
Expand Down Expand Up @@ -797,6 +808,10 @@ func flattenArmSpringCloudNetwork(input *appplatform.NetworkProfile) []interface
appNetworkResourceGroup = *input.AppNetworkResourceGroup
}

if serviceRuntimeSubnetID == "" && appSubnetID == "" && serviceRuntimeNetworkResourceGroup == "" && appNetworkResourceGroup == "" && len(cidrRanges) == 0 {
return []interface{}{}
}

return []interface{}{
map[string]interface{}{
"app_subnet_id": appSubnetID,
Expand All @@ -807,3 +822,11 @@ func flattenArmSpringCloudNetwork(input *appplatform.NetworkProfile) []interface
},
}
}

func flattenOutboundPublicIPAddresses(input *appplatform.NetworkProfile) []interface{} {
if input == nil || input.OutboundIPs == nil {
return []interface{}{}
}

return utils.FlattenStringSlice(input.OutboundIPs.PublicIPs)
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func TestAccDataSourceAzureRMSpringCloudService_basic(t *testing.T) {
Config: testAccDataSourceSpringCloudService_basic(data),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(data.ResourceName, "id"),
resource.TestCheckResourceAttrSet(data.ResourceName, "outbound_public_ip_addresses.0"),
),
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ func TestAccAzureRMSpringCloudService_virtualNetwork(t *testing.T) {
testCheckAzureRMSpringCloudServiceExists(data.ResourceName),
resource.TestCheckResourceAttrSet(data.ResourceName, "network.0.service_runtime_network_resource_group"),
resource.TestCheckResourceAttrSet(data.ResourceName, "network.0.app_network_resource_group"),
resource.TestCheckResourceAttrSet(data.ResourceName, "outbound_public_ip_addresses.0"),
),
},
data.ImportStep(
Expand Down
4 changes: 3 additions & 1 deletion website/docs/d/spring_cloud_service.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ The following attributes are exported:

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

* `config_server_git_setting` - A `config_server_git_setting` block as defined below.

* `location` - The location of Spring Cloud Service.

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

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

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 @@ -153,6 +153,8 @@ The following attributes are exported:

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

* `outbound_public_ip_addresses` - A list of the outbound Public IP Addresses used by this Spring Cloud Service.

## Timeouts

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