Extend LogMe instance parameters (#438)
* Extend LogMe instance parameters * Update acc test * Add more field descriptions * Improve code and tests * Add more fields to acc test * Fix linter * Add float parameter
This commit is contained in:
parent
e553628b5e
commit
a08dbd8926
15 changed files with 868 additions and 200 deletions
|
|
@ -87,6 +87,22 @@ func (r *instanceDataSource) Schema(_ context.Context, _ datasource.SchemaReques
|
|||
"plan_id": "The selected plan ID.",
|
||||
}
|
||||
|
||||
parametersDescriptions := map[string]string{
|
||||
"sgw_acl": "Comma separated list of IP networks in CIDR notation which are allowed to access this instance.",
|
||||
"consumer_timeout": "The timeout in milliseconds for the consumer.",
|
||||
"enable_monitoring": "Enable monitoring.",
|
||||
"graphite": "Graphite server URL (host and port). If set, monitoring with Graphite will be enabled.",
|
||||
"max_disk_threshold": "The maximum disk threshold in MB. If the disk usage exceeds this threshold, the instance will be stopped.",
|
||||
"metrics_frequency": "The frequency in seconds at which metrics are emitted.",
|
||||
"metrics_prefix": "The prefix for the metrics. Could be useful when using Graphite monitoring to prefix the metrics with a certain value, like an API key",
|
||||
"monitoring_instance_id": "The monitoring instance ID.",
|
||||
"plugins": "List of plugins to install. Must be a supported plugin name.",
|
||||
"roles": "List of roles to assign to the instance.",
|
||||
"syslog": "List of syslog servers to send logs to.",
|
||||
"tls_ciphers": "List of TLS ciphers to use.",
|
||||
"tls_protocols": "TLS protocol to use.",
|
||||
}
|
||||
|
||||
resp.Schema = schema.Schema{
|
||||
Description: descriptions["main"],
|
||||
Attributes: map[string]schema.Attribute{
|
||||
|
|
@ -129,47 +145,60 @@ func (r *instanceDataSource) Schema(_ context.Context, _ datasource.SchemaReques
|
|||
"parameters": schema.SingleNestedAttribute{
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"sgw_acl": schema.StringAttribute{
|
||||
Computed: true,
|
||||
Description: parametersDescriptions["sgw_acl"],
|
||||
Computed: true,
|
||||
},
|
||||
"consumer_timeout": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
Description: parametersDescriptions["consumer_timeout"],
|
||||
Computed: true,
|
||||
},
|
||||
"enable_monitoring": schema.BoolAttribute{
|
||||
Computed: true,
|
||||
Description: parametersDescriptions["enable_monitoring"],
|
||||
Computed: true,
|
||||
},
|
||||
"graphite": schema.StringAttribute{
|
||||
Computed: true,
|
||||
Description: parametersDescriptions["graphite"],
|
||||
Computed: true,
|
||||
},
|
||||
"max_disk_threshold": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
Description: parametersDescriptions["max_disk_threshold"],
|
||||
Computed: true,
|
||||
},
|
||||
"metrics_frequency": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
Description: parametersDescriptions["metrics_frequency"],
|
||||
Computed: true,
|
||||
},
|
||||
"metrics_prefix": schema.StringAttribute{
|
||||
Computed: true,
|
||||
Description: parametersDescriptions["metrics_prefix"],
|
||||
Computed: true,
|
||||
},
|
||||
"monitoring_instance_id": schema.StringAttribute{
|
||||
Computed: true,
|
||||
Description: parametersDescriptions["monitoring_instance_id"],
|
||||
Computed: true,
|
||||
},
|
||||
"plugins": schema.ListAttribute{
|
||||
Description: parametersDescriptions["plugins"],
|
||||
ElementType: types.StringType,
|
||||
Computed: true,
|
||||
},
|
||||
"roles": schema.ListAttribute{
|
||||
Description: parametersDescriptions["roles"],
|
||||
ElementType: types.StringType,
|
||||
Computed: true,
|
||||
},
|
||||
"syslog": schema.ListAttribute{
|
||||
Description: parametersDescriptions["syslog"],
|
||||
ElementType: types.StringType,
|
||||
Computed: true,
|
||||
},
|
||||
"tls_ciphers": schema.ListAttribute{
|
||||
Description: parametersDescriptions["tls_ciphers"],
|
||||
ElementType: types.StringType,
|
||||
Computed: true,
|
||||
},
|
||||
"tls_protocols": schema.StringAttribute{
|
||||
Computed: true,
|
||||
Description: parametersDescriptions["tls_protocols"],
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
Computed: true,
|
||||
|
|
|
|||
|
|
@ -340,7 +340,7 @@ func (r *instanceResource) Create(ctx context.Context, req resource.CreateReques
|
|||
projectId := model.ProjectId.ValueString()
|
||||
ctx = tflog.SetField(ctx, "project_id", projectId)
|
||||
|
||||
var parameters = ¶metersModel{}
|
||||
var parameters *parametersModel
|
||||
if !(model.Parameters.IsNull() || model.Parameters.IsUnknown()) {
|
||||
diags = model.Parameters.As(ctx, parameters, basetypes.ObjectAsOptions{})
|
||||
resp.Diagnostics.Append(diags...)
|
||||
|
|
@ -451,8 +451,9 @@ func (r *instanceResource) Update(ctx context.Context, req resource.UpdateReques
|
|||
ctx = tflog.SetField(ctx, "project_id", projectId)
|
||||
ctx = tflog.SetField(ctx, "instance_id", instanceId)
|
||||
|
||||
var parameters = ¶metersModel{}
|
||||
var parameters *parametersModel
|
||||
if !(model.Parameters.IsNull() || model.Parameters.IsUnknown()) {
|
||||
parameters = ¶metersModel{}
|
||||
diags = model.Parameters.As(ctx, parameters, basetypes.ObjectAsOptions{})
|
||||
resp.Diagnostics.Append(diags...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
|
|
|
|||
|
|
@ -190,9 +190,7 @@ func TestToCreatePayload(t *testing.T) {
|
|||
{
|
||||
"default_values",
|
||||
&Model{},
|
||||
&rabbitmq.CreateInstancePayload{
|
||||
Parameters: &rabbitmq.InstanceParameters{},
|
||||
},
|
||||
&rabbitmq.CreateInstancePayload{},
|
||||
true,
|
||||
},
|
||||
{
|
||||
|
|
@ -238,16 +236,16 @@ func TestToCreatePayload(t *testing.T) {
|
|||
&rabbitmq.CreateInstancePayload{
|
||||
InstanceName: utils.Ptr("name"),
|
||||
PlanId: utils.Ptr("plan"),
|
||||
Parameters: &rabbitmq.InstanceParameters{},
|
||||
},
|
||||
true,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.description, func(t *testing.T) {
|
||||
var parameters = ¶metersModel{}
|
||||
var parameters *parametersModel
|
||||
if tt.input != nil {
|
||||
if !(tt.input.Parameters.IsNull() || tt.input.Parameters.IsUnknown()) {
|
||||
parameters = ¶metersModel{}
|
||||
diags := tt.input.Parameters.As(context.Background(), parameters, basetypes.ObjectAsOptions{})
|
||||
if diags.HasError() {
|
||||
t.Fatalf("Error converting parameters: %v", diags.Errors())
|
||||
|
|
@ -281,9 +279,7 @@ func TestToUpdatePayload(t *testing.T) {
|
|||
{
|
||||
"default_values",
|
||||
&Model{},
|
||||
&rabbitmq.PartialUpdateInstancePayload{
|
||||
Parameters: &rabbitmq.InstanceParameters{},
|
||||
},
|
||||
&rabbitmq.PartialUpdateInstancePayload{},
|
||||
true,
|
||||
},
|
||||
{
|
||||
|
|
@ -323,17 +319,17 @@ func TestToUpdatePayload(t *testing.T) {
|
|||
PlanId: types.StringValue("plan"),
|
||||
},
|
||||
&rabbitmq.PartialUpdateInstancePayload{
|
||||
PlanId: utils.Ptr("plan"),
|
||||
Parameters: &rabbitmq.InstanceParameters{},
|
||||
PlanId: utils.Ptr("plan"),
|
||||
},
|
||||
true,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.description, func(t *testing.T) {
|
||||
var parameters = ¶metersModel{}
|
||||
var parameters *parametersModel
|
||||
if tt.input != nil {
|
||||
if !(tt.input.Parameters.IsNull() || tt.input.Parameters.IsUnknown()) {
|
||||
parameters = ¶metersModel{}
|
||||
diags := tt.input.Parameters.As(context.Background(), parameters, basetypes.ObjectAsOptions{})
|
||||
if diags.HasError() {
|
||||
t.Fatalf("Error converting parameters: %v", diags.Errors())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue