github.com/ndarilek/terraform@v0.3.8-0.20150320140257-d3135c1b2bac/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_network_interface": resourceAwsNetworkInterface(), 62 "aws_route53_record": resourceAwsRoute53Record(), 63 "aws_route53_zone": resourceAwsRoute53Zone(), 64 "aws_route_table": resourceAwsRouteTable(), 65 "aws_route_table_association": resourceAwsRouteTableAssociation(), 66 "aws_s3_bucket": resourceAwsS3Bucket(), 67 "aws_security_group": resourceAwsSecurityGroup(), 68 "aws_subnet": resourceAwsSubnet(), 69 "aws_vpc": resourceAwsVpc(), 70 "aws_vpc_peering_connection": resourceAwsVpcPeeringConnection(), 71 "aws_vpn_gateway": resourceAwsVpnGateway(), 72 }, 73 74 ConfigureFunc: providerConfigure, 75 } 76 } 77 78 var descriptions map[string]string 79 80 func init() { 81 descriptions = map[string]string{ 82 "region": "The region where AWS operations will take place. Examples\n" + 83 "are us-east-1, us-west-2, etc.", 84 85 "access_key": "The access key for API operations. You can retrieve this\n" + 86 "from the 'Security & Credentials' section of the AWS console.", 87 88 "secret_key": "The secret key for API operations. You can retrieve this\n" + 89 "from the 'Security & Credentials' section of the AWS console.", 90 } 91 } 92 93 func providerConfigure(d *schema.ResourceData) (interface{}, error) { 94 config := Config{ 95 AccessKey: d.Get("access_key").(string), 96 SecretKey: d.Get("secret_key").(string), 97 Region: d.Get("region").(string), 98 } 99 100 return config.Client() 101 }