|
| 1 | +package test |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + awssdk "github.com/aws/aws-sdk-go/aws" |
| 7 | + "github.com/aws/aws-sdk-go/service/ec2" |
| 8 | + "github.com/cloudposse/test-helpers/pkg/atmos" |
| 9 | + helper "github.com/cloudposse/test-helpers/pkg/atmos/aws-component-helper" |
| 10 | + "github.com/gruntwork-io/terratest/modules/aws" |
| 11 | + "github.com/stretchr/testify/require" |
| 12 | +) |
| 13 | + |
| 14 | +func TestComponent(t *testing.T) { |
| 15 | + awsRegion := "us-east-2" |
| 16 | + |
| 17 | + fixture := helper.NewFixture(t, "../", awsRegion, "test/fixtures") |
| 18 | + |
| 19 | + defer fixture.TearDown() |
| 20 | + fixture.SetUp(&atmos.Options{}) |
| 21 | + |
| 22 | + fixture.Suite("default", func(t *testing.T, suite *helper.Suite) { |
| 23 | + suite.AddDependency("vpc", "default-test") |
| 24 | + |
| 25 | + suite.Setup(t, func(t *testing.T, atm *helper.Atmos) { |
| 26 | + randomID := suite.GetRandomIdentifier() |
| 27 | + inputs := map[string]interface{}{ |
| 28 | + "zone_config": []map[string]string{ |
| 29 | + { |
| 30 | + "subdomain": randomID, |
| 31 | + "zone_name": "example.net", |
| 32 | + }, |
| 33 | + }, |
| 34 | + } |
| 35 | + atm.GetAndDeploy("dns-delegated", "default-test", inputs) |
| 36 | + }) |
| 37 | + |
| 38 | + suite.TearDown(t, func(t *testing.T, atm *helper.Atmos) { |
| 39 | + atm.GetAndDestroy("dns-delegated", "default-test", map[string]interface{}{}) |
| 40 | + }) |
| 41 | + |
| 42 | + suite.Test(t, "single-cluster", func(t *testing.T, atm *helper.Atmos) { |
| 43 | + inputs := map[string]interface{}{ |
| 44 | + "name": "rds", |
| 45 | + "mysql_deletion_protection": false, |
| 46 | + "mysql_storage_encrypted": true, |
| 47 | + "aurora_mysql_engine": "aurora-mysql", |
| 48 | + "allowed_cidr_blocks": []string{}, |
| 49 | + "eks_component_names": []string{}, |
| 50 | + "publicly_accessible": true, |
| 51 | + "aurora_mysql_engine_version": "8.0.mysql_aurora.3.02.0", |
| 52 | + "aurora_mysql_cluster_family": "aurora-mysql8.0", |
| 53 | + "mysql_name": "shared", |
| 54 | + "mysql_cluster_size": 2, |
| 55 | + "mysql_admin_user": "", |
| 56 | + "mysql_admin_password": "", |
| 57 | + "mysql_db_name": "", |
| 58 | + "mysql_instance_type": "db.t3.medium", |
| 59 | + "mysql_skip_final_snapshot": true, |
| 60 | + } |
| 61 | + |
| 62 | + defer atm.GetAndDestroy("aurora-mysql/cluster", "default-test", inputs) |
| 63 | + component := atm.GetAndDeploy("aurora-mysql/cluster", "default-test", inputs) |
| 64 | + |
| 65 | + clusterARN := atm.Output(component, "aurora_mysql_cluster_arn") |
| 66 | + require.Equal(t, clusterARN, "") |
| 67 | + |
| 68 | + // output "aurora_mysql_cluster_id" { |
| 69 | + // output "aurora_mysql_cluster_name" { |
| 70 | + // output "aurora_mysql_endpoint" { |
| 71 | + // output "aurora_mysql_master_hostname" { |
| 72 | + // output "aurora_mysql_master_password" { |
| 73 | + // output "aurora_mysql_master_password_ssm_key" { |
| 74 | + // output "aurora_mysql_master_username" { |
| 75 | + // output "aurora_mysql_reader_endpoint" { |
| 76 | + // output "aurora_mysql_replicas_hostname" { |
| 77 | + // output "cluster_domain" { |
| 78 | + // output "kms_key_arn" { |
| 79 | + |
| 80 | + }) |
| 81 | + |
| 82 | + // suite.Test(t, "public-private-subnets", func(t *testing.T, atm *helper.Atmos) { |
| 83 | + // inputs := map[string]interface{}{ |
| 84 | + // "name": "vpc-terraform", |
| 85 | + // "availability_zones": []string{"b", "c"}, |
| 86 | + // "public_subnets_enabled": true, |
| 87 | + // "nat_gateway_enabled": true, |
| 88 | + // "nat_instance_enabled": false, |
| 89 | + // "subnet_type_tag_key": "eg.cptest.co/subnet/type", |
| 90 | + // "max_nats": 1, |
| 91 | + // "max_subnet_count": 3, |
| 92 | + // "vpc_flow_logs_enabled": false, |
| 93 | + // "ipv4_primary_cidr_block": "172.16.0.0/16", |
| 94 | + // } |
| 95 | + |
| 96 | + // defer atm.GetAndDestroy("vpc/public", "default-test", inputs) |
| 97 | + // component := atm.GetAndDeploy("vpc/public", "default-test", inputs) |
| 98 | + |
| 99 | + // vpcId := atm.Output(component, "vpc_id") |
| 100 | + // require.True(t, strings.HasPrefix(vpcId, "vpc-")) |
| 101 | + |
| 102 | + // vpc := aws.GetVpcById(t, vpcId, awsRegion) |
| 103 | + |
| 104 | + // assert.Equal(t, vpc.Name, fmt.Sprintf("eg-default-ue2-test-vpc-terraform-%s", component.RandomIdentifier)) |
| 105 | + // assert.Equal(t, *vpc.CidrAssociations[0], "172.16.0.0/16") |
| 106 | + // assert.Equal(t, *vpc.CidrBlock, "172.16.0.0/16") |
| 107 | + // assert.Nil(t, vpc.Ipv6CidrAssociations) |
| 108 | + // assert.Equal(t, vpc.Tags["Environment"], "ue2") |
| 109 | + // assert.Equal(t, vpc.Tags["Namespace"], "eg") |
| 110 | + // assert.Equal(t, vpc.Tags["Stage"], "test") |
| 111 | + // assert.Equal(t, vpc.Tags["Tenant"], "default") |
| 112 | + |
| 113 | + // subnets := vpc.Subnets |
| 114 | + // require.Equal(t, 4, len(subnets)) |
| 115 | + |
| 116 | + // public_subnet_ids := atm.OutputList(component, "public_subnet_ids") |
| 117 | + // assert.Equal(t, 2, len(public_subnet_ids)) |
| 118 | + |
| 119 | + // public_subnet_cidrs := atm.OutputList(component, "public_subnet_cidrs") |
| 120 | + // assert.Equal(t, 2, len(public_subnet_cidrs)) |
| 121 | + |
| 122 | + // private_subnet_ids := atm.OutputList(component, "private_subnet_ids") |
| 123 | + // assert.Equal(t, 2, len(private_subnet_ids)) |
| 124 | + |
| 125 | + // private_subnet_cidrs := atm.OutputList(component, "private_subnet_cidrs") |
| 126 | + // assert.Equal(t, 2, len(private_subnet_cidrs)) |
| 127 | + |
| 128 | + // assert.False(t, aws.IsPublicSubnet(t, private_subnet_ids[0], awsRegion)) |
| 129 | + // assert.False(t, aws.IsPublicSubnet(t, private_subnet_ids[1], awsRegion)) |
| 130 | + |
| 131 | + // assert.True(t, aws.IsPublicSubnet(t, public_subnet_ids[0], awsRegion)) |
| 132 | + // assert.True(t, aws.IsPublicSubnet(t, public_subnet_ids[1], awsRegion)) |
| 133 | + |
| 134 | + // nats, err := GetNatsByVpcIdE(t, vpcId, awsRegion) |
| 135 | + // assert.NoError(t, err) |
| 136 | + // assert.Equal(t, 1, len(nats)) |
| 137 | + // }) |
| 138 | + |
| 139 | + }) |
| 140 | +} |
| 141 | + |
| 142 | +func GetNatsByVpcIdE(t *testing.T, vpcId string, awsRegion string) ([]*ec2.NatGateway, error) { |
| 143 | + client, err := aws.NewEc2ClientE(t, awsRegion) |
| 144 | + if err != nil { |
| 145 | + return nil, err |
| 146 | + } |
| 147 | + |
| 148 | + filter := ec2.Filter{Name: awssdk.String("vpc-id"), Values: []*string{&vpcId}} |
| 149 | + response, err := client.DescribeNatGateways(&ec2.DescribeNatGatewaysInput{Filter: []*ec2.Filter{&filter}}) |
| 150 | + if err != nil { |
| 151 | + return nil, err |
| 152 | + } |
| 153 | + return response.NatGateways, nil |
| 154 | +} |
0 commit comments