Skip to content

Commit

Permalink
Promoted managed_prometheus field in google_container_cluster` to GA (
Browse files Browse the repository at this point in the history
#6877) (#13150)

Signed-off-by: Modular Magician <magic-modules@google.com>

Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician committed Nov 30, 2022
1 parent 3cf7155 commit f9dece2
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .changelog/6877.txt
@@ -0,0 +1,3 @@
```release-note:enhancement
container: promoted `managed_prometheus` field in google_container_cluster` to GA
```
33 changes: 33 additions & 0 deletions google/resource_container_cluster.go
Expand Up @@ -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.`,
},
},
},
},
},
},
},
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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)

Expand Down
64 changes: 63 additions & 1 deletion google/resource_container_cluster_test.go
Expand Up @@ -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),
},
Expand Down Expand Up @@ -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" ]
Expand Down Expand Up @@ -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" {
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/container_cluster.html.markdown
Expand Up @@ -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).

<a name="nested_managed_prometheus"></a>The `managed_prometheus` block supports:

Expand Down

0 comments on commit f9dece2

Please sign in to comment.