Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests/provider: Fix hardcoded ARN (EMR*) #15734

Merged
merged 1 commit into from
Oct 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 52 additions & 7 deletions aws/resource_aws_emr_instance_fleet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,66 +227,84 @@ data "aws_availability_zones" "available" {
# Many instance types are not available in this availability zone
exclude_zone_ids = ["usw2-az4"]
state = "available"

filter {
name = "opt-in-status"
values = ["opt-in-not-required"]
}
}

resource "aws_vpc" "test" {
cidr_block = "10.0.0.0/16"
enable_dns_hostnames = true

tags = {
Name = "tf-acc-test-emr-cluster"
}
}

resource "aws_internet_gateway" "test" {
vpc_id = aws_vpc.test.id

tags = {
Name = "tf-acc-test-emr-cluster"
}
}

resource "aws_security_group" "test" {
vpc_id = aws_vpc.test.id

ingress {
from_port = 0
protocol = "-1"
self = true
to_port = 0
}

egress {
cidr_blocks = ["0.0.0.0/0"]
from_port = 0
protocol = "-1"
to_port = 0
}

tags = {
Name = "tf-acc-test-emr-cluster"
}

# EMR will modify ingress rules
lifecycle {
ignore_changes = [ingress]
}
}

resource "aws_subnet" "test" {
availability_zone = data.aws_availability_zones.available.names[0]
cidr_block = "10.0.0.0/24"
map_public_ip_on_launch = false
vpc_id = aws_vpc.test.id

tags = {
Name = "tf-acc-test-emr-cluster"
}
}

resource "aws_route_table" "test" {
vpc_id = aws_vpc.test.id

route {
cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.test.id
}
}

resource "aws_route_table_association" "test" {
route_table_id = aws_route_table.test.id
subnet_id = aws_subnet.test.id
}

data "aws_partition" "current" {}

resource "aws_iam_role" "emr_service" {
name = "%[1]s_default_role"
assume_role_policy = <<EOT
Expand All @@ -297,7 +315,7 @@ resource "aws_iam_role" "emr_service" {
"Sid": "",
"Effect": "Allow",
"Principal": {
"Service": "elasticmapreduce.amazonaws.com"
"Service": "elasticmapreduce.${data.aws_partition.current.dns_suffix}"
},
"Action": "sts:AssumeRole"
}
Expand All @@ -308,13 +326,14 @@ EOT

resource "aws_iam_role_policy_attachment" "emr_service" {
role = aws_iam_role.emr_service.id
policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonElasticMapReduceRole"
policy_arn = "arn:${data.aws_partition.current.partition}:iam::aws:policy/service-role/AmazonElasticMapReduceRole"
}

resource "aws_iam_instance_profile" "emr_instance_profile" {
name = "%[1]s_profile"
role = aws_iam_role.emr_instance_profile.name
}

resource "aws_iam_role" "emr_instance_profile" {
name = "%[1]s_profile_role"
assume_role_policy = <<EOT
Expand All @@ -325,18 +344,20 @@ resource "aws_iam_role" "emr_instance_profile" {
"Sid": "",
"Effect": "Allow",
"Principal": {
"Service": "ec2.amazonaws.com"
"Service": "ec2.${data.aws_partition.current.dns_suffix}"
},
"Action": "sts:AssumeRole"
}
]
}
EOT
}

resource "aws_iam_role_policy_attachment" "emr_instance_profile" {
role = aws_iam_role.emr_instance_profile.id
policy_arn = aws_iam_policy.emr_instance_profile.arn
}

resource "aws_iam_policy" "emr_instance_profile" {
name = "%[1]s_profile"
policy = <<EOT
Expand Down Expand Up @@ -373,38 +394,46 @@ resource "aws_iam_policy" "emr_instance_profile" {
}
EOT
}

