admin管理员组文章数量:1023204
I am trying to schedule an autoscaler in GCP using terraform. I want to schedule it using cronjob and according to google documentation but it's not working.
This is part of my main.tf as per the google documentation:
resource "google_compute_instance_group_manager" "mig" {
name = "${var.gcp_env}-${var.gcp_project}-mig"
version {
instance_template = google_compute_instance_template.debian12_template.self_link
}
base_instance_name = "${var.gcp_env}-${var.gcp_project}-instance"
target_size = 2
zone = "${var.gcp_region}-a"
named_port {
name = "http"
port = 80
}
}
resource "google_compute_autoscaler" "autoscaler" {
name = "${var.gcp_env}-${var.gcp_project}-autoscaler"
zone = "${var.gcp_region}-a"
target = google_compute_instance_group_manager.mig.id
autoscaling_policy {
mode = "ON"
cooldown_period = 60
cpu_utilization {
target = 0.9
}
max_replicas = 2
min_replicas = 1
}
scaling_schedules {
name = "every-weekday-morning"
description = "Increase to 2 every weekday at 7AM for 12 hours."
min_required_replicas = 2
schedule = "0 9 * * MON-FRI"
time_zone = "utc/utc"
duration_sec = 32400
}
}
When I try to run it I get the error:
$ terraform apply -auto-approve
╷
│ Error: Unsupported block type
│
│ on main.tf line 115, in resource "google_compute_autoscaler" "autoscaler":
│ 115: scaling_schedules {
│
│ Blocks of type "scaling_schedules" are not expected here.
I don't get it. When I checked the Terraform documentation it doesn't have anything for scaling_schedule (I couldn't find it after going through it.)
Would appreciate some help on solving this
I am trying to schedule an autoscaler in GCP using terraform. I want to schedule it using cronjob and according to google documentation but it's not working.
This is part of my main.tf as per the google documentation:
resource "google_compute_instance_group_manager" "mig" {
name = "${var.gcp_env}-${var.gcp_project}-mig"
version {
instance_template = google_compute_instance_template.debian12_template.self_link
}
base_instance_name = "${var.gcp_env}-${var.gcp_project}-instance"
target_size = 2
zone = "${var.gcp_region}-a"
named_port {
name = "http"
port = 80
}
}
resource "google_compute_autoscaler" "autoscaler" {
name = "${var.gcp_env}-${var.gcp_project}-autoscaler"
zone = "${var.gcp_region}-a"
target = google_compute_instance_group_manager.mig.id
autoscaling_policy {
mode = "ON"
cooldown_period = 60
cpu_utilization {
target = 0.9
}
max_replicas = 2
min_replicas = 1
}
scaling_schedules {
name = "every-weekday-morning"
description = "Increase to 2 every weekday at 7AM for 12 hours."
min_required_replicas = 2
schedule = "0 9 * * MON-FRI"
time_zone = "utc/utc"
duration_sec = 32400
}
}
When I try to run it I get the error:
$ terraform apply -auto-approve
╷
│ Error: Unsupported block type
│
│ on main.tf line 115, in resource "google_compute_autoscaler" "autoscaler":
│ 115: scaling_schedules {
│
│ Blocks of type "scaling_schedules" are not expected here.
I don't get it. When I checked the Terraform documentation it doesn't have anything for scaling_schedule (I couldn't find it after going through it.)
Would appreciate some help on solving this
Share Improve this question asked Nov 19, 2024 at 5:02 DarkDeadDarkDead 1653 silver badges16 bronze badges2 Answers
Reset to default 1The google
provider must be at least version 3.69.0 to support that block in that resource as per CHANGELOG. This can be accomplished through semantic versioning specification on the provider version in your required_providers
block.
terraform {
required_providers {
google = {
source = "hashicorp/google"
version = "~> 3.0"
}
}
}
It would probably be recommended to use ~> 5.0
(or even ~> 6.0
depending upon your situation) instead, but that depends on your environment.
For some reason it worked when I commented out the scaling_schedule
part in the autoscaler. So, there's that. I thought it would accept multiple policies(?) for autoscaling. Like during a certain time and/or if there's a spike in cpu but I guess only 1 works.
I am trying to schedule an autoscaler in GCP using terraform. I want to schedule it using cronjob and according to google documentation but it's not working.
This is part of my main.tf as per the google documentation:
resource "google_compute_instance_group_manager" "mig" {
name = "${var.gcp_env}-${var.gcp_project}-mig"
version {
instance_template = google_compute_instance_template.debian12_template.self_link
}
base_instance_name = "${var.gcp_env}-${var.gcp_project}-instance"
target_size = 2
zone = "${var.gcp_region}-a"
named_port {
name = "http"
port = 80
}
}
resource "google_compute_autoscaler" "autoscaler" {
name = "${var.gcp_env}-${var.gcp_project}-autoscaler"
zone = "${var.gcp_region}-a"
target = google_compute_instance_group_manager.mig.id
autoscaling_policy {
mode = "ON"
cooldown_period = 60
cpu_utilization {
target = 0.9
}
max_replicas = 2
min_replicas = 1
}
scaling_schedules {
name = "every-weekday-morning"
description = "Increase to 2 every weekday at 7AM for 12 hours."
min_required_replicas = 2
schedule = "0 9 * * MON-FRI"
time_zone = "utc/utc"
duration_sec = 32400
}
}
When I try to run it I get the error:
$ terraform apply -auto-approve
╷
│ Error: Unsupported block type
│
│ on main.tf line 115, in resource "google_compute_autoscaler" "autoscaler":
│ 115: scaling_schedules {
│
│ Blocks of type "scaling_schedules" are not expected here.
I don't get it. When I checked the Terraform documentation it doesn't have anything for scaling_schedule (I couldn't find it after going through it.)
Would appreciate some help on solving this
I am trying to schedule an autoscaler in GCP using terraform. I want to schedule it using cronjob and according to google documentation but it's not working.
This is part of my main.tf as per the google documentation:
resource "google_compute_instance_group_manager" "mig" {
name = "${var.gcp_env}-${var.gcp_project}-mig"
version {
instance_template = google_compute_instance_template.debian12_template.self_link
}
base_instance_name = "${var.gcp_env}-${var.gcp_project}-instance"
target_size = 2
zone = "${var.gcp_region}-a"
named_port {
name = "http"
port = 80
}
}
resource "google_compute_autoscaler" "autoscaler" {
name = "${var.gcp_env}-${var.gcp_project}-autoscaler"
zone = "${var.gcp_region}-a"
target = google_compute_instance_group_manager.mig.id
autoscaling_policy {
mode = "ON"
cooldown_period = 60
cpu_utilization {
target = 0.9
}
max_replicas = 2
min_replicas = 1
}
scaling_schedules {
name = "every-weekday-morning"
description = "Increase to 2 every weekday at 7AM for 12 hours."
min_required_replicas = 2
schedule = "0 9 * * MON-FRI"
time_zone = "utc/utc"
duration_sec = 32400
}
}
When I try to run it I get the error:
$ terraform apply -auto-approve
╷
│ Error: Unsupported block type
│
│ on main.tf line 115, in resource "google_compute_autoscaler" "autoscaler":
│ 115: scaling_schedules {
│
│ Blocks of type "scaling_schedules" are not expected here.
I don't get it. When I checked the Terraform documentation it doesn't have anything for scaling_schedule (I couldn't find it after going through it.)
Would appreciate some help on solving this
Share Improve this question asked Nov 19, 2024 at 5:02 DarkDeadDarkDead 1653 silver badges16 bronze badges2 Answers
Reset to default 1The google
provider must be at least version 3.69.0 to support that block in that resource as per CHANGELOG. This can be accomplished through semantic versioning specification on the provider version in your required_providers
block.
terraform {
required_providers {
google = {
source = "hashicorp/google"
version = "~> 3.0"
}
}
}
It would probably be recommended to use ~> 5.0
(or even ~> 6.0
depending upon your situation) instead, but that depends on your environment.
For some reason it worked when I commented out the scaling_schedule
part in the autoscaler. So, there's that. I thought it would accept multiple policies(?) for autoscaling. Like during a certain time and/or if there's a spike in cpu but I guess only 1 works.
本文标签: google cloud platformschedule autoscaler in terraform for GCPStack Overflow
版权声明:本文标题:google cloud platform - schedule autoscaler in terraform for GCP? - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745581314a2157325.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论