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

Remove newly added id attributes in resources #102

Merged
merged 1 commit into from
Oct 27, 2021

Conversation

stack72
Copy link
Contributor

@stack72 stack72 commented Oct 27, 2021

As part of #92, new "id" attributes were added to the schema for some
of the resources. These are not actually needed since they are part of
the plugin sdk by default. These parameters were not required before
and "id" is something that is available on ALL TF based resources

Because we (Pulumi) dervice our schema from your schema (and the plugin SDK)
we are getting the following error:

sdk/python/bin/build/lib/pulumi_civo/dns_domain_name.py:218: error: Duplicate argument "id" in function definition

If the schema needed these, then the make build would fail but it still works

▶ make build
==> Checking that code complies with gofmt requirements...
go install

You can see from the internals of the plugin SDK (helper/schema/resource_data.go),
the following func:

// SetId sets the ID of the resource. If the value is blank, then the
// resource is destroyed.
func (d *ResourceData) SetId(v string) {
	d.once.Do(d.init)
	d.newState.ID = v

	// once we transition away from the legacy state types, "id" will no longer
	// be a special field, and will become a normal attribute.
	// set the attribute normally
	d.setWriter.unsafeWriteField("id", v)

	// Make sure the newState is also set, otherwise the old value
	// may get precedence.
	if d.newState.Attributes == nil {
		d.newState.Attributes = map[string]string{}
	}
	d.newState.Attributes["id"] = v
}

So when you use d.SetID, it actually creates the ID attribute for you

As part of civo#92, new "id" attributes were added to the schema for some
of the resources. These are not actually needed since they are part of
the plugin sdk by default. These parameters were not required before
and "id" is something that is available on *ALL* TF based resources

Because we (Pulumi) dervice our schema from your schema (and the plugin SDK)
we are getting the following error:

```
sdk/python/bin/build/lib/pulumi_civo/dns_domain_name.py:218: error: Duplicate argument "id" in function definition
```

If the schema needed these, then the make build would fail but it still works

```
▶ make build
==> Checking that code complies with gofmt requirements...
go install
```

You can see from the internals of the plugin SDK (helper/schema/resource_data.go),
the following func:

```
// SetId sets the ID of the resource. If the value is blank, then the
// resource is destroyed.
func (d *ResourceData) SetId(v string) {
	d.once.Do(d.init)
	d.newState.ID = v

	// once we transition away from the legacy state types, "id" will no longer
	// be a special field, and will become a normal attribute.
	// set the attribute normally
	d.setWriter.unsafeWriteField("id", v)

	// Make sure the newState is also set, otherwise the old value
	// may get precedence.
	if d.newState.Attributes == nil {
		d.newState.Attributes = map[string]string{}
	}
	d.newState.Attributes["id"] = v
}
```

So when you use d.SetID, it actually creates the ID attribute for you
@alejandrojnm alejandrojnm merged commit 604a784 into civo:master Oct 27, 2021
Copy link
Member

@alejandrojnm alejandrojnm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants