Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kubernetes_service requires port to be set in situations where kubernetes API doesn't. #26

Closed
shadycuz opened this issue Jul 10, 2017 · 3 comments · Fixed by #27
Closed
Labels

Comments

@shadycuz
Copy link

Terraform Version

levi@La-Tower:~$ terraform -v
Terraform v0.9.11

Affected Resource(s)

  • kubernetes_service

Terraform Configuration Files

resource "kubernetes_service" "my_external_name" {
  metadata {
    name = "my-external-name"
  }
  spec {
    type = "ExternalName"
    external_name = "google.com"
  }
}

Debug Output

https://gist.github.com/shadycuz/507fbd614b43aacd6a5a46edfbbfc834#file-gistfile1-txt

Expected Behavior

Service should be created, as described in the kubernetes service documentation.

Extract

An ExternalName service is a special case of service that does not have selectors. It does not define any ports or endpoints. Rather, it serves as a way to return an alias to an external service residing outside the cluster.

kind: Service
apiVersion: v1
metadata:
  name: my-service
  namespace: prod
spec:
  type: ExternalName
  externalName: my.database.example.com

When looking up the host my-service.prod.svc.CLUSTER, the cluster DNS service will return a CNAME record with the value my.database.example.com. Accessing such a service works in the same way as others, with the only difference that the redirection happens at the DNS level and no proxying or forwarding occurs. Should you later decide to move your database into your cluster, you can start its pods, add appropriate selectors or endpoints and change the service type.

Actual Behavior

Terraform throws an error.

1 error(s) occurred:

* kubernetes_service.my_external_name: "spec.0.port": required field is not set

If you set the port, it will then say you need to set target_port

Setting both of these will work, and the service will be created. The service does work as expected...

but I also created a service with out using terraform and ports were not required.

leviisbomb made with terraform forcing me to set the ports.
my-service made manually with out terraform.

image

Steps to Reproduce

Try to create a Kubernetes Service resource with out defining ports.

  1. terraform apply

Important Factoids

port is required per the terraform documentation but it in this case it is not actually required in kubernetes.

@radeksimko
Copy link
Member

Hi @shadycuz
thank you for noticing this and reporting it as bug.

I just submitted fix in #27

@shadycuz
Copy link
Author

You are welcome @radeksimko

It seems like a pretty easy fix but sometimes ports are required. Is it up to the user to follow the dependencies from the documenation of that resource?

If I try to execute a service that requires a port, will terraform error when I run plan or will it allow me to run apply and error when kubernetes rejects it?

just curious.

Thanks =)

@radeksimko
Copy link
Member

@shadycuz We don't have any good mechanisms to express conditional requirements (field being Required under some conditions) at this point in the core schema, so we just fall back to the API validation there.

The only caveat is that the failure will be raised during apply, not plan.

@ghost ghost locked and limited conversation to collaborators Apr 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants