Skip to content

Commit

Permalink
added better documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
anschoewe committed Feb 20, 2021
1 parent 09cbb9e commit 74f1462
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 13 deletions.
7 changes: 4 additions & 3 deletions curl/data_source_curl.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package curl
import (
"context"
"fmt"
"log"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"io/ioutil"
"log"
"net/http"
"strconv"
"time"
Expand All @@ -19,16 +19,17 @@ func dataSource() *schema.Resource {
"uri": &schema.Schema{
Type: schema.TypeString,
Required: true,

Description: "URI of resource you'd like to retrieve via HTTP(s).",
},
"http_method": &schema.Schema{
Type: schema.TypeString,
Required: true,

Description: "HTTP method like GET, POST, PUT, DELETE, PATCH.",
},
"response": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "Valued returned by the HTTP request.",
},
},
}
Expand Down
4 changes: 4 additions & 0 deletions curl/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,26 @@ func Provider() *schema.Provider {
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("CURL_CLIENT_ID", nil),
Description: "OAuth2 client id",
},
"secret": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Sensitive: true,
DefaultFunc: schema.EnvDefaultFunc("CURL_CLIENT_SECRET", nil),
Description: "OAuth2 secret. Instead of setting the secret in the Terraform file, using the CURL_CLIENT_SECRET environment variable is advised.",
},
"resource": &schema.Schema{
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("CURL_RESOURCE", nil),
Description: "OAuth2 value expected by Azure AD when issuing tokens. It affects the 'audience' in the issued access_token.",
},
"tenant_id": &schema.Schema{
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("CURL_TENANT_ID", nil),
Description: "OAuth2 value expected by Azure AD when issuing tokens.",
},
},
ResourcesMap: map[string]*schema.Resource{},
Expand Down
33 changes: 30 additions & 3 deletions docs/data-sources/curl.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,51 @@ description: |-

# curl (Data Source)

Sends HTTP(s) requests, optionally with OAuth2 access_token in the 'Authorization' header.

## Example Usage

```hcl
provider "curl" {
// client_id = "<client id of this app, registered in Azure AD>"
// resource = "https://vault.azure.net" //example of the scope/resource to call Azure KeyVault APIs
// tenant_id = "<azure tenant id>"
// secret = "" //taken from environment variable 'CURL_CLIENT_SECRET'
}
data "curl" "getTodos" {
http_method = "GET"
uri = "https://jsonplaceholder.typicode.com/todos/1"
}
locals {
json_data = jsondecode(data.curl.getTodos.response)
}
# Returns all Todos
output "all_todos" {
value = local.json_data
}
//# Returns the title of todo
output "todo_title" {
value = local.json_data.title
}
<!-- schema generated by tfplugindocs -->
## Schema
### Required
- **http_method** (String)
- **uri** (String)
- **http_method** (String) HTTP method like GET, POST, PUT, DELETE, PATCH.
- **uri** (String) URI of resource you'd like to retrieve via HTTP(s).
### Optional
- **id** (String) The ID of this resource.
### Read-Only
- **response** (String)
- **response** (String) Valued returned by the HTTP request.
12 changes: 5 additions & 7 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,14 @@ description: |-

# curl Provider




Sends HTTP(s) requests, optionally with OAuth2 access_token in the 'Authorization' header.

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

### Optional

- **client_id** (String)
- **resource** (String)
- **secret** (String, Sensitive)
- **tenant_id** (String)
- **client_id** (String) OAuth2 client id
- **resource** (String) OAuth2 value expected by Azure AD when issuing tokens. It affects the 'audience' in the issued access_token.
- **secret** (String, Sensitive) OAuth2 secret. Instead of setting the secret in the Terraform file, using the CURL_CLIENT_SECRET environment variable is advised.
- **tenant_id** (String) OAuth2 value expected by Azure AD when issuing tokens.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ require (
github.com/Azure/go-autorest/autorest/azure/auth v0.5.7
github.com/hashicorp/terraform-plugin-docs v0.4.0 // indirect
github.com/hashicorp/terraform-plugin-sdk/v2 v2.4.3
github.com/mattn/go-colorable v0.1.8 // indirect
github.com/zclconf/go-cty v1.7.1 // indirect
)

0 comments on commit 74f1462

Please sign in to comment.