Skip to content

Commit a907fbb

Browse files
Add go bindings to terraform
1 parent 0497c61 commit a907fbb

File tree

3 files changed

+163
-1
lines changed

3 files changed

+163
-1
lines changed

cloudsmith/resource_repository_upstream.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const (
1919
Dart = "dart"
2020
Deb = "deb"
2121
Docker = "docker"
22+
Go = "go"
2223
Helm = "helm"
2324
Maven = "maven"
2425
Npm = "npm"
@@ -71,6 +72,7 @@ var (
7172
Dart,
7273
Deb,
7374
Docker,
75+
Go,
7476
Helm,
7577
Maven,
7678
Npm,
@@ -295,6 +297,24 @@ func resourceRepositoryUpstreamCreate(d *schema.ResourceData, m interface{}) err
295297
}
296298
return execErr
297299
}
300+
case Go:
301+
req := pc.APIClient.ReposApi.ReposUpstreamGoCreate(pc.Auth, namespace, repository)
302+
req = req.Data(cloudsmith.GoUpstreamRequest{
303+
AuthMode: authMode,
304+
AuthSecret: authSecret,
305+
AuthUsername: authUsername,
306+
ExtraHeader1: extraHeader1,
307+
ExtraHeader2: extraHeader2,
308+
ExtraValue1: extraValue1,
309+
ExtraValue2: extraValue2,
310+
IsActive: isActive,
311+
Mode: mode,
312+
Name: name,
313+
Priority: priority,
314+
UpstreamUrl: upstreamUrl,
315+
VerifySsl: verifySsl,
316+
})
317+
upstream, resp, err = pc.APIClient.ReposApi.ReposUpstreamGoCreateExecute(req)
298318
case Helm:
299319
req := pc.APIClient.ReposApi.ReposUpstreamHelmCreate(pc.Auth, namespace, repository)
300320
req = req.Data(cloudsmith.HelmUpstreamRequest{
@@ -498,6 +518,9 @@ func getUpstream(d *schema.ResourceData, m interface{}) (Upstream, *http.Respons
498518
case Docker:
499519
req := pc.APIClient.ReposApi.ReposUpstreamDockerRead(pc.Auth, namespace, repository, d.Id())
500520
upstream, resp, err = pc.APIClient.ReposApi.ReposUpstreamDockerReadExecute(req)
521+
case Go:
522+
req := pc.APIClient.ReposApi.ReposUpstreamGoRead(pc.Auth, namespace, repository, d.Id())
523+
upstream, resp, err = pc.APIClient.ReposApi.ReposUpstreamGoReadExecute(req)
501524
case Helm:
502525
req := pc.APIClient.ReposApi.ReposUpstreamHelmRead(pc.Auth, namespace, repository, d.Id())
503526
upstream, resp, err = pc.APIClient.ReposApi.ReposUpstreamHelmReadExecute(req)
@@ -723,6 +746,24 @@ func resourceRepositoryUpstreamUpdate(d *schema.ResourceData, m interface{}) err
723746
if execErr != nil {
724747
return execErr
725748
}
749+
case Go:
750+
req := pc.APIClient.ReposApi.ReposUpstreamGoUpdate(pc.Auth, namespace, repository, slugPerm)
751+
req = req.Data(cloudsmith.GoUpstreamRequest{
752+
AuthMode: authMode,
753+
AuthSecret: authSecret,
754+
AuthUsername: authUsername,
755+
ExtraHeader1: extraHeader1,
756+
ExtraHeader2: extraHeader2,
757+
ExtraValue1: extraValue1,
758+
ExtraValue2: extraValue2,
759+
IsActive: isActive,
760+
Mode: mode,
761+
Name: name,
762+
Priority: priority,
763+
UpstreamUrl: upstreamUrl,
764+
VerifySsl: verifySsl,
765+
})
766+
upstream, _, err = pc.APIClient.ReposApi.ReposUpstreamGoUpdateExecute(req)
726767
case Helm:
727768
req := pc.APIClient.ReposApi.ReposUpstreamHelmUpdate(pc.Auth, namespace, repository, slugPerm)
728769
req = req.Data(cloudsmith.HelmUpstreamRequest{
@@ -920,6 +961,9 @@ func resourceRepositoryUpstreamDelete(d *schema.ResourceData, m interface{}) err
920961
case Docker:
921962
req := pc.APIClient.ReposApi.ReposUpstreamDockerDelete(pc.Auth, namespace, repository, d.Id())
922963
_, err = pc.APIClient.ReposApi.ReposUpstreamDockerDeleteExecute(req)
964+
case Go:
965+
req := pc.APIClient.ReposApi.ReposUpstreamGoDelete(pc.Auth, namespace, repository, d.Id())
966+
_, err = pc.APIClient.ReposApi.ReposUpstreamGoDeleteExecute(req)
923967
case Helm:
924968
req := pc.APIClient.ReposApi.ReposUpstreamHelmDelete(pc.Auth, namespace, repository, d.Id())
925969
_, err = pc.APIClient.ReposApi.ReposUpstreamHelmDeleteExecute(req)

cloudsmith/resource_repository_upstream_test.go

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,109 @@ resource "cloudsmith_repository_upstream" "fakedocker" {
450450
})
451451
}
452452

453+
func TestAccRepositoryUpstreamGo_basic(t *testing.T) {
454+
t.Parallel()
455+
456+
const goUpstreamResourceName = "cloudsmith_repository_upstream.go_proxy"
457+
458+
testAccRepositoryGoUpstreamConfigBasic := fmt.Sprintf(`
459+
resource "cloudsmith_repository" "test" {
460+
name = "terraform-acc-test-upstream-go"
461+
namespace = "%s"
462+
}
463+
464+
resource "cloudsmith_repository_upstream" "go_proxy" {
465+
namespace = cloudsmith_repository.test.namespace
466+
repository = cloudsmith_repository.test.slug
467+
name = cloudsmith_repository.test.name
468+
upstream_type = "go"
469+
upstream_url = "https://proxy.golang.org"
470+
}
471+
`, namespace)
472+
473+
testAccRepositoryGoUpstreamConfigUpdate := fmt.Sprintf(`
474+
resource "cloudsmith_repository" "test" {
475+
name = "terraform-acc-test-upstream-go"
476+
namespace = "%s"
477+
}
478+
479+
resource "cloudsmith_repository_upstream" "go_proxy" {
480+
extra_header_1 = "X-Custom-Header"
481+
extra_header_2 = "Access-Control-Allow-Origin"
482+
extra_value_1 = "custom-value"
483+
extra_value_2 = "*"
484+
is_active = true
485+
mode = "Proxy Only"
486+
name = cloudsmith_repository.test.name
487+
namespace = cloudsmith_repository.test.namespace
488+
priority = 12345
489+
repository = cloudsmith_repository.test.slug
490+
upstream_type = "go"
491+
upstream_url = "https://proxy.golang.org"
492+
verify_ssl = false
493+
}
494+
`, namespace)
495+
496+
resource.Test(t, resource.TestCase{
497+
PreCheck: func() { testAccPreCheck(t) },
498+
Providers: testAccProviders,
499+
CheckDestroy: testAccRepositoryUpstreamCheckDestroy(goUpstreamResourceName),
500+
Steps: []resource.TestStep{
501+
{
502+
Config: testAccRepositoryGoUpstreamConfigBasic,
503+
Check: resource.ComposeTestCheckFunc(
504+
resource.TestCheckResourceAttr(goUpstreamResourceName, AuthMode, "None"),
505+
resource.TestCheckResourceAttr(goUpstreamResourceName, AuthUsername, ""),
506+
resource.TestCheckNoResourceAttr(goUpstreamResourceName, Component),
507+
resource.TestCheckResourceAttrSet(goUpstreamResourceName, CreatedAt),
508+
resource.TestCheckNoResourceAttr(goUpstreamResourceName, DistroVersion),
509+
resource.TestCheckNoResourceAttr(goUpstreamResourceName, DistroVersions),
510+
resource.TestCheckResourceAttr(goUpstreamResourceName, ExtraHeader1, ""),
511+
resource.TestCheckResourceAttr(goUpstreamResourceName, ExtraHeader2, ""),
512+
resource.TestCheckResourceAttr(goUpstreamResourceName, ExtraValue1, ""),
513+
resource.TestCheckResourceAttr(goUpstreamResourceName, ExtraValue2, ""),
514+
resource.TestCheckNoResourceAttr(goUpstreamResourceName, IncludeSources),
515+
resource.TestCheckResourceAttr(goUpstreamResourceName, IsActive, "true"),
516+
resource.TestCheckResourceAttr(goUpstreamResourceName, Mode, "Proxy Only"),
517+
resource.TestCheckResourceAttrSet(goUpstreamResourceName, Priority),
518+
resource.TestCheckResourceAttrSet(goUpstreamResourceName, SlugPerm),
519+
resource.TestCheckResourceAttrSet(goUpstreamResourceName, UpdatedAt),
520+
resource.TestCheckNoResourceAttr(goUpstreamResourceName, UpstreamDistribution),
521+
resource.TestCheckResourceAttr(goUpstreamResourceName, VerifySsl, "true"),
522+
),
523+
},
524+
{
525+
Config: testAccRepositoryGoUpstreamConfigUpdate,
526+
Check: resource.ComposeTestCheckFunc(
527+
resource.TestCheckNoResourceAttr(goUpstreamResourceName, Component),
528+
resource.TestCheckResourceAttrSet(goUpstreamResourceName, CreatedAt),
529+
resource.TestCheckNoResourceAttr(goUpstreamResourceName, DistroVersion),
530+
resource.TestCheckNoResourceAttr(goUpstreamResourceName, DistroVersions),
531+
resource.TestCheckNoResourceAttr(goUpstreamResourceName, IncludeSources),
532+
resource.TestCheckResourceAttrSet(goUpstreamResourceName, UpdatedAt),
533+
resource.TestCheckNoResourceAttr(goUpstreamResourceName, UpstreamDistribution),
534+
resource.TestCheckResourceAttr(goUpstreamResourceName, IsActive, "true"),
535+
),
536+
},
537+
{
538+
ResourceName: goUpstreamResourceName,
539+
ImportState: true,
540+
ImportStateIdFunc: func(s *terraform.State) (string, error) {
541+
resourceState := s.RootModule().Resources[goUpstreamResourceName]
542+
return fmt.Sprintf(
543+
"%s.%s.%s.%s",
544+
resourceState.Primary.Attributes[Namespace],
545+
resourceState.Primary.Attributes[Repository],
546+
resourceState.Primary.Attributes[UpstreamType],
547+
resourceState.Primary.Attributes[SlugPerm],
548+
), nil
549+
},
550+
ImportStateVerify: true,
551+
},
552+
},
553+
})
554+
}
555+
453556
func TestAccRepositoryUpstreamHelm_basic(t *testing.T) {
454557
t.Parallel()
455558

@@ -1336,6 +1439,9 @@ func testAccRepositoryUpstreamCheckDestroy(resourceName string) resource.TestChe
13361439
case Docker:
13371440
req := pc.APIClient.ReposApi.ReposUpstreamDockerRead(pc.Auth, namespace, repository, slugPerm)
13381441
_, resp, err = pc.APIClient.ReposApi.ReposUpstreamDockerReadExecute(req)
1442+
case Go:
1443+
req := pc.APIClient.ReposApi.ReposUpstreamGoRead(pc.Auth, namespace, repository, slugPerm)
1444+
_, resp, err = pc.APIClient.ReposApi.ReposUpstreamGoReadExecute(req)
13391445
case Helm:
13401446
req := pc.APIClient.ReposApi.ReposUpstreamHelmRead(pc.Auth, namespace, repository, slugPerm)
13411447
_, resp, err = pc.APIClient.ReposApi.ReposUpstreamHelmReadExecute(req)

docs/resources/repository_upstream.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,18 @@ resource "cloudsmith_repository_upstream" "other_docker_upstream" {
111111
}
112112
```
113113

114+
### Go
115+
116+
```hcl
117+
resource "cloudsmith_repository_upstream" "go_proxy" {
118+
name = "Go Proxy"
119+
namespace = "${data.cloudsmith_organization.my_organization.slug_perm}"
120+
repository = "${resource.cloudsmith_repository.my_repository.slug_perm}"
121+
upstream_type = "go"
122+
upstream_url = "https://proxy.golang.org"
123+
}
124+
```
125+
114126
### Helm
115127

116128
```hcl
@@ -235,7 +247,7 @@ The following arguments are supported:
235247
| `priority` | N | number | N/A | Upstream sources are selected for resolving requests by sequential order (1..n), followed by creation date. |
236248
| `repository` | Y | string | N/A | The Repository to which the upstream belongs. |
237249
| `upstream_distribution` | N | string | N/A | Used only in conjunction with an `upstream_type` of `"deb"` to declare the [distribution](https://wiki.debian.org/DebianRepository/Format#Overview) to fetch from the upstream. |
238-
| `upstream_type` | Y | string | `"composer"`<br>`"cran"`<br>`"dart"`<br>`"deb"`<br>`"docker"`<br>`"helm"`<br>`"maven"`<br>`"npm"`<br>`"nuget"`<br>`"python"`<br>`"rpm"`<br>`"ruby"`<br>`"swift"` | The type of Upstream. |
250+
| `upstream_type` | Y | string | `"composer"`<br>`"cran"`<br>`"dart"`<br>`"deb"`<br>`"docker"`<br>`"go"`<br>`"helm"`<br>`"maven"`<br>`"npm"`<br>`"nuget"`<br>`"python"`<br>`"rpm"`<br>`"ruby"`<br>`"swift"` | The type of Upstream. |
239251
| `upstream_url` | Y | string | N/A | The URL for this upstream source. This must be a fully qualified URL including any path elements required to reach the root of the repository. The URL cannot end with a trailing slash. |
240252
| `verify_ssl` | N | bool | N/A | If enabled, SSL certificates are verified when requests are made to this upstream. It's recommended to leave this enabled for all public sources to help mitigate Man-In-The-Middle (MITM) attacks. Please note this only applies to HTTPS upstreams. |
241253

0 commit comments

Comments
 (0)