diff --git a/azurerm/internal/services/springcloud/registration.go b/azurerm/internal/services/springcloud/registration.go index e5a02f9c637d..38f1264eb922 100644 --- a/azurerm/internal/services/springcloud/registration.go +++ b/azurerm/internal/services/springcloud/registration.go @@ -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(), } } diff --git a/azurerm/internal/services/springcloud/spring_cloud_app_data_source.go b/azurerm/internal/services/springcloud/spring_cloud_app_data_source.go new file mode 100644 index 000000000000..8b0dfc59ea8a --- /dev/null +++ b/azurerm/internal/services/springcloud/spring_cloud_app_data_source.go @@ -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 +} diff --git a/azurerm/internal/services/springcloud/spring_cloud_app_data_source_test.go b/azurerm/internal/services/springcloud/spring_cloud_app_data_source_test.go new file mode 100644 index 000000000000..0ebc8fffa819 --- /dev/null +++ b/azurerm/internal/services/springcloud/spring_cloud_app_data_source_test.go @@ -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)) +} diff --git a/website/azurerm.erb b/website/azurerm.erb index 74934af68b35..df917fb61d09 100644 --- a/website/azurerm.erb +++ b/website/azurerm.erb @@ -618,6 +618,10 @@ azurerm_snapshot +
  • + azurerm_spring_cloud_app +
  • +
  • azurerm_spring_cloud_service
  • diff --git a/website/docs/d/spring_cloud_app.html.markdown b/website/docs/d/spring_cloud_app.html.markdown new file mode 100644 index 000000000000..aa228ed6cdd2 --- /dev/null +++ b/website/docs/d/spring_cloud_app.html.markdown @@ -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.