Merge branch 'feat/device-farm-integration' of https://github.com/DanielMSchmidt/terraform into DanielMSchmidt-feat/device-farm-integration

This commit is contained in:
stack72 2017-05-11 14:39:30 +03:00
commit 4942c4d44d
No known key found for this signature in database
GPG Key ID: 8619A619B085CB16
10 changed files with 13573 additions and 1 deletions

View File

@ -31,6 +31,7 @@ import (
"github.com/aws/aws-sdk-go/service/cognitoidentity"
"github.com/aws/aws-sdk-go/service/configservice"
"github.com/aws/aws-sdk-go/service/databasemigrationservice"
"github.com/aws/aws-sdk-go/service/devicefarm"
"github.com/aws/aws-sdk-go/service/directoryservice"
"github.com/aws/aws-sdk-go/service/dynamodb"
"github.com/aws/aws-sdk-go/service/ec2"
@ -94,6 +95,7 @@ type Config struct {
CloudWatchEventsEndpoint string
CloudWatchLogsEndpoint string
DynamoDBEndpoint string
DeviceFarmEndpoint string
Ec2Endpoint string
ElbEndpoint string
IamEndpoint string
@ -122,6 +124,7 @@ type AWSClient struct {
cloudwatcheventsconn *cloudwatchevents.CloudWatchEvents
cognitoconn *cognitoidentity.CognitoIdentity
configconn *configservice.ConfigService
devicefarmconn *devicefarm.DeviceFarm
dmsconn *databasemigrationservice.DatabaseMigrationService
dsconn *directoryservice.DirectoryService
dynamodbconn *dynamodb.DynamoDB
@ -286,6 +289,10 @@ func (c *Config) Client() (interface{}, error) {
awsS3Sess := sess.Copy(&aws.Config{Endpoint: aws.String(c.S3Endpoint)})
awsSnsSess := sess.Copy(&aws.Config{Endpoint: aws.String(c.SnsEndpoint)})
awsSqsSess := sess.Copy(&aws.Config{Endpoint: aws.String(c.SqsEndpoint)})
awsDeviceFarmSess := sess.Copy(&aws.Config{Endpoint: aws.String(c.DeviceFarmEndpoint)})
log.Println("[INFO] Initializing DeviceFarm SDK connection")
client.devicefarmconn = devicefarm.New(awsDeviceFarmSess)
// These two services need to be set up early so we can check on AccountID
client.iamconn = iam.New(awsIamSess)

View File

@ -278,6 +278,7 @@ func Provider() terraform.ResourceProvider {
"aws_db_parameter_group": resourceAwsDbParameterGroup(),
"aws_db_security_group": resourceAwsDbSecurityGroup(),
"aws_db_subnet_group": resourceAwsDbSubnetGroup(),
"aws_devicefarm_project": resourceAwsDevicefarmProject(),
"aws_directory_service_directory": resourceAwsDirectoryServiceDirectory(),
"aws_dms_certificate": resourceAwsDmsCertificate(),
"aws_dms_endpoint": resourceAwsDmsEndpoint(),
@ -495,6 +496,8 @@ func init() {
"cloudwatchlogs_endpoint": "Use this to override the default endpoint URL constructed from the `region`.\n",
"devicefarm_endpoint": "Use this to override the default endpoint URL constructed from the `region`.\n",
"dynamodb_endpoint": "Use this to override the default endpoint URL constructed from the `region`.\n" +
"It's typically used to connect to dynamodb-local.",
@ -597,6 +600,7 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
config.CloudWatchEndpoint = endpoints["cloudwatch"].(string)
config.CloudWatchEventsEndpoint = endpoints["cloudwatchevents"].(string)
config.CloudWatchLogsEndpoint = endpoints["cloudwatchlogs"].(string)
config.DeviceFarmEndpoint = endpoints["devicefarm"].(string)
config.DynamoDBEndpoint = endpoints["dynamodb"].(string)
config.Ec2Endpoint = endpoints["ec2"].(string)
config.ElbEndpoint = endpoints["elb"].(string)
@ -699,6 +703,12 @@ func endpointsSchema() *schema.Schema {
Default: "",
Description: descriptions["cloudformation_endpoint"],
},
"devicefarm": {
Type: schema.TypeString,
Optional: true,
Default: "",
Description: descriptions["devicefarm_endpoint"],
},
"dynamodb": {
Type: schema.TypeString,
Optional: true,
@ -774,6 +784,7 @@ func endpointsToHash(v interface{}) int {
buf.WriteString(fmt.Sprintf("%s-", m["cloudwatchevents"].(string)))
buf.WriteString(fmt.Sprintf("%s-", m["cloudwatchlogs"].(string)))
buf.WriteString(fmt.Sprintf("%s-", m["cloudformation"].(string)))
buf.WriteString(fmt.Sprintf("%s-", m["devicefarm"].(string)))
buf.WriteString(fmt.Sprintf("%s-", m["dynamodb"].(string)))
buf.WriteString(fmt.Sprintf("%s-", m["iam"].(string)))
buf.WriteString(fmt.Sprintf("%s-", m["ec2"].(string)))

View File

@ -0,0 +1,112 @@
package aws
import (
"fmt"
"log"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/devicefarm"
"github.com/hashicorp/terraform/helper/schema"
)
func resourceAwsDevicefarmProject() *schema.Resource {
return &schema.Resource{
Create: resourceAwsDevicefarmProjectCreate,
Read: resourceAwsDevicefarmProjectRead,
Update: resourceAwsDevicefarmProjectUpdate,
Delete: resourceAwsDevicefarmProjectDelete,
Schema: map[string]*schema.Schema{
"arn": &schema.Schema{
Type: schema.TypeString,
Computed: true,
},
"name": &schema.Schema{
Type: schema.TypeString,
Required: true,
},
},
}
}
func resourceAwsDevicefarmProjectCreate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).devicefarmconn
region := meta.(*AWSClient).region
// We need to ensure that DeviceFarm is only being run against us-west-2
// As this is the only place that AWS currently supports it
if region != "us-west-2" {
return fmt.Errorf("DeviceFarm can only be used with us-west-2. You are trying to use it on %s", region)
}
input := &devicefarm.CreateProjectInput{
Name: aws.String(d.Get("name").(string)),
}
log.Printf("[DEBUG] Creating DeviceFarm Project: %s", d.Get("name").(string))
out, err := conn.CreateProject(input)
if err != nil {
return fmt.Errorf("Error creating DeviceFarm Project: %s", err)
}
log.Printf("[DEBUG] Successsfully Created DeviceFarm Project: %s", *out.Project.Arn)
d.SetId(*out.Project.Arn)
return resourceAwsDevicefarmProjectRead(d, meta)
}
func resourceAwsDevicefarmProjectRead(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).devicefarmconn
input := &devicefarm.GetProjectInput{
Arn: aws.String(d.Id()),
}
log.Printf("[DEBUG] Reading DeviceFarm Project: %s", d.Id())
out, err := conn.GetProject(input)
if err != nil {
return fmt.Errorf("Error reading DeviceFarm Project: %s", err)
}
d.Set("name", out.Project.Name)
d.Set("arn", out.Project.Arn)
return nil
}
func resourceAwsDevicefarmProjectUpdate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).devicefarmconn
if d.HasChange("name") {
input := &devicefarm.UpdateProjectInput{
Arn: aws.String(d.Id()),
Name: aws.String(d.Get("name").(string)),
}
log.Printf("[DEBUG] Updating DeviceFarm Project: %s", d.Id())
_, err := conn.UpdateProject(input)
if err != nil {
return fmt.Errorf("Error Updating DeviceFarm Project: %s", err)
}
}
return resourceAwsDevicefarmProjectRead(d, meta)
}
func resourceAwsDevicefarmProjectDelete(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).devicefarmconn
input := &devicefarm.DeleteProjectInput{
Arn: aws.String(d.Id()),
}
log.Printf("[DEBUG] Deleting DeviceFarm Project: %s", d.Id())
_, err := conn.DeleteProject(input)
if err != nil {
return fmt.Errorf("Error deleting DeviceFarm Project: %s", err)
}
return nil
}

View File

@ -0,0 +1,153 @@
package aws
import (
"fmt"
"testing"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/devicefarm"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
)
func TestAccAWSDeviceFarmProject_basic(t *testing.T) {
var v devicefarm.Project
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckDeviceFarmProjectDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccDeviceFarmProjectConfig,
Check: resource.ComposeTestCheckFunc(
testAccCheckDeviceFarmProjectExists(
"aws_devicefarm_project.foo", &v),
),
},
},
})
}
func TestAccAWSDeviceFarmProject_update(t *testing.T) {
var afterCreate, afterUpdate devicefarm.Project
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckDeviceFarmProjectDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccDeviceFarmProjectConfig,
Check: resource.ComposeTestCheckFunc(
testAccCheckDeviceFarmProjectExists(
"aws_devicefarm_project.foo", &afterCreate),
resource.TestCheckResourceAttr(
"aws_devicefarm_project.foo", "name", "tf-testproject-01"),
),
},
resource.TestStep{
Config: testAccDeviceFarmProjectConfigUpdate,
Check: resource.ComposeTestCheckFunc(
testAccCheckDeviceFarmProjectExists(
"aws_devicefarm_project.foo", &afterUpdate),
resource.TestCheckResourceAttr(
"aws_devicefarm_project.foo", "name", "tf-testproject-02"),
testAccCheckDeviceFarmProjectNotRecreated(
t, &afterCreate, &afterUpdate),
),
},
},
})
}
func testAccCheckDeviceFarmProjectNotRecreated(t *testing.T,
before, after *devicefarm.Project) resource.TestCheckFunc {
return func(s *terraform.State) error {
if *before.Arn != *after.Arn {
t.Fatalf("Expected DeviceFarm Project ARNs to be the same. But they were: %v, %v", *before.Arn, *after.Arn)
}
return nil
}
}
func testAccCheckDeviceFarmProjectExists(n string, v *devicefarm.Project) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
if !ok {
return fmt.Errorf("Not found: %s", n)
}
if rs.Primary.ID == "" {
return fmt.Errorf("No ID is set")
}
conn := testAccProvider.Meta().(*AWSClient).devicefarmconn
resp, err := conn.GetProject(
&devicefarm.GetProjectInput{Arn: aws.String(rs.Primary.ID)})
if err != nil {
return err
}
if resp.Project == nil {
return fmt.Errorf("DeviceFarmProject not found")
}
*v = *resp.Project
return nil
}
}
func testAccCheckDeviceFarmProjectDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*AWSClient).devicefarmconn
for _, rs := range s.RootModule().Resources {
if rs.Type != "aws_devicefarm_project" {
continue
}
// Try to find the resource
resp, err := conn.GetProject(
&devicefarm.GetProjectInput{Arn: aws.String(rs.Primary.ID)})
if err == nil {
if resp.Project != nil {
return fmt.Errorf("still exist.")
}
return nil
}
// Verify the error is what we want
dferr, ok := err.(awserr.Error)
if !ok {
return err
}
if dferr.Code() != "DeviceFarmProjectNotFoundFault" {
return err
}
}
return nil
}
const testAccDeviceFarmProjectConfig = `
provider "aws" {
region = "us-west-2"
}
resource "aws_devicefarm_project" "foo" {
name = "tf-testproject-01"
}
`
const testAccDeviceFarmProjectConfigUpdate = `
provider "aws" {
region = "us-west-2"
}
resource "aws_devicefarm_project" "foo" {
name = "tf-testproject-02"
}
`

