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