forked from DrFaust92/terraform-provider-confluence
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/Mesomorphic/terraform-pro…
- Loading branch information
Showing
16 changed files
with
231 additions
and
24 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
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 |
---|---|---|
@@ -1 +1 @@ | ||
0.2.0 | ||
0.2.1 |
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
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,105 @@ | ||
package confluence | ||
|
||
import ( | ||
"strconv" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" | ||
) | ||
|
||
func resourceSpace() *schema.Resource { | ||
return &schema.Resource{ | ||
Create: resourceSpaceCreate, | ||
Read: resourceSpaceRead, | ||
Update: resourceSpaceUpdate, | ||
Delete: resourceSpaceDelete, | ||
Importer: &schema.ResourceImporter{ | ||
StateContext: schema.ImportStatePassthroughContext, | ||
}, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"key": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ValidateFunc: validation.StringLenBetween(0, 255), | ||
}, | ||
"url": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func resourceSpaceCreate(d *schema.ResourceData, m interface{}) error { | ||
client := m.(*Client) | ||
contentRequest := spaceFromResourceData(d) | ||
contentResponse, err := client.CreateSpace(contentRequest) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
d.SetId(strconv.Itoa(contentResponse.Id)) | ||
return resourceSpaceRead(d, m) | ||
} | ||
|
||
func resourceSpaceRead(d *schema.ResourceData, m interface{}) error { | ||
client := m.(*Client) | ||
contentResponse, err := client.GetSpace(d.Get("key").(string)) | ||
if err != nil { | ||
d.SetId("") | ||
return err | ||
} | ||
return updateResourceDataFromSpace(d, contentResponse, client) | ||
} | ||
|
||
func resourceSpaceUpdate(d *schema.ResourceData, m interface{}) error { | ||
client := m.(*Client) | ||
contentRequest := spaceFromResourceData(d) | ||
_, err := client.UpdateSpace(contentRequest) | ||
if err != nil { | ||
d.SetId("") | ||
return err | ||
} | ||
return resourceSpaceRead(d, m) | ||
} | ||
|
||
func resourceSpaceDelete(d *schema.ResourceData, m interface{}) error { | ||
client := m.(*Client) | ||
err := client.DeleteSpace(d.Get("key").(string)) | ||
if err != nil { | ||
return err | ||
} | ||
// d.SetId("") is automatically called assuming delete returns no errors | ||
return nil | ||
} | ||
|
||
func spaceFromResourceData(d *schema.ResourceData) *Space { | ||
id, _ := strconv.Atoi(d.Id()) | ||
result := &Space{ | ||
Id: id, | ||
Key: d.Get("key").(string), | ||
Name: d.Get("name").(string), | ||
} | ||
return result | ||
} | ||
|
||
func updateResourceDataFromSpace(d *schema.ResourceData, space *Space, client *Client) error { | ||
d.SetId(strconv.Itoa(space.Id)) | ||
m := map[string]interface{}{ | ||
"key": space.Key, | ||
"name": space.Name, | ||
"url": space.Links.Base + space.Links.WebUI, | ||
} | ||
for k, v := range m { | ||
err := d.Set(k, v) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package confluence | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
// Content is a primary resource in Confluence | ||
type Space struct { | ||
Id int `json:"id,omitempty"` | ||
Name string `json:"name,omitempty"` | ||
Key string `json:"key,omitempty"` | ||
Links *SpaceLinks `json:"_links,omitempty"` | ||
} | ||
|
||
// ContentLinks is part of Content | ||
type SpaceLinks struct { | ||
Base string `json:"base,omitempty"` | ||
WebUI string `json:"webui,omitempty"` | ||
} | ||
|
||
func (c *Client) CreateSpace(space *Space) (*Space, error) { | ||
var response Space | ||
if err := c.Post("/rest/api/space", space, &response); err != nil { | ||
return nil, err | ||
} | ||
return &response, nil | ||
} | ||
|
||
func (c *Client) GetSpace(id string) (*Space, error) { | ||
var response Space | ||
path := fmt.Sprintf("/rest/api/space/%s", id) | ||
if err := c.Get(path, &response); err != nil { | ||
return nil, err | ||
} | ||
|
||
return &response, nil | ||
} | ||
|
||
func (c *Client) UpdateSpace(space *Space) (*Space, error) { | ||
var response Space | ||
|
||
path := fmt.Sprintf("/rest/api/space/%s", space.Key) | ||
if err := c.Put(path, space, &response); err != nil { | ||
return nil, err | ||
} | ||
return &response, nil | ||
} | ||
|
||
func (c *Client) DeleteSpace(id string) error { | ||
path := fmt.Sprintf("/rest/api/space/%s", id) | ||
if err := c.Delete(path); err != nil { | ||
if strings.HasPrefix(err.Error(), "202 ") { | ||
//202 is the delete API success response | ||
//Other APIs return 204. Because, reasons. | ||
return 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
provider "confluence" { | ||
site = var.site | ||
user = var.user | ||
token = var.token | ||
} | ||
resource confluence_space "example" { | ||
key = var.space | ||
name = "Terraformed Space" | ||
} | ||
resource confluence_content "example" { | ||
space = confluence_space.example.key | ||
title = "Terraformed Page" | ||
body = "Terraformed Content" | ||
} | ||
|
||
variable "site" { | ||
type = string | ||
} | ||
|
||
variable "user" { | ||
type = string | ||
} | ||
|
||
variable "token" { | ||
type = string | ||
} | ||
|
||
variable "space" { | ||
type = string | ||
} | ||
output "example" { | ||
value = confluence_space.example | ||
} |
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 |
---|---|---|
@@ -1,9 +1,10 @@ | ||
site_name: "Terraform Provider: Confluence" | ||
site_url: https://chesshacker.github.io/terraform-provider-confluence/ | ||
repo_url: https://github.com/chesshacker/terraform-provider-confluence | ||
site_url: https://github.com/mesomorphic/terraform-provider-confluence | ||
repo_url: https://github.com/mesomorphic/terraform-provider-confluence | ||
nav: | ||
- Getting Started: index.md | ||
- Resources: | ||
- confluence_attachment: resources/confluence_attachment.md | ||
- confluence_content: resources/confluence_content.md | ||
- confluence_space: resources/confluence_space.md | ||
theme: readthedocs |
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,6 @@ | ||
{ | ||
"version": 1, | ||
"metadata": { | ||
"protocol_versions": ["5.0"] | ||
} | ||
} |