github.com/nalum/terraform@v0.3.2-0.20141223102918-aa2c22ffeff6/builtin/providers/aws/provider.go (about) 1 package aws 2 3 import ( 4 "os" 5 6 "github.com/hashicorp/terraform/helper/schema" 7 "github.com/hashicorp/terraform/terraform" 8 ) 9 10 // Provider returns a terraform.ResourceProvider. 11 func Provider() terraform.ResourceProvider { 12 // TODO: Move the validation to this, requires conditional schemas 13 // TODO: Move the configuration to this, requires validation 14 15 return &schema.Provider{ 16 Schema: map[string]*schema.Schema{ 17 "access_key": &schema.Schema{ 18 Type: schema.TypeString, 19 Required: true, 20 DefaultFunc: envDefaultFunc("AWS_ACCESS_KEY"), 21 Description: descriptions["access_key"], 22 }, 23 24 "secret_key": &schema.Schema{ 25 Type: schema.TypeString, 26 Required: true, 27 DefaultFunc: envDefaultFunc("AWS_SECRET_KEY"), 28 Description: descriptions["secret_key"], 29 }, 30 31 "region": &schema.Schema{ 32 Type: schema.TypeString, 33 Required: true, 34 DefaultFunc: envDefaultFunc("AWS_REGION"), 35 Description: descriptions["region"], 36 InputDefault: "us-east-1", 37 }, 38 }, 39 40 ResourcesMap: map[string]*schema.Resource{ 41 "aws_autoscaling_group": resourceAwsAutoscalingGroup(), 42 "aws_db_instance": resourceAwsDbInstance(), 43 "aws_db_parameter_group": resourceAwsDbParameterGroup(), 44 "aws_db_security_group": resourceAwsDbSecurityGroup(), 45 "aws_db_subnet_group": resourceAwsDbSubnetGroup(), 46 "aws_eip": resourceAwsEip(), 47 "aws_elb": resourceAwsElb(), 48 "aws_instance": resourceAwsInstance(), 49 "aws_internet_gateway": resourceAwsInternetGateway(), 50 "aws_launch_configuration": resourceAwsLaunchConfiguration(), 51 "aws_network_acl": resourceAwsNetworkAcl(), 52 "aws_route53_record": resourceAwsRoute53Record(), 53 "aws_route53_zone": resourceAwsRoute53Zone(), 54 "aws_route_table": resourceAwsRouteTable(), 55 "aws_route_table_association": resourceAwsRouteTableAssociation(), 56 "aws_s3_bucket": resourceAwsS3Bucket(), 57 "aws_security_group": resourceAwsSecurityGroup(), 58 "aws_subnet": resourceAwsSubnet(), 59 "aws_vpc": resourceAwsVpc(), 60 }, 61 62 ConfigureFunc: providerConfigure, 63 } 64 } 65 66 var descriptions map[string]string 67 68 func init() { 69 descriptions = map[string]string{ 70 "region": "The region where AWS operations will take place. Examples\n" + 71 "are us-east-1, us-west-2, etc.", 72 73 "access_key": "The access key for API operations. You can retrieve this\n" + 74 "from the 'Security & Credentials' section of the AWS console.", 75 76 "secret_key": "The secret key for API operations. You can retrieve this\n" + 77 "from the 'Security & Credentials' section of the AWS console.", 78 } 79 } 80 81 func envDefaultFunc(k string) schema.SchemaDefaultFunc { 82 return func() (interface{}, error) { 83 if v := os.Getenv(k); v != "" { 84 return v, nil 85 } 86 87 return nil, nil 88 } 89 } 90 91 func providerConfigure(d *schema.ResourceData) (interface{}, error) { 92 config := Config{ 93 AccessKey: d.Get("access_key").(string), 94 SecretKey: d.Get("secret_key").(string), 95 Region: d.Get("region").(string), 96 } 97 98 return config.Client() 99 }