github.com/jrperritt/terraform@v0.1.1-0.20170525065507-96f391dafc38/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:     25,
    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  				Removed:     "Use `dynamodb` inside `endpoints` block instead",
    99  			},
   100  
   101  			"kinesis_endpoint": {
   102  				Type:        schema.TypeString,
   103  				Optional:    true,
   104  				Default:     "",
   105  				Description: descriptions["kinesis_endpoint"],
   106  				Removed:     "Use `kinesis` inside `endpoints` block instead",
   107  			},
   108  
   109  			"endpoints": endpointsSchema(),
   110  
   111  			"insecure": {
   112  				Type:        schema.TypeBool,
   113  				Optional:    true,
   114  				Default:     false,
   115  				Description: descriptions["insecure"],
   116  			},
   117  
   118  			"skip_credentials_validation": {
   119  				Type:        schema.TypeBool,
   120  				Optional:    true,
   121  				Default:     false,
   122  				Description: descriptions["skip_credentials_validation"],
   123  			},
   124  
   125  			"skip_get_ec2_platforms": {
   126  				Type:        schema.TypeBool,
   127  				Optional:    true,
   128  				Default:     false,
   129  				Description: descriptions["skip_get_ec2_platforms"],
   130  			},
   131  
   132  			"skip_region_validation": {
   133  				Type:        schema.TypeBool,
   134  				Optional:    true,
   135  				Default:     false,
   136  				Description: descriptions["skip_region_validation"],
   137  			},
   138  
   139  			"skip_requesting_account_id": {
   140  				Type:        schema.TypeBool,
   141  				Optional:    true,
   142  				Default:     false,
   143  				Description: descriptions["skip_requesting_account_id"],
   144  			},
   145  
   146  			"skip_metadata_api_check": {
   147  				Type:        schema.TypeBool,
   148  				Optional:    true,
   149  				Default:     false,
   150  				Description: descriptions["skip_metadata_api_check"],
   151  			},
   152  
   153  			"s3_force_path_style": {
   154  				Type:        schema.TypeBool,
   155  				Optional:    true,
   156  				Default:     false,
   157  				Description: descriptions["s3_force_path_style"],
   158  			},
   159  		},
   160  
   161  		DataSourcesMap: map[string]*schema.Resource{
   162  			"aws_acm_certificate":          dataSourceAwsAcmCertificate(),
   163  			"aws_alb":                      dataSourceAwsAlb(),
   164  			"aws_alb_listener":             dataSourceAwsAlbListener(),
   165  			"aws_ami":                      dataSourceAwsAmi(),
   166  			"aws_ami_ids":                  dataSourceAwsAmiIds(),
   167  			"aws_autoscaling_groups":       dataSourceAwsAutoscalingGroups(),
   168  			"aws_availability_zone":        dataSourceAwsAvailabilityZone(),
   169  			"aws_availability_zones":       dataSourceAwsAvailabilityZones(),
   170  			"aws_billing_service_account":  dataSourceAwsBillingServiceAccount(),
   171  			"aws_caller_identity":          dataSourceAwsCallerIdentity(),
   172  			"aws_canonical_user_id":        dataSourceAwsCanonicalUserId(),
   173  			"aws_cloudformation_stack":     dataSourceAwsCloudFormationStack(),
   174  			"aws_db_instance":              dataSourceAwsDbInstance(),
   175  			"aws_db_snapshot":              dataSourceAwsDbSnapshot(),
   176  			"aws_ebs_snapshot":             dataSourceAwsEbsSnapshot(),
   177  			"aws_ebs_snapshot_ids":         dataSourceAwsEbsSnapshotIds(),
   178  			"aws_ebs_volume":               dataSourceAwsEbsVolume(),
   179  			"aws_ecs_cluster":              dataSourceAwsEcsCluster(),
   180  			"aws_ecs_container_definition": dataSourceAwsEcsContainerDefinition(),
   181  			"aws_ecs_task_definition":      dataSourceAwsEcsTaskDefinition(),
   182  			"aws_efs_file_system":          dataSourceAwsEfsFileSystem(),
   183  			"aws_eip":                      dataSourceAwsEip(),
   184  			"aws_elb_hosted_zone_id":       dataSourceAwsElbHostedZoneId(),
   185  			"aws_elb_service_account":      dataSourceAwsElbServiceAccount(),
   186  			"aws_iam_account_alias":        dataSourceAwsIamAccountAlias(),
   187  			"aws_iam_policy_document":      dataSourceAwsIamPolicyDocument(),
   188  			"aws_iam_role":                 dataSourceAwsIAMRole(),
   189  			"aws_iam_server_certificate":   dataSourceAwsIAMServerCertificate(),
   190  			"aws_instance":                 dataSourceAwsInstance(),
   191  			"aws_ip_ranges":                dataSourceAwsIPRanges(),
   192  			"aws_kinesis_stream":           dataSourceAwsKinesisStream(),
   193  			"aws_kms_alias":                dataSourceAwsKmsAlias(),
   194  			"aws_kms_ciphertext":           dataSourceAwsKmsCiphetext(),
   195  			"aws_kms_secret":               dataSourceAwsKmsSecret(),
   196  			"aws_partition":                dataSourceAwsPartition(),
   197  			"aws_prefix_list":              dataSourceAwsPrefixList(),
   198  			"aws_redshift_service_account": dataSourceAwsRedshiftServiceAccount(),
   199  			"aws_region":                   dataSourceAwsRegion(),
   200  			"aws_route_table":              dataSourceAwsRouteTable(),
   201  			"aws_route53_zone":             dataSourceAwsRoute53Zone(),
   202  			"aws_s3_bucket_object":         dataSourceAwsS3BucketObject(),
   203  			"aws_sns_topic":                dataSourceAwsSnsTopic(),
   204  			"aws_subnet":                   dataSourceAwsSubnet(),
   205  			"aws_subnet_ids":               dataSourceAwsSubnetIDs(),
   206  			"aws_security_group":           dataSourceAwsSecurityGroup(),
   207  			"aws_vpc":                      dataSourceAwsVpc(),
   208  			"aws_vpc_endpoint":             dataSourceAwsVpcEndpoint(),
   209  			"aws_vpc_endpoint_service":     dataSourceAwsVpcEndpointService(),
   210  			"aws_vpc_peering_connection":   dataSourceAwsVpcPeeringConnection(),
   211  			"aws_vpn_gateway":              dataSourceAwsVpnGateway(),
   212  		},
   213  
   214  		ResourcesMap: map[string]*schema.Resource{
   215  			"aws_alb":                                      resourceAwsAlb(),
   216  			"aws_alb_listener":                             resourceAwsAlbListener(),
   217  			"aws_alb_listener_rule":                        resourceAwsAlbListenerRule(),
   218  			"aws_alb_target_group":                         resourceAwsAlbTargetGroup(),
   219  			"aws_alb_target_group_attachment":              resourceAwsAlbTargetGroupAttachment(),
   220  			"aws_ami":                                      resourceAwsAmi(),
   221  			"aws_ami_copy":                                 resourceAwsAmiCopy(),
   222  			"aws_ami_from_instance":                        resourceAwsAmiFromInstance(),
   223  			"aws_ami_launch_permission":                    resourceAwsAmiLaunchPermission(),
   224  			"aws_api_gateway_account":                      resourceAwsApiGatewayAccount(),
   225  			"aws_api_gateway_api_key":                      resourceAwsApiGatewayApiKey(),
   226  			"aws_api_gateway_authorizer":                   resourceAwsApiGatewayAuthorizer(),
   227  			"aws_api_gateway_base_path_mapping":            resourceAwsApiGatewayBasePathMapping(),
   228  			"aws_api_gateway_client_certificate":           resourceAwsApiGatewayClientCertificate(),
   229  			"aws_api_gateway_deployment":                   resourceAwsApiGatewayDeployment(),
   230  			"aws_api_gateway_domain_name":                  resourceAwsApiGatewayDomainName(),
   231  			"aws_api_gateway_integration":                  resourceAwsApiGatewayIntegration(),
   232  			"aws_api_gateway_integration_response":         resourceAwsApiGatewayIntegrationResponse(),
   233  			"aws_api_gateway_method":                       resourceAwsApiGatewayMethod(),
   234  			"aws_api_gateway_method_response":              resourceAwsApiGatewayMethodResponse(),
   235  			"aws_api_gateway_method_settings":              resourceAwsApiGatewayMethodSettings(),
   236  			"aws_api_gateway_model":                        resourceAwsApiGatewayModel(),
   237  			"aws_api_gateway_resource":                     resourceAwsApiGatewayResource(),
   238  			"aws_api_gateway_rest_api":                     resourceAwsApiGatewayRestApi(),
   239  			"aws_api_gateway_stage":                        resourceAwsApiGatewayStage(),
   240  			"aws_api_gateway_usage_plan":                   resourceAwsApiGatewayUsagePlan(),
   241  			"aws_api_gateway_usage_plan_key":               resourceAwsApiGatewayUsagePlanKey(),
   242  			"aws_app_cookie_stickiness_policy":             resourceAwsAppCookieStickinessPolicy(),
   243  			"aws_appautoscaling_target":                    resourceAwsAppautoscalingTarget(),
   244  			"aws_appautoscaling_policy":                    resourceAwsAppautoscalingPolicy(),
   245  			"aws_autoscaling_attachment":                   resourceAwsAutoscalingAttachment(),
   246  			"aws_autoscaling_group":                        resourceAwsAutoscalingGroup(),
   247  			"aws_autoscaling_notification":                 resourceAwsAutoscalingNotification(),
   248  			"aws_autoscaling_policy":                       resourceAwsAutoscalingPolicy(),
   249  			"aws_autoscaling_schedule":                     resourceAwsAutoscalingSchedule(),
   250  			"aws_cloudformation_stack":                     resourceAwsCloudFormationStack(),
   251  			"aws_cloudfront_distribution":                  resourceAwsCloudFrontDistribution(),
   252  			"aws_cloudfront_origin_access_identity":        resourceAwsCloudFrontOriginAccessIdentity(),
   253  			"aws_cloudtrail":                               resourceAwsCloudTrail(),
   254  			"aws_cloudwatch_event_rule":                    resourceAwsCloudWatchEventRule(),
   255  			"aws_cloudwatch_event_target":                  resourceAwsCloudWatchEventTarget(),
   256  			"aws_cloudwatch_log_destination":               resourceAwsCloudWatchLogDestination(),
   257  			"aws_cloudwatch_log_destination_policy":        resourceAwsCloudWatchLogDestinationPolicy(),
   258  			"aws_cloudwatch_log_group":                     resourceAwsCloudWatchLogGroup(),
   259  			"aws_cloudwatch_log_metric_filter":             resourceAwsCloudWatchLogMetricFilter(),
   260  			"aws_cloudwatch_log_stream":                    resourceAwsCloudWatchLogStream(),
   261  			"aws_cloudwatch_log_subscription_filter":       resourceAwsCloudwatchLogSubscriptionFilter(),
   262  			"aws_config_config_rule":                       resourceAwsConfigConfigRule(),
   263  			"aws_config_configuration_recorder":            resourceAwsConfigConfigurationRecorder(),
   264  			"aws_config_configuration_recorder_status":     resourceAwsConfigConfigurationRecorderStatus(),
   265  			"aws_config_delivery_channel":                  resourceAwsConfigDeliveryChannel(),
   266  			"aws_cognito_identity_pool":                    resourceAwsCognitoIdentityPool(),
   267  			"aws_autoscaling_lifecycle_hook":               resourceAwsAutoscalingLifecycleHook(),
   268  			"aws_cloudwatch_metric_alarm":                  resourceAwsCloudWatchMetricAlarm(),
   269  			"aws_codedeploy_app":                           resourceAwsCodeDeployApp(),
   270  			"aws_codedeploy_deployment_config":             resourceAwsCodeDeployDeploymentConfig(),
   271  			"aws_codedeploy_deployment_group":              resourceAwsCodeDeployDeploymentGroup(),
   272  			"aws_codecommit_repository":                    resourceAwsCodeCommitRepository(),
   273  			"aws_codecommit_trigger":                       resourceAwsCodeCommitTrigger(),
   274  			"aws_codebuild_project":                        resourceAwsCodeBuildProject(),
   275  			"aws_codepipeline":                             resourceAwsCodePipeline(),
   276  			"aws_customer_gateway":                         resourceAwsCustomerGateway(),
   277  			"aws_db_event_subscription":                    resourceAwsDbEventSubscription(),
   278  			"aws_db_instance":                              resourceAwsDbInstance(),
   279  			"aws_db_option_group":                          resourceAwsDbOptionGroup(),
   280  			"aws_db_parameter_group":                       resourceAwsDbParameterGroup(),
   281  			"aws_db_security_group":                        resourceAwsDbSecurityGroup(),
   282  			"aws_db_snapshot":                              resourceAwsDbSnapshot(),
   283  			"aws_db_subnet_group":                          resourceAwsDbSubnetGroup(),
   284  			"aws_devicefarm_project":                       resourceAwsDevicefarmProject(),
   285  			"aws_directory_service_directory":              resourceAwsDirectoryServiceDirectory(),
   286  			"aws_dms_certificate":                          resourceAwsDmsCertificate(),
   287  			"aws_dms_endpoint":                             resourceAwsDmsEndpoint(),
   288  			"aws_dms_replication_instance":                 resourceAwsDmsReplicationInstance(),
   289  			"aws_dms_replication_subnet_group":             resourceAwsDmsReplicationSubnetGroup(),
   290  			"aws_dms_replication_task":                     resourceAwsDmsReplicationTask(),
   291  			"aws_dynamodb_table":                           resourceAwsDynamoDbTable(),
   292  			"aws_ebs_snapshot":                             resourceAwsEbsSnapshot(),
   293  			"aws_ebs_volume":                               resourceAwsEbsVolume(),
   294  			"aws_ecr_repository":                           resourceAwsEcrRepository(),
   295  			"aws_ecr_repository_policy":                    resourceAwsEcrRepositoryPolicy(),
   296  			"aws_ecs_cluster":                              resourceAwsEcsCluster(),
   297  			"aws_ecs_service":                              resourceAwsEcsService(),
   298  			"aws_ecs_task_definition":                      resourceAwsEcsTaskDefinition(),
   299  			"aws_efs_file_system":                          resourceAwsEfsFileSystem(),
   300  			"aws_efs_mount_target":                         resourceAwsEfsMountTarget(),
   301  			"aws_egress_only_internet_gateway":             resourceAwsEgressOnlyInternetGateway(),
   302  			"aws_eip":                                      resourceAwsEip(),
   303  			"aws_eip_association":                          resourceAwsEipAssociation(),
   304  			"aws_elasticache_cluster":                      resourceAwsElasticacheCluster(),
   305  			"aws_elasticache_parameter_group":              resourceAwsElasticacheParameterGroup(),
   306  			"aws_elasticache_replication_group":            resourceAwsElasticacheReplicationGroup(),
   307  			"aws_elasticache_security_group":               resourceAwsElasticacheSecurityGroup(),
   308  			"aws_elasticache_subnet_group":                 resourceAwsElasticacheSubnetGroup(),
   309  			"aws_elastic_beanstalk_application":            resourceAwsElasticBeanstalkApplication(),
   310  			"aws_elastic_beanstalk_application_version":    resourceAwsElasticBeanstalkApplicationVersion(),
   311  			"aws_elastic_beanstalk_configuration_template": resourceAwsElasticBeanstalkConfigurationTemplate(),
   312  			"aws_elastic_beanstalk_environment":            resourceAwsElasticBeanstalkEnvironment(),
   313  			"aws_elasticsearch_domain":                     resourceAwsElasticSearchDomain(),
   314  			"aws_elasticsearch_domain_policy":              resourceAwsElasticSearchDomainPolicy(),
   315  			"aws_elastictranscoder_pipeline":               resourceAwsElasticTranscoderPipeline(),
   316  			"aws_elastictranscoder_preset":                 resourceAwsElasticTranscoderPreset(),
   317  			"aws_elb":                                      resourceAwsElb(),
   318  			"aws_elb_attachment":                           resourceAwsElbAttachment(),
   319  			"aws_emr_cluster":                              resourceAwsEMRCluster(),
   320  			"aws_emr_instance_group":                       resourceAwsEMRInstanceGroup(),
   321  			"aws_emr_security_configuration":               resourceAwsEMRSecurityConfiguration(),
   322  			"aws_flow_log":                                 resourceAwsFlowLog(),
   323  			"aws_glacier_vault":                            resourceAwsGlacierVault(),
   324  			"aws_iam_access_key":                           resourceAwsIamAccessKey(),
   325  			"aws_iam_account_alias":                        resourceAwsIamAccountAlias(),
   326  			"aws_iam_account_password_policy":              resourceAwsIamAccountPasswordPolicy(),
   327  			"aws_iam_group_policy":                         resourceAwsIamGroupPolicy(),
   328  			"aws_iam_group":                                resourceAwsIamGroup(),
   329  			"aws_iam_group_membership":                     resourceAwsIamGroupMembership(),
   330  			"aws_iam_group_policy_attachment":              resourceAwsIamGroupPolicyAttachment(),
   331  			"aws_iam_instance_profile":                     resourceAwsIamInstanceProfile(),
   332  			"aws_iam_openid_connect_provider":              resourceAwsIamOpenIDConnectProvider(),
   333  			"aws_iam_policy":                               resourceAwsIamPolicy(),
   334  			"aws_iam_policy_attachment":                    resourceAwsIamPolicyAttachment(),
   335  			"aws_iam_role_policy_attachment":               resourceAwsIamRolePolicyAttachment(),
   336  			"aws_iam_role_policy":                          resourceAwsIamRolePolicy(),
   337  			"aws_iam_role":                                 resourceAwsIamRole(),
   338  			"aws_iam_saml_provider":                        resourceAwsIamSamlProvider(),
   339  			"aws_iam_server_certificate":                   resourceAwsIAMServerCertificate(),
   340  			"aws_iam_user_policy_attachment":               resourceAwsIamUserPolicyAttachment(),
   341  			"aws_iam_user_policy":                          resourceAwsIamUserPolicy(),
   342  			"aws_iam_user_ssh_key":                         resourceAwsIamUserSshKey(),
   343  			"aws_iam_user":                                 resourceAwsIamUser(),
   344  			"aws_iam_user_login_profile":                   resourceAwsIamUserLoginProfile(),
   345  			"aws_inspector_assessment_target":              resourceAWSInspectorAssessmentTarget(),
   346  			"aws_inspector_assessment_template":            resourceAWSInspectorAssessmentTemplate(),
   347  			"aws_inspector_resource_group":                 resourceAWSInspectorResourceGroup(),
   348  			"aws_instance":                                 resourceAwsInstance(),
   349  			"aws_internet_gateway":                         resourceAwsInternetGateway(),
   350  			"aws_key_pair":                                 resourceAwsKeyPair(),
   351  			"aws_kinesis_firehose_delivery_stream":         resourceAwsKinesisFirehoseDeliveryStream(),
   352  			"aws_kinesis_stream":                           resourceAwsKinesisStream(),
   353  			"aws_kms_alias":                                resourceAwsKmsAlias(),
   354  			"aws_kms_key":                                  resourceAwsKmsKey(),
   355  			"aws_lambda_function":                          resourceAwsLambdaFunction(),
   356  			"aws_lambda_event_source_mapping":              resourceAwsLambdaEventSourceMapping(),
   357  			"aws_lambda_alias":                             resourceAwsLambdaAlias(),
   358  			"aws_lambda_permission":                        resourceAwsLambdaPermission(),
   359  			"aws_launch_configuration":                     resourceAwsLaunchConfiguration(),
   360  			"aws_lightsail_domain":                         resourceAwsLightsailDomain(),
   361  			"aws_lightsail_instance":                       resourceAwsLightsailInstance(),
   362  			"aws_lightsail_key_pair":                       resourceAwsLightsailKeyPair(),
   363  			"aws_lightsail_static_ip":                      resourceAwsLightsailStaticIp(),
   364  			"aws_lightsail_static_ip_attachment":           resourceAwsLightsailStaticIpAttachment(),
   365  			"aws_lb_cookie_stickiness_policy":              resourceAwsLBCookieStickinessPolicy(),
   366  			"aws_load_balancer_policy":                     resourceAwsLoadBalancerPolicy(),
   367  			"aws_load_balancer_backend_server_policy":      resourceAwsLoadBalancerBackendServerPolicies(),
   368  			"aws_load_balancer_listener_policy":            resourceAwsLoadBalancerListenerPolicies(),
   369  			"aws_lb_ssl_negotiation_policy":                resourceAwsLBSSLNegotiationPolicy(),
   370  			"aws_main_route_table_association":             resourceAwsMainRouteTableAssociation(),
   371  			"aws_nat_gateway":                              resourceAwsNatGateway(),
   372  			"aws_network_acl":                              resourceAwsNetworkAcl(),
   373  			"aws_default_network_acl":                      resourceAwsDefaultNetworkAcl(),
   374  			"aws_network_acl_rule":                         resourceAwsNetworkAclRule(),
   375  			"aws_network_interface":                        resourceAwsNetworkInterface(),
   376  			"aws_network_interface_attachment":             resourceAwsNetworkInterfaceAttachment(),
   377  			"aws_opsworks_application":                     resourceAwsOpsworksApplication(),
   378  			"aws_opsworks_stack":                           resourceAwsOpsworksStack(),
   379  			"aws_opsworks_java_app_layer":                  resourceAwsOpsworksJavaAppLayer(),
   380  			"aws_opsworks_haproxy_layer":                   resourceAwsOpsworksHaproxyLayer(),
   381  			"aws_opsworks_static_web_layer":                resourceAwsOpsworksStaticWebLayer(),
   382  			"aws_opsworks_php_app_layer":                   resourceAwsOpsworksPhpAppLayer(),
   383  			"aws_opsworks_rails_app_layer":                 resourceAwsOpsworksRailsAppLayer(),
   384  			"aws_opsworks_nodejs_app_layer":                resourceAwsOpsworksNodejsAppLayer(),
   385  			"aws_opsworks_memcached_layer":                 resourceAwsOpsworksMemcachedLayer(),
   386  			"aws_opsworks_mysql_layer":                     resourceAwsOpsworksMysqlLayer(),
   387  			"aws_opsworks_ganglia_layer":                   resourceAwsOpsworksGangliaLayer(),
   388  			"aws_opsworks_custom_layer":                    resourceAwsOpsworksCustomLayer(),
   389  			"aws_opsworks_instance":                        resourceAwsOpsworksInstance(),
   390  			"aws_opsworks_user_profile":                    resourceAwsOpsworksUserProfile(),
   391  			"aws_opsworks_permission":                      resourceAwsOpsworksPermission(),
   392  			"aws_opsworks_rds_db_instance":                 resourceAwsOpsworksRdsDbInstance(),
   393  			"aws_placement_group":                          resourceAwsPlacementGroup(),
   394  			"aws_proxy_protocol_policy":                    resourceAwsProxyProtocolPolicy(),
   395  			"aws_rds_cluster":                              resourceAwsRDSCluster(),
   396  			"aws_rds_cluster_instance":                     resourceAwsRDSClusterInstance(),
   397  			"aws_rds_cluster_parameter_group":              resourceAwsRDSClusterParameterGroup(),
   398  			"aws_redshift_cluster":                         resourceAwsRedshiftCluster(),
   399  			"aws_redshift_security_group":                  resourceAwsRedshiftSecurityGroup(),
   400  			"aws_redshift_parameter_group":                 resourceAwsRedshiftParameterGroup(),
   401  			"aws_redshift_subnet_group":                    resourceAwsRedshiftSubnetGroup(),
   402  			"aws_route53_delegation_set":                   resourceAwsRoute53DelegationSet(),
   403  			"aws_route53_record":                           resourceAwsRoute53Record(),
   404  			"aws_route53_zone_association":                 resourceAwsRoute53ZoneAssociation(),
   405  			"aws_route53_zone":                             resourceAwsRoute53Zone(),
   406  			"aws_route53_health_check":                     resourceAwsRoute53HealthCheck(),
   407  			"aws_route":                                    resourceAwsRoute(),
   408  			"aws_route_table":                              resourceAwsRouteTable(),
   409  			"aws_default_route_table":                      resourceAwsDefaultRouteTable(),
   410  			"aws_route_table_association":                  resourceAwsRouteTableAssociation(),
   411  			"aws_ses_active_receipt_rule_set":              resourceAwsSesActiveReceiptRuleSet(),
   412  			"aws_ses_domain_identity":                      resourceAwsSesDomainIdentity(),
   413  			"aws_ses_receipt_filter":                       resourceAwsSesReceiptFilter(),
   414  			"aws_ses_receipt_rule":                         resourceAwsSesReceiptRule(),
   415  			"aws_ses_receipt_rule_set":                     resourceAwsSesReceiptRuleSet(),
   416  			"aws_ses_configuration_set":                    resourceAwsSesConfigurationSet(),
   417  			"aws_ses_event_destination":                    resourceAwsSesEventDestination(),
   418  			"aws_s3_bucket":                                resourceAwsS3Bucket(),
   419  			"aws_s3_bucket_policy":                         resourceAwsS3BucketPolicy(),
   420  			"aws_s3_bucket_object":                         resourceAwsS3BucketObject(),
   421  			"aws_s3_bucket_notification":                   resourceAwsS3BucketNotification(),
   422  			"aws_security_group":                           resourceAwsSecurityGroup(),
   423  			"aws_default_security_group":                   resourceAwsDefaultSecurityGroup(),
   424  			"aws_security_group_rule":                      resourceAwsSecurityGroupRule(),
   425  			"aws_simpledb_domain":                          resourceAwsSimpleDBDomain(),
   426  			"aws_ssm_activation":                           resourceAwsSsmActivation(),
   427  			"aws_ssm_association":                          resourceAwsSsmAssociation(),
   428  			"aws_ssm_document":                             resourceAwsSsmDocument(),
   429  			"aws_ssm_maintenance_window":                   resourceAwsSsmMaintenanceWindow(),
   430  			"aws_ssm_maintenance_window_target":            resourceAwsSsmMaintenanceWindowTarget(),
   431  			"aws_ssm_maintenance_window_task":              resourceAwsSsmMaintenanceWindowTask(),
   432  			"aws_spot_datafeed_subscription":               resourceAwsSpotDataFeedSubscription(),
   433  			"aws_spot_instance_request":                    resourceAwsSpotInstanceRequest(),
   434  			"aws_spot_fleet_request":                       resourceAwsSpotFleetRequest(),
   435  			"aws_sqs_queue":                                resourceAwsSqsQueue(),
   436  			"aws_sqs_queue_policy":                         resourceAwsSqsQueuePolicy(),
   437  			"aws_snapshot_create_volume_permission":        resourceAwsSnapshotCreateVolumePermission(),
   438  			"aws_sns_topic":                                resourceAwsSnsTopic(),
   439  			"aws_sns_topic_policy":                         resourceAwsSnsTopicPolicy(),
   440  			"aws_sns_topic_subscription":                   resourceAwsSnsTopicSubscription(),
   441  			"aws_sfn_activity":                             resourceAwsSfnActivity(),
   442  			"aws_sfn_state_machine":                        resourceAwsSfnStateMachine(),
   443  			"aws_default_subnet":                           resourceAwsDefaultSubnet(),
   444  			"aws_subnet":                                   resourceAwsSubnet(),
   445  			"aws_volume_attachment":                        resourceAwsVolumeAttachment(),
   446  			"aws_vpc_dhcp_options_association":             resourceAwsVpcDhcpOptionsAssociation(),
   447  			"aws_default_vpc_dhcp_options":                 resourceAwsDefaultVpcDhcpOptions(),
   448  			"aws_vpc_dhcp_options":                         resourceAwsVpcDhcpOptions(),
   449  			"aws_vpc_peering_connection":                   resourceAwsVpcPeeringConnection(),
   450  			"aws_vpc_peering_connection_accepter":          resourceAwsVpcPeeringConnectionAccepter(),
   451  			"aws_default_vpc":                              resourceAwsDefaultVpc(),
   452  			"aws_vpc":                                      resourceAwsVpc(),
   453  			"aws_vpc_endpoint":                             resourceAwsVpcEndpoint(),
   454  			"aws_vpc_endpoint_route_table_association":     resourceAwsVpcEndpointRouteTableAssociation(),
   455  			"aws_vpn_connection":                           resourceAwsVpnConnection(),
   456  			"aws_vpn_connection_route":                     resourceAwsVpnConnectionRoute(),
   457  			"aws_vpn_gateway":                              resourceAwsVpnGateway(),
   458  			"aws_vpn_gateway_attachment":                   resourceAwsVpnGatewayAttachment(),
   459  			"aws_waf_byte_match_set":                       resourceAwsWafByteMatchSet(),
   460  			"aws_waf_ipset":                                resourceAwsWafIPSet(),
   461  			"aws_waf_rule":                                 resourceAwsWafRule(),
   462  			"aws_waf_size_constraint_set":                  resourceAwsWafSizeConstraintSet(),
   463  			"aws_waf_web_acl":                              resourceAwsWafWebAcl(),
   464  			"aws_waf_xss_match_set":                        resourceAwsWafXssMatchSet(),
   465  			"aws_waf_sql_injection_match_set":              resourceAwsWafSqlInjectionMatchSet(),
   466  			"aws_wafregional_byte_match_set":               resourceAwsWafRegionalByteMatchSet(),
   467  			"aws_wafregional_ipset":                        resourceAwsWafRegionalIPSet(),
   468  		},
   469  		ConfigureFunc: providerConfigure,
   470  	}
   471  }
   472  
   473  var descriptions map[string]string
   474  
   475  func init() {
   476  	descriptions = map[string]string{
   477  		"region": "The region where AWS operations will take place. Examples\n" +
   478  			"are us-east-1, us-west-2, etc.",
   479  
   480  		"access_key": "The access key for API operations. You can retrieve this\n" +
   481  			"from the 'Security & Credentials' section of the AWS console.",
   482  
   483  		"secret_key": "The secret key for API operations. You can retrieve this\n" +
   484  			"from the 'Security & Credentials' section of the AWS console.",
   485  
   486  		"profile": "The profile for API operations. If not set, the default profile\n" +
   487  			"created with `aws configure` will be used.",
   488  
   489  		"shared_credentials_file": "The path to the shared credentials file. If not set\n" +
   490  			"this defaults to ~/.aws/credentials.",
   491  
   492  		"token": "session token. A session token is only required if you are\n" +
   493  			"using temporary security credentials.",
   494  
   495  		"max_retries": "The maximum number of times an AWS API request is\n" +
   496  			"being executed. If the API request still fails, an error is\n" +
   497  			"thrown.",
   498  
   499  		"cloudformation_endpoint": "Use this to override the default endpoint URL constructed from the `region`.\n",
   500  
   501  		"cloudwatch_endpoint": "Use this to override the default endpoint URL constructed from the `region`.\n",
   502  
   503  		"cloudwatchevents_endpoint": "Use this to override the default endpoint URL constructed from the `region`.\n",
   504  
   505  		"cloudwatchlogs_endpoint": "Use this to override the default endpoint URL constructed from the `region`.\n",
   506  
   507  		"devicefarm_endpoint": "Use this to override the default endpoint URL constructed from the `region`.\n",
   508  
   509  		"dynamodb_endpoint": "Use this to override the default endpoint URL constructed from the `region`.\n" +
   510  			"It's typically used to connect to dynamodb-local.",
   511  
   512  		"kinesis_endpoint": "Use this to override the default endpoint URL constructed from the `region`.\n" +
   513  			"It's typically used to connect to kinesalite.",
   514  
   515  		"kms_endpoint": "Use this to override the default endpoint URL constructed from the `region`.\n",
   516  
   517  		"iam_endpoint": "Use this to override the default endpoint URL constructed from the `region`.\n",
   518  
   519  		"ec2_endpoint": "Use this to override the default endpoint URL constructed from the `region`.\n",
   520  
   521  		"elb_endpoint": "Use this to override the default endpoint URL constructed from the `region`.\n",
   522  
   523  		"rds_endpoint": "Use this to override the default endpoint URL constructed from the `region`.\n",
   524  
   525  		"s3_endpoint": "Use this to override the default endpoint URL constructed from the `region`.\n",
   526  
   527  		"sns_endpoint": "Use this to override the default endpoint URL constructed from the `region`.\n",
   528  
   529  		"sqs_endpoint": "Use this to override the default endpoint URL constructed from the `region`.\n",
   530  
   531  		"insecure": "Explicitly allow the provider to perform \"insecure\" SSL requests. If omitted," +
   532  			"default value is `false`",
   533  
   534  		"skip_credentials_validation": "Skip the credentials validation via STS API. " +
   535  			"Used for AWS API implementations that do not have STS available/implemented.",
   536  
   537  		"skip_get_ec2_platforms": "Skip getting the supported EC2 platforms. " +
   538  			"Used by users that don't have ec2:DescribeAccountAttributes permissions.",
   539  
   540  		"skip_region_validation": "Skip static validation of region name. " +
   541  			"Used by users of alternative AWS-like APIs or users w/ access to regions that are not public (yet).",
   542  
   543  		"skip_requesting_account_id": "Skip requesting the account ID. " +
   544  			"Used for AWS API implementations that do not have IAM/STS API and/or metadata API.",
   545  
   546  		"skip_medatadata_api_check": "Skip the AWS Metadata API check. " +
   547  			"Used for AWS API implementations that do not have a metadata api endpoint.",
   548  
   549  		"s3_force_path_style": "Set this to true to force the request to use path-style addressing,\n" +
   550  			"i.e., http://s3.amazonaws.com/BUCKET/KEY. By default, the S3 client will\n" +
   551  			"use virtual hosted bucket addressing when possible\n" +
   552  			"(http://BUCKET.s3.amazonaws.com/KEY). Specific to the Amazon S3 service.",
   553  
   554  		"assume_role_role_arn": "The ARN of an IAM role to assume prior to making API calls.",
   555  
   556  		"assume_role_session_name": "The session name to use when assuming the role. If omitted," +
   557  			" no session name is passed to the AssumeRole call.",
   558  
   559  		"assume_role_external_id": "The external ID to use when assuming the role. If omitted," +
   560  			" no external ID is passed to the AssumeRole call.",
   561  
   562  		"assume_role_policy": "The permissions applied when assuming a role. You cannot use," +
   563  			" this policy to grant further permissions that are in excess to those of the, " +
   564  			" role that is being assumed.",
   565  	}
   566  }
   567  
   568  func providerConfigure(d *schema.ResourceData) (interface{}, error) {
   569  	config := Config{
   570  		AccessKey:               d.Get("access_key").(string),
   571  		SecretKey:               d.Get("secret_key").(string),
   572  		Profile:                 d.Get("profile").(string),
   573  		CredsFilename:           d.Get("shared_credentials_file").(string),
   574  		Token:                   d.Get("token").(string),
   575  		Region:                  d.Get("region").(string),
   576  		MaxRetries:              d.Get("max_retries").(int),
   577  		Insecure:                d.Get("insecure").(bool),
   578  		SkipCredsValidation:     d.Get("skip_credentials_validation").(bool),
   579  		SkipGetEC2Platforms:     d.Get("skip_get_ec2_platforms").(bool),
   580  		SkipRegionValidation:    d.Get("skip_region_validation").(bool),
   581  		SkipRequestingAccountId: d.Get("skip_requesting_account_id").(bool),
   582  		SkipMetadataApiCheck:    d.Get("skip_metadata_api_check").(bool),
   583  		S3ForcePathStyle:        d.Get("s3_force_path_style").(bool),
   584  	}
   585  
   586  	assumeRoleList := d.Get("assume_role").(*schema.Set).List()
   587  	if len(assumeRoleList) == 1 {
   588  		assumeRole := assumeRoleList[0].(map[string]interface{})
   589  		config.AssumeRoleARN = assumeRole["role_arn"].(string)
   590  		config.AssumeRoleSessionName = assumeRole["session_name"].(string)
   591  		config.AssumeRoleExternalID = assumeRole["external_id"].(string)
   592  
   593  		if v := assumeRole["policy"].(string); v != "" {
   594  			config.AssumeRolePolicy = v
   595  		}
   596  
   597  		log.Printf("[INFO] assume_role configuration set: (ARN: %q, SessionID: %q, ExternalID: %q, Policy: %q)",
   598  			config.AssumeRoleARN, config.AssumeRoleSessionName, config.AssumeRoleExternalID, config.AssumeRolePolicy)
   599  	} else {
   600  		log.Printf("[INFO] No assume_role block read from configuration")
   601  	}
   602  
   603  	endpointsSet := d.Get("endpoints").(*schema.Set)
   604  
   605  	for _, endpointsSetI := range endpointsSet.List() {
   606  		endpoints := endpointsSetI.(map[string]interface{})
   607  		config.CloudFormationEndpoint = endpoints["cloudformation"].(string)
   608  		config.CloudWatchEndpoint = endpoints["cloudwatch"].(string)
   609  		config.CloudWatchEventsEndpoint = endpoints["cloudwatchevents"].(string)
   610  		config.CloudWatchLogsEndpoint = endpoints["cloudwatchlogs"].(string)
   611  		config.DeviceFarmEndpoint = endpoints["devicefarm"].(string)
   612  		config.DynamoDBEndpoint = endpoints["dynamodb"].(string)
   613  		config.Ec2Endpoint = endpoints["ec2"].(string)
   614  		config.ElbEndpoint = endpoints["elb"].(string)
   615  		config.IamEndpoint = endpoints["iam"].(string)
   616  		config.KinesisEndpoint = endpoints["kinesis"].(string)
   617  		config.KmsEndpoint = endpoints["kms"].(string)
   618  		config.RdsEndpoint = endpoints["rds"].(string)
   619  		config.S3Endpoint = endpoints["s3"].(string)
   620  		config.SnsEndpoint = endpoints["sns"].(string)
   621  		config.SqsEndpoint = endpoints["sqs"].(string)
   622  	}
   623  
   624  	if v, ok := d.GetOk("allowed_account_ids"); ok {
   625  		config.AllowedAccountIds = v.(*schema.Set).List()
   626  	}
   627  
   628  	if v, ok := d.GetOk("forbidden_account_ids"); ok {
   629  		config.ForbiddenAccountIds = v.(*schema.Set).List()
   630  	}
   631  
   632  	return config.Client()
   633  }
   634  
   635  // This is a global MutexKV for use within this plugin.
   636  var awsMutexKV = mutexkv.NewMutexKV()
   637  
   638  func assumeRoleSchema() *schema.Schema {
   639  	return &schema.Schema{
   640  		Type:     schema.TypeSet,
   641  		Optional: true,
   642  		MaxItems: 1,
   643  		Elem: &schema.Resource{
   644  			Schema: map[string]*schema.Schema{
   645  				"role_arn": {
   646  					Type:        schema.TypeString,
   647  					Optional:    true,
   648  					Description: descriptions["assume_role_role_arn"],
   649  				},
   650  
   651  				"session_name": {
   652  					Type:        schema.TypeString,
   653  					Optional:    true,
   654  					Description: descriptions["assume_role_session_name"],
   655  				},
   656  
   657  				"external_id": {
   658  					Type:        schema.TypeString,
   659  					Optional:    true,
   660  					Description: descriptions["assume_role_external_id"],
   661  				},
   662  
   663  				"policy": {
   664  					Type:        schema.TypeString,
   665  					Optional:    true,
   666  					Description: descriptions["assume_role_policy"],
   667  				},
   668  			},
   669  		},
   670  		Set: assumeRoleToHash,
   671  	}
   672  }
   673  
   674  func assumeRoleToHash(v interface{}) int {
   675  	var buf bytes.Buffer
   676  	m := v.(map[string]interface{})
   677  	buf.WriteString(fmt.Sprintf("%s-", m["role_arn"].(string)))
   678  	buf.WriteString(fmt.Sprintf("%s-", m["session_name"].(string)))
   679  	buf.WriteString(fmt.Sprintf("%s-", m["external_id"].(string)))
   680  	buf.WriteString(fmt.Sprintf("%s-", m["policy"].(string)))
   681  	return hashcode.String(buf.String())
   682  }
   683  
   684  func endpointsSchema() *schema.Schema {
   685  	return &schema.Schema{
   686  		Type:     schema.TypeSet,
   687  		Optional: true,
   688  		Elem: &schema.Resource{
   689  			Schema: map[string]*schema.Schema{
   690  				"cloudwatch": {
   691  					Type:        schema.TypeString,
   692  					Optional:    true,
   693  					Default:     "",
   694  					Description: descriptions["cloudwatch_endpoint"],
   695  				},
   696  				"cloudwatchevents": {
   697  					Type:        schema.TypeString,
   698  					Optional:    true,
   699  					Default:     "",
   700  					Description: descriptions["cloudwatchevents_endpoint"],
   701  				},
   702  				"cloudwatchlogs": {
   703  					Type:        schema.TypeString,
   704  					Optional:    true,
   705  					Default:     "",
   706  					Description: descriptions["cloudwatchlogs_endpoint"],
   707  				},
   708  				"cloudformation": {
   709  					Type:        schema.TypeString,
   710  					Optional:    true,
   711  					Default:     "",
   712  					Description: descriptions["cloudformation_endpoint"],
   713  				},
   714  				"devicefarm": {
   715  					Type:        schema.TypeString,
   716  					Optional:    true,
   717  					Default:     "",
   718  					Description: descriptions["devicefarm_endpoint"],
   719  				},
   720  				"dynamodb": {
   721  					Type:        schema.TypeString,
   722  					Optional:    true,
   723  					Default:     "",
   724  					Description: descriptions["dynamodb_endpoint"],
   725  				},
   726  				"iam": {
   727  					Type:        schema.TypeString,
   728  					Optional:    true,
   729  					Default:     "",
   730  					Description: descriptions["iam_endpoint"],
   731  				},
   732  
   733  				"ec2": {
   734  					Type:        schema.TypeString,
   735  					Optional:    true,
   736  					Default:     "",
   737  					Description: descriptions["ec2_endpoint"],
   738  				},
   739  
   740  				"elb": {
   741  					Type:        schema.TypeString,
   742  					Optional:    true,
   743  					Default:     "",
   744  					Description: descriptions["elb_endpoint"],
   745  				},
   746  				"kinesis": {
   747  					Type:        schema.TypeString,
   748  					Optional:    true,
   749  					Default:     "",
   750  					Description: descriptions["kinesis_endpoint"],
   751  				},
   752  				"kms": {
   753  					Type:        schema.TypeString,
   754  					Optional:    true,
   755  					Default:     "",
   756  					Description: descriptions["kms_endpoint"],
   757  				},
   758  				"rds": {
   759  					Type:        schema.TypeString,
   760  					Optional:    true,
   761  					Default:     "",
   762  					Description: descriptions["rds_endpoint"],
   763  				},
   764  				"s3": {
   765  					Type:        schema.TypeString,
   766  					Optional:    true,
   767  					Default:     "",
   768  					Description: descriptions["s3_endpoint"],
   769  				},
   770  				"sns": {
   771  					Type:        schema.TypeString,
   772  					Optional:    true,
   773  					Default:     "",
   774  					Description: descriptions["sns_endpoint"],
   775  				},
   776  				"sqs": {
   777  					Type:        schema.TypeString,
   778  					Optional:    true,
   779  					Default:     "",
   780  					Description: descriptions["sqs_endpoint"],
   781  				},
   782  			},
   783  		},
   784  		Set: endpointsToHash,
   785  	}
   786  }
   787  
   788  func endpointsToHash(v interface{}) int {
   789  	var buf bytes.Buffer
   790  	m := v.(map[string]interface{})
   791  	buf.WriteString(fmt.Sprintf("%s-", m["cloudwatch"].(string)))
   792  	buf.WriteString(fmt.Sprintf("%s-", m["cloudwatchevents"].(string)))
   793  	buf.WriteString(fmt.Sprintf("%s-", m["cloudwatchlogs"].(string)))
   794  	buf.WriteString(fmt.Sprintf("%s-", m["cloudformation"].(string)))
   795  	buf.WriteString(fmt.Sprintf("%s-", m["devicefarm"].(string)))
   796  	buf.WriteString(fmt.Sprintf("%s-", m["dynamodb"].(string)))
   797  	buf.WriteString(fmt.Sprintf("%s-", m["iam"].(string)))
   798  	buf.WriteString(fmt.Sprintf("%s-", m["ec2"].(string)))
   799  	buf.WriteString(fmt.Sprintf("%s-", m["elb"].(string)))
   800  	buf.WriteString(fmt.Sprintf("%s-", m["kinesis"].(string)))
   801  	buf.WriteString(fmt.Sprintf("%s-", m["kms"].(string)))
   802  	buf.WriteString(fmt.Sprintf("%s-", m["rds"].(string)))
   803  	buf.WriteString(fmt.Sprintf("%s-", m["s3"].(string)))
   804  	buf.WriteString(fmt.Sprintf("%s-", m["sns"].(string)))
   805  	buf.WriteString(fmt.Sprintf("%s-", m["sqs"].(string)))
   806  
   807  	return hashcode.String(buf.String())
   808  }