github.com/richardbowden/terraform@v0.6.12-0.20160901200758-30ea22c25211/terraform/terraform_test.go (about) 1 package terraform 2 3 import ( 4 "flag" 5 "fmt" 6 "io" 7 "io/ioutil" 8 "log" 9 "os" 10 "path/filepath" 11 "strings" 12 "sync" 13 "testing" 14 15 "github.com/hashicorp/go-getter" 16 "github.com/hashicorp/terraform/config" 17 "github.com/hashicorp/terraform/config/module" 18 "github.com/hashicorp/terraform/helper/logging" 19 ) 20 21 // This is the directory where our test fixtures are. 22 const fixtureDir = "./test-fixtures" 23 24 func TestMain(m *testing.M) { 25 flag.Parse() 26 if testing.Verbose() { 27 // if we're verbose, use the logging requested by TF_LOG 28 logging.SetOutput() 29 } else { 30 // otherwise silence all logs 31 log.SetOutput(ioutil.Discard) 32 } 33 34 os.Exit(m.Run()) 35 } 36 37 func tempDir(t *testing.T) string { 38 dir, err := ioutil.TempDir("", "tf") 39 if err != nil { 40 t.Fatalf("err: %s", err) 41 } 42 if err := os.RemoveAll(dir); err != nil { 43 t.Fatalf("err: %s", err) 44 } 45 46 return dir 47 } 48 49 // tempEnv lets you temporarily set an environment variable. It returns 50 // a function to defer to reset the old value. 51 // the old value that should be set via a defer. 52 func tempEnv(t *testing.T, k string, v string) func() { 53 old := os.Getenv(k) 54 os.Setenv(k, v) 55 return func() { os.Setenv(k, old) } 56 } 57 58 func testConfig(t *testing.T, name string) *config.Config { 59 c, err := config.LoadFile(filepath.Join(fixtureDir, name, "main.tf")) 60 if err != nil { 61 t.Fatalf("err: %s", err) 62 } 63 64 return c 65 } 66 67 func testModule(t *testing.T, name string) *module.Tree { 68 mod, err := module.NewTreeModule("", filepath.Join(fixtureDir, name)) 69 if err != nil { 70 t.Fatalf("err: %s", err) 71 } 72 73 s := &getter.FolderStorage{StorageDir: tempDir(t)} 74 if err := mod.Load(s, module.GetModeGet); err != nil { 75 t.Fatalf("err: %s", err) 76 } 77 78 return mod 79 } 80 81 // testModuleInline takes a map of path -> config strings and yields a config 82 // structure with those files loaded from disk 83 func testModuleInline(t *testing.T, config map[string]string) *module.Tree { 84 cfgPath, err := ioutil.TempDir("", "tf-test") 85 if err != nil { 86 t.Errorf("Error creating temporary directory for config: %s", err) 87 } 88 defer os.RemoveAll(cfgPath) 89 90 for path, configStr := range config { 91 dir := filepath.Dir(path) 92 if dir != "." { 93 err := os.MkdirAll(filepath.Join(cfgPath, dir), os.FileMode(0777)) 94 if err != nil { 95 t.Fatalf("Error creating subdir: %s", err) 96 } 97 } 98 // Write the configuration 99 cfgF, err := os.Create(filepath.Join(cfgPath, path)) 100 if err != nil { 101 t.Fatalf("Error creating temporary file for config: %s", err) 102 } 103 104 _, err = io.Copy(cfgF, strings.NewReader(configStr)) 105 cfgF.Close() 106 if err != nil { 107 t.Fatalf("Error creating temporary file for config: %s", err) 108 } 109 } 110 111 // Parse the configuration 112 mod, err := module.NewTreeModule("", cfgPath) 113 if err != nil { 114 t.Fatalf("Error loading configuration: %s", err) 115 } 116 117 // Load the modules 118 modStorage := &getter.FolderStorage{ 119 StorageDir: filepath.Join(cfgPath, ".tfmodules"), 120 } 121 err = mod.Load(modStorage, module.GetModeGet) 122 if err != nil { 123 t.Errorf("Error downloading modules: %s", err) 124 } 125 126 return mod 127 } 128 129 func testStringMatch(t *testing.T, s fmt.Stringer, expected string) { 130 actual := strings.TrimSpace(s.String()) 131 expected = strings.TrimSpace(expected) 132 if actual != expected { 133 t.Fatalf("Actual\n\n%s\n\nExpected:\n\n%s", actual, expected) 134 } 135 } 136 137 func testProviderFuncFixed(rp ResourceProvider) ResourceProviderFactory { 138 return func() (ResourceProvider, error) { 139 return rp, nil 140 } 141 } 142 143 func testProvisionerFuncFixed(rp ResourceProvisioner) ResourceProvisionerFactory { 144 return func() (ResourceProvisioner, error) { 145 return rp, nil 146 } 147 } 148 149 // HookRecordApplyOrder is a test hook that records the order of applies 150 // by recording the PreApply event. 151 type HookRecordApplyOrder struct { 152 NilHook 153 154 Active bool 155 156 IDs []string 157 States []*InstanceState 158 Diffs []*InstanceDiff 159 160 l sync.Mutex 161 } 162 163 func (h *HookRecordApplyOrder) PreApply( 164 info *InstanceInfo, 165 s *InstanceState, 166 d *InstanceDiff) (HookAction, error) { 167 if h.Active { 168 h.l.Lock() 169 defer h.l.Unlock() 170 171 h.IDs = append(h.IDs, info.Id) 172 h.Diffs = append(h.Diffs, d) 173 h.States = append(h.States, s) 174 } 175 176 return HookActionContinue, nil 177 } 178 179 // Below are all the constant strings that are the expected output for 180 // various tests. 181 182 const testTerraformInputProviderStr = ` 183 aws_instance.bar: 184 ID = foo 185 bar = override 186 foo = us-east-1 187 type = aws_instance 188 aws_instance.foo: 189 ID = foo 190 bar = baz 191 num = 2 192 type = aws_instance 193 ` 194 195 const testTerraformInputProviderOnlyStr = ` 196 aws_instance.foo: 197 ID = foo 198 foo = us-west-2 199 type = aws_instance 200 ` 201 202 const testTerraformInputVarOnlyStr = ` 203 aws_instance.foo: 204 ID = foo 205 foo = us-east-1 206 type = aws_instance 207 ` 208 209 const testTerraformInputVarOnlyUnsetStr = ` 210 aws_instance.foo: 211 ID = foo 212 bar = baz 213 foo = foovalue 214 type = aws_instance 215 ` 216 217 const testTerraformInputVarsStr = ` 218 aws_instance.bar: 219 ID = foo 220 bar = override 221 foo = us-east-1 222 type = aws_instance 223 aws_instance.foo: 224 ID = foo 225 bar = baz 226 num = 2 227 type = aws_instance 228 ` 229 230 const testTerraformApplyStr = ` 231 aws_instance.bar: 232 ID = foo 233 foo = bar 234 type = aws_instance 235 aws_instance.foo: 236 ID = foo 237 num = 2 238 type = aws_instance 239 ` 240 241 const testTerraformApplyRefCountStr = ` 242 aws_instance.bar: 243 ID = foo 244 foo = 3 245 type = aws_instance 246 247 Dependencies: 248 aws_instance.foo 249 aws_instance.foo.0: 250 ID = foo 251 aws_instance.foo.1: 252 ID = foo 253 aws_instance.foo.2: 254 ID = foo 255 ` 256 257 const testTerraformApplyProviderAliasStr = ` 258 aws_instance.bar: 259 ID = foo 260 provider = aws.bar 261 foo = bar 262 type = aws_instance 263 aws_instance.foo: 264 ID = foo 265 num = 2 266 type = aws_instance 267 ` 268 269 const testTerraformApplyEmptyModuleStr = ` 270 <no state> 271 Outputs: 272 273 end = XXXX 274 275 module.child: 276 <no state> 277 Outputs: 278 279 aws_access_key = YYYYY 280 aws_route53_zone_id = XXXX 281 aws_secret_key = ZZZZ 282 ` 283 284 const testTerraformApplyDependsCreateBeforeStr = ` 285 aws_instance.lb: 286 ID = foo 287 instance = foo 288 type = aws_instance 289 290 Dependencies: 291 aws_instance.web 292 aws_instance.web: 293 ID = foo 294 require_new = ami-new 295 type = aws_instance 296 ` 297 298 const testTerraformApplyCreateBeforeStr = ` 299 aws_instance.bar: 300 ID = foo 301 require_new = xyz 302 type = aws_instance 303 ` 304 305 const testTerraformApplyCreateBeforeUpdateStr = ` 306 aws_instance.bar: 307 ID = foo 308 foo = baz 309 type = aws_instance 310 ` 311 312 const testTerraformApplyCancelStr = ` 313 aws_instance.foo: 314 ID = foo 315 num = 2 316 ` 317 318 const testTerraformApplyComputeStr = ` 319 aws_instance.bar: 320 ID = foo 321 foo = computed_dynamical 322 type = aws_instance 323 324 Dependencies: 325 aws_instance.foo 326 aws_instance.foo: 327 ID = foo 328 dynamical = computed_dynamical 329 num = 2 330 type = aws_instance 331 ` 332 333 const testTerraformApplyCountDecStr = ` 334 aws_instance.foo.0: 335 ID = bar 336 foo = foo 337 type = aws_instance 338 aws_instance.foo.1: 339 ID = bar 340 foo = foo 341 type = aws_instance 342 ` 343 344 const testTerraformApplyCountDecToOneStr = ` 345 aws_instance.foo: 346 ID = bar 347 foo = foo 348 type = aws_instance 349 ` 350 351 const testTerraformApplyCountDecToOneCorruptedStr = ` 352 aws_instance.foo: 353 ID = bar 354 foo = foo 355 type = aws_instance 356 ` 357 358 const testTerraformApplyCountDecToOneCorruptedPlanStr = ` 359 DIFF: 360 361 DESTROY: aws_instance.foo.0 362 363 STATE: 364 365 aws_instance.foo: 366 ID = bar 367 foo = foo 368 type = aws_instance 369 aws_instance.foo.0: 370 ID = baz 371 type = aws_instance 372 ` 373 374 const testTerraformApplyCountTaintedStr = ` 375 <no state> 376 ` 377 378 const testTerraformApplyCountVariableStr = ` 379 aws_instance.foo.0: 380 ID = foo 381 foo = foo 382 type = aws_instance 383 aws_instance.foo.1: 384 ID = foo 385 foo = foo 386 type = aws_instance 387 ` 388 389 const testTerraformApplyCountVariableRefStr = ` 390 aws_instance.bar: 391 ID = foo 392 foo = 2 393 type = aws_instance 394 395 Dependencies: 396 aws_instance.foo 397 aws_instance.foo.0: 398 ID = foo 399 aws_instance.foo.1: 400 ID = foo 401 ` 402 403 const testTerraformApplyMinimalStr = ` 404 aws_instance.bar: 405 ID = foo 406 aws_instance.foo: 407 ID = foo 408 ` 409 410 const testTerraformApplyModuleStr = ` 411 aws_instance.bar: 412 ID = foo 413 foo = bar 414 type = aws_instance 415 aws_instance.foo: 416 ID = foo 417 num = 2 418 type = aws_instance 419 420 module.child: 421 aws_instance.baz: 422 ID = foo 423 foo = bar 424 type = aws_instance 425 ` 426 427 const testTerraformApplyModuleBoolStr = ` 428 aws_instance.bar: 429 ID = foo 430 foo = 1 431 type = aws_instance 432 433 Dependencies: 434 module.child 435 436 module.child: 437 <no state> 438 Outputs: 439 440 leader = 1 441 ` 442 443 const testTerraformApplyModuleDestroyOrderStr = ` 444 <no state> 445 module.child: 446 <no state> 447 ` 448 449 const testTerraformApplyMultiProviderStr = ` 450 aws_instance.bar: 451 ID = foo 452 foo = bar 453 type = aws_instance 454 do_instance.foo: 455 ID = foo 456 num = 2 457 type = do_instance 458 ` 459 460 const testTerraformApplyModuleOnlyProviderStr = ` 461 <no state> 462 module.child: 463 aws_instance.foo: 464 ID = foo 465 test_instance.foo: 466 ID = foo 467 ` 468 469 const testTerraformApplyModuleProviderAliasStr = ` 470 <no state> 471 module.child: 472 aws_instance.foo: 473 ID = foo 474 provider = aws.eu 475 ` 476 477 const testTerraformApplyOutputOrphanStr = ` 478 <no state> 479 Outputs: 480 481 foo = bar 482 ` 483 484 const testTerraformApplyProvisionerStr = ` 485 aws_instance.bar: 486 ID = foo 487 488 Dependencies: 489 aws_instance.foo 490 aws_instance.foo: 491 ID = foo 492 dynamical = computed_dynamical 493 num = 2 494 type = aws_instance 495 ` 496 497 const testTerraformApplyProvisionerFailStr = ` 498 aws_instance.bar: (tainted) 499 ID = foo 500 aws_instance.foo: 501 ID = foo 502 num = 2 503 type = aws_instance 504 ` 505 506 const testTerraformApplyProvisionerFailCreateStr = ` 507 aws_instance.bar: (tainted) 508 ID = foo 509 ` 510 511 const testTerraformApplyProvisionerFailCreateNoIdStr = ` 512 <no state> 513 ` 514 515 const testTerraformApplyProvisionerFailCreateBeforeDestroyStr = ` 516 aws_instance.bar: (1 deposed) 517 ID = bar 518 require_new = abc 519 Deposed ID 1 = foo (tainted) 520 ` 521 522 const testTerraformApplyProvisionerResourceRefStr = ` 523 aws_instance.bar: 524 ID = foo 525 num = 2 526 type = aws_instance 527 ` 528 529 const testTerraformApplyProvisionerSelfRefStr = ` 530 aws_instance.foo: 531 ID = foo 532 foo = bar 533 type = aws_instance 534 ` 535 536 const testTerraformApplyProvisionerMultiSelfRefStr = ` 537 aws_instance.foo.0: 538 ID = foo 539 foo = number 0 540 type = aws_instance 541 aws_instance.foo.1: 542 ID = foo 543 foo = number 1 544 type = aws_instance 545 aws_instance.foo.2: 546 ID = foo 547 foo = number 2 548 type = aws_instance 549 ` 550 551 const testTerraformApplyProvisionerDiffStr = ` 552 aws_instance.bar: 553 ID = foo 554 foo = bar 555 type = aws_instance 556 ` 557 558 const testTerraformApplyDestroyStr = ` 559 <no state> 560 ` 561 562 const testTerraformApplyDestroyNestedModuleStr = ` 563 module.child.subchild: 564 <no state> 565 ` 566 567 const testTerraformApplyErrorStr = ` 568 aws_instance.bar: 569 ID = bar 570 571 Dependencies: 572 aws_instance.foo 573 aws_instance.foo: 574 ID = foo 575 num = 2 576 ` 577 578 const testTerraformApplyErrorCreateBeforeDestroyStr = ` 579 aws_instance.bar: 580 ID = bar 581 require_new = abc 582 ` 583 584 const testTerraformApplyErrorDestroyCreateBeforeDestroyStr = ` 585 aws_instance.bar: (1 deposed) 586 ID = foo 587 Deposed ID 1 = bar 588 ` 589 590 const testTerraformApplyErrorPartialStr = ` 591 aws_instance.bar: 592 ID = bar 593 594 Dependencies: 595 aws_instance.foo 596 aws_instance.foo: 597 ID = foo 598 num = 2 599 ` 600 601 const testTerraformApplyTaintStr = ` 602 aws_instance.bar: 603 ID = foo 604 num = 2 605 type = aws_instance 606 ` 607 608 const testTerraformApplyTaintDepStr = ` 609 aws_instance.bar: 610 ID = bar 611 foo = foo 612 num = 2 613 type = aws_instance 614 615 Dependencies: 616 aws_instance.foo 617 aws_instance.foo: 618 ID = foo 619 num = 2 620 type = aws_instance 621 ` 622 623 const testTerraformApplyTaintDepRequireNewStr = ` 624 aws_instance.bar: 625 ID = foo 626 foo = foo 627 require_new = yes 628 type = aws_instance 629 630 Dependencies: 631 aws_instance.foo 632 aws_instance.foo: 633 ID = foo 634 num = 2 635 type = aws_instance 636 ` 637 638 const testTerraformApplyOutputStr = ` 639 aws_instance.bar: 640 ID = foo 641 foo = bar 642 type = aws_instance 643 aws_instance.foo: 644 ID = foo 645 num = 2 646 type = aws_instance 647 648 Outputs: 649 650 foo_num = 2 651 ` 652 653 const testTerraformApplyOutputAddStr = ` 654 aws_instance.test.0: 655 ID = foo 656 foo = foo0 657 type = aws_instance 658 aws_instance.test.1: 659 ID = foo 660 foo = foo1 661 type = aws_instance 662 663 Outputs: 664 665 firstOutput = foo0 666 secondOutput = foo1 667 ` 668 669 const testTerraformApplyOutputListStr = ` 670 aws_instance.bar.0: 671 ID = foo 672 foo = bar 673 type = aws_instance 674 aws_instance.bar.1: 675 ID = foo 676 foo = bar 677 type = aws_instance 678 aws_instance.bar.2: 679 ID = foo 680 foo = bar 681 type = aws_instance 682 aws_instance.foo: 683 ID = foo 684 num = 2 685 type = aws_instance 686 687 Outputs: 688 689 foo_num = [bar,bar,bar] 690 ` 691 692 const testTerraformApplyOutputMultiStr = ` 693 aws_instance.bar.0: 694 ID = foo 695 foo = bar 696 type = aws_instance 697 aws_instance.bar.1: 698 ID = foo 699 foo = bar 700 type = aws_instance 701 aws_instance.bar.2: 702 ID = foo 703 foo = bar 704 type = aws_instance 705 aws_instance.foo: 706 ID = foo 707 num = 2 708 type = aws_instance 709 710 Outputs: 711 712 foo_num = bar,bar,bar 713 ` 714 715 const testTerraformApplyOutputMultiIndexStr = ` 716 aws_instance.bar.0: 717 ID = foo 718 foo = bar 719 type = aws_instance 720 aws_instance.bar.1: 721 ID = foo 722 foo = bar 723 type = aws_instance 724 aws_instance.bar.2: 725 ID = foo 726 foo = bar 727 type = aws_instance 728 aws_instance.foo: 729 ID = foo 730 num = 2 731 type = aws_instance 732 733 Outputs: 734 735 foo_num = bar 736 ` 737 738 const testTerraformApplyUnknownAttrStr = ` 739 aws_instance.foo: 740 ID = foo 741 num = 2 742 type = aws_instance 743 ` 744 745 const testTerraformApplyVarsStr = ` 746 aws_instance.bar: 747 ID = foo 748 bar = foo 749 baz = override 750 foo = us-west-2 751 type = aws_instance 752 aws_instance.foo: 753 ID = foo 754 bar = baz 755 list = Hello,World 756 map = Baz,Foo,Hello 757 num = 2 758 type = aws_instance 759 ` 760 761 const testTerraformApplyVarsEnvStr = ` 762 aws_instance.bar: 763 ID = foo 764 bar = Hello,World 765 baz = Baz,Foo,Hello 766 foo = baz 767 type = aws_instance 768 ` 769 770 const testTerraformPlanStr = ` 771 DIFF: 772 773 CREATE: aws_instance.bar 774 foo: "" => "2" 775 type: "" => "aws_instance" 776 CREATE: aws_instance.foo 777 num: "" => "2" 778 type: "" => "aws_instance" 779 780 STATE: 781 782 <no state> 783 ` 784 785 const testTerraformPlanComputedStr = ` 786 DIFF: 787 788 CREATE: aws_instance.bar 789 foo: "" => "<computed>" 790 type: "" => "aws_instance" 791 CREATE: aws_instance.foo 792 foo: "" => "<computed>" 793 num: "" => "2" 794 type: "" => "aws_instance" 795 796 STATE: 797 798 <no state> 799 ` 800 801 const testTerraformPlanComputedIdStr = ` 802 DIFF: 803 804 CREATE: aws_instance.bar 805 foo: "" => "<computed>" 806 type: "" => "aws_instance" 807 CREATE: aws_instance.foo 808 foo: "" => "<computed>" 809 num: "" => "2" 810 type: "" => "aws_instance" 811 812 STATE: 813 814 <no state> 815 ` 816 817 const testTerraformPlanComputedListStr = ` 818 DIFF: 819 820 CREATE: aws_instance.bar 821 foo: "" => "<computed>" 822 type: "" => "aws_instance" 823 CREATE: aws_instance.foo 824 list.#: "" => "<computed>" 825 num: "" => "2" 826 type: "" => "aws_instance" 827 828 STATE: 829 830 <no state> 831 ` 832 833 const testTerraformPlanCountStr = ` 834 DIFF: 835 836 CREATE: aws_instance.bar 837 foo: "" => "foo,foo,foo,foo,foo" 838 type: "" => "aws_instance" 839 CREATE: aws_instance.foo.0 840 foo: "" => "foo" 841 type: "" => "aws_instance" 842 CREATE: aws_instance.foo.1 843 foo: "" => "foo" 844 type: "" => "aws_instance" 845 CREATE: aws_instance.foo.2 846 foo: "" => "foo" 847 type: "" => "aws_instance" 848 CREATE: aws_instance.foo.3 849 foo: "" => "foo" 850 type: "" => "aws_instance" 851 CREATE: aws_instance.foo.4 852 foo: "" => "foo" 853 type: "" => "aws_instance" 854 855 STATE: 856 857 <no state> 858 ` 859 860 const testTerraformPlanCountIndexStr = ` 861 DIFF: 862 863 CREATE: aws_instance.foo.0 864 foo: "" => "0" 865 type: "" => "aws_instance" 866 CREATE: aws_instance.foo.1 867 foo: "" => "1" 868 type: "" => "aws_instance" 869 870 STATE: 871 872 <no state> 873 ` 874 875 const testTerraformPlanCountIndexZeroStr = ` 876 DIFF: 877 878 CREATE: aws_instance.foo 879 foo: "" => "0" 880 type: "" => "aws_instance" 881 882 STATE: 883 884 <no state> 885 ` 886 887 const testTerraformPlanCountOneIndexStr = ` 888 DIFF: 889 890 CREATE: aws_instance.bar 891 foo: "" => "foo" 892 type: "" => "aws_instance" 893 CREATE: aws_instance.foo 894 foo: "" => "foo" 895 type: "" => "aws_instance" 896 897 STATE: 898 899 <no state> 900 ` 901 902 const testTerraformPlanCountZeroStr = ` 903 DIFF: 904 905 CREATE: aws_instance.bar 906 foo: "" => "" 907 type: "" => "aws_instance" 908 909 STATE: 910 911 <no state> 912 ` 913 914 const testTerraformPlanCountVarStr = ` 915 DIFF: 916 917 CREATE: aws_instance.bar 918 foo: "" => "foo,foo,foo" 919 type: "" => "aws_instance" 920 CREATE: aws_instance.foo.0 921 foo: "" => "foo" 922 type: "" => "aws_instance" 923 CREATE: aws_instance.foo.1 924 foo: "" => "foo" 925 type: "" => "aws_instance" 926 CREATE: aws_instance.foo.2 927 foo: "" => "foo" 928 type: "" => "aws_instance" 929 930 STATE: 931 932 <no state> 933 ` 934 935 const testTerraformPlanCountDecreaseStr = ` 936 DIFF: 937 938 CREATE: aws_instance.bar 939 foo: "" => "bar" 940 type: "" => "aws_instance" 941 DESTROY: aws_instance.foo.1 942 DESTROY: aws_instance.foo.2 943 944 STATE: 945 946 aws_instance.foo.0: 947 ID = bar 948 foo = foo 949 type = aws_instance 950 aws_instance.foo.1: 951 ID = bar 952 aws_instance.foo.2: 953 ID = bar 954 ` 955 956 const testTerraformPlanCountIncreaseStr = ` 957 DIFF: 958 959 CREATE: aws_instance.bar 960 foo: "" => "bar" 961 type: "" => "aws_instance" 962 CREATE: aws_instance.foo.1 963 foo: "" => "foo" 964 type: "" => "aws_instance" 965 CREATE: aws_instance.foo.2 966 foo: "" => "foo" 967 type: "" => "aws_instance" 968 969 STATE: 970 971 aws_instance.foo: 972 ID = bar 973 foo = foo 974 type = aws_instance 975 ` 976 977 const testTerraformPlanCountIncreaseFromOneStr = ` 978 DIFF: 979 980 CREATE: aws_instance.bar 981 foo: "" => "bar" 982 type: "" => "aws_instance" 983 CREATE: aws_instance.foo.1 984 foo: "" => "foo" 985 type: "" => "aws_instance" 986 CREATE: aws_instance.foo.2 987 foo: "" => "foo" 988 type: "" => "aws_instance" 989 990 STATE: 991 992 aws_instance.foo.0: 993 ID = bar 994 foo = foo 995 type = aws_instance 996 ` 997 998 const testTerraformPlanCountIncreaseFromOneCorruptedStr = ` 999 DIFF: 1000 1001 CREATE: aws_instance.bar 1002 foo: "" => "bar" 1003 type: "" => "aws_instance" 1004 DESTROY: aws_instance.foo 1005 CREATE: aws_instance.foo.1 1006 foo: "" => "foo" 1007 type: "" => "aws_instance" 1008 CREATE: aws_instance.foo.2 1009 foo: "" => "foo" 1010 type: "" => "aws_instance" 1011 1012 STATE: 1013 1014 aws_instance.foo: 1015 ID = bar 1016 foo = foo 1017 type = aws_instance 1018 aws_instance.foo.0: 1019 ID = bar 1020 foo = foo 1021 type = aws_instance 1022 ` 1023 1024 const testTerraformPlanDestroyStr = ` 1025 DIFF: 1026 1027 DESTROY: aws_instance.one 1028 DESTROY: aws_instance.two 1029 1030 STATE: 1031 1032 aws_instance.one: 1033 ID = bar 1034 aws_instance.two: 1035 ID = baz 1036 ` 1037 1038 const testTerraformPlanDiffVarStr = ` 1039 DIFF: 1040 1041 CREATE: aws_instance.bar 1042 num: "" => "3" 1043 type: "" => "aws_instance" 1044 UPDATE: aws_instance.foo 1045 num: "2" => "3" 1046 1047 STATE: 1048 1049 aws_instance.foo: 1050 ID = bar 1051 num = 2 1052 ` 1053 1054 const testTerraformPlanEmptyStr = ` 1055 DIFF: 1056 1057 CREATE: aws_instance.bar 1058 CREATE: aws_instance.foo 1059 1060 STATE: 1061 1062 <no state> 1063 ` 1064 1065 const testTerraformPlanEscapedVarStr = ` 1066 DIFF: 1067 1068 CREATE: aws_instance.foo 1069 foo: "" => "bar-${baz}" 1070 type: "" => "aws_instance" 1071 1072 STATE: 1073 1074 <no state> 1075 ` 1076 1077 const testTerraformPlanModulesStr = ` 1078 DIFF: 1079 1080 CREATE: aws_instance.bar 1081 foo: "" => "2" 1082 type: "" => "aws_instance" 1083 CREATE: aws_instance.foo 1084 num: "" => "2" 1085 type: "" => "aws_instance" 1086 1087 module.child: 1088 CREATE: aws_instance.foo 1089 num: "" => "2" 1090 type: "" => "aws_instance" 1091 1092 STATE: 1093 1094 <no state> 1095 ` 1096 1097 const testTerraformPlanModuleCycleStr = ` 1098 DIFF: 1099 1100 CREATE: aws_instance.b 1101 CREATE: aws_instance.c 1102 some_input: "" => "<computed>" 1103 type: "" => "aws_instance" 1104 1105 STATE: 1106 1107 <no state> 1108 ` 1109 1110 const testTerraformPlanModuleDestroyStr = ` 1111 DIFF: 1112 1113 DESTROY: aws_instance.foo 1114 1115 module.child: 1116 DESTROY MODULE 1117 DESTROY: aws_instance.foo 1118 1119 STATE: 1120 1121 aws_instance.foo: 1122 ID = bar 1123 1124 module.child: 1125 aws_instance.foo: 1126 ID = bar 1127 ` 1128 1129 const testTerraformPlanModuleDestroyCycleStr = ` 1130 DIFF: 1131 1132 module.a_module: 1133 DESTROY MODULE 1134 DESTROY: aws_instance.a 1135 module.b_module: 1136 DESTROY MODULE 1137 DESTROY: aws_instance.b 1138 1139 STATE: 1140 1141 module.a_module: 1142 aws_instance.a: 1143 ID = a 1144 module.b_module: 1145 aws_instance.b: 1146 ID = b 1147 ` 1148 1149 const testTerraformPlanModuleDestroyMultivarStr = ` 1150 DIFF: 1151 1152 module.child: 1153 DESTROY MODULE 1154 DESTROY: aws_instance.foo.0 1155 DESTROY: aws_instance.foo.1 1156 1157 STATE: 1158 1159 <no state> 1160 module.child: 1161 aws_instance.foo.0: 1162 ID = bar0 1163 aws_instance.foo.1: 1164 ID = bar1 1165 ` 1166 1167 const testTerraformPlanModuleInputStr = ` 1168 DIFF: 1169 1170 CREATE: aws_instance.bar 1171 foo: "" => "2" 1172 type: "" => "aws_instance" 1173 1174 module.child: 1175 CREATE: aws_instance.foo 1176 foo: "" => "42" 1177 type: "" => "aws_instance" 1178 1179 STATE: 1180 1181 <no state> 1182 ` 1183 1184 const testTerraformPlanModuleInputComputedStr = ` 1185 DIFF: 1186 1187 CREATE: aws_instance.bar 1188 foo: "" => "<computed>" 1189 type: "" => "aws_instance" 1190 1191 module.child: 1192 CREATE: aws_instance.foo 1193 foo: "" => "<computed>" 1194 type: "" => "aws_instance" 1195 1196 STATE: 1197 1198 <no state> 1199 ` 1200 1201 const testTerraformPlanModuleInputVarStr = ` 1202 DIFF: 1203 1204 CREATE: aws_instance.bar 1205 foo: "" => "2" 1206 type: "" => "aws_instance" 1207 1208 module.child: 1209 CREATE: aws_instance.foo 1210 foo: "" => "52" 1211 type: "" => "aws_instance" 1212 1213 STATE: 1214 1215 <no state> 1216 ` 1217 1218 const testTerraformPlanModuleMultiVarStr = ` 1219 DIFF: 1220 1221 CREATE: aws_instance.parent.0 1222 CREATE: aws_instance.parent.1 1223 1224 module.child: 1225 CREATE: aws_instance.bar.0 1226 baz: "" => "baz" 1227 type: "" => "aws_instance" 1228 CREATE: aws_instance.bar.1 1229 baz: "" => "baz" 1230 type: "" => "aws_instance" 1231 CREATE: aws_instance.foo 1232 foo: "" => "baz,baz" 1233 type: "" => "aws_instance" 1234 1235 STATE: 1236 1237 <no state> 1238 ` 1239 1240 const testTerraformPlanModuleOrphansStr = ` 1241 DIFF: 1242 1243 CREATE: aws_instance.foo 1244 num: "" => "2" 1245 type: "" => "aws_instance" 1246 1247 module.child: 1248 DESTROY: aws_instance.foo 1249 1250 STATE: 1251 1252 module.child: 1253 aws_instance.foo: 1254 ID = baz 1255 ` 1256 1257 const testTerraformPlanModuleVarStr = ` 1258 DIFF: 1259 1260 CREATE: aws_instance.bar 1261 foo: "" => "2" 1262 type: "" => "aws_instance" 1263 1264 module.child: 1265 CREATE: aws_instance.foo 1266 num: "" => "2" 1267 type: "" => "aws_instance" 1268 1269 STATE: 1270 1271 <no state> 1272 ` 1273 1274 const testTerraformPlanModuleVarComputedStr = ` 1275 DIFF: 1276 1277 CREATE: aws_instance.bar 1278 foo: "" => "<computed>" 1279 type: "" => "aws_instance" 1280 1281 module.child: 1282 CREATE: aws_instance.foo 1283 foo: "" => "<computed>" 1284 type: "" => "aws_instance" 1285 1286 STATE: 1287 1288 <no state> 1289 ` 1290 1291 const testTerraformPlanModuleVarIntStr = ` 1292 DIFF: 1293 1294 module.child: 1295 CREATE: aws_instance.foo 1296 num: "" => "2" 1297 type: "" => "aws_instance" 1298 1299 STATE: 1300 1301 <no state> 1302 ` 1303 1304 const testTerraformPlanOrphanStr = ` 1305 DIFF: 1306 1307 DESTROY: aws_instance.baz 1308 CREATE: aws_instance.foo 1309 num: "" => "2" 1310 type: "" => "aws_instance" 1311 1312 STATE: 1313 1314 aws_instance.baz: 1315 ID = bar 1316 ` 1317 1318 const testTerraformPlanStateStr = ` 1319 DIFF: 1320 1321 CREATE: aws_instance.bar 1322 foo: "" => "2" 1323 type: "" => "aws_instance" 1324 UPDATE: aws_instance.foo 1325 num: "" => "2" 1326 type: "" => "aws_instance" 1327 1328 STATE: 1329 1330 aws_instance.foo: 1331 ID = bar 1332 ` 1333 1334 const testTerraformPlanTaintStr = ` 1335 DIFF: 1336 1337 DESTROY/CREATE: aws_instance.bar 1338 foo: "" => "2" 1339 type: "" => "aws_instance" 1340 1341 STATE: 1342 1343 aws_instance.bar: (tainted) 1344 ID = baz 1345 aws_instance.foo: 1346 ID = bar 1347 num = 2 1348 ` 1349 1350 const testTerraformPlanMultipleTaintStr = ` 1351 DIFF: 1352 1353 DESTROY/CREATE: aws_instance.bar 1354 foo: "" => "2" 1355 type: "" => "aws_instance" 1356 1357 STATE: 1358 1359 aws_instance.bar: (2 tainted) 1360 ID = <not created> 1361 Tainted ID 1 = baz 1362 Tainted ID 2 = zip 1363 aws_instance.foo: 1364 ID = bar 1365 num = 2 1366 ` 1367 1368 const testTerraformPlanVarMultiCountOneStr = ` 1369 DIFF: 1370 1371 CREATE: aws_instance.bar 1372 foo: "" => "2" 1373 type: "" => "aws_instance" 1374 CREATE: aws_instance.foo 1375 num: "" => "2" 1376 type: "" => "aws_instance" 1377 1378 STATE: 1379 1380 <no state> 1381 ` 1382 1383 const testTerraformPlanPathVarStr = ` 1384 DIFF: 1385 1386 CREATE: aws_instance.foo 1387 cwd: "" => "%s/barpath" 1388 module: "" => "%s/foopath" 1389 root: "" => "%s/barpath" 1390 type: "" => "aws_instance" 1391 1392 STATE: 1393 1394 <no state> 1395 ` 1396 1397 const testTerraformPlanIgnoreChangesStr = ` 1398 DIFF: 1399 1400 UPDATE: aws_instance.foo 1401 type: "" => "aws_instance" 1402 1403 STATE: 1404 1405 aws_instance.foo: 1406 ID = bar 1407 ami = ami-abcd1234 1408 ` 1409 1410 const testTerraformPlanComputedValueInMap = ` 1411 DIFF: 1412 1413 CREATE: aws_computed_source.intermediates 1414 computed_read_only: "" => "<computed>" 1415 1416 module.test_mod: 1417 CREATE: aws_instance.inner2 1418 looked_up: "" => "<computed>" 1419 type: "" => "aws_instance" 1420 1421 STATE: 1422 1423 <no state> 1424 ` 1425 1426 const testTerraformPlanModuleVariableFromSplat = ` 1427 DIFF: 1428 1429 module.mod1: 1430 CREATE: aws_instance.test.0 1431 thing: "" => "doesnt" 1432 type: "" => "aws_instance" 1433 CREATE: aws_instance.test.1 1434 thing: "" => "doesnt" 1435 type: "" => "aws_instance" 1436 module.mod2: 1437 CREATE: aws_instance.test.0 1438 thing: "" => "doesnt" 1439 type: "" => "aws_instance" 1440 CREATE: aws_instance.test.1 1441 thing: "" => "doesnt" 1442 type: "" => "aws_instance" 1443 1444 STATE: 1445 1446 <no state>` 1447 1448 const testTerraformInputHCL = ` 1449 hcl_instance.hcltest: 1450 ID = foo 1451 bar.w = z 1452 bar.x = y 1453 foo.# = 2 1454 foo.0 = a 1455 foo.1 = b 1456 type = hcl_instance 1457 `