13027
vendor/github.com/aws/aws-sdk-go/service/devicefarm/api.go generated vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,82 @@
// Code generated by private/model/cli/gen-api/main.go. DO NOT EDIT.
// Package devicefarm provides the client and types for making API
// requests to AWS Device Farm.
//
// AWS Device Farm is a service that enables mobile app developers to test Android,
// iOS, and Fire OS apps on physical phones, tablets, and other devices in the
// cloud.
//
// See https://docs.aws.amazon.com/goto/WebAPI/devicefarm-2015-06-23 for more information on this service.
//
// See devicefarm package documentation for more information.
// https://docs.aws.amazon.com/sdk-for-go/api/service/devicefarm/
//
// Using the Client
//
// To use the client for AWS Device Farm you will first need
// to create a new instance of it.
//
// When creating a client for an AWS service you'll first need to have a Session
// already created. The Session provides configuration that can be shared
// between multiple service clients. Additional configuration can be applied to
// the Session and service's client when they are constructed. The aws package's
// Config type contains several fields such as Region for the AWS Region the
// client should make API requests too. The optional Config value can be provided
// as the variadic argument for Sessions and client creation.
//
// Once the service's client is created you can use it to make API requests the
// AWS service. These clients are safe to use concurrently.
//
// // Create a session to share configuration, and load external configuration.
// sess := session.Must(session.NewSession())
//
// // Create the service's client with the session.
// svc := devicefarm.New(sess)
//
// See the SDK's documentation for more information on how to use service clients.
// https://docs.aws.amazon.com/sdk-for-go/api/
//
// See aws package's Config type for more information on configuration options.
// https://docs.aws.amazon.com/sdk-for-go/api/aws/#Config
//
// See the AWS Device Farm client DeviceFarm for more
// information on creating the service's client.
// https://docs.aws.amazon.com/sdk-for-go/api/service/devicefarm/#New
//
// Once the client is created you can make an API request to the service.
// Each API method takes a input parameter, and returns the service response
// and an error.
//
// The API method will document which error codes the service can be returned
// by the operation if the service models the API operation's errors. These
// errors will also be available as const strings prefixed with "ErrCode".
//
// result, err := svc.CreateDevicePool(params)
// if err != nil {
// // Cast err to awserr.Error to handle specific error codes.
// aerr, ok := err.(awserr.Error)
// if ok && aerr.Code() == <error code to check for> {
// // Specific error code handling
// }
// return err
// }
//
// fmt.Println("CreateDevicePool result:")
// fmt.Println(result)
//
// Using the Client with Context
//
// The service's client also provides methods to make API requests with a Context
// value. This allows you to control the timeout, and cancellation of pending
// requests. These methods also take request Option as variadic parameter to apply
// additional configuration to the API request.
//
// ctx := context.Background()
//
// result, err := svc.CreateDevicePoolWithContext(ctx, params)
//
// See the request package documentation for more information on using Context pattern
// with the SDK.
// https://docs.aws.amazon.com/sdk-for-go/api/aws/request/
package devicefarm

