-
Notifications
You must be signed in to change notification settings - Fork 163
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 #1162 from cloudskiff/add_google_bigtable_table
Add google_bigtable_table
- Loading branch information
Showing
14 changed files
with
346 additions
and
0 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
12 changes: 12 additions & 0 deletions
12
pkg/iac/terraform/state/test/google_bigtable_table/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,12 @@ | ||
[ | ||
{ | ||
"Id": "projects/cloudskiff-dev-elie/instances/tf-instance/tables/tf-table", | ||
"Type": "google_bigtable_table", | ||
"Attrs": { | ||
"id": "projects/cloudskiff-dev-elie/instances/tf-instance/tables/tf-table", | ||
"instance_name": "tf-instance", | ||
"name": "tf-table", | ||
"project": "cloudskiff-dev-elie" | ||
} | ||
} | ||
] |
33 changes: 33 additions & 0 deletions
33
pkg/iac/terraform/state/test/google_bigtable_table/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,33 @@ | ||
{ | ||
"version": 4, | ||
"terraform_version": "0.15.5", | ||
"serial": 53, | ||
"lineage": "0738cef4-9d69-9ccc-aebd-1177cafa0aa9", | ||
"outputs": {}, | ||
"resources": [ | ||
{ | ||
"mode": "managed", | ||
"type": "google_bigtable_table", | ||
"name": "table", | ||
"provider": "provider[\"registry.terraform.io/hashicorp/google\"]", | ||
"instances": [ | ||
{ | ||
"schema_version": 0, | ||
"attributes": { | ||
"column_family": [], | ||
"id": "projects/cloudskiff-dev-elie/instances/tf-instance/tables/tf-table", | ||
"instance_name": "tf-instance", | ||
"name": "tf-table", | ||
"project": "cloudskiff-dev-elie", | ||
"split_keys": null | ||
}, | ||
"sensitive_attributes": [], | ||
"private": "bnVsbA==", | ||
"dependencies": [ | ||
"google_bigtable_instance.instance" | ||
] | ||
} | ||
] | ||
} | ||
] | ||
} |
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,53 @@ | ||
package google | ||
|
||
import ( | ||
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 GoogleBigtableTableEnumerator struct { | ||
repository repository.AssetRepository | ||
factory resource.ResourceFactory | ||
} | ||
|
||
func NewGoogleBigtableTableEnumerator(repo repository.AssetRepository, factory resource.ResourceFactory) *GoogleBigtableTableEnumerator { | ||
return &GoogleBigtableTableEnumerator{ | ||
repository: repo, | ||
factory: factory, | ||
} | ||
} | ||
|
||
func (e *GoogleBigtableTableEnumerator) SupportedType() resource.ResourceType { | ||
return google.GoogleBigtableTableResourceType | ||
} | ||
|
||
func (e *GoogleBigtableTableEnumerator) Enumerate() ([]*resource.Resource, error) { | ||
resources, err := e.repository.SearchAllBigtableTables() | ||
|
||
if err != nil { | ||
return nil, remoteerror.NewResourceListingError(err, string(e.SupportedType())) | ||
} | ||
|
||
results := make([]*resource.Resource, 0, len(resources)) | ||
|
||
for _, res := range resources { | ||
name, exist := res.GetResource().GetData().GetFields()["name"] | ||
if !exist || name.GetStringValue() == "" { | ||
logrus.WithField("name", res.GetName()).Warn("Unable to retrieve resource name") | ||
continue | ||
} | ||
results = append( | ||
results, | ||
e.factory.CreateAbstractResource( | ||
string(e.SupportedType()), | ||
name.GetStringValue(), | ||
map[string]interface{}{}, | ||
), | ||
) | ||
} | ||
|
||
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package google | ||
|
||
const GoogleBigtableTableResourceType = "google_bigtable_table" |
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,36 @@ | ||
package google_test | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/cloudskiff/driftctl/test" | ||
"github.com/cloudskiff/driftctl/test/acceptance" | ||
) | ||
|
||
func TestAcc_Google_BigtableTable(t *testing.T) { | ||
acceptance.Run(t, acceptance.AccTestCase{ | ||
TerraformVersion: "0.15.5", | ||
Paths: []string{"./testdata/acc/google_bigtable_table"}, | ||
Args: []string{ | ||
"scan", | ||
"--to", "gcp+tf", | ||
}, | ||
Checks: []acceptance.AccCheck{ | ||
{ | ||
// New resources are not visible immediately on GCP api after an apply | ||
// Logic below retry driftctl scan until we can retrieve the results (infra will be in sync) and for maximum 60 seconds | ||
ShouldRetry: func(result *test.ScanResult, retryDuration time.Duration, retryCount uint8) bool { | ||
return !result.IsSync() && retryDuration < time.Minute | ||
}, | ||
Check: func(result *test.ScanResult, stdout string, err error) { | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
result.AssertInfrastructureIsInSync() | ||
result.AssertManagedCount(1) | ||
}, | ||
}, | ||
}, | ||
}) | ||
} |
2 changes: 2 additions & 0 deletions
2
pkg/resource/google/testdata/acc/google_bigtable_table/.driftignore
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,2 @@ | ||
* | ||
!google_bigtable_table |
21 changes: 21 additions & 0 deletions
21
pkg/resource/google/testdata/acc/google_bigtable_table/.terraform.lock.hcl
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.