-
Notifications
You must be signed in to change notification settings - Fork 147
/
data_source_organization.go
90 lines (74 loc) · 2.12 KB
/
data_source_organization.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
package tfe
import (
"fmt"
"log"
tfe "github.com/hashicorp/go-tfe"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func dataSourceTFEOrganization() *schema.Resource {
return &schema.Resource{
Read: dataSourceTFEOrganizationRead,
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
},
"external_id": {
Type: schema.TypeString,
Computed: true,
},
"collaborator_auth_policy": {
Type: schema.TypeString,
Computed: true,
},
"cost_estimation_enabled": {
Type: schema.TypeBool,
Computed: true,
},
"email": {
Type: schema.TypeString,
Computed: true,
},
"owners_team_saml_role_id": {
Type: schema.TypeString,
Computed: true,
},
"two_factor_conformant": {
Type: schema.TypeBool,
Computed: true,
},
"send_passing_statuses_for_untriggered_speculative_plans": {
Type: schema.TypeBool,
Computed: true,
},
"assessments_enforced": {
Type: schema.TypeBool,
Computed: true,
},
},
}
}
func dataSourceTFEOrganizationRead(d *schema.ResourceData, meta interface{}) error {
tfeClient := meta.(*tfe.Client)
name := d.Get("name").(string)
log.Printf("[DEBUG] Read configuration for Organization: %s", name)
org, err := tfeClient.Organizations.Read(ctx, name)
if err != nil {
if err == tfe.ErrResourceNotFound {
return fmt.Errorf("Could not read organization '%s'", name)
}
return fmt.Errorf("Error retrieving organization: %w", err)
}
log.Printf("[DEBUG] Setting Organization Attributes")
d.SetId(org.ExternalID)
d.Set("name", org.Name)
d.Set("external_id", org.ExternalID)
d.Set("collaborator_auth_policy", org.CollaboratorAuthPolicy)
d.Set("cost_estimation_enabled", org.CostEstimationEnabled)
d.Set("email", org.Email)
d.Set("owners_team_saml_role_id", org.OwnersTeamSAMLRoleID)
d.Set("two_factor_conformant", org.TwoFactorConformant)
d.Set("send_passing_statuses_for_untriggered_speculative_plans", org.SendPassingStatusesForUntriggeredSpeculativePlans)
d.Set("assessments_enforced", org.AssessmentsEnforced)
return nil
}