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

How to contribute support for more resources to this project #21

Closed
jckuester opened this issue Jul 30, 2018 · 1 comment
Closed

How to contribute support for more resources to this project #21

jckuester opened this issue Jul 30, 2018 · 1 comment

Comments

@jckuester
Copy link
Owner

jckuester commented Jul 30, 2018

The following explanation hopefully makes it easy contributing the resources you need to this project. As an example, we go through adding the resource aws_vpc (which is already supported).

1) Add Terraform type ID of the new resource type

Fine the terraform name of the AWS resource type to support (here is a list of all existing resource types) and add it to resource/supported.go.

	Vpc                 TerraformResourceType = "aws_vpc"

2) Add function to list resources

Add here a function that lists all resources of the new resource type. For this you need to find the method of the AWS go API to list all VPCs (you find it by looking in the go doc of the AWS API)

func (a *AWS) vpcs() (interface{}, error) {
	output, err := a.DescribeVpcs(&ec2.DescribeVpcsInput{})
	if err != nil {
		return nil, err
	}
	return output.Vpcs, nil
}

Supported resources need to be added to resource/supported.go.

3) Add delete ID

The field name of the ID used by Terraform to delete the resource. For this we actually have to look in the delete method of the AWS provider for the VPC

var (
	deleteIDs = map[TerraformResourceType]string{
                ...
		Vpc:                 "VpcId",
                ...
        }
)

4) Add custom filter method

In most cases can be left as filterGeneric. Some resources require custom filter methods.

5) Integration tests

Solid testing is necessary, since we don't want this tool to delete resources unexpectedly :-) Integration tests for each resource have its own file; the ones for aws_vpc are in test/vpc_test.go.

The test for each resource is structured as follows:

  1. Create two different resources of aws_vpc (one with ID/tag foo, another with ID/tag bar)
  2. Create a yaml filter for AWSweeper to delete resource with ID/tag foo
  3. Check if resource with ID/tag foo is gone
  4. Check if resource with ID/tag bar hasn't been deleted
@jckuester jckuester changed the title Guideline: How to add support for AWS resources you need Guideline: How to add the AWS resources you need to this project Jul 30, 2018
@jckuester jckuester changed the title Guideline: How to add the AWS resources you need to this project Guideline: How to add new AWS resources to this project Nov 2, 2018
@jckuester jckuester changed the title Guideline: How to add new AWS resources to this project How to add new AWS resources to this project Nov 2, 2018
@jckuester jckuester changed the title How to add new AWS resources to this project How to contribute support of new resources to this project Nov 2, 2018
@jckuester jckuester changed the title How to contribute support of new resources to this project How to contribute new resources to this project Nov 2, 2018
@jckuester jckuester changed the title How to contribute new resources to this project How to contribute support for more resources to this project Nov 2, 2018
@jckuester
Copy link
Owner Author

I am closing this issue as the approach to add new resources changed a lot: All code to list resources is planned to be generated via the awsls project, so the generator would be the place if you want to contribute. Deletion happens via the Terraform AWS Provider, so individual functions to delete resources are not needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant