Skip to content

Commit 3321bf4

Browse files
Add support for brokerCapacityConfig for managedkafka (#15638) (#25074)
[upstream:abf05ffe9573613da8cdd17664204643770bf403] Signed-off-by: Modular Magician <[email protected]>
1 parent 8781007 commit 3321bf4

File tree

6 files changed

+78
-3
lines changed

6 files changed

+78
-3
lines changed

.changelog/15638.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
managedkafka: added `broker_capacity_config` field to `google_managed_kafka_cluster` resource
3+
```

google/services/managedkafka/resource_managed_kafka_cluster.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,21 @@ func ResourceManagedKafkaCluster() *schema.Resource {
183183
ForceNew: true,
184184
Description: `ID of the location of the Kafka resource. See https://cloud.google.com/managed-kafka/docs/locations for a list of supported locations.`,
185185
},
186+
"broker_capacity_config": {
187+
Type: schema.TypeList,
188+
Optional: true,
189+
Description: `Capacity configuration at a per-broker level within the Kafka cluster. The config will be appled to each broker in the cluster.`,
190+
MaxItems: 1,
191+
Elem: &schema.Resource{
192+
Schema: map[string]*schema.Schema{
193+
"disk_size_gb": {
194+
Type: schema.TypeString,
195+
Optional: true,
196+
Description: `The disk to provision for each broker in Gigabytes. Minimum: 100 GB.`,
197+
},
198+
},
199+
},
200+
},
186201
"labels": {
187202
Type: schema.TypeMap,
188203
Optional: true,
@@ -312,6 +327,12 @@ func resourceManagedKafkaClusterCreate(d *schema.ResourceData, meta interface{})
312327
} else if v, ok := d.GetOkExists("capacity_config"); !tpgresource.IsEmptyValue(reflect.ValueOf(capacityConfigProp)) && (ok || !reflect.DeepEqual(v, capacityConfigProp)) {
313328
obj["capacityConfig"] = capacityConfigProp
314329
}
330+
brokerCapacityConfigProp, err := expandManagedKafkaClusterBrokerCapacityConfig(d.Get("broker_capacity_config"), d, config)
331+
if err != nil {
332+
return err
333+
} else if v, ok := d.GetOkExists("broker_capacity_config"); !tpgresource.IsEmptyValue(reflect.ValueOf(brokerCapacityConfigProp)) && (ok || !reflect.DeepEqual(v, brokerCapacityConfigProp)) {
334+
obj["brokerCapacityConfig"] = brokerCapacityConfigProp
335+
}
315336
rebalanceConfigProp, err := expandManagedKafkaClusterRebalanceConfig(d.Get("rebalance_config"), d, config)
316337
if err != nil {
317338
return err
@@ -494,6 +515,12 @@ func resourceManagedKafkaClusterUpdate(d *schema.ResourceData, meta interface{})
494515
} else if v, ok := d.GetOkExists("capacity_config"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, capacityConfigProp)) {
495516
obj["capacityConfig"] = capacityConfigProp
496517
}
518+
brokerCapacityConfigProp, err := expandManagedKafkaClusterBrokerCapacityConfig(d.Get("broker_capacity_config"), d, config)
519+
if err != nil {
520+
return err
521+
} else if v, ok := d.GetOkExists("broker_capacity_config"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, brokerCapacityConfigProp)) {
522+
obj["brokerCapacityConfig"] = brokerCapacityConfigProp
523+
}
497524
rebalanceConfigProp, err := expandManagedKafkaClusterRebalanceConfig(d.Get("rebalance_config"), d, config)
498525
if err != nil {
499526
return err
@@ -530,6 +557,10 @@ func resourceManagedKafkaClusterUpdate(d *schema.ResourceData, meta interface{})
530557
updateMask = append(updateMask, "capacityConfig")
531558
}
532559

560+
if d.HasChange("broker_capacity_config") {
561+
updateMask = append(updateMask, "brokerCapacityConfig")
562+
}
563+
533564
if d.HasChange("rebalance_config") {
534565
updateMask = append(updateMask, "rebalanceConfig")
535566
}
@@ -976,6 +1007,32 @@ func expandManagedKafkaClusterCapacityConfigMemoryBytes(v interface{}, d tpgreso
9761007
return v, nil
9771008
}
9781009

