ARTICLE · INTELLIGENCE

战地情报 · 详情页

来自尧图项目组的一线实战观察与深度解析

Terraform AWS Provider v6.58.0 版本解读:新资源、增强与关键修复实战指南

Terraform AWS Provider v6.58.0 版本解读:新资源、增强与关键修复实战指南 Terraform AWS Provider v6.58.0 版本解读新资源、增强与关键修复实战指南【免费下载链接】terraform-provider-awsThe AWS Provider enables Terraform to manage AWS resources.项目地址: https://gitcode.com/GitHub_Trending/te/terraform-provider-aws版本概览本文基于 terraform-provider-aws 仓库的 .changes/6.x/6.58.0.md 发布说明系统解读 v6.58.02026-08-05 发布的四大类变更新增 4 个 List Resource 与 4 个标准 Resource、面向 ECS/AWS Glue/API Gateway 等服务的 8 项功能增强以及覆盖 14 个资源的 Bug 修复。读者在阅读本文后将能够理解这些新资源的能力边界与配置要点掌握关键增强的迁移用法并能针对已知问题制定升级验证方案。1. 版本定位与变更全景v6.58.0 是 AWS Provider 6.x 系列的一次常规功能版本整体以可观测性生态补全 邮件网关规则能力落地为两条主线一方面补齐 Amazon Managed PrometheusAMP的异常检测、抓取器日志等资源另一方面将 SES Mail Manager 的规则集Rule Set和 Resilience Hub V2 的策略Policy纳入官方管理范围。变更类别数量涉及服务新 List Resource4SES Mail Manager、AMP、Resilience Hub V2新 Resource4SES Mail Manager、AMP、Resilience Hub V2功能增强8API Gateway、Direct Connect、ECS、AWS Glue、AMPBug 修复14API Gateway、ECS、IAM、SSM 等发布说明原文以三节组织FEATURES / ENHANCEMENTS / BUG FIXES本文沿用该骨架并结合 website/docs 下的资源文档与 internal/service 源码对每个变更点做纵深解析。2. 新增资源详解FEATURES2.1aws_mailmanager_rule_setSES Mail Manager 规则集新增 List Resource 与 Resource 各一个用于管理 SES Mail Manager 的规则集实现邮件的过滤与动作编排。规则集是邮件处理流水线的核心每条规则由条件condition / unless与动作action组成条件全部满足时触发动作。从仓库的官方文档website/docs/r/mailmanager_rule_set.html.markdown可知其完整的能力矩阵规则数量限制每条规则集最多 40 条规则rule块每条规则最多 10 个动作、10 个condition条件、10 个unless排除条件。条件类型六选一boolean_expression布尔表达式、dmarc_expressionDMARC 策略匹配、ip_expression来源 IP 的 CIDR 匹配、number_expression数值比较如MESSAGE_SIZE、string_expression字符串匹配、verdict_expressionSPF/DKIM 验证结果。动作类型十二选一add_header添加邮件头、archive归档、bounce退回邮件、deliver_to_mailbox投递到 WorkMail 邮箱、deliver_to_q_business投递到 Amazon Q Business、drop丢弃、invoke_lambda调用 Lambda、publish_to_sns发布到 SNS、relay转发到 SMTP、replace_recipient替换收件人、send发送到互联网、write_to_s3写入 S3。基础配置示例完整继承官方文档resource aws_mailmanager_rule_set example { name example rule { name add-header action { add_header { header_name X-Example header_value example } } } }带条件的典型用法——用string_expression匹配发件人并追加邮件头resource aws_mailmanager_rule_set example { name example rule { name tag-newsletter condition { string_expression { evaluate { attribute FROM } operator CONTAINS values [newsletterexample.com] } } action { add_header { header_name X-Category header_value newsletter } } } }参数要点节选自官方参数参考name、rule为必填参数region、tags可选其中tags支持 provider 级default_tags覆盖。boolean_expression的操作符取值为IS_TRUE/IS_FALSE可评估的邮件属性包括READ_RECEIPT_REQUESTED、TLS、TLS_WRAPPED也可基于 Add On 结果analysis或地址列表成员关系is_in_address_list判断。dmarc_expression操作符为EQUALS/NOT_EQUALS策略值为NONE/QUARANTINE/REJECT。string_expression操作符为EQUALS/NOT_EQUALS/STARTS_WITH/ENDS_WITH/CONTAINSvalues支持 110 个字符串、单个不超过 4096 字符mime_header_attribute必须以X-或x-开头且长度 1256。verdict_expression的 verdict 值为PASS/FAIL/GRAY/PROCESSING_FAILED。各动作普遍支持action_failure_policy动作失败策略涉及跨服务操作的如bounce、deliver_to_mailbox、invoke_lambda、publish_to_sns、send、write_to_s3均要求提供role_arnIAM 角色。导出属性arn、created_date、id、last_modification_date、tags_all。导入方式Terraform v1.12 使用identityv1.5 使用idimport { to aws_mailmanager_rule_set.example id rule-set-id }terraform import aws_mailmanager_rule_set.example rule-set-id源码依据该资源采用 Terraform Plugin Framework 实现核心逻辑位于 internal/service/mailmanager/rule_set.go1510 行通过FrameworkResource(aws_mailmanager_rule_set, nameRule Set)、IdentityAttribute(id)等注解声明元数据并组合framework.WithImportByIdentity支持基于身份Identity的导入列表资源位于 internal/service/mailmanager/rule_set_list.go。配套测试覆盖导入rule_set_identity_gen_test.go、标签rule_set_tags_gen_test.go与常规 CRUDrule_set_test.go。2.2 AMP 三件套Anomaly Detector、Scraper 与 Scraper Logging Configurationv6.58.0 为 Amazon Managed PrometheusAMP即 Managed Prometheus 服务一次性落地了三个新资源其中aws_prometheus_scraper与aws_prometheus_scraper_logging_configuration还同时提供 List Resource 形态补齐了 AMP 全托管采集链路的 Terraform 覆盖。2.2.1aws_prometheus_anomaly_detector基于 Random Cut Forest 的指标异常检测该资源在指定 AMP Workspace 内创建基于 Random Cut ForestRCF算法的异常检测器。官方文档见 website/docs/r/prometheus_anomaly_detector.html.markdown。基础用法resource aws_prometheus_workspace example {} resource aws_prometheus_anomaly_detector example { alias example workspace_id aws_prometheus_workspace.example.id configuration { random_cut_forest { query avg(up) } } missing_data_action { skip true } }进阶用法——设置评估间隔、标签与抑制阈值resource aws_prometheus_anomaly_detector example { alias example workspace_id aws_prometheus_workspace.example.id evaluation_interval_in_seconds 120 labels { env production team platform } configuration { random_cut_forest { query avg(up) sample_size 256 shingle_size 4 ignore_near_expected_from_above { ratio 1.5 } ignore_near_expected_from_below { amount 2.0 } } } missing_data_action { mark_as_anomaly true } }参数要点必填alias、configuration、missing_data_action、workspace_id。evaluation_interval_in_seconds可选Computed控制评估频率labels用于将检测范围限定到特定时间序列。configuration.random_cut_forest中query为 PromQL 查询必填sample_size训练数据点数至少 256与shingle_size构成单次输入的连续数据点数至少 2均为 Optional Computed。ignore_near_expected_from_above/ignore_near_expected_from_below用于抑制观测值略高于/低于期望值的误报二者必须且只能配置amount绝对量或ratio比例≥0之一且二者互斥Conflicts with。missing_data_action必须在mark_as_anomaly true将缺失点视为异常与skip true跳过缺失点之间二选一。Timeouts 默认create/update/delete 均为10m。导出属性arn、created_at、id、tags_all。导入identity 模式下需要id与workspace_id两个字段terraform import aws_prometheus_anomaly_detector.example ad-12345678-abcd-1234-abcd-123456789012,ws-12345678-abcd-1234-abcd-123456789012源码依据实现位于 internal/service/amp/anomaly_detector.go列表资源在 internal/service/amp/anomaly_detector_list.go测试包括 identity 与 tags 生成测试。2.2.2aws_prometheus_scraper全托管指标采集器Scraper该资源对应 AMP 的全托管 collectorscraper可从 EKS 集群或 VPC 内目标自动发现并抓取 Prometheus 指标。官方文档见 website/docs/r/prometheus_scraper.html.markdown。重要行为提示文档明确指出一旦修改 Scraper 的 sourceEKS 集群或 VPC 配置Terraform 会删除当前 Scraper 并重建一个新实例因此该参数变动会触发资源替换replace。基础用法——EKS 集群来源 AMP 工作区目标resource aws_prometheus_scraper example { source { eks { cluster_arn data.aws_eks_cluster.example.arn subnet_ids data.aws_eks_cluster.example.vpc_config[0].subnet_ids } } destination { amp { workspace_arn aws_prometheus_workspace.example.arn } } scrape_configuration EOT global: scrape_interval: 30s scrape_configs: - job_name: pod_exporter kubernetes_sd_configs: - role: pod EOT }v6.58.0 增强点CloudWatch Metrics 目标destination.cloudwatch。本版本为destination增加了cloudwatch配置块对应变更条目 Adddestination.cloudwatchconfiguration block for CloudWatch Metrics destination support允许将采集到的指标直接写入 CloudWatch Metricsresource aws_prometheus_scraper example { source { eks { cluster_arn data.aws_eks_cluster.example.arn subnet_ids data.aws_eks_cluster.example.vpc_config[0].subnet_ids } } destination { cloudwatch { dataset_arn arn:aws:cloudwatch:us-west-2:123456789012:dataset/default } } scrape_configuration EOT global: scrape_interval: 30s scrape_configs: - job_name: pod_exporter kubernetes_sd_configs: - role: pod EOT }cloudwatch块只接受一个必填参数dataset_arn默认数据集使用arn:aws:cloudwatch:{region}:{account}:dataset/default。注意amp与cloudwatch二者必须指定其一但不可同时指定。VPC 来源与 OpenSearch Exporterresource aws_prometheus_scraper example { source { vpc { security_group_ids [aws_security_group.example.id] subnet_ids [aws_subnet.example1.id, aws_subnet.example2.id] } } destination { amp { workspace_arn aws_prometheus_workspace.example.arn } } exporter { opensearch { domain_arn aws_opensearch_domain.example.arn } } scrape_configuration EOT global: scrape_interval: 30s scrape_configs: - job_name: my-service dns_sd_configs: - names: [my-service.my-namespace] type: A port: 8080 metrics_path: /metrics EOT }使用服务托管默认配置可通过数据源aws_prometheus_default_scraper_configuration直接引用 AWS 维护的默认抓取配置免去手写 YAMLdata aws_prometheus_default_scraper_configuration example {} resource aws_prometheus_scraper example { destination { amp { workspace_arn aws_prometheus_workspace.example.arn } } scrape_configuration data.aws_prometheus_default_scraper_configuration.example.configuration source { eks { cluster_arn data.aws_eks_cluster.example.arn subnet_ids data.aws_eks_cluster.example.vpc_config[0].subnet_ids } } }跨账户写入role_configuration允许抓取器所在源账户把指标远程写入目标账户的 AMP 工作区。前提约束目标 Role 与目标 Workspace 必须在同一账户源 Scraper 与目标 Workspace 必须在同一区域。使用role_configuration同时提供source_role_arn与target_role_arnresource aws_prometheus_scraper example { source { eks { cluster_arn data.aws_eks_cluster.example.arn subnet_ids data.aws_eks_cluster.example.vpc_config[0].subnet_ids } } destination { amp { workspace_arn target_account_workspace_arn } } role_configuration { source_role_arn aws_iam_role.source.arn target_role_arn arn:aws:iam::ACCOUNT-ID:role/target-role-name } scrape_configuration ... }参数要点与注意事项必填source、destination、scrape_configuration可选alias、exporter、region、role_configuration、tags。source.eks需cluster_arn与subnet_ids至少两个不同可用区security_group_ids可选source.vpc的security_group_ids与subnet_ids均必填且子网需分布在至少两个可用区。EKS aws-auth 配置源 EKS 集群必须配置 Kubernetes 权限以允许 Scraper 访问指标。标签注意托管 Scraper 会向其目标 AMP 工作区自动添加AMPAgentlessScraper标签。为避免 Terraform 状态把该标签从工作区移除官方建议在目标工作区上显式声明该标签或使用lifecycle忽略标签变更。Timeouts 默认create30m、update2m、delete20m。导出属性arn、role_arnScraper 自动生成的、用于发现/采集/产出指标的 IAM 角色、tags_all。导入terraform import aws_prometheus_scraper.example s-b6f487db-4761-4930-9215-e9d588a7efe2List Resourcewebsite/docs/list-resources/prometheus_scraper.html.markdown支持通过filters键值对如status [ACTIVE, CREATING]过滤查询list aws_prometheus_scraper example { provider aws config { filters { status [ACTIVE, CREATING] } } }源码依据实现位于 internal/service/amp/scraper.go809 行通过SetDefaultCreateTimeout(30 * time.Minute)、SetDefaultDeleteTimeout(20 * time.Minute)、SetDefaultUpdateTimeout(2 * time.Minute)与文档中的默认 Timeouts 一一对应同时组合了framework.WithTimeouts与framework.WithImportByIdentity。本版本为 scraper 新增的 Resource Identity 支持ENHANCEMENTS 条目即体现在IdentityAttribute(id)与WithImportByIdentity的组合上。2.2.3aws_prometheus_scraper_logging_configurationScraper 日志配置该资源为指定 Scraper 配置 CloudWatch Logs 日志投递官方文档见 website/docs/r/prometheus_scraper_logging_configuration.html.markdown。基础用法resource aws_prometheus_scraper example { source { eks { cluster_arn aws_eks_cluster.example.arn subnet_ids aws_subnet.example[*].id } } destination { amp { workspace_arn aws_prometheus_workspace.example.arn } } scrape_configuration EOT global: scrape_interval: 15s scrape_configs: - job_name: prometheus static_configs: - targets: [localhost:9090] EOT } resource aws_cloudwatch_log_group example { name /aws/prometheus/scraper-logs/example } resource aws_prometheus_scraper_logging_configuration example { scraper_id aws_prometheus_scraper.example.id logging_destination { cloudwatch_logs { log_group_arn ${aws_cloudwatch_log_group.example.arn}:* } } }按组件选择日志scraper_components取值COLLECTOR、EXPORTER、SERVICE_DISCOVERYresource aws_prometheus_scraper_logging_configuration example { scraper_id aws_prometheus_scraper.example.id scraper_components [COLLECTOR, EXPORTER] logging_destination { cloudwatch_logs { log_group_arn ${aws_cloudwatch_log_group.example.arn}:* } } }参数要点必填scraper_id、logging_destination其下cloudwatch_logs.log_group_arn必填且必须以:*结尾。该资源不导出额外属性exports no additional attributes。Timeouts 默认create/update/delete 均为5m。导入按scraper_idterraform import aws_prometheus_scraper_logging_configuration.example s-b6f487db-4761-4930-9215-e9d588a7efe22.3aws_resiliencehubv2_policy模块化韧性策略该资源用于管理 AWS Resilience Hub V2 的韧性策略Policy。与传统的单一策略类型不同V2 策略通过模块化、可组合的需求来定义韧性预期——按需组合可用性 SLO、多 AZ 容灾、多区域容灾与数据恢复目标官方文档见 website/docs/r/resiliencehubv2_policy.html.markdown。基础用法——仅可用性 SLOresource aws_resiliencehubv2_policy example { name example-policy availability_slo { target 99.9 } }多 AZ 数据恢复组合resource aws_resiliencehubv2_policy example { name example-policy description Policy with multi-AZ and data recovery targets availability_slo { target 99.99 } data_recovery { time_between_backups_in_minutes 60 } multi_az { disaster_recovery_approach ACTIVE_ACTIVE rpo_in_minutes 5 rto_in_minutes 10 } tags { Environment production } }多区域容灾resource aws_resiliencehubv2_policy example { name example-multi-region-policy availability_slo { target 99.95 } multi_region { disaster_recovery_approach ACTIVE_PASSIVE rpo_in_minutes 15 rto_in_minutes 30 } }参数要点必填name修改该值会创建新资源即触发ForceNew。availability_slo.target可用性目标百分比如99.9。data_recovery.time_between_backups_in_minutes备份间隔上限分钟。multi_az/multi_region的disaster_recovery_approach可选值ACTIVE_ACTIVE、HOT_STANDBY、WARM_STANDBY、PILOT_LIGHT、BACKUP_AND_RESTORErpo_in_minutes恢复点目标与rto_in_minutes恢复时间目标可选。可选参数还包括kms_key_idKMS 密钥 ARN用于策略加密与tags。导出属性arn、tags_all。导入按 ARNterraform import aws_resiliencehubv2_policy.example arn:aws:resiliencehub:us-west-2:123456789012:policy/example-policy:abc123配套资源该服务目录下还包含aws_resiliencehubv2_user_journey、aws_resiliencehubv2_service等 V2 资源见 website/docs/r/resiliencehubv2_user_journey.html.markdown策略可与它们组合构成完整的韧性评估体系。3. 功能增强详解ENHANCEMENTS3.1 API GatewayREST API 可配置资源超时aws_api_gateway_rest_api新增可配置的资源级 Timeouts#49205与 3.2 节的 Bug 修复配套用于应对创建/更新期间的BadRequestException: There is already an update in progress间歇性错误。resource aws_api_gateway_rest_api example { name example timeouts { create 15m update 15m delete 15m } }3.2 Direct Connectaws_dx_connection新增state属性aws_dx_connection增加只读属性state#42150可输出连接当前状态如available、ordering、requested等便于在其他资源中引用判断连接是否就绪。3.3 ECSCapacity Provider 弹性能力扩展aws_ecs_capacity_provider的managed_instances_provider.instance_launch_template迎来三项增强新增RESERVED取值capacity_option_type现在允许设置RESERVED容量预占型#48816。新增capacity_reservations参数支持配置容量预留#48816。新增local_storage_configuration属性为启动模板配置本地存储#47513。典型配置形态resource aws_ecs_capacity_provider example { name example auto_scaling_group_provider { auto_scaling_group_arn aws_autoscaling_group.example.arn managed_instances_provider { instance_launch_template { capacity_option_type RESERVED capacity_reservations { # 容量预留相关配置 } } } } }3.4 AWS GlueCatalog Table Optimizer 支持压缩配置aws_glue_catalog_table_optimizer新增configuration.compaction_configuration参数#43868允许精细化控制 Iceberg 等表的文件压缩compaction行为例如设置压缩阈值与策略。3.5 AMPScraper 的 Identity 支持与 CloudWatch 目标已在 2.2.2 详述aws_prometheus_scraper新增 Resource Identity 支持#47466支持基于 identity 的导入见 internal/service/amp/scraper.go 中的IdentityAttribute(id)注解。aws_prometheus_scraper新增destination.cloudwatch目标#49088对接 CloudWatch Metrics用法见上文CloudWatch Metrics 目标一节。4. Bug 修复详解BUG FIXES4.1 API Gateway REST API等待可用/删除完成修复BadRequestException: There is already an update in progress间歇性错误#49205现在创建与更新时会等待 REST API 进入可用状态删除时会等待完全删除完毕避免并发操作冲突。4.2 ECS 服务稳态等待与卷配置修复sigint_rollback误回滚修复#49077wait_for_steady_state期间不再因 SIGINT 信号误将健康部署回滚。非 EBS 部署卷不入库#48947防止非 EBS 的 deployment volume 配置被错误写入 state。4.3 IAM 用户销毁冲突重试aws_iam_user在销毁时遇到冲突如权限边界/附加策略尚未解除将自动重试并忽略销毁过程中的非错误#49260减少手动重跑的运维负担。4.4 SSM 参数ARN 与版本导入修复传入 ARN 值时能正确导入此前 ARN 解析会失败#49134。导入特定版本时不再报错此前导入带版本号的参数会失败。4.5 AWS Glue视图View创建与持久化差异修复修复 ATHENA 方言视图创建/更新时的InvalidInputException: StorageDescriptor is not allowed#49156。修复 SPARK 方言视图在未显式提供storage_descriptor时的InvalidInputException。修复view_definition.representationsvalidation_connection、view_original_text、view_expanded_text的永久 plan diff——AWS Glue 对已验证的 ATHENA 视图不回显这些字段provider 现在正确忽略差异。4.6 Bedrock Agent验证器与内存策略修复aws_bedrockagent_data_source修复 v6.56.0 引入的回归——当parsing_strategy BEDROCK_DATA_AUTOMATION时错误强制要求bedrock_data_automation_configuration#49111。aws_bedrockagentcore_memory_strategy修复Received null value, however the target type cannot handle null values值转换错误#49188修复期望 1 个结果却得到 2 个too many results: wanted 1, got 2的唯一性冲突#49250当configuration.consolidation、extraction、reflection块被移除时改为替换资源而不是报错#49188。aws_bedrockagentcore_agent_runtimecustom_jwt_authorizer的claim_match_value中允许match_value_string与match_value_string_list出现冒号:#48437。4.7 其余修复aws_appstream_stack修复embed_host_domains在更新时未发送给 AWS API、导致已有栈上产生永久 plan diff 的问题#49015。aws_elasticache_replication_group修复apply_immediately false时因下一次维护窗口内存在待生效变更而产生的永久 diff#48246。aws_route53recoverycontrolconfig_safety_rule修复创建操作返回错误时的崩溃panic#49155。5. 升级与验证建议升级方式修改 provider 版本约束后执行terraform init -upgrade。本仓库的版本号声明文件位于 version/VERSION 与 version/version.go6.x 的完整变更历史可对照 .changes/6.x 目录。重点回归项使用aws_api_gateway_rest_api、aws_ecs_service、aws_glue_catalog_table、aws_iam_user与aws_ssm_parameter的配置应在升级后运行terraform plan检查是否有非预期 diff。新资源采纳路径涉及 SES Mail Manager 规则集的用户可对照 website/docs/r/mailmanager_rule_set.html.markdown 逐步搭建条件 动作流水线使用 AMP 的用户可按Scraper → Logging Configuration → Anomaly Detector的顺序补齐全托管监控链路。持久化/替换语义确认特别注意aws_prometheus_scraper的 source 变更会触发资源替换以及aws_resiliencehubv2_policy的name修改会创建新资源避免在非预期时刻产生资源重建。6. 结语v6.58.0 是 AWS Provider 在可观测性AMP与邮件处理SES Mail Manager两个方向上的重要补强同时通过 REST API 超时等待、IAM 销毁重试、SSM 导入等修复提升了核心高频资源的使用稳定性。建议在升级到该版本后优先验证本文第 5 节列出的重点回归项再逐步启用新增资源。【免费下载链接】terraform-provider-awsThe AWS Provider enables Terraform to manage AWS resources.项目地址: https://gitcode.com/GitHub_Trending/te/terraform-provider-aws创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
RELATED READING

延伸阅读

更多一线实战笔记与深度复盘,助您持续精进