forked from hashicorp/terraform-provider-azurerm
/
logic_app_integration_account_data_source.go
70 lines (56 loc) · 2.26 KB
/
logic_app_integration_account_data_source.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package logic
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/location"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)
func dataSourceLogicAppIntegrationAccount() *schema.Resource {
return &schema.Resource{
Read: dataSourceArmLogicAppIntegrationAccountRead,
Timeouts: &schema.ResourceTimeout{
Read: schema.DefaultTimeout(5 * time.Minute),
},
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
},
"resource_group_name": azure.SchemaResourceGroupNameForDataSource(),
"location": azure.SchemaLocationForDataSource(),
"sku_name": {
Type: schema.TypeString,
Computed: true,
},
"tags": tags.SchemaDataSource(),
},
}
}
func dataSourceArmLogicAppIntegrationAccountRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*clients.Client).Logic.IntegrationAccountClient
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d)
defer cancel()
name := d.Get("name").(string)
resourceGroup := d.Get("resource_group_name").(string)
resp, err := client.Get(ctx, resourceGroup, name)
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
return fmt.Errorf("Logic App Integration Account Account %q does not exist in Resource Group %q", name, resourceGroup)
}
return fmt.Errorf("retrieving Logic App Integration Account Account %q (Resource Group %q): %+v", name, resourceGroup, err)
}
if resp.ID == nil || *resp.ID == "" {
return fmt.Errorf("reading Logic App Integration Account Account %q (Resource Group %q): ID is empty or nil", name, resourceGroup)
}
d.SetId(*resp.ID)
d.Set("name", name)
d.Set("resource_group_name", resourceGroup)
d.Set("location", location.NormalizeNilable(resp.Location))
d.Set("sku_name", string(resp.Sku.Name))
return tags.FlattenAndSet(d, resp.Tags)
}