Skip to content

Commit

Permalink
Merge pull request #302 from aqche/support_heroku_cert
Browse files Browse the repository at this point in the history
Add support for Heroku Cert
  • Loading branch information
sergeylanzman committed Nov 26, 2019
2 parents 3686f92 + e6886e2 commit 4754e1d
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,8 @@ List of supported Heroku resources:
* `heroku_app_webhook`
* `build`
* `heroku_build`
* `cert`
* `heroku_cert`
* `domain`
* `heroku_domain`
* `drain`
Expand Down
58 changes: 58 additions & 0 deletions providers/heroku/cert.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright 2019 The Terraformer Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package heroku

import (
"context"
"log"

"github.com/GoogleCloudPlatform/terraformer/terraform_utils"
heroku "github.com/heroku/heroku-go/v5"
)

type CertGenerator struct {
HerokuService
}

func (g CertGenerator) createResources(svc *heroku.Service, appList []heroku.App) []terraform_utils.Resource {
var resources []terraform_utils.Resource
for _, app := range appList {
output, err := svc.SSLEndpointList(context.TODO(), app.ID, &heroku.ListRange{Field: "id"})
if err != nil {
log.Println(err)
}
for _, sslEndpoint := range output {
resources = append(resources, terraform_utils.NewResource(
sslEndpoint.ID,
sslEndpoint.Name,
"heroku_cert",
"heroku",
map[string]string{"app": app.Name},
[]string{},
map[string]interface{}{}))
}
}
return resources
}

func (g *CertGenerator) InitResources() error {
svc := g.generateService()
output, err := svc.AppList(context.TODO(), &heroku.ListRange{Field: "id"})
if err != nil {
return err
}
g.Resources = g.createResources(svc, output)
return nil
}
1 change: 1 addition & 0 deletions providers/heroku/heroku_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ func (p *HerokuProvider) GetSupportedService() map[string]terraform_utils.Servic
"app_feature": &AppFeatureGenerator{},
"app_webhook": &AppWebhookGenerator{},
"build": &BuildGenerator{},
"cert": &CertGenerator{},
"domain": &DomainGenerator{},
"drain": &DrainGenerator{},
"formation": &FormationGenerator{},
Expand Down

0 comments on commit 4754e1d

Please sign in to comment.