-
Notifications
You must be signed in to change notification settings - Fork 149
Expand file tree
/
Copy pathresource.go
More file actions
67 lines (55 loc) · 2.2 KB
/
Copy pathresource.go
File metadata and controls
67 lines (55 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package monitor
import (
"context"
"github.com/elastic/terraform-provider-elasticstack/internal/clients"
"github.com/elastic/terraform-provider-elasticstack/internal/kibana/synthetics"
"github.com/hashicorp/terraform-plugin-framework-validators/resourcevalidator"
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource"
)
const resourceName = synthetics.MetadataPrefix + "monitor"
// NewResource creates a new synthetics monitor resource
func NewResource() resource.Resource {
return &Resource{}
}
// Ensure provider defined types fully satisfy framework interfaces
var _ resource.Resource = &Resource{}
var _ resource.ResourceWithConfigure = &Resource{}
var _ resource.ResourceWithImportState = &Resource{}
var _ resource.ResourceWithConfigValidators = &Resource{}
var _ synthetics.ESApiClient = &Resource{}
// Resource represents a synthetics monitor resource
type Resource struct {
client *clients.ApiClient
}
func (r *Resource) GetClient() *clients.ApiClient {
return r.client
}
func (r *Resource) ConfigValidators(ctx context.Context) []resource.ConfigValidator {
return []resource.ConfigValidator{
resourcevalidator.ExactlyOneOf(
path.MatchRoot("http"),
path.MatchRoot("tcp"),
path.MatchRoot("icmp"),
path.MatchRoot("browser"),
),
resourcevalidator.AtLeastOneOf(
path.MatchRoot("locations"),
path.MatchRoot("private_locations"),
),
}
}
func (r *Resource) ImportState(ctx context.Context, request resource.ImportStateRequest, response *resource.ImportStateResponse) {
resource.ImportStatePassthroughID(ctx, path.Root("id"), request, response)
}
func (r *Resource) Configure(ctx context.Context, request resource.ConfigureRequest, response *resource.ConfigureResponse) {
client, diags := clients.ConvertProviderData(request.ProviderData)
response.Diagnostics.Append(diags...)
r.client = client
}
func (r *Resource) Metadata(ctx context.Context, request resource.MetadataRequest, response *resource.MetadataResponse) {
response.TypeName = request.ProviderTypeName + resourceName
}
func (r *Resource) Schema(ctx context.Context, request resource.SchemaRequest, response *resource.SchemaResponse) {
response.Schema = monitorConfigSchema()
}