Skip to content

Commit

Permalink
Merge branch 'staging'
Browse files Browse the repository at this point in the history
  • Loading branch information
mausam-patel committed Mar 7, 2024
2 parents c5549ba + 9904bfe commit a3eb76e
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@
* Introduced support for User resource
* Introduced support for Role resource
* Added enhancement to HEC token resource to retry previous failed deployment task when creating, updating, deleting Hec Tokens

## Version v1.2.1
* Fixes bug found in Roles resource in which `srch_indexes_default` was set to value of `srch_indexes_allowed`
* Introduces workaround to allow zero value to be set for Roles resource fields where valid. See [Roles Documentation](https://registry.terraform.io/providers/splunk/scp/latest/docs/resources/roles).
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Terraform Provider for Splunk Cloud Platform

At this point in time, this provider only supports the index resource for Splunk Cloud Platform deployments.
At this point in time, this provider supports the following resources for Splunk Cloud Platform deployments.
- Indexes
- Hec Tokens
- IP Allowlist
- Users
- Roles

```
Copyright 2023 Splunk Inc.
Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Instead, it is recommended to using a dedicated secret store such as Vault or AW
The following attributes must be set for the provider to work.
- `server`
- `stack`
- Either `auth_token` or `username`/`password`
- Either `auth_token` or `username`/`password` NOTE: IL2 environment will not be able to use `username`/`password` for authentication.

## Schema

Expand Down
16 changes: 16 additions & 0 deletions docs/resources/roles.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,22 @@ Defaults are currently set to:

## Notes/Troubleshooting

### Setting fields to zero value
**Issue**: The [GetOk](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema#ResourceData.GetOk)
implementation in the Legacy SDK does not recognize zero values for fields. However, 0 is a valid value for various fields
such as `cumulative_rt_srch_jobs_quota` and `rt_srch_jobs_quota`

**Solution:** If possible, please set these values to a non-zero value. If you would like to set either of these fields
to zero, the user can choose to manage this field exclusively through UI/ACS API/ACS CLI - only adding the field to their
configuration if they would like to set it to a non-zero value.

Alternatively users should upgrade to at least v1.2.1 of this provider to leverage a workaround which relies on the
[GetChange](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema#ResourceData.GetChange)
functionality of the Legacy SDK. The caveat is that you must run `terraform apply` twice when first creating a new role in
order for the zero values to be set (they will only be set when updating a resource, not when creating one). Please note that
terraform config and real infrastructure should converge after the second run of `terraform apply`.


### Terraform Import
**Issue:** If you receive a 409 conflict error when creating a resource, either use a different role name to create a new resource, or use `terraform import` to bring
the resource under terraform management.
Expand Down
40 changes: 34 additions & 6 deletions internal/roles/role_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,8 @@ func resourceRoleUpdate(ctx context.Context, d *schema.ResourceData, m interface
patchParam := v2.PatchRoleInfoParams{
FederatedSearchManageAck: roleParam,
}
tflog.Info(ctx, fmt.Sprintf("updated role resource: %d\n", patchRequest.CumulativeRTSrchJobsQuota))

patchRequestBody := v2.PatchRoleInfoJSONRequestBody{
RolesInfo: patchRequest.RolesInfo,
CumulativeRTSrchJobsQuota: patchRequest.CumulativeRTSrchJobsQuota,
Expand All @@ -320,7 +322,7 @@ func resourceRoleUpdate(ctx context.Context, d *schema.ResourceData, m interface
return diag.Errorf(fmt.Sprintf("Error waiting for role (%s) to be updated: %s", roleName, err))
}

tflog.Info(ctx, fmt.Sprintf("updated hec resource: %s\n", roleName))
tflog.Info(ctx, fmt.Sprintf("updated role resource: %s\n", roleName))
return resourceRoleRead(ctx, d, m)
}

Expand Down Expand Up @@ -349,14 +351,24 @@ func parseRoleRequest(d *schema.ResourceData) (*v2.RolesRequest, string) {
name := d.Get(schemaKeyName).(string)

// RolesRequest attributes

// workaround to allow 0 value, repeated for all fields where 0 is valid value
if value, ok := d.GetOk(schemaKeyCumulativeRTSrchJobsQuota); ok {
parsedData := value.(int)
rolesRequest.CumulativeRTSrchJobsQuota = &parsedData
} else if d.HasChange(schemaKeyCumulativeRTSrchJobsQuota) {
_, new_val := d.GetChange(schemaKeyCumulativeRTSrchJobsQuota)
parsedData := new_val.(int)
rolesRequest.CumulativeRTSrchJobsQuota = &parsedData
}

if value, ok := d.GetOk(schemaKeyCumulativeSrchJobsQuota); ok {
parsedData := value.(int)
rolesRequest.CumulativeSrchJobsQuota = &parsedData
} else if d.HasChange(schemaKeyCumulativeSrchJobsQuota) {
_, new_val := d.GetChange(schemaKeyCumulativeSrchJobsQuota)
parsedData := new_val.(int)
rolesRequest.CumulativeSrchJobsQuota = &parsedData
}

if value, ok := d.GetOk(schemaKeyDefaultApp); ok {
Expand All @@ -375,18 +387,22 @@ func parseRoleRequest(d *schema.ResourceData) (*v2.RolesRequest, string) {
rolesRequest.Capabilities = &parsedData
}

// workaround to allow zero value
if value, ok := d.GetOk(schemaKeyRTSrchJobsQuota); ok {
parsedData := value.(int)
rolesRequest.RtSrchJobsQuota = &parsedData
} else if d.HasChange(schemaKeyRTSrchJobsQuota) {
_, new_val := d.GetChange(schemaKeyRTSrchJobsQuota)
parsedData := new_val.(int)
rolesRequest.RtSrchJobsQuota = &parsedData
}

if value, ok := d.GetOk(schemaKeySrchDiskQuota); ok {
parsedData := value.(int)
rolesRequest.SrchDiskQuota = &parsedData
}

if value, ok := d.GetOk(schemaKeySrchDiskQuota); ok {
parsedData := value.(int)
} else if d.HasChange(schemaKeySrchDiskQuota) {
_, new_val := d.GetChange(schemaKeySrchDiskQuota)
parsedData := new_val.(int)
rolesRequest.SrchDiskQuota = &parsedData
}

Expand All @@ -402,22 +418,34 @@ func parseRoleRequest(d *schema.ResourceData) (*v2.RolesRequest, string) {

if values, ok := d.GetOk(schemaKeySrchIndexesDefault); ok {
parsedData := utils.ParseSetValues(values)
rolesRequest.SrchIndexesAllowed = &parsedData
rolesRequest.SrchIndexesDefault = &parsedData
}

if value, ok := d.GetOk(schemaKeySrchJobsQuota); ok {
parsedData := value.(int)
rolesRequest.SrchJobsQuota = &parsedData
} else if d.HasChange(schemaKeySrchJobsQuota) {
_, new_val := d.GetChange(schemaKeySrchJobsQuota)
parsedData := new_val.(int)
rolesRequest.SrchJobsQuota = &parsedData
}

if value, ok := d.GetOk(schemaKeySrchTimeEarliest); ok {
parsedData := value.(int)
rolesRequest.SrchTimeEarliest = &parsedData
} else if d.HasChange(schemaKeySrchTimeEarliest) {
_, new_val := d.GetChange(schemaKeySrchTimeEarliest)
parsedData := new_val.(int)
rolesRequest.SrchTimeEarliest = &parsedData
}

if value, ok := d.GetOk(schemaKeySrchTimeWin); ok {
parsedData := value.(int)
rolesRequest.SrchTimeWin = &parsedData
} else if d.HasChange(schemaKeySrchTimeWin) {
_, new_val := d.GetChange(schemaKeySrchTimeWin)
parsedData := new_val.(int)
rolesRequest.SrchTimeWin = &parsedData
}
return &rolesRequest, name
}
Expand Down

0 comments on commit a3eb76e

Please sign in to comment.