Repository: chanzuckerberg/fogg
Pull request #326 (2019-07-22 22:57:22)

[fix] Enable fogg.tf remote state data source for accounts without an aws provider
### Test Plan
unittests

codecov[bot]: # [Codecov](https://codecov.io/gh/chanzuckerberg/fogg/pull/326?src=pr&el=h1) Report
> Merging [#326](https://codecov.io/gh/chanzuckerberg/fogg/pull/326?src=pr&el=desc) into [master](https://codecov.io/gh/chanzuckerberg/fogg/commit/80cbcabc7bdbfcb969df774e07ff407d0b2c2083?src=pr&el=desc) will **increase** coverage by `0.02%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/chanzuckerberg/fogg/pull/326/graphs/tree.svg?width=650&token=57DhtZ7g2A&height=150&src=pr)](https://codecov.io/gh/chanzuckerberg/fogg/pull/326?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master     #326      +/-   ##
==========================================
+ Coverage   80.15%   80.17%   +0.02%     
==========================================
  Files          20       20              
  Lines        1784     1786       +2     
==========================================
+ Hits         1430     1432       +2     
  Misses        222      222              
  Partials      132      132
```


| [Impacted Files](https://codecov.io/gh/chanzuckerberg/fogg/pull/326?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [plan/plan.go](https://codecov.io/gh/chanzuckerberg/fogg/pull/326/diff?src=pr&el=tree#diff-cGxhbi9wbGFuLmdv) | `92.22% <100%> (+0.08%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/chanzuckerberg/fogg/pull/326?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/chanzuckerberg/fogg/pull/326?src=pr&el=footer). Last update [80cbcab...eeb1213](https://codecov.io/gh/chanzuckerberg/fogg/pull/326?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

codecov[bot]: # [Codecov](https://codecov.io/gh/chanzuckerberg/fogg/pull/326?src=pr&el=h1) Report
> Merging [#326](https://codecov.io/gh/chanzuckerberg/fogg/pull/326?src=pr&el=desc) into [master](https://codecov.io/gh/chanzuckerberg/fogg/commit/80cbcabc7bdbfcb969df774e07ff407d0b2c2083?src=pr&el=desc) will **increase** coverage by `0.02%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/chanzuckerberg/fogg/pull/326/graphs/tree.svg?width=650&token=57DhtZ7g2A&height=150&src=pr)](https://codecov.io/gh/chanzuckerberg/fogg/pull/326?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master     #326      +/-   ##
==========================================
+ Coverage   80.15%   80.17%   +0.02%     
==========================================
  Files          20       20              
  Lines        1784     1786       +2     
==========================================
+ Hits         1430     1432       +2     
  Misses        222      222              
  Partials      132      132
```


| [Impacted Files](https://codecov.io/gh/chanzuckerberg/fogg/pull/326?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [plan/plan.go](https://codecov.io/gh/chanzuckerberg/fogg/pull/326/diff?src=pr&el=tree#diff-cGxhbi9wbGFuLmdv) | `92.22% <100%> (+0.08%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/chanzuckerberg/fogg/pull/326?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/chanzuckerberg/fogg/pull/326?src=pr&el=footer). Last update [80cbcab...eeb1213](https://codecov.io/gh/chanzuckerberg/fogg/pull/326?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/plan/plan.go b/plan/plan.go
index 185366e3..1a86c855 100644
--- a/plan/plan.go
+++ b/plan/plan.go
@@ -114,8 +114,8 @@ type Module struct {
 type Account struct {
 	ComponentCommon `json:",inline" yaml:",inline"`
 
-	AllAccounts map[string]json.Number `yaml:"all_accounts"`
-	AccountName string                 `yaml:"account_name"`
+	AllAccounts map[string]*json.Number `yaml:"all_accounts"`
+	AccountName string                  `yaml:"account_name"`
 	Global      *Component
 }
 
@@ -195,7 +195,6 @@ func (p *Plan) buildAccounts(c *v2.Config) map[string]Account {
 		accountPlan.AllAccounts = resolveAccounts(c.Accounts)
 		accountPlan.PathToRepoRoot = "../../../"
 		accountPlan.Global = &p.Global
-
 		accountPlans[name] = accountPlan
 	}
 
@@ -408,12 +407,14 @@ func resolveExtraVars(vars ...map[string]string) map[string]string {
 	return resolved
 }
 
-func resolveAccounts(accounts map[string]v2.Account) map[string]json.Number {
-	a := make(map[string]json.Number)
+func resolveAccounts(accounts map[string]v2.Account) map[string]*json.Number {
+	a := make(map[string]*json.Number)
 	for name, account := range accounts {
-		if account.Providers != nil && account.Providers.AWS != nil && account.Providers.AWS.AccountID != nil {
-			a[name] = *account.Providers.AWS.AccountID
+		var acctID *json.Number
+		if account.Providers != nil && account.Providers.AWS != nil {
+			acctID = account.Providers.AWS.AccountID
 		}
+		a[name] = acctID
 	}
 	return a
 }


Test patch:
diff --git a/plan/plan_test.go b/plan/plan_test.go
index 728414d1..76d7a2d0 100644
--- a/plan/plan_test.go
+++ b/plan/plan_test.go
@@ -9,8 +9,8 @@ import (
 	v2 "github.com/chanzuckerberg/fogg/config/v2"
 	"github.com/chanzuckerberg/fogg/util"
 	"github.com/sirupsen/logrus"
-	"github.com/stretchr/testify/assert"
 	"github.com/spf13/afero"
+	"github.com/stretchr/testify/assert"
 )
 
 func init() {
@@ -57,7 +57,8 @@ func TestResolveAccounts(t *testing.T) {
 
 	other := resolveAccounts(accounts)
 	assert.NotNil(t, other)
-	assert.Equal(t, map[string]json.Number{"bar": bar, "foo": foo}, other)
+	var nilJsonNumber *json.Number
+	assert.Equal(t, map[string]*json.Number{"bar": &bar, "foo": &foo, "baz": nilJsonNumber}, other)
 }
 
 func TestPlanBasicV1(t *testing.T) {
@@ -159,7 +160,7 @@ func TestPlanBasicV2Yaml(t *testing.T) {
 	a.NoError(err)
 	err = afero.WriteFile(fs, "fogg.yml", b, 0644)
 	a.NoError(err)
-	c2, err := v2.ReadConfig(fs, b, "fogg.yml" )
+	c2, err := v2.ReadConfig(fs, b, "fogg.yml")
 	assert.Nil(t, err)
 
 	w, err := c2.Validate()
diff --git a/testdata/v2_no_aws_provider/terraform/accounts/bar/fogg.tf b/testdata/v2_no_aws_provider/terraform/accounts/bar/fogg.tf
index 37bc9a2e..04ed7213 100644
--- a/testdata/v2_no_aws_provider/terraform/accounts/bar/fogg.tf
+++ b/testdata/v2_no_aws_provider/terraform/accounts/bar/fogg.tf
@@ -45,3 +45,14 @@ data "terraform_remote_state" "global" {
     profile = "profile"
   }
 }
+
+data "terraform_remote_state" "foo" {
+  backend = "s3"
+
+  config = {
+    bucket  = "buck"
+    key     = "terraform/proj/accounts/foo.tfstate"
+    region  = "us-west-2"
+    profile = "profile"
+  }
+}
diff --git a/testdata/v2_no_aws_provider/terraform/accounts/foo/fogg.tf b/testdata/v2_no_aws_provider/terraform/accounts/foo/fogg.tf
index b248e75d..cba9359e 100644
--- a/testdata/v2_no_aws_provider/terraform/accounts/foo/fogg.tf
+++ b/testdata/v2_no_aws_provider/terraform/accounts/foo/fogg.tf
@@ -45,3 +45,14 @@ data "terraform_remote_state" "global" {
     profile = "profile"
   }
 }
+
+data "terraform_remote_state" "bar" {
+  backend = "s3"
+
+  config = {
+    bucket  = "buck"
+    key     = "terraform/proj/accounts/bar.tfstate"
+    region  = "us-west-2"
+    profile = "profile"
+  }
+}