Skip to content
This repository was archived by the owner on Jan 23, 2025. It is now read-only.

Commit

Permalink
fix(google): Fix GKE legacy endpoint use detection (#497)
Browse files Browse the repository at this point in the history
Resolves #470

Signed-off-by: Liam Galvin <[email protected]>
  • Loading branch information
liamg committed Apr 7, 2022
1 parent 074d1f1 commit e23b8b7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
10 changes: 7 additions & 3 deletions internal/adapters/terraform/google/gke/adapt.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,13 @@ func (a *adapter) adaptCluster(resource *terraform.Block, module *terraform.Modu
cluster.PodSecurityPolicy.Enabled = enabledAttr.AsBoolValueOrDefault(false, policyBlock)
}

legacyMetadataAttr := resource.GetNestedAttribute("metadata.disable-legacy-endpoints")
if legacyMetadataAttr.IsNotNil() && legacyMetadataAttr.IsTrue() {
cluster.ClusterMetadata.EnableLegacyEndpoints = types.Bool(false, legacyMetadataAttr.GetMetadata())
legacyMetadataAttr := resource.GetNestedAttribute("node_config.metadata.disable-legacy-endpoints")
if legacyMetadataAttr.IsNotNil() {
if legacyMetadataAttr.IsTrue() {
cluster.ClusterMetadata.EnableLegacyEndpoints = types.Bool(false, legacyMetadataAttr.GetMetadata())
} else if legacyMetadataAttr.IsFalse() {
cluster.ClusterMetadata.EnableLegacyEndpoints = types.Bool(true, legacyMetadataAttr.GetMetadata())
}
}

if masterBlock := resource.GetBlock("master_auth"); masterBlock.IsNotNil() {
Expand Down
16 changes: 10 additions & 6 deletions internal/rules/google/gke/metadata_endpoints_disabled.tf.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,22 @@ package gke
var terraformMetadataEndpointsDisabledGoodExamples = []string{
`
resource "google_container_cluster" "good_example" {
metadata {
disable-legacy-endpoints = true
}
node_config {
metadata {
disable-legacy-endpoints = true
}
}
}`,
}

var terraformMetadataEndpointsDisabledBadExamples = []string{
`
resource "google_container_cluster" "bad_example" {
metadata {
disable-legacy-endpoints = false
}
node_config {
metadata {
disable-legacy-endpoints = false
}
}
}`,
}

Expand Down

0 comments on commit e23b8b7

Please sign in to comment.