【问题标题】:Terraform: AWS Inspector plan failsTerraform:AWS Inspector 计划失败
【发布时间】:2021-07-16 13:07:14
【问题描述】:

我正在使用 terraform 来管理 AWS 基础设施。我对 AWS 和 terraform 完全陌生,而且信息量很大。

我正在尝试使用以下代码通过 terraform 启用服务 AWS Inspector:

resource "aws_inspector_assessment_template" "example" {
  name       = "example"
#   target_arn = aws_inspector_assessment_target.example.arn
  duration   = 3600

#   rules_package_arns = [
#     "arn:aws:inspector:us-west-2:758058086616:rulespackage/0-9hgA516p",
#     "arn:aws:inspector:us-west-2:758058086616:rulespackage/0-H5hpSawc",
#     "arn:aws:inspector:us-west-2:758058086616:rulespackage/0-JJOtZiqQ",
#     "arn:aws:inspector:us-west-2:758058086616:rulespackage/0-vg5GGHSD",
#   ]
}

但我得到的只是以下错误:

Error: Missing required argument

  on aws_inspector.tf line 1, in resource "aws_inspector_assessment_template" "example":
   1: resource "aws_inspector_assessment_template" "example" {

The argument "rules_package_arns" is required, but no definition was found.


Error: Missing required argument

  on aws_inspector.tf line 1, in resource "aws_inspector_assessment_template" "example":
   1: resource "aws_inspector_assessment_template" "example" {

The argument "target_arn" is required, but no definition was found.

这显然是因为我注释掉了target_arnrules_package_arns

问题是我不明白这些变量是什么以及要给出什么值。你能帮我解决这个问题吗?

【问题讨论】:

标签: amazon-web-services terraform terraform-provider-aws


【解决方案1】:

不应注释掉所有必需的部分。因此你的错误。

您还必须创建 aws_inspector_assessment_target,并且可以使用 aws_inspector_rules_packages 来获取您需要的 ARN。拥有这些资源,您可以在 aws_inspector_assessment_template 中引用它们。

一个例子是TF docs:

# Declare the data source
data "aws_inspector_rules_packages" "rules" {}

# e.g. Use in aws_inspector_assessment_template
resource "aws_inspector_resource_group" "group" {
  tags = {
    test = "test"
  }
}

resource "aws_inspector_assessment_target" "assessment" {
  name               = "test"
  resource_group_arn = aws_inspector_resource_group.group.arn
}

resource "aws_inspector_assessment_template" "assessment" {
  name       = "Test"
  target_arn = aws_inspector_assessment_target.assessment.arn
  duration   = "60"

  rules_package_arns = data.aws_inspector_rules_packages.rules.arns
}

【讨论】:

    猜你喜欢
    • 2018-10-15
    • 1970-01-01
    • 2021-03-21
    • 2010-12-10
    • 2010-11-20
    • 2021-08-08
    • 1970-01-01
    • 2023-01-25
    • 2018-05-12
    相关资源
    最近更新 更多