diff --git a/.changelog/6877.txt b/.changelog/6877.txt new file mode 100644 index 00000000000..30db9cfad6b --- /dev/null +++ b/.changelog/6877.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +container: promoted `managed_prometheus` field in google_container_cluster` to GA +``` diff --git a/google/resource_container_cluster.go b/google/resource_container_cluster.go index e3a08929b04..f7a63a873a8 100644 --- a/google/resource_container_cluster.go +++ b/google/resource_container_cluster.go @@ -807,6 +807,22 @@ func resourceContainerCluster() *schema.Resource { ValidateFunc: validation.StringInSlice([]string{"SYSTEM_COMPONENTS", "APISERVER", "CONTROLLER_MANAGER", "SCHEDULER"}, false), }, }, + "managed_prometheus": { + Type: schema.TypeList, + Optional: true, + Computed: true, + MaxItems: 1, + Description: `Configuration for Google Cloud Managed Services for Prometheus.`, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "enabled": { + Type: schema.TypeBool, + Required: true, + Description: `Whether or not the managed collection is enabled.`, + }, + }, + }, + }, }, }, }, @@ -3848,6 +3864,12 @@ func expandMonitoringConfig(configured interface{}) *container.MonitoringConfig EnableComponents: convertStringArr(enable_components), } } + if v, ok := config["managed_prometheus"]; ok && len(v.([]interface{})) > 0 { + managed_prometheus := v.([]interface{})[0].(map[string]interface{}) + mc.ManagedPrometheusConfig = &container.ManagedPrometheusConfig{ + Enabled: managed_prometheus["enabled"].(bool), + } + } return mc } @@ -4430,9 +4452,20 @@ func flattenMonitoringConfig(c *container.MonitoringConfig) []map[string]interfa if c.ComponentConfig != nil { result["enable_components"] = c.ComponentConfig.EnableComponents } + if c.ManagedPrometheusConfig != nil { + result["managed_prometheus"] = flattenManagedPrometheusConfig(c.ManagedPrometheusConfig) + } return []map[string]interface{}{result} } +func flattenManagedPrometheusConfig(c *container.ManagedPrometheusConfig) []map[string]interface{} { + return []map[string]interface{}{ + { + "enabled": c != nil && c.Enabled, + }, + } +} + func resourceContainerClusterStateImporter(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { config := meta.(*Config) diff --git a/google/resource_container_cluster_test.go b/google/resource_container_cluster_test.go index 034a9eda652..ce3f7a9e831 100644 --- a/google/resource_container_cluster_test.go +++ b/google/resource_container_cluster_test.go @@ -2255,6 +2255,34 @@ func TestAccContainerCluster_withMonitoringConfig(t *testing.T) { ImportStateVerify: true, ImportStateVerifyIgnore: []string{"min_master_version"}, }, + { + Config: testAccContainerCluster_withMonitoringConfigPrometheusUpdated(clusterName), + }, + { + ResourceName: "google_container_cluster.primary", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"min_master_version"}, + }, + // Back to basic settings to test setting Prometheus on its own + { + Config: testAccContainerCluster_basic_1_23_8(clusterName), + }, + { + ResourceName: "google_container_cluster.primary", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"min_master_version"}, + }, + { + Config: testAccContainerCluster_withMonitoringConfigPrometheusOnly(clusterName), + }, + { + ResourceName: "google_container_cluster.primary", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"min_master_version"}, + }, { Config: testAccContainerCluster_basic_1_23_8(clusterName), }, @@ -5753,7 +5781,7 @@ resource "google_container_cluster" "primary" { location = "us-central1-a" initial_node_count = 1 logging_config { - enable_components = [ "SYSTEM_COMPONENTS", "APISERVER", "CONTROLLER_MANAGER", "SCHEDULER", "WORKLOADS" ] + enable_components = [ "SYSTEM_COMPONENTS", "APISERVER", "CONTROLLER_MANAGER", "SCHEDULER"] } monitoring_config { enable_components = [ "SYSTEM_COMPONENTS" ] @@ -5800,6 +5828,40 @@ resource "google_container_cluster" "primary" { `, name) } +func testAccContainerCluster_withMonitoringConfigPrometheusUpdated(name string) string { + return fmt.Sprintf(` +resource "google_container_cluster" "primary" { + name = "%s" + location = "us-central1-a" + initial_node_count = 1 + min_master_version = "1.23.8-gke.1900" + monitoring_config { + enable_components = [ "SYSTEM_COMPONENTS", "APISERVER", "CONTROLLER_MANAGER", "SCHEDULER" ] + managed_prometheus { + enabled = true + } + } +} +`, name) +} + +func testAccContainerCluster_withMonitoringConfigPrometheusOnly(name string) string { + return fmt.Sprintf(` +resource "google_container_cluster" "primary" { + name = "%s" + location = "us-central1-a" + initial_node_count = 1 + min_master_version = "1.23.8-gke.1900" + monitoring_config { + enable_components = [] + managed_prometheus { + enabled = true + } + } +} +`, name) +} + func testAccContainerCluster_withSoleTenantGroup(name string) string { return fmt.Sprintf(` resource "google_compute_node_template" "soletenant-tmpl" { diff --git a/website/docs/r/container_cluster.html.markdown b/website/docs/r/container_cluster.html.markdown index 7332fbd5f22..1cc428c3ddd 100644 --- a/website/docs/r/container_cluster.html.markdown +++ b/website/docs/r/container_cluster.html.markdown @@ -540,7 +540,7 @@ This block also contains several computed attributes, documented below. * `enable_components` - (Optional) The GKE components exposing metrics. Supported values include: `SYSTEM_COMPONENTS`, `APISERVER`, `CONTROLLER_MANAGER`, and `SCHEDULER`. In beta provider, `WORKLOADS` is supported on top of those 4 values. (`WORKLOADS` is deprecated and removed in GKE 1.24.) -* `managed_prometheus` - (Optional, [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html)) Configuration for Managed Service for Prometheus. Structure is [documented below](#nested_managed_prometheus). +* `managed_prometheus` - (Optional) Configuration for Managed Service for Prometheus. Structure is [documented below](#nested_managed_prometheus). The `managed_prometheus` block supports: