ably / terraform-provider-ably

Ably's Terraform Provider, enabling you to manage your Ably account programmatically.
https://registry.terraform.io/providers/ably/ably
Apache License 2.0
11 stars 2 forks source link

Optional parameters are not really optional at the moment #41

Closed kavalerov closed 2 years ago

kavalerov commented 2 years ago

Summary

There are certain parameters on each resource (i.e. tls_only on the ably_app resource) that are optional (at least in the Control API itself) - if user doesn't provide a value for them, there is a default value. However, right now when trying to apply a configuration without such optional resources Terraform complains about inconsistent results.

Expected result User can skip optional parameters in the terraform configuration.

Steps to reproduce

  1. Declare a new ably_app resource without defining optional parameters:
resource "ably_app" "app2" {
  name                      = "Sandbox2"
}
  1. Run terraform plan - should be successful
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # ably_app.app2 will be created
  + resource "ably_app" "app2" {
      + account_id = (known after apply)
      + id         = (known after apply)
      + name       = "Sandbox2"
    }

Plan: 1 to add, 0 to change, 0 to destroy.
  1. Run terraform apply - terraform will complain about inconsistent state
terraform apply
╷
│ Warning: Provider development overrides are in effect
│
│ The following provider development overrides are set in the CLI configuration:
│  - github.com/ably/ably in /Users/kavalerov/bin
│
│ The behavior may therefore not match any released version of the provider and applying changes may cause the state to become incompatible with published
│ releases.
╵
ably_app.app0: Refreshing state... [id=hPj47Q]
ably_app.app1: Refreshing state... [id=97O26Q]

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # ably_app.app2 will be created
  + resource "ably_app" "app2" {
      + account_id = (known after apply)
      + id         = (known after apply)
      + name       = "Sandbox2"
    }

Plan: 1 to add, 0 to change, 0 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

ably_app.app2: Creating...
╷
│ Error: Provider produced inconsistent result after apply
│
│ When applying changes to ably_app.app2, provider "provider[\"github.com/ably/ably\"]" produced an unexpected new value: .status: was null, but now
│ cty.StringVal("enabled").
│
│ This is a bug in the provider, which should be reported in the provider's own issue tracker.
╵
╷
│ Error: Provider produced inconsistent result after apply
│
│ When applying changes to ably_app.app2, provider "provider[\"github.com/ably/ably\"]" produced an unexpected new value: .tls_only: was null, but now
│ cty.False.
│
│ This is a bug in the provider, which should be reported in the provider's own issue tracker.
╵

┆Issue is synchronized with this Jira Task by Unito

kavalerov commented 2 years ago

While I file this as a bug, I am wondering if it actually the way it should be - when describing resource in Terraform there are no "optional" parameters - user needs to describe the infrastructure as it should be explicitly. @graham-russell wdyt?

kavalerov commented 2 years ago

Example of optional parameter in AWS provider: https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket#bucket

graham-russell commented 2 years ago

Yes, I think we should provide default values for params if they are undeclared in HCL. Good catch @kavalerov. I'll look into this one.

kavalerov commented 2 years ago

Similar thing is happening right now with the namespaces in #44 (related to #9 ) - I suggest we still fix this altogether as part of this ticket.

Morganamilo commented 2 years ago

This was fixed in #86

sync-by-unito[bot] commented 1 year ago

➤ Automation for Jira commented:

The link to the corresponding Jira issue is https://ably.atlassian.net/browse/SDK-3040