inspec / inspec-gcp

InSpec GCP (Google Cloud Platform) Resource Pack
https://www.inspec.io/
Other
148 stars 70 forks source link

Nodepool resource google_container_node_pool fails to get config.taints.XXX resources #637

Closed varunthakur2480 closed 3 weeks ago

varunthakur2480 commented 3 months ago

I am trying to add some checks on my GKE nodepool resources and using the documentation to get the following its('config.taints.key') {should eq "cloud.google.com/gke-spot"} its('config.taints.value') {should be true} its('config.taints.effect') {should eq "NO_SCHEDULE"}

But it fails with following error undefined method key' for #<Array:0x0000000008dc1e70> [2024-06-28 13:18:41] × NodePool abc-20240628065114347700000001 config.taints.value [2024-06-28 13:18:41] undefined methodvalue' for # [2024-06-28 13:18:41] × NodePool abc-20240628065114347700000001 config.taints.effect [2024-06-28 13:18:41] undefined method effect' for #<Array:0x0000000008dc1e70> [2024-06-28 13:18:41] × NodePool abc-20240628065114347700000001 config.spot [2024-06-28 13:18:41] undefined methodspot' for #<#::GoogleInSpec::Container::Property::NodePoolConfig:0x0000000008dc1ee8>

I am using inspec-gcp-1.11.101.tar.gz binary

Possible Solution

sa-progress commented 3 weeks ago

Hi @varunthakur2480

The Nodepool resource appears to be functioning correctly. The issue you’re encountering is likely due to the absence of configurations. You can use the following approach to handle this:

node_pool = google_container_node_pool(project: gcp_project_id, location: gcp_kube_cluster_zone, cluster_name: gcp_kube_cluster_name, nodepool_name: regional_node_pool['name'])

  taints = node_pool.config.taints
  taints&.each do |taint|
      describe taint do
        its('key') { should eq 'cloud.google.com/gke-spot' }
        its('value') { should eq 'true' }
        its('effect') { should eq 'NO_SCHEDULE' }
      end
  end

response -

Screenshot 2024-09-10 at 3 09 20 PM