Example #1
0
func ExampleELBV2_SetSubnets() {
	sess, err := session.NewSession()
	if err != nil {
		fmt.Println("failed to create session,", err)
		return
	}

	svc := elbv2.New(sess)

	params := &elbv2.SetSubnetsInput{
		LoadBalancerArn: aws.String("LoadBalancerArn"), // Required
		Subnets: []*string{ // Required
			aws.String("SubnetId"), // Required
			// More values...
		},
	}
	resp, err := svc.SetSubnets(params)

	if err != nil {
		// Print the error, cast err to awserr.Error to get the Code and
		// Message from an error.
		fmt.Println(err.Error())
		return
	}

	// Pretty-print the response data.
	fmt.Println(resp)
}
Example #2
0
func ExampleELBV2_RemoveTags() {
	sess, err := session.NewSession()
	if err != nil {
		fmt.Println("failed to create session,", err)
		return
	}

	svc := elbv2.New(sess)

	params := &elbv2.RemoveTagsInput{
		ResourceArns: []*string{ // Required
			aws.String("ResourceArn"), // Required
			// More values...
		},
		TagKeys: []*string{ // Required
			aws.String("TagKey"), // Required
			// More values...
		},
	}
	resp, err := svc.RemoveTags(params)

	if err != nil {
		// Print the error, cast err to awserr.Error to get the Code and
		// Message from an error.
		fmt.Println(err.Error())
		return
	}

	// Pretty-print the response data.
	fmt.Println(resp)
}
Example #3
0
func ExampleELBV2_SetRulePriorities() {
	sess, err := session.NewSession()
	if err != nil {
		fmt.Println("failed to create session,", err)
		return
	}

	svc := elbv2.New(sess)

	params := &elbv2.SetRulePrioritiesInput{
		RulePriorities: []*elbv2.RulePriorityPair{ // Required
			{ // Required
				Priority: aws.Int64(1),
				RuleArn:  aws.String("RuleArn"),
			},
			// More values...
		},
	}
	resp, err := svc.SetRulePriorities(params)

	if err != nil {
		// Print the error, cast err to awserr.Error to get the Code and
		// Message from an error.
		fmt.Println(err.Error())
		return
	}

	// Pretty-print the response data.
	fmt.Println(resp)
}
Example #4
0
func ExampleELBV2_ModifyTargetGroupAttributes() {
	sess, err := session.NewSession()
	if err != nil {
		fmt.Println("failed to create session,", err)
		return
	}

	svc := elbv2.New(sess)

	params := &elbv2.ModifyTargetGroupAttributesInput{
		Attributes: []*elbv2.TargetGroupAttribute{ // Required
			{ // Required
				Key:   aws.String("TargetGroupAttributeKey"),
				Value: aws.String("TargetGroupAttributeValue"),
			},
			// More values...
		},
		TargetGroupArn: aws.String("TargetGroupArn"), // Required
	}
	resp, err := svc.ModifyTargetGroupAttributes(params)

	if err != nil {
		// Print the error, cast err to awserr.Error to get the Code and
		// Message from an error.
		fmt.Println(err.Error())
		return
	}

	// Pretty-print the response data.
	fmt.Println(resp)
}
Example #5
0
func ExampleELBV2_RegisterTargets() {
	sess, err := session.NewSession()
	if err != nil {
		fmt.Println("failed to create session,", err)
		return
	}

	svc := elbv2.New(sess)

	params := &elbv2.RegisterTargetsInput{
		TargetGroupArn: aws.String("TargetGroupArn"), // Required
		Targets: []*elbv2.TargetDescription{ // Required
			{ // Required
				Id:   aws.String("TargetId"), // Required
				Port: aws.Int64(1),
			},
			// More values...
		},
	}
	resp, err := svc.RegisterTargets(params)

	if err != nil {
		// Print the error, cast err to awserr.Error to get the Code and
		// Message from an error.
		fmt.Println(err.Error())
		return
	}

	// Pretty-print the response data.
	fmt.Println(resp)
}
Example #6
0
func ExampleELBV2_DescribeTargetGroups() {
	sess, err := session.NewSession()
	if err != nil {
		fmt.Println("failed to create session,", err)
		return
	}

	svc := elbv2.New(sess)

	params := &elbv2.DescribeTargetGroupsInput{
		LoadBalancerArn: aws.String("LoadBalancerArn"),
		Marker:          aws.String("Marker"),
		Names: []*string{
			aws.String("TargetGroupName"), // Required
			// More values...
		},
		PageSize: aws.Int64(1),
		TargetGroupArns: []*string{
			aws.String("TargetGroupArn"), // Required
			// More values...
		},
	}
	resp, err := svc.DescribeTargetGroups(params)

	if err != nil {
		// Print the error, cast err to awserr.Error to get the Code and
		// Message from an error.
		fmt.Println(err.Error())
		return
	}

	// Pretty-print the response data.
	fmt.Println(resp)
}
Example #7
0
func ExampleELBV2_ModifyTargetGroup() {
	sess, err := session.NewSession()
	if err != nil {
		fmt.Println("failed to create session,", err)
		return
	}

	svc := elbv2.New(sess)

	params := &elbv2.ModifyTargetGroupInput{
		TargetGroupArn:             aws.String("TargetGroupArn"), // Required
		HealthCheckIntervalSeconds: aws.Int64(1),
		HealthCheckPath:            aws.String("Path"),
		HealthCheckPort:            aws.String("HealthCheckPort"),
		HealthCheckProtocol:        aws.String("ProtocolEnum"),
		HealthCheckTimeoutSeconds:  aws.Int64(1),
		HealthyThresholdCount:      aws.Int64(1),
		Matcher: &elbv2.Matcher{
			HttpCode: aws.String("HttpCode"), // Required
		},
		UnhealthyThresholdCount: aws.Int64(1),
	}
	resp, err := svc.ModifyTargetGroup(params)

	if err != nil {
		// Print the error, cast err to awserr.Error to get the Code and
		// Message from an error.
		fmt.Println(err.Error())
		return
	}

	// Pretty-print the response data.
	fmt.Println(resp)
}
Example #8
0
func ExampleELBV2_DescribeRules() {
	sess, err := session.NewSession()
	if err != nil {
		fmt.Println("failed to create session,", err)
		return
	}

	svc := elbv2.New(sess)

	params := &elbv2.DescribeRulesInput{
		ListenerArn: aws.String("ListenerArn"),
		RuleArns: []*string{
			aws.String("RuleArn"), // Required
			// More values...
		},
	}
	resp, err := svc.DescribeRules(params)

	if err != nil {
		// Print the error, cast err to awserr.Error to get the Code and
		// Message from an error.
		fmt.Println(err.Error())
		return
	}

	// Pretty-print the response data.
	fmt.Println(resp)
}
Example #9
0
func ExampleELBV2_CreateRule() {
	sess, err := session.NewSession()
	if err != nil {
		fmt.Println("failed to create session,", err)
		return
	}

	svc := elbv2.New(sess)

	params := &elbv2.CreateRuleInput{
		Actions: []*elbv2.Action{ // Required
			{ // Required
				TargetGroupArn: aws.String("TargetGroupArn"), // Required
				Type:           aws.String("ActionTypeEnum"), // Required
			},
			// More values...
		},
		Conditions: []*elbv2.RuleCondition{ // Required
			{ // Required
				Field: aws.String("ConditionFieldName"),
				Values: []*string{
					aws.String("StringValue"), // Required
					// More values...
				},
			},
			// More values...
		},
		ListenerArn: aws.String("ListenerArn"), // Required
		Priority:    aws.Int64(1),              // Required
	}
	resp, err := svc.CreateRule(params)

	if err != nil {
		// Print the error, cast err to awserr.Error to get the Code and
		// Message from an error.
		fmt.Println(err.Error())
		return
	}

	// Pretty-print the response data.
	fmt.Println(resp)
}
Example #10
0
// GetRegionLoadBalancersV2 returns a slice of Application Load Balancers in the region into the provided LoadBalancersV2 slice
func GetRegionLoadBalancersV2(region string, lbList *LoadBalancersV2) error {
	svc := elbv2.New(session.New(&aws.Config{Region: aws.String(region)}))
	result, err := svc.DescribeLoadBalancers(&elbv2.DescribeLoadBalancersInput{})

	fmt.Println(result)

	if err != nil {
		return err
	}

	secGrpList := new(SecurityGroups)
	err = GetRegionSecurityGroups(region, secGrpList, "")

	lb := make(LoadBalancersV2, len(result.LoadBalancers))
	for i, balancer := range result.LoadBalancers {
		lb[i].Marshal(balancer, region, secGrpList)
	}
	*lbList = append(*lbList, lb[:]...)

	return nil
}
Example #11
0
func ExampleELBV2_CreateLoadBalancer() {
	sess, err := session.NewSession()
	if err != nil {
		fmt.Println("failed to create session,", err)
		return
	}

	svc := elbv2.New(sess)

	params := &elbv2.CreateLoadBalancerInput{
		Name: aws.String("LoadBalancerName"), // Required
		Subnets: []*string{ // Required
			aws.String("SubnetId"), // Required
			// More values...
		},
		Scheme: aws.String("LoadBalancerSchemeEnum"),
		SecurityGroups: []*string{
			aws.String("SecurityGroupId"), // Required
			// More values...
		},
		Tags: []*elbv2.Tag{
			{ // Required
				Key:   aws.String("TagKey"), // Required
				Value: aws.String("TagValue"),
			},
			// More values...
		},
	}
	resp, err := svc.CreateLoadBalancer(params)

	if err != nil {
		// Print the error, cast err to awserr.Error to get the Code and
		// Message from an error.
		fmt.Println(err.Error())
		return
	}

	// Pretty-print the response data.
	fmt.Println(resp)
}
Example #12
0
func ExampleELBV2_ModifyListener() {
	sess, err := session.NewSession()
	if err != nil {
		fmt.Println("failed to create session,", err)
		return
	}

	svc := elbv2.New(sess)

	params := &elbv2.ModifyListenerInput{
		ListenerArn: aws.String("ListenerArn"), // Required
		Certificates: []*elbv2.Certificate{
			{ // Required
				CertificateArn: aws.String("CertificateArn"),
			},
			// More values...
		},
		DefaultActions: []*elbv2.Action{
			{ // Required
				TargetGroupArn: aws.String("TargetGroupArn"), // Required
				Type:           aws.String("ActionTypeEnum"), // Required
			},
			// More values...
		},
		Port:      aws.Int64(1),
		Protocol:  aws.String("ProtocolEnum"),
		SslPolicy: aws.String("SslPolicyName"),
	}
	resp, err := svc.ModifyListener(params)

	if err != nil {
		// Print the error, cast err to awserr.Error to get the Code and
		// Message from an error.
		fmt.Println(err.Error())
		return
	}

	// Pretty-print the response data.
	fmt.Println(resp)
}
Example #13
0
func ExampleELBV2_DescribeTargetGroupAttributes() {
	sess, err := session.NewSession()
	if err != nil {
		fmt.Println("failed to create session,", err)
		return
	}

	svc := elbv2.New(sess)

	params := &elbv2.DescribeTargetGroupAttributesInput{
		TargetGroupArn: aws.String("TargetGroupArn"), // Required
	}
	resp, err := svc.DescribeTargetGroupAttributes(params)

	if err != nil {
		// Print the error, cast err to awserr.Error to get the Code and
		// Message from an error.
		fmt.Println(err.Error())
		return
	}

	// Pretty-print the response data.
	fmt.Println(resp)
}
Example #14
0
// Client configures and returns a fully initialized AWSClient
func (c *Config) Client() (interface{}, error) {
	// Get the auth and region. This can fail if keys/regions were not
	// specified and we're attempting to use the environment.
	log.Println("[INFO] Building AWS region structure")
	err := c.ValidateRegion()
	if err != nil {
		return nil, err
	}

	var client AWSClient
	// store AWS region in client struct, for region specific operations such as
	// bucket storage in S3
	client.region = c.Region

	log.Println("[INFO] Building AWS auth structure")
	creds, err := GetCredentials(c)
	if err != nil {
		return nil, err
	}
	// Call Get to check for credential provider. If nothing found, we'll get an
	// error, and we can present it nicely to the user
	cp, err := creds.Get()
	if err != nil {
		if awsErr, ok := err.(awserr.Error); ok && awsErr.Code() == "NoCredentialProviders" {
			return nil, errors.New(`No valid credential sources found for AWS Provider.
  Please see https://terraform.io/docs/providers/aws/index.html for more information on
  providing credentials for the AWS Provider`)
		}

		return nil, fmt.Errorf("Error loading credentials for AWS Provider: %s", err)
	}

	log.Printf("[INFO] AWS Auth provider used: %q", cp.ProviderName)

	awsConfig := &aws.Config{
		Credentials:      creds,
		Region:           aws.String(c.Region),
		MaxRetries:       aws.Int(c.MaxRetries),
		HTTPClient:       cleanhttp.DefaultClient(),
		S3ForcePathStyle: aws.Bool(c.S3ForcePathStyle),
	}

	if logging.IsDebugOrHigher() {
		awsConfig.LogLevel = aws.LogLevel(aws.LogDebugWithHTTPBody)
		awsConfig.Logger = awsLogger{}
	}

	if c.Insecure {
		transport := awsConfig.HTTPClient.Transport.(*http.Transport)
		transport.TLSClientConfig = &tls.Config{
			InsecureSkipVerify: true,
		}
	}

	// Set up base session
	sess, err := session.NewSession(awsConfig)
	if err != nil {
		return nil, errwrap.Wrapf("Error creating AWS session: {{err}}", err)
	}

	// Removes the SDK Version handler, so we only have the provider User-Agent
	// Ex: "User-Agent: APN/1.0 HashiCorp/1.0 Terraform/0.7.9-dev"
	sess.Handlers.Build.Remove(request.NamedHandler{Name: "core.SDKVersionUserAgentHandler"})
	sess.Handlers.Build.PushFrontNamed(addTerraformVersionToUserAgent)

	if extraDebug := os.Getenv("TERRAFORM_AWS_AUTHFAILURE_DEBUG"); extraDebug != "" {
		sess.Handlers.UnmarshalError.PushFrontNamed(debugAuthFailure)
	}

	// Some services exist only in us-east-1, e.g. because they manage
	// resources that can span across multiple regions, or because
	// signature format v4 requires region to be us-east-1 for global
	// endpoints:
	// http://docs.aws.amazon.com/general/latest/gr/sigv4_changes.html
	usEast1Sess := sess.Copy(&aws.Config{Region: aws.String("us-east-1")})

	// Some services have user-configurable endpoints
	awsEc2Sess := sess.Copy(&aws.Config{Endpoint: aws.String(c.Ec2Endpoint)})
	awsElbSess := sess.Copy(&aws.Config{Endpoint: aws.String(c.ElbEndpoint)})
	awsIamSess := sess.Copy(&aws.Config{Endpoint: aws.String(c.IamEndpoint)})
	awsS3Sess := sess.Copy(&aws.Config{Endpoint: aws.String(c.S3Endpoint)})
	dynamoSess := sess.Copy(&aws.Config{Endpoint: aws.String(c.DynamoDBEndpoint)})
	kinesisSess := sess.Copy(&aws.Config{Endpoint: aws.String(c.KinesisEndpoint)})

	// These two services need to be set up early so we can check on AccountID
	client.iamconn = iam.New(awsIamSess)
	client.stsconn = sts.New(sess)

	if !c.SkipCredsValidation {
		err = c.ValidateCredentials(client.stsconn)
		if err != nil {
			return nil, err
		}
	}

	if !c.SkipRequestingAccountId {
		partition, accountId, err := GetAccountInfo(client.iamconn, client.stsconn, cp.ProviderName)
		if err == nil {
			client.partition = partition
			client.accountid = accountId
		}
	}

	authErr := c.ValidateAccountId(client.accountid)
	if authErr != nil {
		return nil, authErr
	}

	client.acmconn = acm.New(sess)
	client.apigateway = apigateway.New(sess)
	client.appautoscalingconn = applicationautoscaling.New(sess)
	client.autoscalingconn = autoscaling.New(sess)
	client.cfconn = cloudformation.New(sess)
	client.cloudfrontconn = cloudfront.New(sess)
	client.cloudtrailconn = cloudtrail.New(sess)
	client.cloudwatchconn = cloudwatch.New(sess)
	client.cloudwatcheventsconn = cloudwatchevents.New(sess)
	client.cloudwatchlogsconn = cloudwatchlogs.New(sess)
	client.codecommitconn = codecommit.New(usEast1Sess)
	client.codedeployconn = codedeploy.New(sess)
	client.dsconn = directoryservice.New(sess)
	client.dynamodbconn = dynamodb.New(dynamoSess)
	client.ec2conn = ec2.New(awsEc2Sess)
	client.ecrconn = ecr.New(sess)
	client.ecsconn = ecs.New(sess)
	client.efsconn = efs.New(sess)
	client.elasticacheconn = elasticache.New(sess)
	client.elasticbeanstalkconn = elasticbeanstalk.New(sess)
	client.elastictranscoderconn = elastictranscoder.New(sess)
	client.elbconn = elb.New(awsElbSess)
	client.elbv2conn = elbv2.New(awsElbSess)
	client.emrconn = emr.New(sess)
	client.esconn = elasticsearch.New(sess)
	client.firehoseconn = firehose.New(sess)
	client.glacierconn = glacier.New(sess)
	client.kinesisconn = kinesis.New(kinesisSess)
	client.kmsconn = kms.New(sess)
	client.lambdaconn = lambda.New(sess)
	client.lightsailconn = lightsail.New(usEast1Sess)
	client.opsworksconn = opsworks.New(usEast1Sess)
	client.r53conn = route53.New(usEast1Sess)
	client.rdsconn = rds.New(sess)
	client.redshiftconn = redshift.New(sess)
	client.simpledbconn = simpledb.New(sess)
	client.s3conn = s3.New(awsS3Sess)
	client.sesConn = ses.New(sess)
	client.snsconn = sns.New(sess)
	client.sqsconn = sqs.New(sess)
	client.ssmconn = ssm.New(sess)
	client.wafconn = waf.New(sess)

	return &client, nil
}