Skip to content

Commit beb2fbe

Browse files
authored
added optional functionality to disable TLS verification (#6)
1 parent 0c1d8ee commit beb2fbe

File tree

7 files changed

+50
-19
lines changed

7 files changed

+50
-19
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@ terraform {
2222
required_providers {
2323
curl2 = {
2424
source = "mehulgohil/curl2"
25-
version = "1.1.1"
25+
version = "1.2.0"
2626
}
2727
}
2828
}
2929
30-
provider "curl2" {}
30+
provider "curl2" {
31+
# disable_tls = true
32+
}
3133
3234
data "curl2" "getPosts" {
3335
http_method = "GET"

curl2/client.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,7 @@ type HttpClient struct {
1616
timeout int
1717
}
1818

19-
func NewClient() (*HttpClient, error) {
20-
opts := ApiClientOpts{
21-
insecure: false,
22-
timeout: 0,
23-
}
24-
19+
func NewClient(opts ApiClientOpts) (*HttpClient, error) {
2520
tlsConfig := &tls.Config{
2621
InsecureSkipVerify: opts.insecure,
2722
}

curl2/provider.go

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"github.com/hashicorp/terraform-plugin-framework/provider"
77
"github.com/hashicorp/terraform-plugin-framework/provider/schema"
88
"github.com/hashicorp/terraform-plugin-framework/resource"
9+
"github.com/hashicorp/terraform-plugin-framework/types"
910
"github.com/hashicorp/terraform-plugin-log/tflog"
1011
)
1112

@@ -19,6 +20,11 @@ func NewProvider() provider.Provider {
1920

2021
type curl2Provider struct{}
2122

23+
// curl2ProviderModel maps provider schema data to a Go type.
24+
type curl2ProviderModel struct {
25+
DisableTLS types.Bool `tfsdk:"disable_tls"`
26+
}
27+
2228
func (c *curl2Provider) Metadata(_ context.Context, _ provider.MetadataRequest, resp *provider.MetadataResponse) {
2329
resp.TypeName = "curl2"
2430
}
@@ -27,14 +33,30 @@ func (c *curl2Provider) Metadata(_ context.Context, _ provider.MetadataRequest,
2733
func (c *curl2Provider) Schema(_ context.Context, _ provider.SchemaRequest, resp *provider.SchemaResponse) {
2834
resp.Schema = schema.Schema{
2935
Description: "Triggers HTTP(s) requests along with JSON body, authentication as well as custom headers",
30-
Attributes: map[string]schema.Attribute{},
36+
Attributes: map[string]schema.Attribute{
37+
"disable_tls": schema.BoolAttribute{
38+
Optional: true,
39+
Description: "Use to disable the TLS verification. Defaults to false.",
40+
},
41+
},
3142
}
3243
}
3344

3445
func (c *curl2Provider) Configure(ctx context.Context, req provider.ConfigureRequest, resp *provider.ConfigureResponse) {
3546
tflog.Info(ctx, "Configuring curl2 client", map[string]any{"success": false})
47+
// Retrieve provider data from configuration
48+
var config curl2ProviderModel
49+
diags := req.Config.Get(ctx, &config)
50+
resp.Diagnostics.Append(diags...)
51+
if resp.Diagnostics.HasError() {
52+
return
53+
}
3654

37-
client, err := NewClient()
55+
opts := ApiClientOpts{
56+
insecure: config.DisableTLS.ValueBool(),
57+
timeout: 0, //default to 0, no timeout
58+
}
59+
client, err := NewClient(opts)
3860
if err != nil {
3961
resp.Diagnostics.AddError(
4062
"Unable to Create curl2 client",

docs/data-sources/curl2.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@ terraform {
1717
required_providers {
1818
curl2 = {
1919
source = "mehulgohil/curl2"
20-
version = "1.1.1"
20+
version = "1.2.0"
2121
}
2222
}
2323
}
2424
25-
provider "curl2" {}
25+
provider "curl2" {
26+
# disable_tls = true
27+
}
2628
2729
data "curl2" "getPosts" {
2830
http_method = "GET"
@@ -74,7 +76,7 @@ output "post_posts_output" {
7476
- `basic_auth_password` (String, Sensitive) Password to be used for Authentication.
7577
- `basic_auth_username` (String) Username to be used for Basic Authentication.
7678
- `bearer_token` (String, Sensitive) Bearer Token to be used for Authentication.
77-
- `headers` (Map of String)
79+
- `headers` (Map of String) Headers to be added.
7880
- `json` (String) JSON object in string format if using POST, PUT or PATCH method.
7981

8082
### Read-Only

docs/index.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@ terraform {
1717
required_providers {
1818
curl2 = {
1919
source = "mehulgohil/curl2"
20-
version = "1.1.1"
20+
version = "1.2.0"
2121
}
2222
}
2323
}
2424
25-
provider "curl2" {}
25+
provider "curl2" {
26+
# disable_tls = true
27+
}
2628
2729
data "curl2" "getPosts" {
2830
http_method = "GET"
@@ -46,3 +48,7 @@ output "all_posts_status" {
4648

4749
<!-- schema generated by tfplugindocs -->
4850
## Schema
51+
52+
### Optional
53+
54+
- `disable_tls` (Boolean) Use to disable the TLS verification. Defaults to false.

examples/data-sources/curl2/data-source.tf

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ terraform {
22
required_providers {
33
curl2 = {
44
source = "mehulgohil/curl2"
5-
version = "1.1.1"
5+
version = "1.2.0"
66
}
77
}
88
}
99

10-
provider "curl2" {}
10+
provider "curl2" {
11+
# disable_tls = true
12+
}
1113

1214
data "curl2" "getPosts" {
1315
http_method = "GET"

examples/provider/provider.tf

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ terraform {
22
required_providers {
33
curl2 = {
44
source = "mehulgohil/curl2"
5-
version = "1.1.1"
5+
version = "1.2.0"
66
}
77
}
88
}
99

10-
provider "curl2" {}
10+
provider "curl2" {
11+
# disable_tls = true
12+
}
1113

1214
data "curl2" "getPosts" {
1315
http_method = "GET"

0 commit comments

Comments
 (0)