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