terraform-provider-kubernetes
terraform-provider-kubernetes copied to clipboard
Init container doesn't support restart_policy option (to transform it in a sidecar container)
Terraform Version, Provider Version and Kubernetes Version
Terraform version: 1.6.2
Kubernetes provider version: 2.27.0
Kubernetes version: 1.19
Affected Resource(s)
Terraform Configuration Files
resource "kubernetes_deployment_v1" "example" {
metadata {
name = "terraform-example"
labels = {
test = "MyExampleApp"
}
}
spec {
replicas = 3
selector {
match_labels = {
test = "MyExampleApp"
}
}
template {
metadata {
labels = {
test = "MyExampleApp"
}
}
spec {
container {
name = "example"
image = "nginx:1.21.6"
# Init container
init_container {
name = "init-setup"
image = "busybox:latest"
restart_policy = "Always"
}
}
}
}
}
Debug Output
Terraform v1.6.2
on linux_amd64
Initializing plugins and modules...
╷
│ Error: Unsupported argument
│
│ on app.tf line XX, in resource "kubernetes_deployment_v1" "this":
│ XX: restart_policy = "Always"
│
│ An argument named "restart_policy" is not expected here.
╵
Operation failed: failed running terraform plan (exit 1)
Panic Output
Steps to Reproduce
- Create a ressource kubernetes_deployment_v1 with init container and set the option restart_policy of the init container to "Always" to transform it in a sidecar.
- Apply your code
Expected Behavior
Pod with sidecar init container created
Actual Behavior
Option non supported
Important Factoids
References
- https://kubernetes.io/docs/concepts/workloads/pods/sidecar-containers/
Community Note
- Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
- If you are interested in working on this issue or have submitted a pull request, please leave a comment
Enabled by default with Kubernetes 1.29, a [feature gate](https://kubernetes.io/docs/reference/command-line-tools-reference/feature-gates/) named SidecarContainers allows you to specify a restartPolicy for containers listed in a Pod's initContainers field.
These restartable sidecar containers are independent with other [init containers](https://kubernetes.io/docs/concepts/workloads/pods/init-containers/) and main application container within the same pod.
These can be started, stopped, or restarted without effecting the main application container and other init containers.
Hello @arthurgur, thanks for opening this issue! With this being marked as beta in v1.29, we can proceed with adding this into the provider. You are open to creating a PR that adds this since this is just adding a new field within https://github.com/hashicorp/terraform-provider-kubernetes/blob/bff3ae2a2cc4552fc8da1ba57720f652f8b1beaa/kubernetes/schema_container.go#L256
we can guide you in adding the field and also adding tests that check for this.
Hello @BBBmau, thanks for your reply. Unfortunately I don't have rights to create a branch (or I dont know how, it's my first contribution).
@arthurgur no worries, be sure to look at our contributing guidelines., I would look into also the section on Pull Request Lifecycle since this is your first contribution.