Skip to content

Commit

Permalink
resource/aws_ecs_capacity_provider: Implement API deletion support
Browse files Browse the repository at this point in the history
Reference: aws/containers-roadmap#632
Reference: #11286
Reference: #13459
Reference: #13722

Output from acceptance testing:

```
--- PASS: TestAccAWSEcsCapacityProvider_ManagedScalingPartial (77.79s)
--- PASS: TestAccAWSEcsCapacityProvider_basic (78.73s)
--- PASS: TestAccAWSEcsCapacityProvider_ManagedScaling (79.56s)
--- PASS: TestAccAWSEcsCapacityProvider_disappears (88.48s)
--- PASS: TestAccAWSEcsCapacityProvider_Tags (112.82s)
```

Output from sweeper in AWS Commercial:

```
2020/06/12 16:08:13 [DEBUG] Running Sweepers for region (us-west-2):
2020/06/12 16:08:13 [DEBUG] Running Sweeper (aws_ecs_service) in region (us-west-2)
...
2020/06/12 16:08:15 [DEBUG] Running Sweeper (aws_ecs_cluster) in region (us-west-2)
2020/06/12 16:08:16 [DEBUG] Running Sweeper (aws_ecs_capacity_provider) in region (us-west-2)
2020/06/12 16:08:17 [INFO] Skipping AWS managed ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/FARGATE
2020/06/12 16:08:17 [INFO] Skipping AWS managed ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/FARGATE_SPOT
2020/06/12 16:08:17 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-1166119573944741428
2020/06/12 16:08:43 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-1214316862074147523
2020/06/12 16:09:09 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-1448279580068890702
2020/06/12 16:09:36 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-1694934460247763588
2020/06/12 16:09:51 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-2072503336804561742
2020/06/12 16:10:07 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-2771105388423480732
2020/06/12 16:10:33 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-2945353957962800997
2020/06/12 16:10:50 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-3144225916222141066
2020/06/12 16:11:16 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-3925899594298666043
2020/06/12 16:11:42 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-3962150016779598144
2020/06/12 16:11:58 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-3963492166120243961
2020/06/12 16:12:14 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-4003358451789399294
2020/06/12 16:12:25 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-4028268499646425502
2020/06/12 16:12:54 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-4153885072251016984
2020/06/12 16:13:11 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-4166399643645447747
2020/06/12 16:13:38 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-4171445239693757279
2020/06/12 16:14:04 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-4172310795125459583
2020/06/12 16:14:19 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-4229992971219388054
2020/06/12 16:14:46 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-4288136819760104193
2020/06/12 16:15:12 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-4349585972519622956
2020/06/12 16:15:27 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-4381531870881126840
2020/06/12 16:15:54 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-4390982455513240070
2020/06/12 16:16:20 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-4453882168869869465
2020/06/12 16:16:36 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-4462346553509157188
2020/06/12 16:17:02 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-4492435413472368421
2020/06/12 16:17:29 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-4555905932664127708
2020/06/12 16:17:45 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-4820010642292065959
2020/06/12 16:18:11 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-4897792034669269783
2020/06/12 16:18:27 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-4952273456961512581
2020/06/12 16:18:53 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-5007546636648720970
2020/06/12 16:19:19 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-5089921342587722398
2020/06/12 16:19:36 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-5131511394050367988
2020/06/12 16:20:02 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-5143960229157641932
2020/06/12 16:20:28 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-5222153959641548243
2020/06/12 16:20:44 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-5269370732004417053
2020/06/12 16:21:00 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-5275218636337132552
2020/06/12 16:21:26 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-5313165225435669238
2020/06/12 16:21:52 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-5317601343303819317
2020/06/12 16:22:08 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-5372605070603715784
2020/06/12 16:22:34 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-5412502102769973938
2020/06/12 16:23:02 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-5487876079860998491
2020/06/12 16:23:18 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-5567555810195504947
2020/06/12 16:23:45 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-5581045694666886319
2020/06/12 16:24:01 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-5662285056233848789
2020/06/12 16:24:27 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-5713399100773622260
2020/06/12 16:24:43 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-5726353295792014153
2020/06/12 16:25:10 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-5865493350582185130
2020/06/12 16:25:36 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-591073430861682304
2020/06/12 16:26:03 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-5930476252063755904
2020/06/12 16:26:19 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-5937268970324997212
2020/06/12 16:26:45 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-5953099240552596596
2020/06/12 16:27:12 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-6057641756664895211
2020/06/12 16:27:38 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-6083822096003411781
2020/06/12 16:27:54 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-6205754862154661839
2020/06/12 16:28:20 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-6215731304109765961
2020/06/12 16:28:47 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-6296575898841968917
2020/06/12 16:29:02 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-6350919186060242363
2020/06/12 16:29:29 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-639960606487313597
2020/06/12 16:29:55 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-6456869725426655556
2020/06/12 16:30:11 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-6500304581377895856
2020/06/12 16:30:38 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-6653618561107033017
2020/06/12 16:31:04 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-6729114271842268893
2020/06/12 16:31:20 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-6775995433221542520
2020/06/12 16:31:46 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-6817922588763015267
2020/06/12 16:32:13 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-7199599500362353884
2020/06/12 16:32:30 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-7252901290386312490
2020/06/12 16:32:58 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-7292037842589943866
2020/06/12 16:33:24 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-7369060240242835464
2020/06/12 16:33:40 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-7382157219112354290
2020/06/12 16:33:56 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-7417716994895301914
2020/06/12 16:34:22 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-7454183675389434080
2020/06/12 16:34:38 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-7537987304515815459
2020/06/12 16:34:54 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-7693588145466990158
2020/06/12 16:35:20 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-7793135634219297619
2020/06/12 16:35:36 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-7836504974793015945
2020/06/12 16:35:51 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-7844648380161784907
2020/06/12 16:36:17 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-7863549980287682432
2020/06/12 16:36:33 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-8075091395649869677
2020/06/12 16:36:49 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-8107431922140390994
2020/06/12 16:37:06 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-8212326920035395934
2020/06/12 16:37:32 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-8343083231986017479
2020/06/12 16:37:49 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-8419113724231589749
2020/06/12 16:38:15 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-8479013015637121848
2020/06/12 16:38:31 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-8513324427187718577
2020/06/12 16:38:57 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-8518715734984959063
2020/06/12 16:39:13 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-8523409579138213660
2020/06/12 16:39:29 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-8623262108381621889
2020/06/12 16:39:45 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-8756990262427217335
2020/06/12 16:40:11 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-8792193062271299449
2020/06/12 16:40:38 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-8929497185392422181
2020/06/12 16:40:53 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-8969595858080325411
2020/06/12 16:41:20 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-8998942493828795857
2020/06/12 16:41:46 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-9035098292990692788
2020/06/12 16:42:04 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-9081526900987647109
2020/06/12 16:42:31 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-9122166340107529186
2020/06/12 16:42:48 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-9126839716162034978
2020/06/12 16:43:14 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-9219402473155355765
2020/06/12 16:43:31 [INFO] Deleting ECS Capacity Provider: arn:aws:ecs:us-west-2:--OMITTED--:capacity-provider/tf-acc-test-961530247773045243
2020/06/12 16:43:59 Sweeper Tests ran successfully:
	- aws_ecs_service
	- aws_ecs_cluster
	- aws_ecs_capacity_provider
2020/06/12 16:43:59 [DEBUG] Running Sweepers for region (us-east-1):
2020/06/12 16:43:59 [DEBUG] Running Sweeper (aws_ecs_service) in region (us-east-1)
...
2020/06/12 16:44:01 [DEBUG] Running Sweeper (aws_ecs_cluster) in region (us-east-1)
2020/06/12 16:44:02 [DEBUG] Running Sweeper (aws_ecs_capacity_provider) in region (us-east-1)
2020/06/12 16:44:02 [INFO] Skipping AWS managed ECS Capacity Provider: arn:aws:ecs:us-east-1:--OMITTED--:capacity-provider/FARGATE
2020/06/12 16:44:02 [INFO] Skipping AWS managed ECS Capacity Provider: arn:aws:ecs:us-east-1:--OMITTED--:capacity-provider/FARGATE_SPOT
2020/06/12 16:44:02 Sweeper Tests ran successfully:
	- aws_ecs_service
	- aws_ecs_cluster
	- aws_ecs_capacity_provider
ok  	github.com/terraform-providers/terraform-provider-aws/aws	2149.008s
```

