Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add network rules #2746

Merged
merged 19 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
f9d3da5
feat: added network rules (WIP)
AS-auxmoney Apr 19, 2024
cf1b306
fix: added change comment possibility
AS-auxmoney Apr 20, 2024
87915ef
fix: adding checks between attributes (WIP)
AS-auxmoney Apr 22, 2024
ad82a5b
fix: adding checks between attributes (WIP)
AS-auxmoney Apr 25, 2024
0432b10
fix: implemented correct addition and removal of network rules from n…
AS-auxmoney Apr 25, 2024
642265f
fix: added unsetting of ip_lists
AS-auxmoney May 7, 2024
6445890
chore: removed comments
AS-auxmoney May 8, 2024
8e46b1d
fix: added network rule list validate function
AS-auxmoney May 14, 2024
15fadc2
test: added acceptance tests for network rules and expanded tests for…
AS-auxmoney May 15, 2024
9e6c412
docs: added docs for network rule and expanded docs for network policy
AS-auxmoney May 15, 2024
50e1264
docs: added docs for network rule and expanded docs for network policy
AS-auxmoney May 16, 2024
ada0ac5
refactor: update network policy
AS-auxmoney May 16, 2024
3fa3b75
test: refactored fixtures for network policy acceptance test
AS-auxmoney May 16, 2024
176c5ed
fix: added drop if exists options and read checks
AS-auxmoney May 16, 2024
c86c082
docs: fixed network rules import
AS-auxmoney May 16, 2024
048815f
fix: small PR comments/fixes
AS-auxmoney May 20, 2024
f52c185
Merge remote-tracking branch 'origin/main' into add-network-rules
AS-auxmoney May 20, 2024
64bd7bd
chore: merged main
AS-auxmoney May 20, 2024
38f2184
Merge branch 'main' into add-network-rules
sfc-gh-asawicki May 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions docs/resources/network_policy.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,21 @@ description: |-
## Example Usage

```terraform
resource "snowflake_network_rule" "rule" {
name = "rule"
database = "EXAMPLE_DB"
schema = "EXAMPLE_SCHEMA"
comment = "A rule."
type = "IPV4"
mode = "INGRESS"
value_list = ["192.168.0.100/24", "29.254.123.20"]
}

resource "snowflake_network_policy" "policy" {
name = "policy"
comment = "A policy."

allowed_ip_list = ["192.168.0.100/24"]
blocked_ip_list = ["192.168.0.101"]
allowed_network_rule_list = [snowflake_network_rule.rule.qualified_name]
sfc-gh-asawicki marked this conversation as resolved.
Show resolved Hide resolved
}
```

