Git Product home page Git Product logo

Comments (3)

apparentlymart avatar apparentlymart commented on June 1, 2024

Hi @rosbo!

The configuration language revamp that is underway will introduce a proper idea of "unset" as separate from zero-value, and introduce null as an expression that can be assigned to express "unset", which I think will eventually get us to a place where we can robustly implement this sort of conditional attribute assignment.

# NOT YET IMPLEMENTED; may change before release

resource "google_project" "host" {
  name            = "${var.project_name}"
  org_id          = "${var.org_id != "" ? var.org_id : null}"
  folder_id       = "${var.folder_id != "" ? var.folder_id : null}"
  project_id      = "${var.project_id == "" ? random_id.default-project-id.hex : var.project_id}"
  billing_account = "${var.billing_account}"
}

For now there may be another way to achieve this goal for this resource in particular. In 0.11.0-beta1 we introduced CustomizeDiff as a new function a resource can implement, which gives it the opportunity to inspect the diff, reject certain combinations of changes, and add additional information. In principle this could be used to introduce some custom validation behavior here instead of using ConflictsWith. For example:

func projectCustomizeDiff(d *ResourceDiff, meta interface{}) error {
    orgId := d.Get("org_id")
    folderId := d.Get("folder_id")
    if orgId != "" && folderId != "" {
        return errors.New("org_id and folder_id arguments cannot both be set")
    }
    return nil
}

So far this function is only available in the beta, so it may be worth waiting until we reach 0.11.0 final before updating providers to vendor the new version, in case there are some bugs that need to be dealt with. In principle this function can replace quite a lot of the declarative validations we currently support on schemas, though I'd suggest using it sparingly since the declarative validation rules do, at least, help ensure more consistency between the behaviors of resources.

from terraform-plugin-sdk.

bflad avatar bflad commented on June 1, 2024

Since this issue was raised, the Terraform configuration language in CLI version 0.12 and later has implemented support for null values. When this value is used in the context of configuring an attribute, Terraform will treat the attribute as if it was not set in the configuration at all. Using this style of (non 😄 ) configuration allows ConflictsWith to work as expected.

from terraform-plugin-sdk.

github-actions avatar github-actions commented on June 1, 2024

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

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.