-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
af1d316
commit d18731e
Showing
20 changed files
with
633 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "netdata_room Data Source - terraform-provider-netdata" | ||
subcategory: "" | ||
description: |- | ||
--- | ||
|
||
# netdata_room (Data Source) | ||
|
||
|
||
|
||
## Example Usage | ||
|
||
```terraform | ||
data "netdata_room" "test" { | ||
spaceid = "<spaceid>" | ||
id = "<roomid>" | ||
} | ||
``` | ||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `id` (String) The ID of the room | ||
- `spaceid` (String) The ID of the space | ||
|
||
### Read-Only | ||
|
||
- `description` (String) The description of the room | ||
- `name` (String) The name of the room |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "netdata_room Resource - terraform-provider-netdata" | ||
subcategory: "" | ||
description: |- | ||
--- | ||
|
||
# netdata_room (Resource) | ||
|
||
|
||
|
||
## Example Usage | ||
|
||
```terraform | ||
resource "netdata_room" "test" { | ||
spaceid = "<spaceid>" | ||
name = "MyTestingSpace" | ||
description = "Created by Terraform" | ||
} | ||
``` | ||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `name` (String) The name of the room | ||
- `spaceid` (String) The ID of the space | ||
|
||
### Optional | ||
|
||
- `description` (String) The description of the room | ||
|
||
### Read-Only | ||
|
||
- `id` (String) The ID of the room | ||
|
||
## Import | ||
|
||
Import is supported using the following syntax: | ||
|
||
```shell | ||
#!/bin/sh | ||
|
||
terraform import netdata_room.test spaceid,roomid | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
data "netdata_room" "test" { | ||
spaceid = "<spaceid>" | ||
id = "<roomid>" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
data "netdata_space" "test" { | ||
id = "ee3ec76d-0180-4ef4-93ae-c94c1e7ed2f1" | ||
id = "<spaceid>" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/sh | ||
|
||
terraform import netdata_room.test spaceid,roomid |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
resource "netdata_room" "test" { | ||
spaceid = "<spaceid>" | ||
name = "MyTestingSpace" | ||
description = "Created by Terraform" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
#!/bin/sh | ||
|
||
terraform import netdata_space.test ee3ec76d-0180-4ef4-93ae-c94c1e7ed2f1 | ||
terraform import netdata_space.test spaceid |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
package client | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"net/http" | ||
"strings" | ||
) | ||
|
||
func (c *Client) GetRooms(spaceid string) (*[]RoomInfo, error) { | ||
if spaceid == "" { | ||
return nil, fmt.Errorf("spaceid is empty") | ||
} | ||
req, err := http.NewRequest("GET", fmt.Sprintf("%s/api/v2/spaces/%s/rooms", c.HostURL, spaceid), nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
body, err := c.doRequest(req) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var rooms []RoomInfo | ||
err = json.Unmarshal(body, &rooms) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &rooms, nil | ||
} | ||
|
||
func (c *Client) GetRoomByID(id, spaceid string) (*RoomInfo, error) { | ||
rooms, err := c.GetRooms(spaceid) | ||
if err != nil { | ||
return nil, err | ||
} | ||
for _, room := range *rooms { | ||
if room.ID == id { | ||
return &room, nil | ||
} | ||
} | ||
return nil, ErrNotFound | ||
} | ||
|
||
func (c *Client) CreateRoom(spaceid, name, description string) (*RoomInfo, error) { | ||
if spaceid == "" { | ||
return nil, fmt.Errorf("spaceid is empty") | ||
} | ||
reqBody, err := json.Marshal(map[string]string{ | ||
"name": name, | ||
"description": description, | ||
}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
req, err := http.NewRequest("POST", fmt.Sprintf("%s/api/v1/spaces/%s/rooms", c.HostURL, spaceid), strings.NewReader(string(reqBody))) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
respBody, err := c.doRequest(req) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var room RoomInfo | ||
err = json.Unmarshal(respBody, &room) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
room.Name = name | ||
room.Description = description | ||
|
||
return &room, nil | ||
} | ||
|
||
func (c *Client) UpdateRoomByID(id, spaceid, name, description string) error { | ||
if id == "" { | ||
return fmt.Errorf("id is empty") | ||
} | ||
if spaceid == "" { | ||
return fmt.Errorf("spaceid is empty") | ||
} | ||
reqBody, err := json.Marshal(map[string]string{ | ||
"name": name, | ||
"description": description, | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
req, err := http.NewRequest("PATCH", fmt.Sprintf("%s/api/v1/spaces/%s/rooms/%s", c.HostURL, spaceid, id), strings.NewReader(string(reqBody))) | ||
if err != nil { | ||
return err | ||
} | ||
_, err = c.doRequest(req) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
func (c *Client) DeleteRoomByID(id, spaceid string) error { | ||
if id == "" { | ||
return fmt.Errorf("id is empty") | ||
} | ||
if spaceid == "" { | ||
return fmt.Errorf("spaceid is empty") | ||
} | ||
req, err := http.NewRequest("DELETE", fmt.Sprintf("%s/api/v1/spaces/%s/rooms/%s", c.HostURL, spaceid, id), nil) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
_, err = c.doRequest(req) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.