Skip to content

Commit

Permalink
parse_resource_id should not accepet nullable input (#593)
Browse files Browse the repository at this point in the history
* `parse_resource_id` should not accepet nullable input

* update testcase
  • Loading branch information
ms-henglu authored Aug 29, 2024
1 parent 2cde423 commit 374779f
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 26 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ BREAKING CHANGES:
- The `body` field now only accepts an HCL object. Please remove the `jsondecode` function when using the `body` field.
- The `output` field now only exports an HCL object. Please remove the `jsondecode` function when using the `output` field.

FEATURES:
- **New Provider Function**: build_resource_id
- **New Provider Function**: parse_resource_id
- **New Provider Function**: subscription_resource_id
- **New Provider Function**: tenant_resource_id
- **New Provider Function**: management_group_resource_id
- **New Provider Function**: resource_group_resource_id
- **New Provider Function**: extension_resource_id

ENHANCEMENTS:
- `azapi_resource` resource: Support `replace_triggers_external_values` field which is used to trigger a replacement of the resource.
- `azapi` resources and data sources: Support `retry` field, which is used to specify the retry configuration.
Expand Down
4 changes: 2 additions & 2 deletions docs/functions/parse_resource_id.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ locals {
# "virtualNetworks" = "myVNet"
# })
# "provider_namespace" = "Microsoft.Network"
# "resource_gr oup_name" = "myResourceGroup"
# "resource_group_name" = "myResourceGroup"
# "subscription_id" = "00000000-0000-0000-0000-000000000000"
# "type" = "Microsoft.Network/virtualNetworks"
# }
Expand All @@ -50,5 +50,5 @@ parse_resource_id(resource_type string, resource_id string) object

<!-- arguments generated by tfplugindocs -->
1. `resource_type` (String) The resource type of the Azure resource.
1. `resource_id` (String, Nullable) The resource ID of the Azure resource to parse.
1. `resource_id` (String) The resource ID of the Azure resource to parse.

2 changes: 1 addition & 1 deletion examples/functions/parse_resource_id/function.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ locals {
# "virtualNetworks" = "myVNet"
# })
# "provider_namespace" = "Microsoft.Network"
# "resource_gr oup_name" = "myResourceGroup"
# "resource_group_name" = "myResourceGroup"
# "subscription_id" = "00000000-0000-0000-0000-000000000000"
# "type" = "Microsoft.Network/virtualNetworks"
# }
Expand Down
14 changes: 2 additions & 12 deletions internal/services/functions/parse_resource_id_function.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ func (p *ParseResourceIdFunction) Definition(ctx context.Context, request functi
MarkdownDescription: "The resource type of the Azure resource.",
},
function.StringParameter{
AllowNullValue: true,
AllowUnknownValues: true,
AllowNullValue: false,
AllowUnknownValues: false,
Name: "resource_id",
Description: "The resource ID of the Azure resource to parse.",
MarkdownDescription: "The resource ID of the Azure resource to parse.",
Expand All @@ -70,16 +70,6 @@ func (p *ParseResourceIdFunction) Run(ctx context.Context, request function.RunR
return
}

if resourceId.IsNull() {
response.Error = response.Result.Set(ctx, types.ObjectNull(ParseResourceIdResultAttrTypes))
return
}

if resourceId.IsUnknown() {
response.Error = response.Result.Set(ctx, types.ObjectUnknown(ParseResourceIdResultAttrTypes))
return
}

resourceType := utils.TryAppendDefaultApiVersion(resourceTypeParam)

id, err := parse.ResourceIDWithResourceType(resourceId.ValueString(), resourceType)
Expand Down
11 changes: 0 additions & 11 deletions internal/services/functions/parse_resource_id_function_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,17 +148,6 @@ func TestParseResourceIdFunction(t *testing.T) {
Result: function.NewResultData(types.ObjectUnknown(functions.ParseResourceIdResultAttrTypes)),
},
},
"unknown-resource-id": {
request: function.RunRequest{
Arguments: function.NewArgumentsData([]attr.Value{
types.StringValue("Microsoft.Network/virtualNetworks"),
types.StringUnknown(),
}),
},
expected: function.RunResponse{
Result: function.NewResultData(types.ObjectUnknown(functions.ParseResourceIdResultAttrTypes)),
},
},
}

for name, testCase := range testCases {
Expand Down

0 comments on commit 374779f

Please sign in to comment.