mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-16 18:35:03 -06:00
Merge pull request #579 from svanharmelen/f-update-heroku-provider
providers/heroku: fixed acc tests and updated the provider schema to use a DefaultFunc
This commit is contained in:
commit
2492708eaf
@ -3,29 +3,18 @@ package heroku
|
|||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
|
||||||
|
|
||||||
"github.com/cyberdelia/heroku-go/v3"
|
"github.com/cyberdelia/heroku-go/v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
APIKey string `mapstructure:"api_key"`
|
Email string
|
||||||
Email string `mapstructure:"email"`
|
APIKey string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Client() returns a new Service for accessing Heroku.
|
// Client() returns a new Service for accessing Heroku.
|
||||||
//
|
//
|
||||||
func (c *Config) Client() (*heroku.Service, error) {
|
func (c *Config) Client() (*heroku.Service, error) {
|
||||||
|
|
||||||
// If we have env vars set (like in the acc) tests,
|
|
||||||
// we need to override the values passed in here.
|
|
||||||
if v := os.Getenv("HEROKU_EMAIL"); v != "" {
|
|
||||||
c.Email = v
|
|
||||||
}
|
|
||||||
if v := os.Getenv("HEROKU_API_KEY"); v != "" {
|
|
||||||
c.APIKey = v
|
|
||||||
}
|
|
||||||
|
|
||||||
service := heroku.NewService(&http.Client{
|
service := heroku.NewService(&http.Client{
|
||||||
Transport: &heroku.Transport{
|
Transport: &heroku.Transport{
|
||||||
Username: c.Email,
|
Username: c.Email,
|
||||||
|
@ -2,10 +2,10 @@ package heroku
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
|
"os"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform/helper/schema"
|
"github.com/hashicorp/terraform/helper/schema"
|
||||||
"github.com/hashicorp/terraform/terraform"
|
"github.com/hashicorp/terraform/terraform"
|
||||||
"github.com/mitchellh/mapstructure"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Provider returns a terraform.ResourceProvider.
|
// Provider returns a terraform.ResourceProvider.
|
||||||
@ -13,13 +13,15 @@ func Provider() terraform.ResourceProvider {
|
|||||||
return &schema.Provider{
|
return &schema.Provider{
|
||||||
Schema: map[string]*schema.Schema{
|
Schema: map[string]*schema.Schema{
|
||||||
"email": &schema.Schema{
|
"email": &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
|
DefaultFunc: envDefaultFunc("HEROKU_EMAIL"),
|
||||||
},
|
},
|
||||||
|
|
||||||
"api_key": &schema.Schema{
|
"api_key": &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
|
DefaultFunc: envDefaultFunc("HEROKU_API_KEY"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -34,11 +36,20 @@ func Provider() terraform.ResourceProvider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func envDefaultFunc(k string) schema.SchemaDefaultFunc {
|
||||||
|
return func() (interface{}, error) {
|
||||||
|
if v := os.Getenv(k); v != "" {
|
||||||
|
return v, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func providerConfigure(d *schema.ResourceData) (interface{}, error) {
|
func providerConfigure(d *schema.ResourceData) (interface{}, error) {
|
||||||
var config Config
|
config := Config{
|
||||||
configRaw := d.Get("").(map[string]interface{})
|
Email: d.Get("email").(string),
|
||||||
if err := mapstructure.Decode(configRaw, &config); err != nil {
|
APIKey: d.Get("api_key").(string),
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Println("[INFO] Initializing Heroku client")
|
log.Println("[INFO] Initializing Heroku client")
|
||||||
|
@ -4,7 +4,6 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform/config"
|
|
||||||
"github.com/hashicorp/terraform/helper/schema"
|
"github.com/hashicorp/terraform/helper/schema"
|
||||||
"github.com/hashicorp/terraform/terraform"
|
"github.com/hashicorp/terraform/terraform"
|
||||||
)
|
)
|
||||||
@ -29,39 +28,6 @@ func TestProvider_impl(t *testing.T) {
|
|||||||
var _ terraform.ResourceProvider = Provider()
|
var _ terraform.ResourceProvider = Provider()
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestProviderConfigure(t *testing.T) {
|
|
||||||
var expectedKey string
|
|
||||||
var expectedEmail string
|
|
||||||
|
|
||||||
if v := os.Getenv("HEROKU_EMAIL"); v != "" {
|
|
||||||
expectedEmail = v
|
|
||||||
} else {
|
|
||||||
expectedEmail = "foo"
|
|
||||||
}
|
|
||||||
|
|
||||||
if v := os.Getenv("HEROKU_API_KEY"); v != "" {
|
|
||||||
expectedKey = v
|
|
||||||
} else {
|
|
||||||
expectedKey = "foo"
|
|
||||||
}
|
|
||||||
|
|
||||||
raw := map[string]interface{}{
|
|
||||||
"api_key": expectedKey,
|
|
||||||
"email": expectedEmail,
|
|
||||||
}
|
|
||||||
|
|
||||||
rawConfig, err := config.NewRawConfig(raw)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
rp := Provider()
|
|
||||||
err = rp.Configure(terraform.NewResourceConfig(rawConfig))
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %s", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func testAccPreCheck(t *testing.T) {
|
func testAccPreCheck(t *testing.T) {
|
||||||
if v := os.Getenv("HEROKU_EMAIL"); v == "" {
|
if v := os.Getenv("HEROKU_EMAIL"); v == "" {
|
||||||
t.Fatal("HEROKU_EMAIL must be set for acceptance tests")
|
t.Fatal("HEROKU_EMAIL must be set for acceptance tests")
|
||||||
|
@ -128,7 +128,7 @@ func testAccCheckHerokuAppAttributes(app *heroku.App) resource.TestCheckFunc {
|
|||||||
return fmt.Errorf("Bad region: %s", app.Region.Name)
|
return fmt.Errorf("Bad region: %s", app.Region.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
if app.Stack.Name != "cedar" {
|
if app.Stack.Name != "cedar-14" {
|
||||||
return fmt.Errorf("Bad stack: %s", app.Stack.Name)
|
return fmt.Errorf("Bad stack: %s", app.Stack.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user