Skip to content

Commit

Permalink
Merge branch 'yandex-cloud:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
suslovsergey authored Jan 16, 2022
2 parents 29cfbc0 + 6137d7c commit 948010f
Show file tree
Hide file tree
Showing 15 changed files with 230 additions and 14 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ FEATURES:
* **New Resource:** `yandex_datatransfer_transfer`
* managed-kubernetes: add `container_runtime` attribute to `yandex_kubernetes_node_group` resource and data source
* managed-elasticsearch: add `maintenance_window` section in `yandex_mdb_elasticsearch_cluster` resource and data source
* dns: support for resolving by name in `yandex_dns_zone` data source

BUG FIXES:
* mdb: fix error when simultaneously deleting `yandex_mdb_kafka_topic` resource and modifying `yandex_mdb_kafka_cluster` resource

ENHANCEMENTS:
* mdb: add `maintenance_window` section in `yandex_mdb_kafka_cluster` resource and data source

## 0.69.0 (December 27, 2021)
FEATURES:
* **New Data Source:** `yandex_cdn_origin_group`
Expand Down
7 changes: 6 additions & 1 deletion website/docs/d/datasource_dns_zone.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ output "zone" {

## Argument Reference

* `dns_zone_id` - (Required) The ID of the DNS Zone.
* `dns_zone_id` - (Optional) The ID of the DNS Zone.
* `name` - (Optional) - Name of the DNS Zone.

~> **NOTE:** One of `dns_zone_id` or `name` should be specified.

* `folder_id` - (Optional) Folder that the resource belongs to. If value is omitted, the default provider folder is used.

## Attributes Reference

Expand Down
7 changes: 7 additions & 0 deletions website/docs/d/datasource_mdb_kafka_cluster.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ exported:
* `host` - A host of the Kafka cluster. The structure is documented below.
* `security_group_ids` - A list of security groups IDs of the Kafka cluster.
* `host_group_ids` - A list of IDs of the host groups hosting VMs of the cluster.
* `maintenance_window` - Maintenance window settings of the Kafka cluster. The structure is documented below.

The `config` block supports:

Expand Down Expand Up @@ -131,3 +132,9 @@ The `host` block supports:
* `health` - Health of the host.
* `subnet_id` - The ID of the subnet, to which the host belongs.
* `assign_public_ip` - The flag that defines whether a public IP address is assigned to the node.

The `maintenance_window` block supports:

* `type` - Type of maintenance window. Can be either `ANYTIME` or `WEEKLY`.
* `day` - Day of the week (in `DDD` format). Value is one of: "MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"
* `hour` - Hour of the day in UTC (in `HH` format). Value is between 1 and 24.
4 changes: 2 additions & 2 deletions website/docs/d/datasource_mdb_mysql_cluster.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,6 @@ The `access` block supports:

The `maintenance_window` block supports:

* `type` - Type of maintenance window. Can be either `ANYTIME` or `WEEKLY`. A day and hour of window need to be specified with weekly window.
* `type` - Type of maintenance window. Can be either `ANYTIME` or `WEEKLY`.
* `day` - Day of the week (in `DDD` format). Value is one of: "MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"
* `hour` - Hour of the day in UTC (in `HH` format). Values is between 0 and 23.
* `hour` - Hour of the day in UTC (in `HH` format). Value is between 1 and 24.
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ The `host` block supports:

The `maintenance_window` block supports:

* `type` - Type of maintenance window. Can be either `ANYTIME` or `WEEKLY`. A day and hour of window need to be specified with weekly window.
* `type` - Type of maintenance window. Can be either `ANYTIME` or `WEEKLY`.
* `day` - Day of the week (in `DDD` format). Value is one of: "MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"
* `hour` - Hour of the day in UTC (in `HH` format). Values is between 0 and 23.
* `hour` - Hour of the day in UTC (in `HH` format). Value is between 1 and 24.


2 changes: 1 addition & 1 deletion website/docs/d/datasource_vpc_security_group.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,6 @@ The `ingress` and `egress` block supports:
* `to_port` - Maximum port number.
* `port` - Port number (if applied to a single port).
* `security_group_id` - Target security group ID for this rule.
* `predefined_target` - Special-purpose targets such as "self_security_group". [See docs](https://cloud.yandex.ru/docs/vpc/concepts/security-groups) for possible options.
* `predefined_target` - Special-purpose targets. `self_security_group` refers to this particular security group. `loadbalancer_healthchecks` represents [loadbalancer health check nodes](https://cloud.yandex.com/docs/network-load-balancer/concepts/health-check).
* `v4_cidr_blocks` - The blocks of IPv4 addresses for this rule.
* `v6_cidr_blocks` - The blocks of IPv6 addresses for this rule.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ The following attribute is exported:
* `to_port` - Maximum port number.
* `port` - Port number (if applied to a single port).
* `security_group_id` - Target security group ID for this rule.
* `predefined_target` - Special-purpose targets such as "self_security_group". [See docs](https://cloud.yandex.com/docs/vpc/concepts/security-groups) for possible options.
* `predefined_target` - Special-purpose targets. `self_security_group` refers to this particular security group. `loadbalancer_healthchecks` represents [loadbalancer health check nodes](https://cloud.yandex.com/docs/network-load-balancer/concepts/health-check).
* `v4_cidr_blocks` - The blocks of IPv4 addresses for this rule.
* `v6_cidr_blocks` - The blocks of IPv6 addresses for this rule.
12 changes: 12 additions & 0 deletions website/docs/r/mdb_kafka_cluster.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ The following arguments are supported:

* `deletion_protection` - (Optional) Inhibits deletion of the cluster. Can be either `true` or `false`.

* `maintenance_window` - (Optional) Maintenance policy of the Kafka cluster. The structure is documented below.

~> **Note:** Historically, `topic` blocks of the `yandex_mdb_kafka_cluster` resource were used to manage topics of the Kafka cluster.
However, this approach has a number of disadvantages. In particular, when adding and removing topics from the tf recipe,
terraform generates a diff that misleads the user about the planned changes. Also, this approach turned out to be
Expand All @@ -213,6 +215,16 @@ type `yandex_mdb_kafka_topic` was implemented and is now recommended.

- - -

The `maintenance_window` block supports:

* `type` - (Required) Type of maintenance window. Can be either `ANYTIME` or `WEEKLY`. A day and hour of window need to be specified with weekly window.

* `day` - (Optional) Day of the week (in `DDD` format). Allowed values: "MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"

* `hour` - (Optional) Hour of the day in UTC (in `HH` format). Allowed value is between 1 and 24.

- - -

The `config` block supports:

* `version` - (Required) Version of the Kafka server software.
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/vpc_default_security_group.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ The `ingress` and `egress` block supports:
* `to_port` (Optional) - Maximum port number.
* `port` (Optional) - Port number (if applied to a single port).
* `security_group_id` (Optional) - Target security group ID for this rule.
* `predefined_target` (Optional) - Special-purpose targets such as "self_security_group". [See docs](https://cloud.yandex.com/docs/vpc/concepts/security-groups) for possible options.
* `predefined_target` (Optional) - Special-purpose targets. `self_security_group` refers to this particular security group. `loadbalancer_healthchecks` represents [loadbalancer health check nodes](https://cloud.yandex.com/docs/network-load-balancer/concepts/health-check).
* `v4_cidr_blocks` (Optional) - The blocks of IPv4 addresses for this rule.
* `v6_cidr_blocks` (Optional) - The blocks of IPv6 addresses for this rule. `v6_cidr_blocks` argument is currently not supported. It will be available in the future.

Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/vpc_security_group.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ The `ingress` and `egress` block supports:
* `to_port` (Optional) - Maximum port number.
* `port` (Optional) - Port number (if applied to a single port).
* `security_group_id` (Optional) - Target security group ID for this rule.
* `predefined_target` (Optional) - Special-purpose targets such as "self_security_group" or "loadbalancer_healthchecks". [See docs](https://cloud.yandex.com/docs/vpc/concepts/security-groups) for possible options.
* `predefined_target` (Optional) - Special-purpose targets. `self_security_group` refers to this particular security group. `loadbalancer_healthchecks` represents [loadbalancer health check nodes](https://cloud.yandex.com/docs/network-load-balancer/concepts/health-check).
* `v4_cidr_blocks` (Optional) - The blocks of IPv4 addresses for this rule.
* `v6_cidr_blocks` (Optional) - The blocks of IPv6 addresses for this rule. `v6_cidr_blocks` argument is currently not supported. It will be available in the future.

Expand Down
24 changes: 19 additions & 5 deletions yandex/data_source_yandex_dns_zone.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/yandex-cloud/go-genproto/yandex/cloud/dns/v1"
"github.com/yandex-cloud/go-sdk/sdkresolvers"
)

func dataSourceYandexDnsZone() *schema.Resource {
Expand All @@ -22,20 +23,23 @@ func dataSourceYandexDnsZone() *schema.Resource {
Schema: map[string]*schema.Schema{
"dns_zone_id": {
Type: schema.TypeString,
Required: true,
Optional: true,
Computed: true,
},

"zone": {
"name": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},

"folder_id": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},

"name": {
"zone": {
Type: schema.TypeString,
Computed: true,
},
Expand Down Expand Up @@ -78,9 +82,19 @@ func dataSourceYandexDnsZoneRead(d *schema.ResourceData, meta interface{}) error
config := meta.(*Config)
sdk := getSDK(config)

err := checkOneOf(d, "dns_zone_id", "name")
if err != nil {
return err
}

id := d.Get("dns_zone_id").(string)
if id == "" {
return fmt.Errorf("dns_zone_id should be provided")
_, zoneNameOk := d.GetOk("name")

if zoneNameOk {
id, err = resolveObjectID(config.Context(), config, d, sdkresolvers.DNSZoneResolver)
if err != nil {
return fmt.Errorf("failed to resolve data source dns zone by name: %v", err)
}
}

dnsZone, err := sdk.DNS().DnsZone().Get(config.Context(), &dns.GetDnsZoneRequest{
Expand Down
28 changes: 28 additions & 0 deletions yandex/data_source_yandex_mdb_kafka_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,26 @@ func dataSourceYandexMDBKafkaCluster() *schema.Resource {
Computed: true,
Optional: true,
},
"maintenance_window": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"type": {
Type: schema.TypeString,
Computed: true,
},
"day": {
Type: schema.TypeString,
Computed: true,
},
"hour": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
},
}
}
Expand Down Expand Up @@ -190,6 +210,14 @@ func dataSourceYandexMDBKafkaClusterRead(d *schema.ResourceData, meta interface{

d.Set("deletion_protection", cluster.DeletionProtection)

maintenanceWindow, err := flattenKafkaMaintenanceWindow(cluster.MaintenanceWindow)
if err != nil {
return err
}
if err := d.Set("maintenance_window", maintenanceWindow); err != nil {
return err
}

d.SetId(cluster.Id)
return nil
}
73 changes: 73 additions & 0 deletions yandex/mdb_kafka_structures.go
Original file line number Diff line number Diff line change
Expand Up @@ -978,3 +978,76 @@ func expandKafkaTopic(spec map[string]interface{}, version string) (*kafka.Topic
}
return topic, nil
}

func kafkaMaintenanceWindowSchemaValidateFunc(v interface{}, k string) (s []string, es []error) {
dayString := v.(string)
day, ok := kafka.WeeklyMaintenanceWindow_WeekDay_value[dayString]
if !ok || day == 0 {
es = append(es, fmt.Errorf(`expected %s value should be one of ("MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"). Current value is %v`, k, v))
return
}

return
}

func flattenKafkaMaintenanceWindow(mw *kafka.MaintenanceWindow) ([]interface{}, error) {
maintenanceWindow := map[string]interface{}{}
if mw != nil {
switch p := mw.GetPolicy().(type) {
case *kafka.MaintenanceWindow_Anytime:
maintenanceWindow["type"] = "ANYTIME"
case *kafka.MaintenanceWindow_WeeklyMaintenanceWindow:
maintenanceWindow["type"] = "WEEKLY"
maintenanceWindow["hour"] = p.WeeklyMaintenanceWindow.Hour
maintenanceWindow["day"] = kafka.WeeklyMaintenanceWindow_WeekDay_name[int32(p.WeeklyMaintenanceWindow.GetDay())]
default:
return nil, fmt.Errorf("unsupported Kafka maintenance policy type")
}
}

return []interface{}{maintenanceWindow}, nil
}

func expandKafkaMaintenanceWindow(d *schema.ResourceData) (*kafka.MaintenanceWindow, error) {
if _, ok := d.GetOk("maintenance_window"); !ok {
return nil, nil
}

out := &kafka.MaintenanceWindow{}
typeMW, _ := d.GetOk("maintenance_window.0.type")
if typeMW == "ANYTIME" {
if hour, ok := d.GetOk("maintenance_window.0.hour"); ok && hour != "" {
return nil, fmt.Errorf("hour should not be set, when using ANYTIME")
}
if day, ok := d.GetOk("maintenance_window.0.day"); ok && day != "" {
return nil, fmt.Errorf("day should not be set, when using ANYTIME")
}
out.Policy = &kafka.MaintenanceWindow_Anytime{
Anytime: &kafka.AnytimeMaintenanceWindow{},
}
} else if typeMW == "WEEKLY" {
hourInterface, ok := d.GetOk("maintenance_window.0.hour")
if !ok {
return nil, fmt.Errorf("hour should be set when using WEEKLY maintenance")
}
hour := hourInterface.(int)

dayString := d.Get("maintenance_window.0.day").(string)

day, ok := kafka.WeeklyMaintenanceWindow_WeekDay_value[dayString]
if !ok || day == 0 {
return nil, fmt.Errorf(`day value should be one of ("MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN")`)
}

out.Policy = &kafka.MaintenanceWindow_WeeklyMaintenanceWindow{
WeeklyMaintenanceWindow: &kafka.WeeklyMaintenanceWindow{
Hour: int64(hour),
Day: kafka.WeeklyMaintenanceWindow_WeekDay(day),
},
}
} else {
return nil, fmt.Errorf("maintenance_window.0.type should be ANYTIME or WEEKLY")
}

return out, nil
}
Loading

0 comments on commit 948010f

Please sign in to comment.