Skip to content

Commit

Permalink
Move container_attached_install_manifest to a separate PR. (#7108) (#…
Browse files Browse the repository at this point in the history
…13455)

Signed-off-by: Modular Magician <[email protected]>

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Jan 11, 2023
1 parent 5a049d1 commit cd99ad2
Show file tree
Hide file tree
Showing 5 changed files with 196 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/7108.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:new-datasource
google_container_attached_install_manifest
```
84 changes: 84 additions & 0 deletions google/data_source_google_container_attached_install_manifest.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package google

import (
"fmt"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func dataSourceGoogleContainerAttachedInstallManifest() *schema.Resource {
return &schema.Resource{
Read: dataSourceGoogleContainerAttachedInstallManifestRead,
Schema: map[string]*schema.Schema{
"project": {
Type: schema.TypeString,
Required: true,
},
"location": {
Type: schema.TypeString,
Required: true,
},
"cluster_id": {
Type: schema.TypeString,
Required: true,
},
"platform_version": {
Type: schema.TypeString,
Required: true,
},
"manifest": {
Type: schema.TypeString,
Computed: true,
},
},
}
}

func dataSourceGoogleContainerAttachedInstallManifestRead(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
userAgent, err := generateUserAgentString(d, config.userAgent)
if err != nil {
return err
}

clusterId := d.Get("cluster_id").(string)
platformVersion := d.Get("platform_version").(string)

project, err := getProject(d, config)
if err != nil {
return err
}

location, err := getLocation(d, config)
if err != nil {
return err
}
if len(location) == 0 {
return fmt.Errorf("Cannot determine location: set location in this data source or at provider-level")
}

url, err := replaceVars(d, config, "{{ContainerAttachedBasePath}}projects/{{project}}/locations/{{location}}:generateAttachedClusterInstallManifest")
if err != nil {
return err
}
params := map[string]string{
"attached_cluster_id": clusterId,
"platform_version": platformVersion,
}
url, err = addQueryParams(url, params)
if err != nil {
return err
}
res, err := sendRequest(config, "GET", project, url, userAgent, nil)
if err != nil {
return err
}

if err := d.Set("manifest", res["manifest"]); err != nil {
return fmt.Errorf("Error setting manifest: %s", err)
}

d.SetId(time.Now().UTC().String())
return nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package google

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
)

func TestAccDataSourceGoogleContainerAttachedInstallManifest(t *testing.T) {
t.Parallel()

vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccDataSourceGoogleContainerAttachedInstallManifestConfig(randString(t, 10)),
Check: resource.ComposeTestCheckFunc(
testAccDataSourceGoogleContainerAttachedInstallManifestCheck("data.google_container_attached_install_manifest.manifest"),
),
},
},
})
}

func testAccDataSourceGoogleContainerAttachedInstallManifestCheck(data_source_name string) resource.TestCheckFunc {
return func(s *terraform.State) error {
ds, ok := s.RootModule().Resources[data_source_name]
if !ok {
return fmt.Errorf("root module has no resource called %s", data_source_name)
}

manifest, ok := ds.Primary.Attributes["manifest"]
if !ok {
return fmt.Errorf("cannot find 'manifest' attribute")
}
if manifest == "" {
return fmt.Errorf("install manifest data is empty")
}
return nil
}
}

func testAccDataSourceGoogleContainerAttachedInstallManifestConfig(suffix string) string {
return fmt.Sprintf(`
data "google_project" "project" {
}
data "google_container_attached_versions" "versions" {
location = "us-west1"
project = data.google_project.project.project_id
}
data "google_container_attached_install_manifest" "manifest" {
location = "us-west1"
project = data.google_project.project.project_id
cluster_id = "test-cluster-%s"
platform_version = data.google_container_attached_versions.versions.valid_versions[0]
}
`, suffix)
}
1 change: 1 addition & 0 deletions google/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,7 @@ func Provider() *schema.Provider {
"google_container_azure_versions": dataSourceGoogleContainerAzureVersions(),
"google_container_aws_versions": dataSourceGoogleContainerAwsVersions(),
"google_container_attached_versions": dataSourceGoogleContainerAttachedVersions(),
"google_container_attached_install_manifest": dataSourceGoogleContainerAttachedInstallManifest(),
"google_container_cluster": dataSourceGoogleContainerCluster(),
"google_container_engine_versions": dataSourceGoogleContainerEngineVersions(),
"google_container_registry_image": dataSourceGoogleContainerImage(),
Expand Down
45 changes: 45 additions & 0 deletions website/docs/d/container_attached_install_manifest.html.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
subcategory: "ContainerAttached"
page_title: "Google: google_container_attached_install_manifest"
description: |-
Generates a YAML manifest for boot-strapping an Attached cluster registration.
---

# google\_container\_attached\_install_manifest

Provides access to available platform versions in a location for a given project.

## Example Usage

```hcl
data "google_container_attached_install_manifest" "manifest" {
location = "us-west1"
project = "my-project"
cluster_id = "test-cluster-1"
platform_version = "1.25.0-gke.1"
}
output "install_manifest" {
value = data.google_container_attached_install_manifest.manifest
}
```

## Argument Reference

The following arguments are supported:

* `location` (Optional) - The location to list versions for.

* `project` (Optional) - ID of the project to list available platform versions for. Should match the project the cluster will be deployed to.
Defaults to the project that the provider is authenticated with.

* `cluster_id` (Required) - The name that will be used when creating the attached cluster resource.

* `platform_version` (Required) - The platform version for the cluster. A list of valid values can be retrieved using the `google_container_attached_versions` data source.

## Attributes Reference

The following attributes are exported:

* `manifest` - A string with the YAML manifest that needs to be applied to the cluster.

0 comments on commit cd99ad2

Please sign in to comment.