github.com/khulnasoft-lab/defsec@v1.0.5-0.20230827010352-5e9f46893d95/avd_docs/google/gke/AVD-GCP-0054/Terraform.md (about)

     1  
     2  Use the COS image type
     3  
     4  ```hcl
     5   resource "google_service_account" "default" {
     6     account_id   = "service-account-id"
     7     display_name = "Service Account"
     8   }
     9   
    10   resource "google_container_cluster" "primary" {
    11     name     = "my-gke-cluster"
    12     location = "us-central1"
    13   
    14     # We can't create a cluster with no node pool defined, but we want to only use
    15     # separately managed node pools. So we create the smallest possible default
    16     # node pool and immediately delete it.
    17     remove_default_node_pool = true
    18     initial_node_count       = 1
    19   }
    20   
    21   resource "google_container_node_pool" "good_example" {
    22     name       = "my-node-pool"
    23     cluster    = google_container_cluster.primary.id
    24     node_count = 1
    25   
    26     node_config {
    27       preemptible  = true
    28       machine_type = "e2-medium"
    29   
    30       # Google recommends custom service accounts that have cloud-platform scope and permissions granted via IAM Roles.
    31       service_account = google_service_account.default.email
    32       oauth_scopes = [
    33         "https://www.googleapis.com/auth/cloud-platform"
    34       ]
    35       image_type = "COS"
    36     }
    37   }
    38   
    39  ```
    40  
    41  #### Remediation Links
    42   - https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/container_node_pool#image_type
    43