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