Azure / Azure/bicep

Kubernetes Extensibility `core/Service@v1` has incorrect type for `targetPort` in VS Code extension

Open
#9,704 7 comments 0 reactions 1 assignee Claimed by @shenglol View on GitHub
story: extensibility
Dominant language
Bicep
Stars
3.6k
Forks
830
Avg merge
1d 4h
Merged PRs (30d)
81

Description

**Bicep version**

Bicep VSCode extension: `v0.13.1`
Bicep binary: `Bicep CLI version 0.13.1 (e3ac80d678)`

**Describe the bug**

`spec.ports.targetPort` has an incorrect type. It expects a string, however it should be an int instead.

Here's a valid template that deploys correctly:

```bicep
import 'kubernetes@1.0.0' with {
kubeConfig: kubeConfig
namespace: 'default'
}

resource frontendService 'core/Service@v1' = {
metadata: {
name: 'frontend'
labels: {
app: 'frontend'
}
}
spec: {
selector: {
app: 'frontend'
}
ports: [
{
port: 80
targetPort: 80 // The tooling expects this to be a string instead of an int
protocol: 'TCP'
}
]
type: 'LoadBalancer'
}
}
```

However I get the following warning:

image

When a string is used for deployment as suggested by the tooling, the following error is returned:

```txt
ERROR: ***"status":"Failed","error":***"code":"DeploymentFailed","message":"At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/arm-deployment-operations for usage details.","details":[***"code":"BadRequest","message":"***\r\n \"error\": ***\r\n \"code\": \"InvalidTemplateDeployment\",\r\n \"message\": \"The template deployment 'frontend' is not valid according to the validation procedure. The tracking id is 'ecb95883-861b-45f5-a8f4-057e19cd5e5a'. See inner errors for details.\",\r\n \"details\": [\r\n ***\r\n \"code\": \"UnprocessableEntity\",\r\n \"target\": \"/resources/frontendService\",\r\n \"message\": \"***\\\"kind\\\":\\\"Status\\\",\\\"apiVersion\\\":\\\"v1\\\",\\\"metadata\\\":***,\\\"status\\\":\\\"Failure\\\",\\\"message\\\":\\\"Service \\\\\\\"frontend\\\\\\\" is invalid: spec.ports[0].targetPort: Invalid value: \\\\\\\"80\\\\\\\": must contain at least one letter or number (a-z, 0-9)\\\",\\\"reason\\\":\\\"Invalid\\\",\\\"details\\\":***\\\"name\\\":\\\"frontend\\\",\\\"kind\\\":\\\"Service\\\",\\\"causes\\\":[***\\\"reason\\\":\\\"FieldValueInvalid\\\",\\\"message\\\":\\\"Invalid value: \\\\\\\"80\\\\\\\": must contain at least one letter or number (a-z, 0-9)\\\",\\\"field\\\":\\\"spec.ports[0].targetPort\\\"***]***,\\\"code\\\":422***\\n\"\r\n ***\r\n ]\r\n ***\r\n***"***]***
```

**To Reproduce**

Paste the above Bicep into VSCode and see the warning

**Additional context**
Add any other context about the problem here.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.