-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into feat/pipeline-enable-notifications
- Loading branch information
Showing
8 changed files
with
234 additions
and
25 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package codefresh | ||
|
||
import ( | ||
"fmt" | ||
|
||
cfClient "github.com/codefresh-io/terraform-provider-codefresh/codefresh/cfclient" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
func dataSourceProject() *schema.Resource { | ||
return &schema.Resource{ | ||
Description: "This data source retrieves a project by its ID or name.", | ||
Read: dataSourceProjectRead, | ||
Schema: map[string]*schema.Schema{ | ||
"_id": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
"name": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
"tags": { | ||
Type: schema.TypeList, | ||
Optional: true, | ||
Elem: &schema.Schema{ | ||
Type: schema.TypeString, | ||
}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceProjectRead(d *schema.ResourceData, meta interface{}) error { | ||
|
||
client := meta.(*cfClient.Client) | ||
var project *cfClient.Project | ||
var err error | ||
|
||
if _id, _idOk := d.GetOk("_id"); _idOk { | ||
project, err = client.GetProjectByID(_id.(string)) | ||
} else if name, nameOk := d.GetOk("name"); nameOk { | ||
project, err = client.GetProjectByName(name.(string)) | ||
} | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
if project == nil { | ||
return fmt.Errorf("data.codefresh_project - cannot find project") | ||
} | ||
|
||
return mapDataProjectToResource(project, d) | ||
|
||
} | ||
|
||
func mapDataProjectToResource(project *cfClient.Project, d *schema.ResourceData) error { | ||
|
||
if project == nil || project.ID == "" { | ||
return fmt.Errorf("data.codefresh_project - failed to mapDataProjectToResource") | ||
} | ||
d.SetId(project.ID) | ||
|
||
d.Set("_id", project.ID) | ||
d.Set("tags", project.Tags) | ||
|
||
return nil | ||
} |
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,40 @@ | ||
--- | ||
page_title: "codefresh_project Data Source - terraform-provider-codefresh" | ||
subcategory: "" | ||
description: |- | ||
This data source retrieves a project by its ID or name. | ||
--- | ||
|
||
# codefresh_project (Data Source) | ||
|
||
This data source retrieves a project by its ID or name. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
data "codefresh_project" "myapp" { | ||
name = "myapp" | ||
} | ||
resource "codefresh_pipeline" "myapp-deploy" { | ||
name = "${data.codefresh_project.myapp.projectName}/myapp-deploy" | ||
... | ||
} | ||
``` | ||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Optional | ||
|
||
- `_id` (String) | ||
- `name` (String) | ||
- `tags` (List of String) | ||
|
||
### Read-Only | ||
|
||
- `id` (String) The ID of this resource. |
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,29 @@ | ||
--- | ||
page_title: "{{.Name}} {{.Type}} - {{.ProviderName}}" | ||
subcategory: "" | ||
description: |- | ||
{{ .Description | plainmarkdown | trimspace | prefixlines " " }} | ||
--- | ||
|
||
# {{.Name}} ({{.Type}}) | ||
|
||
{{ .Description | trimspace }} | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
data "codefresh_project" "myapp" { | ||
name = "myapp" | ||
} | ||
|
||
|
||
resource "codefresh_pipeline" "myapp-deploy" { | ||
|
||
name = "${data.codefresh_project.myapp.projectName}/myapp-deploy" | ||
|
||
... | ||
} | ||
|
||
``` | ||
|
||
{{ .SchemaMarkdown | trimspace }} |