github.com/turtlemonvh/terraform@v0.6.9-0.20151204001754-8e40b6b855e8/terraform/terraform_test.go (about)

     1  package terraform
     2  
     3  import (
     4  	"bytes"
     5  	"crypto/sha1"
     6  	"encoding/gob"
     7  	"encoding/hex"
     8  	"fmt"
     9  	"io/ioutil"
    10  	"os"
    11  	"path/filepath"
    12  	"strings"
    13  	"sync"
    14  	"testing"
    15  
    16  	"github.com/hashicorp/go-getter"
    17  	"github.com/hashicorp/terraform/config"
    18  	"github.com/hashicorp/terraform/config/module"
    19  )
    20  
    21  // This is the directory where our test fixtures are.
    22  const fixtureDir = "./test-fixtures"
    23  
    24  func checksumStruct(t *testing.T, i interface{}) string {
    25  	// TODO(mitchellh): write a library to do this because gob is not
    26  	// deterministic in order
    27  	return "foo"
    28  
    29  	buf := new(bytes.Buffer)
    30  	enc := gob.NewEncoder(buf)
    31  	if err := enc.Encode(i); err != nil {
    32  		t.Fatalf("err: %s", err)
    33  	}
    34  
    35  	sum := sha1.Sum(buf.Bytes())
    36  	return hex.EncodeToString(sum[:])
    37  }
    38  
    39  func tempDir(t *testing.T) string {
    40  	dir, err := ioutil.TempDir("", "tf")
    41  	if err != nil {
    42  		t.Fatalf("err: %s", err)
    43  	}
    44  	if err := os.RemoveAll(dir); err != nil {
    45  		t.Fatalf("err: %s", err)
    46  	}
    47  
    48  	return dir
    49  }
    50  
    51  // tempEnv lets you temporarily set an environment variable. It returns
    52  // the old value that should be set via a defer.
    53  func tempEnv(t *testing.T, k string, v string) string {
    54  	old := os.Getenv(k)
    55  	os.Setenv(k, v)
    56  	return old
    57  }
    58  
    59  func testConfig(t *testing.T, name string) *config.Config {
    60  	c, err := config.LoadFile(filepath.Join(fixtureDir, name, "main.tf"))
    61  	if err != nil {
    62  		t.Fatalf("err: %s", err)
    63  	}
    64  
    65  	return c
    66  }
    67  
    68  func testModule(t *testing.T, name string) *module.Tree {
    69  	mod, err := module.NewTreeModule("", filepath.Join(fixtureDir, name))
    70  	if err != nil {
    71  		t.Fatalf("err: %s", err)
    72  	}
    73  
    74  	s := &getter.FolderStorage{StorageDir: tempDir(t)}
    75  	if err := mod.Load(s, module.GetModeGet); err != nil {
    76  		t.Fatalf("err: %s", err)
    77  	}
    78  
    79  	return mod
    80  }
    81  
    82  func testStringMatch(t *testing.T, s fmt.Stringer, expected string) {
    83  	actual := strings.TrimSpace(s.String())
    84  	expected = strings.TrimSpace(expected)
    85  	if actual != expected {
    86  		t.Fatalf("Actual\n\n%s\n\nExpected:\n\n%s", actual, expected)
    87  	}
    88  }
    89  
    90  func testProviderFuncFixed(rp ResourceProvider) ResourceProviderFactory {
    91  	return func() (ResourceProvider, error) {
    92  		return rp, nil
    93  	}
    94  }
    95  
    96  func testProvisionerFuncFixed(rp ResourceProvisioner) ResourceProvisionerFactory {
    97  	return func() (ResourceProvisioner, error) {
    98  		return rp, nil
    99  	}
   100  }
   101  
   102  // HookRecordApplyOrder is a test hook that records the order of applies
   103  // by recording the PreApply event.
   104  type HookRecordApplyOrder struct {
   105  	NilHook
   106  
   107  	Active bool
   108  
   109  	IDs    []string
   110  	States []*InstanceState
   111  	Diffs  []*InstanceDiff
   112  
   113  	l sync.Mutex
   114  }
   115  
   116  func (h *HookRecordApplyOrder) PreApply(
   117  	info *InstanceInfo,
   118  	s *InstanceState,
   119  	d *InstanceDiff) (HookAction, error) {
   120  	if h.Active {
   121  		h.l.Lock()
   122  		defer h.l.Unlock()
   123  
   124  		h.IDs = append(h.IDs, info.Id)
   125  		h.Diffs = append(h.Diffs, d)
   126  		h.States = append(h.States, s)
   127  	}
   128  
   129  	return HookActionContinue, nil
   130  }
   131  
   132  // Below are all the constant strings that are the expected output for
   133  // various tests.
   134  
   135  const testTerraformInputProviderStr = `
   136  aws_instance.bar:
   137    ID = foo
   138    bar = override
   139    foo = us-east-1
   140    type = aws_instance
   141  aws_instance.foo:
   142    ID = foo
   143    bar = baz
   144    num = 2
   145    type = aws_instance
   146  `
   147  
   148  const testTerraformInputProviderOnlyStr = `
   149  aws_instance.foo:
   150    ID = foo
   151    foo = us-west-2
   152    type = aws_instance
   153  `
   154  
   155  const testTerraformInputVarOnlyStr = `
   156  aws_instance.foo:
   157    ID = foo
   158    foo = us-east-1
   159    type = aws_instance
   160  `
   161  
   162  const testTerraformInputVarOnlyUnsetStr = `
   163  aws_instance.foo:
   164    ID = foo
   165    bar = baz
   166    foo = foovalue
   167    type = aws_instance
   168  `
   169  
   170  const testTerraformInputVarsStr = `
   171  aws_instance.bar:
   172    ID = foo
   173    bar = override
   174    foo = us-east-1
   175    type = aws_instance
   176  aws_instance.foo:
   177    ID = foo
   178    bar = baz
   179    num = 2
   180    type = aws_instance
   181  `
   182  
   183  const testTerraformApplyStr = `
   184  aws_instance.bar:
   185    ID = foo
   186    foo = bar
   187    type = aws_instance
   188  aws_instance.foo:
   189    ID = foo
   190    num = 2
   191    type = aws_instance
   192  `
   193  
   194  const testTerraformApplyProviderAliasStr = `
   195  aws_instance.bar:
   196    ID = foo
   197    provider = aws.bar
   198    foo = bar
   199    type = aws_instance
   200  aws_instance.foo:
   201    ID = foo
   202    num = 2
   203    type = aws_instance
   204  `
   205  
   206  const testTerraformApplyEmptyModuleStr = `
   207  <no state>
   208  Outputs:
   209  
   210  end = XXXX
   211  
   212  module.child:
   213  <no state>
   214  Outputs:
   215  
   216  aws_access_key = YYYYY
   217  aws_route53_zone_id = XXXX
   218  aws_secret_key = ZZZZ
   219  `
   220  
   221  const testTerraformApplyDependsCreateBeforeStr = `
   222  aws_instance.lb:
   223    ID = foo
   224    instance = foo
   225    type = aws_instance
   226  
   227    Dependencies:
   228      aws_instance.web
   229  aws_instance.web:
   230    ID = foo
   231    require_new = ami-new
   232    type = aws_instance
   233  `
   234  
   235  const testTerraformApplyCreateBeforeStr = `
   236  aws_instance.bar:
   237    ID = foo
   238    require_new = xyz
   239    type = aws_instance
   240  `
   241  
   242  const testTerraformApplyCreateBeforeUpdateStr = `
   243  aws_instance.bar:
   244    ID = foo
   245    foo = baz
   246    type = aws_instance
   247  `
   248  
   249  const testTerraformApplyCancelStr = `
   250  aws_instance.foo:
   251    ID = foo
   252    num = 2
   253  `
   254  
   255  const testTerraformApplyComputeStr = `
   256  aws_instance.bar:
   257    ID = foo
   258    foo = computed_dynamical
   259    type = aws_instance
   260  
   261    Dependencies:
   262      aws_instance.foo
   263  aws_instance.foo:
   264    ID = foo
   265    dynamical = computed_dynamical
   266    num = 2
   267    type = aws_instance
   268  `
   269  
   270  const testTerraformApplyCountDecStr = `
   271  aws_instance.foo.0:
   272    ID = bar
   273    foo = foo
   274    type = aws_instance
   275  aws_instance.foo.1:
   276    ID = bar
   277    foo = foo
   278    type = aws_instance
   279  `
   280  
   281  const testTerraformApplyCountDecToOneStr = `
   282  aws_instance.foo:
   283    ID = bar
   284    foo = foo
   285    type = aws_instance
   286  `
   287  
   288  const testTerraformApplyCountDecToOneCorruptedStr = `
   289  aws_instance.foo:
   290    ID = bar
   291    foo = foo
   292    type = aws_instance
   293  `
   294  
   295  const testTerraformApplyCountDecToOneCorruptedPlanStr = `
   296  DIFF:
   297  
   298  DESTROY: aws_instance.foo.0
   299  
   300  STATE:
   301  
   302  aws_instance.foo:
   303    ID = bar
   304    foo = foo
   305    type = aws_instance
   306  aws_instance.foo.0:
   307    ID = baz
   308    type = aws_instance
   309  `
   310  
   311  const testTerraformApplyCountTaintedStr = `
   312  <no state>
   313  `
   314  
   315  const testTerraformApplyCountVariableStr = `
   316  aws_instance.foo.0:
   317    ID = foo
   318    foo = foo
   319    type = aws_instance
   320  aws_instance.foo.1:
   321    ID = foo
   322    foo = foo
   323    type = aws_instance
   324  `
   325  
   326  const testTerraformApplyMinimalStr = `
   327  aws_instance.bar:
   328    ID = foo
   329  aws_instance.foo:
   330    ID = foo
   331  `
   332  
   333  const testTerraformApplyModuleStr = `
   334  aws_instance.bar:
   335    ID = foo
   336    foo = bar
   337    type = aws_instance
   338  aws_instance.foo:
   339    ID = foo
   340    num = 2
   341    type = aws_instance
   342  
   343  module.child:
   344    aws_instance.baz:
   345      ID = foo
   346      foo = bar
   347      type = aws_instance
   348  `
   349  
   350  const testTerraformApplyModuleBoolStr = `
   351  aws_instance.bar:
   352    ID = foo
   353    foo = 1
   354    type = aws_instance
   355  
   356    Dependencies:
   357      module.child
   358  
   359  module.child:
   360    <no state>
   361    Outputs:
   362  
   363    leader = 1
   364  `
   365  
   366  const testTerraformApplyModuleDestroyOrderStr = `
   367  <no state>
   368  module.child:
   369    <no state>
   370  `
   371  
   372  const testTerraformApplyMultiProviderStr = `
   373  aws_instance.bar:
   374    ID = foo
   375    foo = bar
   376    type = aws_instance
   377  do_instance.foo:
   378    ID = foo
   379    num = 2
   380    type = do_instance
   381  `
   382  
   383  const testTerraformApplyModuleOnlyProviderStr = `
   384  <no state>
   385  module.child:
   386    aws_instance.foo:
   387      ID = foo
   388    test_instance.foo:
   389      ID = foo
   390  `
   391  
   392  const testTerraformApplyModuleProviderAliasStr = `
   393  <no state>
   394  module.child:
   395    aws_instance.foo:
   396      ID = foo
   397      provider = aws.eu
   398  `
   399  
   400  const testTerraformApplyOutputOrphanStr = `
   401  <no state>
   402  Outputs:
   403  
   404  foo = bar
   405  `
   406  
   407  const testTerraformApplyProvisionerStr = `
   408  aws_instance.bar:
   409    ID = foo
   410  
   411    Dependencies:
   412      aws_instance.foo
   413  aws_instance.foo:
   414    ID = foo
   415    dynamical = computed_dynamical
   416    num = 2
   417    type = aws_instance
   418  `
   419  
   420  const testTerraformApplyProvisionerFailStr = `
   421  aws_instance.bar: (1 tainted)
   422    ID = <not created>
   423    Tainted ID 1 = foo
   424  aws_instance.foo:
   425    ID = foo
   426    num = 2
   427    type = aws_instance
   428  `
   429  
   430  const testTerraformApplyProvisionerFailCreateStr = `
   431  aws_instance.bar: (1 tainted)
   432    ID = <not created>
   433    Tainted ID 1 = foo
   434  `
   435  
   436  const testTerraformApplyProvisionerFailCreateNoIdStr = `
   437  <no state>
   438  `
   439  
   440  const testTerraformApplyProvisionerFailCreateBeforeDestroyStr = `
   441  aws_instance.bar: (1 tainted)
   442    ID = bar
   443    require_new = abc
   444    Tainted ID 1 = foo
   445  `
   446  
   447  const testTerraformApplyProvisionerResourceRefStr = `
   448  aws_instance.bar:
   449    ID = foo
   450    num = 2
   451    type = aws_instance
   452  `
   453  
   454  const testTerraformApplyProvisionerSelfRefStr = `
   455  aws_instance.foo:
   456    ID = foo
   457    foo = bar
   458    type = aws_instance
   459  `
   460  
   461  const testTerraformApplyProvisionerMultiSelfRefStr = `
   462  aws_instance.foo.0:
   463    ID = foo
   464    foo = number 0
   465    type = aws_instance
   466  aws_instance.foo.1:
   467    ID = foo
   468    foo = number 1
   469    type = aws_instance
   470  aws_instance.foo.2:
   471    ID = foo
   472    foo = number 2
   473    type = aws_instance
   474  `
   475  
   476  const testTerraformApplyProvisionerDiffStr = `
   477  aws_instance.bar:
   478    ID = foo
   479    foo = bar
   480    type = aws_instance
   481  `
   482  
   483  const testTerraformApplyDestroyStr = `
   484  <no state>
   485  `
   486  
   487  const testTerraformApplyDestroyNestedModuleStr = `
   488  module.child.subchild:
   489    <no state>
   490  `
   491  
   492  const testTerraformApplyErrorStr = `
   493  aws_instance.bar:
   494    ID = bar
   495  
   496    Dependencies:
   497      aws_instance.foo
   498  aws_instance.foo:
   499    ID = foo
   500    num = 2
   501  `
   502  
   503  const testTerraformApplyErrorCreateBeforeDestroyStr = `
   504  aws_instance.bar:
   505    ID = bar
   506    require_new = abc
   507  `
   508  
   509  const testTerraformApplyErrorDestroyCreateBeforeDestroyStr = `
   510  aws_instance.bar: (1 deposed)
   511    ID = foo
   512    Deposed ID 1 = bar
   513  `
   514  
   515  const testTerraformApplyErrorPartialStr = `
   516  aws_instance.bar:
   517    ID = bar
   518  
   519    Dependencies:
   520      aws_instance.foo
   521  aws_instance.foo:
   522    ID = foo
   523    num = 2
   524  `
   525  
   526  const testTerraformApplyTaintStr = `
   527  aws_instance.bar:
   528    ID = foo
   529    num = 2
   530    type = aws_instance
   531  `
   532  
   533  const testTerraformApplyTaintDepStr = `
   534  aws_instance.bar:
   535    ID = bar
   536    foo = foo
   537    num = 2
   538    type = aws_instance
   539  
   540    Dependencies:
   541      aws_instance.foo
   542  aws_instance.foo:
   543    ID = foo
   544    num = 2
   545    type = aws_instance
   546  `
   547  
   548  const testTerraformApplyTaintDepRequireNewStr = `
   549  aws_instance.bar:
   550    ID = foo
   551    foo = foo
   552    require_new = yes
   553    type = aws_instance
   554  
   555    Dependencies:
   556      aws_instance.foo
   557  aws_instance.foo:
   558    ID = foo
   559    num = 2
   560    type = aws_instance
   561  `
   562  
   563  const testTerraformApplyOutputStr = `
   564  aws_instance.bar:
   565    ID = foo
   566    foo = bar
   567    type = aws_instance
   568  aws_instance.foo:
   569    ID = foo
   570    num = 2
   571    type = aws_instance
   572  
   573  Outputs:
   574  
   575  foo_num = 2
   576  `
   577  
   578  const testTerraformApplyOutputAddStr = `
   579  aws_instance.test.0:
   580    ID = foo
   581    foo = foo0
   582    type = aws_instance
   583  aws_instance.test.1:
   584    ID = foo
   585    foo = foo1
   586    type = aws_instance
   587  
   588  Outputs:
   589  
   590  firstOutput = foo0
   591  secondOutput = foo1
   592  `
   593  
   594  const testTerraformApplyOutputListStr = `
   595  aws_instance.bar.0:
   596    ID = foo
   597    foo = bar
   598    type = aws_instance
   599  aws_instance.bar.1:
   600    ID = foo
   601    foo = bar
   602    type = aws_instance
   603  aws_instance.bar.2:
   604    ID = foo
   605    foo = bar
   606    type = aws_instance
   607  aws_instance.foo:
   608    ID = foo
   609    num = 2
   610    type = aws_instance
   611  
   612  Outputs:
   613  
   614  foo_num = bar,bar,bar
   615  `
   616  
   617  const testTerraformApplyOutputMultiStr = `
   618  aws_instance.bar.0:
   619    ID = foo
   620    foo = bar
   621    type = aws_instance
   622  aws_instance.bar.1:
   623    ID = foo
   624    foo = bar
   625    type = aws_instance
   626  aws_instance.bar.2:
   627    ID = foo
   628    foo = bar
   629    type = aws_instance
   630  aws_instance.foo:
   631    ID = foo
   632    num = 2
   633    type = aws_instance
   634  
   635  Outputs:
   636  
   637  foo_num = bar,bar,bar
   638  `
   639  
   640  const testTerraformApplyOutputMultiIndexStr = `
   641  aws_instance.bar.0:
   642    ID = foo
   643    foo = bar
   644    type = aws_instance
   645  aws_instance.bar.1:
   646    ID = foo
   647    foo = bar
   648    type = aws_instance
   649  aws_instance.bar.2:
   650    ID = foo
   651    foo = bar
   652    type = aws_instance
   653  aws_instance.foo:
   654    ID = foo
   655    num = 2
   656    type = aws_instance
   657  
   658  Outputs:
   659  
   660  foo_num = bar
   661  `
   662  
   663  const testTerraformApplyUnknownAttrStr = `
   664  aws_instance.foo:
   665    ID = foo
   666    num = 2
   667    type = aws_instance
   668  `
   669  
   670  const testTerraformApplyVarsStr = `
   671  aws_instance.bar:
   672    ID = foo
   673    bar = foo
   674    baz = override
   675    foo = us-west-2
   676    type = aws_instance
   677  aws_instance.foo:
   678    ID = foo
   679    bar = baz
   680    num = 2
   681    type = aws_instance
   682  `
   683  
   684  const testTerraformApplyVarsEnvStr = `
   685  aws_instance.bar:
   686    ID = foo
   687    foo = baz
   688    type = aws_instance
   689  `
   690  
   691  const testTerraformPlanStr = `
   692  DIFF:
   693  
   694  CREATE: aws_instance.bar
   695    foo:  "" => "2"
   696    type: "" => "aws_instance"
   697  CREATE: aws_instance.foo
   698    num:  "" => "2"
   699    type: "" => "aws_instance"
   700  
   701  STATE:
   702  
   703  <no state>
   704  `
   705  
   706  const testTerraformPlanComputedStr = `
   707  DIFF:
   708  
   709  CREATE: aws_instance.bar
   710    foo:  "" => "<computed>"
   711    type: "" => "aws_instance"
   712  CREATE: aws_instance.foo
   713    foo:  "" => "<computed>"
   714    num:  "" => "2"
   715    type: "" => "aws_instance"
   716  
   717  STATE:
   718  
   719  <no state>
   720  `
   721  
   722  const testTerraformPlanComputedIdStr = `
   723  DIFF:
   724  
   725  CREATE: aws_instance.bar
   726    foo:  "" => "<computed>"
   727    type: "" => "aws_instance"
   728  CREATE: aws_instance.foo
   729    foo:  "" => "<computed>"
   730    num:  "" => "2"
   731    type: "" => "aws_instance"
   732  
   733  STATE:
   734  
   735  <no state>
   736  `
   737  
   738  const testTerraformPlanComputedListStr = `
   739  DIFF:
   740  
   741  CREATE: aws_instance.bar
   742    foo:  "" => "<computed>"
   743    type: "" => "aws_instance"
   744  CREATE: aws_instance.foo
   745    list.#: "" => "<computed>"
   746    num:    "" => "2"
   747    type:   "" => "aws_instance"
   748  
   749  STATE:
   750  
   751  <no state>
   752  `
   753  
   754  const testTerraformPlanCountStr = `
   755  DIFF:
   756  
   757  CREATE: aws_instance.bar
   758    foo:  "" => "foo,foo,foo,foo,foo"
   759    type: "" => "aws_instance"
   760  CREATE: aws_instance.foo.0
   761    foo:  "" => "foo"
   762    type: "" => "aws_instance"
   763  CREATE: aws_instance.foo.1
   764    foo:  "" => "foo"
   765    type: "" => "aws_instance"
   766  CREATE: aws_instance.foo.2
   767    foo:  "" => "foo"
   768    type: "" => "aws_instance"
   769  CREATE: aws_instance.foo.3
   770    foo:  "" => "foo"
   771    type: "" => "aws_instance"
   772  CREATE: aws_instance.foo.4
   773    foo:  "" => "foo"
   774    type: "" => "aws_instance"
   775  
   776  STATE:
   777  
   778  <no state>
   779  `
   780  
   781  const testTerraformPlanCountIndexStr = `
   782  DIFF:
   783  
   784  CREATE: aws_instance.foo.0
   785    foo:  "" => "0"
   786    type: "" => "aws_instance"
   787  CREATE: aws_instance.foo.1
   788    foo:  "" => "1"
   789    type: "" => "aws_instance"
   790  
   791  STATE:
   792  
   793  <no state>
   794  `
   795  
   796  const testTerraformPlanCountIndexZeroStr = `
   797  DIFF:
   798  
   799  CREATE: aws_instance.foo
   800    foo:  "" => "0"
   801    type: "" => "aws_instance"
   802  
   803  STATE:
   804  
   805  <no state>
   806  `
   807  
   808  const testTerraformPlanCountOneIndexStr = `
   809  DIFF:
   810  
   811  CREATE: aws_instance.bar
   812    foo:  "" => "foo"
   813    type: "" => "aws_instance"
   814  CREATE: aws_instance.foo
   815    foo:  "" => "foo"
   816    type: "" => "aws_instance"
   817  
   818  STATE:
   819  
   820  <no state>
   821  `
   822  
   823  const testTerraformPlanCountZeroStr = `
   824  DIFF:
   825  
   826  CREATE: aws_instance.bar
   827    foo:  "" => ""
   828    type: "" => "aws_instance"
   829  
   830  STATE:
   831  
   832  <no state>
   833  `
   834  
   835  const testTerraformPlanCountVarStr = `
   836  DIFF:
   837  
   838  CREATE: aws_instance.bar
   839    foo:  "" => "foo,foo,foo"
   840    type: "" => "aws_instance"
   841  CREATE: aws_instance.foo.0
   842    foo:  "" => "foo"
   843    type: "" => "aws_instance"
   844  CREATE: aws_instance.foo.1
   845    foo:  "" => "foo"
   846    type: "" => "aws_instance"
   847  CREATE: aws_instance.foo.2
   848    foo:  "" => "foo"
   849    type: "" => "aws_instance"
   850  
   851  STATE:
   852  
   853  <no state>
   854  `
   855  
   856  const testTerraformPlanCountDecreaseStr = `
   857  DIFF:
   858  
   859  CREATE: aws_instance.bar
   860    foo:  "" => "bar"
   861    type: "" => "aws_instance"
   862  DESTROY: aws_instance.foo.1
   863  DESTROY: aws_instance.foo.2
   864  
   865  STATE:
   866  
   867  aws_instance.foo.0:
   868    ID = bar
   869    foo = foo
   870    type = aws_instance
   871  aws_instance.foo.1:
   872    ID = bar
   873  aws_instance.foo.2:
   874    ID = bar
   875  `
   876  
   877  const testTerraformPlanCountIncreaseStr = `
   878  DIFF:
   879  
   880  CREATE: aws_instance.bar
   881    foo:  "" => "bar"
   882    type: "" => "aws_instance"
   883  CREATE: aws_instance.foo.1
   884    foo:  "" => "foo"
   885    type: "" => "aws_instance"
   886  CREATE: aws_instance.foo.2
   887    foo:  "" => "foo"
   888    type: "" => "aws_instance"
   889  
   890  STATE:
   891  
   892  aws_instance.foo:
   893    ID = bar
   894    foo = foo
   895    type = aws_instance
   896  `
   897  
   898  const testTerraformPlanCountIncreaseFromOneStr = `
   899  DIFF:
   900  
   901  CREATE: aws_instance.bar
   902    foo:  "" => "bar"
   903    type: "" => "aws_instance"
   904  CREATE: aws_instance.foo.1
   905    foo:  "" => "foo"
   906    type: "" => "aws_instance"
   907  CREATE: aws_instance.foo.2
   908    foo:  "" => "foo"
   909    type: "" => "aws_instance"
   910  
   911  STATE:
   912  
   913  aws_instance.foo.0:
   914    ID = bar
   915    foo = foo
   916    type = aws_instance
   917  `
   918  
   919  const testTerraformPlanCountIncreaseFromOneCorruptedStr = `
   920  DIFF:
   921  
   922  CREATE: aws_instance.bar
   923    foo:  "" => "bar"
   924    type: "" => "aws_instance"
   925  DESTROY: aws_instance.foo
   926  CREATE: aws_instance.foo.1
   927    foo:  "" => "foo"
   928    type: "" => "aws_instance"
   929  CREATE: aws_instance.foo.2
   930    foo:  "" => "foo"
   931    type: "" => "aws_instance"
   932  
   933  STATE:
   934  
   935  aws_instance.foo:
   936    ID = bar
   937    foo = foo
   938    type = aws_instance
   939  aws_instance.foo.0:
   940    ID = bar
   941    foo = foo
   942    type = aws_instance
   943  `
   944  
   945  const testTerraformPlanDestroyStr = `
   946  DIFF:
   947  
   948  DESTROY: aws_instance.one
   949  DESTROY: aws_instance.two
   950  
   951  STATE:
   952  
   953  aws_instance.one:
   954    ID = bar
   955  aws_instance.two:
   956    ID = baz
   957  `
   958  
   959  const testTerraformPlanDiffVarStr = `
   960  DIFF:
   961  
   962  CREATE: aws_instance.bar
   963    num:  "" => "3"
   964    type: "" => "aws_instance"
   965  UPDATE: aws_instance.foo
   966    num: "2" => "3"
   967  
   968  STATE:
   969  
   970  aws_instance.foo:
   971    ID = bar
   972    num = 2
   973  `
   974  
   975  const testTerraformPlanEmptyStr = `
   976  DIFF:
   977  
   978  CREATE: aws_instance.bar
   979  CREATE: aws_instance.foo
   980  
   981  STATE:
   982  
   983  <no state>
   984  `
   985  
   986  const testTerraformPlanModulesStr = `
   987  DIFF:
   988  
   989  CREATE: aws_instance.bar
   990    foo:  "" => "2"
   991    type: "" => "aws_instance"
   992  CREATE: aws_instance.foo
   993    num:  "" => "2"
   994    type: "" => "aws_instance"
   995  
   996  module.child:
   997    CREATE: aws_instance.foo
   998      num:  "" => "2"
   999      type: "" => "aws_instance"
  1000  
  1001  STATE:
  1002  
  1003  <no state>
  1004  `
  1005  
  1006  const testTerraformPlanModuleCycleStr = `
  1007  DIFF:
  1008  
  1009  CREATE: aws_instance.b
  1010  CREATE: aws_instance.c
  1011    some_input: "" => "<computed>"
  1012    type:       "" => "aws_instance"
  1013  
  1014  STATE:
  1015  
  1016  <no state>
  1017  `
  1018  
  1019  const testTerraformPlanModuleDestroyStr = `
  1020  DIFF:
  1021  
  1022  DESTROY: aws_instance.foo
  1023  
  1024  module.child:
  1025    DESTROY MODULE
  1026    DESTROY: aws_instance.foo
  1027  
  1028  STATE:
  1029  
  1030  aws_instance.foo:
  1031    ID = bar
  1032  
  1033  module.child:
  1034    aws_instance.foo:
  1035      ID = bar
  1036  `
  1037  
  1038  const testTerraformPlanModuleDestroyCycleStr = `
  1039  DIFF:
  1040  
  1041  module.a_module:
  1042    DESTROY MODULE
  1043    DESTROY: aws_instance.a
  1044  module.b_module:
  1045    DESTROY MODULE
  1046    DESTROY: aws_instance.b
  1047  
  1048  STATE:
  1049  
  1050  module.a_module:
  1051    aws_instance.a:
  1052      ID = a
  1053  module.b_module:
  1054    aws_instance.b:
  1055      ID = b
  1056  `
  1057  
  1058  const testTerraformPlanModuleDestroyMultivarStr = `
  1059  DIFF:
  1060  
  1061  module.child:
  1062    DESTROY MODULE
  1063    DESTROY: aws_instance.foo.0
  1064    DESTROY: aws_instance.foo.1
  1065  
  1066  STATE:
  1067  
  1068  <no state>
  1069  module.child:
  1070    aws_instance.foo.0:
  1071      ID = bar0
  1072    aws_instance.foo.1:
  1073      ID = bar1
  1074  `
  1075  
  1076  const testTerraformPlanModuleInputStr = `
  1077  DIFF:
  1078  
  1079  CREATE: aws_instance.bar
  1080    foo:  "" => "2"
  1081    type: "" => "aws_instance"
  1082  
  1083  module.child:
  1084    CREATE: aws_instance.foo
  1085      foo:  "" => "42"
  1086      type: "" => "aws_instance"
  1087  
  1088  STATE:
  1089  
  1090  <no state>
  1091  `
  1092  
  1093  const testTerraformPlanModuleInputComputedStr = `
  1094  DIFF:
  1095  
  1096  CREATE: aws_instance.bar
  1097    foo:  "" => "<computed>"
  1098    type: "" => "aws_instance"
  1099  
  1100  module.child:
  1101    CREATE: aws_instance.foo
  1102      foo:  "" => "<computed>"
  1103      type: "" => "aws_instance"
  1104  
  1105  STATE:
  1106  
  1107  <no state>
  1108  `
  1109  
  1110  const testTerraformPlanModuleInputVarStr = `
  1111  DIFF:
  1112  
  1113  CREATE: aws_instance.bar
  1114    foo:  "" => "2"
  1115    type: "" => "aws_instance"
  1116  
  1117  module.child:
  1118    CREATE: aws_instance.foo
  1119      foo:  "" => "52"
  1120      type: "" => "aws_instance"
  1121  
  1122  STATE:
  1123  
  1124  <no state>
  1125  `
  1126  
  1127  const testTerraformPlanModuleMultiVarStr = `
  1128  DIFF:
  1129  
  1130  CREATE: aws_instance.parent.0
  1131  CREATE: aws_instance.parent.1
  1132  
  1133  module.child:
  1134    CREATE: aws_instance.bar.0
  1135      baz:  "" => "baz"
  1136      type: "" => "aws_instance"
  1137    CREATE: aws_instance.bar.1
  1138      baz:  "" => "baz"
  1139      type: "" => "aws_instance"
  1140    CREATE: aws_instance.foo
  1141      foo:  "" => "baz,baz"
  1142      type: "" => "aws_instance"
  1143  
  1144  STATE:
  1145  
  1146  <no state>
  1147  `
  1148  
  1149  const testTerraformPlanModuleOrphansStr = `
  1150  DIFF:
  1151  
  1152  CREATE: aws_instance.foo
  1153    num:  "" => "2"
  1154    type: "" => "aws_instance"
  1155  
  1156  module.child:
  1157    DESTROY: aws_instance.foo
  1158  
  1159  STATE:
  1160  
  1161  module.child:
  1162    aws_instance.foo:
  1163      ID = baz
  1164  `
  1165  
  1166  const testTerraformPlanModuleVarStr = `
  1167  DIFF:
  1168  
  1169  CREATE: aws_instance.bar
  1170    foo:  "" => "2"
  1171    type: "" => "aws_instance"
  1172  
  1173  module.child:
  1174    CREATE: aws_instance.foo
  1175      num:  "" => "2"
  1176      type: "" => "aws_instance"
  1177  
  1178  STATE:
  1179  
  1180  <no state>
  1181  `
  1182  
  1183  const testTerraformPlanModuleVarComputedStr = `
  1184  DIFF:
  1185  
  1186  CREATE: aws_instance.bar
  1187    foo:  "" => "<computed>"
  1188    type: "" => "aws_instance"
  1189  
  1190  module.child:
  1191    CREATE: aws_instance.foo
  1192      foo:  "" => "<computed>"
  1193      type: "" => "aws_instance"
  1194  
  1195  STATE:
  1196  
  1197  <no state>
  1198  `
  1199  
  1200  const testTerraformPlanModuleVarIntStr = `
  1201  DIFF:
  1202  
  1203  module.child:
  1204    CREATE: aws_instance.foo
  1205      num:  "" => "2"
  1206      type: "" => "aws_instance"
  1207  
  1208  STATE:
  1209  
  1210  <no state>
  1211  `
  1212  
  1213  const testTerraformPlanOrphanStr = `
  1214  DIFF:
  1215  
  1216  DESTROY: aws_instance.baz
  1217  CREATE: aws_instance.foo
  1218    num:  "" => "2"
  1219    type: "" => "aws_instance"
  1220  
  1221  STATE:
  1222  
  1223  aws_instance.baz:
  1224    ID = bar
  1225  `
  1226  
  1227  const testTerraformPlanStateStr = `
  1228  DIFF:
  1229  
  1230  CREATE: aws_instance.bar
  1231    foo:  "" => "2"
  1232    type: "" => "aws_instance"
  1233  UPDATE: aws_instance.foo
  1234    num:  "" => "2"
  1235    type: "" => "aws_instance"
  1236  
  1237  STATE:
  1238  
  1239  aws_instance.foo:
  1240    ID = bar
  1241  `
  1242  
  1243  const testTerraformPlanTaintStr = `
  1244  DIFF:
  1245  
  1246  DESTROY/CREATE: aws_instance.bar
  1247    foo:  "" => "2"
  1248    type: "" => "aws_instance"
  1249  
  1250  STATE:
  1251  
  1252  aws_instance.bar: (1 tainted)
  1253    ID = <not created>
  1254    Tainted ID 1 = baz
  1255  aws_instance.foo:
  1256    ID = bar
  1257    num = 2
  1258  `
  1259  
  1260  const testTerraformPlanMultipleTaintStr = `
  1261  DIFF:
  1262  
  1263  DESTROY/CREATE: aws_instance.bar
  1264    foo:  "" => "2"
  1265    type: "" => "aws_instance"
  1266  
  1267  STATE:
  1268  
  1269  aws_instance.bar: (2 tainted)
  1270    ID = <not created>
  1271    Tainted ID 1 = baz
  1272    Tainted ID 2 = zip
  1273  aws_instance.foo:
  1274    ID = bar
  1275    num = 2
  1276  `
  1277  
  1278  const testTerraformPlanVarMultiCountOneStr = `
  1279  DIFF:
  1280  
  1281  CREATE: aws_instance.bar
  1282    foo:  "" => "2"
  1283    type: "" => "aws_instance"
  1284  CREATE: aws_instance.foo
  1285    num:  "" => "2"
  1286    type: "" => "aws_instance"
  1287  
  1288  STATE:
  1289  
  1290  <no state>
  1291  `
  1292  
  1293  const testTerraformPlanPathVarStr = `
  1294  DIFF:
  1295  
  1296  CREATE: aws_instance.foo
  1297    cwd:    "" => "%s/barpath"
  1298    module: "" => "%s/foopath"
  1299    root:   "" => "%s/barpath"
  1300    type:   "" => "aws_instance"
  1301  
  1302  STATE:
  1303  
  1304  <no state>
  1305  `
  1306  
  1307  const testTerraformPlanIgnoreChangesStr = `
  1308  DIFF:
  1309  
  1310  UPDATE: aws_instance.foo
  1311    type: "" => "aws_instance"
  1312  
  1313  STATE:
  1314  
  1315  aws_instance.foo:
  1316    ID = bar
  1317    ami = ami-abcd1234
  1318  `