forked from GoogleCloudPlatform/terraformer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CloudBuild trigger as further resource, fixes GoogleCloudPlatform…
- Loading branch information
1 parent
028dec7
commit 0165b8f
Showing
5 changed files
with
82 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
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
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,76 @@ | ||
package gcp | ||
|
||
import ( | ||
"context" | ||
|
||
cloudbuild "cloud.google.com/go/cloudbuild/apiv1" | ||
pb "google.golang.org/genproto/googleapis/devtools/cloudbuild/v1" | ||
|
||
"github.com/GoogleCloudPlatform/terraformer/terraformutils" | ||
) | ||
|
||
const cbMaxPageSize = 50 | ||
|
||
type CloudBuildGenerator struct { | ||
GCPService | ||
} | ||
|
||
// InitResources generates TerraformResources from GCP API. | ||
func (g *CloudBuildGenerator) InitResources() error { | ||
ctx := context.Background() | ||
|
||
c, err := cloudbuild.NewClient(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
var ( | ||
triggers []*pb.BuildTrigger | ||
nextPageToken string | ||
) | ||
|
||
for { | ||
req := &pb.ListBuildTriggersRequest{ | ||
ProjectId: g.GetArgs()["project"].(string), | ||
PageToken: nextPageToken, | ||
PageSize: cbMaxPageSize, | ||
} | ||
|
||
res, err := c.ListBuildTriggers(ctx, req) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
triggers = append(triggers, res.Triggers...) | ||
nextPageToken = res.NextPageToken | ||
|
||
if nextPageToken == "" { | ||
break | ||
} | ||
} | ||
|
||
g.Resources = g.createBuildTriggers(triggers) | ||
return nil | ||
} | ||
|
||
func (g *CloudBuildGenerator) createBuildTriggers(triggers []*pb.BuildTrigger) []terraformutils.Resource { | ||
var resources []terraformutils.Resource | ||
|
||
for _, trigger := range triggers { | ||
resources = append(resources, terraformutils.NewResource( | ||
trigger.GetId(), | ||
trigger.GetName(), | ||
"google_cloudbuild_trigger", | ||
g.ProviderName, | ||
map[string]string{ | ||
"project": g.GetArgs()["project"].(string), | ||
}, | ||
[]string{}, | ||
map[string]interface{}{ | ||
"filename": trigger.GetFilename(), | ||
}, | ||
)) | ||
} | ||
|
||
return resources | ||
} |
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