Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(mnq_nats): delete update in nats credential #2720

Merged
merged 3 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 2 additions & 23 deletions internal/services/mnq/nats_credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ func ResourceNatsCredentials() *schema.Resource {
return &schema.Resource{
CreateContext: ResourceMNQNatsCredentialsCreate,
ReadContext: ResourceMNQNatsCredentialsRead,
UpdateContext: ResourceMNQNatsCredentialsUpdate,
DeleteContext: ResourceMNQNatsCredentialsDelete,
Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
Expand All @@ -28,13 +27,15 @@ func ResourceNatsCredentials() *schema.Resource {
"account_id": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "ID of the nats account",
DiffSuppressFunc: dsf.Locality,
},
"name": {
Type: schema.TypeString,
Computed: true,
Optional: true,
ForceNew: true,
Description: "The nats credentials name",
},
"file": {
Expand Down Expand Up @@ -94,28 +95,6 @@ func ResourceMNQNatsCredentialsRead(ctx context.Context, d *schema.ResourceData,
return nil
}

func ResourceMNQNatsCredentialsUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
api, region, id, err := NewNatsAPIWithRegionAndID(m, d.Id())
if err != nil {
return diag.FromErr(err)
}

req := &mnq.NatsAPIUpdateNatsAccountRequest{
Region: region,
NatsAccountID: id,
}

if d.HasChange("name") {
req.Name = types.ExpandUpdatedStringPtr(d.Get("name"))
}

if _, err := api.UpdateNatsAccount(req, scw.WithContext(ctx)); err != nil {
return diag.FromErr(err)
}

return ResourceMNQNatsAccountRead(ctx, d, m)
}

func ResourceMNQNatsCredentialsDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
api, region, id, err := NewNatsAPIWithRegionAndID(m, d.Id())
if err != nil {
Expand Down
44 changes: 44 additions & 0 deletions internal/services/mnq/nats_credentials_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,50 @@ func TestAccNatsCredentials_Basic(t *testing.T) {
})
}

func TestAccNatsCredentials_UpdateName(t *testing.T) {
tt := acctest.NewTestTools(t)
defer tt.Cleanup()

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ProviderFactories: tt.ProviderFactories,
CheckDestroy: isNatsCredentialsDestroyed(tt),
Steps: []resource.TestStep{
{
Config: `
resource scaleway_mnq_nats_account main {
name = "test-mnq-nats-credentials-basic"
}

resource scaleway_mnq_nats_credentials main {
account_id = scaleway_mnq_nats_account.main.id
}
`,
Check: resource.ComposeTestCheckFunc(
isNatsCredentialsPresent(tt, "scaleway_mnq_nats_credentials.main"),
resource.TestCheckResourceAttrSet("scaleway_mnq_nats_credentials.main", "file"),
),
},
{
Config: `
resource scaleway_mnq_nats_account main {
name = "test-mnq-nats-credentials-basic"
}

resource scaleway_mnq_nats_credentials main {
account_id = scaleway_mnq_nats_account.main.id
name="toto"
}
`,
Check: resource.ComposeTestCheckFunc(
isNatsCredentialsPresent(tt, "scaleway_mnq_nats_credentials.main"),
resource.TestCheckResourceAttrSet("scaleway_mnq_nats_credentials.main", "file"),
),
},
},
})
}

func isNatsCredentialsPresent(tt *acctest.TestTools, n string) resource.TestCheckFunc {
return func(state *terraform.State) error {
rs, ok := state.RootModule().Resources[n]
Expand Down
Loading
Loading