github.com/mohanarpit/terraform@v0.6.16-0.20160909104007-291f29853544/builtin/providers/aws/resource_aws_ses_active_receipt_rule_set.go (about)

     1  package aws
     2  
     3  import (
     4  	"fmt"
     5  	"log"
     6  
     7  	"github.com/aws/aws-sdk-go/aws"
     8  	"github.com/aws/aws-sdk-go/service/ses"
     9  	"github.com/hashicorp/terraform/helper/schema"
    10  )
    11  
    12  func resourceAwsSesActiveReceiptRuleSet() *schema.Resource {
    13  	return &schema.Resource{
    14  		Create: resourceAwsSesActiveReceiptRuleSetUpdate,
    15  		Update: resourceAwsSesActiveReceiptRuleSetUpdate,
    16  		Read:   resourceAwsSesActiveReceiptRuleSetRead,
    17  		Delete: resourceAwsSesActiveReceiptRuleSetDelete,
    18  
    19  		Schema: map[string]*schema.Schema{
    20  			"rule_set_name": &schema.Schema{
    21  				Type:     schema.TypeString,
    22  				Required: true,
    23  			},
    24  		},
    25  	}
    26  }
    27  
    28  func resourceAwsSesActiveReceiptRuleSetUpdate(d *schema.ResourceData, meta interface{}) error {
    29  	conn := meta.(*AWSClient).sesConn
    30  
    31  	ruleSetName := d.Get("rule_set_name").(string)
    32  
    33  	createOpts := &ses.SetActiveReceiptRuleSetInput{
    34  		RuleSetName: aws.String(ruleSetName),
    35  	}
    36  
    37  	_, err := conn.SetActiveReceiptRuleSet(createOpts)
    38  	if err != nil {
    39  		return fmt.Errorf("Error setting active SES rule set: %s", err)
    40  	}
    41  
    42  	d.SetId(ruleSetName)
    43  
    44  	return resourceAwsSesActiveReceiptRuleSetRead(d, meta)
    45  }
    46  
    47  func resourceAwsSesActiveReceiptRuleSetRead(d *schema.ResourceData, meta interface{}) error {
    48  	conn := meta.(*AWSClient).sesConn
    49  
    50  	describeOpts := &ses.DescribeActiveReceiptRuleSetInput{}
    51  
    52  	response, err := conn.DescribeActiveReceiptRuleSet(describeOpts)
    53  	if err != nil {
    54  		return err
    55  	}
    56  
    57  	if response.Metadata != nil {
    58  		d.Set("rule_set_name", response.Metadata.Name)
    59  	} else {
    60  		log.Print("[WARN] No active Receipt Rule Set found")
    61  		d.SetId("")
    62  	}
    63  
    64  	return nil
    65  }
    66  
    67  func resourceAwsSesActiveReceiptRuleSetDelete(d *schema.ResourceData, meta interface{}) error {
    68  	conn := meta.(*AWSClient).sesConn
    69  
    70  	deleteOpts := &ses.SetActiveReceiptRuleSetInput{
    71  		RuleSetName: nil,
    72  	}
    73  
    74  	_, err := conn.SetActiveReceiptRuleSet(deleteOpts)
    75  	if err != nil {
    76  		return fmt.Errorf("Error deleting active SES rule set: %s", err)
    77  	}
    78  
    79  	return nil
    80  }