Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mso_rest data source #184

Merged
merged 3 commits into from
Apr 19, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions mso/datasource_mso_rest.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package mso

import (
"log"

"github.com/ciscoecosystem/mso-go-client/client"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
)

func datasourceMSORest() *schema.Resource {
return &schema.Resource{

Read: datasourceMSORestRead,

SchemaVersion: version,

Schema: (map[string]*schema.Schema{
"path": &schema.Schema{
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringLenBetween(1, 1000),
},
"content": &schema.Schema{
Type: schema.TypeString,
Computed: true,
},
}),
}
}

func datasourceMSORestRead(d *schema.ResourceData, m interface{}) error {
log.Printf("[DEBUG] Beginning Read")
danischm marked this conversation as resolved.
Show resolved Hide resolved

path := d.Get("path").(string)
msoClient := m.(*client.Client)
content, err := MakeRestRequest(msoClient, path, "GET", "{}")
if err != nil {
return err
}
d.SetId(path)
d.Set("content", content.String())

log.Printf("[DEBUG] %s: Read finished successfully", d.Id())
return nil
}
1 change: 1 addition & 0 deletions mso/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ func Provider() terraform.ResourceProvider {
"mso_schema_template_service_graph": dataSourceMSOSchemaTemplateServiceGraph(),
"mso_service_node_type": dataSourceMSOServiceNodeType(),
"mso_schema_template_contract_service_graph": datasourceTemplateContractServiceGraph(),
"mso_rest": datasourceMSORest(),
},

ConfigureFunc: configureClient,
Expand Down
27 changes: 27 additions & 0 deletions website/docs/d/rest.html.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
layout: "mso"
page_title: "MSO: mso_rest"
sidebar_current: "docs-mso-data-source-rest"
description: |-
MSO Rest data source to read MSO objects via REST API.
---

# mso_rest #

MSO Rest data source to read MSO objects via REST API.

## Example Usage ##

```hcl
data "mso_rest" "system_config" {
path = "api/v1/platform/systemConfig"
}
```

## Argument Reference ##

* `path` - (Required) MSO REST endpoint, where the data is being read.

## Attribute Reference ##

* `content` - (Read-Only) JSON response as a string.