Skip to content

Commit e906218

Browse files
Add list services (#391)
1 parent c235176 commit e906218

23 files changed

+1104
-6
lines changed

CHANGELOG.md

+8-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,15 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8-
## [Unreleased](https://github.com/fivetran/terraform-provider-fivetran/compare/v1.4.2...HEAD)
8+
## [Unreleased](https://github.com/fivetran/terraform-provider-fivetran/compare/v1.5.0...HEAD)
99

10-
## [1.4.1](https://github.com/fivetran/terraform-provider-fivetran/compare/v1.4.1...v1.4.2)
10+
## [1.5.0](https://github.com/fivetran/terraform-provider-fivetran/compare/v1.4.2...v1.5.0)
11+
12+
- New data source `fivetran_connectors` that allows to retrieve the list of existing Connections available for the current account.
13+
- New data source `fivetran_destinations` that allows to retrieve the list of existing Destinations available for the current account.
14+
- New data source `fivetran_external_logs` that allows to retrieve the list of existing External Logging Services available for the current account.
15+
16+
## [1.4.2](https://github.com/fivetran/terraform-provider-fivetran/compare/v1.4.1...v1.4.2)
1117

1218
## Added
1319
- Add `is_primary_key` to connector schema config

docs/data-sources/connectors.md

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
---
2+
page_title: "Data Source: fivetran_connectors"
3+
---
4+
5+
# Data Source: fivetran_connectors
6+
7+
This data source returns list of connector objects.
8+
9+
## Example Usage
10+
11+
```hcl
12+
data "fivetran_connectors" "connector" {
13+
id = "anonymous_mystery"
14+
}
15+
```
16+
17+
<!-- schema generated by tfplugindocs -->
18+
## Schema
19+
20+
### Read-Only
21+
22+
- `connectors` (Block Set) (see [below for nested schema](#nestedblock--connectors))
23+
- `id` (String) The ID of this resource.
24+
25+
<a id="nestedblock--connectors"></a>
26+
### Nested Schema for `connectors`
27+
28+
Read-Only:
29+
30+
- `connected_by` (String) The unique identifier of the user who has created the connector in your account.
31+
- `created_at` (String) The timestamp of the time the connector was created in your account.
32+
- `daily_sync_time` (String) The optional parameter that defines the sync start time when the sync frequency is already set or being set by the current request to 1440. It can be specified in one hour increments starting from 00:00 to 23:00. If not specified, we will use [the baseline sync start time](https://fivetran.com/docs/getting-started/syncoverview#syncfrequencyandscheduling). This parameter has no effect on the [0 to 60 minutes offset](https://fivetran.com/docs/getting-started/syncoverview#syncstarttimesandoffsets) used to determine the actual sync start time.
33+
- `data_delay_sensitivity` (String) The level of data delay notification threshold. Possible values: LOW, NORMAL, HIGH, CUSTOM. The default value NORMAL. CUSTOM is only available for customers using the Enterprise plan or above.
34+
- `data_delay_threshold` (Number) Custom sync delay notification threshold in minutes. The default value is 0. This parameter is only used when data_delay_sensitivity set to CUSTOM.
35+
- `failed_at` (String) The timestamp of the time the connector sync failed last time.
36+
- `group_id` (String) The unique identifier for the Group (Destination) within the Fivetran system.
37+
- `hybrid_deployment_agent_id` (String) The hybrid deployment agent ID that refers to the controller created for the group the connection belongs to. If the value is specified, the system will try to associate the connection with an existing agent.
38+
- `id` (String) The unique identifier for the connector within the Fivetran system.
39+
- `local_processing_agent_id` (String) (Deprecated) The hybrid deployment agent ID that refers to the controller created for the group the connection belongs to. If the value is specified, the system will try to associate the connection with an existing agent.
40+
- `name` (String) The name used both as the connector's name within the Fivetran system and as the source schema's name within your destination.
41+
- `networking_method` (String) Possible values: Directly, SshTunnel, ProxyAgent.
42+
- `pause_after_trial` (Boolean) Specifies whether the connector should be paused after the free trial period has ended.
43+
- `paused` (Boolean) Specifies whether the connector is paused.
44+
- `private_link_id` (String) The private link ID.
45+
- `proxy_agent_id` (String) The proxy agent ID.
46+
- `schedule_type` (String) The connector schedule configuration type. Supported values: auto, manual.
47+
- `service` (String) The connector type id within the Fivetran system.
48+
- `service_version` (String) The connector type version within the Fivetran system.
49+
- `succeeded_at` (String) The timestamp of the time the connector sync succeeded last time.
50+
- `sync_frequency` (Number) The connector sync frequency in minutes.

docs/data-sources/destinations.md

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
page_title: "Data Source: fivetran_destinations"
3+
---
4+
5+
# Data Source: fivetran_destinations
6+
7+
This data source returns list of destination objects.
8+
9+
## Example Usage
10+
11+
```hcl
12+
data "fivetran_destinations" "dest" {
13+
id = "anonymous_mystery"
14+
}
15+
```
16+
17+
<!-- schema generated by tfplugindocs -->
18+
## Schema
19+
20+
### Read-Only
21+
22+
- `destinations` (Block Set) (see [below for nested schema](#nestedblock--destinations))
23+
- `id` (String) The ID of this resource.
24+
25+
<a id="nestedblock--destinations"></a>
26+
### Nested Schema for `destinations`
27+
28+
Read-Only:
29+
30+
- `daylight_saving_time_enabled` (Boolean) Shift my UTC offset with daylight savings time (US Only)
31+
- `group_id` (String) The unique identifier for the Group within the Fivetran system.
32+
- `hybrid_deployment_agent_id` (String) The hybrid deployment agent ID that refers to the controller created for the group the connection belongs to. If the value is specified, the system will try to associate the connection with an existing agent.
33+
- `id` (String) The unique identifier for the destination within the Fivetran system.
34+
- `local_processing_agent_id` (String) (Deprecated) The hybrid deployment agent ID that refers to the controller created for the group the connection belongs to. If the value is specified, the system will try to associate the connection with an existing agent.
35+
- `networking_method` (String) Possible values: Directly, SshTunnel, ProxyAgent.
36+
- `private_link_id` (String) The private link ID.
37+
- `region` (String) Data processing location. This is where Fivetran will operate and run computation on data.
38+
- `service` (String) The destination type id within the Fivetran system.
39+
- `setup_status` (String) Destination setup status.
40+
- `time_zone_offset` (String) Determines the time zone for the Fivetran sync schedule.

docs/data-sources/external_logs.md

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
page_title: "Data Source: fivetran_external_logs"
3+
---
4+
5+
# Data Source: fivetran_external_logs
6+
7+
This data source returns list of logging service objects.
8+
9+
## Example Usage
10+
11+
```hcl
12+
data "fivetran_external_logs" "extlog" {
13+
id = "anonymous_mystery"
14+
}
15+
```
16+
17+
<!-- schema generated by tfplugindocs -->
18+
## Schema
19+
20+
### Read-Only
21+
22+
- `id` (String) The ID of this resource.
23+
- `logs` (Block Set) (see [below for nested schema](#nestedblock--logs))
24+
25+
<a id="nestedblock--logs"></a>
26+
### Nested Schema for `logs`
27+
28+
Read-Only:
29+
30+
- `enabled` (Boolean) The boolean value specifying whether the log service is enabled.
31+
- `id` (String) The unique identifier for the log service within the Fivetran system.
32+
- `service` (String) The name for the log service type within the Fivetran system. We support the following log services: azure_monitor_log, cloudwatch, datadog_log, new_relic_log, splunkLog, stackdriver.

fivetran/framework/core/core.go

+54
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,16 @@ func (s Schema) GetDatasourceSchema() map[string]datasourceSchema.Attribute {
105105
return result
106106
}
107107

108+
func (s Schema) GetDatasourceListSchema() map[string]datasourceSchema.Attribute {
109+
result := map[string]datasourceSchema.Attribute{}
110+
for k, v := range s.Fields {
111+
if !v.ResourceOnly {
112+
result[k] = v.getDatasourceSchemaAttributeForList()
113+
}
114+
}
115+
return result
116+
}
117+
108118
func (s Schema) GetResourceSchema() map[string]resourceSchema.Attribute {
109119
result := make(map[string]resourceSchema.Attribute)
110120
for k, v := range s.Fields {
@@ -165,6 +175,50 @@ func (s SchemaField) getDatasourceSchemaAttribute() datasourceSchema.Attribute {
165175
return result
166176
}
167177

178+
func (s SchemaField) getDatasourceSchemaAttributeForList() datasourceSchema.Attribute {
179+
var result datasourceSchema.Attribute
180+
switch s.ValueType {
181+
case StringEnum:
182+
result = datasourceSchema.StringAttribute{
183+
Computed: true,
184+
Sensitive: s.Sensitive,
185+
Description: s.Description,
186+
}
187+
case String:
188+
result = datasourceSchema.StringAttribute{
189+
Computed: true,
190+
Sensitive: s.Sensitive,
191+
Description: s.Description,
192+
}
193+
case Boolean:
194+
result = datasourceSchema.BoolAttribute{
195+
Computed: true,
196+
Description: s.Description,
197+
}
198+
case Integer:
199+
result = datasourceSchema.Int64Attribute{
200+
Computed: true,
201+
Description: s.Description,
202+
}
203+
case StringsList:
204+
result = datasourceSchema.ListAttribute{
205+
Computed: true,
206+
Sensitive: s.Sensitive,
207+
Description: s.Description,
208+
ElementType: basetypes.StringType{},
209+
}
210+
case StringsSet:
211+
result = datasourceSchema.SetAttribute{
212+
Computed: true,
213+
Sensitive: s.Sensitive,
214+
Description: s.Description,
215+
ElementType: basetypes.StringType{},
216+
}
217+
}
218+
219+
return result
220+
}
221+
168222
func (s SchemaField) getResourceSchemaAttribute() resourceSchema.Attribute {
169223
var result resourceSchema.Attribute
170224
switch s.ValueType {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package model
2+
3+
import (
4+
"context"
5+
"fmt"
6+
7+
"github.com/fivetran/go-fivetran/connectors"
8+
"github.com/hashicorp/terraform-plugin-framework/types"
9+
"github.com/hashicorp/terraform-plugin-framework/attr"
10+
)
11+
12+
type Connectors struct {
13+
Id types.String `tfsdk:"id"`
14+
Connectors types.Set `tfsdk:"connectors"`
15+
}
16+
17+
func (d *Connectors) ReadFromResponse(ctx context.Context, resp connectors.ConnectorsListResponse) {
18+
elementAttrType := map[string]attr.Type{
19+
"id": types.StringType,
20+
"name": types.StringType,
21+
"connected_by": types.StringType,
22+
"created_at": types.StringType,
23+
"group_id": types.StringType,
24+
"service": types.StringType,
25+
"succeeded_at": types.StringType,
26+
"failed_at": types.StringType,
27+
"service_version": types.StringType,
28+
"sync_frequency": types.Int64Type,
29+
"schedule_type": types.StringType,
30+
"paused": types.BoolType,
31+
"pause_after_trial": types.BoolType,
32+
"daily_sync_time": types.StringType,
33+
"data_delay_sensitivity": types.StringType,
34+
"data_delay_threshold": types.Int64Type,
35+
"proxy_agent_id": types.StringType,
36+
"networking_method": types.StringType,
37+
"local_processing_agent_id": types.StringType,
38+
"hybrid_deployment_agent_id": types.StringType,
39+
"private_link_id": types.StringType,
40+
}
41+
42+
if resp.Data.Items == nil {
43+
d.Connectors = types.SetNull(types.ObjectType{AttrTypes: elementAttrType})
44+
}
45+
46+
items := []attr.Value{}
47+
48+
for _, v := range resp.Data.Items {
49+
item := map[string]attr.Value{}
50+
item["id"] = types.StringValue(v.ID)
51+
item["name"] = types.StringValue(v.Schema)
52+
item["connected_by"] = types.StringValue(v.ConnectedBy)
53+
item["created_at"] = types.StringValue(v.CreatedAt.String())
54+
item["group_id"] = types.StringValue(v.GroupID)
55+
item["service"] = types.StringValue(v.Service)
56+
item["succeeded_at"] = types.StringValue(v.SucceededAt.String())
57+
item["failed_at"] = types.StringValue(v.FailedAt.String())
58+
item["service_version"] = types.StringValue(fmt.Sprintf("%v", *v.ServiceVersion))
59+
item["sync_frequency"] = types.Int64Value(int64(*v.SyncFrequency))
60+
item["schedule_type"] = types.StringValue(v.ScheduleType)
61+
item["paused"] = types.BoolValue(*v.Paused)
62+
item["pause_after_trial"] = types.BoolValue(*v.PauseAfterTrial)
63+
item["daily_sync_time"] = types.StringValue(v.DailySyncTime)
64+
item["data_delay_sensitivity"] = types.StringValue(v.DataDelaySensitivity)
65+
item["data_delay_threshold"] = types.Int64Value(int64(*v.DataDelayThreshold))
66+
item["proxy_agent_id"] = types.StringValue(v.ProxyAgentId)
67+
item["networking_method"] = types.StringValue(v.NetworkingMethod)
68+
item["local_processing_agent_id"] = types.StringValue(v.HybridDeploymentAgentId)
69+
item["hybrid_deployment_agent_id"] = types.StringValue(v.HybridDeploymentAgentId)
70+
item["private_link_id"] = types.StringValue(v.PrivateLinkId)
71+
72+
objectValue, _ := types.ObjectValue(elementAttrType, item)
73+
items = append(items, objectValue)
74+
}
75+
76+
d.Id = types.StringValue("0")
77+
d.Connectors, _ = types.SetValue(types.ObjectType{AttrTypes: elementAttrType}, items)
78+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package model
2+
3+
import (
4+
"context"
5+
6+
"github.com/fivetran/go-fivetran/destinations"
7+
"github.com/hashicorp/terraform-plugin-framework/types"
8+
"github.com/hashicorp/terraform-plugin-framework/attr"
9+
)
10+
11+
type Destinations struct {
12+
Id types.String `tfsdk:"id"`
13+
Destinations types.Set `tfsdk:"destinations"`
14+
}
15+
16+
func (d *Destinations) ReadFromResponse(ctx context.Context, resp destinations.DestinationsListResponse) {
17+
elementAttrType := map[string]attr.Type{
18+
"id": types.StringType,
19+
"group_id": types.StringType,
20+
"service": types.StringType,
21+
"region": types.StringType,
22+
"time_zone_offset": types.StringType,
23+
"setup_status": types.StringType,
24+
"networking_method": types.StringType,
25+
"local_processing_agent_id": types.StringType,
26+
"hybrid_deployment_agent_id": types.StringType,
27+
"private_link_id": types.StringType,
28+
"daylight_saving_time_enabled": types.BoolType,
29+
}
30+
31+
if resp.Data.Items == nil {
32+
d.Destinations = types.SetNull(types.ObjectType{AttrTypes: elementAttrType})
33+
}
34+
35+
items := []attr.Value{}
36+
37+
for _, v := range resp.Data.Items {
38+
item := map[string]attr.Value{}
39+
item["id"] = types.StringValue(v.ID)
40+
item["group_id"] = types.StringValue(v.GroupID)
41+
item["service"] = types.StringValue(v.Service)
42+
item["region"] = types.StringValue(v.Region)
43+
item["time_zone_offset"] = types.StringValue(v.TimeZoneOffset)
44+
item["setup_status"] = types.StringValue(v.SetupStatus)
45+
item["private_link_id"] = types.StringValue(v.PrivateLinkId)
46+
item["local_processing_agent_id"] = types.StringValue(v.HybridDeploymentAgentId)
47+
item["hybrid_deployment_agent_id"] = types.StringValue(v.HybridDeploymentAgentId)
48+
item["networking_method"] = types.StringValue(v.NetworkingMethod)
49+
item["daylight_saving_time_enabled"] = types.BoolValue(v.DaylightSavingTimeEnabled)
50+
51+
objectValue, _ := types.ObjectValue(elementAttrType, item)
52+
items = append(items, objectValue)
53+
}
54+
55+
d.Id = types.StringValue("0")
56+
d.Destinations, _ = types.SetValue(types.ObjectType{AttrTypes: elementAttrType}, items)
57+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package model
2+
3+
import (
4+
"context"
5+
6+
"github.com/fivetran/go-fivetran/external_logging"
7+
"github.com/hashicorp/terraform-plugin-framework/types"
8+
"github.com/hashicorp/terraform-plugin-framework/attr"
9+
)
10+
11+
type ExternalLogs struct {
12+
Id types.String `tfsdk:"id"`
13+
ExternalLogs types.Set `tfsdk:"logs"`
14+
}
15+
16+
func (d *ExternalLogs) ReadFromResponse(ctx context.Context, resp externallogging.ExternalLoggingListResponse) {
17+
elementAttrType := map[string]attr.Type{
18+
"id": types.StringType,
19+
"service": types.StringType,
20+
"enabled": types.BoolType,
21+
}
22+
23+
if resp.Data.Items == nil {
24+
d.ExternalLogs = types.SetNull(types.ObjectType{AttrTypes: elementAttrType})
25+
}
26+
27+
items := []attr.Value{}
28+
29+
for _, v := range resp.Data.Items {
30+
item := map[string]attr.Value{}
31+
item["id"] = types.StringValue(v.Id)
32+
item["service"] = types.StringValue(v.Service)
33+
item["enabled"] = types.BoolValue(v.Enabled)
34+
35+
objectValue, _ := types.ObjectValue(elementAttrType, item)
36+
items = append(items, objectValue)
37+
}
38+
39+
d.Id = types.StringValue("0")
40+
d.ExternalLogs, _ = types.SetValue(types.ObjectType{AttrTypes: elementAttrType}, items)
41+
}

0 commit comments

Comments
 (0)