Output from sweeper in AWS GovCloud (US):

```
2020/06/12 16:44:12 [DEBUG] Running Sweepers for region (us-gov-west-1):
2020/06/12 16:44:12 [DEBUG] Running Sweeper (aws_ecs_service) in region (us-gov-west-1)
...
2020/06/12 16:44:15 [DEBUG] Running Sweeper (aws_ecs_cluster) in region (us-gov-west-1)
2020/06/12 16:44:15 [DEBUG] Running Sweeper (aws_ecs_capacity_provider) in region (us-gov-west-1)
2020/06/12 16:44:16 [INFO] Skipping AWS managed ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/FARGATE
2020/06/12 16:44:16 [INFO] Skipping AWS managed ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/FARGATE_SPOT
2020/06/12 16:44:16 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-1079359272588390431
2020/06/12 16:44:32 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-1091721403030643061
2020/06/12 16:44:49 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-124118701737104973
2020/06/12 16:45:05 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-1469479908550615785
2020/06/12 16:45:21 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-1495328979254299097
2020/06/12 16:45:37 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-1570192552920022875
2020/06/12 16:45:53 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-1702879253617485878
2020/06/12 16:46:10 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-1733051630240083998
2020/06/12 16:46:26 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-1738132548683597872
2020/06/12 16:46:42 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-1805662976645609271
2020/06/12 16:47:09 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-2062192335317079329
2020/06/12 16:47:25 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-2069707065133575272
2020/06/12 16:47:41 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-2150453984918292807
2020/06/12 16:47:57 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-22275916688579299
2020/06/12 16:48:23 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-2253671394065094375
2020/06/12 16:48:49 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-2339228133098955551
2020/06/12 16:49:07 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-2574156211684266178
2020/06/12 16:49:22 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-2752762380700125995
2020/06/12 16:49:48 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-2848989872978494094
2020/06/12 16:50:04 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-2946953622752534318
2020/06/12 16:50:20 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-3090104475356873478
2020/06/12 16:50:46 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-3103740844478557513
2020/06/12 16:51:02 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-3217263961319180477
2020/06/12 16:51:19 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-326240655165255790
2020/06/12 16:51:35 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-3390004477179913570
2020/06/12 16:51:51 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-3436726835335989273
2020/06/12 16:52:07 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-34375498090738970
2020/06/12 16:52:33 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-3507721227677392471
2020/06/12 16:52:52 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-3520766046891218589
2020/06/12 16:53:07 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-358056573252401799
2020/06/12 16:53:24 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-3666070025503284267
2020/06/12 16:53:40 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-3784109517244378956
2020/06/12 16:54:06 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-3820898817682438418
2020/06/12 16:54:23 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-4011506940693376517
2020/06/12 16:54:38 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-4129453105226147385
2020/06/12 16:55:04 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-4197907046127220584
2020/06/12 16:55:20 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-4241770633343722587
2020/06/12 16:55:36 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-4368985032101678892
2020/06/12 16:55:51 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-4439420728626315697
2020/06/12 16:56:08 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-4496714593119619411
2020/06/12 16:56:24 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-4501204739468185120
2020/06/12 16:56:40 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-4567042511816903030
2020/06/12 16:56:56 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-4577682418065442379
2020/06/12 16:57:22 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-4676535917872459824
2020/06/12 16:57:38 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-4702765677836468414
2020/06/12 16:58:04 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-477025602905606478
2020/06/12 16:58:20 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-4853695499339201595
2020/06/12 16:58:36 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-4893123258322799210
2020/06/12 16:58:51 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-5194606615636257359
2020/06/12 16:59:08 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-5206318030543204649
2020/06/12 16:59:25 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-539729257610020514
2020/06/12 16:59:41 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-5586108974564028837
2020/06/12 16:59:57 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-5606817826525324114
2020/06/12 17:00:13 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-5614593278380130199
2020/06/12 17:00:39 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-5714164974269524343
2020/06/12 17:00:56 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-5777601936334426422
2020/06/12 17:01:12 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-5943809032881333271
2020/06/12 17:01:28 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-6245031636814385264
2020/06/12 17:01:45 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-6254238723968645778
2020/06/12 17:02:01 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-6289699168039464661
2020/06/12 17:02:17 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-629892732581660436
2020/06/12 17:02:33 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-637710366700534262
2020/06/12 17:02:50 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-6416618778353496698
2020/06/12 17:03:07 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-6469841988342455847
2020/06/12 17:03:22 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-6574546048640787759
2020/06/12 17:03:38 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-6716032750032290186
2020/06/12 17:03:54 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-6716265721765535018
2020/06/12 17:04:10 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-6875491434630647580
2020/06/12 17:04:26 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-7044978827743853716
2020/06/12 17:04:42 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-705583589249211132
2020/06/12 17:04:58 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-710929199183527839
2020/06/12 17:05:15 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-7138691677249010592
2020/06/12 17:05:33 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-7826596618679709446
2020/06/12 17:05:48 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-7826762715546186838
2020/06/12 17:06:04 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-7861646026289255697
2020/06/12 17:06:20 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-7867972157839323201
2020/06/12 17:06:46 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-7940736878705957151
2020/06/12 17:07:02 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-7979796976286617461
2020/06/12 17:07:18 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-8029412752402447798
2020/06/12 17:07:34 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-8107260796896052449
2020/06/12 17:08:00 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-819058898540929989
2020/06/12 17:08:16 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-8308574199723922186
2020/06/12 17:08:32 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-8348767479935320744
2020/06/12 17:08:58 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-8445543790345720213
2020/06/12 17:09:14 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-8459315989560723109
2020/06/12 17:09:30 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-852133974718322774
2020/06/12 17:09:46 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-857313015089578341
2020/06/12 17:10:02 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-8667170982155728193
2020/06/12 17:10:18 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-8699906308846331113
2020/06/12 17:10:35 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-872591246763788047
2020/06/12 17:10:51 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-8743345519762083033
2020/06/12 17:11:07 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-8904882139544984054
2020/06/12 17:11:23 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-8937249607375741125
2020/06/12 17:11:50 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-9001311395659872235
2020/06/12 17:12:05 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-9036553020323666542
2020/06/12 17:12:22 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-9101050942840404948
2020/06/12 17:12:37 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-9175494597999527555
2020/06/12 17:13:05 [INFO] Deleting ECS Capacity Provider: arn:aws-us-gov:ecs:us-gov-west-1:--OMITTED--:capacity-provider/tf-acc-test-922326287809433763
2020/06/12 17:13:20 Sweeper Tests ran successfully:
	- aws_ecs_service
	- aws_ecs_cluster
	- aws_ecs_capacity_provider
ok  	github.com/terraform-providers/terraform-provider-aws/aws	1749.481s
```
  • Loading branch information
