diff --git a/examples/provider/provider.tf b/examples/provider/provider.tf index 767379d..80a9712 100644 --- a/examples/provider/provider.tf +++ b/examples/provider/provider.tf @@ -1,3 +1 @@ -provider "cala" { - endpoint = "http://localhost:2252" -} +provider "cala" {} diff --git a/examples/resources/cala_account/resource.tf b/examples/resources/cala_account/resource.tf index 38724f5..a35f0ae 100644 --- a/examples/resources/cala_account/resource.tf +++ b/examples/resources/cala_account/resource.tf @@ -1,7 +1,11 @@ resource "cala_account" "name" { - name = "name" - code = "slghsg" - account_id = "1ce41f76-1e86-4879-b326-0c4a8501ded3" + name = "name" + code = "slghsg" + id = "1ce41f76-1e86-4879-b326-0c4a8501ded3" +} + +provider "cala" { + endpoint = "http://localhost:2252" } terraform { diff --git a/provider/provider.go b/provider/provider.go index 9504d19..d490db0 100644 --- a/provider/provider.go +++ b/provider/provider.go @@ -42,7 +42,7 @@ func (p *CalaProvider) Schema(ctx context.Context, req provider.SchemaRequest, r Attributes: map[string]schema.Attribute{ "endpoint": schema.StringAttribute{ MarkdownDescription: "The endpoint for cala server.", - Optional: false, + Required: true, }, }, } diff --git a/provider/resource_account.go b/provider/resource_account.go index d8cee92..330f862 100644 --- a/provider/resource_account.go +++ b/provider/resource_account.go @@ -7,6 +7,7 @@ import ( "github.com/Khan/genqlient/graphql" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-log/tflog" ) @@ -26,6 +27,8 @@ type AccountResourceModel struct { AccountId types.String `tfsdk:"id"` Name types.String `tfsdk:"name"` Code types.String `tfsdk:"code"` + NormalBalanceType types.String `tfsdk:"normal_balance_type"` + Status types.String `tfsdk:"status"` } func (r *AccountResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { @@ -36,7 +39,7 @@ func (r *AccountResource) Schema(ctx context.Context, req resource.SchemaRequest resp.Schema = schema.Schema{ MarkdownDescription: "Cala account.", Attributes: map[string]schema.Attribute{ - "account_id": schema.StringAttribute{ + "id": schema.StringAttribute{ MarkdownDescription: "ID of the account.", Required: true, }, @@ -48,6 +51,16 @@ func (r *AccountResource) Schema(ctx context.Context, req resource.SchemaRequest MarkdownDescription: "code", Required: true, }, + "normal_balance_type": schema.StringAttribute{ + MarkdownDescription: "normalBalanceType", + Default: stringdefault.StaticString("CREDIT"), + Computed: true, + }, + "status": schema.StringAttribute{ + MarkdownDescription: "status", + Default: stringdefault.StaticString("ACTIVE"), + Computed: true, + }, }, } } @@ -85,6 +98,8 @@ func (r *AccountResource) Create(ctx context.Context, req resource.CreateRequest AccountId: data.AccountId.ValueString(), Name: data.Name.ValueString(), Code: data.Code.ValueString(), + NormalBalanceType: DebitOrCreditCredit, + Status: StatusActive, } response, err := accountCreate(ctx, *r.client, input)