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