-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathdata_source_transip_openstack_project.go
69 lines (59 loc) · 1.63 KB
/
data_source_transip_openstack_project.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
package main
import (
"fmt"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/transip/gotransip/v6/openstack"
"github.com/transip/gotransip/v6/repository"
)
func dataSourceOpenstackProject() *schema.Resource {
return &schema.Resource{
Read: dataSourceOpenstackProjectRead,
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Description: "Project name",
Required: true,
},
"description": {
Type: schema.TypeString,
Description: "Describes this project",
Optional: true,
},
"locked": {
Type: schema.TypeBool,
Description: "Set to true when an ongoing process blocks the project from being modified",
Optional: true,
},
"blocked": {
Type: schema.TypeBool,
Description: "Set to true when a project has been administratively blocked",
Optional: true,
},
},
}
}
func dataSourceOpenstackProjectRead(d *schema.ResourceData, m interface{}) error {
name := d.Get("name").(string)
client := m.(repository.Client)
repository := openstack.ProjectRepository{Client: client}
projects, err := repository.GetAll()
if err != nil {
return fmt.Errorf("failed to get openstack projects %q: %s", name, err)
}
// get ID of openstack project
for _, project := range projects {
if project.Name == name {
d.SetId(project.ID)
break
}
}
i, err := repository.GetByID(d.Id())
if err != nil {
return fmt.Errorf("failed to lookup openstack project %q: %s", name, err)
}
d.Set("name", i.Name)
d.Set("description", i.Description)
d.Set("locked", i.IsLocked)
d.Set("blocked", i.IsBlocked)
return nil
}