- 20, Oct 2024
- #1
Я создаю модуль AWS Cloudfront, и возникают некоторые проблемы, поскольку некоторые параметры Cloudfront также являются «динамическими/необязательными».
Когда я пытаюсь запустить
show me the error:Error: Incorrect attribute value type on ../../../../../terraform-aws-modules/cloudfront_distribution/main.tf line 29, in resource "aws_cloudfront_distribution" "cdn": 29: origin_ssl_protocols = custom_origin_config.value.origin_ssl_protocols Inappropriate value for attribute "origin_ssl_protocols": set of string required. Error: Incorrect attribute value type on ../../../../../terraform-aws-modules/cloudfront_distribution/main.tf line 43, in resource "aws_cloudfront_distribution" "cdn": 43: locations = geo_restriction.value.location Inappropriate value for attribute "locations": set of string required. Error: Incorrect attribute value type on ../../../../../terraform-aws-modules/cloudfront_distribution/main.tf line 55, in resource "aws_cloudfront_distribution" "cdn": 55: cloudfront_default_certificate = viewer_certificate.value.cloudfront_default_certificate Inappropriate value for attribute "cloudfront_default_certificate": a bool is required.
variable "origin" {
type = any
# default = []
description = "One or more origins for this distribution (multiples allowed)."
}
variable "custom_origin_config" {
type = list
# default = []
description = "The CloudFront custom origin configuration information. If an S3 origin is required, use s3_origin_config instead."
}
После моего модуль vars.tf
:
dynamic "origin" {
for_each = var.origin
content {
domain_name = origin.value.domain_name
origin_id = origin.value.origin_id
origin_path = origin.value.origin_path
dynamic "custom_origin_config" {
for_each = var.custom_origin_config
content {
http_port = custom_origin_config.value.http_port
https_port = custom_origin_config.value.https_port
origin_protocol_policy = custom_origin_config.value.origin_protocol_policy
origin_ssl_protocols = custom_origin_config.value.origin_ssl_protocols
origin_keepalive_timeout = custom_origin_config.value.origin_keepalive_timeout
origin_read_timeout = custom_origin_config.value.origin_read_timeout
}
}
}
}
Мой main.tf
:
variable "origin" {
type = any
default = []
description = "One or more origins for this distribution (multiples allowed)."
}
variable "custom_origin_config" {
type = any
default = []
description = "The CloudFront custom origin configuration information. If an S3 origin is required, use s3_origin_config instead."
}
РЕДАКТИРОВАТЬ 1
А внес небольшие изменения vars.tf
resource "aws_cloudfront_distribution" "cdn" {
enabled = var.enabled
comment = var.comment
default_root_object = var.default_root_object
aliases = var.aliases
is_ipv6_enabled = var.is_ipv6_enabled
http_version = var.http_version
price_class = var.price_class
web_acl_id = var.web_acl_id
retain_on_delete = var.retain_on_delete
wait_for_deployment = var.wait_for_deployment
dynamic "origin" {
for_each = var.origin
content {
domain_name = origin.value.domain_name
origin_id = origin.value.origin_id
origin_path = origin.value.origin_path
}
}
dynamic "custom_origin_config" {
for_each = var.custom_origin_config
content {
http_port = custom_origin_config.value.http_port
https_port = custom_origin_config.value.https_port
origin_protocol_policy = custom_origin_config.value.origin_protocol_policy
origin_ssl_protocols = custom_origin_config.value.origin_ssl_protocols
origin_keepalive_timeout = custom_origin_config.value.origin_keepalive_timeout
origin_read_timeout = custom_origin_config.value.origin_read_timeout
}
}
и на main.tf
:
on ../../../../../terraform-aws-modules/cloudfront_distribution/main.tf line 24, in resource "aws_cloudfront_distribution" "cdn":
24: dynamic "custom_origin_config" {
Blocks of type "custom_origin_config" are not expected here.
И теперь выходная ошибка изменилась:
$ terraform validate
Кто-то сталкивался с такой проблемой, удалось ее решить?
#amazon-web-services #terraform #terraform-module