-
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 #26 from mohith10/telephony-feature
Added the Telephony feature -> data source and resource
- Loading branch information
Showing
12 changed files
with
468 additions
and
2 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
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) | ||
|
||
|
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,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) |
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,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) | ||
|
||
|
27 changes: 27 additions & 0 deletions
27
examples/data-sources/inventory_telephony_data_source/data-source.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,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
32
examples/data-sources/telephony_data_source/data-source.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,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 | ||
} |
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 = "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 | ||
} |
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,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 | ||
} |
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,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 | ||
} |
Oops, something went wrong.