Skip to content

Commit

Permalink
improve s3
Browse files Browse the repository at this point in the history
Change-Id: I1c3576906e6e3a173ae2ad7ab06ec4bd80aa7ba9
  • Loading branch information
sergeylanzman committed Sep 27, 2018
1 parent 118a173 commit 60121d4
Show file tree
Hide file tree
Showing 13 changed files with 176 additions and 70 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.idea
generated
2 changes: 1 addition & 1 deletion aws_terraforming/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func Generate(service, region string) {
return

}
case "vpn_connetions":
case "vpn_connections":
err := vpn_connection.Generate(region)
if err != nil {
log.Println(err)
Expand Down
11 changes: 10 additions & 1 deletion aws_terraforming/igw/igw.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ var ignoreKey = map[string]bool{
"id": true,
}

var allowEmptyValues = map[string]bool{
"tags.": true,
}

func createResources(igws *ec2.DescribeInternetGatewaysOutput) []terraform_utils.TerraformResource {
resoures := []terraform_utils.TerraformResource{}
for _, internetGateway := range igws.InternetGateways {
Expand Down Expand Up @@ -47,7 +51,12 @@ func Generate(region string) error {
if err != nil {
return err
}
resources, err = terraform_utils.TfstateToTfConverter("terraform.tfstate", "aws", ignoreKey)
converter := terraform_utils.TfstateConverter{
Provider: "aws",
IgnoreKeys: ignoreKey,
AllowEmptyValue: allowEmptyValues,
}
resources, err = converter.Convert("terraform.tfstate")
if err != nil {
return err
}
Expand Down
11 changes: 10 additions & 1 deletion aws_terraforming/nacl/nacl.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ var ignoreKey = map[string]bool{
"id": true,
}

var allowEmptyValues = map[string]bool{
"tags.": true,
}

func createResources(nacls *ec2.DescribeNetworkAclsOutput) []terraform_utils.TerraformResource {
resoures := []terraform_utils.TerraformResource{}
for _, nacl := range nacls.NetworkAcls {
Expand Down Expand Up @@ -47,7 +51,12 @@ func Generate(region string) error {
if err != nil {
return err
}
resources, err = terraform_utils.TfstateToTfConverter("terraform.tfstate", "aws", ignoreKey)
converter := terraform_utils.TfstateConverter{
Provider: "aws",
IgnoreKeys: ignoreKey,
AllowEmptyValue: allowEmptyValues,
}
resources, err = converter.Convert("terraform.tfstate")
if err != nil {
return err
}
Expand Down
24 changes: 19 additions & 5 deletions aws_terraforming/s3/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ var ignoreKey = map[string]bool{
"acceleration_status": true,
}

var allowEmptyValues = map[string]bool{
"tags.": true,
}

var additionalFields = map[string]string{
"force_destroy": "false",
}

func createResources(buckets *s3.ListBucketsOutput, region string) []terraform_utils.TerraformResource {
resoures := []terraform_utils.TerraformResource{}
for _, bucket := range buckets.Buckets {
Expand All @@ -42,11 +50,17 @@ func Generate(region string) error {
}

resources := createResources(buckets, region)
//err = terraform_utils.GenerateTfState(resources)
//if err != nil {
// return err
//}
resources, err = terraform_utils.TfstateToTfConverter("terraform.tfstate", "aws", ignoreKey)
err = terraform_utils.GenerateTfState(resources)
if err != nil {
return err
}
converter := terraform_utils.TfstateConverter{
Provider: "aws",
IgnoreKeys: ignoreKey,
AllowEmptyValue: allowEmptyValues,
AdditionalFields: additionalFields,
}
resources, err = converter.Convert("terraform.tfstate")
if err != nil {
return err
}
Expand Down
14 changes: 13 additions & 1 deletion aws_terraforming/sg/sg.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ var ignoreKey = map[string]bool{
"id": true,
}

var allowEmptyValues = map[string]bool{
"tags.": true,
}

func createResources(securityGroups []*ec2.SecurityGroup) []terraform_utils.TerraformResource {
resources := []terraform_utils.TerraformResource{}
for _, sg := range securityGroups {
Expand Down Expand Up @@ -58,7 +62,15 @@ func Generate(region string) error {
}
resources := createResources(securityGroups)
err = terraform_utils.GenerateTfState(resources)
resources, err = terraform_utils.TfstateToTfConverter("terraform.tfstate", "aws", ignoreKey)
if err != nil {
return err
}
converter := terraform_utils.TfstateConverter{
Provider: "aws",
IgnoreKeys: ignoreKey,
AllowEmptyValue: allowEmptyValues,
}
resources, err = converter.Convert("terraform.tfstate")
if err != nil {
return err
}
Expand Down
11 changes: 10 additions & 1 deletion aws_terraforming/subnet/subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ var ignoreKey = map[string]bool{
"arn": true,
}

var allowEmptyValues = map[string]bool{
"tags.": true,
}

func createResources(subnets *ec2.DescribeSubnetsOutput) []terraform_utils.TerraformResource {
resoures := []terraform_utils.TerraformResource{}
for _, subnet := range subnets.Subnets {
Expand Down Expand Up @@ -48,7 +52,12 @@ func Generate(region string) error {
if err != nil {
return err
}
resources, err = terraform_utils.TfstateToTfConverter("terraform.tfstate", "aws", ignoreKey)
converter := terraform_utils.TfstateConverter{
Provider: "aws",
IgnoreKeys: ignoreKey,
AllowEmptyValue: allowEmptyValues,
}
resources, err = converter.Convert("terraform.tfstate")
if err != nil {
return err
}
Expand Down
11 changes: 10 additions & 1 deletion aws_terraforming/vpc/vpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ var ignoreKey = map[string]bool{
"default_network_acl_id": true,
}

var allowEmptyValues = map[string]bool{
"tags.": true,
}

func createResources(vpcs *ec2.DescribeVpcsOutput) []terraform_utils.TerraformResource {
resoures := []terraform_utils.TerraformResource{}
for _, vpc := range vpcs.Vpcs {
Expand Down Expand Up @@ -54,7 +58,12 @@ func Generate(region string) error {
if err != nil {
return err
}
resources, err = terraform_utils.TfstateToTfConverter("terraform.tfstate", "aws", ignoreKey)
converter := terraform_utils.TfstateConverter{
Provider: "aws",
IgnoreKeys: ignoreKey,
AllowEmptyValue: allowEmptyValues,
}
resources, err = converter.Convert("terraform.tfstate")
if err != nil {
return err
}
Expand Down
11 changes: 10 additions & 1 deletion aws_terraforming/vpn_connection/vpn_connetion.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ var ignoreKey = map[string]bool{
"tunnel1_address": true,
}

var allowEmptyValues = map[string]bool{
"tags.": true,
}

func createResources(vpncs *ec2.DescribeVpnConnectionsOutput) []terraform_utils.TerraformResource {
resoures := []terraform_utils.TerraformResource{}
for _, vpnc := range vpncs.VpnConnections {
Expand Down Expand Up @@ -57,7 +61,12 @@ func Generate(region string) error {
if err != nil {
return err
}
resources, err = terraform_utils.TfstateToTfConverter("terraform.tfstate", "aws", ignoreKey)
converter := terraform_utils.TfstateConverter{
Provider: "aws",
IgnoreKeys: ignoreKey,
AllowEmptyValue: allowEmptyValues,
}
resources, err = converter.Convert("terraform.tfstate")
if err != nil {
return err
}
Expand Down
10 changes: 9 additions & 1 deletion aws_terraforming/vpn_gateway/vgw.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import (
var ignoreKey = map[string]bool{
"id": true,
}
var allowEmptyValues = map[string]bool{
"tags.": true,
}

func createResources(vpnGws *ec2.DescribeVpnGatewaysOutput) []terraform_utils.TerraformResource {
resoures := []terraform_utils.TerraformResource{}
Expand Down Expand Up @@ -47,7 +50,12 @@ func Generate(region string) error {
if err != nil {
return err
}
resources, err = terraform_utils.TfstateToTfConverter("terraform.tfstate", "aws", ignoreKey)
converter := terraform_utils.TfstateConverter{
Provider: "aws",
IgnoreKeys: ignoreKey,
AllowEmptyValue: allowEmptyValues,
}
resources, err = converter.Convert("terraform.tfstate")
if err != nil {
return err
}
Expand Down
10 changes: 6 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ package main
import "waze/terraform/aws_terraforming"

var (
cloud = "aws"
service = "s3"
region = "eu-west-1"
cloud = "aws"
//service = "s3"
region = "eu-west-1"
)

func main() {
switch cloud {
case "aws":
awsTerraforming.Generate(service, region)
for _, service := range []string{"vpc", "sg", "subnet", "igw", "vpn_gateway", "vpn_connections", "s3"} {
awsTerraforming.Generate(service, region)
}
}
}
Loading

0 comments on commit 60121d4

Please sign in to comment.