github.com/mehmetalisavas/terraform@v0.7.10/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 testTerraformApplyTaintStr = ` 657 aws_instance.bar: 658 ID = foo 659 num = 2 660 type = aws_instance 661 ` 662 663 const testTerraformApplyTaintDepStr = ` 664 aws_instance.bar: 665 ID = bar 666 foo = foo 667 num = 2 668 type = aws_instance 669 670 Dependencies: 671 aws_instance.foo 672 aws_instance.foo: 673 ID = foo 674 num = 2 675 type = aws_instance 676 ` 677 678 const testTerraformApplyTaintDepRequireNewStr = ` 679 aws_instance.bar: 680 ID = foo 681 foo = foo 682 require_new = yes 683 type = aws_instance 684 685 Dependencies: 686 aws_instance.foo 687 aws_instance.foo: 688 ID = foo 689 num = 2 690 type = aws_instance 691 ` 692 693 const testTerraformApplyOutputStr = ` 694 aws_instance.bar: 695 ID = foo 696 foo = bar 697 type = aws_instance 698 aws_instance.foo: 699 ID = foo 700 num = 2 701 type = aws_instance 702 703 Outputs: 704 705 foo_num = 2 706 ` 707 708 const testTerraformApplyOutputAddStr = ` 709 aws_instance.test.0: 710 ID = foo 711 foo = foo0 712 type = aws_instance 713 aws_instance.test.1: 714 ID = foo 715 foo = foo1 716 type = aws_instance 717 718 Outputs: 719 720 firstOutput = foo0 721 secondOutput = foo1 722 ` 723 724 const testTerraformApplyOutputListStr = ` 725 aws_instance.bar.0: 726 ID = foo 727 foo = bar 728 type = aws_instance 729 aws_instance.bar.1: 730 ID = foo 731 foo = bar 732 type = aws_instance 733 aws_instance.bar.2: 734 ID = foo 735 foo = bar 736 type = aws_instance 737 aws_instance.foo: 738 ID = foo 739 num = 2 740 type = aws_instance 741 742 Outputs: 743 744 foo_num = [bar,bar,bar] 745 ` 746 747 const testTerraformApplyOutputMultiStr = ` 748 aws_instance.bar.0: 749 ID = foo 750 foo = bar 751 type = aws_instance 752 aws_instance.bar.1: 753 ID = foo 754 foo = bar 755 type = aws_instance 756 aws_instance.bar.2: 757 ID = foo 758 foo = bar 759 type = aws_instance 760 aws_instance.foo: 761 ID = foo 762 num = 2 763 type = aws_instance 764 765 Outputs: 766 767 foo_num = bar,bar,bar 768 ` 769 770 const testTerraformApplyOutputMultiIndexStr = ` 771 aws_instance.bar.0: 772 ID = foo 773 foo = bar 774 type = aws_instance 775 aws_instance.bar.1: 776 ID = foo 777 foo = bar 778 type = aws_instance 779 aws_instance.bar.2: 780 ID = foo 781 foo = bar 782 type = aws_instance 783 aws_instance.foo: 784 ID = foo 785 num = 2 786 type = aws_instance 787 788 Outputs: 789 790 foo_num = bar 791 ` 792 793 const testTerraformApplyUnknownAttrStr = ` 794 aws_instance.foo: 795 ID = foo 796 num = 2 797 type = aws_instance 798 ` 799 800 const testTerraformApplyVarsStr = ` 801 aws_instance.bar: 802 ID = foo 803 bar = foo 804 baz = override 805 foo = us-west-2 806 type = aws_instance 807 aws_instance.foo: 808 ID = foo 809 bar = baz 810 list = Hello,World 811 map = Baz,Foo,Hello 812 num = 2 813 type = aws_instance 814 ` 815 816 const testTerraformApplyVarsEnvStr = ` 817 aws_instance.bar: 818 ID = foo 819 bar = Hello,World 820 baz = Baz,Foo,Hello 821 foo = baz 822 type = aws_instance 823 ` 824 825 const testTerraformPlanStr = ` 826 DIFF: 827 828 CREATE: aws_instance.bar 829 foo: "" => "2" 830 type: "" => "aws_instance" 831 CREATE: aws_instance.foo 832 num: "" => "2" 833 type: "" => "aws_instance" 834 835 STATE: 836 837 <no state> 838 ` 839 840 const testTerraformPlanComputedStr = ` 841 DIFF: 842 843 CREATE: aws_instance.bar 844 foo: "" => "<computed>" 845 type: "" => "aws_instance" 846 CREATE: aws_instance.foo 847 foo: "" => "<computed>" 848 num: "" => "2" 849 type: "" => "aws_instance" 850 851 STATE: 852 853 <no state> 854 ` 855 856 const testTerraformPlanComputedIdStr = ` 857 DIFF: 858 859 CREATE: aws_instance.bar 860 foo: "" => "<computed>" 861 type: "" => "aws_instance" 862 CREATE: aws_instance.foo 863 foo: "" => "<computed>" 864 num: "" => "2" 865 type: "" => "aws_instance" 866 867 STATE: 868 869 <no state> 870 ` 871 872 const testTerraformPlanComputedListStr = ` 873 DIFF: 874 875 CREATE: aws_instance.bar 876 foo: "" => "<computed>" 877 type: "" => "aws_instance" 878 CREATE: aws_instance.foo 879 list.#: "" => "<computed>" 880 num: "" => "2" 881 type: "" => "aws_instance" 882 883 STATE: 884 885 <no state> 886 ` 887 888 const testTerraformPlanCountStr = ` 889 DIFF: 890 891 CREATE: aws_instance.bar 892 foo: "" => "foo,foo,foo,foo,foo" 893 type: "" => "aws_instance" 894 CREATE: aws_instance.foo.0 895 foo: "" => "foo" 896 type: "" => "aws_instance" 897 CREATE: aws_instance.foo.1 898 foo: "" => "foo" 899 type: "" => "aws_instance" 900 CREATE: aws_instance.foo.2 901 foo: "" => "foo" 902 type: "" => "aws_instance" 903 CREATE: aws_instance.foo.3 904 foo: "" => "foo" 905 type: "" => "aws_instance" 906 CREATE: aws_instance.foo.4 907 foo: "" => "foo" 908 type: "" => "aws_instance" 909 910 STATE: 911 912 <no state> 913 ` 914 915 const testTerraformPlanCountIndexStr = ` 916 DIFF: 917 918 CREATE: aws_instance.foo.0 919 foo: "" => "0" 920 type: "" => "aws_instance" 921 CREATE: aws_instance.foo.1 922 foo: "" => "1" 923 type: "" => "aws_instance" 924 925 STATE: 926 927 <no state> 928 ` 929 930 const testTerraformPlanCountIndexZeroStr = ` 931 DIFF: 932 933 CREATE: aws_instance.foo 934 foo: "" => "0" 935 type: "" => "aws_instance" 936 937 STATE: 938 939 <no state> 940 ` 941 942 const testTerraformPlanCountOneIndexStr = ` 943 DIFF: 944 945 CREATE: aws_instance.bar 946 foo: "" => "foo" 947 type: "" => "aws_instance" 948 CREATE: aws_instance.foo 949 foo: "" => "foo" 950 type: "" => "aws_instance" 951 952 STATE: 953 954 <no state> 955 ` 956 957 const testTerraformPlanCountZeroStr = ` 958 DIFF: 959 960 CREATE: aws_instance.bar 961 foo: "" => "" 962 type: "" => "aws_instance" 963 964 STATE: 965 966 <no state> 967 ` 968 969 const testTerraformPlanCountVarStr = ` 970 DIFF: 971 972 CREATE: aws_instance.bar 973 foo: "" => "foo,foo,foo" 974 type: "" => "aws_instance" 975 CREATE: aws_instance.foo.0 976 foo: "" => "foo" 977 type: "" => "aws_instance" 978 CREATE: aws_instance.foo.1 979 foo: "" => "foo" 980 type: "" => "aws_instance" 981 CREATE: aws_instance.foo.2 982 foo: "" => "foo" 983 type: "" => "aws_instance" 984 985 STATE: 986 987 <no state> 988 ` 989 990 const testTerraformPlanCountDecreaseStr = ` 991 DIFF: 992 993 CREATE: aws_instance.bar 994 foo: "" => "bar" 995 type: "" => "aws_instance" 996 DESTROY: aws_instance.foo.1 997 DESTROY: aws_instance.foo.2 998 999 STATE: 1000 1001 aws_instance.foo.0: 1002 ID = bar 1003 foo = foo 1004 type = aws_instance 1005 aws_instance.foo.1: 1006 ID = bar 1007 aws_instance.foo.2: 1008 ID = bar 1009 ` 1010 1011 const testTerraformPlanCountIncreaseStr = ` 1012 DIFF: 1013 1014 CREATE: aws_instance.bar 1015 foo: "" => "bar" 1016 type: "" => "aws_instance" 1017 CREATE: aws_instance.foo.1 1018 foo: "" => "foo" 1019 type: "" => "aws_instance" 1020 CREATE: aws_instance.foo.2 1021 foo: "" => "foo" 1022 type: "" => "aws_instance" 1023 1024 STATE: 1025 1026 aws_instance.foo: 1027 ID = bar 1028 foo = foo 1029 type = aws_instance 1030 ` 1031 1032 const testTerraformPlanCountIncreaseFromOneStr = ` 1033 DIFF: 1034 1035 CREATE: aws_instance.bar 1036 foo: "" => "bar" 1037 type: "" => "aws_instance" 1038 CREATE: aws_instance.foo.1 1039 foo: "" => "foo" 1040 type: "" => "aws_instance" 1041 CREATE: aws_instance.foo.2 1042 foo: "" => "foo" 1043 type: "" => "aws_instance" 1044 1045 STATE: 1046 1047 aws_instance.foo.0: 1048 ID = bar 1049 foo = foo 1050 type = aws_instance 1051 ` 1052 1053 const testTerraformPlanCountIncreaseFromOneCorruptedStr = ` 1054 DIFF: 1055 1056 CREATE: aws_instance.bar 1057 foo: "" => "bar" 1058 type: "" => "aws_instance" 1059 DESTROY: aws_instance.foo 1060 CREATE: aws_instance.foo.1 1061 foo: "" => "foo" 1062 type: "" => "aws_instance" 1063 CREATE: aws_instance.foo.2 1064 foo: "" => "foo" 1065 type: "" => "aws_instance" 1066 1067 STATE: 1068 1069 aws_instance.foo: 1070 ID = bar 1071 foo = foo 1072 type = aws_instance 1073 aws_instance.foo.0: 1074 ID = bar 1075 foo = foo 1076 type = aws_instance 1077 ` 1078 1079 const testTerraformPlanDestroyStr = ` 1080 DIFF: 1081 1082 DESTROY: aws_instance.one 1083 DESTROY: aws_instance.two 1084 1085 STATE: 1086 1087 aws_instance.one: 1088 ID = bar 1089 aws_instance.two: 1090 ID = baz 1091 ` 1092 1093 const testTerraformPlanDiffVarStr = ` 1094 DIFF: 1095 1096 CREATE: aws_instance.bar 1097 num: "" => "3" 1098 type: "" => "aws_instance" 1099 UPDATE: aws_instance.foo 1100 num: "2" => "3" 1101 1102 STATE: 1103 1104 aws_instance.foo: 1105 ID = bar 1106 num = 2 1107 ` 1108 1109 const testTerraformPlanEmptyStr = ` 1110 DIFF: 1111 1112 CREATE: aws_instance.bar 1113 CREATE: aws_instance.foo 1114 1115 STATE: 1116 1117 <no state> 1118 ` 1119 1120 const testTerraformPlanEscapedVarStr = ` 1121 DIFF: 1122 1123 CREATE: aws_instance.foo 1124 foo: "" => "bar-${baz}" 1125 type: "" => "aws_instance" 1126 1127 STATE: 1128 1129 <no state> 1130 ` 1131 1132 const testTerraformPlanModulesStr = ` 1133 DIFF: 1134 1135 CREATE: aws_instance.bar 1136 foo: "" => "2" 1137 type: "" => "aws_instance" 1138 CREATE: aws_instance.foo 1139 num: "" => "2" 1140 type: "" => "aws_instance" 1141 1142 module.child: 1143 CREATE: aws_instance.foo 1144 num: "" => "2" 1145 type: "" => "aws_instance" 1146 1147 STATE: 1148 1149 <no state> 1150 ` 1151 1152 const testTerraformPlanModuleCycleStr = ` 1153 DIFF: 1154 1155 CREATE: aws_instance.b 1156 CREATE: aws_instance.c 1157 some_input: "" => "<computed>" 1158 type: "" => "aws_instance" 1159 1160 STATE: 1161 1162 <no state> 1163 ` 1164 1165 const testTerraformPlanModuleDestroyStr = ` 1166 DIFF: 1167 1168 DESTROY: aws_instance.foo 1169 1170 module.child: 1171 DESTROY: aws_instance.foo 1172 1173 STATE: 1174 1175 aws_instance.foo: 1176 ID = bar 1177 1178 module.child: 1179 aws_instance.foo: 1180 ID = bar 1181 ` 1182 1183 const testTerraformPlanModuleDestroyCycleStr = ` 1184 DIFF: 1185 1186 module.a_module: 1187 DESTROY: aws_instance.a 1188 module.b_module: 1189 DESTROY: aws_instance.b 1190 1191 STATE: 1192 1193 module.a_module: 1194 aws_instance.a: 1195 ID = a 1196 module.b_module: 1197 aws_instance.b: 1198 ID = b 1199 ` 1200 1201 const testTerraformPlanModuleDestroyMultivarStr = ` 1202 DIFF: 1203 1204 module.child: 1205 DESTROY: aws_instance.foo.0 1206 DESTROY: aws_instance.foo.1 1207 1208 STATE: 1209 1210 <no state> 1211 module.child: 1212 aws_instance.foo.0: 1213 ID = bar0 1214 aws_instance.foo.1: 1215 ID = bar1 1216 ` 1217 1218 const testTerraformPlanModuleInputStr = ` 1219 DIFF: 1220 1221 CREATE: aws_instance.bar 1222 foo: "" => "2" 1223 type: "" => "aws_instance" 1224 1225 module.child: 1226 CREATE: aws_instance.foo 1227 foo: "" => "42" 1228 type: "" => "aws_instance" 1229 1230 STATE: 1231 1232 <no state> 1233 ` 1234 1235 const testTerraformPlanModuleInputComputedStr = ` 1236 DIFF: 1237 1238 CREATE: aws_instance.bar 1239 foo: "" => "<computed>" 1240 type: "" => "aws_instance" 1241 1242 module.child: 1243 CREATE: aws_instance.foo 1244 foo: "" => "<computed>" 1245 type: "" => "aws_instance" 1246 1247 STATE: 1248 1249 <no state> 1250 ` 1251 1252 const testTerraformPlanModuleInputVarStr = ` 1253 DIFF: 1254 1255 CREATE: aws_instance.bar 1256 foo: "" => "2" 1257 type: "" => "aws_instance" 1258 1259 module.child: 1260 CREATE: aws_instance.foo 1261 foo: "" => "52" 1262 type: "" => "aws_instance" 1263 1264 STATE: 1265 1266 <no state> 1267 ` 1268 1269 const testTerraformPlanModuleMultiVarStr = ` 1270 DIFF: 1271 1272 CREATE: aws_instance.parent.0 1273 CREATE: aws_instance.parent.1 1274 1275 module.child: 1276 CREATE: aws_instance.bar.0 1277 baz: "" => "baz" 1278 type: "" => "aws_instance" 1279 CREATE: aws_instance.bar.1 1280 baz: "" => "baz" 1281 type: "" => "aws_instance" 1282 CREATE: aws_instance.foo 1283 foo: "" => "baz,baz" 1284 type: "" => "aws_instance" 1285 1286 STATE: 1287 1288 <no state> 1289 ` 1290 1291 const testTerraformPlanModuleOrphansStr = ` 1292 DIFF: 1293 1294 CREATE: aws_instance.foo 1295 num: "" => "2" 1296 type: "" => "aws_instance" 1297 1298 module.child: 1299 DESTROY: aws_instance.foo 1300 1301 STATE: 1302 1303 module.child: 1304 aws_instance.foo: 1305 ID = baz 1306 ` 1307 1308 const testTerraformPlanModuleVarStr = ` 1309 DIFF: 1310 1311 CREATE: aws_instance.bar 1312 foo: "" => "2" 1313 type: "" => "aws_instance" 1314 1315 module.child: 1316 CREATE: aws_instance.foo 1317 num: "" => "2" 1318 type: "" => "aws_instance" 1319 1320 STATE: 1321 1322 <no state> 1323 ` 1324 1325 const testTerraformPlanModuleVarComputedStr = ` 1326 DIFF: 1327 1328 CREATE: aws_instance.bar 1329 foo: "" => "<computed>" 1330 type: "" => "aws_instance" 1331 1332 module.child: 1333 CREATE: aws_instance.foo 1334 foo: "" => "<computed>" 1335 type: "" => "aws_instance" 1336 1337 STATE: 1338 1339 <no state> 1340 ` 1341 1342 const testTerraformPlanModuleVarIntStr = ` 1343 DIFF: 1344 1345 module.child: 1346 CREATE: aws_instance.foo 1347 num: "" => "2" 1348 type: "" => "aws_instance" 1349 1350 STATE: 1351 1352 <no state> 1353 ` 1354 1355 const testTerraformPlanOrphanStr = ` 1356 DIFF: 1357 1358 DESTROY: aws_instance.baz 1359 CREATE: aws_instance.foo 1360 num: "" => "2" 1361 type: "" => "aws_instance" 1362 1363 STATE: 1364 1365 aws_instance.baz: 1366 ID = bar 1367 ` 1368 1369 const testTerraformPlanStateStr = ` 1370 DIFF: 1371 1372 CREATE: aws_instance.bar 1373 foo: "" => "2" 1374 type: "" => "aws_instance" 1375 UPDATE: aws_instance.foo 1376 num: "" => "2" 1377 type: "" => "aws_instance" 1378 1379 STATE: 1380 1381 aws_instance.foo: 1382 ID = bar 1383 ` 1384 1385 const testTerraformPlanTaintStr = ` 1386 DIFF: 1387 1388 DESTROY/CREATE: aws_instance.bar 1389 foo: "" => "2" 1390 type: "" => "aws_instance" 1391 1392 STATE: 1393 1394 aws_instance.bar: (tainted) 1395 ID = baz 1396 aws_instance.foo: 1397 ID = bar 1398 num = 2 1399 ` 1400 1401 const testTerraformPlanTaintIgnoreChangesStr = ` 1402 DIFF: 1403 1404 DESTROY/CREATE: aws_instance.foo 1405 type: "" => "aws_instance" 1406 vars: "" => "foo" 1407 1408 STATE: 1409 1410 aws_instance.foo: (tainted) 1411 ID = foo 1412 type = aws_instance 1413 vars = foo 1414 ` 1415 1416 const testTerraformPlanMultipleTaintStr = ` 1417 DIFF: 1418 1419 DESTROY/CREATE: aws_instance.bar 1420 foo: "" => "2" 1421 type: "" => "aws_instance" 1422 1423 STATE: 1424 1425 aws_instance.bar: (2 tainted) 1426 ID = <not created> 1427 Tainted ID 1 = baz 1428 Tainted ID 2 = zip 1429 aws_instance.foo: 1430 ID = bar 1431 num = 2 1432 ` 1433 1434 const testTerraformPlanVarMultiCountOneStr = ` 1435 DIFF: 1436 1437 CREATE: aws_instance.bar 1438 foo: "" => "2" 1439 type: "" => "aws_instance" 1440 CREATE: aws_instance.foo 1441 num: "" => "2" 1442 type: "" => "aws_instance" 1443 1444 STATE: 1445 1446 <no state> 1447 ` 1448 1449 const testTerraformPlanPathVarStr = ` 1450 DIFF: 1451 1452 CREATE: aws_instance.foo 1453 cwd: "" => "%s/barpath" 1454 module: "" => "%s/foopath" 1455 root: "" => "%s/barpath" 1456 type: "" => "aws_instance" 1457 1458 STATE: 1459 1460 <no state> 1461 ` 1462 1463 const testTerraformPlanIgnoreChangesStr = ` 1464 DIFF: 1465 1466 UPDATE: aws_instance.foo 1467 type: "" => "aws_instance" 1468 1469 STATE: 1470 1471 aws_instance.foo: 1472 ID = bar 1473 ami = ami-abcd1234 1474 ` 1475 1476 const testTerraformPlanIgnoreChangesWildcardStr = ` 1477 DIFF: 1478 1479 1480 1481 STATE: 1482 1483 aws_instance.foo: 1484 ID = bar 1485 ami = ami-abcd1234 1486 instance_type = t2.micro 1487 ` 1488 1489 const testTerraformPlanComputedValueInMap = ` 1490 DIFF: 1491 1492 CREATE: aws_computed_source.intermediates 1493 computed_read_only: "" => "<computed>" 1494 1495 module.test_mod: 1496 CREATE: aws_instance.inner2 1497 looked_up: "" => "<computed>" 1498 type: "" => "aws_instance" 1499 1500 STATE: 1501 1502 <no state> 1503 ` 1504 1505 const testTerraformPlanModuleVariableFromSplat = ` 1506 DIFF: 1507 1508 module.mod1: 1509 CREATE: aws_instance.test.0 1510 thing: "" => "doesnt" 1511 type: "" => "aws_instance" 1512 CREATE: aws_instance.test.1 1513 thing: "" => "doesnt" 1514 type: "" => "aws_instance" 1515 module.mod2: 1516 CREATE: aws_instance.test.0 1517 thing: "" => "doesnt" 1518 type: "" => "aws_instance" 1519 CREATE: aws_instance.test.1 1520 thing: "" => "doesnt" 1521 type: "" => "aws_instance" 1522 1523 STATE: 1524 1525 <no state>` 1526 1527 const testTerraformInputHCL = ` 1528 hcl_instance.hcltest: 1529 ID = foo 1530 bar.w = z 1531 bar.x = y 1532 foo.# = 2 1533 foo.0 = a 1534 foo.1 = b 1535 type = hcl_instance 1536 ` 1537 1538 const testTerraformRefreshDataRefDataStr = ` 1539 data.null_data_source.bar: 1540 ID = foo 1541 bar = yes 1542 type = null_data_source 1543 1544 Dependencies: 1545 data.null_data_source.foo 1546 data.null_data_source.foo: 1547 ID = foo 1548 foo = yes 1549 type = null_data_source 1550 `