Skip to content

Commit

Permalink
add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
ilia-medvedev-codefresh committed May 28, 2024
1 parent 78a3901 commit 05a8216
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 11 deletions.
4 changes: 0 additions & 4 deletions codefresh/data_account_gitops_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ func dataSourceAccountGitopsSettings() *schema.Resource {
Description: "This data source retrieves gitops settings for the active account",
Read: dataSourceAccountGitopsSettingsRead,
Schema: map[string]*schema.Schema{
"_id": {
Type: schema.TypeString,
Computed: true,
},
"name": {
Type: schema.TypeString,
Computed: true,
Expand Down
10 changes: 3 additions & 7 deletions codefresh/resource_account_gitops_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package codefresh
import (
"fmt"
"regexp"
"strings"

"github.com/codefresh-io/terraform-provider-codefresh/codefresh/cfclient"
"github.com/codefresh-io/terraform-provider-codefresh/codefresh/internal/gitops"
Expand All @@ -12,7 +13,7 @@ import (

func resourceAccountGitopsSettings() *schema.Resource {
return &schema.Resource{
Description: "This data source retrieves gitops settings for the active account",
Description: "Codefresh account gitops setting - such as git provider, API URL for the git provider and internal shared config repository",
Read: resourceAccountGitopsSettingsRead,
Create: resourceAccountGitopsSettingsUpdate,
Update: resourceAccountGitopsSettingsUpdate,
Expand All @@ -22,19 +23,14 @@ func resourceAccountGitopsSettings() *schema.Resource {
// Delete not implemenented as gitops settings cannot be removed, only updated
Delete: resourceAccountGitopsSettingsDelete,
Schema: map[string]*schema.Schema{
"_id": {
Type: schema.TypeString,
Description: "Account ID for active account",
Computed: true,
},
"name": {
Type: schema.TypeString,
Description: "Account name for active account",
Computed: true,
},
"git_provider": {
Type: schema.TypeString,
Description: "Git provider name",
Description: fmt.Sprintf("Git provider name - currently supported values are: %s", strings.Join(gitops.GetSupportedGitProvidersList(), " ,")),
Required: true,
ValidateFunc: validation.StringInSlice(gitops.GetSupportedGitProvidersList(), false),
},
Expand Down
18 changes: 18 additions & 0 deletions codefresh/resource_account_gitops_settings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/codefresh-io/terraform-provider-codefresh/codefresh/cfclient"
"github.com/codefresh-io/terraform-provider-codefresh/codefresh/internal/gitops"

//"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
Expand All @@ -29,6 +30,14 @@ func TestAccCodefreshAccountGitopsSettings_basic(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "git_provider", gitops.GitProviderGitHub),
),
},
{
Config: testAccountGitopsSettingsGithubExplicitApiUrl("https://github.com/codefresh-io/terraform-provider-isc-test.git", "https://api.mygithub.com"),
Check: resource.ComposeTestCheckFunc(
testAccCheckGitopsSettings(resourceName, gitops.GitProviderGitHub, "https://api.mygithub.com", "https://github.com/codefresh-io/terraform-provider-isc-test.git"),
resource.TestCheckResourceAttr(resourceName, "git_provider", gitops.GitProviderGitHub),
resource.TestCheckResourceAttr(resourceName, "git_provider_api_url", "https://api.mygithub.com"),
),
},
{
ResourceName: resourceName,
ImportState: true,
Expand Down Expand Up @@ -80,3 +89,12 @@ func testAccountGitopsSettingsGithubDefaultApiUrl(sharedConfigRepository string)
shared_config_repository = "%s"
}`, sharedConfigRepository)
}

func testAccountGitopsSettingsGithubExplicitApiUrl(sharedConfigRepository string, gitProviderApiUrl string) string {
return fmt.Sprintf(`
resource "codefresh_account_gitops_settings" "test" {
git_provider = "GITHUB"
shared_config_repository = "%s"
git_provider_api_url = "%s"
}`, sharedConfigRepository, gitProviderApiUrl)
}
28 changes: 28 additions & 0 deletions docs/data-sources/account_gitops_settings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "codefresh_account_gitops_settings Data Source - terraform-provider-codefresh"
subcategory: ""
description: |-
This data source retrieves gitops settings for the active account
---

# codefresh_account_gitops_settings (Data Source)

This data source retrieves gitops settings for the active account



<!-- schema generated by tfplugindocs -->
## Schema

### Read-Only

- `_id` (String)
- `admins` (List of String)
- `git_provider` (String)
- `git_provider_api_url` (String)
- `id` (String) The ID of this resource.
- `name` (String)
- `shared_config_repository` (String)


52 changes: 52 additions & 0 deletions docs/resources/account_gitops_settings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
page_title: "codefresh_account_gitops_settings Resource - terraform-provider-codefresh"
subcategory: ""
description: |-
Codefresh account gitops setting - such as git provider, API URL for the git provider and internal shared config repository
---

# codefresh_account_gitops_settings (Resource)

Codefresh account gitops setting - such as git provider, API URL for the git provider and internal shared config repository

## Example usage
```hcl
resource "codefresh_account_gitops_settings" "gitops-settings" {
git_provider = "GITHUB"
shared_config_repository = "https://github.com/example-org/codefresh-internal-shared-config.git"
}
```
```hcl
resource "codefresh_account_gitops_settings" "gitops-settings" {
git_provider = "BITBUCKET_SERVER"
git_provider_api_url = https://bitbucket.example.com/rest/api/1.0
shared_config_repository = "http://example-bitbucket.com/scm/proj/codefresh-internal-shared-config.git"
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `git_provider` (String) Git provider name - currently supported values are: GITHUB ,GERRIT ,GITLAB ,BITBUCKET ,BITBUCKET_SERVER
- `shared_config_repository` (String) Shared config repository url. Must be a valid git url which contains `.git`. May also includ path and branch references

### Optional

- `git_provider_api_url` (String) Git provider API url. If not provided can automatically be set for known SaaS git providers. For example - for github it will be set to https://api.github.com

### Read-Only

- `_id` (String) Account ID for active account
- `id` (String) The ID of this resource.
- `name` (String) Account name for active account


-> Once internal config repository is cloned successfully by one or more runtimes it can no longer be changed and all attempted updates will fail.
If you need to change the repository please contact Codefresh support.

## Import
```sh
terraform import codefresh_account_idp.test <id>
```
36 changes: 36 additions & 0 deletions templates/resources/account_gitops_settings.md.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
page_title: "{{.Name}} {{.Type}} - {{.ProviderName}}"
subcategory: ""
description: |-
{{ .Description | plainmarkdown | trimspace | prefixlines " " }}
---

# {{.Name}} ({{.Type}})

{{ .Description | trimspace }}

## Example usage
```hcl
resource "codefresh_account_gitops_settings" "gitops-settings" {
git_provider = "GITHUB"
shared_config_repository = "https://github.com/example-org/codefresh-internal-shared-config.git"
}
```
```hcl
resource "codefresh_account_gitops_settings" "gitops-settings" {
git_provider = "BITBUCKET_SERVER"
git_provider_api_url = https://bitbucket.example.com/rest/api/1.0
shared_config_repository = "http://example-bitbucket.com/scm/proj/codefresh-internal-shared-config.git"
}
```

{{ .SchemaMarkdown | trimspace }}

[!WARNING]
Once internal config repository is cloned successfully by one or more runtimes it can no longer be changed and all attempted updated will fail.
If you need to change the repository please contact Codefresh support.

## Import
```sh
terraform import codefresh_account_idp.test <id>
```

0 comments on commit 05a8216

Please sign in to comment.