-
Notifications
You must be signed in to change notification settings - Fork 26
/
data_azure_integrations.go
130 lines (117 loc) · 3.9 KB
/
data_azure_integrations.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package spacelift
import (
"context"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/spacelift-io/terraform-provider-spacelift/spacelift/internal"
"github.com/spacelift-io/terraform-provider-spacelift/spacelift/internal/structs"
)
func dataAzureIntegrations() *schema.Resource {
return &schema.Resource{
Description: "`spacelift_azure_integrations` represents a list of all the Azure integrations in " +
"the Spacelift account visible to the API user.",
ReadContext: dataAzureIntegrationsRead,
Schema: map[string]*schema.Schema{
"integrations": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"integration_id": {
Type: schema.TypeString,
Description: "Immutable ID of the integration.",
Computed: true,
},
"admin_consent_provided": {
Type: schema.TypeBool,
Description: "" +
"Indicates whether admin consent has been performed for the " +
"AAD Application.",
Computed: true,
},
"admin_consent_url": {
Type: schema.TypeString,
Description: "" +
"The URL to use to provide admin consent to the application in " +
"the customer's tenant",
Computed: true,
},
"application_id": {
Type: schema.TypeString,
Description: "" +
"The applicationId of the Azure AD application used by the " +
"integration.",
Computed: true,
},
"default_subscription_id": {
Type: schema.TypeString,
Description: "" +
"The default subscription ID to use, if one isn't specified " +
"at the stack/module level",
Computed: true,
},
"display_name": {
Type: schema.TypeString,
Description: "" +
"The display name for the application in Azure. This is " +
"automatically generated when the integration is created, and " +
"cannot be changed without deleting and recreating the " +
"integration.",
Computed: true,
},
"labels": {
Type: schema.TypeSet,
Description: "Labels to set on the integration",
Elem: &schema.Schema{Type: schema.TypeString},
Computed: true,
},
"name": {
Type: schema.TypeString,
Description: "The friendly name of the integration.",
Computed: true,
},
"space_id": {
Type: schema.TypeString,
Description: "ID (slug) of the space the integration is in",
Computed: true,
},
"tenant_id": {
Type: schema.TypeString,
Description: "The Azure AD tenant ID",
Computed: true,
},
},
},
},
},
}
}
func dataAzureIntegrationsRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
var query struct {
AzureIntegrations []*structs.AzureIntegration `graphql:"azureIntegrations()"`
}
if err := meta.(*internal.Client).Query(ctx, "azureIntegrations", &query, map[string]interface{}{}); err != nil {
return diag.Errorf("could not query for azure integrations: %v", err)
}
d.SetId("spacelift_azure_integrations")
integrations := query.AzureIntegrations
if integrations == nil {
d.Set("integrations", nil)
return nil
}
mapped := flattenDataAzureIntegrationsList(integrations)
if err := d.Set("integrations", mapped); err != nil {
d.SetId("")
return diag.Errorf("could not set azure integrations: %v", err)
}
return nil
}
func flattenDataAzureIntegrationsList(integrations []*structs.AzureIntegration) []map[string]interface{} {
mapped := make([]map[string]interface{}, len(integrations))
for index, integration := range integrations {
integrationToMap := integration.ToMap()
integrationToMap["integration_id"] = integration.ID
mapped[index] = integrationToMap
}
return mapped
}