|
3 | 3 | * Deletes in reverse dependency order: EC2 → Application → DQS → OSIS → IAM → (preserves AOS/AMP). |
4 | 4 | */ |
5 | 5 | import { OSISClient, DeletePipelineCommand, GetPipelineCommand } from '@aws-sdk/client-osis'; |
6 | | -import { OpenSearchClient, ListApplicationsCommand, DeleteApplicationCommand, DeleteDirectQueryDataSourceCommand, GetApplicationCommand, DescribeDomainCommand } from '@aws-sdk/client-opensearch'; |
| 6 | +import { OpenSearchClient, ListApplicationsCommand, DeleteApplicationCommand, DeleteDirectQueryDataSourceCommand, GetApplicationCommand, DescribeDomainCommand, DeleteDomainCommand } from '@aws-sdk/client-opensearch'; |
7 | 7 | import { IAMClient, DeleteRolePolicyCommand, DeleteRoleCommand, ListRolePoliciesCommand, ListAttachedRolePoliciesCommand, DetachRolePolicyCommand } from '@aws-sdk/client-iam'; |
8 | 8 | import { printStep, printSuccess, printWarning, printInfo, createSpinner } from './ui.mjs'; |
9 | 9 | import { teardownDemoInstance } from './ec2-demo.mjs'; |
@@ -150,7 +150,34 @@ export async function destroy(cfg) { |
150 | 150 | if (e.name !== 'ResourceNotFoundException') printWarning(`Secret cleanup: ${e.message}`); |
151 | 151 | } |
152 | 152 |
|
| 153 | + // 7. OpenSearch domain (if tagged with this stack) |
| 154 | + try { |
| 155 | + const { ResourceGroupsTaggingAPIClient, GetResourcesCommand } = await import('@aws-sdk/client-resource-groups-tagging-api'); |
| 156 | + const tagging = new ResourceGroupsTaggingAPIClient({ region }); |
| 157 | + const { ResourceTagMappingList } = await tagging.send(new GetResourcesCommand({ |
| 158 | + TagFilters: [{ Key: 'observability-stack', Values: [pipelineName] }], |
| 159 | + ResourceTypeFilters: ['es:domain'], |
| 160 | + })); |
| 161 | + for (const r of ResourceTagMappingList || []) { |
| 162 | + const domainName = r.ResourceARN.split('/').pop(); |
| 163 | + await os.send(new DeleteDomainCommand({ DomainName: domainName })); |
| 164 | + printSuccess(`OpenSearch domain '${domainName}' deletion initiated`); |
| 165 | + } |
| 166 | + } catch (e) { printWarning(`Domain cleanup: ${e.message}`); } |
| 167 | + |
| 168 | + // 8. AMP workspace (if tagged with this stack) |
| 169 | + try { |
| 170 | + const { AmpClient, ListWorkspacesCommand, DeleteWorkspaceCommand } = await import('@aws-sdk/client-amp'); |
| 171 | + const amp = new AmpClient({ region }); |
| 172 | + const { workspaces } = await amp.send(new ListWorkspacesCommand({ alias: pipelineName })); |
| 173 | + for (const w of workspaces || []) { |
| 174 | + if (w.alias === pipelineName) { |
| 175 | + await amp.send(new DeleteWorkspaceCommand({ workspaceId: w.workspaceId })); |
| 176 | + printSuccess(`AMP workspace '${w.alias}' deleted`); |
| 177 | + } |
| 178 | + } |
| 179 | + } catch (e) { printWarning(`AMP cleanup: ${e.message}`); } |
| 180 | + |
153 | 181 | console.error(); |
154 | 182 | printSuccess('Destroy complete'); |
155 | | - printInfo('Note: OpenSearch domain and AMP workspace were preserved (shared resources)'); |
156 | 183 | } |
0 commit comments