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