diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..4b46ff0 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,13 @@ +# These are supported funding model platforms + +github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] +patreon: # Replace with a single Patreon username +open_collective: # Replace with a single Open Collective username +ko_fi: mirogta +tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel +community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry +liberapay: # Replace with a single Liberapay username +issuehunt: # Replace with a single IssueHunt username +otechie: # Replace with a single Otechie username +lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry +custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] diff --git a/.gitignore b/.gitignore index e7755fc..792ff4a 100644 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,7 @@ secrets.* # ignore some things terraform could produce in the examples .terraform terraform.tfstate* -vendor \ No newline at end of file +vendor + +__debug_bin +.vscode \ No newline at end of file diff --git a/README.md b/README.md index 3ffe650..f741a32 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -![](https://github.com/mesomorphic/terraform-provider-confluence/workflows/Build%20and%20Test/badge.svg) +![](https://img.shields.io/github/workflow/status/mirogta/terraform-provider-confluence/release) # Terraform Provider for Confluence @@ -19,6 +19,13 @@ $ cd terraform-provider-confluence $ make install ``` +## Debugging + +See: + +- +- + ## Contributing Contributions are welcome! Please read the contribution guidelines [Contributing to Terraform - Confluence Provider](.github/CONTRIBUTING.md) diff --git a/VERSION b/VERSION index f477849..373f8c6 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.2.2 \ No newline at end of file +0.2.3 \ No newline at end of file diff --git a/confluence/content.go b/confluence/content.go index 0c06439..e62c986 100644 --- a/confluence/content.go +++ b/confluence/content.go @@ -11,14 +11,15 @@ type Body struct { // Content is a primary resource in Confluence type Content struct { - Id string `json:"id,omitempty"` - Type string `json:"type,omitempty"` - Title string `json:"title,omitempty"` - Space *SpaceKey `json:"space,omitempty"` - Version *Version `json:"version,omitempty"` - Body *Body `json:"body,omitempty"` - Links *ContentLinks `json:"_links,omitempty"` - Ancestors []*Content `json:"ancestors,omitempty"` + Id string `json:"id,omitempty"` + Type string `json:"type,omitempty"` + Title string `json:"title,omitempty"` + Space *SpaceKey `json:"space,omitempty"` + Version *Version `json:"version,omitempty"` + Body *Body `json:"body,omitempty"` + Links *ContentLinks `json:"_links,omitempty"` + Ancestors []*Content `json:"ancestors,omitempty"` + Metadata *ContentMetadata `json:"metadata,omitempty"` } // ContentLinks is part of Content @@ -43,6 +44,17 @@ type Version struct { Number int `json:"number,omitempty"` } +// ContentMetadata is part of Content +type ContentMetadata struct { + Labels []*Label `json:"labels,omitempty"` +} + +// Label is part of Metadata +type Label struct { + Prefix string `json:"prefix,omitempty"` + Name string `json:"name,omitempty"` +} + func (c *Client) CreateContent(content *Content) (*Content, error) { var response Content if err := c.Post("/rest/api/content", content, &response); err != nil { diff --git a/confluence/resource_content.go b/confluence/resource_content.go index d62a3ef..83b7a50 100644 --- a/confluence/resource_content.go +++ b/confluence/resource_content.go @@ -53,6 +53,13 @@ func resourceContent() *schema.Resource { Default: "", DiffSuppressFunc: resourceContentDiffParent, }, + "labels": { + Type: schema.TypeList, + Optional: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, }, } } @@ -109,7 +116,7 @@ func contentFromResourceData(d *schema.ResourceData) *Content { Body: &Body{ Storage: &Storage{ Value: d.Get("body").(string), - Representation: "storage", + Representation: "editor2", }, }, Title: d.Get("title").(string), @@ -127,6 +134,21 @@ func contentFromResourceData(d *schema.ResourceData) *Content { }, } } + + labelsRaw := d.Get("labels").([]interface{}) + if len(labelsRaw) > 0 { + labels := make([]*Label, len(labelsRaw)) + for i, raw := range labelsRaw { + labels[i] = &Label{ + Prefix: "global", + Name: raw.(string), + } + } + result.Metadata = &ContentMetadata{ + Labels: labels, + } + } + return result } @@ -143,6 +165,13 @@ func updateResourceDataFromContent(d *schema.ResourceData, content *Content, cli if len(content.Ancestors) > 1 { m["parent"] = content.Ancestors[len(content.Ancestors)-1].Id } + if content.Metadata != nil && len(content.Metadata.Labels) > 1 { + labels := []string{} + for i, label := range content.Metadata.Labels { + labels[i] = label.Name + } + m["labels"] = labels + } for k, v := range m { err := d.Set(k, v) if err != nil { diff --git a/docs/resources/confluence_content.md b/docs/resources/confluence_content.md index 4b64b85..e82474c 100644 --- a/docs/resources/confluence_content.md +++ b/docs/resources/confluence_content.md @@ -18,6 +18,7 @@ resource confluence_content "default" { title = "Example Page" body = "

This page was built with Terraform

" parent = "123456" + labels = ["sample-label", "another-label"] } ``` @@ -39,6 +40,8 @@ The following arguments are supported: * `type` - (Optional) The content type (either "page" or "blogpost"). Default is page. +* `labels` - (Optional) List of page labels. + ## Attributes Reference This resource exports the following attributes: diff --git a/examples/content/main.tf b/examples/content/main.tf index 5c2be44..fd7219b 100644 --- a/examples/content/main.tf +++ b/examples/content/main.tf @@ -18,6 +18,7 @@ resource confluence_content "example" { body = templatefile("${path.module}/example.tmpl", { pets = [for p in random_pet.pets : title(p.id)] }) + labels = ["pets", "example"] } terraform { diff --git a/go.mod b/go.mod index 5998004..61dcb2a 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/mesomorphic/terraform-provider-confluence +module github.com/mirogta/terraform-provider-confluence go 1.16 diff --git a/main.go b/main.go index 3708b02..8bba12e 100644 --- a/main.go +++ b/main.go @@ -1,11 +1,30 @@ package main import ( + "context" + "flag" + "log" + "github.com/hashicorp/terraform-plugin-sdk/v2/plugin" - "github.com/mesomorphic/terraform-provider-confluence/confluence" + "github.com/mirogta/terraform-provider-confluence/confluence" ) func main() { - plugin.Serve(&plugin.ServeOpts{ - ProviderFunc: confluence.Provider}) + var debugMode bool + flag.BoolVar(&debugMode, "debug", false, "set to true to run the provider with support for debuggers like delve") + flag.Parse() + + opts := &plugin.ServeOpts{ + ProviderFunc: confluence.Provider, + } + + if debugMode { + err := plugin.Debug(context.Background(), "mirogta/terraform-provider-confluence", opts) + if err != nil { + log.Fatal(err.Error()) + } + return + } + + plugin.Serve(opts) } diff --git a/mkdocs.yml b/mkdocs.yml index 26afad5..b0d01c3 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -1,6 +1,6 @@ site_name: "Terraform Provider: Confluence" -site_url: https://github.com/mesomorphic/terraform-provider-confluence -repo_url: https://github.com/mesomorphic/terraform-provider-confluence +site_url: https://github.com/mirogta/terraform-provider-confluence +repo_url: https://github.com/mirogta/terraform-provider-confluence nav: - Getting Started: index.md - Resources: