title: Is there a way to avoid hardcoding Terraform TypeSet hashed index values in provider tests?
body: <p>When using <code>TypeSet</code>, Terraform indicates the hash indexes are calculated based on the values of the set. I have a Terraform Provider written in Go using the <a href="https://github.com/hashicorp/terraform-plugin-sdk" rel="nofollow noreferrer">Terraform Provider Go SDK</a> where I currently need to hard code these index values in the tests. Can hardcoding the values in the Terraform Provider tests be avoided?</p>
  <p>Terraform docs say the following, but don't provide information on how to calculate the hash index values or avoid calculating them.</p>
  <blockquote>
  <p><code>TypeSet</code> items are stored in state with an index value calculated by the hash of the attributes of the set.</p>
  </blockquote>
  <p>Ref: Terraform docs: <a href="https://www.terraform.io/plugin/sdkv2/schemas/schema-types" rel="nofollow noreferrer">https://www.terraform.io/plugin/sdkv2/schemas/schema-types</a></p>
  <p>Here's the example provided in the documentation where <code>1061987227</code> and <code>493694946</code> are auto-generated hash index values.</p>
  <pre><code>&quot;ingress.#&quot;: &quot;2&quot;,
  &quot;ingress.1061987227.cidr_blocks.#&quot;: &quot;1&quot;,
  &quot;ingress.1061987227.cidr_blocks.0&quot;: &quot;10.0.0.0/8&quot;,
  &quot;ingress.1061987227.description&quot;: &quot;&quot;,
  &quot;ingress.1061987227.from_port&quot;: &quot;80&quot;,
  &quot;ingress.1061987227.ipv6_cidr_blocks.#&quot;: &quot;0&quot;,
  &quot;ingress.1061987227.protocol&quot;: &quot;tcp&quot;,
  &quot;ingress.1061987227.security_groups.#&quot;: &quot;0&quot;,
  &quot;ingress.1061987227.self&quot;: &quot;false&quot;,
  &quot;ingress.1061987227.to_port&quot;: &quot;9000&quot;,
  &quot;ingress.493694946.cidr_blocks.#&quot;: &quot;2&quot;,
  &quot;ingress.493694946.cidr_blocks.0&quot;: &quot;0.0.0.0/0&quot;,
  &quot;ingress.493694946.cidr_blocks.1&quot;: &quot;10.0.0.0/8&quot;,
  &quot;ingress.493694946.description&quot;: &quot;&quot;,
  &quot;ingress.493694946.from_port&quot;: &quot;80&quot;,
  &quot;ingress.493694946.ipv6_cidr_blocks.#&quot;: &quot;0&quot;,
  &quot;ingress.493694946.protocol&quot;: &quot;tcp&quot;,
  &quot;ingress.493694946.security_groups.#&quot;: &quot;0&quot;,
  &quot;ingress.493694946.self&quot;: &quot;false&quot;,
  &quot;ingress.493694946.to_port&quot;: &quot;8000&quot;,
  </code></pre>
  <p>Currently, in my Go tests, I hardcode the hash index values which I'd like to avoid. Here's an excerpt with 3 hard coded index values: <code>368698502</code>, <code>1552086545</code>, and <code>3172309932</code>:</p>
  <pre><code>resource.TestCheckResourceAttr(resourceName, &quot;workspace_configs.368698502.client_ip_header&quot;, &quot;Fastly-Client-IP&quot;),
  resource.TestCheckResourceAttr(resourceName, &quot;workspace_configs.368698502.instance_location&quot;, &quot;advanced&quot;),
  resource.TestCheckResourceAttr(resourceName, &quot;workspace_configs.368698502.listener_protocols.#&quot;, &quot;1&quot;),
  resource.TestCheckResourceAttr(resourceName, &quot;workspace_configs.368698502.listener_protocols.1552086545&quot;, &quot;https&quot;),
  resource.TestCheckResourceAttr(resourceName, &quot;workspace_configs.368698502.routes.#&quot;, &quot;1&quot;),
  resource.TestCheckResourceAttr(resourceName, &quot;workspace_configs.368698502.routes.3172309932.certificate_ids.#&quot;, &quot;0&quot;),
  resource.TestCheckResourceAttr(resourceName, &quot;workspace_configs.368698502.routes.3172309932.connection_pooling&quot;, &quot;true&quot;),
  </code></pre>
  <p>The full code is here: <a href="https://github.com/signalsciences/terraform-provider-sigsci/blob/main/provider/resource_corp_cloudwaf_instance_test.go" rel="nofollow noreferrer">https://github.com/signalsciences/terraform-provider-sigsci/blob/main/provider/resource_corp_cloudwaf_instance_test.go</a></p>
  <p>Is there a way to avoid hard coding the index values? For example, is it possible to create a function that fulfills the <code>CheckResourceAttrWithFunc</code> interface used with <code>TestCheckResourceAttrWith</code>?</p>