github.com/gwilym/terraform@v0.3.8-0.20151231151641-c7573de75b19/builtin/providers/aws/provider.go (about)

     1  package aws
     2  
     3  import (
     4  	"github.com/hashicorp/terraform/helper/hashcode"
     5  	"github.com/hashicorp/terraform/helper/mutexkv"
     6  	"github.com/hashicorp/terraform/helper/schema"
     7  	"github.com/hashicorp/terraform/terraform"
     8  )
     9  
    10  // Provider returns a terraform.ResourceProvider.
    11  func Provider() terraform.ResourceProvider {
    12  	// TODO: Move the validation to this, requires conditional schemas
    13  	// TODO: Move the configuration to this, requires validation
    14  
    15  	// The actual provider
    16  	return &schema.Provider{
    17  		Schema: map[string]*schema.Schema{
    18  			"access_key": &schema.Schema{
    19  				Type:        schema.TypeString,
    20  				Optional:    true,
    21  				Default:     "",
    22  				Description: descriptions["access_key"],
    23  			},
    24  
    25  			"secret_key": &schema.Schema{
    26  				Type:        schema.TypeString,
    27  				Optional:    true,
    28  				Default:     "",
    29  				Description: descriptions["secret_key"],
    30  			},
    31  
    32  			"token": &schema.Schema{
    33  				Type:        schema.TypeString,
    34  				Optional:    true,
    35  				Default:     "",
    36  				Description: descriptions["token"],
    37  			},
    38  
    39  			"region": &schema.Schema{
    40  				Type:     schema.TypeString,
    41  				Required: true,
    42  				DefaultFunc: schema.MultiEnvDefaultFunc([]string{
    43  					"AWS_REGION",
    44  					"AWS_DEFAULT_REGION",
    45  				}, nil),
    46  				Description:  descriptions["region"],
    47  				InputDefault: "us-east-1",
    48  			},
    49  
    50  			"max_retries": &schema.Schema{
    51  				Type:        schema.TypeInt,
    52  				Optional:    true,
    53  				Default:     11,
    54  				Description: descriptions["max_retries"],
    55  			},
    56  
    57  			"allowed_account_ids": &schema.Schema{
    58  				Type:          schema.TypeSet,
    59  				Elem:          &schema.Schema{Type: schema.TypeString},
    60  				Optional:      true,
    61  				ConflictsWith: []string{"forbidden_account_ids"},
    62  				Set: func(v interface{}) int {
    63  					return hashcode.String(v.(string))
    64  				},
    65  			},
    66  
    67  			"forbidden_account_ids": &schema.Schema{
    68  				Type:          schema.TypeSet,
    69  				Elem:          &schema.Schema{Type: schema.TypeString},
    70  				Optional:      true,
    71  				ConflictsWith: []string{"allowed_account_ids"},
    72  				Set: func(v interface{}) int {
    73  					return hashcode.String(v.(string))
    74  				},
    75  			},
    76  
    77  			"dynamodb_endpoint": &schema.Schema{
    78  				Type:        schema.TypeString,
    79  				Optional:    true,
    80  				Default:     "",
    81  				Description: descriptions["dynamodb_endpoint"],
    82  			},
    83  
    84  			"kinesis_endpoint": &schema.Schema{
    85  				Type:        schema.TypeString,
    86  				Optional:    true,
    87  				Default:     "",
    88  				Description: descriptions["kinesis_endpoint"],
    89  			},
    90  		},
    91  
    92  		ResourcesMap: map[string]*schema.Resource{
    93  			"aws_ami":                              resourceAwsAmi(),
    94  			"aws_ami_copy":                         resourceAwsAmiCopy(),
    95  			"aws_ami_from_instance":                resourceAwsAmiFromInstance(),
    96  			"aws_app_cookie_stickiness_policy":     resourceAwsAppCookieStickinessPolicy(),
    97  			"aws_autoscaling_group":                resourceAwsAutoscalingGroup(),
    98  			"aws_autoscaling_notification":         resourceAwsAutoscalingNotification(),
    99  			"aws_autoscaling_policy":               resourceAwsAutoscalingPolicy(),
   100  			"aws_autoscaling_schedule":             resourceAwsAutoscalingSchedule(),
   101  			"aws_cloudformation_stack":             resourceAwsCloudFormationStack(),
   102  			"aws_cloudtrail":                       resourceAwsCloudTrail(),
   103  			"aws_cloudwatch_log_group":             resourceAwsCloudWatchLogGroup(),
   104  			"aws_autoscaling_lifecycle_hook":       resourceAwsAutoscalingLifecycleHook(),
   105  			"aws_cloudwatch_metric_alarm":          resourceAwsCloudWatchMetricAlarm(),
   106  			"aws_codedeploy_app":                   resourceAwsCodeDeployApp(),
   107  			"aws_codedeploy_deployment_group":      resourceAwsCodeDeployDeploymentGroup(),
   108  			"aws_codecommit_repository":            resourceAwsCodeCommitRepository(),
   109  			"aws_customer_gateway":                 resourceAwsCustomerGateway(),
   110  			"aws_db_instance":                      resourceAwsDbInstance(),
   111  			"aws_db_parameter_group":               resourceAwsDbParameterGroup(),
   112  			"aws_db_security_group":                resourceAwsDbSecurityGroup(),
   113  			"aws_db_subnet_group":                  resourceAwsDbSubnetGroup(),
   114  			"aws_directory_service_directory":      resourceAwsDirectoryServiceDirectory(),
   115  			"aws_dynamodb_table":                   resourceAwsDynamoDbTable(),
   116  			"aws_ebs_volume":                       resourceAwsEbsVolume(),
   117  			"aws_ecr_repository":                   resourceAwsEcrRepository(),
   118  			"aws_ecr_repository_policy":            resourceAwsEcrRepositoryPolicy(),
   119  			"aws_ecs_cluster":                      resourceAwsEcsCluster(),
   120  			"aws_ecs_service":                      resourceAwsEcsService(),
   121  			"aws_ecs_task_definition":              resourceAwsEcsTaskDefinition(),
   122  			"aws_efs_file_system":                  resourceAwsEfsFileSystem(),
   123  			"aws_efs_mount_target":                 resourceAwsEfsMountTarget(),
   124  			"aws_eip":                              resourceAwsEip(),
   125  			"aws_elasticache_cluster":              resourceAwsElasticacheCluster(),
   126  			"aws_elasticache_parameter_group":      resourceAwsElasticacheParameterGroup(),
   127  			"aws_elasticache_security_group":       resourceAwsElasticacheSecurityGroup(),
   128  			"aws_elasticache_subnet_group":         resourceAwsElasticacheSubnetGroup(),
   129  			"aws_elasticsearch_domain":             resourceAwsElasticSearchDomain(),
   130  			"aws_elb":                              resourceAwsElb(),
   131  			"aws_flow_log":                         resourceAwsFlowLog(),
   132  			"aws_glacier_vault":                    resourceAwsGlacierVault(),
   133  			"aws_iam_access_key":                   resourceAwsIamAccessKey(),
   134  			"aws_iam_group_policy":                 resourceAwsIamGroupPolicy(),
   135  			"aws_iam_group":                        resourceAwsIamGroup(),
   136  			"aws_iam_group_membership":             resourceAwsIamGroupMembership(),
   137  			"aws_iam_instance_profile":             resourceAwsIamInstanceProfile(),
   138  			"aws_iam_policy":                       resourceAwsIamPolicy(),
   139  			"aws_iam_policy_attachment":            resourceAwsIamPolicyAttachment(),
   140  			"aws_iam_role_policy":                  resourceAwsIamRolePolicy(),
   141  			"aws_iam_role":                         resourceAwsIamRole(),
   142  			"aws_iam_saml_provider":                resourceAwsIamSamlProvider(),
   143  			"aws_iam_server_certificate":           resourceAwsIAMServerCertificate(),
   144  			"aws_iam_user_policy":                  resourceAwsIamUserPolicy(),
   145  			"aws_iam_user":                         resourceAwsIamUser(),
   146  			"aws_instance":                         resourceAwsInstance(),
   147  			"aws_internet_gateway":                 resourceAwsInternetGateway(),
   148  			"aws_key_pair":                         resourceAwsKeyPair(),
   149  			"aws_kinesis_firehose_delivery_stream": resourceAwsKinesisFirehoseDeliveryStream(),
   150  			"aws_kinesis_stream":                   resourceAwsKinesisStream(),
   151  			"aws_lambda_function":                  resourceAwsLambdaFunction(),
   152  			"aws_lambda_event_source_mapping":      resourceAwsLambdaEventSourceMapping(),
   153  			"aws_launch_configuration":             resourceAwsLaunchConfiguration(),
   154  			"aws_lb_cookie_stickiness_policy":      resourceAwsLBCookieStickinessPolicy(),
   155  			"aws_main_route_table_association":     resourceAwsMainRouteTableAssociation(),
   156  			"aws_nat_gateway":                      resourceAwsNatGateway(),
   157  			"aws_network_acl":                      resourceAwsNetworkAcl(),
   158  			"aws_network_acl_rule":                 resourceAwsNetworkAclRule(),
   159  			"aws_network_interface":                resourceAwsNetworkInterface(),
   160  			"aws_opsworks_stack":                   resourceAwsOpsworksStack(),
   161  			"aws_opsworks_java_app_layer":          resourceAwsOpsworksJavaAppLayer(),
   162  			"aws_opsworks_haproxy_layer":           resourceAwsOpsworksHaproxyLayer(),
   163  			"aws_opsworks_static_web_layer":        resourceAwsOpsworksStaticWebLayer(),
   164  			"aws_opsworks_php_app_layer":           resourceAwsOpsworksPhpAppLayer(),
   165  			"aws_opsworks_rails_app_layer":         resourceAwsOpsworksRailsAppLayer(),
   166  			"aws_opsworks_nodejs_app_layer":        resourceAwsOpsworksNodejsAppLayer(),
   167  			"aws_opsworks_memcached_layer":         resourceAwsOpsworksMemcachedLayer(),
   168  			"aws_opsworks_mysql_layer":             resourceAwsOpsworksMysqlLayer(),
   169  			"aws_opsworks_ganglia_layer":           resourceAwsOpsworksGangliaLayer(),
   170  			"aws_opsworks_custom_layer":            resourceAwsOpsworksCustomLayer(),
   171  			"aws_placement_group":                  resourceAwsPlacementGroup(),
   172  			"aws_proxy_protocol_policy":            resourceAwsProxyProtocolPolicy(),
   173  			"aws_rds_cluster":                      resourceAwsRDSCluster(),
   174  			"aws_rds_cluster_instance":             resourceAwsRDSClusterInstance(),
   175  			"aws_route53_delegation_set":           resourceAwsRoute53DelegationSet(),
   176  			"aws_route53_record":                   resourceAwsRoute53Record(),
   177  			"aws_route53_zone_association":         resourceAwsRoute53ZoneAssociation(),
   178  			"aws_route53_zone":                     resourceAwsRoute53Zone(),
   179  			"aws_route53_health_check":             resourceAwsRoute53HealthCheck(),
   180  			"aws_route":                            resourceAwsRoute(),
   181  			"aws_route_table":                      resourceAwsRouteTable(),
   182  			"aws_route_table_association":          resourceAwsRouteTableAssociation(),
   183  			"aws_s3_bucket":                        resourceAwsS3Bucket(),
   184  			"aws_s3_bucket_object":                 resourceAwsS3BucketObject(),
   185  			"aws_security_group":                   resourceAwsSecurityGroup(),
   186  			"aws_security_group_rule":              resourceAwsSecurityGroupRule(),
   187  			"aws_spot_instance_request":            resourceAwsSpotInstanceRequest(),
   188  			"aws_sqs_queue":                        resourceAwsSqsQueue(),
   189  			"aws_sns_topic":                        resourceAwsSnsTopic(),
   190  			"aws_sns_topic_subscription":           resourceAwsSnsTopicSubscription(),
   191  			"aws_subnet":                           resourceAwsSubnet(),
   192  			"aws_volume_attachment":                resourceAwsVolumeAttachment(),
   193  			"aws_vpc_dhcp_options_association":     resourceAwsVpcDhcpOptionsAssociation(),
   194  			"aws_vpc_dhcp_options":                 resourceAwsVpcDhcpOptions(),
   195  			"aws_vpc_peering_connection":           resourceAwsVpcPeeringConnection(),
   196  			"aws_vpc":                              resourceAwsVpc(),
   197  			"aws_vpc_endpoint":                     resourceAwsVpcEndpoint(),
   198  			"aws_vpn_connection":                   resourceAwsVpnConnection(),
   199  			"aws_vpn_connection_route":             resourceAwsVpnConnectionRoute(),
   200  			"aws_vpn_gateway":                      resourceAwsVpnGateway(),
   201  		},
   202  
   203  		ConfigureFunc: providerConfigure,
   204  	}
   205  }
   206  
   207  var descriptions map[string]string
   208  
   209  func init() {
   210  	descriptions = map[string]string{
   211  		"region": "The region where AWS operations will take place. Examples\n" +
   212  			"are us-east-1, us-west-2, etc.",
   213  
   214  		"access_key": "The access key for API operations. You can retrieve this\n" +
   215  			"from the 'Security & Credentials' section of the AWS console.",
   216  
   217  		"secret_key": "The secret key for API operations. You can retrieve this\n" +
   218  			"from the 'Security & Credentials' section of the AWS console.",
   219  
   220  		"token": "session token. A session token is only required if you are\n" +
   221  			"using temporary security credentials.",
   222  
   223  		"max_retries": "The maximum number of times an AWS API request is\n" +
   224  			"being executed. If the API request still fails, an error is\n" +
   225  			"thrown.",
   226  
   227  		"dynamodb_endpoint": "Use this to override the default endpoint URL constructed from the `region`.\n" +
   228  			"It's typically used to connect to dynamodb-local.",
   229  
   230  		"kinesis_endpoint": "Use this to override the default endpoint URL constructed from the `region`.\n" +
   231  			"It's typically used to connect to kinesalite.",
   232  	}
   233  }
   234  
   235  func providerConfigure(d *schema.ResourceData) (interface{}, error) {
   236  	config := Config{
   237  		AccessKey:        d.Get("access_key").(string),
   238  		SecretKey:        d.Get("secret_key").(string),
   239  		Token:            d.Get("token").(string),
   240  		Region:           d.Get("region").(string),
   241  		MaxRetries:       d.Get("max_retries").(int),
   242  		DynamoDBEndpoint: d.Get("dynamodb_endpoint").(string),
   243  		KinesisEndpoint:  d.Get("kinesis_endpoint").(string),
   244  	}
   245  
   246  	if v, ok := d.GetOk("allowed_account_ids"); ok {
   247  		config.AllowedAccountIds = v.(*schema.Set).List()
   248  	}
   249  
   250  	if v, ok := d.GetOk("forbidden_account_ids"); ok {
   251  		config.ForbiddenAccountIds = v.(*schema.Set).List()
   252  	}
   253  
   254  	return config.Client()
   255  }
   256  
   257  // This is a global MutexKV for use within this plugin.
   258  var awsMutexKV = mutexkv.NewMutexKV()