Пример #1
0
func TestAccAWSALB_tags(t *testing.T) {
	var conf elbv2.LoadBalancer
	albName := fmt.Sprintf("testaccawsalb-basic-%s", acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum))

	resource.Test(t, resource.TestCase{
		PreCheck:      func() { testAccPreCheck(t) },
		IDRefreshName: "aws_alb.alb_test",
		Providers:     testAccProviders,
		CheckDestroy:  testAccCheckAWSALBDestroy,
		Steps: []resource.TestStep{
			{
				Config: testAccAWSALBConfig_basic(albName),
				Check: resource.ComposeAggregateTestCheckFunc(
					testAccCheckAWSALBExists("aws_alb.alb_test", &conf),
					resource.TestCheckResourceAttr("aws_alb.alb_test", "tags.%", "1"),
					resource.TestCheckResourceAttr("aws_alb.alb_test", "tags.TestName", "TestAccAWSALB_basic"),
				),
			},
			{
				Config: testAccAWSALBConfig_updatedTags(albName),
				Check: resource.ComposeAggregateTestCheckFunc(
					testAccCheckAWSALBExists("aws_alb.alb_test", &conf),
					resource.TestCheckResourceAttr("aws_alb.alb_test", "tags.%", "2"),
					resource.TestCheckResourceAttr("aws_alb.alb_test", "tags.Type", "Sample Type Tag"),
					resource.TestCheckResourceAttr("aws_alb.alb_test", "tags.Environment", "Production"),
				),
			},
		},
	})
}
Пример #2
0
func TestAccAWSALB_updatedSecurityGroups(t *testing.T) {
	var pre, post elbv2.LoadBalancer
	albName := fmt.Sprintf("testaccawsalb-basic-%s", acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum))

	resource.Test(t, resource.TestCase{
		PreCheck:      func() { testAccPreCheck(t) },
		IDRefreshName: "aws_alb.alb_test",
		Providers:     testAccProviders,
		CheckDestroy:  testAccCheckAWSALBDestroy,
		Steps: []resource.TestStep{
			{
				Config: testAccAWSALBConfig_basic(albName),
				Check: resource.ComposeAggregateTestCheckFunc(
					testAccCheckAWSALBExists("aws_alb.alb_test", &pre),
					resource.TestCheckResourceAttr("aws_alb.alb_test", "security_groups.#", "1"),
				),
			},
			{
				Config: testAccAWSALBConfig_updateSecurityGroups(albName),
				Check: resource.ComposeAggregateTestCheckFunc(
					testAccCheckAWSALBExists("aws_alb.alb_test", &post),
					resource.TestCheckResourceAttr("aws_alb.alb_test", "security_groups.#", "2"),
					testAccCheckAWSAlbARNs(&pre, &post),
				),
			},
		},
	})
}
func TestAccAWSALBTargetGroup_tags(t *testing.T) {
	var conf elbv2.TargetGroup
	targetGroupName := fmt.Sprintf("test-target-group-%s", acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum))

	resource.Test(t, resource.TestCase{
		PreCheck:      func() { testAccPreCheck(t) },
		IDRefreshName: "aws_alb_target_group.test",
		Providers:     testAccProviders,
		CheckDestroy:  testAccCheckAWSALBTargetGroupDestroy,
		Steps: []resource.TestStep{
			{
				Config: testAccAWSALBTargetGroupConfig_basic(targetGroupName),
				Check: resource.ComposeAggregateTestCheckFunc(
					testAccCheckAWSALBTargetGroupExists("aws_alb_target_group.test", &conf),
					resource.TestCheckResourceAttr("aws_alb_target_group.test", "tags.%", "1"),
					resource.TestCheckResourceAttr("aws_alb_target_group.test", "tags.TestName", "TestAccAWSALBTargetGroup_basic"),
				),
			},
			{
				Config: testAccAWSALBTargetGroupConfig_updateTags(targetGroupName),
				Check: resource.ComposeAggregateTestCheckFunc(
					testAccCheckAWSALBTargetGroupExists("aws_alb_target_group.test", &conf),
					resource.TestCheckResourceAttr("aws_alb_target_group.test", "tags.%", "2"),
					resource.TestCheckResourceAttr("aws_alb_target_group.test", "tags.Environment", "Production"),
					resource.TestCheckResourceAttr("aws_alb_target_group.test", "tags.Type", "ALB Target Group"),
				),
			},
		},
	})
}
func TestAccAWSALBTargetGroup_changeNameForceNew(t *testing.T) {
	var before, after elbv2.TargetGroup
	targetGroupNameBefore := fmt.Sprintf("test-target-group-%s", acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum))
	targetGroupNameAfter := fmt.Sprintf("test-target-group-%s", acctest.RandStringFromCharSet(4, acctest.CharSetAlphaNum))

	resource.Test(t, resource.TestCase{
		PreCheck:      func() { testAccPreCheck(t) },
		IDRefreshName: "aws_alb_target_group.test",
		Providers:     testAccProviders,
		CheckDestroy:  testAccCheckAWSALBTargetGroupDestroy,
		Steps: []resource.TestStep{
			{
				Config: testAccAWSALBTargetGroupConfig_basic(targetGroupNameBefore),
				Check: resource.ComposeAggregateTestCheckFunc(
					testAccCheckAWSALBTargetGroupExists("aws_alb_target_group.test", &before),
					resource.TestCheckResourceAttr("aws_alb_target_group.test", "name", targetGroupNameBefore),
				),
			},
			{
				Config: testAccAWSALBTargetGroupConfig_basic(targetGroupNameAfter),
				Check: resource.ComposeAggregateTestCheckFunc(
					testAccCheckAWSALBTargetGroupExists("aws_alb_target_group.test", &after),
					resource.TestCheckResourceAttr("aws_alb_target_group.test", "name", targetGroupNameAfter),
				),
			},
		},
	})
}
Пример #5
0
func TestAccAWSALB_accesslogs(t *testing.T) {
	var conf elbv2.LoadBalancer
	bucketName := fmt.Sprintf("testaccawsalbaccesslogs-%s", acctest.RandStringFromCharSet(6, acctest.CharSetAlphaNum))
	albName := fmt.Sprintf("testaccawsalbaccesslog-%s", acctest.RandStringFromCharSet(4, acctest.CharSetAlpha))

	resource.Test(t, resource.TestCase{
		PreCheck:      func() { testAccPreCheck(t) },
		IDRefreshName: "aws_alb.alb_test",
		Providers:     testAccProviders,
		CheckDestroy:  testAccCheckAWSALBDestroy,
		Steps: []resource.TestStep{
			{
				Config: testAccAWSALBConfig_basic(albName),
				Check: resource.ComposeAggregateTestCheckFunc(
					testAccCheckAWSALBExists("aws_alb.alb_test", &conf),
					resource.TestCheckResourceAttr("aws_alb.alb_test", "name", albName),
					resource.TestCheckResourceAttr("aws_alb.alb_test", "internal", "false"),
					resource.TestCheckResourceAttr("aws_alb.alb_test", "subnets.#", "2"),
					resource.TestCheckResourceAttr("aws_alb.alb_test", "security_groups.#", "1"),
					resource.TestCheckResourceAttr("aws_alb.alb_test", "tags.%", "1"),
					resource.TestCheckResourceAttr("aws_alb.alb_test", "tags.TestName", "TestAccAWSALB_basic"),
					resource.TestCheckResourceAttr("aws_alb.alb_test", "enable_deletion_protection", "false"),
					resource.TestCheckResourceAttr("aws_alb.alb_test", "idle_timeout", "30"),
					resource.TestCheckResourceAttrSet("aws_alb.alb_test", "vpc_id"),
					resource.TestCheckResourceAttrSet("aws_alb.alb_test", "zone_id"),
					resource.TestCheckResourceAttrSet("aws_alb.alb_test", "dns_name"),
					resource.TestCheckResourceAttrSet("aws_alb.alb_test", "arn"),
				),
			},

			{
				Config: testAccAWSALBConfig_accessLogs(albName, bucketName),
				Check: resource.ComposeAggregateTestCheckFunc(
					testAccCheckAWSALBExists("aws_alb.alb_test", &conf),
					resource.TestCheckResourceAttr("aws_alb.alb_test", "name", albName),
					resource.TestCheckResourceAttr("aws_alb.alb_test", "internal", "false"),
					resource.TestCheckResourceAttr("aws_alb.alb_test", "subnets.#", "2"),
					resource.TestCheckResourceAttr("aws_alb.alb_test", "security_groups.#", "1"),
					resource.TestCheckResourceAttr("aws_alb.alb_test", "tags.%", "1"),
					resource.TestCheckResourceAttr("aws_alb.alb_test", "tags.TestName", "TestAccAWSALB_basic"),
					resource.TestCheckResourceAttr("aws_alb.alb_test", "enable_deletion_protection", "false"),
					resource.TestCheckResourceAttr("aws_alb.alb_test", "idle_timeout", "50"),
					resource.TestCheckResourceAttrSet("aws_alb.alb_test", "vpc_id"),
					resource.TestCheckResourceAttrSet("aws_alb.alb_test", "zone_id"),
					resource.TestCheckResourceAttrSet("aws_alb.alb_test", "dns_name"),
					resource.TestCheckResourceAttr("aws_alb.alb_test", "access_logs.#", "1"),
					resource.TestCheckResourceAttr("aws_alb.alb_test", "access_logs.0.bucket", bucketName),
					resource.TestCheckResourceAttr("aws_alb.alb_test", "access_logs.0.prefix", "testAccAWSALBConfig_accessLogs"),
					resource.TestCheckResourceAttrSet("aws_alb.alb_test", "arn"),
				),
			},
		},
	})
}
func TestAccAWSSpotFleetRequest_diversifiedAllocation(t *testing.T) {
	var sfr ec2.SpotFleetRequestConfig
	rName := acctest.RandString(10)

	resource.Test(t, resource.TestCase{
		PreCheck:     func() { testAccPreCheck(t) },
		Providers:    testAccProviders,
		CheckDestroy: testAccCheckAWSSpotFleetRequestDestroy,
		Steps: []resource.TestStep{
			resource.TestStep{
				Config: testAccAWSSpotFleetRequestConfigDiversifiedAllocation(rName),
				Check: resource.ComposeAggregateTestCheckFunc(
					testAccCheckAWSSpotFleetRequestExists(
						"aws_spot_fleet_request.foo", &sfr),
					resource.TestCheckResourceAttr(
						"aws_spot_fleet_request.foo", "spot_request_state", "active"),
					resource.TestCheckResourceAttr(
						"aws_spot_fleet_request.foo", "launch_specification.#", "3"),
					resource.TestCheckResourceAttr(
						"aws_spot_fleet_request.foo", "allocation_strategy", "diversified"),
				),
			},
		},
	})
}
func TestAccAWSSpotFleetRequest_overriddingSpotPrice(t *testing.T) {
	var sfr ec2.SpotFleetRequestConfig
	rName := acctest.RandString(10)

	resource.Test(t, resource.TestCase{
		PreCheck:     func() { testAccPreCheck(t) },
		Providers:    testAccProviders,
		CheckDestroy: testAccCheckAWSSpotFleetRequestDestroy,
		Steps: []resource.TestStep{
			resource.TestStep{
				Config: testAccAWSSpotFleetRequestConfigOverridingSpotPrice(rName),
				Check: resource.ComposeAggregateTestCheckFunc(
					testAccCheckAWSSpotFleetRequestExists(
						"aws_spot_fleet_request.foo", &sfr),
					resource.TestCheckResourceAttr(
						"aws_spot_fleet_request.foo", "spot_request_state", "active"),
					resource.TestCheckResourceAttr(
						"aws_spot_fleet_request.foo", "spot_price", "0.005"),
					resource.TestCheckResourceAttr(
						"aws_spot_fleet_request.foo", "launch_specification.#", "2"),
					resource.TestCheckResourceAttr(
						"aws_spot_fleet_request.foo", "launch_specification.522395050.spot_price", "0.01"),
					resource.TestCheckResourceAttr(
						"aws_spot_fleet_request.foo", "launch_specification.522395050.instance_type", "m3.large"),
					resource.TestCheckResourceAttr(
						"aws_spot_fleet_request.foo", "launch_specification.1590006269.spot_price", ""), //there will not be a value here since it's not overriding
					resource.TestCheckResourceAttr(
						"aws_spot_fleet_request.foo", "launch_specification.1590006269.instance_type", "m1.small"),
				),
			},
		},
	})
}
func TestAccAWSALBListener_basic(t *testing.T) {
	var conf elbv2.Listener
	albName := fmt.Sprintf("testlistener-basic-%s", acctest.RandStringFromCharSet(13, acctest.CharSetAlphaNum))
	targetGroupName := fmt.Sprintf("testtargetgroup-%s", acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum))

	resource.Test(t, resource.TestCase{
		PreCheck:      func() { testAccPreCheck(t) },
		IDRefreshName: "aws_alb_listener.front_end",
		Providers:     testAccProviders,
		CheckDestroy:  testAccCheckAWSALBListenerDestroy,
		Steps: []resource.TestStep{
			{
				Config: testAccAWSALBListenerConfig_basic(albName, targetGroupName),
				Check: resource.ComposeAggregateTestCheckFunc(
					testAccCheckAWSALBListenerExists("aws_alb_listener.front_end", &conf),
					resource.TestCheckResourceAttrSet("aws_alb_listener.front_end", "load_balancer_arn"),
					resource.TestCheckResourceAttrSet("aws_alb_listener.front_end", "arn"),
					resource.TestCheckResourceAttr("aws_alb_listener.front_end", "protocol", "HTTP"),
					resource.TestCheckResourceAttr("aws_alb_listener.front_end", "port", "80"),
					resource.TestCheckResourceAttr("aws_alb_listener.front_end", "default_action.#", "1"),
					resource.TestCheckResourceAttr("aws_alb_listener.front_end", "default_action.0.type", "forward"),
					resource.TestCheckResourceAttrSet("aws_alb_listener.front_end", "default_action.0.target_group_arn"),
				),
			},
		},
	})
}
func TestAccAWSSpotFleetRequest_multipleInstanceTypesInSameAz(t *testing.T) {
	var sfr ec2.SpotFleetRequestConfig
	rName := acctest.RandString(10)

	resource.Test(t, resource.TestCase{
		PreCheck:     func() { testAccPreCheck(t) },
		Providers:    testAccProviders,
		CheckDestroy: testAccCheckAWSSpotFleetRequestDestroy,
		Steps: []resource.TestStep{
			resource.TestStep{
				Config: testAccAWSSpotFleetRequestConfigMultipleInstanceTypesinSameAz(rName),
				Check: resource.ComposeAggregateTestCheckFunc(
					testAccCheckAWSSpotFleetRequestExists(
						"aws_spot_fleet_request.foo", &sfr),
					resource.TestCheckResourceAttr(
						"aws_spot_fleet_request.foo", "spot_request_state", "active"),
					resource.TestCheckResourceAttr(
						"aws_spot_fleet_request.foo", "launch_specification.#", "2"),
					resource.TestCheckResourceAttr(
						"aws_spot_fleet_request.foo", "launch_specification.1590006269.instance_type", "m1.small"),
					resource.TestCheckResourceAttr(
						"aws_spot_fleet_request.foo", "launch_specification.1590006269.availability_zone", "us-west-2a"),
					resource.TestCheckResourceAttr(
						"aws_spot_fleet_request.foo", "launch_specification.3079734941.instance_type", "m3.large"),
					resource.TestCheckResourceAttr(
						"aws_spot_fleet_request.foo", "launch_specification.3079734941.availability_zone", "us-west-2a"),
				),
			},
		},
	})
}
func TestAccDataSourceAWSALBListener_https(t *testing.T) {
	albName := fmt.Sprintf("testlistener-https-%s", acctest.RandStringFromCharSet(13, acctest.CharSetAlphaNum))
	targetGroupName := fmt.Sprintf("testtargetgroup-%s", acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum))

	resource.Test(t, resource.TestCase{
		PreCheck:  func() { testAccPreCheck(t) },
		Providers: testAccProviders,
		Steps: []resource.TestStep{
			{
				Config: testAccDataSourceAWSALBListenerConfigHTTPS(albName, targetGroupName),
				Check: resource.ComposeAggregateTestCheckFunc(
					resource.TestCheckResourceAttrSet("data.aws_alb_listener.front_end", "load_balancer_arn"),
					resource.TestCheckResourceAttrSet("data.aws_alb_listener.front_end", "arn"),
					resource.TestCheckResourceAttr("data.aws_alb_listener.front_end", "protocol", "HTTPS"),
					resource.TestCheckResourceAttr("data.aws_alb_listener.front_end", "port", "443"),
					resource.TestCheckResourceAttr("data.aws_alb_listener.front_end", "default_action.#", "1"),
					resource.TestCheckResourceAttr("data.aws_alb_listener.front_end", "default_action.0.type", "forward"),
					resource.TestCheckResourceAttrSet("data.aws_alb_listener.front_end", "default_action.0.target_group_arn"),
					resource.TestCheckResourceAttrSet("data.aws_alb_listener.front_end", "certificate_arn"),
					resource.TestCheckResourceAttr("data.aws_alb_listener.front_end", "ssl_policy", "ELBSecurityPolicy-2015-05"),
				),
			},
		},
	})
}
func TestAccAWSLightsailDomain_disappears(t *testing.T) {
	var domain lightsail.Domain
	lightsailDomainName := fmt.Sprintf("tf-test-lightsail-%s.com", acctest.RandString(5))

	domainDestroy := func(*terraform.State) error {

		conn := testAccProvider.Meta().(*AWSClient).lightsailconn
		_, err := conn.DeleteDomain(&lightsail.DeleteDomainInput{
			DomainName: aws.String(lightsailDomainName),
		})

		if err != nil {
			return fmt.Errorf("Error deleting Lightsail Domain in disapear test")
		}

		return nil
	}

	resource.Test(t, resource.TestCase{
		PreCheck:     func() { testAccPreCheck(t) },
		Providers:    testAccProviders,
		CheckDestroy: testAccCheckAWSLightsailDomainDestroy,
		Steps: []resource.TestStep{
			{
				Config: testAccAWSLightsailDomainConfig_basic(lightsailDomainName),
				Check: resource.ComposeAggregateTestCheckFunc(
					testAccCheckAWSLightsailDomainExists("aws_lightsail_domain.domain_test", &domain),
					domainDestroy,
				),
				ExpectNonEmptyPlan: true,
			},
		},
	})
}
func TestAccAWSALBListenerRule_basic(t *testing.T) {
	var conf elbv2.Rule
	albName := fmt.Sprintf("testrule-basic-%s", acctest.RandStringFromCharSet(13, acctest.CharSetAlphaNum))
	targetGroupName := fmt.Sprintf("testtargetgroup-%s", acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum))

	resource.Test(t, resource.TestCase{
		PreCheck:      func() { testAccPreCheck(t) },
		IDRefreshName: "aws_alb_listener_rule.static",
		Providers:     testAccProviders,
		CheckDestroy:  testAccCheckAWSALBListenerRuleDestroy,
		Steps: []resource.TestStep{
			{
				Config: testAccAWSALBListenerRuleConfig_basic(albName, targetGroupName),
				Check: resource.ComposeAggregateTestCheckFunc(
					testAccCheckAWSALBListenerRuleExists("aws_alb_listener_rule.static", &conf),
					resource.TestCheckResourceAttrSet("aws_alb_listener_rule.static", "arn"),
					resource.TestCheckResourceAttr("aws_alb_listener_rule.static", "priority", "100"),
					resource.TestCheckResourceAttr("aws_alb_listener_rule.static", "action.#", "1"),
					resource.TestCheckResourceAttr("aws_alb_listener_rule.static", "action.0.type", "forward"),
					resource.TestCheckResourceAttrSet("aws_alb_listener_rule.static", "action.0.target_group_arn"),
					resource.TestCheckResourceAttr("aws_alb_listener_rule.static", "condition.#", "1"),
					resource.TestCheckResourceAttr("aws_alb_listener_rule.static", "condition.0.field", "path-pattern"),
					resource.TestCheckResourceAttr("aws_alb_listener_rule.static", "condition.0.values.#", "1"),
					resource.TestCheckResourceAttrSet("aws_alb_listener_rule.static", "condition.0.values.0"),
				),
			},
		},
	})
}
func TestAccAWSSpotFleetRequest_withWeightedCapacity(t *testing.T) {
	var sfr ec2.SpotFleetRequestConfig
	rName := acctest.RandString(10)

	resource.Test(t, resource.TestCase{
		PreCheck:     func() { testAccPreCheck(t) },
		Providers:    testAccProviders,
		CheckDestroy: testAccCheckAWSSpotFleetRequestDestroy,
		Steps: []resource.TestStep{
			resource.TestStep{
				Config: testAccAWSSpotFleetRequestConfigWithWeightedCapacity(rName),
				Check: resource.ComposeAggregateTestCheckFunc(
					testAccCheckAWSSpotFleetRequestExists(
						"aws_spot_fleet_request.foo", &sfr),
					resource.TestCheckResourceAttr(
						"aws_spot_fleet_request.foo", "spot_request_state", "active"),
					resource.TestCheckResourceAttr(
						"aws_spot_fleet_request.foo", "launch_specification.#", "2"),
					resource.TestCheckResourceAttr(
						"aws_spot_fleet_request.foo", "launch_specification.2325690000.weighted_capacity", "3"),
					resource.TestCheckResourceAttr(
						"aws_spot_fleet_request.foo", "launch_specification.2325690000.instance_type", "r3.large"),
					resource.TestCheckResourceAttr(
						"aws_spot_fleet_request.foo", "launch_specification.3079734941.weighted_capacity", "6"),
					resource.TestCheckResourceAttr(
						"aws_spot_fleet_request.foo", "launch_specification.3079734941.instance_type", "m3.large"),
				),
			},
		},
	})
}
func TestAccAWSSpotFleetRequest_lowestPriceAzInGivenList(t *testing.T) {
	var sfr ec2.SpotFleetRequestConfig
	rName := acctest.RandString(10)

	resource.Test(t, resource.TestCase{
		PreCheck:     func() { testAccPreCheck(t) },
		Providers:    testAccProviders,
		CheckDestroy: testAccCheckAWSSpotFleetRequestDestroy,
		Steps: []resource.TestStep{
			resource.TestStep{
				Config: testAccAWSSpotFleetRequestConfigWithAzs(rName),
				Check: resource.ComposeAggregateTestCheckFunc(
					testAccCheckAWSSpotFleetRequestExists(
						"aws_spot_fleet_request.foo", &sfr),
					resource.TestCheckResourceAttr(
						"aws_spot_fleet_request.foo", "spot_request_state", "active"),
					resource.TestCheckResourceAttr(
						"aws_spot_fleet_request.foo", "launch_specification.#", "2"),
					resource.TestCheckResourceAttr(
						"aws_spot_fleet_request.foo", "launch_specification.1590006269.availability_zone", "us-west-2a"),
					resource.TestCheckResourceAttr(
						"aws_spot_fleet_request.foo", "launch_specification.3809475891.availability_zone", "us-west-2b"),
				),
			},
		},
	})
}
func TestAccAWSSpotFleetRequest_changePriceForcesNewRequest(t *testing.T) {
	var before, after ec2.SpotFleetRequestConfig
	rName := acctest.RandString(10)

	resource.Test(t, resource.TestCase{
		PreCheck:     func() { testAccPreCheck(t) },
		Providers:    testAccProviders,
		CheckDestroy: testAccCheckAWSSpotFleetRequestDestroy,
		Steps: []resource.TestStep{
			resource.TestStep{
				Config: testAccAWSSpotFleetRequestConfig(rName),
				Check: resource.ComposeAggregateTestCheckFunc(
					testAccCheckAWSSpotFleetRequestExists(
						"aws_spot_fleet_request.foo", &before),
					resource.TestCheckResourceAttr(
						"aws_spot_fleet_request.foo", "spot_request_state", "active"),
					resource.TestCheckResourceAttr(
						"aws_spot_fleet_request.foo", "spot_price", "0.005"),
					resource.TestCheckResourceAttr(
						"aws_spot_fleet_request.foo", "launch_specification.#", "1"),
				),
			},
			resource.TestStep{
				Config: testAccAWSSpotFleetRequestConfigChangeSpotBidPrice(rName),
				Check: resource.ComposeAggregateTestCheckFunc(
					testAccCheckAWSSpotFleetRequestExists(
						"aws_spot_fleet_request.foo", &after),
					resource.TestCheckResourceAttr(
						"aws_spot_fleet_request.foo", "spot_request_state", "active"),
					resource.TestCheckResourceAttr(
						"aws_spot_fleet_request.foo", "launch_specification.#", "1"),
					resource.TestCheckResourceAttr(
						"aws_spot_fleet_request.foo", "spot_price", "0.01"),
					testAccCheckAWSSpotFleetRequestConfigRecreated(t, &before, &after),
				),
			},
		},
	})
}
func TestAccAWSWafIPSet_changeNameForceNew(t *testing.T) {
	var before, after waf.IPSet
	ipsetName := fmt.Sprintf("ip-set-%s", acctest.RandString(5))
	ipsetNewName := fmt.Sprintf("ip-set-new-%s", acctest.RandString(5))

	resource.Test(t, resource.TestCase{
		PreCheck:     func() { testAccPreCheck(t) },
		Providers:    testAccProviders,
		CheckDestroy: testAccCheckAWSWafIPSetDestroy,
		Steps: []resource.TestStep{
			{
				Config: testAccAWSWafIPSetConfig(ipsetName),
				Check: resource.ComposeAggregateTestCheckFunc(
					testAccCheckAWSWafIPSetExists("aws_waf_ipset.ipset", &before),
					resource.TestCheckResourceAttr(
						"aws_waf_ipset.ipset", "name", ipsetName),
					resource.TestCheckResourceAttr(
						"aws_waf_ipset.ipset", "ip_set_descriptors.4037960608.type", "IPV4"),
					resource.TestCheckResourceAttr(
						"aws_waf_ipset.ipset", "ip_set_descriptors.4037960608.value", "192.0.7.0/24"),
				),
			},
			{
				Config: testAccAWSWafIPSetConfigChangeName(ipsetNewName),
				Check: resource.ComposeAggregateTestCheckFunc(
					testAccCheckAWSWafIPSetExists("aws_waf_ipset.ipset", &after),
					resource.TestCheckResourceAttr(
						"aws_waf_ipset.ipset", "name", ipsetNewName),
					resource.TestCheckResourceAttr(
						"aws_waf_ipset.ipset", "ip_set_descriptors.4037960608.type", "IPV4"),
					resource.TestCheckResourceAttr(
						"aws_waf_ipset.ipset", "ip_set_descriptors.4037960608.value", "192.0.7.0/24"),
				),
			},
		},
	})
}
func TestAccAWSSpotFleetRequest_withWeightedCapacity(t *testing.T) {
	var sfr ec2.SpotFleetRequestConfig
	rName := acctest.RandString(10)

	fulfillSleep := func() resource.TestCheckFunc {
		// sleep so that EC2 can fuflill the request. We do this to guard against a
		// regression and possible leak where we'll destroy the request and the
		// associated IAM role before anything is actually provisioned and running,
		// thus leaking when those newly started instances are attempted to be
		// destroyed
		// See https://github.com/hashicorp/terraform/pull/8938
		return func(s *terraform.State) error {
			log.Printf("[DEBUG] Test: Sleep to allow EC2 to actually begin fulfilling TestAccAWSSpotFleetRequest_withWeightedCapacity request")
			time.Sleep(1 * time.Minute)
			return nil
		}
	}

	resource.Test(t, resource.TestCase{
		PreCheck:     func() { testAccPreCheck(t) },
		Providers:    testAccProviders,
		CheckDestroy: testAccCheckAWSSpotFleetRequestDestroy,
		Steps: []resource.TestStep{
			resource.TestStep{
				Config: testAccAWSSpotFleetRequestConfigWithWeightedCapacity(rName),
				Check: resource.ComposeAggregateTestCheckFunc(
					fulfillSleep(),
					testAccCheckAWSSpotFleetRequestExists(
						"aws_spot_fleet_request.foo", &sfr),
					resource.TestCheckResourceAttr(
						"aws_spot_fleet_request.foo", "spot_request_state", "active"),
					resource.TestCheckResourceAttr(
						"aws_spot_fleet_request.foo", "launch_specification.#", "2"),
					resource.TestCheckResourceAttr(
						"aws_spot_fleet_request.foo", "launch_specification.2325690000.weighted_capacity", "3"),
					resource.TestCheckResourceAttr(
						"aws_spot_fleet_request.foo", "launch_specification.2325690000.instance_type", "r3.large"),
					resource.TestCheckResourceAttr(
						"aws_spot_fleet_request.foo", "launch_specification.3079734941.weighted_capacity", "6"),
					resource.TestCheckResourceAttr(
						"aws_spot_fleet_request.foo", "launch_specification.3079734941.instance_type", "m3.large"),
				),
			},
		},
	})
}
func TestAccAWSALBTargetGroupAttachment_basic(t *testing.T) {
	targetGroupName := fmt.Sprintf("test-target-group-%s", acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum))

	resource.Test(t, resource.TestCase{
		PreCheck:      func() { testAccPreCheck(t) },
		IDRefreshName: "aws_alb_target_group.test",
		Providers:     testAccProviders,
		CheckDestroy:  testAccCheckAWSALBTargetGroupAttachmentDestroy,
		Steps: []resource.TestStep{
			{
				Config: testAccAWSALBTargetGroupAttachmentConfig_basic(targetGroupName),
				Check: resource.ComposeAggregateTestCheckFunc(
					testAccCheckAWSALBTargetGroupAttachmentExists("aws_alb_target_group_attachment.test"),
				),
			},
		},
	})
}
func TestAccAWSLightsailDomain_basic(t *testing.T) {
	var domain lightsail.Domain
	lightsailDomainName := fmt.Sprintf("tf-test-lightsail-%s.com", acctest.RandString(5))

	resource.Test(t, resource.TestCase{
		PreCheck:     func() { testAccPreCheck(t) },
		Providers:    testAccProviders,
		CheckDestroy: testAccCheckAWSLightsailDomainDestroy,
		Steps: []resource.TestStep{
			{
				Config: testAccAWSLightsailDomainConfig_basic(lightsailDomainName),
				Check: resource.ComposeAggregateTestCheckFunc(
					testAccCheckAWSLightsailDomainExists("aws_lightsail_domain.domain_test", &domain),
				),
			},
		},
	})
}
Пример #20
0
func TestAccAWSALB_generatedName(t *testing.T) {
	var conf elbv2.LoadBalancer

	resource.Test(t, resource.TestCase{
		PreCheck:      func() { testAccPreCheck(t) },
		IDRefreshName: "aws_alb.alb_test",
		Providers:     testAccProviders,
		CheckDestroy:  testAccCheckAWSALBDestroy,
		Steps: []resource.TestStep{
			{
				Config: testAccAWSALBConfig_generatedName(),
				Check: resource.ComposeAggregateTestCheckFunc(
					testAccCheckAWSALBExists("aws_alb.alb_test", &conf),
					resource.TestCheckResourceAttrSet("aws_alb.alb_test", "name"),
				),
			},
		},
	})
}
func TestAccAWSAutoScalingGroup_ALB_TargetGroups_ELBCapacity(t *testing.T) {
	var group autoscaling.Group
	var tg elbv2.TargetGroup

	resource.Test(t, resource.TestCase{
		PreCheck:     func() { testAccPreCheck(t) },
		Providers:    testAccProviders,
		CheckDestroy: testAccCheckAWSAutoScalingGroupDestroy,
		Steps: []resource.TestStep{
			resource.TestStep{
				Config: testAccAWSAutoScalingGroupConfig_ALB_TargetGroup_ELBCapacity,
				Check: resource.ComposeAggregateTestCheckFunc(
					testAccCheckAWSAutoScalingGroupExists("aws_autoscaling_group.bar", &group),
					testAccCheckAWSALBTargetGroupExists("aws_alb_target_group.test", &tg),
					testAccCheckAWSALBTargetGroupHealthy(&tg),
				),
			},
		},
	})
}
func TestAccAWSLightsailKeyPair_nameprefix(t *testing.T) {
	var conf1, conf2 lightsail.KeyPair

	resource.Test(t, resource.TestCase{
		PreCheck:     func() { testAccPreCheck(t) },
		Providers:    testAccProviders,
		CheckDestroy: testAccCheckAWSLightsailKeyPairDestroy,
		Steps: []resource.TestStep{
			{
				Config: testAccAWSLightsailKeyPairConfig_prefixed(),
				Check: resource.ComposeAggregateTestCheckFunc(
					testAccCheckAWSLightsailKeyPairExists("aws_lightsail_key_pair.lightsail_key_pair_test_omit", &conf1),
					testAccCheckAWSLightsailKeyPairExists("aws_lightsail_key_pair.lightsail_key_pair_test_prefixed", &conf2),
					resource.TestCheckResourceAttrSet("aws_lightsail_key_pair.lightsail_key_pair_test_omit", "name"),
					resource.TestCheckResourceAttrSet("aws_lightsail_key_pair.lightsail_key_pair_test_prefixed", "name"),
				),
			},
		},
	})
}
func TestAccAWSSpotFleetRequest_withEBSDisk(t *testing.T) {
	var config ec2.SpotFleetRequestConfig
	rName := acctest.RandString(10)

	resource.Test(t, resource.TestCase{
		PreCheck:     func() { testAccPreCheck(t) },
		Providers:    testAccProviders,
		CheckDestroy: testAccCheckAWSSpotFleetRequestDestroy,
		Steps: []resource.TestStep{
			resource.TestStep{
				Config: testAccAWSSpotFleetRequestEBSConfig(rName),
				Check: resource.ComposeAggregateTestCheckFunc(
					testAccCheckAWSSpotFleetRequestExists(
						"aws_spot_fleet_request.foo", &config),
					testAccCheckAWSSpotFleetRequest_EBSAttributes(
						&config),
				),
			},
		},
	})
}
func TestAccAWSSpotFleetRequest_lowestPriceAzOrSubnetInRegion(t *testing.T) {
	var sfr ec2.SpotFleetRequestConfig

	resource.Test(t, resource.TestCase{
		PreCheck:     func() { testAccPreCheck(t) },
		Providers:    testAccProviders,
		CheckDestroy: testAccCheckAWSSpotFleetRequestDestroy,
		Steps: []resource.TestStep{
			resource.TestStep{
				Config: testAccAWSSpotFleetRequestConfig,
				Check: resource.ComposeAggregateTestCheckFunc(
					testAccCheckAWSSpotFleetRequestExists(
						"aws_spot_fleet_request.foo", &sfr),
					resource.TestCheckResourceAttr(
						"aws_spot_fleet_request.foo", "spot_request_state", "active"),
					resource.TestCheckResourceAttr(
						"aws_spot_fleet_request.foo", "launch_specification.#", "1"),
				),
			},
		},
	})
}
func TestAccAWSLightsailKeyPair_basic(t *testing.T) {
	var conf lightsail.KeyPair
	lightsailName := fmt.Sprintf("tf-test-lightsail-%d", acctest.RandInt())

	resource.Test(t, resource.TestCase{
		PreCheck:     func() { testAccPreCheck(t) },
		Providers:    testAccProviders,
		CheckDestroy: testAccCheckAWSLightsailKeyPairDestroy,
		Steps: []resource.TestStep{
			{
				Config: testAccAWSLightsailKeyPairConfig_basic(lightsailName),
				Check: resource.ComposeAggregateTestCheckFunc(
					testAccCheckAWSLightsailKeyPairExists("aws_lightsail_key_pair.lightsail_key_pair_test", &conf),
					resource.TestCheckResourceAttrSet("aws_lightsail_key_pair.lightsail_key_pair_test", "arn"),
					resource.TestCheckResourceAttrSet("aws_lightsail_key_pair.lightsail_key_pair_test", "fingerprint"),
					resource.TestCheckResourceAttrSet("aws_lightsail_key_pair.lightsail_key_pair_test", "public_key"),
					resource.TestCheckResourceAttrSet("aws_lightsail_key_pair.lightsail_key_pair_test", "private_key"),
				),
			},
		},
	})
}
func TestAccAWSSpotFleetRequest_multipleInstanceTypesInSameSubnet(t *testing.T) {
	var sfr ec2.SpotFleetRequestConfig

	resource.Test(t, resource.TestCase{
		PreCheck:     func() { testAccPreCheck(t) },
		Providers:    testAccProviders,
		CheckDestroy: testAccCheckAWSSpotFleetRequestDestroy,
		Steps: []resource.TestStep{
			resource.TestStep{
				Config: testAccAWSSpotFleetRequestConfigMultipleInstanceTypesinSameSubnet,
				Check: resource.ComposeAggregateTestCheckFunc(
					testAccCheckAWSSpotFleetRequestExists(
						"aws_spot_fleet_request.foo", &sfr),
					resource.TestCheckResourceAttr(
						"aws_spot_fleet_request.foo", "spot_request_state", "active"),
					resource.TestCheckResourceAttr(
						"aws_spot_fleet_request.foo", "launch_specification.#", "2"),
				),
			},
		},
	})
}
func TestAccAWSALBTargetGroup_basic(t *testing.T) {
	var conf elbv2.TargetGroup
	targetGroupName := fmt.Sprintf("test-target-group-%s", acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum))

	resource.Test(t, resource.TestCase{
		PreCheck:      func() { testAccPreCheck(t) },
		IDRefreshName: "aws_alb_target_group.test",
		Providers:     testAccProviders,
		CheckDestroy:  testAccCheckAWSALBTargetGroupDestroy,
		Steps: []resource.TestStep{
			{
				Config: testAccAWSALBTargetGroupConfig_basic(targetGroupName),
				Check: resource.ComposeAggregateTestCheckFunc(
					testAccCheckAWSALBTargetGroupExists("aws_alb_target_group.test", &conf),
					resource.TestCheckResourceAttrSet("aws_alb_target_group.test", "arn"),
					resource.TestCheckResourceAttr("aws_alb_target_group.test", "name", targetGroupName),
					resource.TestCheckResourceAttr("aws_alb_target_group.test", "port", "443"),
					resource.TestCheckResourceAttr("aws_alb_target_group.test", "protocol", "HTTPS"),
					resource.TestCheckResourceAttrSet("aws_alb_target_group.test", "vpc_id"),
					resource.TestCheckResourceAttr("aws_alb_target_group.test", "deregistration_delay", "200"),
					resource.TestCheckResourceAttr("aws_alb_target_group.test", "stickiness.#", "1"),
					resource.TestCheckResourceAttr("aws_alb_target_group.test", "stickiness.0.enabled", "true"),
					resource.TestCheckResourceAttr("aws_alb_target_group.test", "stickiness.0.type", "lb_cookie"),
					resource.TestCheckResourceAttr("aws_alb_target_group.test", "stickiness.0.cookie_duration", "10000"),
					resource.TestCheckResourceAttr("aws_alb_target_group.test", "health_check.#", "1"),
					resource.TestCheckResourceAttr("aws_alb_target_group.test", "health_check.0.path", "/health"),
					resource.TestCheckResourceAttr("aws_alb_target_group.test", "health_check.0.interval", "60"),
					resource.TestCheckResourceAttr("aws_alb_target_group.test", "health_check.0.port", "8081"),
					resource.TestCheckResourceAttr("aws_alb_target_group.test", "health_check.0.protocol", "HTTP"),
					resource.TestCheckResourceAttr("aws_alb_target_group.test", "health_check.0.timeout", "3"),
					resource.TestCheckResourceAttr("aws_alb_target_group.test", "health_check.0.healthy_threshold", "3"),
					resource.TestCheckResourceAttr("aws_alb_target_group.test", "health_check.0.unhealthy_threshold", "3"),
					resource.TestCheckResourceAttr("aws_alb_target_group.test", "health_check.0.matcher", "200-299"),
				),
			},
		},
	})
}
func TestAccAWSLightsailInstance_basic(t *testing.T) {
	var conf lightsail.Instance
	lightsailName := fmt.Sprintf("tf-test-lightsail-%d", acctest.RandInt())

	resource.Test(t, resource.TestCase{
		PreCheck:      func() { testAccPreCheck(t) },
		IDRefreshName: "aws_lightsail_instance.lightsail_instance_test",
		Providers:     testAccProviders,
		CheckDestroy:  testAccCheckAWSLightsailInstanceDestroy,
		Steps: []resource.TestStep{
			{
				Config: testAccAWSLightsailInstanceConfig_basic(lightsailName),
				Check: resource.ComposeAggregateTestCheckFunc(
					testAccCheckAWSLightsailInstanceExists("aws_lightsail_instance.lightsail_instance_test", &conf),
					resource.TestCheckResourceAttrSet("aws_lightsail_instance.lightsail_instance_test", "availability_zone"),
					resource.TestCheckResourceAttrSet("aws_lightsail_instance.lightsail_instance_test", "blueprint_id"),
					resource.TestCheckResourceAttrSet("aws_lightsail_instance.lightsail_instance_test", "bundle_id"),
					resource.TestCheckResourceAttrSet("aws_lightsail_instance.lightsail_instance_test", "key_pair_name"),
				),
			},
		},
	})
}
func TestAccAWSAutoScalingGroup_ALB_TargetGroups(t *testing.T) {
	var group autoscaling.Group
	var tg elbv2.TargetGroup
	var tg2 elbv2.TargetGroup

	testCheck := func(targets []*elbv2.TargetGroup) resource.TestCheckFunc {
		return func(*terraform.State) error {
			var ts []string
			var gs []string
			for _, t := range targets {
				ts = append(ts, *t.TargetGroupArn)
			}

			for _, s := range group.TargetGroupARNs {
				gs = append(gs, *s)
			}

			sort.Strings(ts)
			sort.Strings(gs)

			if !reflect.DeepEqual(ts, gs) {
				return fmt.Errorf("Error: target group match not found!\nASG Target groups: %#v\nTarget Group: %#v", ts, gs)
			}
			return nil
		}
	}

	resource.Test(t, resource.TestCase{
		PreCheck:     func() { testAccPreCheck(t) },
		Providers:    testAccProviders,
		CheckDestroy: testAccCheckAWSAutoScalingGroupDestroy,
		Steps: []resource.TestStep{
			resource.TestStep{
				Config: testAccAWSAutoScalingGroupConfig_ALB_TargetGroup_pre,
				Check: resource.ComposeAggregateTestCheckFunc(
					testAccCheckAWSAutoScalingGroupExists("aws_autoscaling_group.bar", &group),
					testAccCheckAWSALBTargetGroupExists("aws_alb_target_group.test", &tg),
					resource.TestCheckResourceAttr(
						"aws_autoscaling_group.bar", "target_group_arns.#", "0"),
				),
			},

			resource.TestStep{
				Config: testAccAWSAutoScalingGroupConfig_ALB_TargetGroup_post_duo,
				Check: resource.ComposeAggregateTestCheckFunc(
					testAccCheckAWSAutoScalingGroupExists("aws_autoscaling_group.bar", &group),
					testAccCheckAWSALBTargetGroupExists("aws_alb_target_group.test", &tg),
					testAccCheckAWSALBTargetGroupExists("aws_alb_target_group.test_more", &tg2),
					testCheck([]*elbv2.TargetGroup{&tg, &tg2}),
					resource.TestCheckResourceAttr(
						"aws_autoscaling_group.bar", "target_group_arns.#", "2"),
				),
			},

			resource.TestStep{
				Config: testAccAWSAutoScalingGroupConfig_ALB_TargetGroup_post,
				Check: resource.ComposeAggregateTestCheckFunc(
					testAccCheckAWSAutoScalingGroupExists("aws_autoscaling_group.bar", &group),
					testAccCheckAWSALBTargetGroupExists("aws_alb_target_group.test", &tg),
					testCheck([]*elbv2.TargetGroup{&tg}),
					resource.TestCheckResourceAttr(
						"aws_autoscaling_group.bar", "target_group_arns.#", "1"),
				),
			},

			resource.TestStep{
				Config: testAccAWSAutoScalingGroupConfig_ALB_TargetGroup_pre,
				Check: resource.ComposeAggregateTestCheckFunc(
					testAccCheckAWSAutoScalingGroupExists("aws_autoscaling_group.bar", &group),
					resource.TestCheckResourceAttr(
						"aws_autoscaling_group.bar", "target_group_arns.#", "0"),
				),
			},
		},
	})
}