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

Conflicts_with fails during Validate even if one of the values is Unkown #251

Closed
1 task done
Iduoad opened this issue Dec 6, 2024 · 2 comments · Fixed by #252
Closed
1 task done

Conflicts_with fails during Validate even if one of the values is Unkown #251

Iduoad opened this issue Dec 6, 2024 · 2 comments · Fixed by #252
Labels
bug Something isn't working
Milestone

Comments

@Iduoad
Copy link

Iduoad commented Dec 6, 2024

Terraform CLI and Framework Versions

$ terraform version
Terraform v1.10.0
$ go list -m github.com/hashicorp/terraform-plugin-framework
github.com/hashicorp/terraform-plugin-framework v1.13.0

Terraform Plugin Framework Code

"image": schema.StringAttribute{
		Optional: true,
		PlanModifiers: []planmodifier.String{
			stringplanmodifier.RequiresReplace(),
		},
        Validators: []validator.String{
          stringvalidator.ConflictsWith(
            path.Expressions{
              path.MatchRoot("source_instance"), 
            }...
          ),
          stringvalidator.AtLeastOneOf(
            path.Expressions{
              path.MatchRoot("image"), 
              path.MatchRoot("source_instance"), 
            }...
          ),
        },
	},
	"source_instance": schema.SingleNestedAttribute{
		Optional: true,
		Attributes: map[string]schema.Attribute{
			"project": schema.StringAttribute{
				Required: true,
			},
			"name": schema.StringAttribute{
				Required: true,
			},
			"snapshot": schema.StringAttribute{
				Optional: true,
			},
		},
		PlanModifiers: []planmodifier.Object{
			objectplanmodifier.RequiresReplace(),
		},
                Validators: []validator.Object{
                   objectvalidator.ConflictsWith(
                       path.Expressions{
                            path.MatchRoot("image"), 
                   }...),
                   objectvalidator.AtLeastOneOf(
                       path.Expressions{
                            path.MatchRoot("image"), 
                            path.MatchRoot("source_instance"), 
                        }...
                  ),
              },
        },

Terraform Configuration

variable "source_instance"{
  default = null
}

resource "my_resource"{
   image = "my_image"
   source_instance = var.source_instance
}

Expected Behavior

terraform validate should run with no errors for the configuration above. Since var.source_instance is Unkown.

Actual Behavior

terraform validate fails with

 Error: Invalid Attribute Combination

with incus_instance.instance1,
on main.tf line 33, in resource "incus_instance" "instance1":
33:   source_instance = var.source_instance

Attribute "image" cannot be specified when "source_instance" is specified

Steps to Reproduce

  1. Create a resource with attribute that is using ConflictsWith
  2. Define one of the conflicting attribute and pass the other one from a variable (Unknown)
  3. terraform validate

Logs

No response

Additional Information

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@austinvalle
Copy link
Member

@Iduoad Thanks for reporting the issue over here! The newly released v0.16.0 should have the fix for your described error above.

https://github.com/hashicorp/terraform-plugin-framework-validators/releases/tag/v0.16.0

@Iduoad
Copy link
Author

Iduoad commented Dec 13, 2024

Thank you so much @austinvalle

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
2 participants