github.com/ggiamarchi/terraform@v0.3.7-0.20150607194748-ed2a66a46a71/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_autoscaling_notification": resourceAwsAutoscalingNotification(), 89 "aws_customer_gateway": resourceAwsCustomerGateway(), 90 "aws_db_instance": resourceAwsDbInstance(), 91 "aws_db_parameter_group": resourceAwsDbParameterGroup(), 92 "aws_db_security_group": resourceAwsDbSecurityGroup(), 93 "aws_db_subnet_group": resourceAwsDbSubnetGroup(), 94 "aws_ebs_volume": resourceAwsEbsVolume(), 95 "aws_ecs_cluster": resourceAwsEcsCluster(), 96 "aws_ecs_service": resourceAwsEcsService(), 97 "aws_ecs_task_definition": resourceAwsEcsTaskDefinition(), 98 "aws_eip": resourceAwsEip(), 99 "aws_elasticache_cluster": resourceAwsElasticacheCluster(), 100 "aws_elasticache_security_group": resourceAwsElasticacheSecurityGroup(), 101 "aws_elasticache_subnet_group": resourceAwsElasticacheSubnetGroup(), 102 "aws_elb": resourceAwsElb(), 103 "aws_iam_access_key": resourceAwsIamAccessKey(), 104 "aws_iam_group_policy": resourceAwsIamGroupPolicy(), 105 "aws_iam_group": resourceAwsIamGroup(), 106 "aws_iam_instance_profile": resourceAwsIamInstanceProfile(), 107 "aws_iam_policy": resourceAwsIamPolicy(), 108 "aws_iam_role_policy": resourceAwsIamRolePolicy(), 109 "aws_iam_role": resourceAwsIamRole(), 110 "aws_iam_server_certificate": resourceAwsIAMServerCertificate(), 111 "aws_iam_user_policy": resourceAwsIamUserPolicy(), 112 "aws_iam_user": resourceAwsIamUser(), 113 "aws_instance": resourceAwsInstance(), 114 "aws_internet_gateway": resourceAwsInternetGateway(), 115 "aws_key_pair": resourceAwsKeyPair(), 116 "aws_kinesis_stream": resourceAwsKinesisStream(), 117 "aws_launch_configuration": resourceAwsLaunchConfiguration(), 118 "aws_lb_cookie_stickiness_policy": resourceAwsLBCookieStickinessPolicy(), 119 "aws_main_route_table_association": resourceAwsMainRouteTableAssociation(), 120 "aws_network_acl": resourceAwsNetworkAcl(), 121 "aws_network_interface": resourceAwsNetworkInterface(), 122 "aws_proxy_protocol_policy": resourceAwsProxyProtocolPolicy(), 123 "aws_route53_record": resourceAwsRoute53Record(), 124 "aws_route53_zone_association": resourceAwsRoute53ZoneAssociation(), 125 "aws_route53_zone": resourceAwsRoute53Zone(), 126 "aws_route_table_association": resourceAwsRouteTableAssociation(), 127 "aws_route_table": resourceAwsRouteTable(), 128 "aws_s3_bucket": resourceAwsS3Bucket(), 129 "aws_security_group": resourceAwsSecurityGroup(), 130 "aws_security_group_rule": resourceAwsSecurityGroupRule(), 131 "aws_sqs_queue": resourceAwsSqsQueue(), 132 "aws_sns_topic": resourceAwsSnsTopic(), 133 "aws_sns_topic_subscription": resourceAwsSnsTopicSubscription(), 134 "aws_subnet": resourceAwsSubnet(), 135 "aws_volume_attachment": resourceAwsVolumeAttachment(), 136 "aws_vpc_dhcp_options_association": resourceAwsVpcDhcpOptionsAssociation(), 137 "aws_vpc_dhcp_options": resourceAwsVpcDhcpOptions(), 138 "aws_vpc_peering_connection": resourceAwsVpcPeeringConnection(), 139 "aws_vpc": resourceAwsVpc(), 140 "aws_vpn_connection": resourceAwsVpnConnection(), 141 "aws_vpn_connection_route": resourceAwsVpnConnectionRoute(), 142 "aws_vpn_gateway": resourceAwsVpnGateway(), 143 }, 144 145 ConfigureFunc: providerConfigure, 146 } 147 } 148 149 var descriptions map[string]string 150 151 func init() { 152 descriptions = map[string]string{ 153 "region": "The region where AWS operations will take place. Examples\n" + 154 "are us-east-1, us-west-2, etc.", 155 156 "access_key": "The access key for API operations. You can retrieve this\n" + 157 "from the 'Security & Credentials' section of the AWS console.", 158 159 "secret_key": "The secret key for API operations. You can retrieve this\n" + 160 "from the 'Security & Credentials' section of the AWS console.", 161 162 "token": "session token. A session token is only required if you are\n" + 163 "using temporary security credentials.", 164 165 "max_retries": "The maximum number of times an AWS API request is\n" + 166 "being executed. If the API request still fails, an error is\n" + 167 "thrown.", 168 } 169 } 170 171 func providerConfigure(d *schema.ResourceData) (interface{}, error) { 172 config := Config{ 173 AccessKey: d.Get("access_key").(string), 174 SecretKey: d.Get("secret_key").(string), 175 Token: d.Get("token").(string), 176 Region: d.Get("region").(string), 177 MaxRetries: d.Get("max_retries").(int), 178 } 179 180 if v, ok := d.GetOk("allowed_account_ids"); ok { 181 config.AllowedAccountIds = v.(*schema.Set).List() 182 } 183 184 if v, ok := d.GetOk("forbidden_account_ids"); ok { 185 config.ForbiddenAccountIds = v.(*schema.Set).List() 186 } 187 188 return config.Client() 189 }