Skip to content

Commit

Permalink
Instance data read
Browse files Browse the repository at this point in the history
  • Loading branch information
krystian-panek-vmltech committed Oct 17, 2023
1 parent e59dc34 commit f2724df
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 4 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,11 @@ make testacc

Run command: `sh develop.sh <example_path> <tf_args>`.

For example: `sh develop.sh examples/ssh plan`.
For example:

- `sh develop.sh examples/ssh plan`
- `sh develop.sh examples/ssh apply -auto-approve`
- `sh develop.sh examples/ssh destroy -auto-approve`

## Debugging the Provider

Expand Down
55 changes: 52 additions & 3 deletions internal/provider/instance_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,10 @@ func NewInstanceResource() resource.Resource {
return &InstanceResource{}
}

// InstanceResource defines the resource implementation.

type InstanceResource struct {
clientManager *client.ClientManager
}

// InstanceResourceModel describes the resource data model.
type InstanceResourceModel struct {
Client struct {
Type types.String `tfsdk:"type"`
Expand All @@ -45,6 +42,19 @@ type InstanceResourceModel struct {
LibDir types.String `tfsdk:"lib_dir"`
InstanceId types.String `tfsdk:"instance_id"`
} `tfsdk:"compose"`
Data InstanceResourceDataModel `tfsdk:"data"`
}

type InstanceResourceDataModel struct {
Instances []struct {
ID types.String `yaml:"id" tfsdk:"id"`
URL types.String `yaml:"url" tfsdk:"url"`
AemVersion types.String `yaml:"aem_version" tfsdk:"aem_version"`
Attributes []types.String `yaml:"attributes" tfsdk:"attributes"`
RunModes []types.String `yaml:"run_modes" tfsdk:"run_modes"`
HealthChecks []types.String `yaml:"health_checks" tfsdk:"health_checks"`
Dir types.String `yaml:"dir" tfsdk:"dir"`
} `json:"instances" tfsdk:"instances"`
}

func (r *InstanceResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) {
Expand Down Expand Up @@ -96,6 +106,41 @@ func (r *InstanceResource) Schema(ctx context.Context, req resource.SchemaReques
},
},
},
"data": schema.SingleNestedBlock{
Attributes: map[string]schema.Attribute{
"instances": schema.ListNestedAttribute{
Computed: true,
NestedObject: schema.NestedAttributeObject{
Attributes: map[string]schema.Attribute{
"id": schema.StringAttribute{
Computed: true,
},
"url": schema.StringAttribute{
Computed: true,
},
"aem_version": schema.StringAttribute{
Computed: true,
},
"attributes": schema.ListAttribute{
ElementType: types.StringType,
Computed: true,
},
"run_modes": schema.ListAttribute{
ElementType: types.StringType,
Computed: true,
},
"health_checks": schema.ListAttribute{
ElementType: types.StringType,
Computed: true,
},
"dir": schema.StringAttribute{
Computed: true,
},
},
},
},
},
},
},
}
}
Expand Down Expand Up @@ -191,6 +236,10 @@ func (r *InstanceResource) Create(ctx context.Context, req resource.CreateReques
// Documentation: https://terraform.io/plugin/log
tflog.Info(ctx, "Created AEM instance resource")

var dataRead InstanceResourceDataModel
// TODO request data from command 'sh aemw instance status --output-format yaml'
data.Data = dataRead

// Save data into Terraform state
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
}
Expand Down

0 comments on commit f2724df

Please sign in to comment.