-
Notifications
You must be signed in to change notification settings - Fork 12
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 #172 from cisco-en-programmability/develop
Develop v1.1.5
- Loading branch information
Showing
188 changed files
with
558 additions
and
186 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
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,238 @@ | ||
package dnacenter | ||
|
||
import ( | ||
"context" | ||
"reflect" | ||
|
||
"log" | ||
|
||
dnacentersdkgo "github.com/cisco-en-programmability/dnacenter-go-sdk/v5/sdk" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
func resourceConfigurationTemplateVersion() *schema.Resource { | ||
return &schema.Resource{ | ||
Description: `It manages create and read operations on Configuration Templates. | ||
- API to version the current contents of the template. | ||
`, | ||
|
||
CreateContext: resourceConfigurationTemplateVersionCreate, | ||
ReadContext: resourceConfigurationTemplateVersionRead, | ||
UpdateContext: resourceConfigurationTemplateVersionUpdate, | ||
DeleteContext: resourceConfigurationTemplateVersionDelete, | ||
Importer: &schema.ResourceImporter{ | ||
StateContext: schema.ImportStatePassthroughContext, | ||
}, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"last_updated": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"item": &schema.Schema{ | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
|
||
"composite": &schema.Schema{ | ||
Description: `Is it composite template | ||
`, | ||
// Type: schema.TypeBool, | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"name": &schema.Schema{ | ||
Description: `Name of template | ||
`, | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"project_id": &schema.Schema{ | ||
Description: `UUID of project | ||
`, | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"project_name": &schema.Schema{ | ||
Description: `Name of project | ||
`, | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"template_id": &schema.Schema{ | ||
Description: `UUID of template | ||
`, | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"versions_info": &schema.Schema{ | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
|
||
"author": &schema.Schema{ | ||
Description: `Author of version template | ||
`, | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"description": &schema.Schema{ | ||
Description: `Description of template | ||
`, | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"id": &schema.Schema{ | ||
Description: `UUID of template | ||
`, | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"version": &schema.Schema{ | ||
Description: `Current version of template | ||
`, | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"version_comment": &schema.Schema{ | ||
Description: `Version comment | ||
`, | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"version_time": &schema.Schema{ | ||
Description: `Template version time | ||
`, | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
"parameters": &schema.Schema{ | ||
Type: schema.TypeList, | ||
Optional: true, | ||
Computed: true, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
|
||
"comments": &schema.Schema{ | ||
Description: `Template version comments | ||
`, | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
}, | ||
"template_id": &schema.Schema{ | ||
Description: `UUID of template | ||
`, | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func resourceConfigurationTemplateVersionCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||
client := m.(*dnacentersdkgo.Client) | ||
|
||
var diags diag.Diagnostics | ||
|
||
resourceItem := *getResourceItem(d.Get("parameters")) | ||
request1 := expandRequestConfigurationTemplateVersionVersionTemplate(ctx, "parameters.0", d) | ||
log.Printf("[DEBUG] request sent => %v", responseInterfaceToString(*request1)) | ||
|
||
vTemplateID := resourceItem["template_id"] | ||
vvTemplateID := interfaceToString(vTemplateID) | ||
// if vvTemplateID != "" { | ||
// getResponse1, _, err := client.ConfigurationTemplates.GetsAllTheVersionsOfAGivenTemplate(vvTemplateID) | ||
// if err == nil && getResponse1 != nil { | ||
// resourceMap := make(map[string]string) | ||
// resourceMap["template_id"] = vvTemplateID | ||
// d.SetId(joinResourceID(resourceMap)) | ||
// return resourceConfigurationTemplateVersionRead(ctx, d, m) | ||
// } | ||
// } | ||
resp1, restyResp1, err := client.ConfigurationTemplates.VersionTemplate(request1) | ||
if err != nil || resp1 == nil { | ||
if restyResp1 != nil { | ||
diags = append(diags, diagErrorWithResponse( | ||
"Failure when executing VersionTemplate", err, restyResp1.String())) | ||
return diags | ||
} | ||
diags = append(diags, diagError( | ||
"Failure when executing VersionTemplate", err)) | ||
return diags | ||
} | ||
resourceMap := make(map[string]string) | ||
resourceMap["template_id"] = vvTemplateID | ||
d.SetId(joinResourceID(resourceMap)) | ||
return resourceConfigurationTemplateVersionRead(ctx, d, m) | ||
} | ||
|
||
func resourceConfigurationTemplateVersionRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||
client := m.(*dnacentersdkgo.Client) | ||
var diags diag.Diagnostics | ||
|
||
resourceID := d.Id() | ||
resourceMap := separateResourceID(resourceID) | ||
|
||
vTemplateID := resourceMap["template_id"] | ||
|
||
selectedMethod := 1 | ||
if selectedMethod == 1 { | ||
log.Printf("[DEBUG] Selected method: GetsAllTheVersionsOfAGivenTemplate") | ||
vvTemplateID := vTemplateID | ||
|
||
item1, _, err := client.ConfigurationTemplates.GetsAllTheVersionsOfAGivenTemplate(vvTemplateID) | ||
if err != nil || item1 == nil { | ||
d.SetId("") | ||
return diags | ||
} | ||
// Review flatten function used | ||
vItem1 := flattenConfigurationTemplatesGetsAllTheVersionsOfAGivenTemplateItems(item1) | ||
if err := d.Set("item", vItem1); err != nil { | ||
diags = append(diags, diagError( | ||
"Failure when setting GetsAllTheVersionsOfAGivenTemplate search response", | ||
err)) | ||
return diags | ||
} | ||
|
||
} | ||
return diags | ||
} | ||
|
||
func resourceConfigurationTemplateVersionUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||
return resourceConfigurationTemplateVersionRead(ctx, d, m) | ||
} | ||
|
||
func resourceConfigurationTemplateVersionDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||
var diags diag.Diagnostics | ||
// NOTE: Unable to delete ConfigurationTemplateVersion on Dna Center | ||
// Returning empty diags to delete it on Terraform | ||
return diags | ||
} | ||
func expandRequestConfigurationTemplateVersionVersionTemplate(ctx context.Context, key string, d *schema.ResourceData) *dnacentersdkgo.RequestConfigurationTemplatesVersionTemplate { | ||
request := dnacentersdkgo.RequestConfigurationTemplatesVersionTemplate{} | ||
if v, ok := d.GetOkExists(fixKeyAccess(key + ".comments")); !isEmptyValue(reflect.ValueOf(d.Get(fixKeyAccess(key+".comments")))) && (ok || !reflect.DeepEqual(v, d.Get(fixKeyAccess(key+".comments")))) { | ||
request.Comments = interfaceToString(v) | ||
} | ||
if v, ok := d.GetOkExists(fixKeyAccess(key + ".template_id")); !isEmptyValue(reflect.ValueOf(d.Get(fixKeyAccess(key+".template_id")))) && (ok || !reflect.DeepEqual(v, d.Get(fixKeyAccess(key+".template_id")))) { | ||
request.TemplateID = interfaceToString(v) | ||
} | ||
if isEmptyValue(reflect.ValueOf(request)) { | ||
return nil | ||
} | ||
return &request | ||
} |
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,87 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "dnacenter_configuration_template_version Resource - terraform-provider-dnacenter" | ||
subcategory: "" | ||
description: |- | ||
It manages create and read operations on Configuration Templates. | ||
API to version the current contents of the template. | ||
--- | ||
|
||
# dnacenter_configuration_template_version (Resource) | ||
|
||
It manages create and read operations on Configuration Templates. | ||
|
||
- API to version the current contents of the template. | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
resource "dnacenter_configuration_template_version" "example" { | ||
provider = dnacenter | ||
parameters { | ||
# comments = "string" | ||
template_id = "string" | ||
} | ||
} | ||
output "dnacenter_configuration_template_version_example" { | ||
value = dnacenter_configuration_template_version.example | ||
} | ||
``` | ||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Optional | ||
|
||
- `parameters` (Block List) (see [below for nested schema](#nestedblock--parameters)) | ||
|
||
### Read-Only | ||
|
||
- `id` (String) The ID of this resource. | ||
- `item` (List of Object) (see [below for nested schema](#nestedatt--item)) | ||
- `last_updated` (String) | ||
|
||
<a id="nestedblock--parameters"></a> | ||
### Nested Schema for `parameters` | ||
|
||
Required: | ||
|
||
- `template_id` (String) UUID of template | ||
|
||
Optional: | ||
|
||
- `comments` (String) Template version comments | ||
|
||
|
||
<a id="nestedatt--item"></a> | ||
### Nested Schema for `item` | ||
|
||
Read-Only: | ||
|
||
- `composite` (String) | ||
- `name` (String) | ||
- `project_id` (String) | ||
- `project_name` (String) | ||
- `template_id` (String) | ||
- `versions_info` (List of Object) (see [below for nested schema](#nestedobjatt--item--versions_info)) | ||
|
||
<a id="nestedobjatt--item--versions_info"></a> | ||
### Nested Schema for `item.versions_info` | ||
|
||
Read-Only: | ||
|
||
- `author` (String) | ||
- `description` (String) | ||
- `id` (String) | ||
- `version` (String) | ||
- `version_comment` (String) | ||
- `version_time` (Number) | ||
|
||
## Import | ||
|
||
Import is supported using the following syntax: | ||
|
||
```shell | ||
terraform import dnacenter_configuration_template_version.example "template_id:=string" | ||
``` |
1 change: 1 addition & 0 deletions
1
examples/resources/dnacenter_configuration_template_version/import.sh
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 @@ | ||
terraform import dnacenter_configuration_template_version.example "template_id:=string" |
12 changes: 12 additions & 0 deletions
12
examples/resources/dnacenter_configuration_template_version/resource.tf
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,12 @@ | ||
|
||
resource "dnacenter_configuration_template_version" "example" { | ||
provider = dnacenter | ||
parameters { | ||
# comments = "string" | ||
template_id = "string" | ||
} | ||
} | ||
|
||
output "dnacenter_configuration_template_version_example" { | ||
value = dnacenter_configuration_template_version.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
Oops, something went wrong.