

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 使用 Terraform 開始使用 AWS DevOps 代理程式
<a name="getting-started-with-aws-devops-agent-getting-started-with-aws-devops-agent-using-terraform"></a>

## 概觀
<a name="overview"></a>

本指南說明如何使用 Terraform 來建立和部署 AWS DevOps 代理程式資源。Terraform 組態會自動建立代理程式空間、IAM 角色、運算子應用程式和 AWS 帳戶關聯。

Terraform 方法透過將所有必要資源定義為基礎設施作為程式碼，自動執行 [CLI 入門指南](https://docs.aws.amazon.com/devopsagent/latest/userguide/getting-started-with-aws-devops-agent-cli-onboarding-guide.html)中所述的手動步驟。

AWS DevOps 代理程式可在下列 6 AWS 區域使用：美國東部 （維吉尼亞北部）、美國西部 （奧勒岡）、亞太區域 （雪梨）、亞太區域 （東京）、歐洲 （法蘭克福） 和歐洲 （愛爾蘭）。如需支援區域的詳細資訊，請參閱 [支援的區域](about-aws-devops-agent-supported-regions.md)。

## 先決條件
<a name="prerequisites"></a>

開始前，請確定您具有下列項目：
+ Terraform >= 已安裝 1.0
+ AWS CLI 已安裝並使用適當的登入資料設定
+ 一個 AWS 帳戶用於監控 （主要） 帳戶
+ （選用） 如果您想要設定跨 AWS 帳戶監控的第二個帳戶
+ （適用於第 4 部分） `awscc`提供者版本 1.98.0 或更新版本。`awscc_devopsagent_trigger` 已在該版本中新增 `awscc_devopsagent_asset`和資源。若要檢查組態中的版本，請執行 `terraform providers`。

## 本指南涵蓋的內容
<a name="what-this-guide-covers"></a>

本指南分為四個部分：
+ **第 1** 部分 — 使用 運算子應用程式和監控帳戶中的 AWS 關聯部署代理程式空間。完成此部分後，客服人員可以監控該帳戶中的問題。
+ **第 2 部分 （選用）** — 新增服務帳戶的來源 AWS 關聯，並將跨帳戶 IAM 角色加上 echo Lambda 部署至該帳戶。這可讓客服人員空間跨帳戶監控資源。
+ 第 **3 部分 （選用）** — 註冊第三方服務 (Dynatrace、ServiceNow、Splunk、New Relic、GitLab、PagerDuty)，並將其與代理程式空間建立關聯。
+ 第 **4 部分 （選用）** — 將技能、自訂代理程式和排程觸發新增至代理程式空間，因此代理程式具有自訂知識，且排程觸發程式會自動執行該自訂代理程式。

## 已建立資源
<a name="resources-created"></a>

### 第 1 部分：監控帳戶
<a name="part-1-monitoring-account"></a>
+ **IAM 角色** (`DevOpsAgentRole-AgentSpace-*`) — 由 DevOps Agent 服務擔任以監控帳戶。包括 `AIDevOpsAgentAccessPolicy`受管政策和允許建立 Resource Explorer 服務連結角色的內嵌政策。僅在`existing_agentspace_role_arn`未設定 時建立。
+ **IAM 角色** (`DevOpsAgentRole-WebappAdmin-*`) — 具有客服人員操作`AIDevOpsOperatorAppAccessPolicy`受管政策的操作員應用程式角色。僅在`existing_operator_role_arn`未設定 時建立。
+ **客服人員空間** （可設定的名稱） — 使用 `awscc_devopsagent_agent_space` 資源建立的中央客服人員空間。包括運算子應用程式組態。
+ **關聯** (AWS 監視器） — 使用 `awscc_devopsagent_association` 資源將監控帳戶連結至客服人員空間。
+ **關聯** (AWS 來源） — （選用） 將服務帳戶連結到代理程式空間以進行跨帳戶監控。

### 第 2 部分：服務帳戶 （選用）
<a name="part-2-service-account-optional"></a>
+ **IAM 角色** (`DevOpsAgentRole-SecondaryAccount-TF`) — 具有固定名稱的跨帳戶角色。受監控帳戶中的代理程式空間信任。包括 `AIDevOpsAgentAccessPolicy`受管政策和允許建立 Resource Explorer 服務連結角色的內嵌政策。
+ **Lambda 函數** (`echo-service-tf`) — 回應輸入事件的簡單範例服務。

### 第 4 部分：資產和觸發條件 （選用）
<a name="part-4-assets-and-triggers-optional"></a>

此組態會建立下列資源：
+ **技能** (`rds-performance-investigation`) — 代理程式在相關時載入的技能，使用 `awscc_devopsagent_asset` 資源搭配 `asset_type`的 建立`skill`。
+ **自訂代理程式** (`rds-firefighter`) — 將代理程式範圍限定為具有連接技能的特定工作流程，使用具有 `asset_type`的 `awscc_devopsagent_asset` 資源建立`custom_agent`。
+ **Trigger** (`TIME_BASED`) — 依排程執行自訂代理程式，使用 `awscc_devopsagent_trigger` 資源建立。

## 設定
<a name="setup"></a>

### 步驟 1：複製範例儲存庫
<a name="step-1-clone-the-sample-repository"></a>

```
git clone https://github.com/aws-samples/sample-aws-devops-agent-terraform.git
cd sample-aws-devops-agent-terraform
```

### 步驟 2：設定變數
<a name="step-2-configure-variables"></a>

複製範例變數檔案，並針對您的環境進行自訂：

```
cp terraform.tfvars.example terraform.tfvars
```

`terraform.tfvars` 使用您的客服人員空間名稱和描述進行編輯：

```
agent_space_name        = "MyCompanyAgentSpace"
agent_space_description = "DevOps Agent Space for monitoring production workloads"
```

## 第 1 部分：部署代理程式空間
<a name="part-1-deploy-the-agent-space"></a>

在本節中，您會在監控帳戶中建立代理程式空間、IAM 角色、運算子應用程式和 AWS 關聯。

### 步驟 1：使用自動化部署 （建議）
<a name="step-1-deploy-with-automation-recommended"></a>

使用提供的部署指令碼進行簡化設定：

```
./deploy.sh
```

此指令碼會自動：
+ 檢查先決條件 (Terraform、 AWS CLI、登入資料）
+ 視需要`terraform.tfvars`從範例建立
+ 初始化、驗證、規劃和套用 Terraform

或者，如果您偏好手動控制：

```
terraform init
terraform plan
terraform apply
```

出現提示`yes`時輸入 以確認部署。

### 步驟 2：記錄輸出
<a name="step-2-record-the-outputs"></a>

部署完成後，Terraform 會列印輸出。記錄這些值以供日後使用：

```
Outputs:
agent_space_id              = "abc123"
agent_space_arn             = "arn:aws:aidevops:<REGION>:<MONITORING_ACCOUNT_ID>:agentspace/abc123"
agent_space_name            = "MyCompanyAgentSpace"
devops_agentspace_role_arn  = "arn:aws:iam::<MONITORING_ACCOUNT_ID>:role/DevOpsAgentRole-AgentSpace-a1b2c3d4"
devops_operator_role_arn    = "arn:aws:iam::<MONITORING_ACCOUNT_ID>:role/DevOpsAgentRole-WebappAdmin-a1b2c3d4"
primary_account_id          = "<MONITORING_ACCOUNT_ID>"
primary_account_association_id = "assoc-xyz"
```

如果您打算完成第 2 部分，請儲存該`agent_space_arn`值。您需要它來設定服務帳戶資源。

### 步驟 3：驗證部署
<a name="step-3-verify-the-deployment"></a>

執行部署後驗證指令碼：

```
./post-deploy.sh
```

或使用 AWS CLI 來驗證已成功建立代理程式空間：

```
aws devops-agent get-agent-space \
  --agent-space-id <AGENT_SPACE_ID> \
  --region <REGION>
```

此時，您的代理程式空間會在啟用 運算子應用程式且您的監控帳戶相關聯的情況下部署。代理程式可以監控此帳戶中的問題。

## 第 2 部分 （選用）：新增跨帳戶監控
<a name="part-2-optional-add-cross-account-monitoring"></a>

在本節中，您會擴展設定，讓客服人員空間可以監控第二個 AWS 帳戶 （服務帳戶） 中的資源。這涉及兩個動作：

1. 新增指向服務帳戶的來源 AWS 關聯。

1. 將跨帳戶 IAM 角色和 echo Lambda 函數部署至服務帳戶。

**重要**  
** 您必須完成第 1 部分，才能繼續。服務帳戶資源需要`agent_space_arn`來自第 1 部分部署輸出的 。

### 步驟 1：設定服務帳戶 ID
<a name="step-1-configure-the-service-account-id"></a>

在 中`terraform.tfvars`，設定您的服務帳戶 ID：

```
service_account_id = "<YOUR_SERVICE_ACCOUNT_ID>"
```

### 步驟 2：設定客服人員空間 ARN
<a name="step-2-set-the-agent-space-arn"></a>

從第 1 部分輸出複製 `agent_space_arn`值 （步驟 2)，並在 中設定`terraform.tfvars`：

```
agent_space_arn = "arn:aws:aidevops:<REGION>:<MONITORING_ACCOUNT_ID>:agentspace/<SPACE_ID>"
```

服務帳戶資源使用此值來限制次要帳戶角色的信任政策範圍。只有在設定此值時，才會建立這些資源。

### 步驟 3：設定 `aws.service` 供應商
<a name="step-3-configure-the-awsservice-provider"></a>

在 中`main.tf`，使用服務帳戶的登入資料設定`aws.service`提供者別名。您可以使用具名設定檔或擔任角色：

使用設定檔：

```
provider "aws" {
  alias   = "service"
  region  = var.aws_region
  profile = "your-service-account-profile"
}
```

或使用擔任角色：

```
provider "aws" {
  alias  = "service"
  region = var.aws_region
  assume_role {
    role_arn = "arn:aws:iam::<SERVICE_ACCOUNT_ID>:role/OrganizationAccountAccessRole"
  }
}
```

### 步驟 4：部署
<a name="step-4-deploy"></a>

套用更新的組態：

```
terraform apply
```

這會在服務帳戶中建立下列資源：
+ 信任監控帳戶中客服人員空間的 IAM 角色 (`DevOpsAgentRole-SecondaryAccount-TF`)
+ 以 echo Lambda 函數 (`echo-service-tf`) 做為範例服務

它也會在監控帳戶中建立來源 AWS 關聯，以連結服務帳戶。

### 步驟 5：驗證部署
<a name="step-5-verify-the-deployment"></a>

測試 echo 服務以確認 Lambda 函數已成功部署：

```
aws lambda invoke \
  --function-name echo-service-tf \
  --payload '{"test": "hello world"}' \
  --profile <your-service-account-profile> \
  --region <REGION> \
  response.json
cat response.json
```

## 第 3 部分 （選用）：註冊第三方整合
<a name="part-3-optional-register-third-party-integrations"></a>

在本節中，您會向代理程式空間註冊外部服務 (Dynatrace、ServiceNow、Splunk、New Relic、GitLab、PagerDuty)。這些整合可讓 AWS DevOps 代理程式在調查期間存取遙測、事件資料和來源控制資訊。

與需要單獨的 IntegrationsStack 階段和代理程式空間 ID 手動配線的 AWS CDK 範例不同，這些資源會直接參考代理程式空間，並可部署在第 1 部分`terraform apply`相同的 中。

### 支援的整合
<a name="supported-integrations"></a>


| 服務 | 服務類型 | 身分驗證 | 
| --- | --- | --- | 
| Dynatrace | dynatrace | OAuth 用戶端憑證 | 
| ServiceNow | servicenow | OAuth 用戶端憑證 | 
| Splunk | mcpserversplunk | 承載字符 | 
| New Relic | mcpservernewrelic | API 金鑰 | 
| GitLab | gitlab | 存取權杖 | 
| PagerDuty | pagerduty | OAuth 用戶端憑證 | 

**注意**  
** 資料狗不包含在 Terraform 組態中。連線 Datadog 需要互動式使用者 OAuth 授權 （瀏覽器登入和同意），如 中所述[連接 DataDog](connecting-telemetry-sources-connecting-datadog.md)，Terraform 無法自動化。透過 主控台的功能提供者頁面手動註冊 Datadog。

### 步驟 1：設定整合憑證
<a name="step-1-configure-integration-credentials"></a>

將 `integrations`區塊新增至 `terraform.tfvars`，僅填入您想要的服務。下列範例顯示 Dynatrace 整合：

```
integrations = {
  dynatrace = {
    account_urn   = "<DYNATRACE_ACCOUNT_URN>"
    client_id     = "<DYNATRACE_CLIENT_ID>"
    client_name   = "<DYNATRACE_CLIENT_NAME>"
    client_secret = "<DYNATRACE_CLIENT_SECRET>"
    env_id        = "<DYNATRACE_ENVIRONMENT_ID>"
    resources     = ["<DYNATRACE_RESOURCE_1>"]
  }
}
```

如需每個整合的完整形狀，請參閱範例儲存庫`terraform.tfvars.example`中的 。

**ServiceNow 需求：**一律`instance_id`明確設定為簡短執行個體名稱 （例如，`"ven04972"`— 而非完整 `instance_url`)。如果省略 `instance_id` ，則關聯會回復為 `instance_url`，DevOps Agent API 會使用 拒絕該關聯`400 GeneralServiceException: instanceId '<url>' does not match the registered ServiceNow instance`。

**安全性：**`integrations`變數會標記為 `sensitive`，因此其值會從計劃中修訂並套用輸出。請勿將實際登入資料遞交至 `terraform.tfvars`。對於生產，來自 AWS Secrets Manager 或 AWS Systems Manager 參數存放區的來源秘密 （例如，使用`data`來源），而不是純文字。

### 步驟 2：部署
<a name="step-2-deploy"></a>

套用組態：

```
terraform apply
```

這會為每個啟用的整合建立服務註冊和關聯。

### 步驟 3：檢閱輸出
<a name="step-3-review-the-outputs"></a>

部署完成後，整合輸出會將每個啟用的服務映射至其已註冊IDs：

```
integration_service_ids = {
  "dynatrace" = "service-abc123"
}
integration_association_ids = {
  "dynatrace" = "assoc-xyz789"
}
```

**注意：**Terraform 不會傳回 Webhook URL 和秘密做為輸出，因為秘密是敏感的。`terraform apply` 完成後，在主控台中輪換 Webhook 以取得 URL 和秘密。如需管理 Webhook 登入資料的指示，請參閱[管理 Webhook 登入](configuring-integrations-and-knowledge-invoking-devops-agent-through-webhook.md)資料。

如需為每個服務設定登入資料的詳細資訊，請參閱：
+ [連接 Dynatrace](connecting-telemetry-sources-connecting-dynatrace.md)
+ [連接 ServiceNow](connecting-to-ticketing-and-chat-connecting-servicenow.md)
+ [連接 Splunk](connecting-telemetry-sources-connecting-splunk.md)
+ [連接新複本](connecting-telemetry-sources-connecting-new-relic.md)
+ [連接 GitLab](connecting-to-cicd-pipelines-connecting-gitlab.md)
+ [連接 PagerDuty](connecting-to-ticketing-and-chat-connecting-pagerduty.md)

## 第 4 部分 （選用）：新增技能、自訂代理程式和排程觸發
<a name="part-4-optional-add-a-skill-custom-agent-and-scheduled-trigger"></a>

在本節中，您將三個資源新增至您在第 1 部分中建立的客服人員空間。您可以新增客服人員在相關時載入的**技能**，以及將客服人員範圍限定為特定工作流程的**自訂客服人員**。您也可以新增自動執行自訂代理程式的**排程觸發**。這些資源使用 `awscc_devopsagent_asset`和 `awscc_devopsagent_trigger` 資源。

這些資源可能會對您的帳戶產生額外費用 AWS 。若要在完成時將其移除，請遵循本指南結尾的清除區段。

此範例使用 `skill`和 `custom_agent` 資產類型。相同的`awscc_devopsagent_asset`資源會建立每個資產類型，例如 `memory_store`、 `agents_md`和 `attachment`。若要使用不同的類型，請變更 `asset_type` 引數，並提供 類型所需的中繼資料。如需資產類型的完整清單、其所需的中繼資料和屬性參考，請參閱 [管理資產](about-aws-devops-agent-managing-assets.md)。

**重要**  
** 您必須完成第 1 部分，才能繼續。這些資源需要第 1 部分部署的代理程式空間 ID。

### 步驟 1：新增組態
<a name="step-1-add-the-configuration"></a>

使用下列內容建立名為 `assets.tf` 的檔案。以時間為基礎的觸發動作會依資產 ID 參考自訂代理程式，格式為 `custom:<assetId>`。組態會自動從自訂代理程式的 `asset_id` 屬性進行路由。自訂代理程式的`skills`清單也會採用資產 IDs 而非名稱，因此會參考技能的`asset_id`屬性。這也會為 Terraform 提供隱含相依性，因此技能會在連接它的代理程式之前建立。

請注意， `metadata`和 `action`引數是以字串形式傳遞的 JSON 文件，因此此範例使用 `jsonencode`。

```
variable "agent_space_id" {
  type        = string
  description = "The agent space ID from the Part 1 output"
}

# A skill the agent loads when relevant
resource "awscc_devopsagent_asset" "example_skill" {
  agent_space_id = var.agent_space_id
  asset_type     = "skill"

  metadata = jsonencode({
    name        = "rds-performance-investigation"
    description = "Investigation procedures for RDS performance issues."
    agent_types = ["GENERIC"]
  })

  files = [{
    path         = "SKILL.md"
    content_text = <<-EOT
      # RDS Performance Investigation
      Use this skill when investigating database latency, connection
      errors, or query timeouts.
    EOT
  }]
}

# A custom agent with attached skills that a trigger can invoke
resource "awscc_devopsagent_asset" "example_custom_agent" {
  agent_space_id = var.agent_space_id
  asset_type     = "custom_agent"

  metadata = jsonencode({
    name   = "rds-firefighter"
    skills = [awscc_devopsagent_asset.example_skill.asset_id]
  })

  files = [{
    path         = "AGENT.md"
    content_text = <<-EOT
      # RDS Firefighter
      Custom agent for RDS incidents.
    EOT
  }]
}

# A time-based trigger that runs the custom agent on a schedule
resource "awscc_devopsagent_trigger" "daily" {
  agent_space_id = var.agent_space_id
  type           = "TIME_BASED"

  condition = {
    schedule = {
      expression = "rate(1 day)"
    }
  }

  action = jsonencode({
    actionType = "create:task"
    task = {
      agent = "custom:${awscc_devopsagent_asset.example_custom_agent.asset_id}"
    }
  })

  status = "Active"
}

output "skill_asset_id" {
  description = "The skill asset ID"
  value       = awscc_devopsagent_asset.example_skill.asset_id
}

output "custom_agent_asset_id" {
  description = "The custom agent asset ID"
  value       = awscc_devopsagent_asset.example_custom_agent.asset_id
}

output "trigger_id" {
  description = "The trigger ID"
  value       = awscc_devopsagent_trigger.daily.trigger_id
}
```

如果您要將此項目新增至範例儲存庫，您可以直接參考客服人員空間資源，而不是宣告`agent_space_id`變數。

### 步驟 2：部署
<a name="step-2-deploy"></a>

使用第 1 部分輸出中的`agent_space_id`值`terraform.tfvars`，在 中設定代理程式空間 ID：

```
agent_space_id = "<AGENT_SPACE_ID>"
```

套用組態：

```
terraform apply
```

資產的 `agent_space_id`和 `asset_type`引數僅限建立，觸發器的 `agent_space_id`、`condition`、 `type`和 `action`引數也是如此。變更其中任何一個會取代 資源。您可以更新觸發的 `status`(`Active` 或 `Inactive`)，將其設定為 `Inactive`以暫停觸發，而不將其刪除。

### 步驟 3：驗證部署
<a name="step-3-verify-the-deployment"></a>

若要確認資產和觸發條件已建立，請執行下列 AWS CLI 命令：

```
aws devops-agent list-assets \
  --agent-space-id <AGENT_SPACE_ID> \
  --region <REGION>

aws devops-agent list-triggers \
  --agent-space-id <AGENT_SPACE_ID> \
  --region <REGION>
```

## 使用現有的 IAM 角色 （選用）
<a name="using-existing-iam-roles-optional"></a>

根據預設，Terraform 組態會為代理程式空間和運算子應用程式建立新的 IAM 角色。如果您已有具有必要政策的 IAM 角色，您可以略過角色建立，並改為提供現有的角色 ARNs。

### 要求
<a name="requirements"></a>

現有角色必須符合下列要求：

#### 客服人員空間角色
<a name="agent-space-role"></a>
+ 信任政策允許 使用 `aidevops.amazonaws.com` 擔任角色 `sts:AssumeRole`
+ 已連接 `AIDevOpsAgentAccessPolicy`受管政策
+ （選用） 具有允許建立 Resource Explorer 服務連結角色的內嵌政策

#### Operator 應用程式角色
<a name="operator-app-role"></a>
+ 信任政策允許 使用 `sts:AssumeRole`和 `aidevops.amazonaws.com` 擔任角色 `sts:TagSession`
+ 已連接 `AIDevOpsOperatorAppAccessPolicy`受管政策

### 組態
<a name="configuration"></a>

在 中`terraform.tfvars`，設定一個或兩個角色 ARNs：

```
existing_agentspace_role_arn = "arn:aws:iam::ACCOUNT_ID:role/YourAgentSpaceRole"
existing_operator_role_arn   = "arn:aws:iam::ACCOUNT_ID:role/YourOperatorRole"
```

設定這些值時，`iam.tf`會略過 中對應的角色資源。此方法完全回溯相容 — 具有空值 （預設值） 的現有組態會保留目前的角色建立行為。

## 疑難排解
<a name="troubleshooting"></a>

**IAM 傳播延遲**
+ 組態包含 IAM 角色建立與客服人員空間建立`time_sleep`之間的 30 秒。DevOps Agent 服務會在建立 Agent Space 期間驗證運算子角色的信任政策，如果 IAM 尚未完全傳播，則可能會失敗。如果您仍然看到信任政策錯誤，請等待一分鐘，然後`terraform apply`再次執行 - IAM 角色將已存在，而套用將在停止的位置取得。

**ServiceNow `instanceId does not match`錯誤**
+ 在`service_now`整合區塊中`instance_id`明確設定為簡短執行個體名稱 （例如，`"ven04972"`)，而非完整 `instance_url`。請參閱上述第 3 部分中的備註。

**Dynatrace 關聯 `status: invalid`**
+ 如果 `terraform apply`成功，但產生的關聯報告 `status = "invalid"`（使用 `aws devops-agent get-association`或 主控台可見），這表示 Dynatrace 拒絕 OAuth 用戶端登入資料。針對 `account_urn` Dynatrace `client_id`帳戶重複檢查 `client_secret`、 和 ，而不是 Terraform 組態問題。

**許可錯誤**
+ 確認您的 AWS 登入資料具有建立角色和政策所需的 IAM 許可。
+ 檢查信任政策條件是否符合您的帳戶 ID。

**跨帳戶部署失敗**
+ 必須使用服務帳戶的登入資料來設定`aws.service`提供者。使用具名設定檔或擔任角色區塊。
+ 確認該`agent_space_arn`值符合來自第 1 部分輸出的 ARN。

**找不到 Terraform 資源類型**
+ 確認您有`awscc`提供者版本 `~> 1.0`或更新版本。`awscc_devopsagent_agent_space` 和資源`awscc_devopsagent_association`需要 AWS 雲端控制供應商。
+ 第 4 部分中使用的 `awscc_devopsagent_trigger` `awscc_devopsagent_asset`和資源需要`awscc`提供者版本 1.98.0 或更新版本。執行 `terraform providers` 以檢查您的版本，並在提高版本限制`terraform init -upgrade`之後執行 。

## 清除
<a name="cleanup"></a>

如果您已完成第 4 部分，請先移除技能、自訂代理程式和觸發程序。與將這些資源放在個別堆疊中的 AWS CDK 指南不同， `assets.tf`是相同 Terraform 組態的一部分，因此純 會`terraform destroy`移除代理程式空間。刪除`assets.tf`並套用變更，以僅移除第 4 部分資源：

```
rm assets.tf
terraform apply
```

若要保留檔案，請改為以三個資源為目標：

```
terraform destroy \
  -target=awscc_devopsagent_trigger.daily \
  -target=awscc_devopsagent_asset.example_custom_agent \
  -target=awscc_devopsagent_asset.example_skill
```

僅移除這些資源會使代理程式空間保持不變。如果您將第 4 部分套用到您與他人共用的代理程式空間，或是您在第 1 部分中未建立的代理程式空間，請執行此操作。

若要移除所有其他項目，如果您部署了第 2 部分，請以相反順序銷毀：

```
./cleanup.sh
```

或手動：

```
terraform destroy
```

**警告：**這會永久刪除您的客服人員空間和所有相關聯的資料。在繼續之前，請確定您已備份任何重要資訊。

## 安全考量
<a name="security-considerations"></a>
+ Terraform 組態會建立具有信任政策的 IAM 角色，只允許`aidevops.amazonaws.com`服務主體擔任這些角色。
+ 信任政策包含限制存取特定 AWS 帳戶和客服人員空間 ARN 的條件。
+ 所有政策都遵循最低權限原則。根據組織的安全需求，檢閱和自訂 IAM 政策。
+ 跨帳戶角色 (`DevOpsAgentRole-SecondaryAccount-TF`) 使用固定名稱，範圍為特定的客服人員空間 ARN。

## 後續步驟
<a name="next-steps"></a>

使用 Terraform 部署您的 AWS DevOps 代理程式之後：

1. 請參閱 DevOps Agent [AWS 使用者指南，了解 DevOps Agent](https://docs.aws.amazon.com/devopsagent/latest/userguide/) 功能的完整範圍。

1. 考慮將 Terraform 部署整合到您的 CI/CD 管道，以進行自動化基礎設施管理。

## 其他資源
<a name="additional-resources"></a>
+ [AWS DevOps 代理程式使用者指南](https://docs.aws.amazon.com/devopsagent/latest/userguide/)
+ [範例 Terraform 儲存庫](https://github.com/aws-samples/sample-aws-devops-agent-terraform)
+ [CLI 加入指南](https://docs.aws.amazon.com/devopsagent/latest/userguide/getting-started-with-aws-devops-agent-cli-onboarding-guide.html)
+ *Terraform 登錄*檔中的 [awscc\_devopsagent\_agent\_space](https://registry.terraform.io/providers/hashicorp/awscc/latest/docs/resources/devopsagent_agent_space) 資源
+ *Terraform 登錄*檔中的 [awscc\_devopsagent\_association](https://registry.terraform.io/providers/hashicorp/awscc/latest/docs/resources/devopsagent_association) 資源
+ *Terraform 登錄*檔中的 [awscc\_devopsagent\_private\_connection](https://registry.terraform.io/providers/hashicorp/awscc/latest/docs/resources/devopsagent_private_connection) 資源
+ *Terraform 登錄*檔中的 [awscc\_devopsagent\_asset](https://registry.terraform.io/providers/hashicorp/awscc/latest/docs/resources/devopsagent_asset) 資源
+ *Terraform 登錄*檔中的 [awscc\_devopsagent\_trigger](https://registry.terraform.io/providers/hashicorp/awscc/latest/docs/resources/devopsagent_trigger) 資源
+ [管理資產](about-aws-devops-agent-managing-assets.md)