1010+
func expandManagedKafkaClusterBrokerCapacityConfig(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
1011+
if v == nil {
1012+
return nil, nil
1013+
}
1014+
l := v.([]interface{})
1015+
if len(l) == 0 || l[0] == nil {
1016+
return nil, nil
1017+
}
1018+
raw := l[0]
1019+
original := raw.(map[string]interface{})
1020+
transformed := make(map[string]interface{})
1021+
1022+
transformedDiskSizeGb, err := expandManagedKafkaClusterBrokerCapacityConfigDiskSizeGb(original["disk_size_gb"], d, config)
1023+
if err != nil {
1024+
return nil, err
1025+
} else if val := reflect.ValueOf(transformedDiskSizeGb); val.IsValid() && !tpgresource.IsEmptyValue(val) {
1026+
transformed["diskSizeGb"] = transformedDiskSizeGb
1027+
}
1028+
1029+
return transformed, nil
1030+
}
1031+
1032+
func expandManagedKafkaClusterBrokerCapacityConfigDiskSizeGb(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
1033+
return v, nil
1034+
}
1035+
9791036
func expandManagedKafkaClusterRebalanceConfig(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
9801037
if v == nil {
9811038
return nil, nil

google/services/managedkafka/resource_managed_kafka_cluster_generated_meta.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ api_version: 'v1'
66
api_resource_type_kind: 'Cluster'
77
autogen_status: true
88
fields:
9+
- api_field: 'brokerCapacityConfig.diskSizeGb'
910
- api_field: 'capacityConfig.memoryBytes'
1011
- api_field: 'capacityConfig.vcpuCount'
1112
- field: 'cluster_id'

google/services/managedkafka/resource_managed_kafka_cluster_generated_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func TestAccManagedKafkaCluster_managedkafkaClusterBasicExample(t *testing.T) {
6969
ResourceName: "google_managed_kafka_cluster.example",
7070
ImportState: true,
7171
ImportStateVerify: true,
72-
ImportStateVerifyIgnore: []string{"cluster_id", "labels", "location", "terraform_labels"},
72+
ImportStateVerifyIgnore: []string{"broker_capacity_config", "cluster_id", "labels", "location", "terraform_labels"},
7373
},
7474
},
7575
})
@@ -123,7 +123,7 @@ func TestAccManagedKafkaCluster_managedkafkaClusterMtlsExample(t *testing.T) {
123123
ResourceName: "google_managed_kafka_cluster.example",
124124
ImportState: true,
125125
ImportStateVerify: true,
126-
ImportStateVerifyIgnore: []string{"cluster_id", "labels", "location", "terraform_labels"},
126+
ImportStateVerifyIgnore: []string{"broker_capacity_config", "cluster_id", "labels", "location", "terraform_labels"},
127127
},
128128
},
129129
})

google/services/managedkafka/resource_managed_kafka_cluster_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func TestAccManagedKafkaCluster_update(t *testing.T) {
5151
ResourceName: "google_managed_kafka_cluster.example",
5252
ImportState: true,
5353
ImportStateVerify: true,
54-
ImportStateVerifyIgnore: []string{"cluster_id", "labels", "location", "terraform_labels"},
54+
ImportStateVerifyIgnore: []string{"broker_capacity_config", "cluster_id", "labels", "location", "terraform_labels"},
5555
},
5656
{
5757
Config: testAccManagedKafkaCluster_updateTlsConfigToEmpty(context),
@@ -104,6 +104,9 @@ resource "google_managed_kafka_cluster" "example" {
104104
vcpu_count = 4
105105
memory_bytes = 4512135122
106106
}
107+
broker_capacity_config {
108+
disk_size_gb = 1500
109+
}
107110
gcp_config {
108111
access_config {
109112
network_configs {

website/docs/r/managed_kafka_cluster.html.markdown

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,11 @@ The following arguments are supported:
175175
**Note**: This field is non-authoritative, and will only manage the labels present in your configuration.
176176
Please refer to the field `effective_labels` for all of the labels present on the resource.
177177

178+
* `broker_capacity_config` -
179+
(Optional)
180+
Capacity configuration at a per-broker level within the Kafka cluster. The config will be appled to each broker in the cluster.
181+
Structure is [documented below](#nested_broker_capacity_config).
182+
178183
* `rebalance_config` -
179184
(Optional)
180185
Defines rebalancing behavior of a Kafka cluster.
@@ -226,6 +231,12 @@ The following arguments are supported:
226231
(Required)
227232
The memory to provision for the cluster in bytes. The value must be between 1 GiB and 8 GiB per vCPU. Ex. 1024Mi, 4Gi.
228233

234+
<a name="nested_broker_capacity_config"></a>The `broker_capacity_config` block supports:
235+
236+
* `disk_size_gb` -
237+
(Optional)
238+
The disk to provision for each broker in Gigabytes. Minimum: 100 GB.
239+
229240
<a name="nested_rebalance_config"></a>The `rebalance_config` block supports:
230241

231242
* `mode` -

0 commit comments

Comments
 (0)