Skip to content

Commit

Permalink
feat: Remove force replacement from gcfs_config (GoogleCloudPlatform#…
Browse files Browse the repository at this point in the history
  • Loading branch information
dominykasn authored and iyabchen committed Sep 14, 2024
1 parent 0718d4a commit 2971b87
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,12 @@ func schemaLoggingVariant() *schema.Schema {
}
}

func schemaGcfsConfig(forceNew bool) *schema.Schema {
func schemaGcfsConfig() *schema.Schema {
return &schema.Schema{
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Description: `GCFS configuration for this node.`,
ForceNew: forceNew,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"enabled": {
Expand Down Expand Up @@ -339,7 +338,7 @@ func schemaNodeConfig() *schema.Schema {
},
},

"gcfs_config": schemaGcfsConfig(true),
"gcfs_config": schemaGcfsConfig(),

"gvnic": {
Type: schema.TypeList,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func clusterSchemaNodePoolDefaults() *schema.Schema {
Schema: map[string]*schema.Schema{
"containerd_config": schemaContainerdConfig(),
{{- if ne $.TargetVersionName "ga" }}
"gcfs_config": schemaGcfsConfig(false),
"gcfs_config": schemaGcfsConfig(),
{{- end }}
"insecure_kubelet_readonly_port_enabled": schemaInsecureKubeletReadonlyPortEnabled(),
"logging_variant": schemaLoggingVariant(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1718,7 +1718,11 @@ func TestAccContainerNodePool_gcfsConfig(t *testing.T) {
CheckDestroy: testAccCheckContainerNodePoolDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccContainerNodePool_gcfsConfig(cluster, np, networkName, subnetworkName),
Config: testAccContainerNodePool_gcfsConfig(cluster, np, networkName, subnetworkName, true),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("google_container_node_pool.np",
"node_config.0.gcfs_config.0.enabled", "true"),
),
},
{
ResourceName: "google_container_node_pool.np",
Expand All @@ -1729,7 +1733,7 @@ func TestAccContainerNodePool_gcfsConfig(t *testing.T) {
})
}

func testAccContainerNodePool_gcfsConfig(cluster, np, networkName, subnetworkName string) string {
func testAccContainerNodePool_gcfsConfig(cluster, np, networkName, subnetworkName string, enabled bool) string {
return fmt.Sprintf(`
resource "google_container_cluster" "cluster" {
name = "%s"
Expand All @@ -1750,11 +1754,11 @@ resource "google_container_node_pool" "np" {
machine_type = "n1-standard-8"
image_type = "COS_CONTAINERD"
gcfs_config {
enabled = true
enabled = %t
}
}
}
`, cluster, networkName, subnetworkName, np)
`, cluster, networkName, subnetworkName, np, enabled)
}

func TestAccContainerNodePool_gvnic(t *testing.T) {
Expand Down Expand Up @@ -4734,30 +4738,30 @@ func TestAccContainerNodePool_privateRegistry(t *testing.T) {

func testAccContainerNodePool_privateRegistryEnabled(secretID, cluster, nodepool, network, subnetwork string) string {
return fmt.Sprintf(`
data "google_project" "test_project" {
data "google_project" "test_project" {
}

resource "google_secret_manager_secret" "secret-basic" {
secret_id = "%s"
replication {
user_managed {
replicas {
location = "us-central1"
}
}
}
}

resource "google_secret_manager_secret" "secret-basic" {
secret_id = "%s"
replication {
user_managed {
replicas {
location = "us-central1"
}
}
}
}

resource "google_secret_manager_secret_version" "secret-version-basic" {
secret = google_secret_manager_secret.secret-basic.id
secret_data = "dummypassword"
}

resource "google_secret_manager_secret_iam_member" "secret_iam" {
secret_id = google_secret_manager_secret.secret-basic.id
role = "roles/secretmanager.admin"
member = "serviceAccount:${data.google_project.test_project.number}[email protected]"
depends_on = [google_secret_manager_secret_version.secret-version-basic]
resource "google_secret_manager_secret_version" "secret-version-basic" {
secret = google_secret_manager_secret.secret-basic.id
secret_data = "dummypassword"
}

resource "google_secret_manager_secret_iam_member" "secret_iam" {
secret_id = google_secret_manager_secret.secret-basic.id
role = "roles/secretmanager.admin"
member = "serviceAccount:${data.google_project.test_project.number}[email protected]"
depends_on = [google_secret_manager_secret_version.secret-version-basic]
}

resource "google_container_cluster" "cluster" {
Expand All @@ -4768,13 +4772,13 @@ resource "google_container_cluster" "cluster" {
network = "%s"
subnetwork = "%s"
}

resource "google_container_node_pool" "np" {
name = "%s"
location = "us-central1-a"
cluster = google_container_cluster.cluster.name
initial_node_count = 1

node_config {
oauth_scopes = [
"https://www.googleapis.com/auth/cloud-platform",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,19 +100,17 @@ func schemaLoggingVariant() *schema.Schema {
}
}

func schemaGcfsConfig(forceNew bool) *schema.Schema {
func schemaGcfsConfig() *schema.Schema {
return &schema.Schema{
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Description: `GCFS configuration for this node.`,
ForceNew: forceNew,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"enabled": {
Type: schema.TypeBool,
Required: true,
ForceNew: forceNew,
Description: `Whether or not GCFS is enabled`,
},
},
Expand Down Expand Up @@ -340,7 +338,7 @@ func schemaNodeConfig() *schema.Schema {
},
},

"gcfs_config": schemaGcfsConfig(true),
"gcfs_config": schemaGcfsConfig(),

"gvnic": {
Type: schema.TypeList,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func clusterSchemaNodePoolDefaults() *schema.Schema {
Schema: map[string]*schema.Schema{
"containerd_config": schemaContainerdConfig(),
<% unless version == 'ga' -%>
"gcfs_config": schemaGcfsConfig(false),
"gcfs_config": schemaGcfsConfig(),
<% end -%>
"insecure_kubelet_readonly_port_enabled": schemaInsecureKubeletReadonlyPortEnabled(),
"logging_variant": schemaLoggingVariant(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1719,7 +1719,11 @@ func TestAccContainerNodePool_gcfsConfig(t *testing.T) {
CheckDestroy: testAccCheckContainerNodePoolDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccContainerNodePool_gcfsConfig(cluster, np, networkName, subnetworkName),
Config: testAccContainerNodePool_gcfsConfig(cluster, np, networkName, subnetworkName, true),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("google_container_node_pool.np",
"node_config.0.gcfs_config.0.enabled", "true"),
),
},
{
ResourceName: "google_container_node_pool.np",
Expand All @@ -1730,7 +1734,7 @@ func TestAccContainerNodePool_gcfsConfig(t *testing.T) {
})
}

func testAccContainerNodePool_gcfsConfig(cluster, np, networkName, subnetworkName string) string {
func testAccContainerNodePool_gcfsConfig(cluster, np, networkName, subnetworkName string, enabled bool) string {
return fmt.Sprintf(`
resource "google_container_cluster" "cluster" {
name = "%s"
Expand All @@ -1751,11 +1755,11 @@ resource "google_container_node_pool" "np" {
machine_type = "n1-standard-8"
image_type = "COS_CONTAINERD"
gcfs_config {
enabled = true
enabled = %t
}
}
}
`, cluster, networkName, subnetworkName, np)
`, cluster, networkName, subnetworkName, np, enabled)
}

func TestAccContainerNodePool_gvnic(t *testing.T) {
Expand Down Expand Up @@ -4735,30 +4739,30 @@ func TestAccContainerNodePool_privateRegistry(t *testing.T) {

func testAccContainerNodePool_privateRegistryEnabled(secretID, cluster, nodepool, network, subnetwork string) string {
return fmt.Sprintf(`
data "google_project" "test_project" {
data "google_project" "test_project" {
}

resource "google_secret_manager_secret" "secret-basic" {
secret_id = "%s"
replication {
user_managed {
replicas {
location = "us-central1"
}
}
}
}

resource "google_secret_manager_secret" "secret-basic" {
secret_id = "%s"
replication {
user_managed {
replicas {
location = "us-central1"
}
}
}
}

resource "google_secret_manager_secret_version" "secret-version-basic" {
secret = google_secret_manager_secret.secret-basic.id
secret_data = "dummypassword"
}

resource "google_secret_manager_secret_iam_member" "secret_iam" {
secret_id = google_secret_manager_secret.secret-basic.id
role = "roles/secretmanager.admin"
member = "serviceAccount:${data.google_project.test_project.number}[email protected]"
depends_on = [google_secret_manager_secret_version.secret-version-basic]
resource "google_secret_manager_secret_version" "secret-version-basic" {
secret = google_secret_manager_secret.secret-basic.id
secret_data = "dummypassword"
}

resource "google_secret_manager_secret_iam_member" "secret_iam" {
secret_id = google_secret_manager_secret.secret-basic.id
role = "roles/secretmanager.admin"
member = "serviceAccount:${data.google_project.test_project.number}[email protected]"
depends_on = [google_secret_manager_secret_version.secret-version-basic]
}

resource "google_container_cluster" "cluster" {
Expand All @@ -4769,13 +4773,13 @@ resource "google_container_cluster" "cluster" {
network = "%s"
subnetwork = "%s"
}

resource "google_container_node_pool" "np" {
name = "%s"
location = "us-central1-a"
cluster = google_container_cluster.cluster.name
initial_node_count = 1

node_config {
oauth_scopes = [
"https://www.googleapis.com/auth/cloud-platform",
Expand Down

0 comments on commit 2971b87

Please sign in to comment.