-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
1 parent
5a049d1
commit cd99ad2
Showing
5 changed files
with
196 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
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
84
google/data_source_google_container_attached_install_manifest.go
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,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 | ||
} |
63 changes: 63 additions & 0 deletions
63
google/data_source_google_container_attached_install_manifest_test.go
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,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) | ||
} |
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
45 changes: 45 additions & 0 deletions
45
website/docs/d/container_attached_install_manifest.html.markdown
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,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. |