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