Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
39 changes: 39 additions & 0 deletions docs/data-sources/alb_waf_configuration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "stackit_alb_waf_configuration Data Source - stackit"
subcategory: ""
description: |-
albwaf resource schema.
---

# stackit_alb_waf_configuration (Data Source)

albwaf resource schema.

## Example Usage

```terraform
data "stackit_alb_waf_configuration" "example" {
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
name = "example-waf-configuration"
}
```

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

### Required

- `name` (String) The name of the WAF Configuration.
- `project_id` (String) STACKIT project ID to which the WAF Configuration is associated.

### Optional

- `region` (String) The resource region (e.g. eu01). If not defined, the provider region is used.

### Read-Only

- `custom_rule_group_name` (String) Name of the custom rule group for this WAF Configuration.
- `id` (String) Terraform's internal resource ID. It is structured as "`project_id`,`region`,`name`".
- `labels` (Map of String) User-defined metadata as key-value pairs. Should not exceed 64 entries.
- `managed_rule_set_name` (String) Name of the managed rule set configuration for this WAF Configuration.
11 changes: 0 additions & 11 deletions docs/data-sources/alb_waf_managed_rule_set.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ data "stackit_alb_waf_managed_rule_set" "example" {
- `groups` (Attributes Map) Inventory of all available Managed Rule Set groups and their current configuration. (see [below for nested schema](#nestedatt--groups))
- `id` (String) Terraform's internal resource identifier. Structured as "`project_id`,`region`,`name`".
- `type` (String) Type of the Managed Rule Set.
- `usage` (Attributes) Managed Rule Set usage (see [below for nested schema](#nestedatt--usage))
- `version` (String) Managed Rule Set version.

<a id="nestedatt--groups"></a>
Expand All @@ -59,13 +58,3 @@ Read-Only:
- `description` (String) A description of what this rule does.
- `mode` (String) The current mode of the rule.
- `severity` (String) Impact level.



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

Read-Only:

- `count` (Number) Number of WAFs using this Managed Rule Set.
- `items` (List of String) List of WAFs that use this Managed Rule Set.
39 changes: 39 additions & 0 deletions docs/resources/alb_waf_configuration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "stackit_alb_waf_configuration Resource - stackit"
subcategory: ""
description: |-
albwaf resource schema.
---

# stackit_alb_waf_configuration (Resource)

albwaf resource schema.

## Example Usage

```terraform
resource "stackit_alb_waf_configuration" "example" {
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
name = "example-waf-configuration"
}
```

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

### Required

- `name` (String) The name of the WAF Configuration.
- `project_id` (String) STACKIT project ID to which the WAF Configuration is associated.

### Optional

- `custom_rule_group_name` (String) Name of the custom rule group for this WAF Configuration.
- `labels` (Map of String) User-defined metadata as key-value pairs. Should not exceed 64 entries.
- `managed_rule_set_name` (String) Name of the managed rule set configuration for this WAF Configuration.
- `region` (String) The resource region (e.g. eu01). If not defined, the provider region is used.

### Read-Only

- `id` (String) Terraform's internal resource ID. It is structured as "`project_id`,`region`,`name`".
11 changes: 0 additions & 11 deletions docs/resources/alb_waf_managed_rule_set.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ resource "stackit_alb_waf_managed_rule_set" "example" {

- `groups` (Attributes Map) Inventory of all available Managed Rule Set groups and their current configuration. (see [below for nested schema](#nestedatt--groups))
- `id` (String) Terraform's internal resource identifier. Structured as "`project_id`,`region`,`name`".
- `usage` (Attributes) Managed Rule Set usage (see [below for nested schema](#nestedatt--usage))
- `version` (String) Managed Rule Set version.

<a id="nestedatt--groups"></a>
Expand All @@ -60,13 +59,3 @@ Read-Only:
- `description` (String) A description of what this rule does.
- `mode` (String) The current mode of the rule.
- `severity` (String) Impact level.



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

Read-Only:

- `count` (Number) Number of WAFs using this Managed Rule Set.
- `items` (List of String) List of WAFs that use this Managed Rule Set.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
data "stackit_alb_waf_configuration" "example" {
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
name = "example-waf-configuration"
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
resource "stackit_alb_waf_configuration" "example" {
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
name = "example-waf-configuration"
}

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require (
github.com/hashicorp/terraform-plugin-testing v1.16.0
github.com/stackitcloud/stackit-sdk-go/core v0.26.0
github.com/stackitcloud/stackit-sdk-go/services/alb v0.16.0
github.com/stackitcloud/stackit-sdk-go/services/albwaf v0.10.0
github.com/stackitcloud/stackit-sdk-go/services/albwaf v0.11.0
github.com/stackitcloud/stackit-sdk-go/services/cdn v1.19.0
github.com/stackitcloud/stackit-sdk-go/services/certificates v1.9.0
github.com/stackitcloud/stackit-sdk-go/services/dns v0.21.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -672,8 +672,8 @@ github.com/stackitcloud/stackit-sdk-go/core v0.26.0 h1:jQEb9gkehfp6VCP6TcYk7BI10
github.com/stackitcloud/stackit-sdk-go/core v0.26.0/go.mod h1:WU1hhxnjXw2EV7CYa1nlEvNpMiRY6CvmIOaHuL3pOaA=
github.com/stackitcloud/stackit-sdk-go/services/alb v0.16.0 h1:WoWlHdzISGXPEaJOYt6HP5F9M5nbyCJL6VqRJZIaOQs=
github.com/stackitcloud/stackit-sdk-go/services/alb v0.16.0/go.mod h1:eK6oRB5Tmpt6KbXQ4UYBGg2LgW5bPtVoncL9E8JSRww=
github.com/stackitcloud/stackit-sdk-go/services/albwaf v0.10.0 h1:0WsTSSZ0LjNpM3E1d3MgkBXmzMQThVQ7IuXhL2w4EyM=
github.com/stackitcloud/stackit-sdk-go/services/albwaf v0.10.0/go.mod h1:4M9G1I64kZwlXO32ZoIpt0GAN4SpZ1SYerwCVVIBGoE=
github.com/stackitcloud/stackit-sdk-go/services/albwaf v0.11.0 h1:ejTZTnGKFUWs9Ch9U30Jd+tpDA/SnHuSF9DpfD6w+To=
github.com/stackitcloud/stackit-sdk-go/services/albwaf v0.11.0/go.mod h1:4M9G1I64kZwlXO32ZoIpt0GAN4SpZ1SYerwCVVIBGoE=
github.com/stackitcloud/stackit-sdk-go/services/authorization v0.15.2 h1:b7WJ/vwxlVmNNX91kI3obqGcuoPAyaCbDL5aCMQ/sNg=
github.com/stackitcloud/stackit-sdk-go/services/authorization v0.15.2/go.mod h1:T/JF25XGJ3GqER/1L2N//DgY8x5tY7gA3N+/0nvmOWY=
github.com/stackitcloud/stackit-sdk-go/services/cdn v1.19.0 h1:k+KJ4gp9awhJMY5y55vDqRSr6G/S9+8haTNILGbgH9s=
Expand Down
123 changes: 118 additions & 5 deletions stackit/internal/services/albwaf/albwaf_acc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ import (
var (
//go:embed testdata/managed-rule-set.tf
managedRuleSetConfig string

//go:embed testdata/resource-max.tf
wafConfig string
)

var testManagedRuleSet = config.Variables{
Expand All @@ -39,6 +42,23 @@ var testManagedRuleSetUpdated = func() config.Variables {
return updatedConfig
}

var testConfigVarsMax = config.Variables{
"project_id": config.StringVariable(testutil.ProjectId),
"waf_configuration_name": config.StringVariable("tf-acc-" + acctest.RandStringFromCharSet(8, acctest.CharSetAlpha)),
"rule_set_name": config.StringVariable("tf-acc-" + acctest.RandStringFromCharSet(8, acctest.CharSetAlpha)),
"type": config.StringVariable("TYPE_OWASP_CRS"),
"waf_configuration_label": config.StringVariable("some-label"),
}

var testConfigVarsMaxUpdated = func() config.Variables {
updatedConfig := config.Variables{}
maps.Copy(updatedConfig, testConfigVarsMax)
updatedConfig["waf_configuration_name"] = config.StringVariable(fmt.Sprintf("%s-updated", testutil.ConvertConfigVariable(updatedConfig["waf_configuration_name"])))
updatedConfig["rule_set_name"] = config.StringVariable(fmt.Sprintf("%s-updated", testutil.ConvertConfigVariable(updatedConfig["rule_set_name"])))
updatedConfig["waf_configuration_label"] = config.StringVariable(fmt.Sprintf("%s-updated", testutil.ConvertConfigVariable(updatedConfig["waf_configuration_label"])))
return updatedConfig
}

func TestAccManagedRuleSet(t *testing.T) {
resource.Test(t, resource.TestCase{
ProtoV6ProviderFactories: testutil.TestAccProtoV6ProviderFactories,
Expand All @@ -53,8 +73,6 @@ func TestAccManagedRuleSet(t *testing.T) {
resource.TestCheckResourceAttr("stackit_alb_waf_managed_rule_set.managed_rule_set", "region", testutil.Region),
resource.TestCheckResourceAttrSet("stackit_alb_waf_managed_rule_set.managed_rule_set", "id"),
resource.TestCheckResourceAttr("stackit_alb_waf_managed_rule_set.managed_rule_set", "name", testutil.ConvertConfigVariable(testManagedRuleSet["name"])),

resource.TestCheckResourceAttr("stackit_alb_waf_managed_rule_set.managed_rule_set", "usage.count", "0"),
),
},
// Data source
Expand All @@ -79,8 +97,6 @@ func TestAccManagedRuleSet(t *testing.T) {
"stackit_alb_waf_managed_rule_set.managed_rule_set", "id",
),
resource.TestCheckResourceAttr("data.stackit_alb_waf_managed_rule_set.managed_rule_set", "name", testutil.ConvertConfigVariable(testManagedRuleSet["name"])),

resource.TestCheckResourceAttr("data.stackit_alb_waf_managed_rule_set.managed_rule_set", "usage.count", "0"),
),
},
// Import
Expand Down Expand Up @@ -115,8 +131,105 @@ func TestAccManagedRuleSet(t *testing.T) {
resource.TestCheckResourceAttr("stackit_alb_waf_managed_rule_set.managed_rule_set", "region", testutil.Region),
resource.TestCheckResourceAttrSet("stackit_alb_waf_managed_rule_set.managed_rule_set", "id"),
resource.TestCheckResourceAttr("stackit_alb_waf_managed_rule_set.managed_rule_set", "name", testutil.ConvertConfigVariable(testManagedRuleSetUpdated()["name"])),
),
},
// Deletion is done by the framework implicitly
},
})
}

func TestAccWafConfigurationMax(t *testing.T) {
resource.Test(t, resource.TestCase{
ProtoV6ProviderFactories: testutil.TestAccProtoV6ProviderFactories,
CheckDestroy: testAccCheckDestroy,
Steps: []resource.TestStep{
// Creation
{
ConfigVariables: testConfigVarsMax,
Config: fmt.Sprintf("%s\n%s", testutil.NewConfigBuilder().EnableBetaResources(true).BuildProviderConfig(), wafConfig),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("stackit_alb_waf_managed_rule_set.managed_rule_set", "name", testutil.ConvertConfigVariable(testConfigVarsMax["rule_set_name"])),

resource.TestCheckResourceAttr("stackit_alb_waf_configuration.waf_instance", "project_id", testutil.ProjectId),
resource.TestCheckResourceAttr("stackit_alb_waf_configuration.waf_instance", "region", testutil.Region),
resource.TestCheckResourceAttrSet("stackit_alb_waf_configuration.waf_instance", "id"),
resource.TestCheckResourceAttr("stackit_alb_waf_configuration.waf_instance", "name", testutil.ConvertConfigVariable(testConfigVarsMax["waf_configuration_name"])),
resource.TestCheckResourceAttrPair("stackit_alb_waf_configuration.waf_instance", "managed_rule_set_name", "stackit_alb_waf_managed_rule_set.managed_rule_set", "name"),
resource.TestCheckResourceAttr("stackit_alb_waf_configuration.waf_instance", "labels.label1", testutil.ConvertConfigVariable(testConfigVarsMax["waf_configuration_label"])),
),
},
// Data source
{
ConfigVariables: testConfigVarsMax,
Config: fmt.Sprintf(`
%s
%s

data "stackit_alb_waf_managed_rule_set" "managed_rule_set" {
project_id = stackit_alb_waf_managed_rule_set.managed_rule_set.project_id
name = stackit_alb_waf_managed_rule_set.managed_rule_set.name
}

data "stackit_alb_waf_configuration" "waf" {
project_id = stackit_alb_waf_configuration.waf_instance.project_id
name = stackit_alb_waf_configuration.waf_instance.name
}
`,
testutil.NewConfigBuilder().EnableBetaResources(true).BuildProviderConfig(), wafConfig,
),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrPair(
"data.stackit_alb_waf_managed_rule_set.managed_rule_set", "id",
"stackit_alb_waf_managed_rule_set.managed_rule_set", "id",
),
resource.TestCheckResourceAttr("data.stackit_alb_waf_managed_rule_set.managed_rule_set", "name", testutil.ConvertConfigVariable(testConfigVarsMax["rule_set_name"])),

resource.TestCheckResourceAttr("data.stackit_alb_waf_configuration.waf", "project_id", testutil.ProjectId),
resource.TestCheckResourceAttr("data.stackit_alb_waf_configuration.waf", "region", testutil.Region),
resource.TestCheckResourceAttrPair(
"data.stackit_alb_waf_configuration.waf", "id",
"stackit_alb_waf_configuration.waf_instance", "id",
),
resource.TestCheckResourceAttr("data.stackit_alb_waf_configuration.waf", "name", testutil.ConvertConfigVariable(testConfigVarsMax["waf_configuration_name"])),
resource.TestCheckResourceAttrPair("data.stackit_alb_waf_configuration.waf", "managed_rule_set_name", "data.stackit_alb_waf_managed_rule_set.managed_rule_set", "name"),
resource.TestCheckResourceAttr("data.stackit_alb_waf_configuration.waf", "labels.label1", testutil.ConvertConfigVariable(testConfigVarsMax["waf_configuration_label"])),
),
},
// Import
{
ConfigVariables: testConfigVarsMax,
ResourceName: "stackit_alb_waf_configuration.waf_instance",
ImportStateIdFunc: func(s *terraform.State) (string, error) {
r, ok := s.RootModule().Resources["stackit_alb_waf_configuration.waf_instance"]
if !ok {
return "", fmt.Errorf("couldn't find resource stackit_alb_waf_configuration.waf_instance")
}
name, ok := r.Primary.Attributes["name"]
if !ok {
return "", fmt.Errorf("couldn't find attribute name")
}
return fmt.Sprintf("%s,%s,%s", testutil.ProjectId, testutil.Region, name), nil
},
ImportState: true,
ImportStateVerify: true,
},
// Update
{
ConfigVariables: testConfigVarsMaxUpdated(),
Config: fmt.Sprintf("%s\n%s", testutil.NewConfigBuilder().EnableBetaResources(true).BuildProviderConfig(), wafConfig),
ConfigPlanChecks: resource.ConfigPlanChecks{
PreApply: []plancheck.PlanCheck{
plancheck.ExpectResourceAction("stackit_alb_waf_configuration.waf_instance", plancheck.ResourceActionReplace),
},
},
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("stackit_alb_waf_configuration.waf_instance", "project_id", testutil.ProjectId),
resource.TestCheckResourceAttr("stackit_alb_waf_configuration.waf_instance", "region", testutil.Region),
resource.TestCheckResourceAttrSet("stackit_alb_waf_configuration.waf_instance", "id"),
resource.TestCheckResourceAttr("stackit_alb_waf_configuration.waf_instance", "name", testutil.ConvertConfigVariable(testConfigVarsMaxUpdated()["waf_configuration_name"])),
resource.TestCheckResourceAttr("stackit_alb_waf_configuration.waf_instance", "labels.label1", testutil.ConvertConfigVariable(testConfigVarsMaxUpdated()["waf_configuration_label"])),

resource.TestCheckResourceAttr("stackit_alb_waf_managed_rule_set.managed_rule_set", "usage.count", "0"),
resource.TestCheckResourceAttr("stackit_alb_waf_managed_rule_set.managed_rule_set", "name", testutil.ConvertConfigVariable(testConfigVarsMaxUpdated()["rule_set_name"])),
),
},
// Deletion is done by the framework implicitly
Expand Down
16 changes: 0 additions & 16 deletions stackit/internal/services/albwaf/managed_rule_set/datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-log/tflog"
"github.com/stackitcloud/stackit-sdk-go/core/oapierror"
albWaf "github.com/stackitcloud/stackit-sdk-go/services/albwaf/v1betaapi"
Expand Down Expand Up @@ -100,21 +99,6 @@ func (d *managedRuleSetDataSource) Schema(_ context.Context, _ datasource.Schema
Description: descriptions["version"],
Computed: true,
},
"usage": schema.SingleNestedAttribute{
Description: descriptions["usage"],
Computed: true,
Attributes: map[string]schema.Attribute{
"count": schema.Int32Attribute{
Description: descriptions["usage_count"],
Computed: true,
},
"items": schema.ListAttribute{
Description: descriptions["usage_items"],
Computed: true,
ElementType: types.StringType,
},
},
},
"groups": schema.MapNestedAttribute{
Description: descriptions["groups"],
Computed: true,
Expand Down
Loading
Loading