-
Notifications
You must be signed in to change notification settings - Fork 1
/
data_source_subscription.go
73 lines (59 loc) · 1.53 KB
/
data_source_subscription.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
71
72
73
package azurerm
import (
"fmt"
"github.com/hashicorp/terraform/helper/schema"
)
func dataSourceArmSubscription() *schema.Resource {
return &schema.Resource{
Read: dataSourceArmSubscriptionRead,
Schema: map[string]*schema.Schema{
"subscription_id": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"display_name": {
Type: schema.TypeString,
Computed: true,
},
"state": {
Type: schema.TypeString,
Computed: true,
},
"location_placement_id": {
Type: schema.TypeString,
Computed: true,
},
"quota_id": {
Type: schema.TypeString,
Computed: true,
},
"spending_limit": {
Type: schema.TypeString,
Computed: true,
},
},
}
}
func dataSourceArmSubscriptionRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient)
groupClient := client.subscriptionsGroupClient
subscriptionId := d.Get("subscription_id").(string)
if subscriptionId == "" {
subscriptionId = client.subscriptionId
}
resp, err := groupClient.Get(subscriptionId)
if err != nil {
return fmt.Errorf("Error reading subscription: %+v", err)
}
d.SetId(*resp.ID)
d.Set("subscription_id", resp.SubscriptionID)
d.Set("display_name", resp.DisplayName)
d.Set("state", resp.State)
if resp.SubscriptionPolicies != nil {
d.Set("location_placement_id", resp.SubscriptionPolicies.LocationPlacementID)
d.Set("quota_id", resp.SubscriptionPolicies.QuotaID)
d.Set("spending_limit", resp.SubscriptionPolicies.SpendingLimit)
}
return nil
}