Repository: chanzuckerberg/fogg
Pull request #644 (2022-05-05 17:35:47)

fix: assert provider getting into fogg
### Summary
I made an error in the assert provider and forgot to add the assert provider to the templates. This PR fixes that.

### Test Plan
Say unittests, or list out steps to verify changes.

### References
(Optional) Additional links to provide more context.



Patch:
diff --git a/config/v2/config.go b/config/v2/config.go
index 88e7df10..70724702 100644
--- a/config/v2/config.go
+++ b/config/v2/config.go
@@ -135,7 +135,6 @@ type Providers struct {
 
 type AssertProvider struct {
 	Version *string `yaml:"version,omitempty"`
-	Domain  *string `yaml:"domain,omitempty"`
 }
 
 // CommonProvider encapsulates common properties across providers
diff --git a/config/v2/resolvers.go b/config/v2/resolvers.go
index 9d6b8982..bd12aac2 100644
--- a/config/v2/resolvers.go
+++ b/config/v2/resolvers.go
@@ -101,7 +101,7 @@ func ResolveAuth0Provider(commons ...Common) *Auth0Provider {
 }
 
 func ResolveAssertProvider(commons ...Common) *AssertProvider {
-	var domain, version *string
+	var version *string
 	for _, c := range commons {
 		if c.Providers == nil || c.Providers.Assert == nil {
 			continue
@@ -109,14 +109,10 @@ func ResolveAssertProvider(commons ...Common) *AssertProvider {
 		if c.Providers.Assert.Version != nil {
 			version = c.Providers.Assert.Version
 		}
-
-		if c.Providers.Assert.Domain != nil {
-			domain = c.Providers.Assert.Domain
-		}
 	}
 
-	if domain != nil && version != nil {
-		return &AssertProvider{Version: version, Domain: domain}
+	if version != nil {
+		return &AssertProvider{Version: version}
 	}
 	return nil
 }
diff --git a/go.mod b/go.mod
index a3a9187c..eb6c88aa 100644
--- a/go.mod
+++ b/go.mod
@@ -14,7 +14,7 @@ require (
 	github.com/fatih/color v1.10.0
 	github.com/go-errors/errors v1.1.1
 	github.com/google/go-github/v27 v27.0.6
-	github.com/hashicorp/go-getter v1.5.2
+	github.com/hashicorp/go-getter v1.5.11
 	github.com/hashicorp/go-multierror v1.1.1
 	github.com/hashicorp/go-version v1.2.1
 	github.com/hashicorp/hcl/v2 v2.12.0
@@ -58,7 +58,7 @@ require (
 	github.com/google/uuid v1.1.1 // indirect
 	github.com/googleapis/gax-go/v2 v2.0.5 // indirect
 	github.com/hashicorp/errwrap v1.0.0 // indirect
-	github.com/hashicorp/go-cleanhttp v0.5.1 // indirect
+	github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
 	github.com/hashicorp/go-retryablehttp v0.6.6 // indirect
 	github.com/hashicorp/go-safetemp v1.0.0 // indirect
 	github.com/hashicorp/go-uuid v1.0.2 // indirect
diff --git a/go.sum b/go.sum
index 5588cd7f..1aa1da95 100644
--- a/go.sum
+++ b/go.sum
@@ -403,9 +403,13 @@ github.com/hashicorp/go-checkpoint v0.5.0/go.mod h1:7nfLNL10NsxqO4iWuW6tWW0HjZuD
 github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
 github.com/hashicorp/go-cleanhttp v0.5.1 h1:dH3aiDG9Jvb5r5+bYHsikaOUIpcM0xvgMXVoDkXMzJM=
 github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
+github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ=
+github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48=
 github.com/hashicorp/go-getter v1.5.1/go.mod h1:a7z7NPPfNQpJWcn4rSWFtdrSldqLdLPEF3d8nFMsSLM=
 github.com/hashicorp/go-getter v1.5.2 h1:XDo8LiAcDisiqZdv0TKgz+HtX3WN7zA2JD1R1tjsabE=
 github.com/hashicorp/go-getter v1.5.2/go.mod h1:orNH3BTYLu/fIxGIdLjLoAJHWMDQ/UKQr5O4m3iBuoo=
+github.com/hashicorp/go-getter v1.5.11 h1:wioTuNmaBU3IE9vdFtFMcmZWj0QzLc6DYaP6sNe5onY=
+github.com/hashicorp/go-getter v1.5.11/go.mod h1:9i48BP6wpWweI/0/+FBjqLrp9S8XtwUGjiu0QkWHEaY=
 github.com/hashicorp/go-hclog v0.0.0-20180709165350-ff2cf002a8dd/go.mod h1:9bjs9uLqI8l75knNv3lV1kA55veR+WUPSiKIWcQHudI=
 github.com/hashicorp/go-hclog v0.9.2 h1:CG6TE5H9/JXsFWJCfoIVpKFIkFe6ysEuHirp4DxCsHI=
 github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ=
diff --git a/plan/plan.go b/plan/plan.go
index 6bd6f35b..87d65d24 100644
--- a/plan/plan.go
+++ b/plan/plan.go
@@ -121,6 +121,7 @@ func (c CIComponent) generateCIConfig(
 }
 
 type ProviderConfiguration struct {
+	Assert                 *AssertProvider     `yaml:"assert"`
 	Auth0                  *Auth0Provider      `yaml:"auth0"`
 	AWS                    *AWSProvider        `yaml:"aws"`
 	AWSAdditionalProviders []AWSProvider       `yaml:"aws_regional_providers"`
@@ -208,6 +209,10 @@ type Auth0Provider struct {
 	Domain string `yaml:"domain,omitempty"`
 }
 
+type AssertProvider struct {
+	Version string `yaml:"version,omitempty"`
+}
+
 //SnowflakeProvider represents Snowflake DB provider configuration
 type SnowflakeProvider struct {
 	Account string `yaml:"account,omitempty"`
@@ -631,11 +636,11 @@ func resolveComponentCommon(commons ...v2.Common) ComponentCommon {
 		}
 	}
 
-	var assertPlan *v2.AssertProvider
+	var assertPlan *AssertProvider
 	assertConfig := v2.ResolveAssertProvider(commons...)
 	if assertConfig != nil {
-		assertPlan = &v2.AssertProvider{
-			Domain: assertPlan.Domain,
+		assertPlan = &AssertProvider{
+			Version: *assertConfig.Version,
 		}
 
 		providerVersions["assert"] = ProviderVersion{
@@ -885,6 +890,7 @@ func resolveComponentCommon(commons ...v2.Common) ComponentCommon {
 	return ComponentCommon{
 		Backend: backend,
 		ProviderConfiguration: ProviderConfiguration{
+			Assert:                 assertPlan,
 			Auth0:                  auth0Plan,
 			AWS:                    awsPlan,
 			AWSAdditionalProviders: additionalProviders,
diff --git a/templates/templates/common/assert_provider.tmpl b/templates/templates/common/assert_provider.tmpl
new file mode 100644
index 00000000..eae7e301
--- /dev/null
+++ b/templates/templates/common/assert_provider.tmpl
@@ -0,0 +1,5 @@
+{{ define "assert" }}
+provider "assert" {
+  version = "{{ .Version }}"
+}
+{{ end }}
diff --git a/templates/templates/component/terraform/fogg.tf.tmpl b/templates/templates/component/terraform/fogg.tf.tmpl
index 8271d648..89a88108 100644
--- a/templates/templates/component/terraform/fogg.tf.tmpl
+++ b/templates/templates/component/terraform/fogg.tf.tmpl
@@ -14,6 +14,10 @@
   {{ template "snowflake_provider" .ProviderConfiguration.Snowflake }}
 {{ end }}
 
+{{ if .ProviderConfiguration.Assert }}
+  {{ template "assert" .ProviderConfiguration.Assert }}
+{{ end }}
+
 {{ if .ProviderConfiguration.Bless }}
   {{ template "bless_provider" .ProviderConfiguration.Bless }}
 {{ end }}


Test patch:
diff --git a/testdata/bless_provider_yaml/fogg.yml b/testdata/bless_provider_yaml/fogg.yml
index 7fe5a84d..5f62b81a 100644
--- a/testdata/bless_provider_yaml/fogg.yml
+++ b/testdata/bless_provider_yaml/fogg.yml
@@ -8,10 +8,12 @@ defaults:
   owner: foo@example.com
   project: foofoo
   providers:
+    assert:
+      version: 0.0.1
     bless:
       additional_regions:
-      - a
-      - b
+        - a
+        - b
       aws_profile: foofoofoo
       aws_region: bar
       version: 0.0.0
diff --git a/testdata/bless_provider_yaml/terraform/accounts/foo/fogg.tf b/testdata/bless_provider_yaml/terraform/accounts/foo/fogg.tf
index 36c5a09e..10731ae5 100644
--- a/testdata/bless_provider_yaml/terraform/accounts/foo/fogg.tf
+++ b/testdata/bless_provider_yaml/terraform/accounts/foo/fogg.tf
@@ -1,6 +1,10 @@
 # Auto-generated by fogg. Do not edit
 # Make improvements in fogg, so that everyone can benefit.
 
+provider "assert" {
+  version = "0.0.1"
+}
+
 provider "bless" {
   region  = "bar"
   profile = "foofoofoo"
@@ -43,7 +47,7 @@ terraform {
     assert = {
       source = "bwoznicki/assert"
 
-      version = "~> 0.0.1"
+      version = "0.0.1"
 
     }
 
diff --git a/testdata/bless_provider_yaml/terraform/envs/bar/bam/fogg.tf b/testdata/bless_provider_yaml/terraform/envs/bar/bam/fogg.tf
index 96196436..510cd5b8 100644
--- a/testdata/bless_provider_yaml/terraform/envs/bar/bam/fogg.tf
+++ b/testdata/bless_provider_yaml/terraform/envs/bar/bam/fogg.tf
@@ -1,6 +1,10 @@
 # Auto-generated by fogg. Do not edit
 # Make improvements in fogg, so that everyone can benefit.
 
+provider "assert" {
+  version = "0.0.1"
+}
+
 provider "bless" {
   region  = "bar"
   profile = "foofoofoo"
@@ -43,7 +47,7 @@ terraform {
     assert = {
       source = "bwoznicki/assert"
 
-      version = "~> 0.0.1"
+      version = "0.0.1"
 
     }
 
diff --git a/testdata/bless_provider_yaml/terraform/global/fogg.tf b/testdata/bless_provider_yaml/terraform/global/fogg.tf
index c7b6dc4d..cac70d73 100644
--- a/testdata/bless_provider_yaml/terraform/global/fogg.tf
+++ b/testdata/bless_provider_yaml/terraform/global/fogg.tf
@@ -1,6 +1,10 @@
 # Auto-generated by fogg. Do not edit
 # Make improvements in fogg, so that everyone can benefit.
 
+provider "assert" {
+  version = "0.0.1"
+}
+
 provider "bless" {
   region  = "bar"
   profile = "foofoofoo"
@@ -43,7 +47,7 @@ terraform {
     assert = {
       source = "bwoznicki/assert"
 
-      version = "~> 0.0.1"
+      version = "0.0.1"
 
     }