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

feat: added LOCAL_DEV env variable for api mock development #45

Merged
merged 3 commits into from
Oct 20, 2022

Conversation

jackdelahunt
Copy link
Contributor

Description

This pr adds functionality for the provider to use the local mock server found here. This means when calling on the API to provision resources for us it goes trough the mock API and not the real one.

Verify

Terraform config (main.tf)

terraform {
  required_providers {
    rhoas = {
      source  = "registry.terraform.io/redhat-developer/rhoas"
      version = "0.1.0"
    }
  }
}

provider "rhoas" {
    offline_token = "..."
}

resource "rhoas_kafka" "instance" {
  name = "instance"
}

Commands

  • Clone app-services-sdk-js and start mock server with these steps -> here
  • make clean
  • make install
  • LOCAL_DEV=http://localhost:8000 terraform init
  • LOCAL_DEV=http://localhost:8000 terraform apply

Expected Results

You should receive a success message saying the kafka was created

@juandspy
Copy link
Collaborator

juandspy commented Oct 19, 2022

@jackdelahunt It's not working for me. I exported my token and then run:

resource.tf
terraform {
  required_providers {
    rhoas = {
      source  = "registry.terraform.io/redhat-developer/rhoas"
      version = "0.1"
    }
  }
}

provider "rhoas" {}

resource "rhoas_kafka" "foo" {
  name = "foo"
}
output logs
❯ LOCAL_DEV=http://localhost:8000 terraform plan
2022-10-19T15:20:27.762+0200 [WARN]  ValidateProviderConfig from "provider[\"registry.terraform.io/redhat-developer/rhoas\"]" changed the config value, but that value is unused
rhoas_kafka.foo: Refreshing state... [id=cd7vapj3jqdd4i185bvg]
2022-10-19T15:20:28.038+0200 [ERROR] provider.terraform-provider-rhoas: Response contains error diagnostic: @caller=/home/jdiazsua/go/pkg/mod/github.com/hashicorp/terraform-plugin-go@v0.14.0/tfprotov5/internal/diag/diagnostics.go:55 @module=sdk.proto diagnostic_detail= diagnostic_summary="API error: 400 Bad Request, response error: {"reason":"Missing or invalid id field","id":"103","kind":"Error","href":"/api/kafkas_mgmt/v1/errors/103","code":"KAFKAS-MGMT-103","operation_id":"1iWIimqGcrDuL61aUxIZqBTqNRa"}" tf_proto_version=5.3 tf_provider_addr=registry.terraform.io/redhat-developer/rhoas tf_req_id=f788411e-35e9-56c8-268f-6048a498de38 tf_rpc=ReadResource diagnostic_severity=ERROR tf_resource_type=rhoas_kafka timestamp=2022-10-19T15:20:28.037+0200
2022-10-19T15:20:28.039+0200 [ERROR] vertex "rhoas_kafka.foo" error: API error: 400 Bad Request, response error: {"reason":"Missing or invalid id field","id":"103","kind":"Error","href":"/api/kafkas_mgmt/v1/errors/103","code":"KAFKAS-MGMT-103","operation_id":"1iWIimqGcrDuL61aUxIZqBTqNRa"}
2022-10-19T15:20:28.039+0200 [ERROR] vertex "rhoas_kafka.foo (expand)" error: API error: 400 Bad Request, response error: {"reason":"Missing or invalid id field","id":"103","kind":"Error","href":"/api/kafkas_mgmt/v1/errors/103","code":"KAFKAS-MGMT-103","operation_id":"1iWIimqGcrDuL61aUxIZqBTqNRa"}
╷
│ Error: API error: 400 Bad Request, response error: {"reason":"Missing or invalid id field","id":"103","kind":"Error","href":"/api/kafkas_mgmt/v1/errors/103","code":"KAFKAS-MGMT-103","operation_id":"1iWIimqGcrDuL61aUxIZqBTqNRa"}
│ 
│   with rhoas_kafka.foo,
│   on resource.tf line 12, in resource "rhoas_kafka" "foo":
│   12: resource "rhoas_kafka" "foo" {
│ 
╵

Oh, and I'm running the server as a docker container:

REPOSITORY                                                 TAG           IMAGE ID       CREATED         SIZE
quay.io/rhosak/api-mock                                    latest        afa27f01931c   2 days ago      356MB

Also, do I need a valid token to use the server?

@dimakis
Copy link

dimakis commented Oct 19, 2022

@jackdelahunt It's not working for me. I exported my token and then run:

resource.tf
output logs
Oh, and I'm running the server as a docker container:

REPOSITORY                                                 TAG           IMAGE ID       CREATED         SIZE
quay.io/rhosak/api-mock                                    latest        afa27f01931c   2 days ago      356MB

Also, do I need a valid token to use the server?

The token request is made separately against RedHat SSO. This should be avoided (in the code) if running TF against localhost or a flag.

@juandspy
Copy link
Collaborator

The token request is made separately against RedHat SSO. This should be avoided (in the code) if running TF against localhost or a flag.

@dimakis Something like this?

@dimakis
Copy link

dimakis commented Oct 19, 2022

The token request is made separately against RedHat SSO. This should be avoided (in the code) if running TF against localhost or a flag.

@dimakis Something like this?

yes, I left a comment on your PR just as a thought, which explains my thinking a little more

@jackdelahunt
Copy link
Contributor Author

@dimakis @juandspy I merged Juans pr and it is still working for me, try it again and see how it goes

@juandspy
Copy link
Collaborator

I've cloned the repo again and it just worked 🤯 I guess I was doing something wrong. In any case, thanks a lot for these changes @jackdelahunt

Copy link

@rkpattnaik780 rkpattnaik780 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified! Great PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants