2014-12-10 00:06:52 +01:00
|
|
|
package atlas
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/hashicorp/atlas-go/v1"
|
|
|
|
"github.com/hashicorp/terraform/helper/schema"
|
|
|
|
"github.com/hashicorp/terraform/terraform"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
// defaultAtlasServer is the default endpoint for Atlas if
|
|
|
|
// none is specified.
|
|
|
|
defaultAtlasServer = "https://atlas.hashicorp.com"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Provider returns a terraform.ResourceProvider.
|
|
|
|
func Provider() terraform.ResourceProvider {
|
|
|
|
return &schema.Provider{
|
|
|
|
Schema: map[string]*schema.Schema{
|
2014-12-10 03:43:56 +01:00
|
|
|
"token": &schema.Schema{
|
2014-12-10 00:06:52 +01:00
|
|
|
Type: schema.TypeString,
|
2014-12-10 03:43:56 +01:00
|
|
|
Required: true,
|
2015-01-16 18:22:09 +01:00
|
|
|
DefaultFunc: schema.EnvDefaultFunc("ATLAS_TOKEN", nil),
|
2014-12-10 03:43:56 +01:00
|
|
|
Description: descriptions["token"],
|
2014-12-10 00:06:52 +01:00
|
|
|
},
|
|
|
|
|
2014-12-10 03:43:56 +01:00
|
|
|
"address": &schema.Schema{
|
2014-12-10 00:06:52 +01:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
2015-01-16 18:22:09 +01:00
|
|
|
DefaultFunc: schema.EnvDefaultFunc("ATLAS_ADDRESS", defaultAtlasServer),
|
2014-12-10 03:43:56 +01:00
|
|
|
Description: descriptions["address"],
|
2014-12-10 00:06:52 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
ResourcesMap: map[string]*schema.Resource{
|
|
|
|
"atlas_artifact": resourceArtifact(),
|
|
|
|
},
|
|
|
|
|
|
|
|
ConfigureFunc: providerConfigure,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func providerConfigure(d *schema.ResourceData) (interface{}, error) {
|
|
|
|
var err error
|
|
|
|
client := atlas.DefaultClient()
|
|
|
|
if v := d.Get("address").(string); v != "" {
|
|
|
|
client, err = atlas.NewClient(v)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
client.Token = d.Get("token").(string)
|
|
|
|
|
|
|
|
return client, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
var descriptions map[string]string
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
descriptions = map[string]string{
|
|
|
|
"address": "The address of the Atlas server. If blank, the public\n" +
|
|
|
|
"server at atlas.hashicorp.com will be used.",
|
|
|
|
|
|
|
|
"token": "The access token for reading artifacts. This is required\n" +
|
|
|
|
"if reading private artifacts.",
|
|
|
|
}
|
|
|
|
}
|