Skip to content

Commit

Permalink
Merge pull request #316 from dbt-labs/release-0.3.22
Browse files Browse the repository at this point in the history
Release 0.3.22
  • Loading branch information
b-per authored Nov 7, 2024
2 parents 29c15f0 + 3cae30d commit cc7fa2d
Show file tree
Hide file tree
Showing 19 changed files with 1,315 additions and 13 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@

All notable changes to this project will be documented in this file.

## [Unreleased](https://github.com/dbt-labs/terraform-provider-dbtcloud/compare/v0.3.21...HEAD)
## [Unreleased](https://github.com/dbt-labs/terraform-provider-dbtcloud/compare/v0.3.22...HEAD)

# [0.3.22](https://github.com/dbt-labs/terraform-provider-dbtcloud/compare/v0.3.21...v0.3.22)

### Changes

- Add resource `dbtcloud_account_features` to manage account level features like Advanced CI
- Add resource `dbtcloud_ip_restrictions_rule` to manage IP restrictions for customers with access to the feature in dbt Cloud

# [0.3.21](https://github.com/dbt-labs/terraform-provider-dbtcloud/compare/v0.3.20...v0.3.21)

Expand Down
29 changes: 29 additions & 0 deletions docs/resources/account_features.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
page_title: "dbtcloud_account_features Resource - dbtcloud"
subcategory: ""
description: |-
Manages dbt Cloud global features at the account level, like Advanced CI. The same feature should not be configured in different resources to avoid conflicts.
When destroying the resource or removing the value for an attribute, the features status will not be changed. Deactivating features will require applying them wih the value set to false.
---

# dbtcloud_account_features (Resource)


Manages dbt Cloud global features at the account level, like Advanced CI. The same feature should not be configured in different resources to avoid conflicts.

When destroying the resource or removing the value for an attribute, the features status will not be changed. Deactivating features will require applying them wih the value set to `false`.



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

### Optional

- `advanced_ci` (Boolean) Whether advanced CI is enabled.
- `partial_parsing` (Boolean) Whether partial parsing is enabled.
- `repo_caching` (Boolean) Whether repository caching is enabled.

### Read-Only

- `id` (String) The ID of the account.
82 changes: 82 additions & 0 deletions docs/resources/ip_restrictions_rule.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
---
page_title: "dbtcloud_ip_restrictions_rule Resource - dbtcloud"
subcategory: ""
description: |-
Manages IP restriction rules in dbt Cloud. IP restriction rules allow you to control access to your dbt Cloud instance based on IP address ranges.
---

# dbtcloud_ip_restrictions_rule (Resource)


Manages IP restriction rules in dbt Cloud. IP restriction rules allow you to control access to your dbt Cloud instance based on IP address ranges.

## Example Usage

```terraform
resource "dbtcloud_ip_restrictions_rule" "test" {
name = "My restriction rule"
description = "Important description"
cidrs = [
{
cidr = "::ffff:106:708" # IPv6 config
},
{
cidr = "1.6.7.10/24" # /24 for adding a range of addresses via netmask
}
]
type = "deny"
rule_set_enabled = false
}
```

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

### Required

