diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b1a32de..32ff4cc 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -6,7 +6,7 @@ name: Release on: push: tags: - - 'v*' + - "v*" # Releases need permissions to read and write the repository contents. # GitHub considers creating releases and uploading assets as writing contents. @@ -23,7 +23,7 @@ jobs: fetch-depth: 0 - uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0 with: - go-version-file: 'go.mod' + go-version-file: "go.mod" cache: true - name: Import GPG key uses: crazy-max/ghaction-import-gpg@82a020f1f7f605c65dd2449b392a52c3fcfef7ef # v6.0.0 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f6b6d8e..3779897 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -6,10 +6,10 @@ name: Tests on: pull_request: paths-ignore: - - 'README.md' + - "README.md" push: paths-ignore: - - 'README.md' + - "README.md" # Testing only needs permissions to read the repository contents. permissions: @@ -25,7 +25,7 @@ jobs: - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0 with: - go-version-file: 'go.mod' + go-version-file: "go.mod" cache: true - run: go mod download - run: go build -v . @@ -40,7 +40,7 @@ jobs: - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0 with: - go-version-file: 'go.mod' + go-version-file: "go.mod" cache: true - run: go generate ./... - name: git diff @@ -59,16 +59,16 @@ jobs: matrix: # list whatever Terraform versions here you would like to support terraform: - - '1.0.*' - - '1.1.*' - - '1.2.*' - - '1.3.*' - - '1.4.*' + - "1.0.*" + - "1.1.*" + - "1.2.*" + - "1.3.*" + - "1.4.*" steps: - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0 with: - go-version-file: 'go.mod' + go-version-file: "go.mod" cache: true - uses: hashicorp/setup-terraform@633666f66e0061ca3b725c73b2ec20cd13a8fdd1 # v2.0.3 with: diff --git a/docs/data-sources/jiraassets_object_schema.md b/docs/data-sources/jiraassets_object_schema.md new file mode 100644 index 0000000..f985b30 --- /dev/null +++ b/docs/data-sources/jiraassets_object_schema.md @@ -0,0 +1,32 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "jiraassets_object_schema Data Source - terraform-provider-jira-assets" +subcategory: "" +description: |- + +--- + +# jiraassets_object_schema (Data Source) + + + + + + +## Schema + +### Read-Only + +- `can_manage` (Boolean) +- `created` (String) +- `description` (String) +- `global_id` (String) +- `id` (String) The ID of this resource. +- `id_as_int` (Number) +- `name` (String) +- `object_count` (Number) +- `object_schema_key` (String) +- `object_type_count` (Number) +- `status` (String) +- `updated` (String) +- `workspace_id` (String) diff --git a/docs/data-sources/scaffolding_example.md b/docs/data-sources/scaffolding_example.md deleted file mode 100644 index 9c9de1e..0000000 --- a/docs/data-sources/scaffolding_example.md +++ /dev/null @@ -1,30 +0,0 @@ ---- -# generated by https://github.com/hashicorp/terraform-plugin-docs -page_title: "scaffolding_example Data Source - terraform-provider-scaffolding-framework" -subcategory: "" -description: |- - Example data source ---- - -# scaffolding_example (Data Source) - -Example data source - -## Example Usage - -```terraform -data "scaffolding_example" "example" { - configurable_attribute = "some-value" -} -``` - - -## Schema - -### Optional - -- `configurable_attribute` (String) Example configurable attribute - -### Read-Only - -- `id` (String) Example identifier diff --git a/docs/index.md b/docs/index.md index 8eecef4..3001c15 100644 --- a/docs/index.md +++ b/docs/index.md @@ -1,20 +1,22 @@ --- # generated by https://github.com/hashicorp/terraform-plugin-docs -page_title: "scaffolding-framework Provider" +page_title: "jira-assets Provider" subcategory: "" description: |- - + A Terraform provider for Jira Assets. --- -# scaffolding-framework Provider - +# jira-assets Provider +A Terraform provider for Jira Assets. ## Example Usage ```terraform -provider "scaffolding" { - # example configuration here +provider "jiraassets" { + workspace_id = "" + user = "" + password = "" } ``` @@ -23,4 +25,6 @@ provider "scaffolding" { ### Optional -- `endpoint` (String) Example provider attribute +- `password` (String, Sensitive) Personal access token for the admin or service account. +- `user` (String) Username of an admin or service account with access to the Jira API. +- `workspace_id` (String) Workspace Id of the Assets instance. diff --git a/docs/resources/jiraassets_object.md b/docs/resources/jiraassets_object.md new file mode 100644 index 0000000..c206d3d --- /dev/null +++ b/docs/resources/jiraassets_object.md @@ -0,0 +1,44 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "jiraassets_object Resource - terraform-provider-jira-assets" +subcategory: "" +description: |- + +--- + +# jiraassets_object (Resource) + + + + + + +## Schema + +### Required + +- `attributes` (Attributes Set) (see [below for nested schema](#nestedatt--attributes)) +- `type_id` (String) + +### Optional + +- `avatar_uuid` (String) +- `has_avatar` (Boolean) + +### Read-Only + +- `created` (String) +- `global_id` (String) +- `id` (String) The ID of this resource. +- `label` (String) +- `object_key` (String) +- `updated` (String) +- `workspace_id` (String) + + +### Nested Schema for `attributes` + +Required: + +- `attr_type_id` (String) +- `attr_value` (String) diff --git a/docs/resources/scaffolding_example.md b/docs/resources/scaffolding_example.md deleted file mode 100644 index 47e77ed..0000000 --- a/docs/resources/scaffolding_example.md +++ /dev/null @@ -1,31 +0,0 @@ ---- -# generated by https://github.com/hashicorp/terraform-plugin-docs -page_title: "scaffolding_example Resource - terraform-provider-scaffolding-framework" -subcategory: "" -description: |- - Example resource ---- - -# scaffolding_example (Resource) - -Example resource - -## Example Usage - -```terraform -resource "scaffolding_example" "example" { - configurable_attribute = "some-value" -} -``` - - -## Schema - -### Optional - -- `configurable_attribute` (String) Example configurable attribute -- `defaulted` (String) Example configurable attribute with default value - -### Read-Only - -- `id` (String) Example identifier diff --git a/examples/data-sources/object_schema/data-source.tf b/examples/data-sources/object_schema/data-source.tf new file mode 100644 index 0000000..4ddf1f5 --- /dev/null +++ b/examples/data-sources/object_schema/data-source.tf @@ -0,0 +1,4 @@ +data "object_schema" "example" { + object_type = "example" + object_id = "example" +} diff --git a/examples/data-sources/scaffolding_example/data-source.tf b/examples/data-sources/scaffolding_example/data-source.tf deleted file mode 100644 index a852489..0000000 --- a/examples/data-sources/scaffolding_example/data-source.tf +++ /dev/null @@ -1,3 +0,0 @@ -data "scaffolding_example" "example" { - configurable_attribute = "some-value" -} diff --git a/examples/provider/provider.tf b/examples/provider/provider.tf index 942db45..f167628 100644 --- a/examples/provider/provider.tf +++ b/examples/provider/provider.tf @@ -1,3 +1,5 @@ -provider "scaffolding" { - # example configuration here +provider "jiraassets" { + workspace_id = "" + user = "" + password = "" } diff --git a/examples/resources/object/resource.tf b/examples/resources/object/resource.tf new file mode 100644 index 0000000..c0e0ab9 --- /dev/null +++ b/examples/resources/object/resource.tf @@ -0,0 +1,10 @@ +resource "jiraassets_object" "example_object_1" { + object_type = "example" + object_id = "example" + attributes = [ + { + attr_type_id = "" + attr_value = "" + } + ] +} diff --git a/examples/resources/scaffolding_example/resource.tf b/examples/resources/scaffolding_example/resource.tf deleted file mode 100644 index 9ae3f57..0000000 --- a/examples/resources/scaffolding_example/resource.tf +++ /dev/null @@ -1,3 +0,0 @@ -resource "scaffolding_example" "example" { - configurable_attribute = "some-value" -} diff --git a/internal/provider/example_data_source.go b/internal/provider/example_data_source.go deleted file mode 100644 index 585b9d2..0000000 --- a/internal/provider/example_data_source.go +++ /dev/null @@ -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 NewExampleDataSource() 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)...) -} diff --git a/internal/provider/example_data_source_test.go b/internal/provider/example_data_source_test.go deleted file mode 100644 index 6f9aa7d..0000000 --- a/internal/provider/example_data_source_test.go +++ /dev/null @@ -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.scaffolding_example.test", "id", "example-id"), - ), - }, - }, - }) -} - -const testAccExampleDataSourceConfig = ` -data "scaffolding_example" "test" { - configurable_attribute = "example" -} -` diff --git a/internal/provider/example_resource.go b/internal/provider/example_resource.go deleted file mode 100644 index 70e961a..0000000 --- a/internal/provider/example_resource.go +++ /dev/null @@ -1,187 +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/path" - "github.com/hashicorp/terraform-plugin-framework/resource" - "github.com/hashicorp/terraform-plugin-framework/resource/schema" - "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" - "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault" - "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" - "github.com/hashicorp/terraform-plugin-framework/types" - "github.com/hashicorp/terraform-plugin-log/tflog" -) - -// Ensure provider defined types fully satisfy framework interfaces. -var _ resource.Resource = &ExampleResource{} -var _ resource.ResourceWithImportState = &ExampleResource{} - -func NewExampleResource() resource.Resource { - return &ExampleResource{} -} - -// ExampleResource defines the resource implementation. -type ExampleResource struct { - client *http.Client -} - -// ExampleResourceModel describes the resource data model. -type ExampleResourceModel struct { - ConfigurableAttribute types.String `tfsdk:"configurable_attribute"` - Defaulted types.String `tfsdk:"defaulted"` - Id types.String `tfsdk:"id"` -} - -func (r *ExampleResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { - resp.TypeName = req.ProviderTypeName + "_example" -} - -func (r *ExampleResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { - resp.Schema = schema.Schema{ - // This description is used by the documentation generator and the language server. - MarkdownDescription: "Example resource", - - Attributes: map[string]schema.Attribute{ - "configurable_attribute": schema.StringAttribute{ - MarkdownDescription: "Example configurable attribute", - Optional: true, - }, - "defaulted": schema.StringAttribute{ - MarkdownDescription: "Example configurable attribute with default value", - Optional: true, - Computed: true, - Default: stringdefault.StaticString("example value when not configured"), - }, - "id": schema.StringAttribute{ - Computed: true, - MarkdownDescription: "Example identifier", - PlanModifiers: []planmodifier.String{ - stringplanmodifier.UseStateForUnknown(), - }, - }, - }, - } -} - -func (r *ExampleResource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.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 Resource Configure Type", - fmt.Sprintf("Expected *http.Client, got: %T. Please report this issue to the provider developers.", req.ProviderData), - ) - - return - } - - r.client = client -} - -func (r *ExampleResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { - var data ExampleResourceModel - - // Read Terraform plan data into the model - resp.Diagnostics.Append(req.Plan.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 := r.client.Do(httpReq) - // if err != nil { - // resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to create 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, "created a resource") - - // Save data into Terraform state - resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) -} - -func (r *ExampleResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { - var data ExampleResourceModel - - // Read Terraform prior state data into the model - resp.Diagnostics.Append(req.State.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 := r.client.Do(httpReq) - // if err != nil { - // resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to read example, got error: %s", err)) - // return - // } - - // Save updated data into Terraform state - resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) -} - -func (r *ExampleResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { - var data ExampleResourceModel - - // Read Terraform plan data into the model - resp.Diagnostics.Append(req.Plan.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 := r.client.Do(httpReq) - // if err != nil { - // resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to update example, got error: %s", err)) - // return - // } - - // Save updated data into Terraform state - resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) -} - -func (r *ExampleResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { - var data ExampleResourceModel - - // Read Terraform prior state data into the model - resp.Diagnostics.Append(req.State.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 := r.client.Do(httpReq) - // if err != nil { - // resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to delete example, got error: %s", err)) - // return - // } -} - -func (r *ExampleResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) -} diff --git a/internal/provider/example_resource_test.go b/internal/provider/example_resource_test.go deleted file mode 100644 index c5464d0..0000000 --- a/internal/provider/example_resource_test.go +++ /dev/null @@ -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("scaffolding_example.test", "configurable_attribute", "one"), - resource.TestCheckResourceAttr("scaffolding_example.test", "defaulted", "example value when not configured"), - resource.TestCheckResourceAttr("scaffolding_example.test", "id", "example-id"), - ), - }, - // ImportState testing - { - ResourceName: "scaffolding_example.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("scaffolding_example.test", "configurable_attribute", "two"), - ), - }, - // Delete testing automatically occurs in TestCase - }, - }) -} - -func testAccExampleResourceConfig(configurableAttribute string) string { - return fmt.Sprintf(` -resource "scaffolding_example" "test" { - configurable_attribute = %[1]q -} -`, configurableAttribute) -} diff --git a/internal/provider/object_resource.go b/internal/provider/object_resource.go index 6359494..7d06231 100644 --- a/internal/provider/object_resource.go +++ b/internal/provider/object_resource.go @@ -2,11 +2,11 @@ package provider import ( "context" + "fmt" "github.com/ctreminiom/go-atlassian/assets" "github.com/ctreminiom/go-atlassian/pkg/infra/models" - // "github.com/hashicorp/terraform-plugin-log/tflog" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" @@ -70,33 +70,39 @@ type objectAttrResourceModel struct { // Schema defines the schema for the resource. func (r *objectResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) { resp.Schema = schema.Schema{ + Description: "A Jira Assets object resource.", Attributes: map[string]schema.Attribute{ "workspace_id": schema.StringAttribute{ - Computed: true, + Computed: true, + Description: "The ID of the workspace the object belongs to.", PlanModifiers: []planmodifier.String{ stringplanmodifier.UseStateForUnknown(), }, }, "global_id": schema.StringAttribute{ - Computed: true, + Computed: true, + Description: "The global ID of the object.", PlanModifiers: []planmodifier.String{ stringplanmodifier.UseStateForUnknown(), }, }, "id": schema.StringAttribute{ - Computed: true, + Computed: true, + Description: "The ID of the object.", PlanModifiers: []planmodifier.String{ stringplanmodifier.UseStateForUnknown(), }, }, "label": schema.StringAttribute{ - Computed: true, + Computed: true, + Description: "The name of the object. This value is fetched from the attribute that is currently marked as label for the object type of this object", PlanModifiers: []planmodifier.String{ stringplanmodifier.UseStateForUnknown(), }, }, "object_key": schema.StringAttribute{ - Computed: true, + Computed: true, + Description: "The external identifier for this object", PlanModifiers: []planmodifier.String{ stringplanmodifier.UseStateForUnknown(), }, @@ -105,14 +111,17 @@ func (r *objectResource) Schema(_ context.Context, _ resource.SchemaRequest, res Required: true, }, "attributes": schema.SetNestedAttribute{ - Required: true, + Required: true, + Description: "The definition of the attribute that is associated with an object type", NestedObject: schema.NestedAttributeObject{ Attributes: map[string]schema.Attribute{ "attr_type_id": schema.StringAttribute{ - Required: true, + Description: "The type of the attribute. The type decides how this value should be interpreted", + Required: true, }, "attr_value": schema.StringAttribute{ - Required: true, + Description: "The actual values of the object attribute. The size of the values array is determined by the cardinality constraints on the object type attribute as well as how many values are associated with the object attribute", + Required: true, }, }, }, @@ -130,7 +139,8 @@ func (r *objectResource) Schema(_ context.Context, _ resource.SchemaRequest, res Optional: true, }, "avatar_uuid": schema.StringAttribute{ - Optional: true, + Optional: true, + Description: "The UUID as retrieved by uploading an avatar.", }, }, } @@ -392,7 +402,14 @@ func (r *objectResource) Configure(ctx context.Context, req resource.ConfigureRe return } - providerClient := req.ProviderData.(JiraAssetsProviderClient) + providerClient, ok := req.ProviderData.(JiraAssetsProviderClient) + if !ok { + resp.Diagnostics.AddError( + "Unexpected Data Source Configure Type", + fmt.Sprintf("Expected *hashicups.Client, got: %T. Please report this issue to the provider developers.", req.ProviderData), + ) + return + } r.client = providerClient.client r.workspace_id = providerClient.workspaceId diff --git a/internal/provider/object_resource_test.go b/internal/provider/object_resource_test.go new file mode 100644 index 0000000..def1de9 --- /dev/null +++ b/internal/provider/object_resource_test.go @@ -0,0 +1,30 @@ +package provider + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-testing/helper/resource" +) + +func TestAccJiraAssetsObjectResource(t *testing.T) { + resource.Test(t, resource.TestCase{ + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: `resource "jiraassets_object" "test" { + type_id = "" + attributes = [ + { + attr_type_id = "" + attr_value = "" + } + ] + }`, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("jiraassets_object.test", "id", "1"), + resource.TestCheckResourceAttr("jiraassets_object.test", "attribute", "1"), + ), + }, + }, + }) +} diff --git a/internal/provider/object_schema_datasource.go b/internal/provider/object_schema_datasource.go index 1c313f1..4b5bab9 100644 --- a/internal/provider/object_schema_datasource.go +++ b/internal/provider/object_schema_datasource.go @@ -2,6 +2,7 @@ package provider import ( "context" + "fmt" "github.com/ctreminiom/go-atlassian/assets" "github.com/hashicorp/terraform-plugin-framework/datasource" @@ -52,15 +53,16 @@ type objectSchemaDataSourceModel struct { func (d *objectSchemaDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) { resp.Schema = schema.Schema{ Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + Required: true, + Description: "The ID of the object schema.", + }, "workspace_id": schema.StringAttribute{ Computed: true, }, "global_id": schema.StringAttribute{ Computed: true, }, - "id": schema.StringAttribute{ - Required: true, - }, "name": schema.StringAttribute{ Computed: true, }, @@ -156,15 +158,14 @@ func (d *objectSchemaDataSource) Configure(ctx context.Context, req datasource.C return } - providerClient := req.ProviderData.(JiraAssetsProviderClient) - // client, ok := providerClient.client.(*assets.Client) - // if !ok { - // resp.Diagnostics.AddError( - // "Unexpected Data Source Configure Type", - // fmt.Sprintf("Expected *assets.Client, got %T", req.ProviderData), - // ) - // return - // } + providerClient, ok := req.ProviderData.(JiraAssetsProviderClient) + if !ok { + resp.Diagnostics.AddError( + "Unexpected Data Source Configure Type", + fmt.Sprintf("Expected *assets.Client, got %T", req.ProviderData), + ) + return + } d.client = providerClient.client d.workspace_id = providerClient.workspaceId diff --git a/internal/provider/provider.go b/internal/provider/provider.go index 993def0..bf32deb 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -45,7 +45,7 @@ type JiraAssetsProviderModel struct { Password types.String `tfsdk:"password"` } -// struct describes client and worksapceId +// JiraAssetsProviderClient describes client and worksapceId. type JiraAssetsProviderClient struct { client *assets.Client workspaceId string @@ -58,9 +58,10 @@ func (p *JiraAssetsProvider) Metadata(ctx context.Context, req provider.Metadata func (p *JiraAssetsProvider) Schema(ctx context.Context, req provider.SchemaRequest, resp *provider.SchemaResponse) { resp.Schema = schema.Schema{ + MarkdownDescription: "A Terraform provider for Jira Assets.", Attributes: map[string]schema.Attribute{ "workspace_id": schema.StringAttribute{ - MarkdownDescription: "Workspace Id of the Asssets instance.", + MarkdownDescription: "Workspace Id of the Assets instance.", Optional: true, }, "user": schema.StringAttribute{ @@ -187,7 +188,7 @@ func (p *JiraAssetsProvider) Configure(ctx context.Context, req provider.Configu if err != nil { resp.Diagnostics.AddError( "Unable to create Assets client", - "An unexpected error occured wehn creating the Assets API client. Error: "+err.Error(), + "An unexpected error occurred when creating the Assets API client. Error: "+err.Error(), ) } diff --git a/internal/provider/provider_test.go b/internal/provider/provider_test.go index ef6599b..7292659 100644 --- a/internal/provider/provider_test.go +++ b/internal/provider/provider_test.go @@ -4,8 +4,6 @@ package provider import ( - "testing" - "github.com/hashicorp/terraform-plugin-framework/providerserver" "github.com/hashicorp/terraform-plugin-go/tfprotov6" ) @@ -15,11 +13,5 @@ import ( // 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. + "jiraassets": providerserver.NewProtocol6WithError(New("test")()), }