github.com/minamijoyo/terraform@v0.7.8-0.20161029001309-18b3736ba44b/builtin/providers/aws/provider.go (about)

     1  package aws
     2  
     3  import (
     4  	"bytes"
     5  	"fmt"
     6  	"log"
     7  
     8  	"github.com/hashicorp/terraform/helper/hashcode"
     9  	"github.com/hashicorp/terraform/helper/mutexkv"
    10  	"github.com/hashicorp/terraform/helper/schema"
    11  	"github.com/hashicorp/terraform/terraform"
    12  )
    13  
    14  // Provider returns a terraform.ResourceProvider.
    15  func Provider() terraform.ResourceProvider {
    16  	// TODO: Move the validation to this, requires conditional schemas
    17  	// TODO: Move the configuration to this, requires validation
    18  
    19  	// The actual provider
    20  	return &schema.Provider{
    21  		Schema: map[string]*schema.Schema{
    22  			"access_key": {
    23  				Type:        schema.TypeString,
    24  				Optional:    true,
    25  				Default:     "",
    26  				Description: descriptions["access_key"],
    27  			},
    28  
    29  			"secret_key": {
    30  				Type:        schema.TypeString,
    31  				Optional:    true,
    32  				Default:     "",
    33  				Description: descriptions["secret_key"],
    34  			},
    35  
    36  			"profile": {
    37  				Type:        schema.TypeString,
    38  				Optional:    true,
    39  				Default:     "",
    40  				Description: descriptions["profile"],
    41  			},
    42  
    43  			"assume_role": assumeRoleSchema(),
    44  
    45  			"shared_credentials_file": {
    46  				Type:        schema.TypeString,
    47  				Optional:    true,
    48  				Default:     "",
    49  				Description: descriptions["shared_credentials_file"],
    50  			},
    51  
    52  			"token": {
    53  				Type:        schema.TypeString,
    54  				Optional:    true,
    55  				Default:     "",
    56  				Description: descriptions["token"],
    57  			},
    58  
    59  			"region": {
    60  				Type:     schema.TypeString,
    61  				Required: true,
    62  				DefaultFunc: schema.MultiEnvDefaultFunc([]string{
    63  					"AWS_REGION",
    64  					"AWS_DEFAULT_REGION",
    65  				}, nil),
    66  				Description:  descriptions["region"],
    67  				InputDefault: "us-east-1",
    68  			},
    69  
    70  			"max_retries": {
    71  				Type:        schema.TypeInt,
    72  				Optional:    true,
    73  				Default:     11,
    74  				Description: descriptions["max_retries"],
    75  			},
    76  
    77  			"allowed_account_ids": {
    78  				Type:          schema.TypeSet,
    79  				Elem:          &schema.Schema{Type: schema.TypeString},
    80  				Optional:      true,
    81  				ConflictsWith: []string{"forbidden_account_ids"},
    82  				Set:           schema.HashString,
    83  			},
    84  
    85  			"forbidden_account_ids": {
    86  				Type:          schema.TypeSet,
    87  				Elem:          &schema.Schema{Type: schema.TypeString},
    88  				Optional:      true,
    89  				ConflictsWith: []string{"allowed_account_ids"},
    90  				Set:           schema.HashString,
    91  			},
    92  
    93  			"dynamodb_endpoint": {
    94  				Type:        schema.TypeString,
    95  				Optional:    true,
    96  				Default:     "",
    97  				Description: descriptions["dynamodb_endpoint"],
    98  			},
    99  
   100  			"kinesis_endpoint": {
   101  				Type:        schema.TypeString,
   102  				Optional:    true,
   103  				Default:     "",
   104  				Description: descriptions["kinesis_endpoint"],
   105  			},
   106  
   107  			"endpoints": endpointsSchema(),
   108  
   109  			"insecure": {
   110  				Type:        schema.TypeBool,
   111  				Optional:    true,
   112  				Default:     false,
   113  				Description: descriptions["insecure"],
   114  			},
   115  
   116  			"skip_credentials_validation": {
   117  				Type:        schema.TypeBool,
   118  				Optional:    true,
   119  				Default:     false,
   120  				Description: descriptions["skip_credentials_validation"],
   121  			},
   122  
   123  			"skip_requesting_account_id": {
   124  				Type:        schema.TypeBool,
   125  				Optional:    true,
   126  				Default:     false,
   127  				Description: descriptions["skip_requesting_account_id"],
   128  			},
   129  
   130  			"skip_metadata_api_check": {
   131  				Type:        schema.TypeBool,
   132  				Optional:    true,
   133  				Default:     false,
   134  				Description: descriptions["skip_metadata_api_check"],
   135  			},
   136  
   137  			"s3_force_path_style": {
   138  				Type:        schema.TypeBool,
   139  				Optional:    true,
   140  				Default:     false,
   141  				Description: descriptions["s3_force_path_style"],
   142  			},
   143  		},
   144  
   145  		DataSourcesMap: map[string]*schema.Resource{
   146  			"aws_ami":                      dataSourceAwsAmi(),
   147  			"aws_availability_zone":        dataSourceAwsAvailabilityZone(),
   148  			"aws_availability_zones":       dataSourceAwsAvailabilityZones(),
   149  			"aws_billing_service_account":  dataSourceAwsBillingServiceAccount(),
   150  			"aws_caller_identity":          dataSourceAwsCallerIdentity(),
   151  			"aws_cloudformation_stack":     dataSourceAwsCloudFormationStack(),
   152  			"aws_ecs_container_definition": dataSourceAwsEcsContainerDefinition(),
   153  			"aws_elb_service_account":      dataSourceAwsElbServiceAccount(),
   154  			"aws_iam_policy_document":      dataSourceAwsIamPolicyDocument(),
   155  			"aws_ip_ranges":                dataSourceAwsIPRanges(),
   156  			"aws_prefix_list":              dataSourceAwsPrefixList(),
   157  			"aws_redshift_service_account": dataSourceAwsRedshiftServiceAccount(),
   158  			"aws_region":                   dataSourceAwsRegion(),
   159  			"aws_s3_bucket_object":         dataSourceAwsS3BucketObject(),
   160  			"aws_subnet":                   dataSourceAwsSubnet(),
   161  			"aws_security_group":           dataSourceAwsSecurityGroup(),
   162  			"aws_vpc":                      dataSourceAwsVpc(),
   163  		},
   164  
   165  		ResourcesMap: map[string]*schema.Resource{
   166  			"aws_alb":                                      resourceAwsAlb(),
   167  			"aws_alb_listener":                             resourceAwsAlbListener(),
   168  			"aws_alb_listener_rule":                        resourceAwsAlbListenerRule(),
   169  			"aws_alb_target_group":                         resourceAwsAlbTargetGroup(),
   170  			"aws_alb_target_group_attachment":              resourceAwsAlbTargetGroupAttachment(),
   171  			"aws_ami":                                      resourceAwsAmi(),
   172  			"aws_ami_copy":                                 resourceAwsAmiCopy(),
   173  			"aws_ami_from_instance":                        resourceAwsAmiFromInstance(),
   174  			"aws_ami_launch_permission":                    resourceAwsAmiLaunchPermission(),
   175  			"aws_api_gateway_account":                      resourceAwsApiGatewayAccount(),
   176  			"aws_api_gateway_api_key":                      resourceAwsApiGatewayApiKey(),
   177  			"aws_api_gateway_authorizer":                   resourceAwsApiGatewayAuthorizer(),
   178  			"aws_api_gateway_base_path_mapping":            resourceAwsApiGatewayBasePathMapping(),
   179  			"aws_api_gateway_client_certificate":           resourceAwsApiGatewayClientCertificate(),
   180  			"aws_api_gateway_deployment":                   resourceAwsApiGatewayDeployment(),
   181  			"aws_api_gateway_domain_name":                  resourceAwsApiGatewayDomainName(),
   182  			"aws_api_gateway_integration":                  resourceAwsApiGatewayIntegration(),
   183  			"aws_api_gateway_integration_response":         resourceAwsApiGatewayIntegrationResponse(),
   184  			"aws_api_gateway_method":                       resourceAwsApiGatewayMethod(),
   185  			"aws_api_gateway_method_response":              resourceAwsApiGatewayMethodResponse(),
   186  			"aws_api_gateway_model":                        resourceAwsApiGatewayModel(),
   187  			"aws_api_gateway_resource":                     resourceAwsApiGatewayResource(),
   188  			"aws_api_gateway_rest_api":                     resourceAwsApiGatewayRestApi(),
   189  			"aws_app_cookie_stickiness_policy":             resourceAwsAppCookieStickinessPolicy(),
   190  			"aws_appautoscaling_target":                    resourceAwsAppautoscalingTarget(),
   191  			"aws_appautoscaling_policy":                    resourceAwsAppautoscalingPolicy(),
   192  			"aws_autoscaling_group":                        resourceAwsAutoscalingGroup(),
   193  			"aws_autoscaling_notification":                 resourceAwsAutoscalingNotification(),
   194  			"aws_autoscaling_policy":                       resourceAwsAutoscalingPolicy(),
   195  			"aws_autoscaling_schedule":                     resourceAwsAutoscalingSchedule(),
   196  			"aws_cloudformation_stack":                     resourceAwsCloudFormationStack(),
   197  			"aws_cloudfront_distribution":                  resourceAwsCloudFrontDistribution(),
   198  			"aws_cloudfront_origin_access_identity":        resourceAwsCloudFrontOriginAccessIdentity(),
   199  			"aws_cloudtrail":                               resourceAwsCloudTrail(),
   200  			"aws_cloudwatch_event_rule":                    resourceAwsCloudWatchEventRule(),
   201  			"aws_cloudwatch_event_target":                  resourceAwsCloudWatchEventTarget(),
   202  			"aws_cloudwatch_log_group":                     resourceAwsCloudWatchLogGroup(),
   203  			"aws_cloudwatch_log_metric_filter":             resourceAwsCloudWatchLogMetricFilter(),
   204  			"aws_cloudwatch_log_stream":                    resourceAwsCloudWatchLogStream(),
   205  			"aws_cloudwatch_log_subscription_filter":       resourceAwsCloudwatchLogSubscriptionFilter(),
   206  			"aws_autoscaling_lifecycle_hook":               resourceAwsAutoscalingLifecycleHook(),
   207  			"aws_cloudwatch_metric_alarm":                  resourceAwsCloudWatchMetricAlarm(),
   208  			"aws_codedeploy_app":                           resourceAwsCodeDeployApp(),
   209  			"aws_codedeploy_deployment_group":              resourceAwsCodeDeployDeploymentGroup(),
   210  			"aws_codecommit_repository":                    resourceAwsCodeCommitRepository(),
   211  			"aws_codecommit_trigger":                       resourceAwsCodeCommitTrigger(),
   212  			"aws_customer_gateway":                         resourceAwsCustomerGateway(),
   213  			"aws_db_event_subscription":                    resourceAwsDbEventSubscription(),
   214  			"aws_db_instance":                              resourceAwsDbInstance(),
   215  			"aws_db_option_group":                          resourceAwsDbOptionGroup(),
   216  			"aws_db_parameter_group":                       resourceAwsDbParameterGroup(),
   217  			"aws_db_security_group":                        resourceAwsDbSecurityGroup(),
   218  			"aws_db_subnet_group":                          resourceAwsDbSubnetGroup(),
   219  			"aws_directory_service_directory":              resourceAwsDirectoryServiceDirectory(),
   220  			"aws_dynamodb_table":                           resourceAwsDynamoDbTable(),
   221  			"aws_ebs_volume":                               resourceAwsEbsVolume(),
   222  			"aws_ecr_repository":                           resourceAwsEcrRepository(),
   223  			"aws_ecr_repository_policy":                    resourceAwsEcrRepositoryPolicy(),
   224  			"aws_ecs_cluster":                              resourceAwsEcsCluster(),
   225  			"aws_ecs_service":                              resourceAwsEcsService(),
   226  			"aws_ecs_task_definition":                      resourceAwsEcsTaskDefinition(),
   227  			"aws_efs_file_system":                          resourceAwsEfsFileSystem(),
   228  			"aws_efs_mount_target":                         resourceAwsEfsMountTarget(),
   229  			"aws_eip":                                      resourceAwsEip(),
   230  			"aws_eip_association":                          resourceAwsEipAssociation(),
   231  			"aws_elasticache_cluster":                      resourceAwsElasticacheCluster(),
   232  			"aws_elasticache_parameter_group":              resourceAwsElasticacheParameterGroup(),
   233  			"aws_elasticache_replication_group":            resourceAwsElasticacheReplicationGroup(),
   234  			"aws_elasticache_security_group":               resourceAwsElasticacheSecurityGroup(),
   235  			"aws_elasticache_subnet_group":                 resourceAwsElasticacheSubnetGroup(),
   236  			"aws_elastic_beanstalk_application":            resourceAwsElasticBeanstalkApplication(),
   237  			"aws_elastic_beanstalk_configuration_template": resourceAwsElasticBeanstalkConfigurationTemplate(),
   238  			"aws_elastic_beanstalk_environment":            resourceAwsElasticBeanstalkEnvironment(),
   239  			"aws_elasticsearch_domain":                     resourceAwsElasticSearchDomain(),
   240  			"aws_elastictranscoder_pipeline":               resourceAwsElasticTranscoderPipeline(),
   241  			"aws_elastictranscoder_preset":                 resourceAwsElasticTranscoderPreset(),
   242  			"aws_elb":                                      resourceAwsElb(),
   243  			"aws_elb_attachment":                           resourceAwsElbAttachment(),
   244  			"aws_emr_cluster":                              resourceAwsEMRCluster(),
   245  			"aws_emr_instance_group":                       resourceAwsEMRInstanceGroup(),
   246  			"aws_flow_log":                                 resourceAwsFlowLog(),
   247  			"aws_glacier_vault":                            resourceAwsGlacierVault(),
   248  			"aws_iam_access_key":                           resourceAwsIamAccessKey(),
   249  			"aws_iam_account_password_policy":              resourceAwsIamAccountPasswordPolicy(),
   250  			"aws_iam_group_policy":                         resourceAwsIamGroupPolicy(),
   251  			"aws_iam_group":                                resourceAwsIamGroup(),
   252  			"aws_iam_group_membership":                     resourceAwsIamGroupMembership(),
   253  			"aws_iam_group_policy_attachment":              resourceAwsIamGroupPolicyAttachment(),
   254  			"aws_iam_instance_profile":                     resourceAwsIamInstanceProfile(),
   255  			"aws_iam_policy":                               resourceAwsIamPolicy(),
   256  			"aws_iam_policy_attachment":                    resourceAwsIamPolicyAttachment(),
   257  			"aws_iam_role_policy_attachment":               resourceAwsIamRolePolicyAttachment(),
   258  			"aws_iam_role_policy":                          resourceAwsIamRolePolicy(),
   259  			"aws_iam_role":                                 resourceAwsIamRole(),
   260  			"aws_iam_saml_provider":                        resourceAwsIamSamlProvider(),
   261  			"aws_iam_server_certificate":                   resourceAwsIAMServerCertificate(),
   262  			"aws_iam_user_policy_attachment":               resourceAwsIamUserPolicyAttachment(),
   263  			"aws_iam_user_policy":                          resourceAwsIamUserPolicy(),
   264  			"aws_iam_user_ssh_key":                         resourceAwsIamUserSshKey(),
   265  			"aws_iam_user":                                 resourceAwsIamUser(),
   266  			"aws_iam_user_login_profile":                   resourceAwsIamUserLoginProfile(),
   267  			"aws_instance":                                 resourceAwsInstance(),
   268  			"aws_internet_gateway":                         resourceAwsInternetGateway(),
   269  			"aws_key_pair":                                 resourceAwsKeyPair(),
   270  			"aws_kinesis_firehose_delivery_stream":         resourceAwsKinesisFirehoseDeliveryStream(),
   271  			"aws_kinesis_stream":                           resourceAwsKinesisStream(),
   272  			"aws_kms_alias":                                resourceAwsKmsAlias(),
   273  			"aws_kms_key":                                  resourceAwsKmsKey(),
   274  			"aws_lambda_function":                          resourceAwsLambdaFunction(),
   275  			"aws_lambda_event_source_mapping":              resourceAwsLambdaEventSourceMapping(),
   276  			"aws_lambda_alias":                             resourceAwsLambdaAlias(),
   277  			"aws_lambda_permission":                        resourceAwsLambdaPermission(),
   278  			"aws_launch_configuration":                     resourceAwsLaunchConfiguration(),
   279  			"aws_lb_cookie_stickiness_policy":              resourceAwsLBCookieStickinessPolicy(),
   280  			"aws_load_balancer_policy":                     resourceAwsLoadBalancerPolicy(),
   281  			"aws_load_balancer_backend_server_policy":      resourceAwsLoadBalancerBackendServerPolicies(),
   282  			"aws_load_balancer_listener_policy":            resourceAwsLoadBalancerListenerPolicies(),
   283  			"aws_lb_ssl_negotiation_policy":                resourceAwsLBSSLNegotiationPolicy(),
   284  			"aws_main_route_table_association":             resourceAwsMainRouteTableAssociation(),
   285  			"aws_nat_gateway":                              resourceAwsNatGateway(),
   286  			"aws_network_acl":                              resourceAwsNetworkAcl(),
   287  			"aws_default_network_acl":                      resourceAwsDefaultNetworkAcl(),
   288  			"aws_default_route_table":                      resourceAwsDefaultRouteTable(),
   289  			"aws_network_acl_rule":                         resourceAwsNetworkAclRule(),
   290  			"aws_network_interface":                        resourceAwsNetworkInterface(),
   291  			"aws_opsworks_application":                     resourceAwsOpsworksApplication(),
   292  			"aws_opsworks_stack":                           resourceAwsOpsworksStack(),
   293  			"aws_opsworks_java_app_layer":                  resourceAwsOpsworksJavaAppLayer(),
   294  			"aws_opsworks_haproxy_layer":                   resourceAwsOpsworksHaproxyLayer(),
   295  			"aws_opsworks_static_web_layer":                resourceAwsOpsworksStaticWebLayer(),
   296  			"aws_opsworks_php_app_layer":                   resourceAwsOpsworksPhpAppLayer(),
   297  			"aws_opsworks_rails_app_layer":                 resourceAwsOpsworksRailsAppLayer(),
   298  			"aws_opsworks_nodejs_app_layer":                resourceAwsOpsworksNodejsAppLayer(),
   299  			"aws_opsworks_memcached_layer":                 resourceAwsOpsworksMemcachedLayer(),
   300  			"aws_opsworks_mysql_layer":                     resourceAwsOpsworksMysqlLayer(),
   301  			"aws_opsworks_ganglia_layer":                   resourceAwsOpsworksGangliaLayer(),
   302  			"aws_opsworks_custom_layer":                    resourceAwsOpsworksCustomLayer(),
   303  			"aws_opsworks_instance":                        resourceAwsOpsworksInstance(),
   304  			"aws_opsworks_user_profile":                    resourceAwsOpsworksUserProfile(),
   305  			"aws_opsworks_permission":                      resourceAwsOpsworksPermission(),
   306  			"aws_placement_group":                          resourceAwsPlacementGroup(),
   307  			"aws_proxy_protocol_policy":                    resourceAwsProxyProtocolPolicy(),
   308  			"aws_rds_cluster":                              resourceAwsRDSCluster(),
   309  			"aws_rds_cluster_instance":                     resourceAwsRDSClusterInstance(),
   310  			"aws_rds_cluster_parameter_group":              resourceAwsRDSClusterParameterGroup(),
   311  			"aws_redshift_cluster":                         resourceAwsRedshiftCluster(),
   312  			"aws_redshift_security_group":                  resourceAwsRedshiftSecurityGroup(),
   313  			"aws_redshift_parameter_group":                 resourceAwsRedshiftParameterGroup(),
   314  			"aws_redshift_subnet_group":                    resourceAwsRedshiftSubnetGroup(),
   315  			"aws_route53_delegation_set":                   resourceAwsRoute53DelegationSet(),
   316  			"aws_route53_record":                           resourceAwsRoute53Record(),
   317  			"aws_route53_zone_association":                 resourceAwsRoute53ZoneAssociation(),
   318  			"aws_route53_zone":                             resourceAwsRoute53Zone(),
   319  			"aws_route53_health_check":                     resourceAwsRoute53HealthCheck(),
   320  			"aws_route":                                    resourceAwsRoute(),
   321  			"aws_route_table":                              resourceAwsRouteTable(),
   322  			"aws_route_table_association":                  resourceAwsRouteTableAssociation(),
   323  			"aws_ses_active_receipt_rule_set":              resourceAwsSesActiveReceiptRuleSet(),
   324  			"aws_ses_receipt_filter":                       resourceAwsSesReceiptFilter(),
   325  			"aws_ses_receipt_rule":                         resourceAwsSesReceiptRule(),
   326  			"aws_ses_receipt_rule_set":                     resourceAwsSesReceiptRuleSet(),
   327  			"aws_s3_bucket":                                resourceAwsS3Bucket(),
   328  			"aws_s3_bucket_policy":                         resourceAwsS3BucketPolicy(),
   329  			"aws_s3_bucket_object":                         resourceAwsS3BucketObject(),
   330  			"aws_s3_bucket_notification":                   resourceAwsS3BucketNotification(),
   331  			"aws_default_security_group":                   resourceAwsDefaultSecurityGroup(),
   332  			"aws_security_group":                           resourceAwsSecurityGroup(),
   333  			"aws_security_group_rule":                      resourceAwsSecurityGroupRule(),
   334  			"aws_simpledb_domain":                          resourceAwsSimpleDBDomain(),
   335  			"aws_ssm_activation":                           resourceAwsSsmActivation(),
   336  			"aws_ssm_association":                          resourceAwsSsmAssociation(),
   337  			"aws_ssm_document":                             resourceAwsSsmDocument(),
   338  			"aws_spot_datafeed_subscription":               resourceAwsSpotDataFeedSubscription(),
   339  			"aws_spot_instance_request":                    resourceAwsSpotInstanceRequest(),
   340  			"aws_spot_fleet_request":                       resourceAwsSpotFleetRequest(),
   341  			"aws_sqs_queue":                                resourceAwsSqsQueue(),
   342  			"aws_sqs_queue_policy":                         resourceAwsSqsQueuePolicy(),
   343  			"aws_sns_topic":                                resourceAwsSnsTopic(),
   344  			"aws_sns_topic_policy":                         resourceAwsSnsTopicPolicy(),
   345  			"aws_sns_topic_subscription":                   resourceAwsSnsTopicSubscription(),
   346  			"aws_subnet":                                   resourceAwsSubnet(),
   347  			"aws_volume_attachment":                        resourceAwsVolumeAttachment(),
   348  			"aws_vpc_dhcp_options_association":             resourceAwsVpcDhcpOptionsAssociation(),
   349  			"aws_vpc_dhcp_options":                         resourceAwsVpcDhcpOptions(),
   350  			"aws_vpc_peering_connection":                   resourceAwsVpcPeeringConnection(),
   351  			"aws_vpc":                                      resourceAwsVpc(),
   352  			"aws_vpc_endpoint":                             resourceAwsVpcEndpoint(),
   353  			"aws_vpn_connection":                           resourceAwsVpnConnection(),
   354  			"aws_vpn_connection_route":                     resourceAwsVpnConnectionRoute(),
   355  			"aws_vpn_gateway":                              resourceAwsVpnGateway(),
   356  			"aws_vpn_gateway_attachment":                   resourceAwsVpnGatewayAttachment(),
   357  			"aws_waf_byte_match_set":                       resourceAwsWafByteMatchSet(),
   358  			"aws_waf_ipset":                                resourceAwsWafIPSet(),
   359  			"aws_waf_rule":                                 resourceAwsWafRule(),
   360  			"aws_waf_size_constraint_set":                  resourceAwsWafSizeConstraintSet(),
   361  			"aws_waf_web_acl":                              resourceAwsWafWebAcl(),
   362  		},
   363  		ConfigureFunc: providerConfigure,
   364  	}
   365  }
   366  
   367  var descriptions map[string]string
   368  
   369  func init() {
   370  	descriptions = map[string]string{
   371  		"region": "The region where AWS operations will take place. Examples\n" +
   372  			"are us-east-1, us-west-2, etc.",
   373  
   374  		"access_key": "The access key for API operations. You can retrieve this\n" +
   375  			"from the 'Security & Credentials' section of the AWS console.",
   376  
   377  		"secret_key": "The secret key for API operations. You can retrieve this\n" +
   378  			"from the 'Security & Credentials' section of the AWS console.",
   379  
   380  		"profile": "The profile for API operations. If not set, the default profile\n" +
   381  			"created with `aws configure` will be used.",
   382  
   383  		"shared_credentials_file": "The path to the shared credentials file. If not set\n" +
   384  			"this defaults to ~/.aws/credentials.",
   385  
   386  		"token": "session token. A session token is only required if you are\n" +
   387  			"using temporary security credentials.",
   388  
   389  		"max_retries": "The maximum number of times an AWS API request is\n" +
   390  			"being executed. If the API request still fails, an error is\n" +
   391  			"thrown.",
   392  
   393  		"dynamodb_endpoint": "Use this to override the default endpoint URL constructed from the `region`.\n" +
   394  			"It's typically used to connect to dynamodb-local.",
   395  
   396  		"kinesis_endpoint": "Use this to override the default endpoint URL constructed from the `region`.\n" +
   397  			"It's typically used to connect to kinesalite.",
   398  
   399  		"iam_endpoint": "Use this to override the default endpoint URL constructed from the `region`.\n",
   400  
   401  		"ec2_endpoint": "Use this to override the default endpoint URL constructed from the `region`.\n",
   402  
   403  		"elb_endpoint": "Use this to override the default endpoint URL constructed from the `region`.\n",
   404  
   405  		"s3_endpoint": "Use this to override the default endpoint URL constructed from the `region`.\n",
   406  
   407  		"insecure": "Explicitly allow the provider to perform \"insecure\" SSL requests. If omitted," +
   408  			"default value is `false`",
   409  
   410  		"skip_credentials_validation": "Skip the credentials validation via STS API. " +
   411  			"Used for AWS API implementations that do not have STS available/implemented.",
   412  
   413  		"skip_requesting_account_id": "Skip requesting the account ID. " +
   414  			"Used for AWS API implementations that do not have IAM/STS API and/or metadata API.",
   415  
   416  		"skip_medatadata_api_check": "Skip the AWS Metadata API check. " +
   417  			"Used for AWS API implementations that do not have a metadata api endpoint.",
   418  
   419  		"s3_force_path_style": "Set this to true to force the request to use path-style addressing,\n" +
   420  			"i.e., http://s3.amazonaws.com/BUCKET/KEY. By default, the S3 client will\n" +
   421  			"use virtual hosted bucket addressing when possible\n" +
   422  			"(http://BUCKET.s3.amazonaws.com/KEY). Specific to the Amazon S3 service.",
   423  
   424  		"assume_role_role_arn": "The ARN of an IAM role to assume prior to making API calls.",
   425  
   426  		"assume_role_session_name": "The session name to use when assuming the role. If omitted," +
   427  			" no session name is passed to the AssumeRole call.",
   428  
   429  		"assume_role_external_id": "The external ID to use when assuming the role. If omitted," +
   430  			" no external ID is passed to the AssumeRole call.",
   431  	}
   432  }
   433  
   434  func providerConfigure(d *schema.ResourceData) (interface{}, error) {
   435  	config := Config{
   436  		AccessKey:               d.Get("access_key").(string),
   437  		SecretKey:               d.Get("secret_key").(string),
   438  		Profile:                 d.Get("profile").(string),
   439  		CredsFilename:           d.Get("shared_credentials_file").(string),
   440  		Token:                   d.Get("token").(string),
   441  		Region:                  d.Get("region").(string),
   442  		MaxRetries:              d.Get("max_retries").(int),
   443  		DynamoDBEndpoint:        d.Get("dynamodb_endpoint").(string),
   444  		KinesisEndpoint:         d.Get("kinesis_endpoint").(string),
   445  		Insecure:                d.Get("insecure").(bool),
   446  		SkipCredsValidation:     d.Get("skip_credentials_validation").(bool),
   447  		SkipRequestingAccountId: d.Get("skip_requesting_account_id").(bool),
   448  		SkipMetadataApiCheck:    d.Get("skip_metadata_api_check").(bool),
   449  		S3ForcePathStyle:        d.Get("s3_force_path_style").(bool),
   450  	}
   451  
   452  	assumeRoleList := d.Get("assume_role").(*schema.Set).List()
   453  	if len(assumeRoleList) == 1 {
   454  		assumeRole := assumeRoleList[0].(map[string]interface{})
   455  		config.AssumeRoleARN = assumeRole["role_arn"].(string)
   456  		config.AssumeRoleSessionName = assumeRole["session_name"].(string)
   457  		config.AssumeRoleExternalID = assumeRole["external_id"].(string)
   458  		log.Printf("[INFO] assume_role configuration set: (ARN: %q, SessionID: %q, ExternalID: %q)",
   459  			config.AssumeRoleARN, config.AssumeRoleSessionName, config.AssumeRoleExternalID)
   460  	} else {
   461  		log.Printf("[INFO] No assume_role block read from configuration")
   462  	}
   463  
   464  	endpointsSet := d.Get("endpoints").(*schema.Set)
   465  
   466  	for _, endpointsSetI := range endpointsSet.List() {
   467  		endpoints := endpointsSetI.(map[string]interface{})
   468  		config.IamEndpoint = endpoints["iam"].(string)
   469  		config.Ec2Endpoint = endpoints["ec2"].(string)
   470  		config.ElbEndpoint = endpoints["elb"].(string)
   471  		config.S3Endpoint = endpoints["s3"].(string)
   472  	}
   473  
   474  	if v, ok := d.GetOk("allowed_account_ids"); ok {
   475  		config.AllowedAccountIds = v.(*schema.Set).List()
   476  	}
   477  
   478  	if v, ok := d.GetOk("forbidden_account_ids"); ok {
   479  		config.ForbiddenAccountIds = v.(*schema.Set).List()
   480  	}
   481  
   482  	return config.Client()
   483  }
   484  
   485  // This is a global MutexKV for use within this plugin.
   486  var awsMutexKV = mutexkv.NewMutexKV()
   487  
   488  func assumeRoleSchema() *schema.Schema {
   489  	return &schema.Schema{
   490  		Type:     schema.TypeSet,
   491  		Optional: true,
   492  		MaxItems: 1,
   493  		Elem: &schema.Resource{
   494  			Schema: map[string]*schema.Schema{
   495  				"role_arn": {
   496  					Type:        schema.TypeString,
   497  					Optional:    true,
   498  					Description: descriptions["assume_role_role_arn"],
   499  				},
   500  
   501  				"session_name": {
   502  					Type:        schema.TypeString,
   503  					Optional:    true,
   504  					Description: descriptions["assume_role_session_name"],
   505  				},
   506  
   507  				"external_id": {
   508  					Type:        schema.TypeString,
   509  					Optional:    true,
   510  					Description: descriptions["assume_role_external_id"],
   511  				},
   512  			},
   513  		},
   514  		Set: assumeRoleToHash,
   515  	}
   516  }
   517  
   518  func assumeRoleToHash(v interface{}) int {
   519  	var buf bytes.Buffer
   520  	m := v.(map[string]interface{})
   521  	buf.WriteString(fmt.Sprintf("%s-", m["role_arn"].(string)))
   522  	buf.WriteString(fmt.Sprintf("%s-", m["session_name"].(string)))
   523  	buf.WriteString(fmt.Sprintf("%s-", m["external_id"].(string)))
   524  	return hashcode.String(buf.String())
   525  }
   526  
   527  func endpointsSchema() *schema.Schema {
   528  	return &schema.Schema{
   529  		Type:     schema.TypeSet,
   530  		Optional: true,
   531  		Elem: &schema.Resource{
   532  			Schema: map[string]*schema.Schema{
   533  				"iam": {
   534  					Type:        schema.TypeString,
   535  					Optional:    true,
   536  					Default:     "",
   537  					Description: descriptions["iam_endpoint"],
   538  				},
   539  
   540  				"ec2": {
   541  					Type:        schema.TypeString,
   542  					Optional:    true,
   543  					Default:     "",
   544  					Description: descriptions["ec2_endpoint"],
   545  				},
   546  
   547  				"elb": {
   548  					Type:        schema.TypeString,
   549  					Optional:    true,
   550  					Default:     "",
   551  					Description: descriptions["elb_endpoint"],
   552  				},
   553  				"s3": {
   554  					Type:        schema.TypeString,
   555  					Optional:    true,
   556  					Default:     "",
   557  					Description: descriptions["s3_endpoint"],
   558  				},
   559  			},
   560  		},
   561  		Set: endpointsToHash,
   562  	}
   563  }
   564  
   565  func endpointsToHash(v interface{}) int {
   566  	var buf bytes.Buffer
   567  	m := v.(map[string]interface{})
   568  	buf.WriteString(fmt.Sprintf("%s-", m["iam"].(string)))
   569  	buf.WriteString(fmt.Sprintf("%s-", m["ec2"].(string)))
   570  	buf.WriteString(fmt.Sprintf("%s-", m["elb"].(string)))
   571  	buf.WriteString(fmt.Sprintf("%s-", m["s3"].(string)))
   572  
   573  	return hashcode.String(buf.String())
   574  }