github.com/bengesoff/terraform@v0.3.1-0.20141018223233-b25a53629922/builtin/providers/aws/provider.go (about)

     1  package aws
     2  
     3  import (
     4  	"os"
     5  
     6  	"github.com/hashicorp/terraform/helper/schema"
     7  )
     8  
     9  // Provider returns a schema.Provider for AWS.
    10  //
    11  // NOTE: schema.Provider became available long after the AWS provider
    12  // was started, so resources may not be converted to this new structure
    13  // yet. This is a WIP. To assist with the migration, make sure any resources
    14  // you migrate are acceptance tested, then perform the migration.
    15  func Provider() *schema.Provider {
    16  	// TODO: Move the validation to this, requires conditional schemas
    17  	// TODO: Move the configuration to this, requires validation
    18  
    19  	return &schema.Provider{
    20  		Schema: map[string]*schema.Schema{
    21  			"region": &schema.Schema{
    22  				Type:         schema.TypeString,
    23  				Required:     true,
    24  				DefaultFunc:  envDefaultFunc("AWS_REGION"),
    25  				Description:  descriptions["region"],
    26  				InputDefault: "us-east-1",
    27  			},
    28  
    29  			"access_key": &schema.Schema{
    30  				Type:        schema.TypeString,
    31  				Required:    true,
    32  				DefaultFunc: envDefaultFunc("AWS_ACCESS_KEY"),
    33  				Description: descriptions["access_key"],
    34  			},
    35  
    36  			"secret_key": &schema.Schema{
    37  				Type:        schema.TypeString,
    38  				Required:    true,
    39  				DefaultFunc: envDefaultFunc("AWS_SECRET_KEY"),
    40  				Description: descriptions["secret_key"],
    41  			},
    42  		},
    43  
    44  		ResourcesMap: map[string]*schema.Resource{
    45  			"aws_autoscaling_group":    resourceAwsAutoscalingGroup(),
    46  			"aws_eip":                  resourceAwsEip(),
    47  			"aws_elb":                  resourceAwsElb(),
    48  			"aws_instance":             resourceAwsInstance(),
    49  			"aws_launch_configuration": resourceAwsLaunchConfiguration(),
    50  			"aws_security_group":       resourceAwsSecurityGroup(),
    51  			"aws_db_subnet_group":      resourceAwsDbSubnetGroup(),
    52  			"aws_vpc":                  resourceAwsVpc(),
    53  		},
    54  	}
    55  }
    56  
    57  func envDefaultFunc(k string) schema.SchemaDefaultFunc {
    58  	return func() (interface{}, error) {
    59  		if v := os.Getenv(k); v != "" {
    60  			return v, nil
    61  		}
    62  
    63  		return nil, nil
    64  	}
    65  }
    66  
    67  var descriptions map[string]string
    68  
    69  func init() {
    70  	descriptions = map[string]string{
    71  		"region": "The region where AWS operations will take place. Examples\n" +
    72  			"are us-east-1, us-west-2, etc.",
    73  
    74  		"access_key": "The access key for API operations. You can retrieve this\n" +
    75  			"from the 'Security & Credentials' section of the AWS console.",
    76  
    77  		"secret_key": "The secret key for API operations. You can retrieve this\n" +
    78  			"from the 'Security & Credentials' section of the AWS console.",
    79  	}
    80  }