github.com/armen/terraform@v0.5.2-0.20150529052519-caa8117a08f1/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_server_certificate": resourceAwsIAMServerCertificate(), 107 "aws_iam_user_policy": resourceAwsIamUserPolicy(), 108 "aws_iam_user": resourceAwsIamUser(), 109 "aws_instance": resourceAwsInstance(), 110 "aws_internet_gateway": resourceAwsInternetGateway(), 111 "aws_key_pair": resourceAwsKeyPair(), 112 "aws_launch_configuration": resourceAwsLaunchConfiguration(), 113 "aws_lb_cookie_stickiness_policy": resourceAwsLBCookieStickinessPolicy(), 114 "aws_main_route_table_association": resourceAwsMainRouteTableAssociation(), 115 "aws_network_acl": resourceAwsNetworkAcl(), 116 "aws_network_interface": resourceAwsNetworkInterface(), 117 "aws_proxy_protocol_policy": resourceAwsProxyProtocolPolicy(), 118 "aws_route53_record": resourceAwsRoute53Record(), 119 "aws_route53_zone_association": resourceAwsRoute53ZoneAssociation(), 120 "aws_route53_zone": resourceAwsRoute53Zone(), 121 "aws_route_table_association": resourceAwsRouteTableAssociation(), 122 "aws_route_table": resourceAwsRouteTable(), 123 "aws_s3_bucket": resourceAwsS3Bucket(), 124 "aws_security_group": resourceAwsSecurityGroup(), 125 "aws_security_group_rule": resourceAwsSecurityGroupRule(), 126 "aws_sqs_queue": resourceAwsSqsQueue(), 127 "aws_sns_topic": resourceAwsSnsTopic(), 128 "aws_sns_topic_subscription": resourceAwsSnsTopicSubscription(), 129 "aws_subnet": resourceAwsSubnet(), 130 "aws_volume_attachment": resourceAwsVolumeAttachment(), 131 "aws_vpc_dhcp_options_association": resourceAwsVpcDhcpOptionsAssociation(), 132 "aws_vpc_dhcp_options": resourceAwsVpcDhcpOptions(), 133 "aws_vpc_peering_connection": resourceAwsVpcPeeringConnection(), 134 "aws_vpc": resourceAwsVpc(), 135 "aws_vpn_connection": resourceAwsVpnConnection(), 136 "aws_vpn_connection_route": resourceAwsVpnConnectionRoute(), 137 "aws_vpn_gateway": resourceAwsVpnGateway(), 138 }, 139 140 ConfigureFunc: providerConfigure, 141 } 142 } 143 144 var descriptions map[string]string 145 146 func init() { 147 descriptions = map[string]string{ 148 "region": "The region where AWS operations will take place. Examples\n" + 149 "are us-east-1, us-west-2, etc.", 150 151 "access_key": "The access key for API operations. You can retrieve this\n" + 152 "from the 'Security & Credentials' section of the AWS console.", 153 154 "secret_key": "The secret key for API operations. You can retrieve this\n" + 155 "from the 'Security & Credentials' section of the AWS console.", 156 157 "token": "session token. A session token is only required if you are\n" + 158 "using temporary security credentials.", 159 160 "max_retries": "The maximum number of times an AWS API request is\n" + 161 "being executed. If the API request still fails, an error is\n" + 162 "thrown.", 163 } 164 } 165 166 func providerConfigure(d *schema.ResourceData) (interface{}, error) { 167 config := Config{ 168 AccessKey: d.Get("access_key").(string), 169 SecretKey: d.Get("secret_key").(string), 170 Token: d.Get("token").(string), 171 Region: d.Get("region").(string), 172 MaxRetries: d.Get("max_retries").(int), 173 } 174 175 if v, ok := d.GetOk("allowed_account_ids"); ok { 176 config.AllowedAccountIds = v.(*schema.Set).List() 177 } 178 179 if v, ok := d.GetOk("forbidden_account_ids"); ok { 180 config.ForbiddenAccountIds = v.(*schema.Set).List() 181 } 182 183 return config.Client() 184 }