Data source attributes not set?

I cannot for the life of me figure out why my data source is not setting attributes.
Here is my provider
Using the below testing code…

provider "orion" {
    host = "localhost"
    user = "test"
    password = "pass"
    ssl = false
}

data "orion_subnet" "test" {
    name = "test"
}

output "orion_subnet" {
    value = data.orion_subnet.test.address
}

I get a tfstate that shows nothing.

{
      "mode": "data",
      "type": "orion_subnet",
      "name": "test",
      "provider": "provider.orion",
      "instances": [
        {
          "schema_version": 0,
          "attributes": {
            "address": null,
            "address_mask": null,
            "available_count": null,
            "cidr": null,
            "display_name": null,
            "id": null,
            "name": null,
            "reserved": null,
            "reserved_count": null,
            "total_count": null,
            "transient_count": null,
            "used_count": null,
            "vlan": null
          }
        }
      ]
    }

The debug logs show that I am getting a resource, but nothing is being set in state.

from my debug statement on line 99

2020-01-06T12:29:20.160-0800 [DEBUG] plugin.terraform-provider-orion: time="2020-01-06T12:29:20-08:00" level=info msg="Subnet found: {%!s(int=1234) 10.199.152.0 %!s(int=23) test subnet test subnet %!s(int=200) %!s(int=2) %!s(int=181) %!s(int=512) NFS - VLAN 410 410 255.255.254.0}"

Not sure what I’m missing. My resource works great, but I seem to be having trouble with the data resource.

Edit: I’ve also set the ID with d.SetID(vlan) and I get the same result.

This was user error. I think I wasn’t rebuilding properly.

After setting ID attribute the data source worked.

1 Like