Skip to content

Commit

Permalink
feat(resources): pinecone_index (#2)
Browse files Browse the repository at this point in the history
* feat(resources): initial work for `pinecone_index`

* implemented `Create` and `Read`
- next, `Update`, `Delete` and idempotency

* chore: gitignore `terraform.tfstate`

* chore: git ignore state backup

* chore: change example tf

* feat: implement update and destroy

* chore: add additional pinecone requests

* feat: basic acceptance test
  • Loading branch information
thiskevinwang committed Oct 5, 2023
1 parent 09a250a commit 60c4d02
Show file tree
Hide file tree
Showing 15 changed files with 1,296 additions and 24 deletions.
6 changes: 6 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Enables acceptance tests
TF_ACC=1

# Secrets used by the acceptance tests
PINECONE_API_KEY=
PINECONE_ENVIRONMENT=
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.tfvars
terraform.tfvars
terraform.tfstate
terraform.tfstate.backup
.env
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ terraform {
provider "pinecone" {}
```

## Testing

```console
cp .env.example .env
go test -v ./...
```

## Appendix

- https://docs.pinecone.io/
Expand Down
2 changes: 2 additions & 0 deletions examples/.tfvars.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pinecone_api_key = "fixme"
pinecone_environment = "us-west4-gcp-free"
2 changes: 0 additions & 2 deletions examples/basic/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,4 @@ terraform {
}

provider "pinecone" {
apikey = "1"
environment = "dev"
}
11 changes: 11 additions & 0 deletions examples/resource/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
provider "pinecone" {
apikey = var.pinecone_api_key
environment = var.pinecone_environment
}

resource "pinecone_index" "my-first-index" {
name = "testidx"
dimension = 1536
metric = "cosine"
pods = 1
}
7 changes: 7 additions & 0 deletions examples/resource/terraform.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
terraform {
required_providers {
pinecone = {
source = "thekevinwang.com/terraform-providers/pinecone"
}
}
}
8 changes: 8 additions & 0 deletions examples/resource/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
variable "pinecone_api_key" {
type = string
sensitive = true
}

variable "pinecone_environment" {
type = string
}
37 changes: 33 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,57 @@ go 1.21.1

require (
github.com/hashicorp/terraform-plugin-framework v1.4.0
github.com/hashicorp/terraform-plugin-go v0.19.0
github.com/hashicorp/terraform-plugin-log v0.9.0
github.com/hashicorp/terraform-plugin-testing v1.5.1
github.com/joho/godotenv v1.5.1
)

require (
github.com/ProtonMail/go-crypto v0.0.0-20230717121422-5aa5874ade95 // indirect
github.com/agext/levenshtein v1.2.2 // indirect
github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect
github.com/cloudflare/circl v1.3.3 // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/hashicorp/go-checkpoint v0.5.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320 // indirect
github.com/hashicorp/go-hclog v1.5.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-plugin v1.5.1 // indirect
github.com/hashicorp/go-uuid v1.0.3 // indirect
github.com/hashicorp/terraform-plugin-go v0.19.0 // indirect
github.com/hashicorp/go-version v1.6.0 // indirect
github.com/hashicorp/hc-install v0.6.0 // indirect
github.com/hashicorp/hcl/v2 v2.18.0 // indirect
github.com/hashicorp/logutils v1.0.0 // indirect
github.com/hashicorp/terraform-exec v0.19.0 // indirect
github.com/hashicorp/terraform-json v0.17.1 // indirect
github.com/hashicorp/terraform-plugin-sdk/v2 v2.29.0 // indirect
github.com/hashicorp/terraform-registry-address v0.2.2 // indirect
github.com/hashicorp/terraform-svchost v0.1.1 // indirect
github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb // indirect
github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
github.com/mitchellh/go-wordwrap v1.0.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/oklog/run v1.0.0 // indirect
github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect
github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
github.com/zclconf/go-cty v1.14.0 // indirect
golang.org/x/crypto v0.13.0 // indirect
golang.org/x/exp v0.0.0-20230809150735-7b3493d9a819 // indirect
golang.org/x/mod v0.12.0 // indirect
golang.org/x/net v0.13.0 // indirect
golang.org/x/sys v0.10.0 // indirect
golang.org/x/text v0.11.0 // indirect
golang.org/x/sys v0.12.0 // indirect
golang.org/x/text v0.13.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230525234030-28d5490b6b19 // indirect
google.golang.org/grpc v1.57.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
Expand Down
164 changes: 158 additions & 6 deletions go.sum

Large diffs are not rendered by default.

31 changes: 19 additions & 12 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-log/tflog"
resources "github.com/thiskevinwang/terraform-provider-pinecone/internal/resources"
services "github.com/thiskevinwang/terraform-provider-pinecone/internal/services"
)

// Ensure the implementation satisfies the expected interfaces.
Expand Down Expand Up @@ -51,14 +53,14 @@ func (p *pineconeProvider) Schema(_ context.Context, _ provider.SchemaRequest, r
Attributes: map[string]schema.Attribute{
"apikey": schema.StringAttribute{
Description: "...Or PINECONE_API_KEY",
Optional: false,
Required: true,
Optional: true,
Required: false,
Sensitive: true,
},
"environment": schema.StringAttribute{
Description: "...Or PINECONE_ENVIRONMENT",
Optional: false,
Required: true,
Optional: true,
Required: false,
},
},
}
Expand Down Expand Up @@ -113,15 +115,15 @@ func (p *pineconeProvider) Configure(ctx context.Context, req provider.Configure

if apikey == "" {
resp.Diagnostics.AddAttributeError(
path.Root("host"),
path.Root("apikey"),
"Missing (ApiKey)",
"Detail (ApiKey)",
)
}

if environment == "" {
resp.Diagnostics.AddAttributeError(
path.Root("username"),
path.Root("environment"),
"Missing (Environment)",
"Detail (Environment)",
)
Expand All @@ -132,19 +134,22 @@ func (p *pineconeProvider) Configure(ctx context.Context, req provider.Configure
}

ctx = tflog.SetField(ctx, "pinecone_api_key", apikey)
ctx = tflog.MaskFieldValuesWithFieldKeys(ctx, "pinecone_api_key")

ctx = tflog.SetField(ctx, "pinecone_environment", environment)
ctx = tflog.MaskFieldValuesWithFieldKeys(ctx, "pinecone_api_key")

tflog.Debug(ctx, "Creating client")

// TODO(kevinwang): create pinecone client?
client := services.Pinecone{
ApiKey: apikey,
Environment: environment,
}

// TODO(kevinwang): Make the client available during DataSource and Resource type Configure methods.
// resp.DataSourceData = client
// resp.ResourceData = client
resp.DataSourceData = client
resp.ResourceData = client

// tflog.Info(ctx, "Configured client", map[string]any{"success": true})
tflog.Info(ctx, "Configured client", map[string]any{"success": true})
}

// DataSources defines the data sources implemented in the provider.
Expand All @@ -154,5 +159,7 @@ func (p *pineconeProvider) DataSources(_ context.Context) []func() datasource.Da

// Resources defines the resources implemented in the provider.
func (p *pineconeProvider) Resources(_ context.Context) []func() resource.Resource {
return []func() resource.Resource{}
return []func() resource.Resource{
resources.NewIndexResource,
}
}
Loading

0 comments on commit 60c4d02

Please sign in to comment.