Git Product home page Git Product logo

Comments (1)

apparentlymart avatar apparentlymart commented on June 1, 2024

This sort of validation was one of the intended use-cases of the CustomizeDiff functionality, which runs as part of terraform plan and is therefore allowed to do network-sensitive validations.

The [ValidateValue] helper function allows this to be expressed in a more declarative way by function composition:

  CustomizeDiff: customdiff.All(
      customdiff.ValidateValue("security_groups", func (value, meta interface{}) error {
          if !hasEc2Classic(meta.(*AWSClient).supportedplatforms) {
              return fmt.Errorf("Use security_group_ids (with SG IDs) in VPC-enabled region"))
          }
      }),
      // ...
  ),

Of course, there are some ergonomic problems here. Most notably, the validation rule is expressed outside of the schema.Schema instance and this may not be easy to find in a resource with a very large schema.

Having a new schema-specific function for this seems fine to me, but from the perspective of Terraform Core I'd prefer to have the provider SDK do it as part of the existing Diff method (the same as CustomizeDiff) rather than introducing a new idea of "network validation". Once you've got the provider configured enough that it could implement network validation there isn't really any harm in running a full plan, even if you intend to ignore the result.

I think I'd approach this by using the very general CustomizeDiff for this sort of problem right now and then that experience will help us understand which parts of its functionality would be valuable to include as schema.Schema features too. For example, I think we can achieve the sort of validation you described here for hashicorp/terraform-provider-aws#3897 with the features we already have, and then convert to a different approach later.

from terraform-plugin-sdk.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.