github.com/paulmey/terraform@v0.5.2-0.20150519145237-046e9b4c884d/builtin/providers/aws/provider.go (about) 1 package aws 2 3 import ( 4 "github.com/hashicorp/terraform/helper/hashcode" 5 "github.com/hashicorp/terraform/helper/schema" 6 "github.com/hashicorp/terraform/terraform" 7 ) 8 9 // Provider returns a terraform.ResourceProvider. 10 func Provider() terraform.ResourceProvider { 11 // TODO: Move the validation to this, requires conditional schemas 12 // TODO: Move the configuration to this, requires validation 13 14 return &schema.Provider{ 15 Schema: map[string]*schema.Schema{ 16 "access_key": &schema.Schema{ 17 Type: schema.TypeString, 18 Required: true, 19 DefaultFunc: schema.MultiEnvDefaultFunc([]string{ 20 "AWS_ACCESS_KEY", 21 "AWS_ACCESS_KEY_ID", 22 }, nil), 23 Description: descriptions["access_key"], 24 }, 25 26 "secret_key": &schema.Schema{ 27 Type: schema.TypeString, 28 Required: true, 29 DefaultFunc: schema.MultiEnvDefaultFunc([]string{ 30 "AWS_SECRET_KEY", 31 "AWS_SECRET_ACCESS_KEY", 32 }, nil), 33 Description: descriptions["secret_key"], 34 }, 35 36 "token": &schema.Schema{ 37 Type: schema.TypeString, 38 Optional: true, 39 DefaultFunc: schema.MultiEnvDefaultFunc([]string{ 40 "AWS_SESSION_TOKEN", 41 "AWS_SECURITY_TOKEN", 42 }, ""), 43 Description: descriptions["token"], 44 }, 45 46 "region": &schema.Schema{ 47 Type: schema.TypeString, 48 Required: true, 49 DefaultFunc: schema.MultiEnvDefaultFunc([]string{ 50 "AWS_REGION", 51 "AWS_DEFAULT_REGION", 52 }, nil), 53 Description: descriptions["region"], 54 InputDefault: "us-east-1", 55 }, 56 57 "max_retries": &schema.Schema{ 58 Type: schema.TypeInt, 59 Optional: true, 60 Default: 11, 61 Description: descriptions["max_retries"], 62 }, 63 64 "allowed_account_ids": &schema.Schema{ 65 Type: schema.TypeSet, 66 Elem: &schema.Schema{Type: schema.TypeString}, 67 Optional: true, 68 ConflictsWith: []string{"forbidden_account_ids"}, 69 Set: func(v interface{}) int { 70 return hashcode.String(v.(string)) 71 }, 72 }, 73 74 "forbidden_account_ids": &schema.Schema{ 75 Type: schema.TypeSet, 76 Elem: &schema.Schema{Type: schema.TypeString}, 77 Optional: true, 78 ConflictsWith: []string{"allowed_account_ids"}, 79 Set: func(v interface{}) int { 80 return hashcode.String(v.(string)) 81 }, 82 }, 83 }, 84 85 ResourcesMap: map[string]*schema.Resource{ 86 "aws_app_cookie_stickiness_policy": resourceAwsAppCookieStickinessPolicy(), 87 "aws_autoscaling_group": resourceAwsAutoscalingGroup(), 88 "aws_customer_gateway": resourceAwsCustomerGateway(), 89 "aws_db_instance": resourceAwsDbInstance(), 90 "aws_db_parameter_group": resourceAwsDbParameterGroup(), 91 "aws_db_security_group": resourceAwsDbSecurityGroup(), 92 "aws_db_subnet_group": resourceAwsDbSubnetGroup(), 93 "aws_ebs_volume": resourceAwsEbsVolume(), 94 "aws_eip": resourceAwsEip(), 95 "aws_elasticache_cluster": resourceAwsElasticacheCluster(), 96 "aws_elasticache_security_group": resourceAwsElasticacheSecurityGroup(), 97 "aws_elasticache_subnet_group": resourceAwsElasticacheSubnetGroup(), 98 "aws_elb": resourceAwsElb(), 99 "aws_iam_access_key": resourceAwsIamAccessKey(), 100 "aws_iam_group_policy": resourceAwsIamGroupPolicy(), 101 "aws_iam_group": resourceAwsIamGroup(), 102 "aws_iam_instance_profile": resourceAwsIamInstanceProfile(), 103 "aws_iam_policy": resourceAwsIamPolicy(), 104 "aws_iam_role_policy": resourceAwsIamRolePolicy(), 105 "aws_iam_role": resourceAwsIamRole(), 106 "aws_iam_user_policy": resourceAwsIamUserPolicy(), 107 "aws_iam_user": resourceAwsIamUser(), 108 "aws_instance": resourceAwsInstance(), 109 "aws_internet_gateway": resourceAwsInternetGateway(), 110 "aws_key_pair": resourceAwsKeyPair(), 111 "aws_launch_configuration": resourceAwsLaunchConfiguration(), 112 "aws_lb_cookie_stickiness_policy": resourceAwsLBCookieStickinessPolicy(), 113 "aws_main_route_table_association": resourceAwsMainRouteTableAssociation(), 114 "aws_network_acl": resourceAwsNetworkAcl(), 115 "aws_network_interface": resourceAwsNetworkInterface(), 116 "aws_proxy_protocol_policy": resourceAwsProxyProtocolPolicy(), 117 "aws_route53_record": resourceAwsRoute53Record(), 118 "aws_route53_zone_association": resourceAwsRoute53ZoneAssociation(), 119 "aws_route53_zone": resourceAwsRoute53Zone(), 120 "aws_route_table_association": resourceAwsRouteTableAssociation(), 121 "aws_route_table": resourceAwsRouteTable(), 122 "aws_s3_bucket": resourceAwsS3Bucket(), 123 "aws_security_group": resourceAwsSecurityGroup(), 124 "aws_security_group_rule": resourceAwsSecurityGroupRule(), 125 "aws_sqs_queue": resourceAwsSqsQueue(), 126 "aws_subnet": resourceAwsSubnet(), 127 "aws_vpc_dhcp_options_association": resourceAwsVpcDhcpOptionsAssociation(), 128 "aws_vpc_dhcp_options": resourceAwsVpcDhcpOptions(), 129 "aws_vpc_peering_connection": resourceAwsVpcPeeringConnection(), 130 "aws_vpc": resourceAwsVpc(), 131 "aws_vpn_connection": resourceAwsVpnConnection(), 132 "aws_vpn_connection_route": resourceAwsVpnConnectionRoute(), 133 "aws_vpn_gateway": resourceAwsVpnGateway(), 134 }, 135 136 ConfigureFunc: providerConfigure, 137 } 138 } 139 140 var descriptions map[string]string 141 142 func init() { 143 descriptions = map[string]string{ 144 "region": "The region where AWS operations will take place. Examples\n" + 145 "are us-east-1, us-west-2, etc.", 146 147 "access_key": "The access key for API operations. You can retrieve this\n" + 148 "from the 'Security & Credentials' section of the AWS console.", 149 150 "secret_key": "The secret key for API operations. You can retrieve this\n" + 151 "from the 'Security & Credentials' section of the AWS console.", 152 153 "token": "session token. A session token is only required if you are\n" + 154 "using temporary security credentials.", 155 156 "max_retries": "The maximum number of times an AWS API request is\n" + 157 "being executed. If the API request still fails, an error is\n" + 158 "thrown.", 159 } 160 } 161 162 func providerConfigure(d *schema.ResourceData) (interface{}, error) { 163 config := Config{ 164 AccessKey: d.Get("access_key").(string), 165 SecretKey: d.Get("secret_key").(string), 166 Token: d.Get("token").(string), 167 Region: d.Get("region").(string), 168 MaxRetries: d.Get("max_retries").(int), 169 } 170 171 if v, ok := d.GetOk("allowed_account_ids"); ok { 172 config.AllowedAccountIds = v.(*schema.Set).List() 173 } 174 175 if v, ok := d.GetOk("forbidden_account_ids"); ok { 176 config.ForbiddenAccountIds = v.(*schema.Set).List() 177 } 178 179 return config.Client() 180 }