bflad committed Jun 12, 2020
1 parent c20841f commit 9d0a3a2
Show file tree
Hide file tree
Showing 5 changed files with 221 additions and 6 deletions.
36 changes: 36 additions & 0 deletions aws/internal/service/ecs/waiter/status.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package waiter

import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ecs"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
)

const (
// EventSubscription NotFound
CapacityProviderStatusNotFound = "NotFound"

// EventSubscription Unknown
CapacityProviderStatusUnknown = "Unknown"
)

// CapacityProviderStatus fetches the Capacity Provider and its Status
func CapacityProviderStatus(conn *ecs.ECS, capacityProvider string) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
input := &ecs.DescribeCapacityProvidersInput{
CapacityProviders: aws.StringSlice([]string{capacityProvider}),
}

output, err := conn.DescribeCapacityProviders(input)

if err != nil {
return nil, CapacityProviderStatusUnknown, err
}

if len(output.CapacityProviders) == 0 {
return nil, CapacityProviderStatusNotFound, nil
}

return output.CapacityProviders[0], aws.StringValue(output.CapacityProviders[0].Status), nil
}
}
31 changes: 31 additions & 0 deletions aws/internal/service/ecs/waiter/waiter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package waiter

import (
"time"

"github.com/aws/aws-sdk-go/service/ecs"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
)

