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

new data source "azurerm_spring_cloud_app" #10678

Merged
merged 3 commits into from
Feb 22, 2021
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
1 change: 1 addition & 0 deletions azurerm/internal/services/springcloud/registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func (r Registration) WebsiteCategories() []string {
// SupportedDataSources returns the supported Data Sources supported by this Service
func (r Registration) SupportedDataSources() map[string]*schema.Resource {
return map[string]*schema.Resource{
"azurerm_spring_cloud_app": dataSourceSpringCloudApp(),
"azurerm_spring_cloud_service": dataSourceSpringCloudService(),
}
}
Expand Down
140 changes: 140 additions & 0 deletions azurerm/internal/services/springcloud/spring_cloud_app_data_source.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
package springcloud

import (
"fmt"
"time"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/springcloud/parse"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/springcloud/validate"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)

func dataSourceSpringCloudApp() *schema.Resource {
return &schema.Resource{
Read: dataSourceSpringCloudAppRead,

Timeouts: &schema.ResourceTimeout{
Read: schema.DefaultTimeout(5 * time.Minute),
},

Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validate.SpringCloudAppName,
},

"resource_group_name": azure.SchemaResourceGroupNameForDataSource(),

"service_name": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validate.SpringCloudServiceName,
},

"fqdn": {
Type: schema.TypeString,
Computed: true,
},

"https_only": {
Type: schema.TypeBool,
Computed: true,
},

"identity": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"type": {
Type: schema.TypeString,
Computed: true,
},

"principal_id": {
Type: schema.TypeString,
Computed: true,
},

"tenant_id": {
Type: schema.TypeString,
Computed: true,
},
},
},
},

"is_public": {
Type: schema.TypeBool,
Computed: true,
},

"persistent_disk": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"mount_path": {
Type: schema.TypeString,
Computed: true,
},

"size_in_gb": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},

"url": {
Type: schema.TypeString,
Computed: true,
},
},
}
}

func dataSourceSpringCloudAppRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*clients.Client).AppPlatform.AppsClient
subscriptionId := meta.(*clients.Client).Account.SubscriptionId
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d)
defer cancel()

id := parse.NewSpringCloudAppID(subscriptionId, d.Get("resource_group_name").(string), d.Get("service_name").(string), d.Get("name").(string))

resp, err := client.Get(ctx, id.ResourceGroup, id.SpringName, id.AppName, "")
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
return fmt.Errorf("%s was not found", id)
}
return fmt.Errorf("retrieving %s: %+v", id, err)
}

d.SetId(id.ID())

d.Set("name", id.AppName)
d.Set("service_name", id.SpringName)
d.Set("resource_group_name", id.ResourceGroup)
if err := d.Set("identity", flattenSpringCloudAppIdentity(resp.Identity)); err != nil {
return fmt.Errorf("setting `identity`: %s", err)
}

if prop := resp.Properties; prop != nil {
d.Set("fqdn", prop.Fqdn)
d.Set("https_only", prop.HTTPSOnly)
d.Set("is_public", prop.Public)
d.Set("url", prop.URL)

if err := d.Set("persistent_disk", flattenSpringCloudAppPersistentDisk(prop.PersistentDisk)); err != nil {
return fmt.Errorf("setting `persistent_disk`: %s", err)
}
}

return nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package springcloud_test

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance/check"
)

type SpringCloudAppDataSource struct {
}

func TestAccDataSourceSpringCloudApp_basic(t *testing.T) {
data := acceptance.BuildTestData(t, "data.azurerm_spring_cloud_app", "test")
r := SpringCloudAppDataSource{}

data.DataSourceTest(t, []resource.TestStep{
{
Config: r.basic(data),
Check: resource.ComposeTestCheckFunc(
check.That(data.ResourceName).Key("id").Exists(),
),
},
})
}

func (SpringCloudAppDataSource) basic(data acceptance.TestData) string {
return fmt.Sprintf(`
%s

data "azurerm_spring_cloud_app" "test" {
name = azurerm_spring_cloud_app.test.name
resource_group_name = azurerm_spring_cloud_app.test.resource_group_name
service_name = azurerm_spring_cloud_app.test.service_name
}
`, SpringCloudAppResource{}.basic(data))
}
4 changes: 4 additions & 0 deletions website/azurerm.erb
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,10 @@
<a href="/docs/providers/azurerm/d/snapshot.html">azurerm_snapshot</a>
</li>

<li>
<a href="/docs/providers/azurerm/d/spring_cloud_app.html">azurerm_spring_cloud_app</a>
</li>

<li>
<a href="/docs/providers/azurerm/d/spring_cloud_service.html">azurerm_spring_cloud_service</a>
</li>
Expand Down
77 changes: 77 additions & 0 deletions website/docs/d/spring_cloud_app.html.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
---
subcategory: "Spring Cloud"
layout: "azurerm"
page_title: "Azure Resource Manager: azurerm_spring_cloud_app"
description: |-
Gets information about an existing Spring Cloud Application
---

# Data Source: azurerm_spring_cloud_app

Use this data source to access information about an existing Spring Cloud Application.

## Example Usage

```hcl
data "azurerm_spring_cloud_app" "example" {
name = azurerm_spring_cloud_app.example.name
resource_group_name = azurerm_spring_cloud_app.example.resource_group_name
service_name = azurerm_spring_cloud_app.example.service_name
}

output "spring_cloud_app_id" {
value = data.azurerm_spring_cloud_app.example.id
}
```

## Argument Reference

The following arguments are supported:

* `name` - (Required) The name of the Spring Cloud Application.

* `resource_group_name` - (Required) The name of the Resource Group where the Spring Cloud Application exists.

* `service_name` - (Required) The name of the Spring Cloud Service.

## Attributes Reference

The following attributes are exported:

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

* `fqdn` - The Fully Qualified DNS Name.

* `https_only` - Is only https allowed?

* `identity` - An `identity` block as defined below.

* `is_public` - Does the Spring Cloud Application have public endpoint?

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

* `url` - The public endpoint of the Spring Cloud Application.

---

The `identity` block exports the following:

* `principal_id` - The Principal ID for the Service Principal associated with the Managed Service Identity of this Spring Cloud Application.

* `tenant_id` - The Tenant ID for the Service Principal associated with the Managed Service Identity of this Spring Cloud Application.

* `type` - The Type of Managed Identity assigned to the Spring Cloud Application.

---

The `persistent_disk` block exports the following:

* `mount_path` - The mount path of the persistent disk.

* `size_in_gb` - The size of the persistent disk in GB.

## Timeouts

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

* `read` - (Defaults to 5 minutes) Used when retrieving the Spring Cloud Application.