github.com/lamielle/terraform@v0.3.2-0.20141121070651-81f008ba53d5/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  			"aws_db_parameter_group":   resourceAwsDbParameterGroup(),
    54  			"aws_subnet":               resourceAwsSubnet(),
    55  		},
    56  	}
    57  }
    58  
    59  func envDefaultFunc(k string) schema.SchemaDefaultFunc {
    60  	return func() (interface{}, error) {
    61  		if v := os.Getenv(k); v != "" {
    62  			return v, nil
    63  		}
    64  
    65  		return nil, nil
    66  	}
    67  }
    68  
    69  var descriptions map[string]string
    70  
    71  func init() {
    72  	descriptions = map[string]string{
    73  		"region": "The region where AWS operations will take place. Examples\n" +
    74  			"are us-east-1, us-west-2, etc.",
    75  
    76  		"access_key": "The access key for API operations. You can retrieve this\n" +
    77  			"from the 'Security & Credentials' section of the AWS console.",
    78  
    79  		"secret_key": "The secret key for API operations. You can retrieve this\n" +
    80  			"from the 'Security & Credentials' section of the AWS console.",
    81  	}
    82  }