const (
// Maximum amount of time to wait for a Capacity Provider to return INACTIVE
CapacityProviderInactiveTimeout = 20 * time.Minute
)

// CapacityProviderInactive waits for a Capacity Provider to return INACTIVE
func CapacityProviderInactive(conn *ecs.ECS, capacityProvider string) (*ecs.CapacityProvider, error) {
stateConf := &resource.StateChangeConf{
Pending: []string{ecs.CapacityProviderStatusActive},
Target: []string{ecs.CapacityProviderStatusInactive},
Refresh: CapacityProviderStatus(conn, capacityProvider),
Timeout: CapacityProviderInactiveTimeout,
}

outputRaw, err := stateConf.WaitForState()

if v, ok := outputRaw.(*ecs.CapacityProvider); ok {
return v, err
}

return nil, err
}
25 changes: 23 additions & 2 deletions aws/resource_aws_ecs_capacity_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/keyvaluetags"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/service/ecs/waiter"
)

func resourceAwsEcsCapacityProvider() *schema.Resource {
Expand Down Expand Up @@ -159,6 +160,12 @@ func resourceAwsEcsCapacityProviderRead(d *schema.ResourceData, meta interface{}
return nil
}

if aws.StringValue(provider.Status) == ecs.CapacityProviderStatusInactive {
log.Printf("[WARN] ECS Capacity Provider (%s) is INACTIVE, removing from state", d.Id())
d.SetId("")
return nil
}

d.Set("arn", provider.CapacityProviderArn)
d.Set("name", provider.Name)

Expand Down Expand Up @@ -188,8 +195,22 @@ func resourceAwsEcsCapacityProviderUpdate(d *schema.ResourceData, meta interface
}

func resourceAwsEcsCapacityProviderDelete(d *schema.ResourceData, meta interface{}) error {
// Reference: https://github.com/aws/containers-roadmap/issues/632
log.Printf("[WARN] delete is not yet implemented for ECS capacity providers")
conn := meta.(*AWSClient).ecsconn

input := &ecs.DeleteCapacityProviderInput{
CapacityProvider: aws.String(d.Id()),
}

_, err := conn.DeleteCapacityProvider(input)

if err != nil {
return fmt.Errorf("error deleting ECS Capacity Provider (%s): %w", d.Id(), err)
}

if _, err := waiter.CapacityProviderInactive(conn, d.Id()); err != nil {
return fmt.Errorf("error waiting for ECS Capacity Provider (%s) to delete: %w", d.Id(), err)
}

return nil
}

Expand Down
133 changes: 131 additions & 2 deletions aws/resource_aws_ecs_capacity_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,100 @@ package aws

import (
"fmt"
"log"
"testing"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ecs"
multierror "github.com/hashicorp/go-multierror"
"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/service/ecs/waiter"
)

// TODO sweepers once Delete is implemented
func init() {
resource.AddTestSweepers("aws_ecs_capacity_provider", &resource.Sweeper{
Name: "aws_ecs_capacity_provider",
F: testSweepEcsCapacityProviders,
Dependencies: []string{
"aws_ecs_cluster",
"aws_ecs_service",
},
})
}

func testSweepEcsCapacityProviders(region string) error {
client, err := sharedClientForRegion(region)

if err != nil {
return fmt.Errorf("error getting client: %w", err)
}

conn := client.(*AWSClient).ecsconn
input := &ecs.DescribeCapacityProvidersInput{}
var sweeperErrs *multierror.Error

for {
output, err := conn.DescribeCapacityProviders(input)

if testSweepSkipSweepError(err) {
log.Printf("[WARN] Skipping ECS Capacity Provider sweep for %s: %s", region, err)
return sweeperErrs.ErrorOrNil()
}

if err != nil {
sweeperErrs = multierror.Append(sweeperErrs, fmt.Errorf("error retrieving ECS Capacity Provider: %w", err))
return sweeperErrs
}

for _, capacityProvider := range output.CapacityProviders {
if capacityProvider == nil {
continue
}

arn := aws.StringValue(capacityProvider.CapacityProviderArn)
input := &ecs.DeleteCapacityProviderInput{
CapacityProvider: capacityProvider.CapacityProviderArn,
}

if aws.StringValue(capacityProvider.Name) == "FARGATE" || aws.StringValue(capacityProvider.Name) == "FARGATE_SPOT" {
log.Printf("[INFO] Skipping AWS managed ECS Capacity Provider: %s", arn)
continue
}

if aws.StringValue(capacityProvider.Status) == ecs.CapacityProviderStatusInactive {
log.Printf("[INFO] Skipping ECS Capacity Provider with INACTIVE status: %s", arn)
continue
}

log.Printf("[INFO] Deleting ECS Capacity Provider: %s", arn)
_, err := conn.DeleteCapacityProvider(input)

if err != nil {
sweeperErr := fmt.Errorf("error deleting ECS Capacity Provider (%s): %w", arn, err)
log.Printf("[ERROR] %s", sweeperErr)
sweeperErrs = multierror.Append(sweeperErrs, sweeperErr)
continue
}

if _, err := waiter.CapacityProviderInactive(conn, arn); err != nil {
sweeperErr := fmt.Errorf("error waiting for ECS Capacity Provider (%s) to delete: %w", arn, err)
log.Printf("[ERROR] %s", sweeperErr)
sweeperErrs = multierror.Append(sweeperErrs, sweeperErr)
continue
}
}

if aws.StringValue(output.NextToken) == "" {
break
}

input.NextToken = output.NextToken
}

return sweeperErrs.ErrorOrNil()
}

func TestAccAWSEcsCapacityProvider_basic(t *testing.T) {
var provider ecs.CapacityProvider
Expand Down Expand Up @@ -49,6 +133,28 @@ func TestAccAWSEcsCapacityProvider_basic(t *testing.T) {
})
}

