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