Merge pull request #539 from cloudskiff/fix/acc_test_destroy

run tf destroy event when apply fail during acc test
main
Martin 2021-05-24 17:29:32 +02:00 committed by GitHub
commit 056ce673f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 76 additions and 14 deletions

View File

@ -8,32 +8,52 @@ terraform {
}
}
locals {
timestamp = formatdate("YYYYMMDDhhmmss", timestamp())
prefix = "dbsubnet-${local.timestamp}"
}
resource "aws_vpc" "vpc" {
cidr_block = "10.1.0.0/16"
tags = {
Name: "${local.prefix}-vpc"
}
}
resource "aws_subnet" "subnet1" {
vpc_id = aws_vpc.vpc.id
cidr_block = "10.1.0.0/24"
availability_zone = "us-east-1a"
tags = {
Name: "${local.prefix}-subnet1"
}
}
resource "aws_subnet" "subnet2" {
vpc_id = aws_vpc.vpc.id
cidr_block = "10.1.1.0/24"
availability_zone = "us-east-1b"
tags = {
Name: "${local.prefix}-subnet2"
}
}
resource "aws_subnet" "subnet3" {
vpc_id = aws_vpc.vpc.id
cidr_block = "10.1.2.0/24"
availability_zone = "us-east-1c"
tags = {
Name: "${local.prefix}-subnet3"
}
}
resource "aws_subnet" "subnet4" {
vpc_id = aws_vpc.vpc.id
cidr_block = "10.1.3.0/24"
availability_zone = "us-east-1a"
tags = {
Name: "${local.prefix}-subnet4"
}
}
resource "aws_db_subnet_group" "foo" {

View File

@ -9,6 +9,11 @@ terraform {
}
}
locals {
timestamp = formatdate("YYYYMMDDhhmmss", timestamp())
prefix = "eip-${local.timestamp}"
}
# data source for an official Ubuntu 20.04 AMI
data "aws_ami" "ubuntu" {
most_recent = true
@ -28,6 +33,9 @@ data "aws_ami" "ubuntu" {
resource "aws_vpc" "default" {
cidr_block = "10.0.0.0/24"
tags = {
Name: "${local.prefix}-default"
}
}
resource "aws_internet_gateway" "gw" {
@ -44,6 +52,9 @@ resource "aws_subnet" "tf_test_subnet" {
cidr_block = "10.0.0.0/24"
depends_on = [aws_internet_gateway.gw]
availability_zone = "us-east-1a"
tags = {
Name: "${local.prefix}-tf_test_subnet"
}
}
resource "aws_instance" "instance" {

View File

@ -8,8 +8,16 @@ terraform {
}
}
locals {
timestamp = formatdate("YYYYMMDDhhmmss", timestamp())
prefix = "subnet-${local.timestamp}"
}
resource "aws_vpc" "vpc_for_subnets" {
cidr_block = "10.0.0.0/16"
tags = {
Name: "${local.prefix}-vpc_for_subnets"
}
}
resource "aws_default_subnet" "default-a" {
@ -31,14 +39,23 @@ resource "aws_subnet" "subnet1" {
create = "60m"
delete = "2h"
}
tags = {
Name: "${local.prefix}-subnet1"
}
}
resource "aws_subnet" "subnet2" {
vpc_id = aws_vpc.vpc_for_subnets.id
cidr_block = "10.0.1.0/24"
tags = {
Name: "${local.prefix}-subnet2"
}
}
resource "aws_subnet" "subnet3" {
vpc_id = aws_vpc.vpc_for_subnets.id
cidr_block = "10.0.2.0/24"
tags = {
Name: "${local.prefix}-subnet3"
}
}

View File

@ -2,25 +2,39 @@ provider "aws" {
region = "us-east-1"
}
locals {
timestamp = formatdate("YYYYMMDDhhmmss", timestamp())
prefix = "vpc-${local.timestamp}"
}
terraform {
required_providers {
aws = "3.19.0"
}
required_providers {
aws = "3.19.0"
}
}
resource "aws_default_vpc" "default" {
tags = {
Name = "Default VPC"
}
tags = {
Name = "Default VPC"
}
}
resource "aws_vpc" "vpc1" {
cidr_block = "10.0.0.0/16"
cidr_block = "10.0.0.0/16"
tags = {
Name: "${local.prefix}-vpc1"
}
}
resource "aws_vpc" "vpc2" {
cidr_block = "10.1.0.0/16"
cidr_block = "10.1.0.0/16"
tags = {
Name: "${local.prefix}-vpc2"
}
}
resource "aws_vpc" "vpc3" {
cidr_block = "10.2.0.0/16"
cidr_block = "10.2.0.0/16"
tags = {
Name: "${local.prefix}-vpc2"
}
}

View File

@ -329,11 +329,6 @@ func Run(t *testing.T, c AccTestCase) {
t.Fatal(err)
}
err = c.terraformApply()
if err != nil {
t.Fatal(err)
}
defer func() {
c.restoreEnv()
err := c.terraformDestroy()
@ -343,6 +338,11 @@ func Run(t *testing.T, c AccTestCase) {
}
}()
err = c.terraformApply()
if err != nil {
t.Fatal(err)
}
logger.Init()
err = c.createResultFile(t)