Пример #1
0
func (p *ResourceProvider) Configure(c *terraform.ResourceConfig) error {
	if _, err := config.Decode(&p.Config, c.Config); err != nil {
		return err
	}

	// Get the auth and region. This can fail if keys/regions were not
	// specified and we're attempting to use the environment.
	var errs []error
	log.Println("[INFO] Building AWS auth structure")
	auth, err := p.Config.AWSAuth()
	if err != nil {
		errs = append(errs, err)
	}

	log.Println("[INFO] Building AWS region structure")
	region, err := p.Config.AWSRegion()
	if err != nil {
		errs = append(errs, err)
	}

	if len(errs) == 0 {
		log.Println("[INFO] Initializing EC2 connection")
		p.ec2conn = ec2.New(auth, region)
		log.Println("[INFO] Initializing ELB connection")
		p.elbconn = elb.New(auth, region)
		log.Println("[INFO] Initializing AutoScaling connection")
		p.autoscalingconn = autoscaling.New(auth, region)
		log.Println("[INFO] Initializing S3 connection")
		p.s3conn = s3.New(auth, region)
		log.Println("[INFO] Initializing RDS connection")
		p.rdsconn = rds.New(auth, region)
		log.Println("[INFO] Initializing Route53 connection")
		p.route53 = route53.New(auth, region)
	}

	if len(errs) > 0 {
		return &multierror.Error{Errors: errs}
	}

	// Create the provider, set the meta
	p.p = Provider()
	p.p.SetMeta(p)

	return nil
}
Пример #2
0
// Client configures and returns a fully initailized AWSClient
func (c *Config) Client() (interface{}, error) {
	var client AWSClient

	// Get the auth and region. This can fail if keys/regions were not
	// specified and we're attempting to use the environment.
	var errs []error
	log.Println("[INFO] Building AWS auth structure")
	auth, err := c.AWSAuth()
	if err != nil {
		errs = append(errs, err)
	}

	log.Println("[INFO] Building AWS region structure")
	region, err := c.AWSRegion()
	if err != nil {
		errs = append(errs, err)
	}

	if len(errs) == 0 {
		log.Println("[INFO] Initializing EC2 connection")
		client.ec2conn = ec2.New(auth, region)
		log.Println("[INFO] Initializing ELB connection")
		client.elbconn = elb.New(auth, region)
		log.Println("[INFO] Initializing AutoScaling connection")
		client.autoscalingconn = autoscaling.New(auth, region)
		log.Println("[INFO] Initializing S3 connection")
		client.s3conn = s3.New(auth, region)
		log.Println("[INFO] Initializing RDS connection")
		client.rdsconn = rds.New(auth, region)
		log.Println("[INFO] Initializing Route53 connection")
		client.route53 = route53.New(auth, region)
	}

	if len(errs) > 0 {
		return nil, &multierror.Error{Errors: errs}
	}

	return &client, nil
}