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