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