hashicorp / terraform-cdk

Define infrastructure resources using programming constructs and provision them using HashiCorp Terraform
https://www.terraform.io/cdktf
Mozilla Public License 2.0
4.8k stars 443 forks source link

"Terraform Apply" fail with 500 error when creating Azure ServiceBus Subscription. #1860

Closed iamzhaoxu closed 11 months ago

iamzhaoxu commented 2 years ago

Community Note

cdktf & Language Versions

cdktf : latest version Language: .NET 6.0.101

Affected Resource(s)

Azurerm - Azure ServiceBus Topic Subscription

Debug Output

https://gist.github.com/iamzhaoxu/7735a82b8694b04f9dbfa1519d136dad

Expected Behavior

I will expect the terraform application will not return a 500 error and create the subscription successfully.

Actual Behavior

It returns 500 error with more details links as https://aka.ms/eventhubsarmexceptions. However, there is nothing related to event hub resource at all in my terraform application.

Steps to Reproduce

Use the code below to create the service bus subscription can produce the error in the stack.

new ServicebusSubscription(this, "akashic_search_component_changed_delta_subscription",
            new ServicebusSubscriptionConfig
            {
                Name = "xxxx",
                TopicId = "xxxx",
                EnableBatchedOperations = true,
                DefaultMessageTtl = "PT24H",
                LockDuration = "PT2M",
                DeadLetteringOnMessageExpiration = false
            });

Important Factoids

When I try to use the code above to create the subscription, the cdktf synthn / ckdtf diff run successfully and does not return any error. The cdktf.json produce the resource as below:

 "resource": {
    "azurerm_servicebus_subscription": {
      "my_subscription": {
        "//": {
          "metadata": {
            "path": "my_app_dev_aae/my_subscription",
            "uniqueId": "my_app_my_subscription"
          }
        },
        "dead_lettering_on_message_expiration": false,
        "default_message_ttl": "xxxx",
        "enable_batched_operations": true,
        "lock_duration": "xxxx",
        "max_delivery_count": 0,
        "name": "xxxx",
        "topic_id": "xxxx"
      }
    }
  },

As you see max_delivery_count is 0 in the file. However, when I check the max_delivery_count on the azure portal, the max delivery count value has a range as 1~ 2000. So the 0 value is not valid for the configuration. image

The terraform CDK does not consider this value as a mandatory field. If I don't configure it in the code with a specified value, the default value of max_delivery_count will become 0. cdktf synthn or ckdtf diff commands do not validate it and let it go through. Then we apply the terraform, it will keep creating the subscription until it timeout and return a 500 error response.

It will be great if we can fail this with a proper reason before the terraform apply.

jsteinich commented 2 years ago

MaxDeliveryCount is technically required, but that information is lost when generating the C# bindings (it's present in TypeScript). https://github.com/aws/jsii/issues/715 has more information. C# 11 will potentially have required properties which may be another way to fix this.

github-actions[bot] commented 10 months 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've 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.