-
Notifications
You must be signed in to change notification settings - Fork 66
/
schema_azure_oidc_account.go
136 lines (109 loc) · 4.92 KB
/
schema_azure_oidc_account.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
131
132
133
134
135
136
package octopusdeploy
import (
"context"
"fmt"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/accounts"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/core"
uuid "github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func expandAzureOpenIDConnectAccount(d *schema.ResourceData) *accounts.AzureOIDCAccount {
name := d.Get("name").(string)
applicationID, _ := uuid.Parse(d.Get("application_id").(string))
tenantID, _ := uuid.Parse(d.Get("tenant_id").(string))
subscriptionID, _ := uuid.Parse(d.Get("subscription_id").(string))
account, _ := accounts.NewAzureOIDCAccount(name, subscriptionID, tenantID, applicationID)
account.ID = d.Id()
if v, ok := d.GetOk("authentication_endpoint"); ok {
account.AuthenticationEndpoint = v.(string)
}
if v, ok := d.GetOk("description"); ok {
account.SetDescription(v.(string))
}
if v, ok := d.GetOk("environments"); ok {
account.EnvironmentIDs = getSliceFromTerraformTypeList(v)
}
if v, ok := d.GetOk("name"); ok {
account.SetName(v.(string))
}
if v, ok := d.GetOk("resource_manager_endpoint"); ok {
account.ResourceManagerEndpoint = v.(string)
}
if v, ok := d.GetOk("space_id"); ok {
account.SetSpaceID(v.(string))
}
if v, ok := d.GetOk("tenanted_deployment_participation"); ok {
account.TenantedDeploymentMode = core.TenantedDeploymentMode(v.(string))
}
if v, ok := d.GetOk("tenant_tags"); ok {
account.TenantTags = getSliceFromTerraformTypeList(v)
}
if v, ok := d.GetOk("tenants"); ok {
account.TenantIDs = getSliceFromTerraformTypeList(v)
}
if v, ok := d.GetOk("execution_subject_keys"); ok {
account.DeploymentSubjectKeys = getSliceFromTerraformTypeList(v)
}
if v, ok := d.GetOk("health_subject_keys"); ok {
account.HealthCheckSubjectKeys = getSliceFromTerraformTypeList(v)
}
if v, ok := d.GetOk("account_test_subject_keys"); ok {
account.AccountTestSubjectKeys = getSliceFromTerraformTypeList(v)
}
return account
}
func getAzureOpenIdConnectAccountSchema() map[string]*schema.Schema {
return map[string]*schema.Schema{
"application_id": getApplicationIDSchema(true),
"authentication_endpoint": getAuthenticationEndpointSchema(false),
"azure_environment": getAzureEnvironmentSchema(),
"description": getDescriptionSchema("Azure OpenID Connect account"),
"environments": getEnvironmentsSchema(),
"id": getIDSchema(),
"name": getNameSchema(true),
"resource_manager_endpoint": getResourceManagerEndpointSchema(false),
"space_id": getSpaceIDSchema(),
"subscription_id": getSubscriptionIDSchema(true),
"tenanted_deployment_participation": getTenantedDeploymentSchema(),
"tenants": getTenantsSchema(),
"tenant_id": getTenantIDSchema(true),
"tenant_tags": getTenantTagsSchema(),
"execution_subject_keys": getSubjectKeysSchema(SchemaSubjectKeysDescriptionExecution),
"health_subject_keys": getSubjectKeysSchema(SchemaSubjectKeysDescriptionHealth),
"account_test_subject_keys": getSubjectKeysSchema(SchemaSubjectKeysDescriptionAccountTest),
"audience": getOidcAudienceSchema(),
}
}
func setAzureOpenIDConnectAccount(ctx context.Context, d *schema.ResourceData, account *accounts.AzureOIDCAccount) error {
d.Set("application_id", account.ApplicationID.String())
d.Set("authentication_endpoint", account.AuthenticationEndpoint)
d.Set("azure_environment", account.AzureEnvironment)
d.Set("description", account.GetDescription())
d.Set("id", account.GetID())
d.Set("name", account.GetName())
d.Set("resource_manager_endpoint", account.ResourceManagerEndpoint)
d.Set("space_id", account.GetSpaceID())
d.Set("subscription_id", account.SubscriptionID.String())
d.Set("tenanted_deployment_participation", account.GetTenantedDeploymentMode())
d.Set("tenant_id", account.TenantID.String())
d.Set("audience", account.Audience)
if err := d.Set("environments", account.GetEnvironmentIDs()); err != nil {
return fmt.Errorf("error setting environments: %s", err)
}
if err := d.Set("tenants", account.GetTenantIDs()); err != nil {
return fmt.Errorf("error setting tenants: %s", err)
}
if err := d.Set("tenant_tags", account.TenantTags); err != nil {
return fmt.Errorf("error setting tenant_tags: %s", err)
}
if err := d.Set("execution_subject_keys", account.DeploymentSubjectKeys); err != nil {
return fmt.Errorf("error setting execution_subject_keys: %s", err)
}
if err := d.Set("health_subject_keys", account.HealthCheckSubjectKeys); err != nil {
return fmt.Errorf("error setting health_subject_keys: %s", err)
}
if err := d.Set("account_test_subject_keys", account.AccountTestSubjectKeys); err != nil {
return fmt.Errorf("error setting account_test_subject_keys: %s", err)
}
return nil
}