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

[BUG] Issue with Memory when creating an app #66

Closed
1 task done
lechnerc77 opened this issue Apr 3, 2024 · 1 comment
Closed
1 task done

[BUG] Issue with Memory when creating an app #66

lechnerc77 opened this issue Apr 3, 2024 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@lechnerc77
Copy link
Member

Is there an existing issue for this?

  • I have searched the existing issues

What version of the Terraform provider are you using?

main-branch

What version of the Terraform CLI are you using?

1.7.3

What CF API version are you using?

3.153

What type of issue are you facing

bug report

Describe the bug

When creating a cloudfoundry_app and defining the memory in the unit MB the creation fails with the following error message:

 Error: Provider produced inconsistent result after apply
│ 
│ When applying changes to cloudfoundry_app.helloterraform, provider "provider[\"registry.terraform.io/sap/cloudfoundry\"]" produced an unexpected new value: .memory: was cty.StringVal("512MB"),
│ but now cty.StringVal("512M").
│ 
│ This is a bug in the provider, which should be reported in the provider's own issue tracker.

Expected Behavior

The creation works as when providing the memory value as "512M".
According to the CF API M and MB are both valid units

Steps To Reproduce

  1. Execute terraform init
  2. Execute terraform apply

Your Terraform Configuration

resource "cloudfoundry_app" "helloterraform" {
  space      = "dev"
  org        = module.trialaccount.cloudfoundry.org_name
  name       = "helloterraform"
  buildpacks = ["nodejs_buildpack"]
  memory     = "512MB"
  path       = data.archive_file.helloterraform.output_path

  routes = [{
    route = cloudfoundry_route.helloterraform.url
  }]

  service_bindings = [{
    service_instance = cloudfoundry_service_instance.helloterraform_xsuaa.name
  }]
}

Roles

-Org Manager

  • Space Manager

Add screenshots to help explain your problem

n/a

Additional context

The whole configuration looks like this:

main.tf

# looks up the id of the pre-created trial account
module "trialaccount" {
  source = "./modules/btp_trial_data"
}

data "cloudfoundry_space" "dev" {
  org  = module.trialaccount.cloudfoundry.org_id
  name = "dev"
}

data "cloudfoundry_domain" "cfapps" {
  name = "cfapps.${module.trialaccount.cloudfoundry.region}.hana.ondemand.com"
}

resource "random_id" "suffix" {
  byte_length = 4
}

resource "cloudfoundry_route" "helloterraform" {
  domain = data.cloudfoundry_domain.cfapps.id
  space  = data.cloudfoundry_space.dev.id
  host   = "helloterraform-${random_id.suffix.hex}"
}

data "cloudfoundry_service" "xsuaa" {
  name = "xsuaa"
}

resource "cloudfoundry_service_instance" "helloterraform_xsuaa" {
  name         = "helloterraform-xsuaa"
  space        = data.cloudfoundry_space.dev.id
  service_plan = data.cloudfoundry_service.xsuaa.service_plans["application"]
  type         = "managed"
  parameters = jsonencode({
    xsappname   = "helloterraform-${random_id.suffix.hex}"
    tenant-mode = "shared"
    scopes = [
      {
        name        = "helloterraform-${random_id.suffix.hex}.Display"
        description = "Display"
      },
    ]
    role-templates = [
      {
        name        = "Viewer"
        description = ""
        scope-references = [
          "helloterraform-${random_id.suffix.hex}.Display"
        ]
      }
    ]
  })
}


resource "cloudfoundry_app" "helloterraform" {
  space      = "dev"
  org        = module.trialaccount.cloudfoundry.org_name
  name       = "helloterraform"
  buildpacks = ["nodejs_buildpack"]
  memory     = "512MB"
  path       = data.archive_file.helloterraform.output_path

  routes = [{
    route = cloudfoundry_route.helloterraform.url
  }]

  service_bindings = [{
    service_instance = cloudfoundry_service_instance.helloterraform_xsuaa.name
  }]
}


data "archive_file" "helloterraform" {
  type        = "zip"
  source_dir  = "./assets/helloterraformapp"
  output_path = "./assets/helloterraform.zip"
}

provider.tf

terraform {
  required_providers {
    btp = {
      source  = "SAP/btp"
      version = "1.2.0"
    }
    cloudfoundry = {
      source  = "SAP/cloudfoundry"
      #source  = "cloudfoundry-community/cloudfoundry"
      version = "0.53.1"
    }
  }
}

# Configure the BTP Provider
provider "btp" {
  globalaccount = "Trial Account"
}

provider "cloudfoundry" {
  api_url = module.trialaccount.cloudfoundry.api_endpoint
}

outputs.tf

output "app_url" {
  value = "https://${cloudfoundry_route.helloterraform.url}"
}

/modules/btp_trial_data/btp_trial_data.tf

# ------------------------------------------------------------------------------------------------------
# Define the required providers for this module
# ------------------------------------------------------------------------------------------------------
terraform {
  required_providers {
    btp = {
      source = "SAP/btp"
    }
  }
}

# ------------------------------------------------------------------------------------------------------
# Fetch data from SAP BTP Trial Account 
# ------------------------------------------------------------------------------------------------------
locals {
  trial                  = [for acc in data.btp_subaccounts.all.values : acc if acc.name == "trial"][0]
  trial_cloudfoundry_env = [for env in data.btp_subaccount_environment_instances.trial.values : env if env.environment_type == "cloudfoundry"][0]
}

data "btp_subaccounts" "all" {}

data "btp_subaccount_environment_instances" "trial" { subaccount_id = local.trial.id }

modules/btp_trial_data/btp_trial_data_output.tf

output "id" {
  description = "The ID of the trial account"
  value       = local.trial.id
}

output "cloudfoundry" {
  description = "The cloudfoundry environment which is by default created for your trialaccount"
  value = {
    api_endpoint = lookup(jsondecode(local.trial_cloudfoundry_env.labels), "API Endpoint")
    org_id       = lookup(jsondecode(local.trial_cloudfoundry_env.labels), "Org ID")
    org_name     = lookup(jsondecode(local.trial_cloudfoundry_env.labels), "Org Name")
    region       = replace(local.trial_cloudfoundry_env.landscape_label, "/cf-/", "")
  }
}
@lechnerc77 lechnerc77 added the bug Something isn't working label Apr 3, 2024
@Gourab1998 Gourab1998 self-assigned this Apr 4, 2024
Gourab1998 added a commit that referenced this issue Apr 5, 2024
Gourab1998 added a commit that referenced this issue Apr 5, 2024
@Gourab1998
Copy link
Contributor

Thanks for raising this issue! Found several more issues while resolving this as mentioned in the PR

Dray56 pushed a commit that referenced this issue May 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants