ConflictsWith with a TypeList

Is it possible to reference keys other than 0,

If I have one of the key as a TypeList in my resource file, which has element type schema.

	Schema: map[string]*schema.Schema{
	"server": {
			Type:     schema.TypeList,
			Optional: true,
			Computed: true,
			Elem: &schema.Resource{
				Schema: map[string]*schema.Schema{
					"id": {
						Type:     schema.TypeString,
						Optional: true,
						Computed: true,
					},
					"zone": {
						Type:     schema.TypeString,
						Optional: true,
						ConflictsWith: [x]string{"server.profile"},
					},
					"profile": {
						Type:     schema.TypeString,
						Optional: true,
						ConflictsWith: []string{"server.zone"},
					},
					"name": {
						Type:     schema.TypeString,
						Optional: true,
					},

},
},
For maxItems:1, ConflictsWith: string{“server.0.zone”}, works fine.

I’m seeing code that requires it to be set to 0, so I feel comfortable asserting it is not, unfortunately.

@paddy Thats a big issue, for schemas we can directly use the keys with conflictswith but with a list, it lacks the functionality even when the element of the list is a schema.

Ideally we should be able to validate these things at planning level but terraform isn’t supporting this at the moment it seems.

It’s certainly not ideal. I’d imagine the best path forward is a feature request on https://github.com/hashicorp/terraform-plugin-sdk/issues/new. But yes, the only way to validate this kind of thing at plan time appears to be using CustomizeDiff.

1 Like