So I've got an odd create/refresh issue, and I'm n...
# general
h
So I've got an odd create/refresh issue, and I'm not sure if it's a bug with pulumi or the terraform-openstack-provider. The problem is that openstack.networking.network defines a field called "segments" in it's schema (https://github.com/terraform-providers/terraform-provider-openstack/blob/master/openstack/resource_openstack_networking_network_v2.go#L69). When I create a network with pulumi and don't set this attribute (because it's optional and honestly I'm not actually sure what its for) there is no "segments" field set in the state file, that's because the openstack terraform provider never returns it as an attribute (see the read method, which is used as the return for create as well https://github.com/terraform-providers/terraform-provider-openstack/blob/master/openstack/resource_openstack_networking_network_v2.go#L201). So MAYBE this is a bug on terraform that there's no way to mark an attribute as input only? At any rate if I then call refresh pulumi then ADDS a segments field, it seems because it fills in all default values for inputs (which includes segments) passes that struct to terraform Refresh which calls read to fill in that struct, but it doesn't remove the segments field. So yeh not sure who's really at fault here, but did wonder if providers are prone to doing things like this if pulumi could just not fill in the default fields at all before passing to Refresh?
m
This is probably the fault of the Terraform bridge. I’ll look into it today.
Okay, yes--this is definitely the fault of tfbridge. When constructing a Terraform resource state from a Pulumi resource state, we convert the state to a TF resource config and then read each field out of the config: https://github.com/pulumi/pulumi-terraform/blob/master/pkg/tfbridge/schema.go#L580-L597
It looks like we may be a bit overzealous w.r.t. the fields we read. Rather than reading only those fields which are defined by the input state, we read all fields defined by the TF schema.
As a consequence of this, TF ends up handing back empty default values for some undefined fields.
This is the theory, at least. 🙂 It's a bit surprising that we don't see this in other parts of the bridge that use the relevant function, but nothing else jumps out at me.
h
Ah ok, if you get a change together I can try and test it out
@microscopic-florist-22719 I gave your pgavlin/attributes branch of pulumi-terraform a go and it fixed this problem of the network erroneously being updated 👍
m
Glad to hear it! I’ll see if I can get it polished off and properly tested. Thanks for giving it a go :)