Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add parent property to ResourceValidationArgs #364

Open
automagic opened this issue Oct 10, 2024 · 1 comment
Open

Add parent property to ResourceValidationArgs #364

automagic opened this issue Oct 10, 2024 · 1 comment
Labels
kind/enhancement Improvements or new features

Comments

@automagic
Copy link

Hello!

  • Vote on this issue by adding a 👍 reaction
  • If you want to implement this feature, comment to let us know (we'll work with you on design, scheduling, etc.)

Issue details

I would be useful to be able to validate if a resource is correctly parented. We can do this for StackPolicies (the field exists on PolicyResource), but we do not have this at the individual level within ResourceValidationArgs or PolicyResourceOptions.

Since both PolicyResource and ResourceValidationOptions have a reference to PolicyResourceOptions it may make sense to have it there instead.

Use-case:

We may want to check if a particular resource type is contained within a component resource, e.g. "AWS secrets manager secrets must be created with 'MySpecialSecretManager' component resource as the parent"

Example:

def s3_bucket_parent_validator(args, report_violation: ReportViolation):
    # Check if the resource is an S3 bucket and if it has a parent set
    if isinstance(args.resource, aws.s3.Bucket):
        if not hasattr(args.resource, "opts") or not getattr(args.resource.opts, "parent", None):
            report_violation("S3 bucket must have a parent resource set")

Affected area/feature

ResourceVal

@automagic automagic added kind/enhancement Improvements or new features needs-triage Needs attention from the triage team labels Oct 10, 2024
@justinvp justinvp removed the needs-triage Needs attention from the triage team label Oct 10, 2024
@justinvp
Copy link
Member

For now, the workaround is to use a stack validation policy to check the parent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement Improvements or new features
Projects
None yet
Development

No branches or pull requests

2 participants