Skip to content

Commit

Permalink
Merge pull request #26 from mohith10/telephony-feature
Browse files Browse the repository at this point in the history
Added the Telephony feature -> data source and resource
  • Loading branch information
hughwphamill authored Oct 18, 2023
2 parents 2b96c33 + 767665a commit bbce129
Show file tree
Hide file tree
Showing 12 changed files with 468 additions and 2 deletions.
3 changes: 2 additions & 1 deletion GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ NAMESPACE=cisco-open
NAME=dcloud
BINARY=terraform-provider-${NAME}
VERSION=0.1
OS_ARCH=darwin_amd64
OS_ARCH=darwin_arm64

default: install

Expand All @@ -24,6 +24,7 @@ release:
GOOS=solaris GOARCH=amd64 go build -o ./bin/${BINARY}_${VERSION}_solaris_amd64
GOOS=windows GOARCH=386 go build -o ./bin/${BINARY}_${VERSION}_windows_386
GOOS=windows GOARCH=amd64 go build -o ./bin/${BINARY}_${VERSION}_windows_amd64
GOOS=darwin GOARCH=arm64 go build -o ./bin/${BINARY}_${VERSION}_darwin_arm64

install: build
mkdir -p ~/.terraform.d/plugins/${HOSTNAME}/${NAMESPACE}/${NAME}/${VERSION}/${OS_ARCH}
Expand Down
36 changes: 36 additions & 0 deletions docs/data-sources/inventory_telephony.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "dcloud_inventory_telephony Data Source - terraform-provider-dcloud"
subcategory: ""
description: |-
All the inventory telephony available to be used in a topology
---

# dcloud_inventory_telephony (Data Source)

All the inventory telephony available to be used in a topology



<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `topology_uid` (String)

### Read-Only

- `id` (String) The ID of this resource.
- `inventory_telephony` (List of Object) (see [below for nested schema](#nestedatt--inventory_telephony))

<a id="nestedatt--inventory_telephony"></a>
### Nested Schema for `inventory_telephony`

Read-Only:

- `id` (String)
- `name` (String)
- `description` (String)


37 changes: 37 additions & 0 deletions docs/data-sources/telephony.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "dcloud_telephony Data Source - terraform-provider-dcloud"
subcategory: ""
description: |-
All the telephony items currently in a given topology
---

# dcloud_telephony (Data Source)

All the telephony items currently in a given topology



<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `topology_uid` (String)

### Read-Only

- `id` (String) The ID of this resource.
- `telephony-items` (List of Object) (see [below for nested schema](#nestedatt--telephonyItems))

<a id="nestedatt--telephonyItems"></a>
### Nested Schema for `telephonyItems`

Read-Only:

- `topology_uid` (String)
- `uid` (String)
- `name` (String)
- `inventory_telephony_id` (String)
- `inventory_telephony_name` (String)
- `inventory_description_name` (String)
31 changes: 31 additions & 0 deletions docs/resources/telephony.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "dcloud_telephony Resource - terraform-provider-dcloud"
subcategory: ""
description: |-
---

# dcloud_telephony (Resource)





<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `topology_uid` (String)
- `inventory_telephony_id` (String)

### Read-Only

- `id` (String) The ID of this resource.
- `uid` (String)
- `name` (String)
- `inventory_telephony_name` (String)
- `inventory_telephony_description` (String)


Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
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 = "Test Topology For Testing Inventory Telephony Items"
description = "Will be used to load inventory telephony items"
notes = ""
datacenter = "LON"
}

data "dcloud_inventory_telephony" "topology1_inventory_telephony" {
topology_uid = dcloud_topology.test_topology.id
}

output "telephony-items" {
value = data.dcloud_inventory_telephony.topology1_inventory_telephony
}
32 changes: 32 additions & 0 deletions examples/data-sources/telephony_data_source/data-source.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
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 = "Test Topology For Testing Telephony Items"
description = "Will be used to load telephony items"
notes = ""
datacenter = "LON"
}

resource "dcloud_telephony" "test_telephony" {
topology_uid = dcloud_topology.test_topology.id
inventory_telephony_id = "1"
}

data "dcloud_telephony" "test_topology_telephony" {
topology_uid = dcloud_topology.test_topology.id
}

output "telephony-items" {
value = data.dcloud_telephony.test_topology_telephony
}
7 changes: 6 additions & 1 deletion examples/provider/provider.tf
Original file line number Diff line number Diff line change
Expand Up @@ -217,4 +217,9 @@ resource "dcloud_scenario" "scenario" {
resource "dcloud_documentation" "documentation" {
topology_uid = dcloud_topology.test_topology.id
doc_url = "https://johndoe.com"
}
}

resource "dcloud_telephony" "telephony" {
topology_uid = dcloud_topology.test_topology.id
inventory_telephony_id = "1"
}
24 changes: 24 additions & 0 deletions examples/resources/telephony_resource/resource.tf
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 = "Telephony Resource Test"
description = "Testing Topology Telephony Resource Management"
notes = "Created via Terraform Test"
datacenter = "LON"
}

resource "dcloud_telephony" "test_telephony" {
inventory_telephony_id = "1"
topology_uid = dcloud_topology.test_topology.id
}
76 changes: 76 additions & 0 deletions internal/dcloud/data_source_inventory_telephony.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
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"
"strconv"
"time"
)

func dataSourceInventoryTelephony() *schema.Resource {
return &schema.Resource{
Description: "All the inventory Telephony Items available to be used in a topology",

ReadContext: dataSourceInventoryTelephonyRead,
Schema: map[string]*schema.Schema{
"topology_uid": {
Type: schema.TypeString,
Required: true,
},
"inventory_telephony": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Computed: true,
},
"name": {
Type: schema.TypeString,
Computed: true,
},
"description": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
},
}
}

func dataSourceInventoryTelephonyRead(ctx context.Context, d *schema.ResourceData, i interface{}) diag.Diagnostics {
tb := i.(*tbclient.Client)
topologyUid := d.Get("topology_uid").(string)
inventoryTelephonyItems, err := tb.GetAllInventoryTelephonyItems(topologyUid)

if err != nil {
return diag.FromErr(err)
}

inventoryTelephonyResources := make([]map[string]interface{}, len(inventoryTelephonyItems))

for i, inventoryTelephonyItem := range inventoryTelephonyItems {
inventoryTelephonyResources[i] = convertInventoryTelephonyToDataResource(inventoryTelephonyItem)
}

if err := d.Set("inventory_telephony", inventoryTelephonyResources); err != nil {
return diag.FromErr(err)
}
d.SetId(strconv.FormatInt(time.Now().Unix(), 10))

return diag.Diagnostics{}
}

func convertInventoryTelephonyToDataResource(inventoryTelephonyItem tbclient.InventoryTelephonyItem) map[string]interface{} {
resource := make(map[string]interface{})
resource["id"] = inventoryTelephonyItem.Id
resource["name"] = inventoryTelephonyItem.Name
resource["description"] = inventoryTelephonyItem.Description

return resource
}
93 changes: 93 additions & 0 deletions internal/dcloud/data_source_telephony.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
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"
"strconv"
"time"
)

func dataSourceTelephony() *schema.Resource {
return &schema.Resource{
Description: "All the Telephony Items currently in a given topology",

ReadContext: dataSourceTelephonyRead,

Schema: map[string]*schema.Schema{
"topology_uid": {
Type: schema.TypeString,
Required: true,
},
"telephony_items": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"uid": {
Type: schema.TypeString,
Computed: true,
},
"name": {
Type: schema.TypeString,
Computed: true,
},
"inventory_telephony_id": {
Type: schema.TypeString,
Computed: true,
},
"inventory_telephony_name": {
Type: schema.TypeString,
Computed: true,
},
"inventory_telephony_description": {
Type: schema.TypeString,
Computed: true,
},
"topology_uid": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
},
}
}

func dataSourceTelephonyRead(ctx context.Context, d *schema.ResourceData, i interface{}) diag.Diagnostics {
tb := i.(*tbclient.Client)

topologyUid := d.Get("topology_uid").(string)

telephonyItems, err := tb.GetAllTelephonyItems(topologyUid)
if err != nil {
return diag.FromErr(err)
}

telephonyResources := make([]map[string]interface{}, len(telephonyItems))

for i, telephonyItem := range telephonyItems {
telephonyResources[i] = convertTelephonyItemToDataResource(telephonyItem)
}

if err := d.Set("telephony_items", telephonyResources); err != nil {
return diag.FromErr(err)
}
d.SetId(strconv.FormatInt(time.Now().Unix(), 10))

return diag.Diagnostics{}
}

func convertTelephonyItemToDataResource(telephonyItem tbclient.TelephonyItem) map[string]interface{} {
resource := make(map[string]interface{})
resource["uid"] = telephonyItem.Uid
resource["topology_uid"] = telephonyItem.Topology.Uid
resource["name"] = telephonyItem.Name
resource["inventory_telephony_id"] = telephonyItem.InventoryTelephonyItem.Id
resource["inventory_telephony_name"] = telephonyItem.InventoryTelephonyItem.Name
resource["inventory_telephony_description"] = telephonyItem.InventoryTelephonyItem.Description

return resource
}
Loading

0 comments on commit bbce129

Please sign in to comment.