Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1025 from cloudskiff/google_compute_firewall
Add google_compute_firewall
- Loading branch information
Showing
18 changed files
with
662 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
pkg/iac/terraform/state/test/google_compute_firewall/results.golden.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
[ | ||
{ | ||
"Id": "projects/cloudskiff-dev-elie/global/firewalls/test-firewall", | ||
"Type": "google_compute_firewall", | ||
"Attrs": { | ||
"allow": [ | ||
{ | ||
"ports": [ | ||
"80", | ||
"8080", | ||
"1000-2000" | ||
], | ||
"protocol": "tcp" | ||
}, | ||
{ | ||
"protocol": "icmp" | ||
} | ||
], | ||
"creation_timestamp": "2021-09-14T02:45:33.796-07:00", | ||
"description": "", | ||
"direction": "INGRESS", | ||
"disabled": false, | ||
"id": "projects/cloudskiff-dev-elie/global/firewalls/test-firewall", | ||
"name": "test-firewall", | ||
"network": "https://www.googleapis.com/compute/v1/projects/cloudskiff-dev-elie/global/networks/test-network", | ||
"priority": 1000, | ||
"project": "cloudskiff-dev-elie", | ||
"self_link": "https://www.googleapis.com/compute/v1/projects/cloudskiff-dev-elie/global/firewalls/test-firewall", | ||
"source_tags": [ | ||
"web" | ||
] | ||
} | ||
} | ||
] |
63 changes: 63 additions & 0 deletions
63
pkg/iac/terraform/state/test/google_compute_firewall/terraform.tfstate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
{ | ||
"version": 4, | ||
"terraform_version": "0.15.0", | ||
"serial": 4, | ||
"lineage": "6eaaea00-2b1a-de47-a247-ebd96b8b5a62", | ||
"outputs": {}, | ||
"resources": [ | ||
{ | ||
"mode": "managed", | ||
"type": "google_compute_firewall", | ||
"name": "default", | ||
"provider": "provider[\"registry.terraform.io/hashicorp/google\"]", | ||
"instances": [ | ||
{ | ||
"schema_version": 1, | ||
"attributes": { | ||
"allow": [ | ||
{ | ||
"ports": [ | ||
"80", | ||
"8080", | ||
"1000-2000" | ||
], | ||
"protocol": "tcp" | ||
}, | ||
{ | ||
"ports": [], | ||
"protocol": "icmp" | ||
} | ||
], | ||
"creation_timestamp": "2021-09-14T02:45:33.796-07:00", | ||
"deny": [], | ||
"description": "", | ||
"destination_ranges": [], | ||
"direction": "INGRESS", | ||
"disabled": false, | ||
"enable_logging": null, | ||
"id": "projects/cloudskiff-dev-elie/global/firewalls/test-firewall", | ||
"log_config": [], | ||
"name": "test-firewall", | ||
"network": "https://www.googleapis.com/compute/v1/projects/cloudskiff-dev-elie/global/networks/test-network", | ||
"priority": 1000, | ||
"project": "cloudskiff-dev-elie", | ||
"self_link": "https://www.googleapis.com/compute/v1/projects/cloudskiff-dev-elie/global/firewalls/test-firewall", | ||
"source_ranges": [], | ||
"source_service_accounts": null, | ||
"source_tags": [ | ||
"web" | ||
], | ||
"target_service_accounts": null, | ||
"target_tags": null, | ||
"timeouts": null | ||
}, | ||
"sensitive_attributes": [], | ||
"private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjoyNDAwMDAwMDAwMDAsImRlbGV0ZSI6MjQwMDAwMDAwMDAwLCJ1cGRhdGUiOjI0MDAwMDAwMDAwMH0sInNjaGVtYV92ZXJzaW9uIjoiMSJ9", | ||
"dependencies": [ | ||
"google_compute_network.default" | ||
] | ||
} | ||
] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package google | ||
|
||
import ( | ||
"strings" | ||
|
||
remoteerror "github.com/cloudskiff/driftctl/pkg/remote/error" | ||
"github.com/cloudskiff/driftctl/pkg/remote/google/repository" | ||
"github.com/cloudskiff/driftctl/pkg/resource" | ||
"github.com/cloudskiff/driftctl/pkg/resource/google" | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
type GoogleComputeFirewallEnumerator struct { | ||
repository repository.AssetRepository | ||
factory resource.ResourceFactory | ||
} | ||
|
||
func NewGoogleComputeFirewallEnumerator(repo repository.AssetRepository, factory resource.ResourceFactory) *GoogleComputeFirewallEnumerator { | ||
return &GoogleComputeFirewallEnumerator{ | ||
repository: repo, | ||
factory: factory, | ||
} | ||
} | ||
|
||
func (e *GoogleComputeFirewallEnumerator) SupportedType() resource.ResourceType { | ||
return google.GoogleComputeFirewallResourceType | ||
} | ||
|
||
func (e *GoogleComputeFirewallEnumerator) Enumerate() ([]*resource.Resource, error) { | ||
resources, err := e.repository.SearchAllFirewalls() | ||
|
||
if err != nil { | ||
return nil, remoteerror.NewResourceListingError(err, string(e.SupportedType())) | ||
} | ||
|
||
results := make([]*resource.Resource, 0, len(resources)) | ||
|
||
for _, res := range resources { | ||
splittedName := strings.Split(res.GetName(), "/") | ||
if len(splittedName) != 8 { | ||
logrus.WithField("name", res.GetName()).Error("Unable to decode project from firewall name") | ||
continue | ||
} | ||
project := splittedName[4] | ||
results = append( | ||
results, | ||
e.factory.CreateAbstractResource( | ||
string(e.SupportedType()), | ||
strings.TrimPrefix(res.GetName(), "//compute.googleapis.com/"), | ||
map[string]interface{}{ | ||
"name": res.DisplayName, | ||
"project": project, | ||
}, | ||
), | ||
) | ||
} | ||
|
||
return results, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.