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