Removed
This commit is contained in:
@@ -1,24 +0,0 @@
|
|||||||
---
|
|
||||||
# generated by https://github.com/hashicorp/terraform-plugin-docs
|
|
||||||
page_title: "virtfusion_example Data Source - terraform-provider-virtfusion"
|
|
||||||
subcategory: ""
|
|
||||||
description: |-
|
|
||||||
Example data source
|
|
||||||
---
|
|
||||||
|
|
||||||
# virtfusion_example (Data Source)
|
|
||||||
|
|
||||||
Example data source
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!-- schema generated by tfplugindocs -->
|
|
||||||
## Schema
|
|
||||||
|
|
||||||
### Optional
|
|
||||||
|
|
||||||
- `configurable_attribute` (String) Example configurable attribute
|
|
||||||
|
|
||||||
### Read-Only
|
|
||||||
|
|
||||||
- `id` (String) Example identifier
|
|
||||||
@@ -1,105 +0,0 @@
|
|||||||
// Copyright (c) HashiCorp, Inc.
|
|
||||||
// SPDX-License-Identifier: MPL-2.0
|
|
||||||
|
|
||||||
package provider
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"fmt"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"github.com/hashicorp/terraform-plugin-framework/datasource"
|
|
||||||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
|
|
||||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
|
||||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Ensure provider defined types fully satisfy framework interfaces.
|
|
||||||
var _ datasource.DataSource = &ExampleDataSource{}
|
|
||||||
|
|
||||||
func NewVirtfusionDataSource() datasource.DataSource {
|
|
||||||
return &ExampleDataSource{}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ExampleDataSource defines the data source implementation.
|
|
||||||
type ExampleDataSource struct {
|
|
||||||
client *http.Client
|
|
||||||
}
|
|
||||||
|
|
||||||
// ExampleDataSourceModel describes the data source data model.
|
|
||||||
type ExampleDataSourceModel struct {
|
|
||||||
ConfigurableAttribute types.String `tfsdk:"configurable_attribute"`
|
|
||||||
Id types.String `tfsdk:"id"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *ExampleDataSource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
|
|
||||||
resp.TypeName = req.ProviderTypeName + "_example"
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *ExampleDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
|
|
||||||
resp.Schema = schema.Schema{
|
|
||||||
// This description is used by the documentation generator and the language server.
|
|
||||||
MarkdownDescription: "Example data source",
|
|
||||||
|
|
||||||
Attributes: map[string]schema.Attribute{
|
|
||||||
"configurable_attribute": schema.StringAttribute{
|
|
||||||
MarkdownDescription: "Example configurable attribute",
|
|
||||||
Optional: true,
|
|
||||||
},
|
|
||||||
"id": schema.StringAttribute{
|
|
||||||
MarkdownDescription: "Example identifier",
|
|
||||||
Computed: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *ExampleDataSource) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
|
|
||||||
// Prevent panic if the provider has not been configured.
|
|
||||||
if req.ProviderData == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
client, ok := req.ProviderData.(*http.Client)
|
|
||||||
|
|
||||||
if !ok {
|
|
||||||
resp.Diagnostics.AddError(
|
|
||||||
"Unexpected Data Source Configure Type",
|
|
||||||
fmt.Sprintf("Expected *http.Client, got: %T. Please report this issue to the provider developers.", req.ProviderData),
|
|
||||||
)
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
d.client = client
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *ExampleDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
|
|
||||||
var data ExampleDataSourceModel
|
|
||||||
|
|
||||||
// Read Terraform configuration data into the model
|
|
||||||
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)
|
|
||||||
|
|
||||||
if resp.Diagnostics.HasError() {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// If applicable, this is a great opportunity to initialize any necessary
|
|
||||||
// provider client data and make a call using it.
|
|
||||||
// httpResp, err := d.client.Do(httpReq)
|
|
||||||
// if err != nil {
|
|
||||||
// resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to read example, got error: %s", err))
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
|
|
||||||
// For the purposes of this example code, hardcoding a response value to
|
|
||||||
// save into the Terraform state.
|
|
||||||
data.Id = types.StringValue("example-id")
|
|
||||||
|
|
||||||
// Write logs using the tflog package
|
|
||||||
// Documentation: https://terraform.io/plugin/log
|
|
||||||
tflog.Trace(ctx, "read a data source")
|
|
||||||
|
|
||||||
// Save data into Terraform state
|
|
||||||
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
|
|
||||||
}
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
// Copyright (c) HashiCorp, Inc.
|
|
||||||
// SPDX-License-Identifier: MPL-2.0
|
|
||||||
|
|
||||||
package provider
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestAccExampleDataSource(t *testing.T) {
|
|
||||||
resource.Test(t, resource.TestCase{
|
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
|
||||||
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
|
|
||||||
Steps: []resource.TestStep{
|
|
||||||
// Read testing
|
|
||||||
{
|
|
||||||
Config: testAccExampleDataSourceConfig,
|
|
||||||
Check: resource.ComposeAggregateTestCheckFunc(
|
|
||||||
resource.TestCheckResourceAttr("data.virtfusion_server.test", "id", "example-id"),
|
|
||||||
),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
const testAccExampleDataSourceConfig = `
|
|
||||||
data "virtfusion_server" "test" {
|
|
||||||
configurable_attribute = "example"
|
|
||||||
}
|
|
||||||
`
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
// Copyright (c) HashiCorp, Inc.
|
|
||||||
// SPDX-License-Identifier: MPL-2.0
|
|
||||||
|
|
||||||
package provider
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/hashicorp/terraform-plugin-framework/providerserver"
|
|
||||||
"github.com/hashicorp/terraform-plugin-go/tfprotov6"
|
|
||||||
)
|
|
||||||
|
|
||||||
// testAccProtoV6ProviderFactories are used to instantiate a provider during
|
|
||||||
// acceptance testing. The factory function will be invoked for every Terraform
|
|
||||||
// CLI command executed to create a provider server to which the CLI can
|
|
||||||
// reattach.
|
|
||||||
var testAccProtoV6ProviderFactories = map[string]func() (tfprotov6.ProviderServer, error){
|
|
||||||
"scaffolding": providerserver.NewProtocol6WithError(New("test")()),
|
|
||||||
}
|
|
||||||
|
|
||||||
func testAccPreCheck(t *testing.T) {
|
|
||||||
// You can add code here to run prior to any test case execution, for example assertions
|
|
||||||
// about the appropriate environment variables being set are common to see in a pre-check
|
|
||||||
// function.
|
|
||||||
}
|
|
||||||
@@ -1,56 +0,0 @@
|
|||||||
// Copyright (c) HashiCorp, Inc.
|
|
||||||
// SPDX-License-Identifier: MPL-2.0
|
|
||||||
|
|
||||||
package provider
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestAccExampleResource(t *testing.T) {
|
|
||||||
resource.Test(t, resource.TestCase{
|
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
|
||||||
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
|
|
||||||
Steps: []resource.TestStep{
|
|
||||||
// Create and Read testing
|
|
||||||
{
|
|
||||||
Config: testAccExampleResourceConfig("one"),
|
|
||||||
Check: resource.ComposeAggregateTestCheckFunc(
|
|
||||||
resource.TestCheckResourceAttr("virtfusion_server.test", "configurable_attribute", "one"),
|
|
||||||
resource.TestCheckResourceAttr("virtfusion_server.test", "defaulted", "example value when not configured"),
|
|
||||||
resource.TestCheckResourceAttr("virtfusion_server.test", "id", "example-id"),
|
|
||||||
),
|
|
||||||
},
|
|
||||||
// ImportState testing
|
|
||||||
{
|
|
||||||
ResourceName: "virtfusion_server.test",
|
|
||||||
ImportState: true,
|
|
||||||
ImportStateVerify: true,
|
|
||||||
// This is not normally necessary, but is here because this
|
|
||||||
// example code does not have an actual upstream service.
|
|
||||||
// Once the Read method is able to refresh information from
|
|
||||||
// the upstream service, this can be removed.
|
|
||||||
ImportStateVerifyIgnore: []string{"configurable_attribute", "defaulted"},
|
|
||||||
},
|
|
||||||
// Update and Read testing
|
|
||||||
{
|
|
||||||
Config: testAccExampleResourceConfig("two"),
|
|
||||||
Check: resource.ComposeAggregateTestCheckFunc(
|
|
||||||
resource.TestCheckResourceAttr("virtfusion_server.test", "configurable_attribute", "two"),
|
|
||||||
),
|
|
||||||
},
|
|
||||||
// Delete testing automatically occurs in TestCase
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func testAccExampleResourceConfig(configurableAttribute string) string {
|
|
||||||
return fmt.Sprintf(`
|
|
||||||
resource "virtfusion_server" "test" {
|
|
||||||
configurable_attribute = %[1]q
|
|
||||||
}
|
|
||||||
`, configurableAttribute)
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user