View File

@ -0,0 +1,43 @@
// Code generated by private/model/cli/gen-api/main.go. DO NOT EDIT.
package devicefarm
const (
// ErrCodeArgumentException for service response error code
// "ArgumentException".
//
// An invalid argument was specified.
ErrCodeArgumentException = "ArgumentException"
// ErrCodeIdempotencyException for service response error code
// "IdempotencyException".
//
// An entity with the same name already exists.
ErrCodeIdempotencyException = "IdempotencyException"
// ErrCodeLimitExceededException for service response error code
// "LimitExceededException".
//
// A limit was exceeded.
ErrCodeLimitExceededException = "LimitExceededException"
// ErrCodeNotEligibleException for service response error code
// "NotEligibleException".
//
// Exception gets thrown when a user is not eligible to perform the specified
// transaction.
ErrCodeNotEligibleException = "NotEligibleException"
// ErrCodeNotFoundException for service response error code
// "NotFoundException".
//
// The specified entity was not found.
ErrCodeNotFoundException = "NotFoundException"
// ErrCodeServiceAccountException for service response error code
// "ServiceAccountException".
//
// There was a problem with the service account.
ErrCodeServiceAccountException = "ServiceAccountException"
)

View File

@ -0,0 +1,95 @@
// Code generated by private/model/cli/gen-api/main.go. DO NOT EDIT.
package devicefarm
import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/client"
"github.com/aws/aws-sdk-go/aws/client/metadata"
"github.com/aws/aws-sdk-go/aws/request"
"github.com/aws/aws-sdk-go/aws/signer/v4"
"github.com/aws/aws-sdk-go/private/protocol/jsonrpc"
)
// DeviceFarm provides the API operation methods for making requests to
// AWS Device Farm. See this package's package overview docs
// for details on the service.
//
// DeviceFarm methods are safe to use concurrently. It is not safe to
// modify mutate any of the struct's properties though.
type DeviceFarm struct {
*client.Client
}
// Used for custom client initialization logic
var initClient func(*client.Client)
// Used for custom request initialization logic
var initRequest func(*request.Request)
// Service information constants
const (
ServiceName = "devicefarm" // Service endpoint prefix API calls made to.
EndpointsID = ServiceName // Service ID for Regions and Endpoints metadata.
)
// New creates a new instance of the DeviceFarm client with a session.
// If additional configuration is needed for the client instance use the optional
// aws.Config parameter to add your extra config.
//
// Example:
// // Create a DeviceFarm client from just a session.
// svc := devicefarm.New(mySession)
//
// // Create a DeviceFarm client with additional configuration
// svc := devicefarm.New(mySession, aws.NewConfig().WithRegion("us-west-2"))
func New(p client.ConfigProvider, cfgs ...*aws.Config) *DeviceFarm {
c := p.ClientConfig(EndpointsID, cfgs...)
return newClient(*c.Config, c.Handlers, c.Endpoint, c.SigningRegion, c.SigningName)
}
// newClient creates, initializes and returns a new service client instance.
func newClient(cfg aws.Config, handlers request.Handlers, endpoint, signingRegion, signingName string) *DeviceFarm {
svc := &DeviceFarm{
Client: client.New(
cfg,
metadata.ClientInfo{
ServiceName: ServiceName,
SigningName: signingName,
SigningRegion: signingRegion,
Endpoint: endpoint,
APIVersion: "2015-06-23",
JSONVersion: "1.1",
TargetPrefix: "DeviceFarm_20150623",
},
handlers,
),
}
// Handlers
svc.Handlers.Sign.PushBackNamed(v4.SignRequestHandler)
svc.Handlers.Build.PushBackNamed(jsonrpc.BuildHandler)
svc.Handlers.Unmarshal.PushBackNamed(jsonrpc.UnmarshalHandler)
svc.Handlers.UnmarshalMeta.PushBackNamed(jsonrpc.UnmarshalMetaHandler)
svc.Handlers.UnmarshalError.PushBackNamed(jsonrpc.UnmarshalErrorHandler)
// Run custom client initialization if present
if initClient != nil {
initClient(svc.Client)
}
return svc
}
// newRequest creates a new request for a DeviceFarm operation and runs any
// custom request initialization.
func (c *DeviceFarm) newRequest(op *request.Operation, params, data interface{}) *request.Request {
req := c.NewRequest(op, params, data)
// Run custom request initialization if present
if initRequest != nil {
initRequest(req)
}
return req
}

