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

resource id should be readonly. space name on datasource should be optional #770

Merged
merged 4 commits into from
Aug 29, 2024

Conversation

benPearce1
Copy link
Collaborator

setup:

resource "octopusdeploy_lifecycle" "lifecycle" {
  id = "Lifecycles-1"
  space_id = data.octopusdeploy_space.space.id
  name = "lifecycle 2"
}

on 0.22.1

# octopusdeploy_lifecycle.lifecycle will be created
  + resource "octopusdeploy_lifecycle" "lifecycle" {
      + description = "description2"
      + id          = (known after apply)
      + name        = "lifecycle 2"
      + space_id    = "Spaces-1"
...

Lifecycle resource was created with id of Lifecycles-1762. From state:

"id": "Lifecycles-1762",
"name": "lifecycle 2",

Plan with 0.30.0-beta8

# octopusdeploy_lifecycle.lifecycle will be updated in-place
  ~ resource "octopusdeploy_lifecycle" "lifecycle" {
      ~ id          = "Lifecycles-1762" -> "Lifecycles-1"
        name        = "lifecycle 2"
        # (2 unchanged attributes hidden)

        # (2 unchanged blocks hidden)
    }

Plan now fails validation as Id is readonly:

│ Error: Invalid Configuration for Read-Only Attribute
│ 
│   with octopusdeploy_lifecycle.lifecycle,
│   on main.tf line 32, in resource "octopusdeploy_lifecycle" "lifecycle":
│   32:   id = "Lifecycles-1"
│ 
│ Cannot set value for this attribute as the provider has marked it as read-only. Remove the configuration line setting the value.
│ 
│ Refer to the provider documentation or contact the provider developers for additional information about configurable and read-only attributes that are
│ supported.
╵

@@ -130,7 +130,6 @@ func GetIdResourceSchema() resourceSchema.Attribute {
return resourceSchema.StringAttribute{
Description: "The unique ID for this resource.",
Computed: true,
Optional: true,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This means that the user cannot set the Id and will get an error

"description": GetReadonlyDescriptionDatasourceSchema(spaceDescription),
"name": datasourceSchema.StringAttribute{
Description: fmt.Sprintf("The name of this resource, no more than %d characters long", 20),
Validators: []validator.String{
stringvalidator.LengthBetween(1, 20),
},
Computed: true,
Optional: true,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Looks like this was broken from #759

Description: "The ID of this resource.",
Computed: true,
},
SchemaAttributeNames.ID: GetIdResourceSchema(),
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Use the helper function for consistency

Copy link
Contributor

@domenicsim1 domenicsim1 left a comment

Choose a reason for hiding this comment

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

Good catch 🪝

@benPearce1 benPearce1 merged commit 4d9acca into main Aug 29, 2024
22 checks passed
@benPearce1 benPearce1 deleted the bp/resource-id-readonly branch August 29, 2024 22:53
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.

2 participants