From f405799f9ce03cb09b4085f1792f69292c262984 Mon Sep 17 00:00:00 2001 From: "denys.kostynchuk" Date: Fri, 25 Oct 2024 11:00:53 +1300 Subject: [PATCH 1/8] Add Google Container Registry feed This is an alias for Docker Registry --- octopusdeploy_framework/framework_provider.go | 1 + .../resource_google_container_registry.go | 176 ++++++++++++++++++ ...rce_google_container_registry_feed_test.go | 148 +++++++++++++++ .../schemas/google_container_registry_feed.go | 47 +++++ octopusdeploy_framework/schemas/s3_feed.go | 2 +- 5 files changed, 373 insertions(+), 1 deletion(-) create mode 100644 octopusdeploy_framework/resource_google_container_registry.go create mode 100644 octopusdeploy_framework/resource_google_container_registry_feed_test.go create mode 100644 octopusdeploy_framework/schemas/google_container_registry_feed.go diff --git a/octopusdeploy_framework/framework_provider.go b/octopusdeploy_framework/framework_provider.go index 5121ed48..45f99835 100644 --- a/octopusdeploy_framework/framework_provider.go +++ b/octopusdeploy_framework/framework_provider.go @@ -86,6 +86,7 @@ func (p *octopusDeployFrameworkProvider) Resources(ctx context.Context) []func() NewMavenFeedResource, NewOCIRegistryFeedResource, NewS3FeedResource, + NewGoogleContainerRegistryFeedResource, NewLifecycleResource, NewEnvironmentResource, NewStepTemplateResource, diff --git a/octopusdeploy_framework/resource_google_container_registry.go b/octopusdeploy_framework/resource_google_container_registry.go new file mode 100644 index 00000000..e9bb299a --- /dev/null +++ b/octopusdeploy_framework/resource_google_container_registry.go @@ -0,0 +1,176 @@ +package octopusdeploy_framework + +import ( + "context" + "fmt" + "github.com/hashicorp/terraform-plugin-framework/path" + + "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/core" + "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/feeds" + "github.com/OctopusDeploy/terraform-provider-octopusdeploy/internal/errors" + "github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/schemas" + "github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/util" + "github.com/hashicorp/terraform-plugin-framework/resource" + "github.com/hashicorp/terraform-plugin-framework/types" + "github.com/hashicorp/terraform-plugin-log/tflog" +) + +type googleContainerRegistryFeedTypeResource struct { + *Config +} + +func NewGoogleContainerRegistryFeedResource() resource.Resource { + return &googleContainerRegistryFeedTypeResource{} +} + +var _ resource.ResourceWithImportState = &googleContainerRegistryFeedTypeResource{} + +func (r *googleContainerRegistryFeedTypeResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { + resp.TypeName = util.GetTypeName("google_container_registry") +} + +func (r *googleContainerRegistryFeedTypeResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { + resp.Schema = schemas.GoogleContainerRegistryFeedSchema{}.GetResourceSchema() +} + +func (r *googleContainerRegistryFeedTypeResource) Configure(_ context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { + r.Config = ResourceConfiguration(req, resp) +} + +func (r *googleContainerRegistryFeedTypeResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { + var data *schemas.GoogleContainerRegistryFeedTypeResourceModel + resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) + if resp.Diagnostics.HasError() { + return + } + + dockerContainerRegistryFeed, err := createDockerContainerRegistryFeedResourceFromGoogleData(data) + if err != nil { + return + } + + tflog.Info(ctx, fmt.Sprintf("creating Google Container Registry feed: %s", dockerContainerRegistryFeed.GetName())) + + client := r.Config.Client + createdFeed, err := feeds.Add(client, dockerContainerRegistryFeed) + if err != nil { + resp.Diagnostics.AddError("unable to create Google Container Registry feed", err.Error()) + return + } + + updateGoogleDataFromDockerContainerRegistryFeed(data, data.SpaceID.ValueString(), createdFeed.(*feeds.DockerContainerRegistry)) + + tflog.Info(ctx, fmt.Sprintf("Google Container Registry feed created (%s)", data.ID)) + resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) +} + +func (r *googleContainerRegistryFeedTypeResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { + var data *schemas.GoogleContainerRegistryFeedTypeResourceModel + resp.Diagnostics.Append(req.State.Get(ctx, &data)...) + if resp.Diagnostics.HasError() { + return + } + + tflog.Info(ctx, fmt.Sprintf("reading Google Container Registry feed (%s)", data.ID)) + + client := r.Config.Client + feed, err := feeds.GetByID(client, data.SpaceID.ValueString(), data.ID.ValueString()) + if err != nil { + if err := errors.ProcessApiErrorV2(ctx, resp, data, err, "google container registry feed"); err != nil { + resp.Diagnostics.AddError("unable to load Google Container Registry feed", err.Error()) + } + return + } + + dockerContainerRegistry := feed.(*feeds.DockerContainerRegistry) + updateGoogleDataFromDockerContainerRegistryFeed(data, data.SpaceID.ValueString(), dockerContainerRegistry) + + tflog.Info(ctx, fmt.Sprintf("Google Container Registry feed read (%s)", dockerContainerRegistry.GetID())) + resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) +} + +func (r *googleContainerRegistryFeedTypeResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { + var data, state *schemas.GoogleContainerRegistryFeedTypeResourceModel + resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) + resp.Diagnostics.Append(req.State.Get(ctx, &state)...) + if resp.Diagnostics.HasError() { + return + } + + tflog.Debug(ctx, fmt.Sprintf("updating Google Container Registry feed '%s'", data.ID.ValueString())) + + feed, err := createDockerContainerRegistryFeedResourceFromGoogleData(data) + feed.ID = state.ID.ValueString() + if err != nil { + resp.Diagnostics.AddError("unable to load Google Container Registry feed", err.Error()) + return + } + + tflog.Info(ctx, fmt.Sprintf("updating Google Container Registry feed (%s)", data.ID)) + + client := r.Config.Client + updatedFeed, err := feeds.Update(client, feed) + if err != nil { + resp.Diagnostics.AddError("unable to update Google Container Registry feed", err.Error()) + return + } + + updateGoogleDataFromDockerContainerRegistryFeed(data, state.SpaceID.ValueString(), updatedFeed.(*feeds.DockerContainerRegistry)) + + tflog.Info(ctx, fmt.Sprintf("Google Container Registry feed updated (%s)", data.ID)) + + resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) +} + +func (r *googleContainerRegistryFeedTypeResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { + var data schemas.GoogleContainerRegistryFeedTypeResourceModel + + resp.Diagnostics.Append(req.State.Get(ctx, &data)...) + if resp.Diagnostics.HasError() { + return + } + + if err := feeds.DeleteByID(r.Config.Client, data.SpaceID.ValueString(), data.ID.ValueString()); err != nil { + resp.Diagnostics.AddError("unable to delete Google Container Registry feed", err.Error()) + return + } +} + +func createDockerContainerRegistryFeedResourceFromGoogleData(data *schemas.GoogleContainerRegistryFeedTypeResourceModel) (*feeds.DockerContainerRegistry, error) { + feed, err := feeds.NewDockerContainerRegistry(data.Name.ValueString()) + if err != nil { + return nil, err + } + + feed.ID = data.ID.ValueString() + feed.FeedURI = data.FeedUri.ValueString() + feed.PackageAcquisitionLocationOptions = nil + feed.Password = core.NewSensitiveValue(data.Password.ValueString()) + feed.SpaceID = data.SpaceID.ValueString() + feed.Username = data.Username.ValueString() + feed.APIVersion = data.APIVersion.ValueString() + feed.RegistryPath = data.RegistryPath.ValueString() + + return feed, nil +} + +func updateGoogleDataFromDockerContainerRegistryFeed(data *schemas.GoogleContainerRegistryFeedTypeResourceModel, spaceId string, feed *feeds.DockerContainerRegistry) { + data.FeedUri = types.StringValue(feed.FeedURI) + data.Name = types.StringValue(feed.Name) + data.SpaceID = types.StringValue(spaceId) + if feed.APIVersion != "" { + data.APIVersion = types.StringValue(feed.APIVersion) + } + if feed.RegistryPath != "" { + data.RegistryPath = types.StringValue(feed.RegistryPath) + } + if feed.Username != "" { + data.Username = types.StringValue(feed.Username) + } + + data.ID = types.StringValue(feed.ID) +} + +func (*googleContainerRegistryFeedTypeResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { + resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) +} diff --git a/octopusdeploy_framework/resource_google_container_registry_feed_test.go b/octopusdeploy_framework/resource_google_container_registry_feed_test.go new file mode 100644 index 00000000..abf0e466 --- /dev/null +++ b/octopusdeploy_framework/resource_google_container_registry_feed_test.go @@ -0,0 +1,148 @@ +package octopusdeploy_framework + +import ( + "fmt" + "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/feeds" + "github.com/hashicorp/terraform-plugin-testing/helper/acctest" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" + "testing" +) + +type googleFeedTestData struct { + name string + uri string + registryPath string + apiVersion string + username string + password string +} + +func TestAccOctopusDeployGoogleFeed(t *testing.T) { + localName := acctest.RandStringFromCharSet(20, acctest.CharSetAlpha) + prefix := "octopusdeploy_s3_feed." + localName + createData := googleFeedTestData{ + name: acctest.RandStringFromCharSet(20, acctest.CharSetAlpha), + uri: "https://cloud.artifact.google.test", + registryPath: acctest.RandStringFromCharSet(10, acctest.CharSetAlpha), + apiVersion: acctest.RandStringFromCharSet(8, acctest.CharSetAlpha), + username: acctest.RandStringFromCharSet(16, acctest.CharSetAlpha), + password: acctest.RandStringFromCharSet(300, acctest.CharSetAlpha), + } + updateData := googleFeedTestData{ + name: createData.name + "-updated", + uri: "https://testcloud.artifact.google.updated", + registryPath: createData.registryPath + "-updated", + apiVersion: createData.apiVersion + "-updated", + username: createData.username + "-updated", + password: createData.password + "-updated", + } + withMinimumData := googleFeedTestData{ + name: "AWS S3 Without Keys", + uri: "https://testcloud.artifact.google.minimum", + } + + resource.Test(t, resource.TestCase{ + CheckDestroy: func(s *terraform.State) error { return testGoogleFeedCheckDestroy(s) }, + PreCheck: func() { TestAccPreCheck(t) }, + ProtoV6ProviderFactories: ProtoV6ProviderFactories(), + Steps: []resource.TestStep{ + { + Config: testGoogleFeedBasic(createData, localName), + Check: testAssertGoogleFeedAttributes(createData, prefix), + }, + { + Config: testGoogleFeedBasic(updateData, localName), + Check: testAssertGoogleFeedAttributes(updateData, prefix), + }, + { + Config: testGoogleFeedWithMinimumData(withMinimumData, localName), + Check: testAssertGoogleFeedMinimumAttributes(withMinimumData, prefix), + }, + }, + }) +} + +func testGoogleFeedBasic(data googleFeedTestData, localName string) string { + return fmt.Sprintf(` + resource "octopusdeploy_google_container_registry" "%s" { + name = "%s" + feed_uri = "%s" + registry_path = "%s" + api_version = "%s" + username = "%s" + password = "%s" + } + `, + localName, + data.name, + data.uri, + data.registryPath, + data.apiVersion, + data.username, + data.password, + ) +} + +func testGoogleFeedWithMinimumData(data googleFeedTestData, localName string) string { + return fmt.Sprintf(` + resource "octopusdeploy_google_container_registry" "%s" { + name = "%s" + feed_uri = "%s" + } + `, + localName, + data.name, + data.uri, + ) +} + +func testAssertGoogleFeedAttributes(expected googleFeedTestData, prefix string) resource.TestCheckFunc { + return resource.ComposeTestCheckFunc( + testGoogleContainerRegistryExists(prefix), + resource.TestCheckResourceAttr(prefix, "name", expected.name), + resource.TestCheckResourceAttr(prefix, "feed_uri", expected.uri), + resource.TestCheckResourceAttr(prefix, "registry_path", expected.registryPath), + resource.TestCheckResourceAttr(prefix, "api_version", expected.apiVersion), + resource.TestCheckResourceAttr(prefix, "username", expected.username), + resource.TestCheckResourceAttr(prefix, "password", expected.password), + ) +} + +func testAssertGoogleFeedMinimumAttributes(expected googleFeedTestData, prefix string) resource.TestCheckFunc { + return resource.ComposeTestCheckFunc( + testGoogleContainerRegistryExists(prefix), + resource.TestCheckResourceAttr(prefix, "name", expected.name), + resource.TestCheckResourceAttr(prefix, "feed_uri", expected.uri), + resource.TestCheckNoResourceAttr(prefix, "registry_path"), + resource.TestCheckNoResourceAttr(prefix, "api_version"), + resource.TestCheckNoResourceAttr(prefix, "username"), + resource.TestCheckNoResourceAttr(prefix, "password"), + ) +} + +func testGoogleFeedCheckDestroy(s *terraform.State) error { + for _, rs := range s.RootModule().Resources { + if rs.Type != "octopusdeploy_google_container_registry_feed" { + continue + } + + feed, err := feeds.GetByID(octoClient, octoClient.GetSpaceID(), rs.Primary.ID) + if err == nil && feed != nil { + return fmt.Errorf("google container registry feed (%s) still exists", rs.Primary.ID) + } + } + + return nil +} + +func testGoogleContainerRegistryExists(prefix string) resource.TestCheckFunc { + return func(s *terraform.State) error { + feedId := s.RootModule().Resources[prefix].Primary.ID + if _, err := feeds.GetByID(octoClient, octoClient.GetSpaceID(), feedId); err != nil { + return err + } + + return nil + } +} diff --git a/octopusdeploy_framework/schemas/google_container_registry_feed.go b/octopusdeploy_framework/schemas/google_container_registry_feed.go new file mode 100644 index 00000000..1826010e --- /dev/null +++ b/octopusdeploy_framework/schemas/google_container_registry_feed.go @@ -0,0 +1,47 @@ +package schemas + +import ( + datasourceSchema "github.com/hashicorp/terraform-plugin-framework/datasource/schema" + resourceSchema "github.com/hashicorp/terraform-plugin-framework/resource/schema" + "github.com/hashicorp/terraform-plugin-framework/types" +) + +type GoogleContainerRegistryFeedSchema struct{} + +var _ EntitySchema = GoogleContainerRegistryFeedSchema{} + +func (d GoogleContainerRegistryFeedSchema) GetResourceSchema() resourceSchema.Schema { + return resourceSchema.Schema{ + Description: "This resource manages a Google Container Registry feed in Octopus Deploy (alias for Docker Container Registry feed)", + Attributes: map[string]resourceSchema.Attribute{ + "api_version": resourceSchema.StringAttribute{ + Optional: true, + }, + "feed_uri": GetFeedUriResourceSchema(), + "id": GetIdResourceSchema(), + "name": GetNameResourceSchema(true), + "password": GetPasswordResourceSchema(false), + "space_id": GetSpaceIdResourceSchema("Google container registry feed"), + "username": GetUsernameResourceSchema(false), + "registry_path": resourceSchema.StringAttribute{ + Optional: true, + }, + }, + } +} + +func (d GoogleContainerRegistryFeedSchema) GetDatasourceSchema() datasourceSchema.Schema { + return datasourceSchema.Schema{} +} + +type GoogleContainerRegistryFeedTypeResourceModel struct { + APIVersion types.String `tfsdk:"api_version"` + FeedUri types.String `tfsdk:"feed_uri"` + Name types.String `tfsdk:"name"` + Password types.String `tfsdk:"password"` + SpaceID types.String `tfsdk:"space_id"` + Username types.String `tfsdk:"username"` + RegistryPath types.String `tfsdk:"registry_path"` + + ResourceModel +} diff --git a/octopusdeploy_framework/schemas/s3_feed.go b/octopusdeploy_framework/schemas/s3_feed.go index cc5612b2..0984ffc3 100644 --- a/octopusdeploy_framework/schemas/s3_feed.go +++ b/octopusdeploy_framework/schemas/s3_feed.go @@ -10,7 +10,7 @@ type S3FeedSchema struct{} func (m S3FeedSchema) GetResourceSchema() resourceSchema.Schema { return resourceSchema.Schema{ - Description: "This resource manages a OCI Registry feed in Octopus Deploy.", + Description: "This resource manages a Amazon S3 Bucket feed in Octopus Deploy.", Attributes: map[string]resourceSchema.Attribute{ "use_machine_credentials": GetRequiredBooleanResourceAttribute("When true will use credentials configured on the worker"), "access_key": GetOptionalStringResourceSchema("The AWS access key to use when authenticating against Amazon Web Services"), From 9f24b6f3a5a98f246fb57d0525b46b1908b7314e Mon Sep 17 00:00:00 2001 From: "denys.kostynchuk" Date: Fri, 25 Oct 2024 11:02:33 +1300 Subject: [PATCH 2/8] Update file name --- ...ry_feed_test.go => resource_google_container_registry_test.go} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename octopusdeploy_framework/{resource_google_container_registry_feed_test.go => resource_google_container_registry_test.go} (100%) diff --git a/octopusdeploy_framework/resource_google_container_registry_feed_test.go b/octopusdeploy_framework/resource_google_container_registry_test.go similarity index 100% rename from octopusdeploy_framework/resource_google_container_registry_feed_test.go rename to octopusdeploy_framework/resource_google_container_registry_test.go From c567487e087cf101d6d0bf64ce908b07cdaf5809 Mon Sep 17 00:00:00 2001 From: "denys.kostynchuk" Date: Fri, 25 Oct 2024 11:13:18 +1300 Subject: [PATCH 3/8] Add docs for Google Container Registry --- docs/resources/google_container_registry.md | 50 +++++++++++++++++++ docs/resources/s3_feed.md | 4 +- .../import.sh | 1 + .../resource.tf | 6 +++ 4 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 docs/resources/google_container_registry.md create mode 100644 examples/resources/octopusdeploy_google_container_registry/import.sh create mode 100644 examples/resources/octopusdeploy_google_container_registry/resource.tf diff --git a/docs/resources/google_container_registry.md b/docs/resources/google_container_registry.md new file mode 100644 index 00000000..bb9d9669 --- /dev/null +++ b/docs/resources/google_container_registry.md @@ -0,0 +1,50 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "octopusdeploy_google_container_registry Resource - terraform-provider-octopusdeploy" +subcategory: "" +description: |- + This resource manages a Google Container Registry feed in Octopus Deploy (alias for Docker Container Registry feed) +--- + +# octopusdeploy_google_container_registry (Resource) + +This resource manages a Google Container Registry feed in Octopus Deploy (alias for Docker Container Registry feed) + +## Example Usage + +```terraform +resource "octopusdeploy_google_container_registry" "example" { + name = "Test Google Container Registry (OK to Delete)" + feed_uri = "https://google.docker.test" + registry_path = "testing/test-image" + password = "google authentication key file contents (json)" +} +``` + + +## Schema + +### Required + +- `feed_uri` (String) +- `name` (String) The name of this resource. + +### Optional + +- `api_version` (String) +- `password` (String, Sensitive) The password associated with this resource. +- `registry_path` (String) +- `space_id` (String) The space ID associated with this Google container registry feed. +- `username` (String, Sensitive) The username associated with this resource. + +### Read-Only + +- `id` (String) The unique ID for this resource. + +## Import + +Import is supported using the following syntax: + +```shell +terraform import [options] octopusdeploy_google_container_registry. +``` diff --git a/docs/resources/s3_feed.md b/docs/resources/s3_feed.md index 1237755e..386182da 100644 --- a/docs/resources/s3_feed.md +++ b/docs/resources/s3_feed.md @@ -3,12 +3,12 @@ page_title: "octopusdeploy_s3_feed Resource - terraform-provider-octopusdeploy" subcategory: "" description: |- - This resource manages a OCI Registry feed in Octopus Deploy. + This resource manages a Amazon S3 Bucket feed in Octopus Deploy. --- # octopusdeploy_s3_feed (Resource) -This resource manages a OCI Registry feed in Octopus Deploy. +This resource manages a Amazon S3 Bucket feed in Octopus Deploy. ## Example Usage diff --git a/examples/resources/octopusdeploy_google_container_registry/import.sh b/examples/resources/octopusdeploy_google_container_registry/import.sh new file mode 100644 index 00000000..b9de531d --- /dev/null +++ b/examples/resources/octopusdeploy_google_container_registry/import.sh @@ -0,0 +1 @@ +terraform import [options] octopusdeploy_google_container_registry. \ No newline at end of file diff --git a/examples/resources/octopusdeploy_google_container_registry/resource.tf b/examples/resources/octopusdeploy_google_container_registry/resource.tf new file mode 100644 index 00000000..ffb3d4b8 --- /dev/null +++ b/examples/resources/octopusdeploy_google_container_registry/resource.tf @@ -0,0 +1,6 @@ +resource "octopusdeploy_google_container_registry" "example" { + name = "Test Google Container Registry (OK to Delete)" + feed_uri = "https://google.docker.test" + registry_path = "testing/test-image" + password = "google authentication key file contents (json)" +} From b09855d9921af3b11118cfaab30b3e080ac77f24 Mon Sep 17 00:00:00 2001 From: "denys.kostynchuk" Date: Fri, 25 Oct 2024 11:18:36 +1300 Subject: [PATCH 4/8] Update docs for Google Container Registry --- docs/resources/google_container_registry.md | 4 ++-- .../schemas/google_container_registry_feed.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/resources/google_container_registry.md b/docs/resources/google_container_registry.md index bb9d9669..805af467 100644 --- a/docs/resources/google_container_registry.md +++ b/docs/resources/google_container_registry.md @@ -3,12 +3,12 @@ page_title: "octopusdeploy_google_container_registry Resource - terraform-provider-octopusdeploy" subcategory: "" description: |- - This resource manages a Google Container Registry feed in Octopus Deploy (alias for Docker Container Registry feed) + This resource manages a Google Container Registry feed in Octopus Deploy (alias of Docker Container Registry feed) --- # octopusdeploy_google_container_registry (Resource) -This resource manages a Google Container Registry feed in Octopus Deploy (alias for Docker Container Registry feed) +This resource manages a Google Container Registry feed in Octopus Deploy (alias of Docker Container Registry feed) ## Example Usage diff --git a/octopusdeploy_framework/schemas/google_container_registry_feed.go b/octopusdeploy_framework/schemas/google_container_registry_feed.go index 1826010e..bd460447 100644 --- a/octopusdeploy_framework/schemas/google_container_registry_feed.go +++ b/octopusdeploy_framework/schemas/google_container_registry_feed.go @@ -12,7 +12,7 @@ var _ EntitySchema = GoogleContainerRegistryFeedSchema{} func (d GoogleContainerRegistryFeedSchema) GetResourceSchema() resourceSchema.Schema { return resourceSchema.Schema{ - Description: "This resource manages a Google Container Registry feed in Octopus Deploy (alias for Docker Container Registry feed)", + Description: "This resource manages a Google Container Registry feed in Octopus Deploy (alias of Docker Container Registry feed)", Attributes: map[string]resourceSchema.Attribute{ "api_version": resourceSchema.StringAttribute{ Optional: true, From ed5d9cc9b5ed71bf45d0674be5cad1c100e6d45d Mon Sep 17 00:00:00 2001 From: "denys.kostynchuk" Date: Fri, 25 Oct 2024 11:46:14 +1300 Subject: [PATCH 5/8] Remove test for existing resource --- .../resource_google_container_registry_test.go | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/octopusdeploy_framework/resource_google_container_registry_test.go b/octopusdeploy_framework/resource_google_container_registry_test.go index abf0e466..13b9d890 100644 --- a/octopusdeploy_framework/resource_google_container_registry_test.go +++ b/octopusdeploy_framework/resource_google_container_registry_test.go @@ -99,7 +99,6 @@ func testGoogleFeedWithMinimumData(data googleFeedTestData, localName string) st func testAssertGoogleFeedAttributes(expected googleFeedTestData, prefix string) resource.TestCheckFunc { return resource.ComposeTestCheckFunc( - testGoogleContainerRegistryExists(prefix), resource.TestCheckResourceAttr(prefix, "name", expected.name), resource.TestCheckResourceAttr(prefix, "feed_uri", expected.uri), resource.TestCheckResourceAttr(prefix, "registry_path", expected.registryPath), @@ -111,7 +110,6 @@ func testAssertGoogleFeedAttributes(expected googleFeedTestData, prefix string) func testAssertGoogleFeedMinimumAttributes(expected googleFeedTestData, prefix string) resource.TestCheckFunc { return resource.ComposeTestCheckFunc( - testGoogleContainerRegistryExists(prefix), resource.TestCheckResourceAttr(prefix, "name", expected.name), resource.TestCheckResourceAttr(prefix, "feed_uri", expected.uri), resource.TestCheckNoResourceAttr(prefix, "registry_path"), @@ -135,14 +133,3 @@ func testGoogleFeedCheckDestroy(s *terraform.State) error { return nil } - -func testGoogleContainerRegistryExists(prefix string) resource.TestCheckFunc { - return func(s *terraform.State) error { - feedId := s.RootModule().Resources[prefix].Primary.ID - if _, err := feeds.GetByID(octoClient, octoClient.GetSpaceID(), feedId); err != nil { - return err - } - - return nil - } -} From 3502dde63ff193b009da47e16ce3c52d3bda838f Mon Sep 17 00:00:00 2001 From: "denys.kostynchuk" Date: Fri, 25 Oct 2024 11:47:09 +1300 Subject: [PATCH 6/8] Update resource test name --- .../resource_google_container_registry_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/octopusdeploy_framework/resource_google_container_registry_test.go b/octopusdeploy_framework/resource_google_container_registry_test.go index 13b9d890..fab44f66 100644 --- a/octopusdeploy_framework/resource_google_container_registry_test.go +++ b/octopusdeploy_framework/resource_google_container_registry_test.go @@ -38,7 +38,7 @@ func TestAccOctopusDeployGoogleFeed(t *testing.T) { password: createData.password + "-updated", } withMinimumData := googleFeedTestData{ - name: "AWS S3 Without Keys", + name: "Google Registry Minimum", uri: "https://testcloud.artifact.google.minimum", } From dd08157c6c79ccef98ff4aea11877162f0bd581d Mon Sep 17 00:00:00 2001 From: "denys.kostynchuk" Date: Fri, 25 Oct 2024 11:56:22 +1300 Subject: [PATCH 7/8] Update test prefix name --- .../resource_google_container_registry_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/octopusdeploy_framework/resource_google_container_registry_test.go b/octopusdeploy_framework/resource_google_container_registry_test.go index fab44f66..d19206d2 100644 --- a/octopusdeploy_framework/resource_google_container_registry_test.go +++ b/octopusdeploy_framework/resource_google_container_registry_test.go @@ -20,7 +20,7 @@ type googleFeedTestData struct { func TestAccOctopusDeployGoogleFeed(t *testing.T) { localName := acctest.RandStringFromCharSet(20, acctest.CharSetAlpha) - prefix := "octopusdeploy_s3_feed." + localName + prefix := "octopusdeploy_google_feed." + localName createData := googleFeedTestData{ name: acctest.RandStringFromCharSet(20, acctest.CharSetAlpha), uri: "https://cloud.artifact.google.test", From bf8e59771f1e2fcef11d3a81f35ccf6163423d13 Mon Sep 17 00:00:00 2001 From: "denys.kostynchuk" Date: Fri, 25 Oct 2024 12:09:33 +1300 Subject: [PATCH 8/8] Use resource name for test prefix --- .../resource_google_container_registry_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/octopusdeploy_framework/resource_google_container_registry_test.go b/octopusdeploy_framework/resource_google_container_registry_test.go index d19206d2..99ef71eb 100644 --- a/octopusdeploy_framework/resource_google_container_registry_test.go +++ b/octopusdeploy_framework/resource_google_container_registry_test.go @@ -20,7 +20,7 @@ type googleFeedTestData struct { func TestAccOctopusDeployGoogleFeed(t *testing.T) { localName := acctest.RandStringFromCharSet(20, acctest.CharSetAlpha) - prefix := "octopusdeploy_google_feed." + localName + prefix := "octopusdeploy_google_container_registry." + localName createData := googleFeedTestData{ name: acctest.RandStringFromCharSet(20, acctest.CharSetAlpha), uri: "https://cloud.artifact.google.test",