github.com/chentex/terraform@v0.11.2-0.20171208003256-252e8145842e/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: (1 deposed) 640 ID = bar 641 provider = provider.aws 642 require_new = abc 643 Deposed ID 1 = foo (tainted) 644 ` 645 646 const testTerraformApplyProvisionerResourceRefStr = ` 647 aws_instance.bar: 648 ID = foo 649 provider = provider.aws 650 num = 2 651 type = aws_instance 652 ` 653 654 const testTerraformApplyProvisionerSelfRefStr = ` 655 aws_instance.foo: 656 ID = foo 657 provider = provider.aws 658 foo = bar 659 type = aws_instance 660 ` 661 662 const testTerraformApplyProvisionerMultiSelfRefStr = ` 663 aws_instance.foo.0: 664 ID = foo 665 provider = provider.aws 666 foo = number 0 667 type = aws_instance 668 aws_instance.foo.1: 669 ID = foo 670 provider = provider.aws 671 foo = number 1 672 type = aws_instance 673 aws_instance.foo.2: 674 ID = foo 675 provider = provider.aws 676 foo = number 2 677 type = aws_instance 678 ` 679 680 const testTerraformApplyProvisionerMultiSelfRefSingleStr = ` 681 aws_instance.foo.0: 682 ID = foo 683 provider = provider.aws 684 foo = number 0 685 type = aws_instance 686 aws_instance.foo.1: 687 ID = foo 688 provider = provider.aws 689 foo = number 1 690 type = aws_instance 691 692 Dependencies: 693 aws_instance.foo.0 694 aws_instance.foo.2: 695 ID = foo 696 provider = provider.aws 697 foo = number 2 698 type = aws_instance 699 700 Dependencies: 701 aws_instance.foo.0 702 ` 703 704 const testTerraformApplyProvisionerDiffStr = ` 705 aws_instance.bar: 706 ID = foo 707 provider = provider.aws 708 foo = bar 709 type = aws_instance 710 ` 711 712 const testTerraformApplyDestroyStr = ` 713 <no state> 714 ` 715 716 const testTerraformApplyErrorStr = ` 717 aws_instance.bar: 718 ID = bar 719 provider = provider.aws 720 721 Dependencies: 722 aws_instance.foo 723 aws_instance.foo: 724 ID = foo 725 provider = provider.aws 726 num = 2 727 ` 728 729 const testTerraformApplyErrorCreateBeforeDestroyStr = ` 730 aws_instance.bar: 731 ID = bar 732 provider = provider.aws 733 require_new = abc 734 ` 735 736 const testTerraformApplyErrorDestroyCreateBeforeDestroyStr = ` 737 aws_instance.bar: (1 deposed) 738 ID = foo 739 provider = provider.aws 740 Deposed ID 1 = bar 741 ` 742 743 const testTerraformApplyErrorPartialStr = ` 744 aws_instance.bar: 745 ID = bar 746 provider = provider.aws 747 748 Dependencies: 749 aws_instance.foo 750 aws_instance.foo: 751 ID = foo 752 provider = provider.aws 753 num = 2 754 ` 755 756 const testTerraformApplyResourceDependsOnModuleStr = ` 757 aws_instance.a: 758 ID = foo 759 provider = provider.aws 760 761 Dependencies: 762 module.child 763 764 module.child: 765 aws_instance.child: 766 ID = foo 767 provider = provider.aws 768 ` 769 770 const testTerraformApplyResourceDependsOnModuleDeepStr = ` 771 aws_instance.a: 772 ID = foo 773 provider = provider.aws 774 775 Dependencies: 776 module.child 777 778 module.child.grandchild: 779 aws_instance.c: 780 ID = foo 781 provider = provider.aws 782 ` 783 784 const testTerraformApplyResourceDependsOnModuleInModuleStr = ` 785 <no state> 786 module.child: 787 aws_instance.b: 788 ID = foo 789 provider = provider.aws 790 791 Dependencies: 792 module.grandchild 793 module.child.grandchild: 794 aws_instance.c: 795 ID = foo 796 provider = provider.aws 797 ` 798 799 const testTerraformApplyTaintStr = ` 800 aws_instance.bar: 801 ID = foo 802 provider = provider.aws 803 num = 2 804 type = aws_instance 805 ` 806 807 const testTerraformApplyTaintDepStr = ` 808 aws_instance.bar: 809 ID = bar 810 provider = provider.aws 811 foo = foo 812 num = 2 813 type = aws_instance 814 815 Dependencies: 816 aws_instance.foo 817 aws_instance.foo: 818 ID = foo 819 provider = provider.aws 820 num = 2 821 type = aws_instance 822 ` 823 824 const testTerraformApplyTaintDepRequireNewStr = ` 825 aws_instance.bar: 826 ID = foo 827 provider = provider.aws 828 foo = foo 829 require_new = yes 830 type = aws_instance 831 832 Dependencies: 833 aws_instance.foo 834 aws_instance.foo: 835 ID = foo 836 provider = provider.aws 837 num = 2 838 type = aws_instance 839 ` 840 841 const testTerraformApplyOutputStr = ` 842 aws_instance.bar: 843 ID = foo 844 provider = provider.aws 845 foo = bar 846 type = aws_instance 847 aws_instance.foo: 848 ID = foo 849 provider = provider.aws 850 num = 2 851 type = aws_instance 852 853 Outputs: 854 855 foo_num = 2 856 ` 857 858 const testTerraformApplyOutputAddStr = ` 859 aws_instance.test.0: 860 ID = foo 861 provider = provider.aws 862 foo = foo0 863 type = aws_instance 864 aws_instance.test.1: 865 ID = foo 866 provider = provider.aws 867 foo = foo1 868 type = aws_instance 869 870 Outputs: 871 872 firstOutput = foo0 873 secondOutput = foo1 874 ` 875 876 const testTerraformApplyOutputListStr = ` 877 aws_instance.bar.0: 878 ID = foo 879 provider = provider.aws 880 foo = bar 881 type = aws_instance 882 aws_instance.bar.1: 883 ID = foo 884 provider = provider.aws 885 foo = bar 886 type = aws_instance 887 aws_instance.bar.2: 888 ID = foo 889 provider = provider.aws 890 foo = bar 891 type = aws_instance 892 aws_instance.foo: 893 ID = foo 894 provider = provider.aws 895 num = 2 896 type = aws_instance 897 898 Outputs: 899 900 foo_num = [bar,bar,bar] 901 ` 902 903 const testTerraformApplyOutputMultiStr = ` 904 aws_instance.bar.0: 905 ID = foo 906 provider = provider.aws 907 foo = bar 908 type = aws_instance 909 aws_instance.bar.1: 910 ID = foo 911 provider = provider.aws 912 foo = bar 913 type = aws_instance 914 aws_instance.bar.2: 915 ID = foo 916 provider = provider.aws 917 foo = bar 918 type = aws_instance 919 aws_instance.foo: 920 ID = foo 921 provider = provider.aws 922 num = 2 923 type = aws_instance 924 925 Outputs: 926 927 foo_num = bar,bar,bar 928 ` 929 930 const testTerraformApplyOutputMultiIndexStr = ` 931 aws_instance.bar.0: 932 ID = foo 933 provider = provider.aws 934 foo = bar 935 type = aws_instance 936 aws_instance.bar.1: 937 ID = foo 938 provider = provider.aws 939 foo = bar 940 type = aws_instance 941 aws_instance.bar.2: 942 ID = foo 943 provider = provider.aws 944 foo = bar 945 type = aws_instance 946 aws_instance.foo: 947 ID = foo 948 provider = provider.aws 949 num = 2 950 type = aws_instance 951 952 Outputs: 953 954 foo_num = bar 955 ` 956 957 const testTerraformApplyUnknownAttrStr = ` 958 aws_instance.foo: 959 ID = foo 960 provider = provider.aws 961 num = 2 962 type = aws_instance 963 ` 964 965 const testTerraformApplyVarsStr = ` 966 aws_instance.bar: 967 ID = foo 968 provider = provider.aws 969 bar = foo 970 baz = override 971 foo = us-west-2 972 type = aws_instance 973 aws_instance.foo: 974 ID = foo 975 provider = provider.aws 976 bar = baz 977 list = Hello,World 978 map = Baz,Foo,Hello 979 num = 2 980 type = aws_instance 981 ` 982 983 const testTerraformApplyVarsEnvStr = ` 984 aws_instance.bar: 985 ID = foo 986 provider = provider.aws 987 bar = Hello,World 988 baz = Baz,Foo,Hello 989 foo = baz 990 type = aws_instance 991 ` 992 993 const testTerraformPlanStr = ` 994 DIFF: 995 996 CREATE: aws_instance.bar 997 foo: "" => "2" 998 type: "" => "aws_instance" 999 CREATE: aws_instance.foo 1000 num: "" => "2" 1001 type: "" => "aws_instance" 1002 1003 STATE: 1004 1005 <no state> 1006 ` 1007 1008 const testTerraformPlanComputedStr = ` 1009 DIFF: 1010 1011 CREATE: aws_instance.bar 1012 foo: "" => "<computed>" 1013 type: "" => "aws_instance" 1014 CREATE: aws_instance.foo 1015 foo: "" => "<computed>" 1016 num: "" => "2" 1017 type: "" => "aws_instance" 1018 1019 STATE: 1020 1021 <no state> 1022 ` 1023 1024 const testTerraformPlanComputedIdStr = ` 1025 DIFF: 1026 1027 CREATE: aws_instance.bar 1028 foo: "" => "<computed>" 1029 type: "" => "aws_instance" 1030 CREATE: aws_instance.foo 1031 foo: "" => "<computed>" 1032 num: "" => "2" 1033 type: "" => "aws_instance" 1034 1035 STATE: 1036 1037 <no state> 1038 ` 1039 1040 const testTerraformPlanComputedListStr = ` 1041 DIFF: 1042 1043 CREATE: aws_instance.bar 1044 foo: "" => "<computed>" 1045 type: "" => "aws_instance" 1046 CREATE: aws_instance.foo 1047 list.#: "" => "<computed>" 1048 num: "" => "2" 1049 type: "" => "aws_instance" 1050 1051 STATE: 1052 1053 <no state> 1054 ` 1055 1056 const testTerraformPlanComputedMultiIndexStr = ` 1057 DIFF: 1058 1059 CREATE: aws_instance.bar 1060 foo: "" => "<computed>" 1061 type: "" => "aws_instance" 1062 CREATE: aws_instance.foo.0 1063 ip.#: "" => "<computed>" 1064 type: "" => "aws_instance" 1065 CREATE: aws_instance.foo.1 1066 ip.#: "" => "<computed>" 1067 type: "" => "aws_instance" 1068 1069 STATE: 1070 1071 <no state> 1072 ` 1073 1074 const testTerraformPlanCountStr = ` 1075 DIFF: 1076 1077 CREATE: aws_instance.bar 1078 foo: "" => "foo,foo,foo,foo,foo" 1079 type: "" => "aws_instance" 1080 CREATE: aws_instance.foo.0 1081 foo: "" => "foo" 1082 type: "" => "aws_instance" 1083 CREATE: aws_instance.foo.1 1084 foo: "" => "foo" 1085 type: "" => "aws_instance" 1086 CREATE: aws_instance.foo.2 1087 foo: "" => "foo" 1088 type: "" => "aws_instance" 1089 CREATE: aws_instance.foo.3 1090 foo: "" => "foo" 1091 type: "" => "aws_instance" 1092 CREATE: aws_instance.foo.4 1093 foo: "" => "foo" 1094 type: "" => "aws_instance" 1095 1096 STATE: 1097 1098 <no state> 1099 ` 1100 1101 const testTerraformPlanCountIndexStr = ` 1102 DIFF: 1103 1104 CREATE: aws_instance.foo.0 1105 foo: "" => "0" 1106 type: "" => "aws_instance" 1107 CREATE: aws_instance.foo.1 1108 foo: "" => "1" 1109 type: "" => "aws_instance" 1110 1111 STATE: 1112 1113 <no state> 1114 ` 1115 1116 const testTerraformPlanCountIndexZeroStr = ` 1117 DIFF: 1118 1119 CREATE: aws_instance.foo 1120 foo: "" => "0" 1121 type: "" => "aws_instance" 1122 1123 STATE: 1124 1125 <no state> 1126 ` 1127 1128 const testTerraformPlanCountOneIndexStr = ` 1129 DIFF: 1130 1131 CREATE: aws_instance.bar 1132 foo: "" => "foo" 1133 type: "" => "aws_instance" 1134 CREATE: aws_instance.foo 1135 foo: "" => "foo" 1136 type: "" => "aws_instance" 1137 1138 STATE: 1139 1140 <no state> 1141 ` 1142 1143 const testTerraformPlanCountZeroStr = ` 1144 DIFF: 1145 1146 CREATE: aws_instance.bar 1147 foo: "" => "" 1148 type: "" => "aws_instance" 1149 1150 STATE: 1151 1152 <no state> 1153 ` 1154 1155 const testTerraformPlanCountVarStr = ` 1156 DIFF: 1157 1158 CREATE: aws_instance.bar 1159 foo: "" => "foo,foo,foo" 1160 type: "" => "aws_instance" 1161 CREATE: aws_instance.foo.0 1162 foo: "" => "foo" 1163 type: "" => "aws_instance" 1164 CREATE: aws_instance.foo.1 1165 foo: "" => "foo" 1166 type: "" => "aws_instance" 1167 CREATE: aws_instance.foo.2 1168 foo: "" => "foo" 1169 type: "" => "aws_instance" 1170 1171 STATE: 1172 1173 <no state> 1174 ` 1175 1176 const testTerraformPlanCountDecreaseStr = ` 1177 DIFF: 1178 1179 CREATE: aws_instance.bar 1180 foo: "" => "bar" 1181 type: "" => "aws_instance" 1182 DESTROY: aws_instance.foo.1 1183 DESTROY: aws_instance.foo.2 1184 1185 STATE: 1186 1187 aws_instance.foo.0: 1188 ID = bar 1189 foo = foo 1190 type = aws_instance 1191 aws_instance.foo.1: 1192 ID = bar 1193 aws_instance.foo.2: 1194 ID = bar 1195 ` 1196 1197 const testTerraformPlanCountIncreaseStr = ` 1198 DIFF: 1199 1200 CREATE: aws_instance.bar 1201 foo: "" => "bar" 1202 type: "" => "aws_instance" 1203 CREATE: aws_instance.foo.1 1204 foo: "" => "foo" 1205 type: "" => "aws_instance" 1206 CREATE: aws_instance.foo.2 1207 foo: "" => "foo" 1208 type: "" => "aws_instance" 1209 1210 STATE: 1211 1212 aws_instance.foo: 1213 ID = bar 1214 foo = foo 1215 type = aws_instance 1216 ` 1217 1218 const testTerraformPlanCountIncreaseFromOneStr = ` 1219 DIFF: 1220 1221 CREATE: aws_instance.bar 1222 foo: "" => "bar" 1223 type: "" => "aws_instance" 1224 CREATE: aws_instance.foo.1 1225 foo: "" => "foo" 1226 type: "" => "aws_instance" 1227 CREATE: aws_instance.foo.2 1228 foo: "" => "foo" 1229 type: "" => "aws_instance" 1230 1231 STATE: 1232 1233 aws_instance.foo.0: 1234 ID = bar 1235 foo = foo 1236 type = aws_instance 1237 ` 1238 1239 const testTerraformPlanCountIncreaseFromOneCorruptedStr = ` 1240 DIFF: 1241 1242 CREATE: aws_instance.bar 1243 foo: "" => "bar" 1244 type: "" => "aws_instance" 1245 DESTROY: aws_instance.foo 1246 CREATE: aws_instance.foo.1 1247 foo: "" => "foo" 1248 type: "" => "aws_instance" 1249 CREATE: aws_instance.foo.2 1250 foo: "" => "foo" 1251 type: "" => "aws_instance" 1252 1253 STATE: 1254 1255 aws_instance.foo: 1256 ID = bar 1257 foo = foo 1258 type = aws_instance 1259 aws_instance.foo.0: 1260 ID = bar 1261 foo = foo 1262 type = aws_instance 1263 ` 1264 1265 const testTerraformPlanDestroyStr = ` 1266 DIFF: 1267 1268 DESTROY: aws_instance.one 1269 DESTROY: aws_instance.two 1270 1271 STATE: 1272 1273 aws_instance.one: 1274 ID = bar 1275 aws_instance.two: 1276 ID = baz 1277 ` 1278 1279 const testTerraformPlanDiffVarStr = ` 1280 DIFF: 1281 1282 CREATE: aws_instance.bar 1283 num: "" => "3" 1284 type: "" => "aws_instance" 1285 UPDATE: aws_instance.foo 1286 num: "2" => "3" 1287 1288 STATE: 1289 1290 aws_instance.foo: 1291 ID = bar 1292 num = 2 1293 ` 1294 1295 const testTerraformPlanEmptyStr = ` 1296 DIFF: 1297 1298 CREATE: aws_instance.bar 1299 CREATE: aws_instance.foo 1300 1301 STATE: 1302 1303 <no state> 1304 ` 1305 1306 const testTerraformPlanEscapedVarStr = ` 1307 DIFF: 1308 1309 CREATE: aws_instance.foo 1310 foo: "" => "bar-${baz}" 1311 type: "" => "aws_instance" 1312 1313 STATE: 1314 1315 <no state> 1316 ` 1317 1318 const testTerraformPlanModulesStr = ` 1319 DIFF: 1320 1321 CREATE: aws_instance.bar 1322 foo: "" => "2" 1323 type: "" => "aws_instance" 1324 CREATE: aws_instance.foo 1325 num: "" => "2" 1326 type: "" => "aws_instance" 1327 1328 module.child: 1329 CREATE: aws_instance.foo 1330 num: "" => "2" 1331 type: "" => "aws_instance" 1332 1333 STATE: 1334 1335 <no state> 1336 ` 1337 1338 const testTerraformPlanModuleCycleStr = ` 1339 DIFF: 1340 1341 CREATE: aws_instance.b 1342 CREATE: aws_instance.c 1343 some_input: "" => "<computed>" 1344 type: "" => "aws_instance" 1345 1346 STATE: 1347 1348 <no state> 1349 ` 1350 1351 const testTerraformPlanModuleDestroyStr = ` 1352 DIFF: 1353 1354 DESTROY: aws_instance.foo 1355 1356 module.child: 1357 DESTROY: aws_instance.foo 1358 1359 STATE: 1360 1361 aws_instance.foo: 1362 ID = bar 1363 1364 module.child: 1365 aws_instance.foo: 1366 ID = bar 1367 ` 1368 1369 const testTerraformPlanModuleDestroyCycleStr = ` 1370 DIFF: 1371 1372 module.a_module: 1373 DESTROY: aws_instance.a 1374 module.b_module: 1375 DESTROY: aws_instance.b 1376 1377 STATE: 1378 1379 module.a_module: 1380 aws_instance.a: 1381 ID = a 1382 module.b_module: 1383 aws_instance.b: 1384 ID = b 1385 ` 1386 1387 const testTerraformPlanModuleDestroyMultivarStr = ` 1388 DIFF: 1389 1390 module.child: 1391 DESTROY: aws_instance.foo.0 1392 DESTROY: aws_instance.foo.1 1393 1394 STATE: 1395 1396 <no state> 1397 module.child: 1398 aws_instance.foo.0: 1399 ID = bar0 1400 aws_instance.foo.1: 1401 ID = bar1 1402 ` 1403 1404 const testTerraformPlanModuleInputStr = ` 1405 DIFF: 1406 1407 CREATE: aws_instance.bar 1408 foo: "" => "2" 1409 type: "" => "aws_instance" 1410 1411 module.child: 1412 CREATE: aws_instance.foo 1413 foo: "" => "42" 1414 type: "" => "aws_instance" 1415 1416 STATE: 1417 1418 <no state> 1419 ` 1420 1421 const testTerraformPlanModuleInputComputedStr = ` 1422 DIFF: 1423 1424 CREATE: aws_instance.bar 1425 foo: "" => "<computed>" 1426 type: "" => "aws_instance" 1427 1428 module.child: 1429 CREATE: aws_instance.foo 1430 foo: "" => "<computed>" 1431 type: "" => "aws_instance" 1432 1433 STATE: 1434 1435 <no state> 1436 ` 1437 1438 const testTerraformPlanModuleInputVarStr = ` 1439 DIFF: 1440 1441 CREATE: aws_instance.bar 1442 foo: "" => "2" 1443 type: "" => "aws_instance" 1444 1445 module.child: 1446 CREATE: aws_instance.foo 1447 foo: "" => "52" 1448 type: "" => "aws_instance" 1449 1450 STATE: 1451 1452 <no state> 1453 ` 1454 1455 const testTerraformPlanModuleMultiVarStr = ` 1456 DIFF: 1457 1458 CREATE: aws_instance.parent.0 1459 CREATE: aws_instance.parent.1 1460 1461 module.child: 1462 CREATE: aws_instance.bar.0 1463 baz: "" => "baz" 1464 type: "" => "aws_instance" 1465 CREATE: aws_instance.bar.1 1466 baz: "" => "baz" 1467 type: "" => "aws_instance" 1468 CREATE: aws_instance.foo 1469 foo: "" => "baz,baz" 1470 type: "" => "aws_instance" 1471 1472 STATE: 1473 1474 <no state> 1475 ` 1476 1477 const testTerraformPlanModuleOrphansStr = ` 1478 DIFF: 1479 1480 CREATE: aws_instance.foo 1481 num: "" => "2" 1482 type: "" => "aws_instance" 1483 1484 module.child: 1485 DESTROY: aws_instance.foo 1486 1487 STATE: 1488 1489 module.child: 1490 aws_instance.foo: 1491 ID = baz 1492 ` 1493 1494 const testTerraformPlanModuleProviderVarStr = ` 1495 DIFF: 1496 1497 module.child: 1498 CREATE: aws_instance.test 1499 type: "" => "aws_instance" 1500 value: "" => "hello" 1501 1502 STATE: 1503 1504 <no state> 1505 ` 1506 1507 const testTerraformPlanModuleVarStr = ` 1508 DIFF: 1509 1510 CREATE: aws_instance.bar 1511 foo: "" => "2" 1512 type: "" => "aws_instance" 1513 1514 module.child: 1515 CREATE: aws_instance.foo 1516 num: "" => "2" 1517 type: "" => "aws_instance" 1518 1519 STATE: 1520 1521 <no state> 1522 ` 1523 1524 const testTerraformPlanModuleVarComputedStr = ` 1525 DIFF: 1526 1527 CREATE: aws_instance.bar 1528 foo: "" => "<computed>" 1529 type: "" => "aws_instance" 1530 1531 module.child: 1532 CREATE: aws_instance.foo 1533 foo: "" => "<computed>" 1534 type: "" => "aws_instance" 1535 1536 STATE: 1537 1538 <no state> 1539 ` 1540 1541 const testTerraformPlanModuleVarIntStr = ` 1542 DIFF: 1543 1544 module.child: 1545 CREATE: aws_instance.foo 1546 num: "" => "2" 1547 type: "" => "aws_instance" 1548 1549 STATE: 1550 1551 <no state> 1552 ` 1553 1554 const testTerraformPlanOrphanStr = ` 1555 DIFF: 1556 1557 DESTROY: aws_instance.baz 1558 CREATE: aws_instance.foo 1559 num: "" => "2" 1560 type: "" => "aws_instance" 1561 1562 STATE: 1563 1564 aws_instance.baz: 1565 ID = bar 1566 ` 1567 1568 const testTerraformPlanStateStr = ` 1569 DIFF: 1570 1571 CREATE: aws_instance.bar 1572 foo: "" => "2" 1573 type: "" => "aws_instance" 1574 UPDATE: aws_instance.foo 1575 num: "" => "2" 1576 type: "" => "aws_instance" 1577 1578 STATE: 1579 1580 aws_instance.foo: 1581 ID = bar 1582 ` 1583 1584 const testTerraformPlanTaintStr = ` 1585 DIFF: 1586 1587 DESTROY/CREATE: aws_instance.bar 1588 foo: "" => "2" 1589 type: "" => "aws_instance" 1590 1591 STATE: 1592 1593 aws_instance.bar: (tainted) 1594 ID = baz 1595 aws_instance.foo: 1596 ID = bar 1597 num = 2 1598 ` 1599 1600 const testTerraformPlanTaintIgnoreChangesStr = ` 1601 DIFF: 1602 1603 DESTROY/CREATE: aws_instance.foo 1604 type: "" => "aws_instance" 1605 vars: "foo" => "foo" 1606 1607 STATE: 1608 1609 aws_instance.foo: (tainted) 1610 ID = foo 1611 type = aws_instance 1612 vars = foo 1613 ` 1614 1615 const testTerraformPlanMultipleTaintStr = ` 1616 DIFF: 1617 1618 DESTROY/CREATE: aws_instance.bar 1619 foo: "" => "2" 1620 type: "" => "aws_instance" 1621 1622 STATE: 1623 1624 aws_instance.bar: (2 tainted) 1625 ID = <not created> 1626 Tainted ID 1 = baz 1627 Tainted ID 2 = zip 1628 aws_instance.foo: 1629 ID = bar 1630 num = 2 1631 ` 1632 1633 const testTerraformPlanVarMultiCountOneStr = ` 1634 DIFF: 1635 1636 CREATE: aws_instance.bar 1637 foo: "" => "2" 1638 type: "" => "aws_instance" 1639 CREATE: aws_instance.foo 1640 num: "" => "2" 1641 type: "" => "aws_instance" 1642 1643 STATE: 1644 1645 <no state> 1646 ` 1647 1648 const testTerraformPlanPathVarStr = ` 1649 DIFF: 1650 1651 CREATE: aws_instance.foo 1652 cwd: "" => "%s/barpath" 1653 module: "" => "%s/foopath" 1654 root: "" => "%s/barpath" 1655 type: "" => "aws_instance" 1656 1657 STATE: 1658 1659 <no state> 1660 ` 1661 1662 const testTerraformPlanIgnoreChangesStr = ` 1663 DIFF: 1664 1665 UPDATE: aws_instance.foo 1666 type: "" => "aws_instance" 1667 1668 STATE: 1669 1670 aws_instance.foo: 1671 ID = bar 1672 ami = ami-abcd1234 1673 ` 1674 1675 const testTFPlanDiffIgnoreChangesWithFlatmaps = ` 1676 UPDATE: aws_instance.foo 1677 lst.#: "1" => "2" 1678 lst.0: "j" => "j" 1679 lst.1: "" => "k" 1680 set.#: "1" => "1" 1681 set.0.a: "1" => "1" 1682 set.0.b: "" => "2" 1683 type: "" => "aws_instance" 1684 ` 1685 1686 const testTerraformPlanIgnoreChangesWildcardStr = ` 1687 DIFF: 1688 1689 1690 1691 STATE: 1692 1693 aws_instance.foo: 1694 ID = bar 1695 ami = ami-abcd1234 1696 instance_type = t2.micro 1697 ` 1698 1699 const testTerraformPlanComputedValueInMap = ` 1700 DIFF: 1701 1702 CREATE: aws_computed_source.intermediates 1703 computed_read_only: "" => "<computed>" 1704 1705 module.test_mod: 1706 CREATE: aws_instance.inner2 1707 looked_up: "" => "<computed>" 1708 type: "" => "aws_instance" 1709 1710 STATE: 1711 1712 <no state> 1713 ` 1714 1715 const testTerraformPlanModuleVariableFromSplat = ` 1716 DIFF: 1717 1718 module.mod1: 1719 CREATE: aws_instance.test.0 1720 thing: "" => "doesnt" 1721 type: "" => "aws_instance" 1722 CREATE: aws_instance.test.1 1723 thing: "" => "doesnt" 1724 type: "" => "aws_instance" 1725 module.mod2: 1726 CREATE: aws_instance.test.0 1727 thing: "" => "doesnt" 1728 type: "" => "aws_instance" 1729 CREATE: aws_instance.test.1 1730 thing: "" => "doesnt" 1731 type: "" => "aws_instance" 1732 1733 STATE: 1734 1735 <no state>` 1736 1737 const testTerraformInputHCL = ` 1738 hcl_instance.hcltest: 1739 ID = foo 1740 provider = provider.hcl 1741 bar.w = z 1742 bar.x = y 1743 foo.# = 2 1744 foo.0 = a 1745 foo.1 = b 1746 type = hcl_instance 1747 ` 1748 1749 const testTerraformRefreshDataRefDataStr = ` 1750 data.null_data_source.bar: 1751 ID = foo 1752 provider = provider.null 1753 bar = yes 1754 type = null_data_source 1755 1756 Dependencies: 1757 data.null_data_source.foo 1758 data.null_data_source.foo: 1759 ID = foo 1760 provider = provider.null 1761 foo = yes 1762 type = null_data_source 1763 `