Skip to content

Commit

Permalink
Merge pull request #172 from cisco-en-programmability/develop
Browse files Browse the repository at this point in the history
Develop v1.1.5
  • Loading branch information
fmunozmiranda authored May 9, 2023
2 parents 38a023f + 0f07902 commit 7af108a
Show file tree
Hide file tree
Showing 188 changed files with 558 additions and 186 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 1.1.5-beta (May 09, 2023)
FEATURES:
**New Resource:** `resourceConfigurationTemplateVersion`

BUGFIXES:
* Updating README, supports 2.3.5.3 DNA Center API Version.

## 1.1.4-beta (May 09, 2023)
BUGFIXES:
* dnacenter_site resource does not save site_id in state any more, however site_id is required for creating other resources #168
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ HOSTNAME=hashicorp.com
NAMESPACE=edu
NAME=dnacenter
BINARY=terraform-provider-${NAME}
VERSION=1.1.4-beta
VERSION=1.1.5-beta
OS_ARCH=darwin_amd64
GOFMT_FILES?=$$(find . -name '*.go' |grep -v vendor)
WEBSITE_REPO=github.com/hashicorp/terraform-website
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ terraform-provider-dnacenter is a Terraform Provider for [Cisco DNA Center](http

The terraform-provider-dnacenter provides a Terraform provider for managing and automating your Cisco DNA Center environment. It consists of a set of resources and data-sources for performing tasks related to DNA Center.

This collection has been tested and supports Cisco DNA Center 2.2.3.3.
This collection has been tested and supports Cisco DNA Center 2.3.5.3.

Other versions of this collection have support for previous Cisco DNA Center versions. The recommended versions are listed below on the [Compatibility matrix](#compatibility-matrix).

Expand All @@ -25,7 +25,7 @@ The following table shows the supported versions.
| 2.2.3.3 | 0.3.0-beta |
| 2.2.3.3 | 0.3.0 |
| 2.3.3.0 | 1.0.19-beta |
| 2.3.5.3 | 1.1.4-beta |
| 2.3.5.3 | 1.1.5-beta |

If your SDK, Terraform provider is older please consider updating it first.

Expand Down
1 change: 1 addition & 0 deletions dnacenter/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ func Provider() *schema.Provider {
"dnacenter_global_credential_http_read": resourceGlobalCredentialHTTPRead(),
"dnacenter_global_credential_cli": resourceGlobalCredentialCli(),
"dnacenter_tag_membership": resourceTagMembership(),
"dnacenter_configuration_template_version": resourceConfigurationTemplateVersion(),
},
DataSourcesMap: map[string]*schema.Resource{
"dnacenter_reserve_ip_subpool": dataSourceReserveIPSubpool(),
Expand Down
238 changes: 238 additions & 0 deletions dnacenter/resource_configuration_template_version.go
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
}
87 changes: 87 additions & 0 deletions docs/resources/configuration_template_version.md
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"
```
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
terraform import dnacenter_configuration_template_version.example "template_id:=string"
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
}
2 changes: 1 addition & 1 deletion examples/samples/data-sources/dnacenter_app_policy/main.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
terraform {
required_providers {
dnacenter = {
version = "1.1.4-beta"
version = "1.1.5-beta"
source = "hashicorp.com/edu/dnacenter"
# "hashicorp.com/edu/dnacenter" is the local built source, change to "cisco-en-programmability/dnacenter" to use downloaded version from registry
}
Expand Down
Loading

0 comments on commit 7af108a

Please sign in to comment.