hashicorp / terraform-provider-azurerm

Terraform provider for Azure Resource Manager
https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs
Mozilla Public License 2.0
4.58k stars 4.62k forks source link

azurerm_api_management_api_operation with representation stops working after provider upgrade to 3.0 #16271

Closed wiktorn closed 2 years ago

wiktorn commented 2 years ago

Is there an existing issue for this?

Community Note

Terraform Version

1.1.7

AzureRM Provider Version

3.0.2

Affected Resource(s)/Data Source(s)

azurerm_api_management_api_operation

Terraform Configuration Files

resource "azurerm_api_management_api_operation" "example" {
...
    response {
        status_code = 200
        representation {
            content_type = "application/json"
            example {
                name = "default"
                value = "..."
            }
        }
    }
}

Debug Output/Panic Output

Error: flattening `request`: Invalid address to set: []string{"request", "0", "representation", "0", "sample"}

Expected Behaviour

No error

Actual Behaviour

Error is raised during plan.

Steps to Reproduce

  1. apply changes using 2.99.0 azurerm provider
  2. upgrade terraform provider to 3.0.2
  3. run terraform plan

Important Factoids

No response

References

It looks like there is a bug in internal/services/apimanagement/schemaz/api_management.go:202

It states:

if features.ThreePointOhBeta() && v.Examples["default"] != nil && v.Examples["default"].Value != nil {
    output["sample"] = v.Examples["default"].Value.(string)
}

And I think that it should be:

if !features.ThreePointOhBeta() && v.Examples["default"] != nil && v.Examples["default"].Value != nil {
    output["sample"] = v.Examples["default"].Value.(string)
}

Notice ! before features.ThreePointOhBeta(). We want to set output["sample"] only when we are on versions below 3.0, as above 3.0 this field is already deprecated and removed.

EDIT: probably the whole 3 lines can be removed. It's not like there will be any 2.x version release out of this code base.

Haven't tested this change yet.

stephybun commented 2 years ago

Hi @wiktorn,

Thanks for raising this issue and for the PR.

However I believe this has been fixed by #14848 which went out in v3.1.0. Could you try v3.1.0 of the provider and let us know whether your issue is resolved?

Thanks!

wiktorn commented 2 years ago

Sorry for late answer. I've rebased my PR #16273 on current main and indeed, using the commit 5e594aa0c3c3b53f2aef4a8c61ee741cf905d939 I'm no longer able to reproduce the issue. I haven't looked at how the changes from #14848 fixes this bug, but I still consider code removed in #16273 to be no longer needed.

github-actions[bot] commented 2 years ago

This functionality has been released in v3.3.0 of the Terraform Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

github-actions[bot] commented 2 years ago

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.