Skip to content

Commit

Permalink
Acctest fix (#4)
Browse files Browse the repository at this point in the history
* add exceptions, trusted sources and web app practice acctests

* fix web application asset

* fix web api asset

* TypeSet instead of TypeList in some resources' schema

Co-authored-by: Omri Shtamberger <[email protected]>
  • Loading branch information
chkp-nadavt and chkp-omris authored May 29, 2022
1 parent 35dac22 commit 1b2a32e
Show file tree
Hide file tree
Showing 27 changed files with 1,038 additions and 56 deletions.
4 changes: 2 additions & 2 deletions docs/resources/inext_appsec_gateway_profile.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ The default is Automatic

### Read-Only

- `additional_settings_ids` (List of String)
- `additional_settings_ids` (Set of String)
- `authentication_token` (String) The token used to register an agent to the profile
- `id` (String, Sensitive) The ID of this resource.
- `profile_type` (String)
- `reverseproxy_additional_settings_ids` (List of String)
- `reverseproxy_additional_settings_ids` (Set of String)


2 changes: 1 addition & 1 deletion docs/resources/inext_docker_profile.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ resource "inext_docker_profile" "my-docker-profile" {

### Read-Only

- `additional_settings_ids` (List of String)
- `additional_settings_ids` (Set of String)
- `authentication_token` (String) The token used to register an agent to the profile
- `id` (String, Sensitive) The ID of this resource.
- `profile_type` (String)
Expand Down
2 changes: 1 addition & 1 deletion docs/resources/inext_embedded_profile.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ The default is Automatic

### Read-Only

- `additional_settings_ids` (List of String)
- `additional_settings_ids` (Set of String)
- `authentication_token` (String) The token used to register an agent to the profile
- `id` (String, Sensitive) The ID of this resource.
- `profile_type` (String)
Expand Down
2 changes: 1 addition & 1 deletion docs/resources/inext_kubernetes_profile.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ resource "inext_kubernetes_profile" "my-kubernetes-profile" {

### Read-Only

- `additional_settings_ids` (List of String)
- `additional_settings_ids` (Set of String)
- `authentication_token` (String) The token used to register an agent to the profile
- `id` (String, Sensitive) The ID of this resource.
- `profile_type` (String)
Expand Down
4 changes: 2 additions & 2 deletions docs/resources/inext_trusted_sources.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ resource "inext_trusted_sources" "my-trusted-source-behavior" {

### Optional

- `sources_identifiers` (List of String) The trusted sources identifier values
- `sources_identifiers` (Set of String) The trusted sources identifier values

### Read-Only

- `id` (String) The ID of this resource.
- `sources_identifiers_ids` (List of String)
- `sources_identifiers_ids` (Set of String)


8 changes: 4 additions & 4 deletions docs/resources/inext_web_api_asset.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ resource "inext_web_api_asset" "my-webapi-asset" {
### Required

- `name` (String) The name of the resource, also acts as it's unique ID
- `urls` (List of String) The application URLs
- `urls` (Set of String) The application URLs

### Optional

Expand All @@ -88,7 +88,7 @@ resource "inext_web_api_asset" "my-webapi-asset" {
- `order` (String)
- `read_only` (Boolean)
- `sources` (String)
- `urls_ids` (List of String)
- `urls_ids` (Set of String)

<a id="nestedblock--practice"></a>
### Nested Schema for `practice`
Expand Down Expand Up @@ -125,11 +125,11 @@ Read-Only:
Optional:

- `identifier` (String) The identifier of the source: SourceIP, XForwardedFor, HeaderKey or Cookie
- `values` (List of String)
- `values` (Set of String)

Read-Only:

- `id` (String) The ID of this resource.
- `values_ids` (List of String)
- `values_ids` (Set of String)


8 changes: 4 additions & 4 deletions docs/resources/inext_web_app_asset.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ resource "inext_web_app_asset" "my-webapp-asset" {
### Required

- `name` (String) The name of the resource, also acts as it's unique ID
- `urls` (List of String) The application URLs
- `urls` (Set of String) The application URLs

### Optional

Expand All @@ -87,7 +87,7 @@ resource "inext_web_app_asset" "my-webapp-asset" {
- `order` (String)
- `read_only` (Boolean)
- `sources` (String)
- `urls_ids` (List of String)
- `urls_ids` (Set of String)

<a id="nestedblock--practice"></a>
### Nested Schema for `practice`
Expand Down Expand Up @@ -127,11 +127,11 @@ Read-Only:
Optional:

- `identifier` (String) The identifier of the source: SourceIP, XForwardedFor, HeaderKey or Cookie
- `values` (List of String)
- `values` (Set of String)

Read-Only:

- `id` (String) The ID of this resource.
- `values_ids` (List of String)
- `values_ids` (Set of String)


8 changes: 4 additions & 4 deletions docs/resources/inext_web_app_practice.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,14 @@ Read-Only:

Optional:

- `inject_uris` (List of String) Defines where to inject the Anti-Bot script. The input is the path of the URI
- `valid_uris` (List of String) Defines which requests must be validated after the script is injected into a specific URI.
- `inject_uris` (Set of String) Defines where to inject the Anti-Bot script. The input is the path of the URI
- `valid_uris` (Set of String) Defines which requests must be validated after the script is injected into a specific URI.
The input is the path of the URI

Read-Only:

- `id` (String) The ID of this resource.
- `inject_uris_ids` (List of String)
- `valid_uris_ids` (List of String)
- `inject_uris_ids` (Set of String)
- `valid_uris_ids` (Set of String)


8 changes: 4 additions & 4 deletions internal/models/log-trigger/trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ type LogTrigger struct {
ResponseCode bool `json:"responseCode"`
LogToSyslog bool `json:"logToSyslog"`
SyslogIPAddress string `json:"syslogIpAddress,omitempty"`
SyslogPort int `json:"SyslogPortNum,omitempty"`
LogToCEF bool `json:"LogToCef"`
CEFIPAddress string `json:"CefIpAddress,omitempty"`
CEFPort int `json:"CefPort,omitempty"`
SyslogPort int `json:"syslogPortNum,omitempty"`
LogToCEF bool `json:"logToCef"`
CEFIPAddress string `json:"cefIpAddress,omitempty"`
CEFPort int `json:"cefPortNum,omitempty"`
}
20 changes: 17 additions & 3 deletions internal/resources/appsec-gateway-profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,21 @@ func ResourceAppSecGatewayProfile() *schema.Resource {
Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
},

CustomizeDiff: func(ctx context.Context, diff *schema.ResourceDiff, meta interface{}) error {
if diff.HasChange("additional_settings") {
if err := diff.SetNewComputed("additional_settings_ids"); err != nil {
return err
}
}

if diff.HasChange("reverseproxy_additional_settings") {
if err := diff.SetNewComputed("reverseproxy_additional_settings_ids"); err != nil {
return err
}
}

return nil
},
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Expand Down Expand Up @@ -54,7 +68,7 @@ func ResourceAppSecGatewayProfile() *schema.Resource {
},
},
"additional_settings_ids": {
Type: schema.TypeList,
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
Expand Down Expand Up @@ -106,7 +120,7 @@ func ResourceAppSecGatewayProfile() *schema.Resource {
},
},
"reverseproxy_additional_settings_ids": {
Type: schema.TypeList,
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
Expand Down
8 changes: 7 additions & 1 deletion internal/resources/docker-profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ func ResourceDockerProfile() *schema.Resource {
Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
},
CustomizeDiff: func(ctx context.Context, diff *schema.ResourceDiff, meta interface{}) error {
if diff.HasChange("additional_settings") {
return diff.SetNewComputed("additional_settings_ids")
}

return nil
},
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Expand All @@ -47,7 +53,7 @@ func ResourceDockerProfile() *schema.Resource {
},
},
"additional_settings_ids": {
Type: schema.TypeList,
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
Expand Down
2 changes: 1 addition & 1 deletion internal/resources/docker-profile/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func handleUpdateAdditionalSetting(d *schema.ResourceData, settingsKey, settting
if oldSettingMap, newSettingMap, hasChange := utils.MustGetChange[map[string]any](d, settingsKey); hasChange {
// get reverse proxy additional settings ids - each in the format: "<key><additonalSettingsIDSeparator><ID>"
additionalSettingsIDsMap := make(map[string]string)
additionalSettingsIDsInterface := d.Get(setttingsIDsKey).([]any)
additionalSettingsIDsInterface := d.Get(setttingsIDsKey).(*schema.Set).List()
for _, intefaceUnparsedID := range additionalSettingsIDsInterface {
// parse ID
keyAndID := strings.Split(intefaceUnparsedID.(string), additonalSettingsIDSeparator)
Expand Down
8 changes: 7 additions & 1 deletion internal/resources/embedded-profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ func ResourceEmbeddedProfile() *schema.Resource {
Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
},
CustomizeDiff: func(ctx context.Context, diff *schema.ResourceDiff, meta interface{}) error {
if diff.HasChange("additional_settings") {
return diff.SetNewComputed("additional_settings_ids")
}

return nil
},
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Expand All @@ -47,7 +53,7 @@ func ResourceEmbeddedProfile() *schema.Resource {
},
},
"additional_settings_ids": {
Type: schema.TypeList,
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
Expand Down
2 changes: 1 addition & 1 deletion internal/resources/embedded-profile/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func handleUpdateAdditionalSetting(d *schema.ResourceData, settingsKey, settting
if oldSettingMap, newSettingMap, hasChange := utils.GetChangeWithParse(d, settingsKey, utils.MustValueAs[map[string]any]); hasChange {
// get reverse proxy additional settings ids - each in the format: "<key><additonalSettingsIDSeparator><ID>"
additionalSettingsIDsMap := make(map[string]string)
additionalSettingsIDsInterface := d.Get(setttingsIDsKey).([]any)
additionalSettingsIDsInterface := d.Get(setttingsIDsKey).(*schema.Set).List()
for _, intefaceUnparsedID := range additionalSettingsIDsInterface {
// parse ID
keyAndID := strings.Split(intefaceUnparsedID.(string), additonalSettingsIDSeparator)
Expand Down
8 changes: 7 additions & 1 deletion internal/resources/kubernetes-profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ func ResourceKubernetesProfile() *schema.Resource {
Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
},
CustomizeDiff: func(ctx context.Context, diff *schema.ResourceDiff, meta interface{}) error {
if diff.HasChange("additional_settings") {
return diff.SetNewComputed("additional_settings_ids")
}

return nil
},
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Expand Down Expand Up @@ -52,7 +58,7 @@ func ResourceKubernetesProfile() *schema.Resource {
},
},
"additional_settings_ids": {
Type: schema.TypeList,
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
Expand Down
2 changes: 1 addition & 1 deletion internal/resources/kubernetes-profile/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func handleUpdateAdditionalSetting(d *schema.ResourceData, settingsKey, settting
if oldSettingMap, newSettingMap, hasChange := utils.GetChangeWithParse(d, settingsKey, utils.MustValueAs[map[string]any]); hasChange {
// get reverse proxy additional settings ids - each in the format: "<key><additonalSettingsIDSeparator><ID>"
additionalSettingsIDsMap := make(map[string]string)
additionalSettingsIDsInterface := d.Get(setttingsIDsKey).([]any)
additionalSettingsIDsInterface := d.Get(setttingsIDsKey).(*schema.Set).List()
for _, intefaceUnparsedID := range additionalSettingsIDsInterface {
// parse ID
keyAndID := strings.Split(intefaceUnparsedID.(string), additonalSettingsIDSeparator)
Expand Down
17 changes: 17 additions & 0 deletions internal/resources/log-trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,23 @@ func resourceLogTriggerUpdate(ctx context.Context, d *schema.ResourceData, meta
return utils.DiagError("Failed to Publish following LogTrigger Update", err, diags)
}

logTrigger, err := logtrigger.GetLogTrigger(c, d.Id())
if err != nil {
if _, discardErr := c.DiscardChanges(); discardErr != nil {
diags = utils.DiagError("failed to discard changes", discardErr, diags)
}

return utils.DiagError("Unable to perform LogTrigger Get before read after update", err, diags)
}

if err := logtrigger.ReadLogTriggerToResourceData(logTrigger, d); err != nil {
if _, discardErr := c.DiscardChanges(); discardErr != nil {
diags = utils.DiagError("failed to discard changes", discardErr, diags)
}

return utils.DiagError("Unable to perform LogTrigger read to state file after update", err, diags)
}

return diags
}

Expand Down
Loading

0 comments on commit 1b2a32e

Please sign in to comment.