- `cidrs` (Attributes Set) Set of CIDR ranges for this rule (see [below for nested schema](#nestedatt--cidrs))
- `name` (String) The name of the IP restriction rule
- `rule_set_enabled` (Boolean) Whether the IP restriction rule set is enabled or not. Important!: This value needs to be the same for all rules if multiple rules are defined. All rules must be active or inactive at the same time.
- `type` (String) The type of the IP restriction rule (allow or deny)

### Optional

- `description` (String) A description of the IP restriction rule

### Read-Only

- `id` (Number) The ID of the IP restriction rule

<a id="nestedatt--cidrs"></a>
### Nested Schema for `cidrs`

Optional:

- `cidr` (String) IP CIDR range (can be IPv4 or IPv6)

Read-Only:

- `cidr_ipv6` (String) IPv6 CIDR range (read-only)
- `id` (Number) ID of the CIDR range
- `ip_restriction_rule_id` (Number) ID of the IP restriction rule

## Import

Import is supported using the following syntax:

```shell
# using import blocks (requires Terraform >= 1.5)
import {
to = dbtcloud_ip_restrictions_rule.my_rule
id = "ip_restriction_rule_id"
}

import {
to = dbtcloud_ip_restrictions_rule.my_rule
id = "12345"
}

# using the older import command
terraform import dbtcloud_ip_restrictions_rule.my_rule "ip_restriction_rule_id"
terraform import dbtcloud_ip_restrictions_rule.my_rule 12345
```
14 changes: 14 additions & 0 deletions examples/resources/dbtcloud_ip_restrictions_rule/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# using import blocks (requires Terraform >= 1.5)
import {
to = dbtcloud_ip_restrictions_rule.my_rule
id = "ip_restriction_rule_id"
}

import {
to = dbtcloud_ip_restrictions_rule.my_rule
id = "12345"
}

# using the older import command
terraform import dbtcloud_ip_restrictions_rule.my_rule "ip_restriction_rule_id"
terraform import dbtcloud_ip_restrictions_rule.my_rule 12345
14 changes: 14 additions & 0 deletions examples/resources/dbtcloud_ip_restrictions_rule/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
resource "dbtcloud_ip_restrictions_rule" "test" {
name = "My restriction rule"
description = "Important description"
cidrs = [
{
cidr = "::ffff:106:708" # IPv6 config
},
{
cidr = "1.6.7.10/24" # /24 for adding a range of addresses via netmask
}
]
type = "deny"
rule_set_enabled = false
}
73 changes: 73 additions & 0 deletions pkg/dbt_cloud/account_features.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package dbt_cloud

import (
"encoding/json"
"fmt"
"net/http"
"strings"
)

type AccountFeaturesResponse struct {
Data AccountFeatures `json:"data"`
Status ResponseStatus `json:"status"`
Extra ResponseExtra `json:"extra"`
}

type AccountFeatures struct {
AdvancedCI bool `json:"advanced-ci"`
PartialParsing bool `json:"partial-parsing"`
RepoCaching bool `json:"repo-caching"`
}

type AccountFeatureUpdateRequest struct {
Feature string `json:"feature"`
Value bool `json:"value"`
}

func (c *Client) GetAccountFeatures() (*AccountFeatures, error) {
req, err := http.NewRequest(
"GET",
fmt.Sprintf("%s/private/accounts/%d/features/", c.HostURL, c.AccountID),
nil,
)
if err != nil {
return nil, err
}

body, err := c.doRequest(req)
if err != nil {
return nil, err
}

featuresResponse := AccountFeaturesResponse{}
err = json.Unmarshal(body, &featuresResponse)
if err != nil {
return nil, err
}

return &featuresResponse.Data, nil
}

func (c *Client) UpdateAccountFeature(feature string, value bool) error {
updateRequest := AccountFeatureUpdateRequest{
Feature: feature,
Value: value,
}

updateData, err := json.Marshal(updateRequest)
if err != nil {
return err
}

req, err := http.NewRequest(
"POST",
fmt.Sprintf("%s/private/accounts/%d/features/", c.HostURL, c.AccountID),
strings.NewReader(string(updateData)),
)
if err != nil {
return err
}

_, err = c.doRequest(req)
return err
}
4 changes: 3 additions & 1 deletion pkg/dbt_cloud/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,9 @@ func (c *Client) doRequest(req *http.Request) ([]byte, error) {
}
}

if (res.StatusCode != http.StatusOK) && (res.StatusCode != 201) {
if (res.StatusCode != http.StatusOK) &&
(res.StatusCode != http.StatusCreated) &&
(res.StatusCode != http.StatusNoContent) {
return nil, fmt.Errorf(
"%s url: %s, status: %d, body: %s",
req.Method,
Expand Down
Loading

0 comments on commit cc7fa2d

Please sign in to comment.