aws_ssm_document addomainjoin 错误。

0

【以下的问题经过翻译处理】 我正在努力通过加入域的ASG(AWS 安全组)部署EC2实例。

每次我都会遇到以下错误

New-SSMAssociation:Document schema version, 2.2, is not supported by association that is created with instance id

我尝试了详细介绍这里的各种模式版本,但是都出现了相同的错误

SSMdoc.tf

resource "aws_ssm_document" "ad-join-domain" {
  name          = "ad-join-domain"
  document_type = "Command"
  content = jsonencode(
    {
      "schemaVersion" = "2.2"
      "description"   = "aws:domainJoin"
      "parameters" : {
        "directoryId" : {
          "description" : "(Required) The ID of the directory.",
          "type" : "String"
        },
        "directoryName" : {
          "description" : "(Required) The name of the domain.",
          "type" : "String"
        },
        "dnsIpAddresses" : {
          "description" : "(Required) The IP addresses of the DNS servers for your directory.",
          "type" : "StringList"
        },
      },
      "mainSteps" = [
        {
          "action" = "aws:domainJoin",
          "name"   = "domainJoin",
          "inputs" = {
            "directoryId" : data.aws_directory_service_directory.adgems.id,
            "directoryName" : data.aws_directory_service_directory.adgems.name,
            "dnsIpAddresses" : [data.aws_directory_service_directory.adgems.dns_ip_addresses]
          }
        }
      ]
    }
  )
}

template.tf

data "template_file" "ad-join-template" {
  template = <<EOF
  <powershell>
    Set-DefaultAWSRegion -Region eu-west-2
    Set-Variable -name instance_id -value (Invoke-Restmethod -uri http://169.254.169.254/latest/meta-data/instance-id)
    New-SSMAssociation -InstanceId $instance_id -Name "${aws_ssm_document.ad-join-domain.name}"
  </powershell
profile picture
专家
已提问 5 个月前57 查看次数
1 回答
0

【以下的回答经过翻译处理】 你好,

我注意到你正在使用带有参数 -InstanceIdNew-SSMAssociation 方法。 然而,使用模式版本 2.0 或更高版本的文档必须改用 -Target 替代 -InstanceId

引用 SSM API

InstanceId 已过时。要为关联指定托管节点 ID,请使用Targets参数。包括参数 InstanceID 的请求与使用模式版本 2.0 或更高版本的系统管理器文档 (SSM 文档) 将失败。此外,如果你使用 InstanceId 参数,则无法使用AssociationNameDocumentVersionMaxErrorsMaxConcurrencyOutputLocationScheduleExpression 参数。要使用这些参数,必须使用 Targets 参数。

你可以将 -InstanceId 替换为:

-Target Key=InstanceIds,Values=$instance_id

请参考以下链接获取更多详细信息: https://docs.aws.amazon.com/powershell/latest/reference/items/New-SSMAssociation.html

https://docs.aws.amazon.com/sdkfornet/v3/apidocs/items/SSM/TTarget.html

profile picture
专家
已回答 5 个月前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则