-
Notifications
You must be signed in to change notification settings - Fork 630
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DLP-1223: Add DLP dataset support to terraform
- Loading branch information
Rishabh Bector
committed
Mar 1, 2024
1 parent
c58feb6
commit adb1211
Showing
17 changed files
with
258 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:new-data-source | ||
cloudflare_dlp_datasets | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
```release-note:dependency | ||
provider: bump `github.com/aws/aws-sdk-go-v2` from 1.25.0 to 1.25.1 | ||
``` | ||
```release-note:dependency | ||
provider: bump `github.com/aws/aws-sdk-go-v2/config` from 1.27.1 to 1.27.2 | ||
``` | ||
```release-note:dependency | ||
provider: bump `github.com/aws/aws-sdk-go-v2/credentials` from 1.17.1 to 1.17.2 | ||
``` | ||
```release-note:dependency | ||
provider: bump `github.com/aws/aws-sdk-go-v2/service/s3` from 1.50.2 to 1.50.3 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
```release-note:dependency | ||
provider: bump `github.com/aws/aws-sdk-go-v2/config` from 1.27.2 to 1.27.3 | ||
``` | ||
```release-note:dependency | ||
provider: bump `github.com/aws/aws-sdk-go-v2/credentials` from 1.17.2 to 1.17.3 | ||
``` | ||
```release-note:dependency | ||
provider: bump `github.com/aws/aws-sdk-go-v2/service/s3` from 1.50.3 to 1.51.0 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:dependency | ||
provider: bump github.com/hashicorp/terraform-plugin-go from 0.21.0 to 0.22.0 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:bug | ||
resource/cloudflare_access_application: Fix issue with sending allow_authenticate_via_warp on updates when it is not provided | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
```release-note:dependency | ||
provider: bump `github.com/aws/aws-sdk-go-v2` from 1.25.1 to 1.25.2 | ||
``` | ||
```release-note:dependency | ||
provider: bump `github.com/aws/aws-sdk-go-v2/config` from 1.27.3 to 1.27.4 | ||
``` | ||
```release-note:dependency | ||
provider: bump `github.com/aws/aws-sdk-go-v2/credentials` from 1.17.3 to 1.17.4 | ||
``` | ||
```release-note:dependency | ||
provider: bump `github.com/aws/aws-sdk-go-v2/service/s3` from 1.51.0 to 1.51.1 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:dependency | ||
provider: bump github.com/hashicorp/terraform-plugin-sdk/v2 from 2.32.0 to 2.33.0 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:dependency | ||
provider: bump github.com/hashicorp/terraform-plugin-sdk/v2 from 2.32.0 to 2.33.0 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:dependency | ||
provider: bump github.com/cloudflare/cloudflare-go from 0.88.0 to 0.89.0 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:dependency | ||
provider: bump github.com/hashicorp/terraform-plugin-mux from 0.14.0 to 0.15.0 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
--- | ||
page_title: "cloudflare_dlp_datasets Data Source - Cloudflare" | ||
subcategory: "" | ||
description: |- | ||
Use this data source to retrieve all DLP datasets for an account. | ||
--- | ||
|
||
# cloudflare_dlp_datasets (Data Source) | ||
|
||
Use this data source to retrieve all DLP datasets for an account. | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
data "cloudflare_dlp_datasets" "example" { | ||
account_id = "f037e56e89293a057740de681ac9abbe" | ||
} | ||
``` | ||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `account_id` (String) The account ID to fetch DLP Datasets from. | ||
|
||
### Read-Only | ||
|
||
- `datasets` (List of Object) A list of DLP Datasets. (see [below for nested schema](#nestedatt--datasets)) | ||
|
||
<a id="nestedatt--datasets"></a> | ||
### Nested Schema for `datasets` | ||
|
||
Read-Only: | ||
|
||
- `description` (String) | ||
- `id` (String) | ||
- `name` (String) | ||
- `secret` (Boolean) | ||
- `status` (String) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
data "cloudflare_dlp_datasets" "example" { | ||
account_id = "f037e56e89293a057740de681ac9abbe" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package dlp_datasets | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/cloudflare/cloudflare-go" | ||
"github.com/hashicorp/terraform-plugin-framework/datasource" | ||
"github.com/hashicorp/terraform-plugin-framework/types" | ||
) | ||
|
||
var _ datasource.DataSource = &CloudflareDlpDatasetsDataSource{} | ||
|
||
func NewDataSource() datasource.DataSource { | ||
return &CloudflareDlpDatasetsDataSource{} | ||
} | ||
|
||
type CloudflareDlpDatasetsDataSource struct { | ||
client *cloudflare.API | ||
} | ||
|
||
func (d *CloudflareDlpDatasetsDataSource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { | ||
resp.TypeName = req.ProviderTypeName + "_dlp_datasets" | ||
} | ||
|
||
func (d *CloudflareDlpDatasetsDataSource) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) { | ||
if req.ProviderData == nil { | ||
return | ||
} | ||
|
||
client, ok := req.ProviderData.(*cloudflare.API) | ||
if !ok { | ||
resp.Diagnostics.AddError( | ||
"Unexpected resource configure type", | ||
fmt.Sprintf("Expected *cloudflare.API, got: %T. Please report this issue to the provider developers.", req.ProviderData), | ||
) | ||
return | ||
} | ||
|
||
d.client = client | ||
} | ||
|
||
func (d *CloudflareDlpDatasetsDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { | ||
var data DlpDatasetsModel | ||
|
||
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...) | ||
|
||
accountDatasets, err := d.client.ListDLPDatasets(ctx, cloudflare.AccountIdentifier(data.AccountID.ValueString()), cloudflare.ListDLPDatasetsParams{}) | ||
if err != nil { | ||
resp.Diagnostics.AddError("failed to fetch DLP Datasets: %w", err.Error()) | ||
return | ||
} | ||
|
||
var datasets []*DlpDatasetModel | ||
for _, dataset := range accountDatasets { | ||
datasets = append(datasets, &DlpDatasetModel{ | ||
ID: types.StringValue(dataset.ID), | ||
Name: types.StringValue(dataset.Name), | ||
Description: types.StringValue(dataset.Description), | ||
Status: types.StringValue(dataset.Status), | ||
Secret: types.BoolValue(*dataset.Secret), | ||
}) | ||
} | ||
|
||
data.Datasets = datasets | ||
resp.Diagnostics.Append(resp.State.Set(ctx, datasets)...) | ||
if resp.Diagnostics.HasError() { | ||
return | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
internal/framework/service/dlp_datasets/data_source_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package dlp_datasets_test | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"testing" | ||
|
||
"github.com/cloudflare/terraform-provider-cloudflare/internal/acctest" | ||
"github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||
) | ||
|
||
func TestAccCloudflareDLPDatasets_DataSource(t *testing.T) { | ||
accountID := os.Getenv("CLOUDFLARE_ACCOUNT_ID") | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { acctest.TestAccPreCheck(t) }, | ||
ProtoV6ProviderFactories: acctest.TestAccProtoV6ProviderFactories, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccCheckCloudflareDlpDatasetsDataSourceConfig(accountID), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrSet("data.cloudflare_dlp_datasets.my_datasets", "account_id"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccCheckCloudflareDlpDatasetsDataSourceConfig(accountID string) string { | ||
return fmt.Sprintf(` | ||
data "cloudflare_dlp_datasets" "my_datasets" { | ||
account_id = "%s" | ||
} | ||
`, accountID) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package dlp_datasets | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-plugin-framework/types" | ||
) | ||
|
||
type DlpDatasetsModel struct { | ||
AccountID types.String `tfsdk:"account_id"` | ||
Datasets []*DlpDatasetModel `tfsdk:"datasets"` | ||
} | ||
|
||
type DlpDatasetModel struct { | ||
ID types.String `tfsdk:"id"` | ||
Name types.String `tfsdk:"name"` | ||
Description types.String `tfsdk:"description"` | ||
Status types.String `tfsdk:"status"` | ||
Secret types.Bool `tfsdk:"secret"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package dlp_datasets | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/hashicorp/terraform-plugin-framework/attr" | ||
"github.com/hashicorp/terraform-plugin-framework/datasource" | ||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema" | ||
"github.com/hashicorp/terraform-plugin-framework/types" | ||
) | ||
|
||
func (d *CloudflareDlpDatasetsDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { | ||
resp.Schema = schema.Schema{ | ||
Description: "Use this data source to retrieve all DLP datasets for an account.", | ||
Attributes: map[string]schema.Attribute{ | ||
"account_id": schema.StringAttribute{ | ||
Required: true, | ||
Description: "The account ID to fetch DLP Datasets from.", | ||
}, | ||
"datasets": schema.ListAttribute{ | ||
Computed: true, | ||
ElementType: types.ObjectType{ | ||
AttrTypes: map[string]attr.Type{ | ||
"id": types.StringType, | ||
"name": types.StringType, | ||
"description": types.StringType, | ||
"status": types.StringType, | ||
"secret": types.BoolType, | ||
}, | ||
}, | ||
Description: "A list of DLP Datasets.", | ||
}, | ||
}, | ||
} | ||
} |