Repository: chanzuckerberg/fogg
Pull request #544 (2021-02-22 23:26:00)

[feature] minimal pagerduty provider support

codecov[bot]: # [Codecov](https://codecov.io/gh/chanzuckerberg/fogg/pull/544?src=pr&el=h1) Report
> :exclamation: No coverage uploaded for pull request base (`main@67003ce`). [Click here to learn what that means](https://docs.codecov.io/docs/error-reference#section-missing-base-commit).
> The diff coverage is `n/a`.

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

```diff
@@           Coverage Diff           @@
##             main     #544   +/-   ##
=======================================
  Coverage        ?   55.75%           
=======================================
  Files           ?       21           
  Lines           ?     2014           
  Branches        ?        0           
=======================================
  Hits            ?     1123           
  Misses          ?      735           
  Partials        ?      156           
```



------

[Continue to review full report at Codecov](https://codecov.io/gh/chanzuckerberg/fogg/pull/544?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/544?src=pr&el=footer). Last update [67003ce...ccf1495](https://codecov.io/gh/chanzuckerberg/fogg/pull/544?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/config/v2/config.go b/config/v2/config.go
index 9b4c8ef1..dec70519 100644
--- a/config/v2/config.go
+++ b/config/v2/config.go
@@ -125,6 +125,7 @@ type Providers struct {
 	Heroku     *HerokuProvider     `yaml:"heroku,omitempty"`
 	Kubernetes *KubernetesProvider `yaml:"kubernetes,omitempty"`
 	Okta       *OktaProvider       `yaml:"okta,omitempty"`
+	Pagerduty  *PagerdutyProvider  `yaml:"pagerduty,omitempty"`
 	Sentry     *SentryProvider     `yaml:"sentry,omitempty"`
 	Snowflake  *SnowflakeProvider  `yaml:"snowflake,omitempty"`
 	Tfe        *TfeProvider        `yaml:"tfe,omitempty"`
@@ -194,6 +195,10 @@ type DatadogProvider struct {
 	Version *string `yaml:"version,omitempty"`
 }
 
+type PagerdutyProvider struct {
+	Version *string `yaml:"version,omitempty"`
+}
+
 type SentryProvider struct {
 	Version *string `yaml:"version,omitempty"`
 	BaseURL *string `yaml:"base_url,omitempty"`
@@ -448,6 +453,13 @@ func (c *Config) Generate(r *rand.Rand, size int) reflect.Value {
 		return nil
 	}
 
+	randPagerdutyProvider := func(r *rand.Rand) *PagerdutyProvider {
+		if r.Float32() < 0.5 {
+			return &PagerdutyProvider{}
+		}
+		return nil
+	}
+
 	randKubernetesProvider := func(r *rand.Rand) *KubernetesProvider {
 		if r.Float32() < 0.5 {
 			return &KubernetesProvider{}
@@ -494,6 +506,7 @@ func (c *Config) Generate(r *rand.Rand, size int) reflect.Value {
 				AWS:        randAWSProvider(r, s),
 				Bless:      randBlessProvider(r, s),
 				Datadog:    randDatadogProvider(r),
+				Pagerduty:  randPagerdutyProvider(r),
 				Grafana:    randGrafanaProvider(r),
 				Heroku:     randHerokuProvider(r),
 				Kubernetes: randKubernetesProvider(r),
diff --git a/config/v2/resolvers.go b/config/v2/resolvers.go
index adbf9257..46787fbd 100644
--- a/config/v2/resolvers.go
+++ b/config/v2/resolvers.go
@@ -309,6 +309,25 @@ func ResolveDatadogProvider(commons ...Common) *DatadogProvider {
 	return p
 }
 
+func ResolvePagerdutyProvider(commons ...Common) *PagerdutyProvider {
+	var p *PagerdutyProvider
+	for _, c := range commons {
+		if c.Providers == nil || c.Providers.Pagerduty == nil {
+			continue
+		}
+		p = c.Providers.Pagerduty
+	}
+
+	version := lastNonNil(PagerdutyProviderVersionGetter, commons...)
+
+	if version != nil {
+		return &PagerdutyProvider{
+			Version: version,
+		}
+	}
+	return p
+}
+
 func ResolveSentryProvider(commons ...Common) *SentryProvider {
 	var p *SentryProvider
 	for _, c := range commons {
@@ -705,6 +724,13 @@ func DatadogProviderVersionGetter(comm Common) *string {
 	return comm.Providers.Datadog.Version
 }
 
+func PagerdutyProviderVersionGetter(comm Common) *string {
+	if comm.Providers == nil || comm.Providers.Pagerduty == nil {
+		return nil
+	}
+	return comm.Providers.Pagerduty.Version
+}
+
 func SentryProviderVersionGetter(comm Common) *string {
 	if comm.Providers == nil || comm.Providers.Sentry == nil {
 		return nil
diff --git a/plan/plan.go b/plan/plan.go
index 81e9f341..5dc2ef90 100644
--- a/plan/plan.go
+++ b/plan/plan.go
@@ -625,7 +625,7 @@ func resolveComponentCommon(commons ...v2.Common) ComponentCommon {
 	if herokuConfig != nil {
 		herokuPlan = &HerokuProvider{}
 
-		providerVersions["herok"] = ProviderVersion{
+		providerVersions["heroku"] = ProviderVersion{
 			Source:  "heroku/heroku",
 			Version: herokuConfig.Version,
 		}
@@ -642,6 +642,14 @@ func resolveComponentCommon(commons ...v2.Common) ComponentCommon {
 		}
 	}
 
+	pagerdutyConfig := v2.ResolvePagerdutyProvider(commons...)
+	if pagerdutyConfig != nil {
+		providerVersions["pagerduty"] = ProviderVersion{
+			Source:  "pagerduty/pagerduty",
+			Version: pagerdutyConfig.Version,
+		}
+	}
+
 	var sentryPlan *SentryProvider
 	sentryConfig := v2.ResolveSentryProvider(commons...)
 	if sentryConfig != nil {


Test patch:
diff --git a/testdata/v2_full_yaml/terraform/envs/prod/hero/fogg.tf b/testdata/v2_full_yaml/terraform/envs/prod/hero/fogg.tf
index 5880e107..4bceb60e 100644
--- a/testdata/v2_full_yaml/terraform/envs/prod/hero/fogg.tf
+++ b/testdata/v2_full_yaml/terraform/envs/prod/hero/fogg.tf
@@ -49,7 +49,7 @@ terraform {
 
     }
 
-    herok = {
+    heroku = {
       source = "heroku/heroku"
 
     }