This repository has been archived by the owner on Aug 5, 2020. It is now read-only.
forked from okta/terraform-provider-okta
/
data_source_okta_auth_server.go
72 lines (66 loc) · 1.93 KB
/
data_source_okta_auth_server.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
package okta
import (
"fmt"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/okta/okta-sdk-golang/okta/query"
)
func dataSourceAuthServer() *schema.Resource {
return &schema.Resource{
Read: dataSourceAuthServerRead,
Schema: map[string]*schema.Schema{
"name": &schema.Schema{
Type: schema.TypeString,
Required: true,
},
"description": &schema.Schema{
Type: schema.TypeString,
Computed: true,
},
"audiences": &schema.Schema{
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"kid": &schema.Schema{
Type: schema.TypeString,
Computed: true,
},
"credentials_last_rotated": &schema.Schema{
Type: schema.TypeString,
Computed: true,
},
"credentials_next_rotation": &schema.Schema{
Type: schema.TypeString,
Computed: true,
},
"credentials_rotation_mode": &schema.Schema{
Type: schema.TypeString,
Computed: true,
},
"status": &schema.Schema{
Type: schema.TypeString,
Computed: true,
},
},
}
}
func dataSourceAuthServerRead(d *schema.ResourceData, m interface{}) error {
name := d.Get("name").(string)
authServer, err := getSupplementFromMetadata(m).FindAuthServer(name, &query.Params{})
if err != nil {
return err
}
if authServer == nil {
return fmt.Errorf("No authorization server found with provided name %s", name)
}
d.SetId(authServer.Id)
d.Set("name", authServer.Name)
d.Set("description", authServer.Description)
d.Set("audiences", convertStringSetToInterface(authServer.Audiences))
d.Set("credentials_rotation_mode", authServer.Credentials.Signing.RotationMode)
d.Set("kid", authServer.Credentials.Signing.Kid)
d.Set("credentials_next_rotation", authServer.Credentials.Signing.NextRotation.String())
d.Set("credentials_last_rotated", authServer.Credentials.Signing.LastRotated.String())
d.Set("status", authServer.Status)
return nil
}