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

bugfix: editing customer variables #73

Merged
merged 1 commit into from
Sep 17, 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
2 changes: 1 addition & 1 deletion docs/resources/template.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ resource "imagefactory_template" "azure_template" {
additional_signatures {
variable_name = imagefactory_variable.uefi_key.name
# If the variable is not defined in the template, the value can be set directly
# variable_value = "UEFI_KEY"
# variable_name = "UEFI_KEY"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/resources/imagefactory_template/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ resource "imagefactory_template" "azure_template" {
additional_signatures {
variable_name = imagefactory_variable.uefi_key.name
# If the variable is not defined in the template, the value can be set directly
# variable_value = "UEFI_KEY"
# variable_name = "UEFI_KEY"
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions imagefactory/variable/resource.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2022 Nordcloud Oy or its affiliates. All Rights Reserved.
// Copyright 2022-2024 Nordcloud Oy or its affiliates. All Rights Reserved.

package variable

Expand Down Expand Up @@ -79,7 +79,7 @@ func update(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Dia
}
}

input := sdk.NewVariable{
input := sdk.VariableChanges{
Name: graphql.String(newVariableName),
Value: graphql.String(variableValue),
}
Expand Down
74 changes: 74 additions & 0 deletions pkg/graphql/graphql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 12 additions & 2 deletions pkg/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -1297,7 +1297,7 @@ input TemplateChanges {
}


# Copyright 2021-2022 Nordcloud Oy or its affiliates. All Rights Reserved.
# Copyright 2021-2024 Nordcloud Oy or its affiliates. All Rights Reserved.

type Variable {
name: String!
Expand All @@ -1313,6 +1313,11 @@ input NewVariable {
value: String!
}

input VariableChanges {
name: String!
value: String!
}


# Copyright 2021-2023 Nordcloud Oy or its affiliates. All Rights Reserved.

Expand Down Expand Up @@ -1958,7 +1963,7 @@ extend type Query {
}


# Copyright 2021-2022 Nordcloud Oy or its affiliates. All Rights Reserved.
# Copyright 2021-2024 Nordcloud Oy or its affiliates. All Rights Reserved.

input CustomerVariableNameInput {
variableName: String!
Expand All @@ -1970,6 +1975,11 @@ extend type Mutation {
"""
createVariable(input: NewVariable!): Variable!

"""
updateVariable updates existing customer variable.
"""
updateVariable(input: VariableChanges!): Variable!

"""
deleteVariable removes existing customer variable.
"""
Expand Down
9 changes: 8 additions & 1 deletion pkg/graphql/variable.graphql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2022 Nordcloud Oy or its affiliates. All Rights Reserved.
# Copyright 2022-2024 Nordcloud Oy or its affiliates. All Rights Reserved.

query GetVariables {
variables {
Expand All @@ -20,6 +20,13 @@ mutation CreateVariable($input: NewVariable!) {
}
}

mutation UpdateVariable($input: VariableChanges!) {
updateVariable(input: $input) {
name
hash
}
}

mutation DeleteVariable($input: CustomerVariableNameInput!) {
deleteVariable(input: $input)
}
2 changes: 1 addition & 1 deletion pkg/sdk/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ type API interface {
// Variables CRUD
GetVariable(name string) (Variable, error)
CreateVariable(input NewVariable) (Variable, error)
UpdateVariable(input NewVariable) (Variable, error)
UpdateVariable(input VariableChanges) (Variable, error)
DeleteVariable(name string) error

// Actions
Expand Down
16 changes: 14 additions & 2 deletions pkg/sdk/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -668,8 +668,20 @@ func (c APIClient) CreateVariable(input NewVariable) (Variable, error) {
return Variable(r.CreateVariable), nil
}

func (c APIClient) UpdateVariable(input NewVariable) (Variable, error) {
return c.CreateVariable(input)
func (c APIClient) UpdateVariable(input VariableChanges) (Variable, error) {
req, err := graphql.NewUpdateVariableRequest(c.apiURL, &graphql.UpdateVariableVariables{
Input: graphql.VariableChanges(input),
})
if err != nil {
return Variable{}, fmt.Errorf("getting update variable request %w", err)
}

r := &graphql.Mutation{}
if err := c.graphqlAPI.Execute(req.Request, r); err != nil {
return Variable{}, fmt.Errorf("updating variable %w", err)
}

return Variable(r.UpdateVariable), nil
}

func (c APIClient) DeleteVariable(name string) error {
Expand Down
4 changes: 3 additions & 1 deletion pkg/sdk/model.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021-2023 Nordcloud Oy or its affiliates. All Rights Reserved.
// Copyright 2021-2024 Nordcloud Oy or its affiliates. All Rights Reserved.

package sdk

Expand Down Expand Up @@ -49,3 +49,5 @@ type APIKeyChanges graphql.ApiKeyChanges
type Variable graphql.Variable

type NewVariable graphql.NewVariable

type VariableChanges graphql.VariableChanges
Loading