From 068cfc6433a565faaeacbee5c8f4f021c4329229 Mon Sep 17 00:00:00 2001 From: Dana Fallon <8871189+danafallon@users.noreply.github.com> Date: Mon, 29 Jul 2024 13:14:07 -0700 Subject: [PATCH] Remove deployments datasource --- docs/data-sources/deployments.md | 31 ----- examples/deployments/main.tf | 6 - internal/provider/deployments_data_source.go | 138 ------------------- internal/provider/provider.go | 4 +- 4 files changed, 1 insertion(+), 178 deletions(-) delete mode 100644 docs/data-sources/deployments.md delete mode 100644 internal/provider/deployments_data_source.go diff --git a/docs/data-sources/deployments.md b/docs/data-sources/deployments.md deleted file mode 100644 index f61568f..0000000 --- a/docs/data-sources/deployments.md +++ /dev/null @@ -1,31 +0,0 @@ ---- -# generated by https://github.com/hashicorp/terraform-plugin-docs -page_title: "artie_deployments Data Source - artie" -subcategory: "" -description: |- - Artie Deployments Data Source ---- - -# artie_deployments (Data Source) - -Artie Deployments Data Source - - - - -## Schema - -### Read-Only - -- `deployments` (Attributes List) (see [below for nested schema](#nestedatt--deployments)) - - -### Nested Schema for `deployments` - -Read-Only: - -- `has_undeployed_changes` (Boolean) -- `last_updated_at` (String) -- `name` (String) -- `status` (String) -- `uuid` (String) diff --git a/examples/deployments/main.tf b/examples/deployments/main.tf index a930432..f0c7e7b 100644 --- a/examples/deployments/main.tf +++ b/examples/deployments/main.tf @@ -101,9 +101,3 @@ resource "artie_deployment" "example" { # } # advanced_settings = {} # } - -# data "artie_deployments" "example" {} - -# output "deployments" { -# value = data.artie_deployments.example.deployments -# } diff --git a/internal/provider/deployments_data_source.go b/internal/provider/deployments_data_source.go deleted file mode 100644 index 20d0582..0000000 --- a/internal/provider/deployments_data_source.go +++ /dev/null @@ -1,138 +0,0 @@ -package provider - -import ( - "context" - "encoding/json" - "fmt" - "io" - "net/http" - - "github.com/hashicorp/terraform-plugin-framework/datasource" - "github.com/hashicorp/terraform-plugin-framework/datasource/schema" -) - -// Ensure the implementation satisfies the expected interfaces. -var ( - _ datasource.DataSource = &deploymentsDataSource{} - _ datasource.DataSourceWithConfigure = &deploymentsDataSource{} -) - -// NewDeploymentsDataSource is a helper function to simplify the provider implementation. -func NewDeploymentsDataSource() datasource.DataSource { - return &deploymentsDataSource{} -} - -type deploymentsModel struct { - UUID string `tfsdk:"uuid"` - Name string `tfsdk:"name"` - Status string `tfsdk:"status"` - LastUpdatedAt string `tfsdk:"last_updated_at"` - HasUndeployedChanges bool `tfsdk:"has_undeployed_changes"` -} - -type deploymentsDataSourceModel struct { - Deployments []deploymentsModel `tfsdk:"deployments"` -} - -type deploymentsResponse struct { - Deployments []deploymentsModel `json:"items"` -} - -type deploymentsDataSource struct { - endpoint string - apiKey string -} - -func (d *deploymentsDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { - resp.TypeName = req.ProviderTypeName + "_deployments" -} - -func (d *deploymentsDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) { - // Prevent panic if the provider has not been configured. - if req.ProviderData == nil { - return - } - - providerData, ok := req.ProviderData.(ArtieProviderData) - if !ok { - resp.Diagnostics.AddError( - "Unexpected Data Source Configure Type", - fmt.Sprintf("Expected ArtieProviderData, got: %T. Please report this issue to the provider developers.", req.ProviderData), - ) - - return - } - - d.endpoint = providerData.Endpoint - d.apiKey = providerData.APIKey -} - -func (d *deploymentsDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) { - resp.Schema = schema.Schema{ - MarkdownDescription: "Artie Deployments Data Source", - Attributes: map[string]schema.Attribute{ - "deployments": schema.ListNestedAttribute{ - Computed: true, - NestedObject: schema.NestedAttributeObject{ - Attributes: map[string]schema.Attribute{ - "uuid": schema.StringAttribute{Computed: true}, - "name": schema.StringAttribute{Computed: true}, - "status": schema.StringAttribute{Computed: true}, - "last_updated_at": schema.StringAttribute{Computed: true}, - "has_undeployed_changes": schema.BoolAttribute{Computed: true}, - }, - }, - }, - }, - } -} - -// Read refreshes the Terraform state with the latest data. -func (d *deploymentsDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { - var state deploymentsDataSourceModel - - apiReq, err := http.NewRequest("GET", fmt.Sprintf("%s/deployments", d.endpoint), nil) - if err != nil { - resp.Diagnostics.AddError("Unable to Read Deployments", err.Error()) - return - } - - apiReq.Header.Set("Authorization", fmt.Sprintf("Bearer %s", d.apiKey)) - apiResp, err := http.DefaultClient.Do(apiReq) - if err != nil { - resp.Diagnostics.AddError("Unable to Read Deployments", err.Error()) - return - } - - if apiResp.StatusCode != http.StatusOK { - resp.Diagnostics.AddError("Unable to Read Deployments", fmt.Sprintf("Received status code %d", apiResp.StatusCode)) - return - } - - bodyBytes, err := io.ReadAll(apiResp.Body) - if err != nil { - resp.Diagnostics.AddError("Unable to Read Deployments", err.Error()) - return - } - - var deploymentsResp deploymentsResponse - err = json.Unmarshal(bodyBytes, &deploymentsResp) - if err != nil { - resp.Diagnostics.AddError("Unable to Read Deployments", err.Error()) - return - } - - for _, deployment := range deploymentsResp.Deployments { - deploymentState := deploymentsModel{ - UUID: deployment.UUID, - Name: deployment.Name, - Status: deployment.Status, - LastUpdatedAt: deployment.LastUpdatedAt, - HasUndeployedChanges: deployment.HasUndeployedChanges, - } - state.Deployments = append(state.Deployments, deploymentState) - } - - // Save data into Terraform state - resp.Diagnostics.Append(resp.State.Set(ctx, &state)...) -} diff --git a/internal/provider/provider.go b/internal/provider/provider.go index 1939494..9bb7040 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -95,9 +95,7 @@ func (p *ArtieProvider) Resources(ctx context.Context) []func() resource.Resourc } func (p *ArtieProvider) DataSources(ctx context.Context) []func() datasource.DataSource { - return []func() datasource.DataSource{ - NewDeploymentsDataSource, - } + return []func() datasource.DataSource{} } func (p *ArtieProvider) Functions(ctx context.Context) []func() function.Function {