resource "aws_emr_cluster" "test" {
name = "%[1]s"
release_label = "emr-5.30.1"
applications = ["Hadoop", "Hive"]
log_uri = "s3n://terraform/testlog/"

master_instance_fleet {
instance_type_configs {
instance_type = "m3.xlarge"
}

target_on_demand_capacity = 1
}

core_instance_fleet {
instance_type_configs {
bid_price_as_percentage_of_on_demand_price = 100

ebs_config {
size = 100
type = "gp2"
volumes_per_instance = 1
}

instance_type = "m4.xlarge"
weighted_capacity = 1
}
name = "core fleet"
target_on_demand_capacity = 1
target_spot_capacity = 0
}

service_role = aws_iam_role.emr_service.arn
depends_on = [
aws_route_table_association.test,
aws_iam_role_policy_attachment.emr_service,
aws_iam_role_policy_attachment.emr_instance_profile,
]

ec2_attributes {
subnet_id = aws_subnet.test.id
emr_managed_master_security_group = aws_security_group.test.id
Expand All @@ -416,17 +445,20 @@ resource "aws_emr_cluster" "test" {

func testAccAWSEmrInstanceFleetConfig(r string) string {
return fmt.Sprintf(testAccAWSEmrInstanceFleetBase+`
resource "aws_emr_instance_fleet" "task" {
resource "aws_emr_instance_fleet" "task" {
cluster_id = aws_emr_cluster.test.id

instance_type_configs {
instance_type = "m3.xlarge"
weighted_capacity = 1
}

launch_specifications {
on_demand_specification {
allocation_strategy = "lowest-price"
}
}

name = "emr_instance_fleet_%[1]s"
target_on_demand_capacity = 1
target_spot_capacity = 0
Expand All @@ -436,17 +468,20 @@ func testAccAWSEmrInstanceFleetConfig(r string) string {

func testAccAWSEmrInstanceFleetConfigZeroCount(r string) string {
return fmt.Sprintf(testAccAWSEmrInstanceFleetBase+`
resource "aws_emr_instance_fleet" "task" {
resource "aws_emr_instance_fleet" "task" {
cluster_id = aws_emr_cluster.test.id

instance_type_configs {
instance_type = "m3.xlarge"
weighted_capacity = 1
}

launch_specifications {
on_demand_specification {
allocation_strategy = "lowest-price"
}
}

name = "emr_instance_fleet_%[1]s"
target_on_demand_capacity = 0
target_spot_capacity = 0
Expand All @@ -456,8 +491,9 @@ func testAccAWSEmrInstanceFleetConfigZeroCount(r string) string {

func testAccAWSEmrInstanceFleetConfigEbsBasic(r string) string {
return fmt.Sprintf(testAccAWSEmrInstanceFleetBase+`
resource "aws_emr_instance_fleet" "task" {
resource "aws_emr_instance_fleet" "task" {
cluster_id = aws_emr_cluster.test.id

instance_type_configs {
bid_price_as_percentage_of_on_demand_price = 100
ebs_config {
Expand All @@ -468,6 +504,7 @@ func testAccAWSEmrInstanceFleetConfigEbsBasic(r string) string {
instance_type = "m4.xlarge"
weighted_capacity = 1
}

launch_specifications {
spot_specification {
allocation_strategy = "capacity-optimized"
Expand All @@ -476,6 +513,7 @@ func testAccAWSEmrInstanceFleetConfigEbsBasic(r string) string {
timeout_duration_minutes = 10
}
}

name = "emr_instance_fleet_%[1]s"
target_on_demand_capacity = 0
target_spot_capacity = 1
Expand All @@ -485,33 +523,40 @@ func testAccAWSEmrInstanceFleetConfigEbsBasic(r string) string {

func testAccAWSEmrInstanceFleetConfigFull(r string) string {
return fmt.Sprintf(testAccAWSEmrInstanceFleetBase+`
resource "aws_emr_instance_fleet" "task" {
resource "aws_emr_instance_fleet" "task" {
cluster_id = aws_emr_cluster.test.id

instance_type_configs {
bid_price_as_percentage_of_on_demand_price = 100
ebs_config {
size = 10
type = "gp2"
volumes_per_instance = 1
}

ebs_config {
size = 20
type = "gp2"
volumes_per_instance = 2
}

instance_type = "m4.xlarge"
weighted_capacity = 1
}

instance_type_configs {
bid_price_as_percentage_of_on_demand_price = 80

ebs_config {
size = 10
type = "gp2"
volumes_per_instance = 1
}

instance_type = "m4.2xlarge"
weighted_capacity = 2
}

launch_specifications {
spot_specification {
allocation_strategy = "capacity-optimized"
Expand Down
8 changes: 7 additions & 1 deletion aws/resource_aws_emr_security_configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ func testAccCheckEmrSecurityConfigurationExists(n string) resource.TestCheckFunc
}

const testAccEmrSecurityConfigurationConfig = `
data "aws_partition" "current" {}

data "aws_region" "current" {}

data "aws_caller_identity" "current" {}

resource "aws_emr_security_configuration" "test" {
configuration = <<EOF
{
Expand All @@ -106,7 +112,7 @@ resource "aws_emr_security_configuration" "test" {
},
"LocalDiskEncryptionConfiguration": {
"EncryptionKeyProviderType": "AwsKms",
"AwsKmsKey": "arn:aws:kms:us-west-2:187416307283:alias/tf_emr_test_key"
"AwsKmsKey": "arn:${data.aws_partition.current.partition}:kms:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:alias/tf_emr_test_key"
}
},
"EnableInTransitEncryption": false,
Expand Down