Repository: chanzuckerberg/fogg
Pull request #739 (2022-09-23 19:37:30)

feat: make auth0 provider configurable
### Summary
This PR makes the auth0 provider configurable so that the user can change the host based on their provider version. This should allow you to do something like:

~~~
dev:
    providers:
      auth0:
        version: 0.37.1   
        source: "auth0/auth0". 
        domain: mydomain.com
~~~

### Test Plan
* auth0_config testdata section



Patch:
diff --git a/config/v2/config.go b/config/v2/config.go
index d61c0ed1..22e479a0 100644
--- a/config/v2/config.go
+++ b/config/v2/config.go
@@ -163,6 +163,7 @@ type CommonProvider struct {
 type Auth0Provider struct {
 	Version *string `yaml:"version,omitempty"`
 	Domain  *string `yaml:"domain,omitempty"`
+	Source  *string `yaml:"source,omitempty"`
 }
 
 // OktaProvider is an okta provider
diff --git a/config/v2/resolvers.go b/config/v2/resolvers.go
index f05c00e7..dc410a80 100644
--- a/config/v2/resolvers.go
+++ b/config/v2/resolvers.go
@@ -80,7 +80,7 @@ func ResolveStringMap(getter func(Common) map[string]string, commons ...Common)
 }
 
 func ResolveAuth0Provider(commons ...Common) *Auth0Provider {
-	var domain, version *string
+	var domain, version, source *string
 	for _, c := range commons {
 		if c.Providers == nil || c.Providers.Auth0 == nil {
 			continue
@@ -92,10 +92,14 @@ func ResolveAuth0Provider(commons ...Common) *Auth0Provider {
 		if c.Providers.Auth0.Domain != nil {
 			domain = c.Providers.Auth0.Domain
 		}
+
+		if c.Providers.Auth0.Source != nil {
+			source = c.Providers.Auth0.Source
+		}
 	}
 
 	if domain != nil && version != nil {
-		return &Auth0Provider{Version: version, Domain: domain}
+		return &Auth0Provider{Version: version, Domain: domain, Source: source}
 	}
 	return nil
 }
diff --git a/plan/plan.go b/plan/plan.go
index a0450aa2..098208b0 100644
--- a/plan/plan.go
+++ b/plan/plan.go
@@ -731,8 +731,12 @@ func resolveComponentCommon(commons ...v2.Common) ComponentCommon {
 			Domain: *auth0Config.Domain,
 		}
 
+		defaultSource := "alexkappa/auth0"
+		if auth0Config.Source == nil {
+			auth0Config.Source = &defaultSource
+		}
 		providerVersions["auth0"] = ProviderVersion{
-			Source:  "auth0/auth0",
+			Source:  *auth0Config.Source,
 			Version: auth0Config.Version,
 		}
 	}


Test patch:
diff --git a/testdata/auth0_provider_yaml/fogg.yml b/testdata/auth0_provider_yaml/fogg.yml
index 4c8aa63d..fd203ba4 100644
--- a/testdata/auth0_provider_yaml/fogg.yml
+++ b/testdata/auth0_provider_yaml/fogg.yml
@@ -1,29 +1,35 @@
 {
-    "version": 2,
-    "defaults": {
-        "providers": {
-            "auth0": {
-                "domain": "adomain",
-                "version": "aversion"
-            }
+  "version": 2,
+  "defaults":
+    {
+      "providers":
+        {
+          "auth0":
+            {
+              "domain": "adomain",
+              "version": "aversion"
+            },
         },
-        "backend": {
-            "bucket": "bucket",
-            "region": "region",
-            "profile": "foofoo"
-        },
-        "project": "foofoo",
-        "owner": "foo@example.com",
-        "terraform_version": "1.1.1"
+      "backend":
+        { "bucket": "bucket", "region": "region", "profile": "foofoo" },
+      "project": "foofoo",
+      "owner": "foo@example.com",
+      "terraform_version": "1.1.1",
     },
-    "accounts": {
-        "foo": {}
+  "accounts":
+    {
+      "foo":
+        {
+          "providers":
+            {
+              "auth0":
+                {
+                  "domain": "adomain",
+                  "version": "aversion",
+                  "source": 'blah/blah',
+                },
+            },
+        },
     },
-    "envs": {
-        "bar": {
-            "components": {
-                "bam": {}
-            }
-        }
-    }
+  "envs": { "bar": { "components": { "bam": {} } } },
 }
diff --git a/testdata/auth0_provider_yaml/terraform/accounts/foo/fogg.tf b/testdata/auth0_provider_yaml/terraform/accounts/foo/fogg.tf
index 0bd68ea0..e56c6a2a 100644
--- a/testdata/auth0_provider_yaml/terraform/accounts/foo/fogg.tf
+++ b/testdata/auth0_provider_yaml/terraform/accounts/foo/fogg.tf
@@ -35,7 +35,7 @@ terraform {
     }
 
     auth0 = {
-      source = "auth0/auth0"
+      source = "blah/blah"
 
       version = "aversion"
 
diff --git a/testdata/auth0_provider_yaml/terraform/envs/bar/bam/fogg.tf b/testdata/auth0_provider_yaml/terraform/envs/bar/bam/fogg.tf
index dcef29ff..8ec3c72c 100644
--- a/testdata/auth0_provider_yaml/terraform/envs/bar/bam/fogg.tf
+++ b/testdata/auth0_provider_yaml/terraform/envs/bar/bam/fogg.tf
@@ -35,7 +35,7 @@ terraform {
     }
 
     auth0 = {
-      source = "auth0/auth0"
+      source = "alexkappa/auth0"
 
       version = "aversion"
 
diff --git a/testdata/auth0_provider_yaml/terraform/global/fogg.tf b/testdata/auth0_provider_yaml/terraform/global/fogg.tf
index 53c2e09e..898ce594 100644
--- a/testdata/auth0_provider_yaml/terraform/global/fogg.tf
+++ b/testdata/auth0_provider_yaml/terraform/global/fogg.tf
@@ -35,7 +35,7 @@ terraform {
     }
 
     auth0 = {
-      source = "auth0/auth0"
+      source = "alexkappa/auth0"
 
       version = "aversion"