func TestAccAWSEcsCapacityProvider_disappears(t *testing.T) {
var provider ecs.CapacityProvider
rName := acctest.RandomWithPrefix("tf-acc-test")
resourceName := "aws_ecs_capacity_provider.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSEcsCapacityProviderDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSEcsCapacityProviderConfig(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSEcsCapacityProviderExists(resourceName, &provider),
testAccCheckResourceDisappears(testAccProvider, resourceAwsEcsCapacityProvider(), resourceName),
),
ExpectNonEmptyPlan: true,
},
},
})
}

func TestAccAWSEcsCapacityProvider_ManagedScaling(t *testing.T) {
var provider ecs.CapacityProvider
rName := acctest.RandomWithPrefix("tf-acc-test")
Expand Down Expand Up @@ -163,7 +269,30 @@ func TestAccAWSEcsCapacityProvider_Tags(t *testing.T) {
// TODO add an update test config - Reference: https://github.com/aws/containers-roadmap/issues/633

func testAccCheckAWSEcsCapacityProviderDestroy(s *terraform.State) error {
// Reference: https://github.com/aws/containers-roadmap/issues/632
conn := testAccProvider.Meta().(*AWSClient).ecsconn

for _, rs := range s.RootModule().Resources {
if rs.Type != "aws_ecs_capacity_provider" {
continue
}

input := &ecs.DescribeCapacityProvidersInput{
CapacityProviders: aws.StringSlice([]string{rs.Primary.ID}),
}

output, err := conn.DescribeCapacityProviders(input)

if err != nil {
return err
}

for _, capacityProvider := range output.CapacityProviders {
if aws.StringValue(capacityProvider.CapacityProviderArn) == rs.Primary.ID && aws.StringValue(capacityProvider.Status) != ecs.CapacityProviderStatusInactive {
return fmt.Errorf("ECS Capacity Provider (%s) still exists", rs.Primary.ID)
}
}
}

return nil
}

Expand Down
2 changes: 0 additions & 2 deletions website/docs/r/ecs_capacity_provider.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ description: |-

Provides an ECS cluster capacity provider. More information can be found on the [ECS Developer Guide](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/cluster-capacity-providers.html).

~> **NOTE:** The AWS API does not currently support deleting ECS cluster capacity providers. Removing this Terraform resource will only remove the Terraform state for it.

## Example Usage

```hcl
Expand Down

0 comments on commit 9d0a3a2

Please sign in to comment.