Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into feature/add-support…
Browse files Browse the repository at this point in the history
…-for-filtering-twingate_groups-datasource
  • Loading branch information
vmanilo committed Feb 20, 2024
2 parents 77b90a0 + 4e98b1f commit 42fd409
Show file tree
Hide file tree
Showing 33 changed files with 1,087 additions and 104 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ on:
branches:
- main


# Ensures only 1 action runs per PR and previous is canceled on new trigger
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
Expand Down
17 changes: 15 additions & 2 deletions docs/data-sources/connectors.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,31 @@ Connectors provide connectivity to Remote Networks. For more information, see Tw
## Example Usage

```terraform
data "twingate_connectors" "all" {}
data "twingate_connectors" "all" {
name = "<your connector's name>"
# name_regexp = "<regular expression of connector name>"
# name_contains = "<a string in the connector name>"
# name_exclude = "<your connector's name to exclude>"
# name_prefix = "<prefix of connector name>"
# name_suffix = "<suffix of connector name>"
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Optional

- `connectors` (Attributes List) List of Connectors (see [below for nested schema](#nestedatt--connectors))
- `name` (String) Returns only connectors that exactly match this name. If no options are passed it will return all connectors. Only one option can be used at a time.
- `name_contains` (String) Match when the value exist in the name of the connector.
- `name_exclude` (String) Match when the value does not exist in the name of the connector.
- `name_prefix` (String) The name of the connector must start with the value.
- `name_regexp` (String) The regular expression match of the name of the connector.
- `name_suffix` (String) The name of the connector must end with the value.

### Read-Only

- `connectors` (Attributes List) List of Connectors (see [below for nested schema](#nestedatt--connectors))
- `id` (String) The ID of this resource.

<a id="nestedatt--connectors"></a>
Expand Down
23 changes: 21 additions & 2 deletions docs/data-sources/remote_networks.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,28 @@ A Remote Network represents a single private network in Twingate that can have o
## Example Usage

```terraform
data "twingate_remote_networks" "all" {}
data "twingate_remote_networks" "all" {
name = "<your network's name>"
# name_regexp = "<regular expression of network name>"
# name_contains = "<a string in the network name>"
# name_exclude = "<your network's name to exclude>"
# name_prefix = "<prefix of network name>"
# name_suffix = "<suffix of network name>"
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Optional

- `name` (String) Returns only remote networks that exactly match this name. If no options are passed it will return all remote networks. Only one option can be used at a time.
- `name_contains` (String) Match when the value exist in the name of the remote network.
- `name_exclude` (String) Match when the value does not exist in the name of the remote network.
- `name_prefix` (String) The name of the remote network must start with the value.
- `name_regexp` (String) The regular expression match of the name of the remote network.
- `name_suffix` (String) The name of the remote network must end with the value.

### Read-Only

- `id` (String) The ID of this resource.
Expand All @@ -27,8 +43,11 @@ data "twingate_remote_networks" "all" {}
<a id="nestedatt--remote_networks"></a>
### Nested Schema for `remote_networks`

Optional:

- `name` (String) The name of the Remote Network.

Read-Only:

- `id` (String) The ID of the Remote Network.
- `location` (String) The location of the Remote Network. Must be one of the following: AWS, AZURE, GOOGLE_CLOUD, ON_PREMISE, OTHER.
- `name` (String) The name of the Remote Network
17 changes: 15 additions & 2 deletions docs/data-sources/security_policies.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,32 @@ Security Policies are defined in the Twingate Admin Console and determine user a
## Example Usage

```terraform
data "twingate_security_policies" "all" {}
data "twingate_security_policies" "all" {
name = "<your security policy's name>"
# name_regexp = "<regular expression of security policy name>"
# name_contains = "<a string in the security policy name>"
# name_exclude = "<your security policy's name to exclude>"
# name_prefix = "<prefix of security policy name>"
# name_suffix = "<suffix of security policy name>"
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Optional

- `security_policies` (Attributes List) (see [below for nested schema](#nestedatt--security_policies))
- `name` (String) Returns only security policies that exactly match this name. If no options are passed it will return all security policies. Only one option can be used at a time.
- `name_contains` (String) Match when the value exist in the name of the security policy.
- `name_exclude` (String) Match when the value does not exist in the name of the security policy.
- `name_prefix` (String) The name of the security policy must start with the value.
- `name_regexp` (String) The regular expression match of the name of the security policy.
- `name_suffix` (String) The name of the security policy must end with the value.

### Read-Only

- `id` (String) The ID of this resource.
- `security_policies` (Attributes List) (see [below for nested schema](#nestedatt--security_policies))

<a id="nestedatt--security_policies"></a>
### Nested Schema for `security_policies`
Expand Down
12 changes: 11 additions & 1 deletion docs/data-sources/service_accounts.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ Service Accounts offer a way to provide programmatic, centrally-controlled, and
```terraform
data "twingate_service_accounts" "foo" {
name = "<your service account's name>"
# name_regexp = "<regular expression of service account name>"
# name_contains = "<a string in the service account name>"
# name_exclude = "<your service account's name to exclude>"
# name_prefix = "<prefix of service account name>"
# name_suffix = "<suffix of service account name>"
}
```

Expand All @@ -23,7 +28,12 @@ data "twingate_service_accounts" "foo" {

### Optional

- `name` (String) Filter results by the name of the Service Account.
- `name` (String) Returns only service accounts that exactly match this name. If no options are passed it will return all service accounts. Only one option can be used at a time.
- `name_contains` (String) Match when the value exist in the name of the service account.
- `name_exclude` (String) Match when the value does not exist in the name of the service account.
- `name_prefix` (String) The name of the service account must start with the value.
- `name_regexp` (String) The regular expression match of the name of the service account.
- `name_suffix` (String) The name of the service account must end with the value.

### Read-Only

Expand Down
9 changes: 8 additions & 1 deletion examples/data-sources/twingate_connectors/data-source.tf
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
data "twingate_connectors" "all" {}
data "twingate_connectors" "all" {
name = "<your connector's name>"
# name_regexp = "<regular expression of connector name>"
# name_contains = "<a string in the connector name>"
# name_exclude = "<your connector's name to exclude>"
# name_prefix = "<prefix of connector name>"
# name_suffix = "<suffix of connector name>"
}
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
data "twingate_remote_networks" "all" {}
data "twingate_remote_networks" "all" {
name = "<your network's name>"
# name_regexp = "<regular expression of network name>"
# name_contains = "<a string in the network name>"
# name_exclude = "<your network's name to exclude>"
# name_prefix = "<prefix of network name>"
# name_suffix = "<suffix of network name>"
}
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
data "twingate_security_policies" "all" {}
data "twingate_security_policies" "all" {
name = "<your security policy's name>"
# name_regexp = "<regular expression of security policy name>"
# name_contains = "<a string in the security policy name>"
# name_exclude = "<your security policy's name to exclude>"
# name_prefix = "<prefix of security policy name>"
# name_suffix = "<suffix of security policy name>"
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
data "twingate_service_accounts" "foo" {
name = "<your service account's name>"
# name_regexp = "<regular expression of service account name>"
# name_contains = "<a string in the service account name>"
# name_exclude = "<your service account's name to exclude>"
# name_prefix = "<prefix of service account name>"
# name_suffix = "<suffix of service account name>"
}
3 changes: 2 additions & 1 deletion twingate/internal/client/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,11 @@ func (client *Client) ReadConnector(ctx context.Context, connectorID string) (*m
return response.ToModel(), nil
}

func (client *Client) ReadConnectors(ctx context.Context) ([]*model.Connector, error) {
func (client *Client) ReadConnectors(ctx context.Context, name, filter string) ([]*model.Connector, error) {
opr := resourceConnector.read()

variables := newVars(
gqlNullable(query.NewConnectorFilterInput(name, filter), "filter"),
cursor(query.CursorConnectors),
pageLimit(client.pageLimit),
)
Expand Down
12 changes: 11 additions & 1 deletion twingate/internal/client/query/connectors-read.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
const CursorConnectors = "connectorsEndCursor"

type ReadConnectors struct {
Connectors `graphql:"connectors(after: $connectorsEndCursor, first: $pageLimit)"`
Connectors `graphql:"connectors(filter: $filter, after: $connectorsEndCursor, first: $pageLimit)"`
}

type Connectors struct {
Expand Down Expand Up @@ -36,3 +36,13 @@ func (c Connectors) ToModel() []*model.Connector {
return edge.Node.ToModel()
})
}

type ConnectorFilterInput struct {
Name *StringFilterOperationInput `json:"name"`
}

func NewConnectorFilterInput(name, filter string) *ConnectorFilterInput {
return &ConnectorFilterInput{
Name: NewStringFilterOperationInput(name, filter),
}
}
12 changes: 11 additions & 1 deletion twingate/internal/client/query/remote-networks-read.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
const CursorRemoteNetworks = "remoteNetworksEndCursor"

type ReadRemoteNetworks struct {
RemoteNetworks `graphql:"remoteNetworks(after: $remoteNetworksEndCursor, first: $pageLimit)"`
RemoteNetworks `graphql:"remoteNetworks(filter: $filter, after: $remoteNetworksEndCursor, first: $pageLimit)"`
}

func (q ReadRemoteNetworks) IsEmpty() bool {
Expand All @@ -28,3 +28,13 @@ func (r RemoteNetworks) ToModel() []*model.RemoteNetwork {
return edge.Node.ToModel()
})
}

type RemoteNetworkFilterInput struct {
Name *StringFilterOperationInput `json:"name"`
}

func NewRemoteNetworkFilterInput(name, filter string) *RemoteNetworkFilterInput {
return &RemoteNetworkFilterInput{
Name: NewStringFilterOperationInput(name, filter),
}
}
12 changes: 11 additions & 1 deletion twingate/internal/client/query/security-policies-read.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
const CursorPolicies = "policiesEndCursor"

type ReadSecurityPolicies struct {
SecurityPolicies `graphql:"securityPolicies(after: $policiesEndCursor, first: $pageLimit)"`
SecurityPolicies `graphql:"securityPolicies(filter: $filter, after: $policiesEndCursor, first: $pageLimit)"`
}

func (q ReadSecurityPolicies) IsEmpty() bool {
Expand All @@ -29,3 +29,13 @@ func (q ReadSecurityPolicies) ToModel() []*model.SecurityPolicy {
return edge.Node.ToModel()
})
}

type SecurityPolicyFilterField struct {
Name *StringFilterOperationInput `json:"name"`
}

func NewSecurityPolicyFilterField(name, filter string) *SecurityPolicyFilterField {
return &SecurityPolicyFilterField{
Name: NewStringFilterOperationInput(name, filter),
}
}
12 changes: 3 additions & 9 deletions twingate/internal/client/query/service-accounts-read.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,21 +99,15 @@ func IsGqlKeyActive(item *GqlKeyIDEdge) bool {
}

type ServiceAccountFilterInput struct {
Name StringFilter `json:"name"`
Name *StringFilterOperationInput `json:"name"`
}

type StringFilter struct {
Eq string `json:"eq"`
}

func NewServiceAccountFilterInput(name string) *ServiceAccountFilterInput {
func NewServiceAccountFilterInput(name, filter string) *ServiceAccountFilterInput {
if name == "" {
return nil
}

return &ServiceAccountFilterInput{
Name: StringFilter{
Eq: name,
},
Name: NewStringFilterOperationInput(name, filter),
}
}
3 changes: 2 additions & 1 deletion twingate/internal/client/remote-network.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ func (client *Client) CreateRemoteNetwork(ctx context.Context, req *model.Remote
return response.ToModel(), nil
}

func (client *Client) ReadRemoteNetworks(ctx context.Context) ([]*model.RemoteNetwork, error) {
func (client *Client) ReadRemoteNetworks(ctx context.Context, name, filter string) ([]*model.RemoteNetwork, error) {
opr := resourceRemoteNetwork.read()

variables := newVars(
gqlNullable(query.NewRemoteNetworkFilterInput(name, filter), "filter"),
cursor(query.CursorRemoteNetworks),
pageLimit(client.pageLimit),
)
Expand Down
3 changes: 2 additions & 1 deletion twingate/internal/client/security-policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ func (client *Client) ReadSecurityPolicy(ctx context.Context, securityPolicyID,
return response.ToModel(), nil
}

func (client *Client) ReadSecurityPolicies(ctx context.Context) ([]*model.SecurityPolicy, error) {
func (client *Client) ReadSecurityPolicies(ctx context.Context, name, filter string) ([]*model.SecurityPolicy, error) {
opr := resourceSecurityPolicy.read()

variables := newVars(
gqlNullable(query.NewSecurityPolicyFilterField(name, filter), "filter"),
cursor(query.CursorPolicies),
pageLimit(client.pageLimit),
)
Expand Down
8 changes: 6 additions & 2 deletions twingate/internal/client/service-account.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,17 @@ func (client *Client) readServiceAccountsAfter(ctx context.Context, variables ma
func (client *Client) ReadServiceAccounts(ctx context.Context, input ...string) ([]*model.ServiceAccount, error) {
opr := resourceServiceAccount.read()

var name string
var name, filter string
if len(input) > 0 {
name = input[0]
}

if len(input) > 1 {
filter = input[1]
}

variables := newVars(
gqlNullable(query.NewServiceAccountFilterInput(name), "filter"),
gqlNullable(query.NewServiceAccountFilterInput(name, filter), "filter"),
cursor(query.CursorServices),
cursor(query.CursorResources),
cursor(query.CursorServiceKeys),
Expand Down
Loading

0 comments on commit 42fd409

Please sign in to comment.