6
vendor/vendor.json vendored
View File

@ -868,6 +868,12 @@
"version": "v1.8.16",
"versionExact": "v1.8.16"
},
{
"checksumSHA1": "JsCuHtHM4ql9lVjpCJ869L7irZk=",
"path": "github.com/aws/aws-sdk-go/service/devicefarm",
"revision": "a5b389b7b05c59adf7ac44f50d0d8be6e0c85710",
"revisionTime": "2017-05-04T23:50:54Z"
},
{
"checksumSHA1": "2Su2xzCbUPbCdVkyWuXcmxAI2Rs=",
"path": "github.com/aws/aws-sdk-go/service/directoryservice",

View File

@ -0,0 +1,36 @@
---
layout: "aws"
page_title: "AWS: aws_devicefarm_project"
sidebar_current: "docs-aws-resource-devicefarm-project"
description: |-
Provides a Devicefarm project
---
# aws\_devicefarm\_project
Provides a resource to manage AWS Device Farm Projects.
Please keep in mind that this feature is only supported on the "us-west-2" region.
This resource will error if you try to create a project in another region.
For more information about Device Farm Projects, see the AWS Documentation on
[Device Farm Projects][aws-get-project].
## Basic Example Usage
```hcl
resource "aws_devicefarm_project" "awesome_devices"
```
## Argument Reference
There are currently no other arguments besides the name supported.
## Attributes Reference
The following attributes are exported:
* `name` - The name of the project
* `arn` - The Amazon Resource Name of this project (computed)
[aws-get-project]: http://docs.aws.amazon.com/devicefarm/latest/APIReference/API_GetProject.html