hashicorp / terraform-provider-google

Terraform Provider for Google Cloud Platform
https://registry.terraform.io/providers/hashicorp/google/latest/docs
Mozilla Public License 2.0
2.36k stars 1.75k forks source link

GKE Nodepool Custom Image VPC #3417

Open chrislovecnm opened 5 years ago

chrislovecnm commented 5 years ago

Community Note

Description

Add the capability to define a custom image name in TF. When defining a node_config add the capability to define an image name.

Add the capability to define the VPC that a google image lives in for a GKE cluster. When defining a node_config you have able to define an image_type. An image may live in a different vpc, from where the GKE cluster resides.

New or Affected Resource(s)

Potential Terraform Configuration

resource "google_container_node_pool" "primary_preemptible_nodes" {
  name       = "my-node-pool"
  location   = "us-central1"
  cluster    = "${google_container_cluster.primary.name}"
  node_count = 1

  node_config {
    image_type = "CUSTOM"
    image = "my-image"
    image_vpc = "my-vpc"

    preemptible  = true
    machine_type = "n1-standard-1"

    metadata {
      disable-legacy-endpoints = "true"
    }

    oauth_scopes = [
      "https://www.googleapis.com/auth/logging.write",
      "https://www.googleapis.com/auth/monitoring",
    ]
  }
}

References

This is a valid command in gcloud

gcloud container node-pools create test-cos --cluster=test-infra \
--image-type=CUSTOM --image=cos-test \
--image-project=cos-gke-test --machine-type=custom-96-230400 \
--node-version=1.11.6-gke.2 --num-nodes=2 --zone=us-central1-c
--project=test --min-cpu-platform=skylake

The above command will create a node pool using the cos-gke-test machine image. This image lives in the cos-gke-test project, while the gke cluster lives in the test project.

b/351038278

emilymye commented 5 years ago

May I ask where you saw this gcloud command? I can't find documentation for this feature, so a link to the docs, API reference, or similar would be helpful.

I also just updated my gcloud and I get this output from running gcloud beta container node-pools create (GA returns subset of these flags):

gcloud beta container node-pools create NAME [optional flags]
  optional flags may be  --accelerator | --cluster | --disk-size | --disk-type |
                         --enable-autorepair | --enable-autoscaling |
                         --enable-autoupgrade | --enable-cloud-endpoints |
                         --help | --image-type | --local-ssd-count |
                         --machine-type | --max-nodes | --max-pods-per-node |
                         --metadata | --metadata-from-file |
                         --min-cpu-platform | --min-nodes | --node-labels |
                         --node-taints | --node-version | --num-nodes |
                         --preemptible | --region | --scopes |
                         --service-account | --tags |
                         --workload-metadata-from-node | --zone

which doesn't include image or image-project. Do you mind running this gcloud command with --log-http to show what it's calling?

chrislovecnm commented 5 years ago

Yah once I have a service account I will. Super secret ninja magic. The command was provided to me via google support.

eyalzek commented 5 years ago

@chrislovecnm any update on this?

roaks3 commented 4 months ago

It looks like there might be an existing undocumented field in the API called nodeImageConfig under nodeConfig that supports these image fields when imageType is CUSTOM. I can't quite tell which API(s) support this field, but my best guess is that it is available and could be added to TF.