Skip to content

Commit 5015e80

Browse files
committed
create user resource
1 parent bce3a32 commit 5015e80

2 files changed

Lines changed: 111 additions & 0 deletions

File tree

cloudstack/provider.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ func Provider() terraform.ResourceProvider {
119119
"cloudstack_zone": resourceCloudStackZone(),
120120
"cloudstack_service_offering": resourceCloudStackServiceOffering(),
121121
"cloudstack_account": resourceCloudStackAccount(),
122+
"cloudstack_user": resourceCloudStackUser(),
122123
},
123124

124125
ConfigureFunc: providerConfigure,
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
//
2+
// Licensed to the Apache Software Foundation (ASF) under one
3+
// or more contributor license agreements. See the NOTICE file
4+
// distributed with this work for additional information
5+
// regarding copyright ownership. The ASF licenses this file
6+
// to you under the Apache License, Version 2.0 (the
7+
// "License"); you may not use this file except in compliance
8+
// with the License. You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing,
13+
// software distributed under the License is distributed on an
14+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
// KIND, either express or implied. See the License for the
16+
// specific language governing permissions and limitations
17+
// under the License.
18+
//
19+
20+
package cloudstack
21+
22+
import (
23+
"fmt"
24+
"log"
25+
26+
"github.com/apache/cloudstack-go/v2/cloudstack"
27+
"github.com/hashicorp/terraform/helper/schema"
28+
)
29+
30+
func resourceCloudStackUser() *schema.Resource {
31+
return &schema.Resource{
32+
Create: resourceCloudStackUserCreate,
33+
Read: resourceCloudStackUserRead,
34+
Update: resourceCloudStackUserUpdate,
35+
Delete: resourceCloudStackUserDelete,
36+
Schema: map[string]*schema.Schema{
37+
"account": {
38+
Type: schema.TypeString,
39+
Optional: true,
40+
},
41+
"email": {
42+
Type: schema.TypeString,
43+
Required: true,
44+
},
45+
"first_name": {
46+
Type: schema.TypeString,
47+
Required: true,
48+
},
49+
"last_name": {
50+
Type: schema.TypeString,
51+
Required: true,
52+
},
53+
"password": {
54+
Type: schema.TypeString,
55+
Required: true,
56+
},
57+
"username": {
58+
Type: schema.TypeString,
59+
Required: true,
60+
},
61+
},
62+
}
63+
}
64+
65+
func resourceCloudStackUserCreate(d *schema.ResourceData, meta interface{}) error {
66+
cs := meta.(*cloudstack.CloudStackClient)
67+
account := d.Get("account").(string)
68+
email := d.Get("email").(string)
69+
first_name := d.Get("first_name").(string)
70+
last_name := d.Get("last_name").(string)
71+
password := d.Get("password").(string)
72+
username := d.Get("username").(string)
73+
74+
// Create a new parameter struct
75+
p := cs.User.NewCreateUserParams(account, email, first_name, last_name, password, username)
76+
77+
log.Printf("[DEBUG] Creating User %s", username)
78+
u, err := cs.User.CreateUser(p)
79+
80+
if err != nil {
81+
return err
82+
}
83+
84+
log.Printf("[DEBUG] User %s successfully created", username)
85+
d.SetId(u.Id)
86+
87+
return resourceCloudStackUserRead(d, meta)
88+
}
89+
90+
func resourceCloudStackUserUpdate(d *schema.ResourceData, meta interface{}) error {
91+
return resourceCloudStackInstanceRead(d, meta)
92+
}
93+
94+
func resourceCloudStackUserDelete(d *schema.ResourceData, meta interface{}) error {
95+
cs := meta.(*cloudstack.CloudStackClient)
96+
97+
// Create a new parameter struct
98+
p := cs.User.NewDeleteUserParams(d.Id())
99+
_, err := cs.User.DeleteUser(p)
100+
101+
if err != nil {
102+
return fmt.Errorf("Error deleting User: %s", err)
103+
}
104+
105+
return nil
106+
}
107+
108+
func resourceCloudStackUserRead(d *schema.ResourceData, meta interface{}) error {
109+
return nil
110+
}

0 commit comments

Comments
 (0)