-
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.
Merge pull request #25 from mohith10/doc-feature
Added "Documentation" feature
- Loading branch information
Showing
5 changed files
with
133 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "dcloud_topology Resource - terraform-provider-dcloud" | ||
subcategory: "" | ||
description: |- | ||
--- | ||
|
||
# dcloud_documentation (Resource) | ||
|
||
|
||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `topology_uid` (String) | ||
- `doc_url` (String) | ||
|
||
### Read-Only | ||
|
||
- `id` (String) The ID of this resource. | ||
- `uid` (String) | ||
|
||
|
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,24 @@ | ||
terraform { | ||
required_providers { | ||
dcloud = { | ||
version = "0.1" | ||
source = "cisco-open/dcloud" | ||
} | ||
} | ||
} | ||
|
||
provider "dcloud" { | ||
tb_url = "https://tbv3-production.ciscodcloud.com/api" | ||
} | ||
|
||
resource "dcloud_topology" "test_topology" { | ||
name = "Documentation Resource Test" | ||
description = "Testing Topology Documentation Resource Management" | ||
notes = "Created via Terraform Test" | ||
datacenter = "LON" | ||
} | ||
|
||
resource "dcloud_documentation" "test_documentation" { | ||
topology_uid = dcloud_topology.test_topology.id | ||
doc_url = "https://johndoe.com" | ||
} |
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,77 @@ | ||
package dcloud | ||
|
||
import ( | ||
"context" | ||
"github.com/cisco-open/dcloud-tb-go-client/tbclient" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
func resourceDoc() *schema.Resource { | ||
return &schema.Resource{ | ||
CreateContext: resourceDocCreate, | ||
ReadContext: resourceDocRead, | ||
UpdateContext: resourceDocUpdate, | ||
DeleteContext: resourceDocDelete, | ||
Schema: map[string]*schema.Schema{ | ||
"topology_uid": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"doc_url": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
/* | ||
Documentation always exists within the context of a Topology, so instead of creating it we read the current one and update its values | ||
*/ | ||
|
||
func resourceDocCreate(ctx context.Context, data *schema.ResourceData, i interface{}) diag.Diagnostics { | ||
c := i.(*tbclient.Client) | ||
|
||
var diags diag.Diagnostics | ||
uid := data.Get("topology_uid").(string) | ||
|
||
documentation, err := c.GetDocumentation(uid) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
documentation.DocumentationUrl = data.Get("doc_url").(string) | ||
_, err = c.UpdateDocumentation(*documentation) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
data.SetId(documentation.Uid) | ||
resourceDocRead(ctx, data, i) | ||
return diags | ||
} | ||
|
||
func resourceDocRead(ctx context.Context, data *schema.ResourceData, i interface{}) diag.Diagnostics { | ||
c := i.(*tbclient.Client) | ||
|
||
var diags diag.Diagnostics | ||
uid := data.Get("topology_uid").(string) | ||
|
||
documentation, err := c.GetDocumentation(uid) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
data.Set("topology_uid", documentation.Uid) | ||
data.Set("doc_url", documentation.DocumentationUrl) | ||
data.SetId(documentation.Uid) | ||
return diags | ||
} | ||
|
||
func resourceDocUpdate(ctx context.Context, data *schema.ResourceData, i interface{}) diag.Diagnostics { | ||
return resourceDocCreate(ctx, data, i) | ||
} | ||
|
||
func resourceDocDelete(ctx context.Context, data *schema.ResourceData, i interface{}) diag.Diagnostics { | ||
data.Set("doc_url", "") | ||
return resourceDocCreate(ctx, data, i) | ||
} |