github.com/jsoriano/terraform@v0.6.7-0.20151026070445-8b70867fdd95/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 testTerraformApplyOutputListStr = `
   579  aws_instance.bar.0:
   580    ID = foo
   581    foo = bar
   582    type = aws_instance
   583  aws_instance.bar.1:
   584    ID = foo
   585    foo = bar
   586    type = aws_instance
   587  aws_instance.bar.2:
   588    ID = foo
   589    foo = bar
   590    type = aws_instance
   591  aws_instance.foo:
   592    ID = foo
   593    num = 2
   594    type = aws_instance
   595  
   596  Outputs:
   597  
   598  foo_num = bar,bar,bar
   599  `
   600  
   601  const testTerraformApplyOutputMultiStr = `
   602  aws_instance.bar.0:
   603    ID = foo
   604    foo = bar
   605    type = aws_instance
   606  aws_instance.bar.1:
   607    ID = foo
   608    foo = bar
   609    type = aws_instance
   610  aws_instance.bar.2:
   611    ID = foo
   612    foo = bar
   613    type = aws_instance
   614  aws_instance.foo:
   615    ID = foo
   616    num = 2
   617    type = aws_instance
   618  
   619  Outputs:
   620  
   621  foo_num = bar,bar,bar
   622  `
   623  
   624  const testTerraformApplyOutputMultiIndexStr = `
   625  aws_instance.bar.0:
   626    ID = foo
   627    foo = bar
   628    type = aws_instance
   629  aws_instance.bar.1:
   630    ID = foo
   631    foo = bar
   632    type = aws_instance
   633  aws_instance.bar.2:
   634    ID = foo
   635    foo = bar
   636    type = aws_instance
   637  aws_instance.foo:
   638    ID = foo
   639    num = 2
   640    type = aws_instance
   641  
   642  Outputs:
   643  
   644  foo_num = bar
   645  `
   646  
   647  const testTerraformApplyUnknownAttrStr = `
   648  aws_instance.foo:
   649    ID = foo
   650    num = 2
   651    type = aws_instance
   652  `
   653  
   654  const testTerraformApplyVarsStr = `
   655  aws_instance.bar:
   656    ID = foo
   657    bar = foo
   658    baz = override
   659    foo = us-west-2
   660    type = aws_instance
   661  aws_instance.foo:
   662    ID = foo
   663    bar = baz
   664    num = 2
   665    type = aws_instance
   666  `
   667  
   668  const testTerraformApplyVarsEnvStr = `
   669  aws_instance.bar:
   670    ID = foo
   671    foo = baz
   672    type = aws_instance
   673  `
   674  
   675  const testTerraformPlanStr = `
   676  DIFF:
   677  
   678  CREATE: aws_instance.bar
   679    foo:  "" => "2"
   680    type: "" => "aws_instance"
   681  CREATE: aws_instance.foo
   682    num:  "" => "2"
   683    type: "" => "aws_instance"
   684  
   685  STATE:
   686  
   687  <no state>
   688  `
   689  
   690  const testTerraformPlanComputedStr = `
   691  DIFF:
   692  
   693  CREATE: aws_instance.bar
   694    foo:  "" => "<computed>"
   695    type: "" => "aws_instance"
   696  CREATE: aws_instance.foo
   697    foo:  "" => "<computed>"
   698    num:  "" => "2"
   699    type: "" => "aws_instance"
   700  
   701  STATE:
   702  
   703  <no state>
   704  `
   705  
   706  const testTerraformPlanComputedIdStr = `
   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 testTerraformPlanComputedListStr = `
   723  DIFF:
   724  
   725  CREATE: aws_instance.bar
   726    foo:  "" => "<computed>"
   727    type: "" => "aws_instance"
   728  CREATE: aws_instance.foo
   729    list.#: "" => "<computed>"
   730    num:    "" => "2"
   731    type:   "" => "aws_instance"
   732  
   733  STATE:
   734  
   735  <no state>
   736  `
   737  
   738  const testTerraformPlanCountStr = `
   739  DIFF:
   740  
   741  CREATE: aws_instance.bar
   742    foo:  "" => "foo,foo,foo,foo,foo"
   743    type: "" => "aws_instance"
   744  CREATE: aws_instance.foo.0
   745    foo:  "" => "foo"
   746    type: "" => "aws_instance"
   747  CREATE: aws_instance.foo.1
   748    foo:  "" => "foo"
   749    type: "" => "aws_instance"
   750  CREATE: aws_instance.foo.2
   751    foo:  "" => "foo"
   752    type: "" => "aws_instance"
   753  CREATE: aws_instance.foo.3
   754    foo:  "" => "foo"
   755    type: "" => "aws_instance"
   756  CREATE: aws_instance.foo.4
   757    foo:  "" => "foo"
   758    type: "" => "aws_instance"
   759  
   760  STATE:
   761  
   762  <no state>
   763  `
   764  
   765  const testTerraformPlanCountIndexStr = `
   766  DIFF:
   767  
   768  CREATE: aws_instance.foo.0
   769    foo:  "" => "0"
   770    type: "" => "aws_instance"
   771  CREATE: aws_instance.foo.1
   772    foo:  "" => "1"
   773    type: "" => "aws_instance"
   774  
   775  STATE:
   776  
   777  <no state>
   778  `
   779  
   780  const testTerraformPlanCountIndexZeroStr = `
   781  DIFF:
   782  
   783  CREATE: aws_instance.foo
   784    foo:  "" => "0"
   785    type: "" => "aws_instance"
   786  
   787  STATE:
   788  
   789  <no state>
   790  `
   791  
   792  const testTerraformPlanCountOneIndexStr = `
   793  DIFF:
   794  
   795  CREATE: aws_instance.bar
   796    foo:  "" => "foo"
   797    type: "" => "aws_instance"
   798  CREATE: aws_instance.foo
   799    foo:  "" => "foo"
   800    type: "" => "aws_instance"
   801  
   802  STATE:
   803  
   804  <no state>
   805  `
   806  
   807  const testTerraformPlanCountZeroStr = `
   808  DIFF:
   809  
   810  CREATE: aws_instance.bar
   811    foo:  "" => ""
   812    type: "" => "aws_instance"
   813  
   814  STATE:
   815  
   816  <no state>
   817  `
   818  
   819  const testTerraformPlanCountVarStr = `
   820  DIFF:
   821  
   822  CREATE: aws_instance.bar
   823    foo:  "" => "foo,foo,foo"
   824    type: "" => "aws_instance"
   825  CREATE: aws_instance.foo.0
   826    foo:  "" => "foo"
   827    type: "" => "aws_instance"
   828  CREATE: aws_instance.foo.1
   829    foo:  "" => "foo"
   830    type: "" => "aws_instance"
   831  CREATE: aws_instance.foo.2
   832    foo:  "" => "foo"
   833    type: "" => "aws_instance"
   834  
   835  STATE:
   836  
   837  <no state>
   838  `
   839  
   840  const testTerraformPlanCountDecreaseStr = `
   841  DIFF:
   842  
   843  CREATE: aws_instance.bar
   844    foo:  "" => "bar"
   845    type: "" => "aws_instance"
   846  DESTROY: aws_instance.foo.1
   847  DESTROY: aws_instance.foo.2
   848  
   849  STATE:
   850  
   851  aws_instance.foo.0:
   852    ID = bar
   853    foo = foo
   854    type = aws_instance
   855  aws_instance.foo.1:
   856    ID = bar
   857  aws_instance.foo.2:
   858    ID = bar
   859  `
   860  
   861  const testTerraformPlanCountIncreaseStr = `
   862  DIFF:
   863  
   864  CREATE: aws_instance.bar
   865    foo:  "" => "bar"
   866    type: "" => "aws_instance"
   867  CREATE: aws_instance.foo.1
   868    foo:  "" => "foo"
   869    type: "" => "aws_instance"
   870  CREATE: aws_instance.foo.2
   871    foo:  "" => "foo"
   872    type: "" => "aws_instance"
   873  
   874  STATE:
   875  
   876  aws_instance.foo:
   877    ID = bar
   878    foo = foo
   879    type = aws_instance
   880  `
   881  
   882  const testTerraformPlanCountIncreaseFromOneStr = `
   883  DIFF:
   884  
   885  CREATE: aws_instance.bar
   886    foo:  "" => "bar"
   887    type: "" => "aws_instance"
   888  CREATE: aws_instance.foo.1
   889    foo:  "" => "foo"
   890    type: "" => "aws_instance"
   891  CREATE: aws_instance.foo.2
   892    foo:  "" => "foo"
   893    type: "" => "aws_instance"
   894  
   895  STATE:
   896  
   897  aws_instance.foo.0:
   898    ID = bar
   899    foo = foo
   900    type = aws_instance
   901  `
   902  
   903  const testTerraformPlanCountIncreaseFromOneCorruptedStr = `
   904  DIFF:
   905  
   906  CREATE: aws_instance.bar
   907    foo:  "" => "bar"
   908    type: "" => "aws_instance"
   909  DESTROY: aws_instance.foo
   910  CREATE: aws_instance.foo.1
   911    foo:  "" => "foo"
   912    type: "" => "aws_instance"
   913  CREATE: aws_instance.foo.2
   914    foo:  "" => "foo"
   915    type: "" => "aws_instance"
   916  
   917  STATE:
   918  
   919  aws_instance.foo:
   920    ID = bar
   921    foo = foo
   922    type = aws_instance
   923  aws_instance.foo.0:
   924    ID = bar
   925    foo = foo
   926    type = aws_instance
   927  `
   928  
   929  const testTerraformPlanDestroyStr = `
   930  DIFF:
   931  
   932  DESTROY: aws_instance.one
   933  DESTROY: aws_instance.two
   934  
   935  STATE:
   936  
   937  aws_instance.one:
   938    ID = bar
   939  aws_instance.two:
   940    ID = baz
   941  `
   942  
   943  const testTerraformPlanDiffVarStr = `
   944  DIFF:
   945  
   946  CREATE: aws_instance.bar
   947    num:  "" => "3"
   948    type: "" => "aws_instance"
   949  UPDATE: aws_instance.foo
   950    num: "2" => "3"
   951  
   952  STATE:
   953  
   954  aws_instance.foo:
   955    ID = bar
   956    num = 2
   957  `
   958  
   959  const testTerraformPlanEmptyStr = `
   960  DIFF:
   961  
   962  CREATE: aws_instance.bar
   963  CREATE: aws_instance.foo
   964  
   965  STATE:
   966  
   967  <no state>
   968  `
   969  
   970  const testTerraformPlanModulesStr = `
   971  DIFF:
   972  
   973  CREATE: aws_instance.bar
   974    foo:  "" => "2"
   975    type: "" => "aws_instance"
   976  CREATE: aws_instance.foo
   977    num:  "" => "2"
   978    type: "" => "aws_instance"
   979  
   980  module.child:
   981    CREATE: aws_instance.foo
   982      num:  "" => "2"
   983      type: "" => "aws_instance"
   984  
   985  STATE:
   986  
   987  <no state>
   988  `
   989  
   990  const testTerraformPlanModuleCycleStr = `
   991  DIFF:
   992  
   993  CREATE: aws_instance.b
   994  CREATE: aws_instance.c
   995    some_input: "" => "<computed>"
   996    type:       "" => "aws_instance"
   997  
   998  STATE:
   999  
  1000  <no state>
  1001  `
  1002  
  1003  const testTerraformPlanModuleDestroyStr = `
  1004  DIFF:
  1005  
  1006  DESTROY: aws_instance.foo
  1007  
  1008  module.child:
  1009    DESTROY MODULE
  1010    DESTROY: aws_instance.foo
  1011  
  1012  STATE:
  1013  
  1014  aws_instance.foo:
  1015    ID = bar
  1016  
  1017  module.child:
  1018    aws_instance.foo:
  1019      ID = bar
  1020  `
  1021  
  1022  const testTerraformPlanModuleDestroyCycleStr = `
  1023  DIFF:
  1024  
  1025  module.a_module:
  1026    DESTROY MODULE
  1027    DESTROY: aws_instance.a
  1028  module.b_module:
  1029    DESTROY MODULE
  1030    DESTROY: aws_instance.b
  1031  
  1032  STATE:
  1033  
  1034  module.a_module:
  1035    aws_instance.a:
  1036      ID = a
  1037  module.b_module:
  1038    aws_instance.b:
  1039      ID = b
  1040  `
  1041  
  1042  const testTerraformPlanModuleDestroyMultivarStr = `
  1043  DIFF:
  1044  
  1045  module.child:
  1046    DESTROY MODULE
  1047    DESTROY: aws_instance.foo.0
  1048    DESTROY: aws_instance.foo.1
  1049  
  1050  STATE:
  1051  
  1052  <no state>
  1053  module.child:
  1054    aws_instance.foo.0:
  1055      ID = bar0
  1056    aws_instance.foo.1:
  1057      ID = bar1
  1058  `
  1059  
  1060  const testTerraformPlanModuleInputStr = `
  1061  DIFF:
  1062  
  1063  CREATE: aws_instance.bar
  1064    foo:  "" => "2"
  1065    type: "" => "aws_instance"
  1066  
  1067  module.child:
  1068    CREATE: aws_instance.foo
  1069      foo:  "" => "42"
  1070      type: "" => "aws_instance"
  1071  
  1072  STATE:
  1073  
  1074  <no state>
  1075  `
  1076  
  1077  const testTerraformPlanModuleInputComputedStr = `
  1078  DIFF:
  1079  
  1080  CREATE: aws_instance.bar
  1081    foo:  "" => "<computed>"
  1082    type: "" => "aws_instance"
  1083  
  1084  module.child:
  1085    CREATE: aws_instance.foo
  1086      foo:  "" => "<computed>"
  1087      type: "" => "aws_instance"
  1088  
  1089  STATE:
  1090  
  1091  <no state>
  1092  `
  1093  
  1094  const testTerraformPlanModuleInputVarStr = `
  1095  DIFF:
  1096  
  1097  CREATE: aws_instance.bar
  1098    foo:  "" => "2"
  1099    type: "" => "aws_instance"
  1100  
  1101  module.child:
  1102    CREATE: aws_instance.foo
  1103      foo:  "" => "52"
  1104      type: "" => "aws_instance"
  1105  
  1106  STATE:
  1107  
  1108  <no state>
  1109  `
  1110  
  1111  const testTerraformPlanModuleMultiVarStr = `
  1112  DIFF:
  1113  
  1114  CREATE: aws_instance.parent.0
  1115  CREATE: aws_instance.parent.1
  1116  
  1117  module.child:
  1118    CREATE: aws_instance.bar.0
  1119      baz:  "" => "baz"
  1120      type: "" => "aws_instance"
  1121    CREATE: aws_instance.bar.1
  1122      baz:  "" => "baz"
  1123      type: "" => "aws_instance"
  1124    CREATE: aws_instance.foo
  1125      foo:  "" => "baz,baz"
  1126      type: "" => "aws_instance"
  1127  
  1128  STATE:
  1129  
  1130  <no state>
  1131  `
  1132  
  1133  const testTerraformPlanModuleOrphansStr = `
  1134  DIFF:
  1135  
  1136  CREATE: aws_instance.foo
  1137    num:  "" => "2"
  1138    type: "" => "aws_instance"
  1139  
  1140  module.child:
  1141    DESTROY: aws_instance.foo
  1142  
  1143  STATE:
  1144  
  1145  module.child:
  1146    aws_instance.foo:
  1147      ID = baz
  1148  `
  1149  
  1150  const testTerraformPlanModuleVarStr = `
  1151  DIFF:
  1152  
  1153  CREATE: aws_instance.bar
  1154    foo:  "" => "2"
  1155    type: "" => "aws_instance"
  1156  
  1157  module.child:
  1158    CREATE: aws_instance.foo
  1159      num:  "" => "2"
  1160      type: "" => "aws_instance"
  1161  
  1162  STATE:
  1163  
  1164  <no state>
  1165  `
  1166  
  1167  const testTerraformPlanModuleVarComputedStr = `
  1168  DIFF:
  1169  
  1170  CREATE: aws_instance.bar
  1171    foo:  "" => "<computed>"
  1172    type: "" => "aws_instance"
  1173  
  1174  module.child:
  1175    CREATE: aws_instance.foo
  1176      foo:  "" => "<computed>"
  1177      type: "" => "aws_instance"
  1178  
  1179  STATE:
  1180  
  1181  <no state>
  1182  `
  1183  
  1184  const testTerraformPlanModuleVarIntStr = `
  1185  DIFF:
  1186  
  1187  module.child:
  1188    CREATE: aws_instance.foo
  1189      num:  "" => "2"
  1190      type: "" => "aws_instance"
  1191  
  1192  STATE:
  1193  
  1194  <no state>
  1195  `
  1196  
  1197  const testTerraformPlanOrphanStr = `
  1198  DIFF:
  1199  
  1200  DESTROY: aws_instance.baz
  1201  CREATE: aws_instance.foo
  1202    num:  "" => "2"
  1203    type: "" => "aws_instance"
  1204  
  1205  STATE:
  1206  
  1207  aws_instance.baz:
  1208    ID = bar
  1209  `
  1210  
  1211  const testTerraformPlanStateStr = `
  1212  DIFF:
  1213  
  1214  CREATE: aws_instance.bar
  1215    foo:  "" => "2"
  1216    type: "" => "aws_instance"
  1217  UPDATE: aws_instance.foo
  1218    num:  "" => "2"
  1219    type: "" => "aws_instance"
  1220  
  1221  STATE:
  1222  
  1223  aws_instance.foo:
  1224    ID = bar
  1225  `
  1226  
  1227  const testTerraformPlanTaintStr = `
  1228  DIFF:
  1229  
  1230  DESTROY/CREATE: aws_instance.bar
  1231    foo:  "" => "2"
  1232    type: "" => "aws_instance"
  1233  
  1234  STATE:
  1235  
  1236  aws_instance.bar: (1 tainted)
  1237    ID = <not created>
  1238    Tainted ID 1 = baz
  1239  aws_instance.foo:
  1240    ID = bar
  1241    num = 2
  1242  `
  1243  
  1244  const testTerraformPlanMultipleTaintStr = `
  1245  DIFF:
  1246  
  1247  DESTROY/CREATE: aws_instance.bar
  1248    foo:  "" => "2"
  1249    type: "" => "aws_instance"
  1250  
  1251  STATE:
  1252  
  1253  aws_instance.bar: (2 tainted)
  1254    ID = <not created>
  1255    Tainted ID 1 = baz
  1256    Tainted ID 2 = zip
  1257  aws_instance.foo:
  1258    ID = bar
  1259    num = 2
  1260  `
  1261  
  1262  const testTerraformPlanVarMultiCountOneStr = `
  1263  DIFF:
  1264  
  1265  CREATE: aws_instance.bar
  1266    foo:  "" => "2"
  1267    type: "" => "aws_instance"
  1268  CREATE: aws_instance.foo
  1269    num:  "" => "2"
  1270    type: "" => "aws_instance"
  1271  
  1272  STATE:
  1273  
  1274  <no state>
  1275  `
  1276  
  1277  const testTerraformPlanPathVarStr = `
  1278  DIFF:
  1279  
  1280  CREATE: aws_instance.foo
  1281    cwd:    "" => "%s/barpath"
  1282    module: "" => "%s/foopath"
  1283    root:   "" => "%s/barpath"
  1284    type:   "" => "aws_instance"
  1285  
  1286  STATE:
  1287  
  1288  <no state>
  1289  `
  1290  
  1291  const testTerraformPlanIgnoreChangesStr = `
  1292  DIFF:
  1293  
  1294  UPDATE: aws_instance.foo
  1295    type: "" => "aws_instance"
  1296  
  1297  STATE:
  1298  
  1299  aws_instance.foo:
  1300    ID = bar
  1301    ami = ami-abcd1234
  1302  `