Skip to content

VAULT-43393 Initial implementation for config control group resource#2840

Open
johnjosephg wants to merge 3 commits intomainfrom
VAULT-43393-config-control-group
Open

VAULT-43393 Initial implementation for config control group resource#2840
johnjosephg wants to merge 3 commits intomainfrom
VAULT-43393-config-control-group

Conversation

@johnjosephg
Copy link
Copy Markdown

@johnjosephg johnjosephg commented Mar 23, 2026

Description

Initial implementation for the vault_config_control_group resource in /sys/config/control-group.

Checklist

  • Added CHANGELOG entry (only for user-facing changes)
  • Acceptance tests where run against all supported Vault Versions

Output from acceptance testing:

go test -v ./internal/vault/sys/config -run 'TestAccControlGroupConfig' -count=1
=== RUN   TestAccControlGroupConfigResourceSchema
=== PAUSE TestAccControlGroupConfigResourceSchema
=== RUN   TestAccControlGroupConfigResource
--- PASS: TestAccControlGroupConfigResource (0.93s)
=== RUN   TestAccControlGroupConfigResourceNamespace
--- PASS: TestAccControlGroupConfigResourceNamespace (1.30s)
=== CONT  TestAccControlGroupConfigResourceSchema
--- PASS: TestAccControlGroupConfigResourceSchema (0.00s)
PASS

Community Note

  • Please vote on this pull request by adding a 👍 reaction to the original pull request comment to help the community and maintainers prioritize this request
  • Please do not leave "+1" comments, they generate extra noise for pull request followers and do not help prioritize the request

PCI review checklist

  • I have documented a clear reason for, and description of, the change I am making.

  • If applicable, I've documented a plan to revert these changes if they require more than reverting the pull request.

  • If applicable, I've documented the impact of any changes to security controls.

    Examples of changes to security controls include using new access control methods, adding or removing logging pipelines, etc.

@johnjosephg johnjosephg marked this pull request as ready for review March 24, 2026 05:52
@johnjosephg johnjosephg requested review from a team as code owners March 24, 2026 05:52
Copy link
Copy Markdown
Member

@Balaji2198 Balaji2198 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this. This resource implementation is currently developed in the SDKv2, but new resources should be built using the Terraform Plugin Framework. Please update the implementation accordingly. You can get the reference from the internal/vault/sys/password_policy.go

Copy link
Copy Markdown
Member

@Balaji2198 Balaji2198 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this, I’ve added a few comments.

Comment thread internal/vault/sys/config/control_group_resource.go Outdated
Comment thread internal/vault/sys/config/control_group_resource_test.go
Comment thread internal/vault/sys/config/control_group_resource.go

func (r *ControlGroupConfigResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
resp.Schema = schema.Schema{
MarkdownDescription: "Manages the singleton control group configuration. Requires Vault Enterprise 1.10.0 or later.",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to mention the version requirement, because TFVP itself is supported from vault version 1.15.x.

Attributes: map[string]schema.Attribute{
consts.FieldMaxTTL: schema.StringAttribute{
Optional: true,
MarkdownDescription: "The maximum ttl for a control group wrapping token. This can be provided in seconds or duration (for example, 2h). Requires Vault Enterprise 1.10.0 or later.",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to mention the version requirement, because TFVP itself is supported from vault version 1.15.x.

// featureSupported checks if the Vault server supports control group configuration.
// This feature requires Vault Enterprise 1.10.0 or later.
// The function takes an error callback to allow flexible error reporting across different contexts.
func (r *ControlGroupConfigResource) featureSupported(addError func(summary string, detail string)) bool {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need version gating, because TFVP itself is supported from vault version 1.15.x.

}

// Check if Vault is Enterprise edition (control groups are an Enterprise feature)
if !provider.IsEnterpriseSupported(r.Meta()) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have to check if its enterprise supported as well. These kind of validations are already in vault and we can let that take care of it.

MarkdownDescription: "Manages the singleton control group configuration. Requires Vault Enterprise 1.10.0 or later.",
Attributes: map[string]schema.Attribute{
consts.FieldMaxTTL: schema.StringAttribute{
Optional: true,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we make this as Required field, because without this we are getting error as max_ttl must be greater than 0 right ?

}

// Normalize the max_ttl to seconds (e.g., "2h" becomes "7200")
maxTTL, err := normalizeMaxTTL(data.MaxTTL.ValueString())
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need of normalization, as the api accepts string field itself.

},
}

base.MustAddLegacyBaseSchema(&resp.Schema)
Copy link
Copy Markdown
Contributor

@vijayavelsekar vijayavelsekar Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use MustAddBaseSchema instead of this because we are not migrating from the old SDK V2.
For ID field, you can have a computed ID field added to the schema.

return
}

if err := r.readIntoModel(ctx, vaultClient, &data); err != nil {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using this, can we reuse the Read function which already have these logic ?

return
}

if err := r.readIntoModel(ctx, vaultClient, &data); err != nil {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using this, can we reuse the Read function which already have these logic ?

Comment thread internal/vault/sys/config/control_group_resource.go

// createOrUpdate is a shared helper function for Create and Update operations.
// The isCreate parameter determines which error message to use for write failures.
func (r *ControlGroupConfigResource) createOrUpdate(ctx context.Context, req interface{}, resp interface{}, isCreate bool) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that you are trying to call the same function for create and update for reusability, but still you see it has separate control flow for create and update.
My thought was to use the same code for both Create and Update
Also I can see that Read can also be reused.
I've attached the sample code that I generated, which reused Create, update and read code. This will show you what I really mean. But I have not tested this code, probably it might have some issues. Just attaching it for your reference.

control_group_resource.txt

The `namespace` is always relative to the provider's configured [namespace](/docs/providers/vault#namespace).
*Available only for Vault Enterprise*.

* `max_ttl` - (Optional) The maximum TTL for a control group wrapping token. This value can be specified as a duration string (e.g., "24h", "1h30m") or as an integer number of seconds (e.g., "86400").
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Max ttl is required as per the schema defenition.

vijayavelsekar
vijayavelsekar previously approved these changes Apr 15, 2026
Copy link
Copy Markdown
Contributor

@vijayavelsekar vijayavelsekar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@johnjosephg johnjosephg force-pushed the VAULT-43393-config-control-group branch from ee1bfbf to 32d3827 Compare April 21, 2026 06:39
Removed duplicate sysconfig.NewControlGroupConfigResource entry from the resource list.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants