github.com/danrjohnson/terraform@v0.7.0-rc2.0.20160627135212-d0fc1fa086ff/terraform/terraform_test.go (about)

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