Introduction
With the release of the Coder Terraform provider version 2.0, owner
attribute of the coder_workspace
data source has been removed.
This change causes impacted templates to generate the following error:
This object has no argument, nested block, or exported attribute named "owner".
This guide explains how to update your Coder templates to retrieve the workspace owner name using the new coder_workspace_owner
data source.
What Has Changed?
The owner
attribute is no longer available in the coder_workspace
data source. Instead, templates must now use the coder_workspace_owner
data source to retrieve the owner name.
How to Update Your Configuration
Follow these steps to modify your Terraform configuration and ensure compatibility with version 2.0 of the Coder Terraform provider:
Step 1: Add the coder_workspace_owner
Data Source
Introduce the new coder_workspace_owner
data source in your Terraform configuration. For example:
data "coder_workspace_owner" "me" {}
Step 2: Update References to the Owner Attribute
Replace all references to the deprecated ${lower(data.coder_workspace.me.owner)}
with the new syntax:
${lower(data.coder_workspace_owner.me.name)}
This ensures that your configuration retrieves the owner name from the correct data source.
Example Configuration Update
Below is an example of a Terraform configuration before and after the update:
Before Update
data "coder_workspace" "me" {
name = "my-workspace"
}
output "workspace_owner" {
value = lower(data.coder_workspace.me.owner)
}
After Update
data "coder_workspace" "me" {
name = "my-workspace"
}
data "coder_workspace_owner" "me" {}
output "workspace_owner" {
value = lower(data.coder_workspace_owner.example_owner.name)
}
Testing and Validation
After updating your configuration, validate your changes using terraform plan
. This will confirm that your configuration is compatible with the Coder Terraform provider versions 2.0 or greater and ensure there are no syntax or runtime errors.
Conclusion
The removal of the workspace owner
attribute in the coder_workspace
data source requires users to adopt the coder_workspace_owner
data source in their Terraform configurations. By following the steps outlined in this guide, you can seamlessly transition to the updated provider and continue managing your infrastructure efficiently.
For more information, refer to the official Coder Terraform documentation.