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