diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 6f2152b..e322bf3 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -32,7 +32,7 @@ jobs: - name: Import GPG key id: import_gpg - uses: hashicorp/ghaction-import-gpg@v2.1.0 + uses: crazy-max/ghaction-import-gpg@v4.4.0 env: # These secrets will need to be configured for the repository: GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }} diff --git a/GNUmakefile b/GNUmakefile index 57b627b..bc0a8d1 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -42,5 +42,8 @@ test: go test -i $(TEST) || exit 1 echo $(TEST) | xargs -t -n4 go test $(TESTARGS) -timeout=30s -parallel=4 +gpg-key: + gpg --armor --export-secret-key $(EMAIL) -w0 | xclip -selection clipboard -i + testacc: TF_ACC=1 go test $(TEST) -v $(TESTARGS) -timeout 120m diff --git a/README.md b/README.md index 44fe52b..cc461ed 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,11 @@ provider "nautobot" { } data "nautobot_manufacturers" "all" {} + +resource "nautobot_manufacturer" "new" { + description = "Created with Terraform" + name = "Vendor I" +} ``` ## Developing the Provider diff --git a/examples/resources/nautobot_resource/resource.tf b/examples/resources/nautobot_resource/resource.tf index c1dac6b..0179a10 100644 --- a/examples/resources/nautobot_resource/resource.tf +++ b/examples/resources/nautobot_resource/resource.tf @@ -1,4 +1,4 @@ resource "nautobot_manufacturer" "new" { description = "Created with Terraform" - name = "Vendor I" + name = "Vendor I" } \ No newline at end of file diff --git a/internal/provider/resource_manufacturer.go b/internal/provider/resource_manufacturer.go index 66ffb38..d7a9d56 100644 --- a/internal/provider/resource_manufacturer.go +++ b/internal/provider/resource_manufacturer.go @@ -48,6 +48,7 @@ func resourceManufacturer() *schema.Resource { Description: "Manufacturer's display name.", Type: schema.TypeString, Optional: true, + Computed: true, }, "id": { Description: "Manufacturer's UUID.", @@ -78,19 +79,19 @@ func resourceManufacturer() *schema.Resource { Description: "Manufacturer's slug.", Type: schema.TypeString, Optional: true, + Computed: true, }, "url": { Description: "Manufacturer's URL.", Type: schema.TypeString, Optional: true, + Computed: true, }, }, } } func resourceManufacturerCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - var diags diag.Diagnostics - c := meta.(*apiClient).Client s := meta.(*apiClient).Server @@ -139,11 +140,9 @@ func resourceManufacturerCreate(ctx context.Context, d *schema.ResourceData, met } id := gjson.Get(string(rsp.Body), "results.0.id") - d.Set("id", id.String()) d.SetId(id.String()) - resourceManufacturerRead(ctx, d, meta) - return diags + return resourceManufacturerRead(ctx, d, meta) } tflog.Trace(ctx, "manufacturer created", map[string]interface{}{ @@ -153,11 +152,9 @@ func resourceManufacturerCreate(ctx context.Context, d *schema.ResourceData, met id := gjson.Get(data, "id") - //d.Set("id", id.String()) d.SetId(id.String()) - resourceManufacturerRead(ctx, d, meta) - return diags + return resourceManufacturerRead(ctx, d, meta) } func resourceManufacturerRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { @@ -192,12 +189,9 @@ func resourceManufacturerRead(ctx context.Context, d *schema.ResourceData, meta d.Set("name", item["name"].(string)) d.Set("created", item["created"].(string)) d.Set("description", item["description"].(string)) - // TODO: Fix issue with display going away d.Set("display", item["display"].(string)) d.Set("id", item["id"].(string)) - // TODO: Fix issue with slug going away d.Set("slug", item["slug"].(string)) - // TODO: Fix issue with url going away d.Set("url", item["url"].(string)) d.Set("last_updated", item["last_updated"].(string)) @@ -227,28 +221,42 @@ func resourceManufacturerRead(ctx context.Context, d *schema.ResourceData, meta } func resourceManufacturerUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - var diags diag.Diagnostics + c := meta.(*apiClient).Client + s := meta.(*apiClient).Server -// DcimManufacturersPartialUpdateWithBodyWithResponse request with arbitrary body returning *DcimManufacturersPartialUpdateResponse -// func (c *ClientWithResponses) DcimManufacturersPartialUpdateWithBodyWithResponse(ctx context.Context, id openapi_types.UUID, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*DcimManufacturersPartialUpdateResponse, error) { -// rsp, err := c.DcimManufacturersPartialUpdateWithBody(ctx, id, contentType, body, reqEditors...) -// if err != nil { -// return nil, err -// } -// return ParseDcimManufacturersPartialUpdateResponse(rsp) -// } + name := d.Get("name").(string) + id := d.Get("id").(string) -// func (c *ClientWithResponses) DcimManufacturersPartialUpdateWithResponse(ctx context.Context, id openapi_types.UUID, body DcimManufacturersPartialUpdateJSONRequestBody, reqEditors ...RequestEditorFn) (*DcimManufacturersPartialUpdateResponse, error) { -// rsp, err := c.DcimManufacturersPartialUpdate(ctx, id, body, reqEditors...) -// if err != nil { -// return nil, err -// } -// return ParseDcimManufacturersPartialUpdateResponse(rsp) -// } + var m nb.PatchedManufacturer + if d.HasChange("name") { + m.Name = &name + } + desc := d.Get("description").(string) + if d.HasChange("description") { + m.Description = &desc + } - return diags + slug := d.Get("slug").(string) + if d.HasChange("slug") { + m.Description = &slug + } + + _, err := c.DcimManufacturersPartialUpdateWithResponse( + ctx, + types.UUID(id), + nb.DcimManufacturersPartialUpdateJSONRequestBody(m)) + if err != nil { + return diag.Errorf("failed to update manufacturer %s on %s: %s", name, s, err.Error()) + } + + tflog.Trace(ctx, "manufacturer updated", map[string]interface{}{ + "name": name, + "data": []string{desc, slug}, + }) + + return resourceManufacturerRead(ctx, d, meta) } func resourceManufacturerDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {