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