Skip to content

Commit

Permalink
Formatted
Browse files Browse the repository at this point in the history
  • Loading branch information
htahir1 committed Oct 27, 2024
1 parent 35057fd commit e6d57d4
Show file tree
Hide file tree
Showing 15 changed files with 251 additions and 85 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ go.work.sum

# env file
.env
.aider*
37 changes: 34 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,51 +2,82 @@ module terraform-provider-zenml

go 1.23.2

require (
github.com/hashicorp/terraform-plugin-docs v0.19.4
github.com/hashicorp/terraform-plugin-sdk/v2 v2.34.0
)

require (
github.com/BurntSushi/toml v1.2.1 // indirect
github.com/Kunde21/markdownfmt/v3 v3.1.0 // indirect
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver/v3 v3.2.0 // indirect
github.com/Masterminds/sprig/v3 v3.2.3 // indirect
github.com/ProtonMail/go-crypto v1.1.0-alpha.2 // indirect
github.com/agext/levenshtein v1.2.2 // indirect
github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect
github.com/armon/go-radix v1.0.0 // indirect
github.com/bgentry/speakeasy v0.1.0 // indirect
github.com/bmatcuk/doublestar/v4 v4.6.1 // indirect
github.com/cloudflare/circl v1.3.7 // indirect
github.com/fatih/color v1.16.0 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/hashicorp/cli v1.1.6 // indirect
github.com/hashicorp/errwrap v1.1.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.6.0 // indirect
github.com/hashicorp/go-uuid v1.0.3 // indirect
github.com/hashicorp/go-version v1.7.0 // indirect
github.com/hashicorp/hc-install v0.7.0 // indirect
github.com/hashicorp/hcl/v2 v2.20.1 // indirect
github.com/hashicorp/logutils v1.0.0 // indirect
github.com/hashicorp/terraform-exec v0.21.0 // indirect
github.com/hashicorp/terraform-json v0.22.1 // indirect
github.com/hashicorp/terraform-plugin-docs v0.19.4 // indirect
github.com/hashicorp/terraform-plugin-sdk/v2 v2.34.0 // indirect
github.com/hashicorp/terraform-plugin-go v0.23.0 // indirect
github.com/hashicorp/terraform-plugin-log v0.9.0 // indirect
github.com/hashicorp/terraform-registry-address v0.2.3 // indirect
github.com/hashicorp/terraform-svchost v0.1.1 // indirect
github.com/hashicorp/yamux v0.1.1 // indirect
github.com/huandu/xstrings v1.3.3 // indirect
github.com/imdario/mergo v0.3.15 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.9 // 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/posener/complete v1.2.3 // indirect
github.com/shopspring/decimal v1.3.1 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect
github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
github.com/yuin/goldmark v1.7.1 // indirect
github.com/yuin/goldmark-meta v1.1.0 // indirect
github.com/zclconf/go-cty v1.14.4 // indirect
go.abhg.dev/goldmark/frontmatter v0.2.0 // indirect
golang.org/x/crypto v0.23.0 // indirect
golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df // indirect
golang.org/x/mod v0.17.0 // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/text v0.15.0 // indirect
golang.org/x/tools v0.13.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de // indirect
google.golang.org/grpc v1.63.2 // indirect
google.golang.org/protobuf v1.34.0 // indirect
gopkg.in/yaml.v2 v2.3.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace terraform-provider-zenml => ./
139 changes: 137 additions & 2 deletions go.sum

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions internal/provider/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ func (c *Client) ListStacks(params *ListParams) (*Page[StackResponse], error) {
}

url := fmt.Sprintf("%s/api/v1/stacks?page=%d&size=%d", c.ServerURL, params.Page, params.PageSize)

// Add filters if any
for k, v := range params.Filter {
url = fmt.Sprintf("%s&%s=%s", url, k, v)
Expand Down Expand Up @@ -305,4 +305,4 @@ func (c *Client) ListServiceConnectors(params *ListParams) (*Page[ServiceConnect
}

return &result, nil
}
}
6 changes: 3 additions & 3 deletions internal/provider/data_source_service_connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func dataSourceServiceConnectorRead(d *schema.ResourceData, m interface{}) error
// Try to find by name and workspace
name, hasName := d.GetOk("name")
workspace, hasWorkspace := d.GetOk("workspace")

if !hasName {
return fmt.Errorf("either id or name must be specified")
}
Expand All @@ -45,7 +45,7 @@ func setServiceConnectorFields(d *schema.ResourceData, connector *ServiceConnect
d.Set("name", connector.Name)
d.Set("type", connector.Type)
d.Set("auth_method", connector.AuthMethod)

if connector.Body != nil {
if connector.Body.ResourceTypes != nil {
d.Set("resource_types", connector.Body.ResourceTypes)
Expand All @@ -54,7 +54,7 @@ func setServiceConnectorFields(d *schema.ResourceData, connector *ServiceConnect
d.Set("workspace", connector.Body.Workspace)
}
}

return nil
}

Expand Down
2 changes: 1 addition & 1 deletion internal/provider/data_source_stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,4 @@ func setStackData(d *schema.ResourceData, stack *StackResponse) error {
}

return nil
}
}
6 changes: 3 additions & 3 deletions internal/provider/data_source_stack_component.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func dataSourceStackComponentRead(d *schema.ResourceData, m interface{}) error {
// Try to find by name and workspace
name, hasName := d.GetOk("name")
workspace, hasWorkspace := d.GetOk("workspace")

if !hasName {
return fmt.Errorf("either id or name must be specified")
}
Expand All @@ -45,14 +45,14 @@ func setStackComponentFields(d *schema.ResourceData, component *ComponentRespons
d.Set("name", component.Name)
d.Set("type", component.Type)
d.Set("flavor", component.Flavor)

if component.Body != nil {
d.Set("configuration", component.Body.Configuration)
if component.Body.Workspace != "" {
d.Set("workspace", component.Body.Workspace)
}
}

return nil
}

Expand Down
101 changes: 50 additions & 51 deletions internal/provider/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,89 +10,88 @@ type Page[T any] struct {

// Stack models
type StackResponse struct {
ID string `json:"id"`
Name string `json:"name"`
Components map[string]Component `json:"components"`
Labels map[string]string `json:"labels,omitempty"`
Metadata *ResponseMetadata `json:"metadata,omitempty"`
ID string `json:"id"`
Name string `json:"name"`
Components map[string]Component `json:"components"`
Labels map[string]string `json:"labels,omitempty"`
Metadata *ResponseMetadata `json:"metadata,omitempty"`
}

type StackUpdate struct {
Name string `json:"name,omitempty"`
Components map[string]Component `json:"components,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
Name string `json:"name,omitempty"`
Components map[string]Component `json:"components,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
}

// Component models
type Component struct {
ID string `json:"id"`
Name string `json:"name,omitempty"`
Type string `json:"type,omitempty"`
Flavor string `json:"flavor,omitempty"`
Configuration map[string]interface{} `json:"configuration,omitempty"`
ConnectorID string `json:"connector_id,omitempty"`
ID string `json:"id"`
Name string `json:"name,omitempty"`
Type string `json:"type,omitempty"`
Flavor string `json:"flavor,omitempty"`
Configuration map[string]interface{} `json:"configuration,omitempty"`
ConnectorID string `json:"connector_id,omitempty"`
}


type ComponentResponse struct {
ID string `json:"id"`
Name string `json:"name"`
Type string `json:"type"`
Flavor string `json:"flavor"`
Body *ComponentBody `json:"body,omitempty"`
Metadata *ResponseMetadata `json:"metadata,omitempty"`
ID string `json:"id"`
Name string `json:"name"`
Type string `json:"type"`
Flavor string `json:"flavor"`
Body *ComponentBody `json:"body,omitempty"`
Metadata *ResponseMetadata `json:"metadata,omitempty"`
}

type ComponentBody struct {
User string `json:"user"`
Workspace string `json:"workspace"`
Configuration map[string]interface{} `json:"configuration"`
ConnectorResourceID *string `json:"connector_resource_id,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
ComponentSpecPath *string `json:"component_spec_path,omitempty"`
Connector *string `json:"connector,omitempty"`
User string `json:"user"`
Workspace string `json:"workspace"`
Configuration map[string]interface{} `json:"configuration"`
ConnectorResourceID *string `json:"connector_resource_id,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
ComponentSpecPath *string `json:"component_spec_path,omitempty"`
Connector *string `json:"connector,omitempty"`
}

type ComponentUpdate struct {
Name string `json:"name,omitempty"`
Configuration map[string]interface{} `json:"configuration,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
ComponentSpecPath *string `json:"component_spec_path,omitempty"`
Connector *string `json:"connector,omitempty"`
Connector *string `json:"connector,omitempty"`
}

// Service Connector models
type ServiceConnectorResponse struct {
ID string `json:"id"`
Name string `json:"name"`
Type string `json:"type"`
AuthMethod string `json:"auth_method"`
Body *ServiceConnectorBody `json:"body,omitempty"`
Metadata *ResponseMetadata `json:"metadata,omitempty"`
ID string `json:"id"`
Name string `json:"name"`
Type string `json:"type"`
AuthMethod string `json:"auth_method"`
Body *ServiceConnectorBody `json:"body,omitempty"`
Metadata *ResponseMetadata `json:"metadata,omitempty"`
}

type ServiceConnectorBody struct {
User string `json:"user"`
Workspace string `json:"workspace"`
Configuration map[string]interface{} `json:"configuration"`
Secrets map[string]interface{} `json:"secrets,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
ResourceTypes []string `json:"resource_types,omitempty"`
User string `json:"user"`
Workspace string `json:"workspace"`
Configuration map[string]interface{} `json:"configuration"`
Secrets map[string]interface{} `json:"secrets,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
ResourceTypes []string `json:"resource_types,omitempty"`
}

type ServiceConnectorUpdate struct {
Name string `json:"name,omitempty"`
Configuration map[string]interface{} `json:"configuration,omitempty"`
Secrets map[string]interface{} `json:"secrets,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
ResourceTypes []string `json:"resource_types,omitempty"`
Name string `json:"name,omitempty"`
Configuration map[string]interface{} `json:"configuration,omitempty"`
Secrets map[string]interface{} `json:"secrets,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
ResourceTypes []string `json:"resource_types,omitempty"`
}

type ResponseMetadata struct {
Created string `json:"created"`
Updated string `json:"updated"`
User string `json:"user"`
Workspace string `json:"workspace"`
Created string `json:"created"`
Updated string `json:"updated"`
User string `json:"user"`
Workspace string `json:"workspace"`
}

// APIError represents an error response from the API
Expand All @@ -104,4 +103,4 @@ type APIError struct {

func (e *APIError) Error() string {
return fmt.Sprintf("API error (code: %d): %s - %s", e.Code, e.Message, e.Details)
}
}
2 changes: 1 addition & 1 deletion internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ func Provider() *schema.Provider {
"zenml_service_connector": dataSourceServiceConnector(),
},
}
}
}
6 changes: 3 additions & 3 deletions internal/provider/resource_service_connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func resourceServiceConnector() *schema.Resource {
Required: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{
"aws", "gcp", "azure", "kubernetes",
"aws", "gcp", "azure", "kubernetes",
"github", "gitlab", "bitbucket", "docker",
"mysql", "postgres", "snowflake", "databricks",
}, false),
Expand Down Expand Up @@ -155,7 +155,7 @@ func resourceServiceConnectorRead(d *schema.ResourceData, m interface{}) error {
d.Set("workspace", connector.Body.Workspace)
d.Set("configuration", connector.Body.Configuration)
d.Set("resource_types", connector.Body.ResourceTypes)

if connector.Body.Labels != nil {
d.Set("labels", connector.Body.Labels)
}
Expand Down Expand Up @@ -224,4 +224,4 @@ func resourceServiceConnectorDelete(d *schema.ResourceData, m interface{}) error

d.SetId("")
return nil
}
}
2 changes: 1 addition & 1 deletion internal/provider/resource_service_connector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,4 @@ resource "zenml_service_connector" "test" {
}
}
`
}
}
10 changes: 5 additions & 5 deletions internal/provider/resource_stack_component.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func resourceStackComponent() *schema.Resource {
Read: resourceStackComponentRead,
Update: resourceStackComponentUpdate,
Delete: resourceStackComponentDelete,

CustomizeDiff: func(ctx context.Context, d *schema.ResourceDiff, m interface{}) error {
// Validate that if connector is set, connector_resource_id should also be set
connector, hasConnector := d.GetOk("connector")
Expand Down Expand Up @@ -170,19 +170,19 @@ func resourceStackComponentRead(d *schema.ResourceData, m interface{}) error {
d.Set("user", component.Body.User)
d.Set("workspace", component.Body.Workspace)
d.Set("configuration", component.Body.Configuration)

if component.Body.ConnectorResourceID != nil {
d.Set("connector_resource_id", *component.Body.ConnectorResourceID)
}

if component.Body.Labels != nil {
d.Set("labels", component.Body.Labels)
}

if component.Body.ComponentSpecPath != nil {
d.Set("component_spec_path", *component.Body.ComponentSpecPath)
}

if component.Body.Connector != nil {
d.Set("connector", *component.Body.Connector)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/resource_stack_component_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,4 +206,4 @@ resource "zenml_stack_component" "test" {
}
}
`
}
}
2 changes: 1 addition & 1 deletion internal/provider/resource_stack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ resource "zenml_stack" "test" {
}
}
`
}
}
Loading

0 comments on commit e6d57d4

Please sign in to comment.