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