Expand All @@ -26,12 +35,14 @@ resource "snowflake_network_policy" "policy" {

### Required

- `allowed_ip_list` (Set of String) Specifies one or more IPv4 addresses (CIDR notation) that are allowed access to your Snowflake account
- `name` (String) Specifies the identifier for the network policy; must be unique for the account in which the network policy is created.

### Optional

- `blocked_ip_list` (Set of String) Specifies one or more IPv4 addresses (CIDR notation) that are denied access to your Snowflake account<br><br>**Do not** add `0.0.0.0/0` to `blocked_ip_list`
- `allowed_ip_list` (Set of String) Specifies one or more IPv4 addresses (CIDR notation) that are allowed access to your Snowflake account.
- `allowed_network_rule_list` (Set of String) Specifies a list of fully qualified network rules that contain the network identifiers that are allowed access to Snowflake.
- `blocked_ip_list` (Set of String) Specifies one or more IPv4 addresses (CIDR notation) that are denied access to your Snowflake account<br><br>**Do not** add `0.0.0.0/0` to `blocked_ip_list`.
- `blocked_network_rule_list` (Set of String) Specifies a list of fully qualified network rules that contain the network identifiers that are denied access to Snowflake.
- `comment` (String) Specifies a comment for the network policy.

### Read-Only
Expand Down
53 changes: 53 additions & 0 deletions docs/resources/network_rule.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
page_title: "snowflake_network_rule Resource - terraform-provider-snowflake"
subcategory: ""
description: |-

---

# snowflake_network_rule (Resource)



## Example Usage

```terraform
resource "snowflake_network_rule" "rule" {
name = "rule"
database = "EXAMPLE_DB"
schema = "EXAMPLE_SCHEMA"
comment = "A rule."
type = "IPV4"
mode = "INGRESS"
value_list = ["192.168.0.100/24", "29.254.123.20"]
}
```

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

### Required

- `database` (String) The database in which to create the network rule.
- `mode` (String) Specifies what is restricted by the network rule. Valid values are INGRESS, INTERNAL_STAGE and EGRESS; see https://docs.snowflake.com/en/sql-reference/sql/create-network-rule#required-parameters for details.
- `name` (String) Specifies the identifier for the network rule; must be unique for the database and schema in which the network rule is created.
- `schema` (String) The schema in which to create the network rule.
- `type` (String) Specifies the type of network identifiers being allowed or blocked. A network rule can have only one type. Allowed values are IPV4, AWSVPCEID, AZURELINKID and HOST_PORT; allowed values are determined by the mode of the network rule; see https://docs.snowflake.com/en/sql-reference/sql/create-network-rule#required-parameters for details.
- `value_list` (Set of String) Specifies the network identifiers that will be allowed or blocked. Valid values in the list are determined by the type of network rule, see https://docs.snowflake.com/en/sql-reference/sql/create-network-rule#required-parameters for details.

### Optional

- `comment` (String) Specifies a comment for the network rule.

### Read-Only

- `id` (String) The ID of this resource.
- `qualified_name` (String) Qualified name of the network rule.

## Import

Import is supported using the following syntax:

```shell
terraform import snowflake_network_rule.example 'databaseName|schemaName|networkRuleName'
```
13 changes: 11 additions & 2 deletions examples/resources/snowflake_network_policy/resource.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
resource "snowflake_network_rule" "rule" {
name = "rule"
database = "EXAMPLE_DB"
schema = "EXAMPLE_SCHEMA"
comment = "A rule."
type = "IPV4"
mode = "INGRESS"
value_list = ["192.168.0.100/24", "29.254.123.20"]
}

resource "snowflake_network_policy" "policy" {
name = "policy"
comment = "A policy."

allowed_ip_list = ["192.168.0.100/24"]
blocked_ip_list = ["192.168.0.101"]
allowed_network_rule_list = [snowflake_network_rule.rule.qualified_name]
}
1 change: 1 addition & 0 deletions examples/resources/snowflake_network_rule/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
terraform import snowflake_network_rule.example 'databaseName|schemaName|networkRuleName'
9 changes: 9 additions & 0 deletions examples/resources/snowflake_network_rule/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
resource "snowflake_network_rule" "rule" {
name = "rule"
database = "EXAMPLE_DB"
schema = "EXAMPLE_SCHEMA"
comment = "A rule."
type = "IPV4"
mode = "INGRESS"
value_list = ["192.168.0.100/24", "29.254.123.20"]
}
3 changes: 3 additions & 0 deletions pkg/acceptance/check_destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ var showByIdFunctions = map[resources.Resource]showByIdFunc{
resources.NetworkPolicy: func(ctx context.Context, client *sdk.Client, id sdk.ObjectIdentifier) error {
return runShowById(ctx, id, client.NetworkPolicies.ShowByID)
},
resources.NetworkRule: func(ctx context.Context, client *sdk.Client, id sdk.ObjectIdentifier) error {
return runShowById(ctx, id, client.NetworkRules.ShowByID)
},
resources.NotificationIntegration: func(ctx context.Context, client *sdk.Client, id sdk.ObjectIdentifier) error {
return runShowById(ctx, id, client.NotificationIntegrations.ShowByID)
},
Expand Down
1 change: 1 addition & 0 deletions pkg/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,7 @@ func getResources() map[string]*schema.Resource {
"snowflake_materialized_view": resources.MaterializedView(),
"snowflake_network_policy": resources.NetworkPolicy(),
"snowflake_network_policy_attachment": resources.NetworkPolicyAttachment(),
"snowflake_network_rule": resources.NetworkRule(),
"snowflake_notification_integration": resources.NotificationIntegration(),
"snowflake_oauth_integration": resources.OAuthIntegration(),
"snowflake_object_parameter": resources.ObjectParameter(),
Expand Down
1 change: 1 addition & 0 deletions pkg/provider/resources/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const (
MaskingPolicy resource = "snowflake_masking_policy"
MaterializedView resource = "snowflake_materialized_view"
NetworkPolicy resource = "snowflake_network_policy"
NetworkRule resource = "snowflake_network_rule"
NotificationIntegration resource = "snowflake_notification_integration"
PasswordPolicy resource = "snowflake_password_policy"
Pipe resource = "snowflake_pipe"
Expand Down
Loading